From a0bb023d782dd2d8703670d560b5ccd8d25d640e Mon Sep 17 00:00:00 2001
From: Yigit Sever
Date: Thu, 4 Nov 2021 12:25:04 +0300
Subject: bins: shfmt, weasel suite, spark

---
 .local/bin/dups | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100755 .local/bin/dups

(limited to '.local/bin/dups')

diff --git a/.local/bin/dups b/.local/bin/dups
new file mode 100755
index 0000000..eb450f5
--- /dev/null
+++ b/.local/bin/dups
@@ -0,0 +1,54 @@
+#!/usr/bin/env perl
+
+# Finds duplicate adjacent words.
+
+use strict ;
+
+my $DupCount = 0 ;
+
+if (!@ARGV) {
+  print "usage: dups <file> ...\n" ;
+  exit ;
+}
+
+while (1) {
+  my $FileName = shift @ARGV ;
+
+  # Exit code = number of duplicates found.
+  exit $DupCount if (!$FileName) ;
+
+  open FILE, $FileName or die $!;
+
+  my $LastWord = "" ;
+  my $LineNum = 0 ;
+
+  while (<FILE>) {
+    chomp ;
+
+    $LineNum ++ ;
+
+    my @words = split (/(\W+)/) ;
+
+    foreach my $word (@words) {
+      # Skip spaces:
+      next if $word =~ /^\s*$/ ;
+
+      # Skip punctuation:
+      if ($word =~ /^\W+$/) {
+        $LastWord = "" ;
+        next ;
+      }
+
+      # Found a dup?
+      if (lc($word) eq lc($LastWord)) {
+        print "$FileName:$LineNum $word\n" ;
+        $DupCount ++ ;
+      } # Thanks to Sean Cronin for tip on case.
+
+      # Mark this as the last word:
+      $LastWord = $word ;
+    }
+  }
+
+  close FILE ;
+}
-- 
cgit v1.2.3-70-g09d2