Don't give special treatement to kraut and scramble
authorMarius Gavrilescu <marius@ieval.ro>
Sat, 18 Jul 2015 08:26:13 +0000 (11:26 +0300)
committerJoey Hess <joeyh@joeyh.name>
Thu, 30 Jul 2015 16:14:32 +0000 (12:14 -0400)
Makefile
debian/copyright
kraut.dir/destructions [deleted file]
kraut.dir/kraut.c [deleted file]
kraut.dir/kraut.l [deleted file]
kraut.l [new file with mode: 0644]
ky00te.dir/makefile
scramble.c [new file with mode: 0644]
scramble.dir/Makefile [deleted file]
scramble.dir/scramble.c [deleted file]

index a30c64ed4fd61ce98062aeceb5df8fb78d66b55a..a59b5ab2cd1d88574dd7530dc7bcec60952fd96d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ LEX     = flex
 BUILD  = jethro kraut cockney jive nyc ken ky00te newspeak nethackify scramble
 OTHER  = eleet b1ff chef jibberish upside-down rasterman studly fudd \
          censor spammer uniencode pirate kenny scottish fanboy LOLCAT
-CFLAGS = -O2 -lfl
+CFLAGS = -O2
 export CFLAGS
 INSTALL_PROGRAM = install
 
@@ -34,16 +34,14 @@ samples:    $(BUILD) $(OTHER)
 clean:
        $(RM) -f core *.o *~ $(BUILD) SAMPLES
        cd ky00te.dir && make clean
-       rm -f kraut.dir/lex.yy.c
        cd nethackify.dir && make clean
-       cd scramble.dir && make clean
 
 .SUFFIXES: .l
 
 .l:
        $(RM) $*.c
        $(LEX) -t $< > $*.c
-       $(CC) -o $@ $*.c $(CFLAGS)
+       $(CC) -o $@ $*.c $(CFLAGS) -lfl
        $(RM) $*.c
 
 .SUFFIXES: .dir
@@ -54,12 +52,7 @@ clean:
 ky00te:
        cd ky00te.dir && make
 
-kraut:
-       cd kraut.dir && lex kraut.l
-       cd kraut.dir && $(CC) kraut.c lex.yy.c -o ../kraut
-
 nethackify:
        cd nethackify.dir && make
 
-scramble: 
-       cd scramble.dir && make
+scramble: scramble.c
index 900ee9e4441170fe0595b2cc6294b0939c7ed595..bdb27fa24d8fe1dbd12ac9310383863382488051 100644 (file)
@@ -12,7 +12,7 @@ Copyright: 1993 Duane Paulson <ci922@cleveland.freenet.edu>
 License: other
   **   Public domain. Use at your own risk. Y'all come back now, heah?
 
-Files: kraut.dir/*
+Files: kraut.l
 Copyright: 1989 John Sparks
 License: other
   /* This is in the public domain. Do with it as you will. *\
diff --git a/kraut.dir/destructions b/kraut.dir/destructions
deleted file mode 100644 (file)
index 4390437..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-                                     Kraut
-                               +++++++++++++++++
-Compiling Kraut:
-
-You should have the files: kraut.c and kraut.l and lex.yy.c
-
-
-kraut.l must be run thru the unix 'lex' utility to produce the file lex.yy.c
-Then compile kraut.c and lex.yy.c to produce kraut
-
-     $lex kraut.l
-     $cc kraut.c lex.yy.c -o kraut
-  (You may get a list of warnings from the compiler. Ignore them.)
-
-Note: lex.yy.c is included in this package. You only need to use lex if you
-wish to make changes to kraut. 
-
-Using Kraut:
-
- Kraut uses standard input and output.
-
-examples:
-
-To translate a file called 'note' and output kraut to a file called 'knote':
-
-     $ cat note | kraut > knote
-
-To translate a file called 'note' and just print it to the screen:
-
-     $ cat note | kraut
-
-To have kraut wait to translate what you type at the keyboard and return it in
-kraut on your screen:
-
-     $ kraut
-
diff --git a/kraut.dir/kraut.c b/kraut.dir/kraut.c
deleted file mode 100644 (file)
index e09ba5f..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <stdio.h>
-/* Kraut v0.9  */
-/*     by      */
-/* John Sparks */
-/*  5-5-1989   */
-
-/* This is in the public domain. Do with it as you will. */
-
-const char *yylex(void);
-
-int main()
-{
-    char *line; 
-
-    while((line = (char *) yylex())) {
-         printf("%s", line);
-    }
-
-    return 0;
-}
-
-int yywrap ()
-{
-    return (1);
-}
diff --git a/kraut.dir/kraut.l b/kraut.dir/kraut.l
deleted file mode 100644 (file)
index e46acde..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-%e 2000
-%p 5000
-%n 1000
-%k 500
-%a 4000
-%o 2000
-BW [      ]
-EW [      .,;!?]
-
-%{
-#define YY_DECL const char *yylex(void)
-     char buf[128];
-
-%}
-
-%%
-ing                  return("ingkt");
-" the "             return(" ze ");
-"The "              return("Ze ");
-" with "            return(" mitt ");
-"With "             return("Mitt ");
-wr                  return("w-r-r");
-Wr                  return("W-r-r");
-R                   return("R-r-r");
-"Yes "              return("Jawohl ");
-" r"                return(" r-r-r");
-"Yes."              return("Jawohl.");
-"Yes!"              return("Jawohl!");
-"YES!"              return("JAWOHL!");
-" yes "             return(" ja ");
-" yes."             return(" ja.");
-" yes!"             return(" yes!");
-"No "               return("Nein ");
-"No!"               return("Nein!");
-"No?"               return("Nein?");
-" no "              return(" nein ");
-" no."              return(" nein.");
-" no!"              return(" nein!");
-" no?"              return(" nein?");
-[Mm]"r."            return("Herr");
-[Mm]"rs."           return("Frau");
-Miss                return("Fraulein");
-" of "              return(" uff ");
-"Of "               return("Uff ");
-my                  return("mein");
-My                  return("Mein");
-" and "             return(" undt ");
-"And "              return("Undt ");
-"One "              return("Ein ");
-" one"              return(" ein");
-"Is "               return("Ist ");
-" is "              return(" ist ");
-"ow "               return("ow ");
-"w "                return("w ");
-sh                  return("sch");
-Sh                  return("Sch");
-ch                  return("ch");
-Ch                  return("Ch");
-" c"                return(" k");
-" C"                return(" K");
-
-v                   return("f");
-V                   return("F");
-" w"                return(" v");
-W                   return("V");
-th                  return("d");
-Th                  return("D");
-[Jj]ohn             return("Johann");
-[Ww]illiam          return("Wilhelm");
-[Bb]rad             return("Wilhelm");
-[Gg]ary             return("Gerhardt");
-[Jj]on              return("Hansel");
-
-[a-f]"!"       {sprintf(buf,"%s Naturlich!",yytext);return(buf);}
-[p-z]"!"       {sprintf(buf,"%s Sieg Heil!",yytext);return(buf);}
-.              return(yytext);
-\n             return("\n");
-
-%%
-
-
diff --git a/kraut.l b/kraut.l
new file mode 100644 (file)
index 0000000..bc522d4
--- /dev/null
+++ b/kraut.l
@@ -0,0 +1,75 @@
+%e 2000
+%p 5000
+%n 1000
+%k 500
+%a 4000
+%o 2000
+BW [      ]
+EW [      .,;!?]
+
+%%
+ing                  printf("ingkt");
+" the "             printf(" ze ");
+"The "              printf("Ze ");
+" with "            printf(" mitt ");
+"With "             printf("Mitt ");
+wr                  printf("w-r-r");
+Wr                  printf("W-r-r");
+R                   printf("R-r-r");
+"Yes "              printf("Jawohl ");
+" r"                printf(" r-r-r");
+"Yes."              printf("Jawohl.");
+"Yes!"              printf("Jawohl!");
+"YES!"              printf("JAWOHL!");
+" yes "             printf(" ja ");
+" yes."             printf(" ja.");
+" yes!"             printf(" yes!");
+"No "               printf("Nein ");
+"No!"               printf("Nein!");
+"No?"               printf("Nein?");
+" no "              printf(" nein ");
+" no."              printf(" nein.");
+" no!"              printf(" nein!");
+" no?"              printf(" nein?");
+[Mm]"r."            printf("Herr");
+[Mm]"rs."           printf("Frau");
+Miss                printf("Fraulein");
+" of "              printf(" uff ");
+"Of "               printf("Uff ");
+my                  printf("mein");
+My                  printf("Mein");
+" and "             printf(" undt ");
+"And "              printf("Undt ");
+"One "              printf("Ein ");
+" one"              printf(" ein");
+"Is "               printf("Ist ");
+" is "              printf(" ist ");
+"ow "               printf("ow ");
+"w "                printf("w ");
+sh                  printf("sch");
+Sh                  printf("Sch");
+ch                  printf("ch");
+Ch                  printf("Ch");
+" c"                printf(" k");
+" C"                printf(" K");
+
+v                   printf("f");
+V                   printf("F");
+" w"                printf(" v");
+W                   printf("V");
+th                  printf("d");
+Th                  printf("D");
+[Jj]ohn             printf("Johann");
+[Ww]illiam          printf("Wilhelm");
+[Bb]rad             printf("Wilhelm");
+[Gg]ary             printf("Gerhardt");
+[Jj]on              printf("Hansel");
+
+[a-f]"!"       {printf("%s Naturlich!",yytext);}
+[p-z]"!"       {printf("%s Sieg Heil!",yytext);}
+.              printf("%s", yytext);
+\n             printf("\n");
+
+%%
+
+
index 47d1f6490219cc18e9b3e373f9d51edb1781aba4..715559e9a85b91703dbd17625c2c20c5efbbb5f1 100644 (file)
@@ -5,7 +5,7 @@ clean:
        rm -f ../ky00te
 
 ../ky00te: y.tab.o lex.yy.o
-       $(CC) -o ../ky00te lex.yy.o y.tab.o $(CFLAGS)
+       $(CC) -o ../ky00te lex.yy.o y.tab.o $(CFLAGS) -lfl
 
 lex.yy.o: lex.yy.c y.tab.h
        $(CC) $(CFLAGS) -c lex.yy.c
diff --git a/scramble.c b/scramble.c
new file mode 100644 (file)
index 0000000..fc35ff8
--- /dev/null
@@ -0,0 +1,205 @@
+/* Scramble the "inner" letters of each word in the input into a random order, and output the result. Non-word (that is, non-alphabetical) characters, and the first and last letters of each word, are left alone.
+ * Output to something other than stdout will append to the file instead of overwriting it - this may be undesirable, and can be changed if so.
+ */
+
+/* Copyright 2009-07-11 Andrew J. Buehler.
+ */
+
+/*   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <ctype.h> // for isalpha()
+#include <stdlib.h> // for malloc()/calloc()/realloc()/free() and rand()/srand()
+#include <string.h> // for strlen()
+#include <time.h> // for time()
+
+#define ALLOW_FILE_IO 0
+
+
+/* strips 'reduction' characters from the end of the input string and returns the result
+ * works only if strlen(string> >= reduction, which is the case in the only place it is presently called
+ */
+char *shorten_string(char *string, int reduction) {
+  int i;
+  
+  i = strlen(string);
+  
+  for (; reduction > 0; reduction--, i--) {
+    string[i-1] = '\0'; // would it work to use an 'i-reduction' approach instead, similar to what was later done in narrow_string()?
+  }
+  
+  return string;
+}
+
+/* strips 'reduction' characters from the beginning and the end of the input string and returns the result
+ * works only if(strlen(string) >= 2*reduction), which is the case in the only place it is presently called
+ */
+char *narrow_string(char *string, int reduction) {
+  int i = reduction;
+  
+  while(string[i]) {
+    string[i-reduction] = string[i];
+    i++;
+  }
+  string[i-reduction] = '\0';
+  
+  return shorten_string(string, reduction);
+}
+
+int all_one_letter(char *string) {
+  char c;
+  int i;
+  
+  c = string[0];
+  for(i = 1; string[i] != '\0'; i++) {
+    if(c != string[i]) {
+      return 0; // a nonduplicate letter has been found
+    }
+    c = string[i];
+  }
+  
+  return 1; // reached the end of the string having found only duplicate letters, so it's all one letter
+}
+
+/* randomly reorders the contents of the string
+ * WARNING: frees the input string and returns a replacement
+ */
+char *scramble_string(char *string) {
+  char *ret, *tmpstr;
+  int len, i, j;
+  
+  len = strlen(string);
+  if(len < 2) return string; // can't scramble a 1-character string or an empty string!
+  if(all_one_letter(string)) return(string); // can't scramble a string which consists entirely of one letter!
+  
+  ret = strdup(string);
+  
+  while(strcmp(string, ret) == 0) {
+    j = 0;
+    tmpstr = strdup(string);
+    while(len > 0) {
+      i = rand() % len;
+      ret[j] = tmpstr[i];
+      j++;
+      while(tmpstr[i] != '\0') {
+        tmpstr[i] = tmpstr[i+1];
+        i++;
+      }
+      len--;
+    }
+    free(tmpstr);
+    len = strlen(string);
+  }
+  
+  
+  free(string);
+  return ret;
+}
+
+char *clear_string(char *string) {
+  int i;
+  
+  i = strlen(string);
+  
+  for(; i >= 0 ; i--) {
+    string[i] = '\0';
+  }
+  
+  return string;
+}
+
+int main(int argc, char **argv) {
+  int word_length;
+  char c, tempchar, *word;
+  FILE *infile, *outfile;
+  
+#if ALLOW_FILE_IO
+ /* open files, if any other than stdin and stdout */
+  if(argc > 1) {
+    if(!strcmp(argv[1], "--help") ||
+       !strcmp(argv[1], "-h")) {
+      printf("Usage: %s [INPUT_FILENAME] [OUTPUT_FILENAME]\n", argv[0]);
+      printf("If INPUT_FILENAME is omitted or is '-', read from standard input\nIf OUTPUT_FILENAME is omitted or is '-', print to standard output\n");
+      return 0;
+    }
+    
+    if(strcmp(argv[1], "-")) {
+      infile = fopen(argv[1], "r");
+      if(infile == NULL) {
+        fprintf(stderr, "Unable to open input file %s for reading\n", argv[1]);
+        return 1;
+      }
+    } else {
+      infile = stdin;
+    }
+    
+    if(argc > 2) {
+      if(strcmp(argv[2], "-")) {
+        outfile = fopen(argv[2], "a");
+        if(outfile == NULL) {
+          fprintf(stderr, "Unable to open output file %s for writing\n", argv[2]);
+          return 2;
+        }
+      } else {
+        outfile = stdout;
+      }
+    }
+  } else { // no arguments specified
+    infile = stdin;
+    outfile = stdout;
+  }
+#else
+  infile = stdin;
+  outfile = stdout;
+#endif
+
+  srand(time(NULL)); // needed for scramble_string() to actually be random
+  
+  word_length = 0;
+  word = malloc(sizeof(char));
+  word[0] = '\0';
+  c = fgetc(infile);
+  
+  if(feof(infile)) {
+    printf("Reached EOF while reading the first character of the input file!\n");
+    return 4;
+  }
+  
+  while(!feof(infile)) {
+    if(isalpha(c)) {
+      word = realloc(word, word_length+2); // one for the new character, one for the null
+      word[word_length] = c;
+      word[word_length + 1] = '\0'; // duplicate addition with the next line, but possibly more readable
+      word_length++;
+    } else {
+      if(word_length) {
+        word_length--;
+        fputc(word[0], outfile);
+        if(word_length) {
+          tempchar = word[word_length];
+          word = scramble_string(narrow_string(word, 1));
+          fprintf(outfile, "%s", word);
+          fputc(tempchar, outfile);
+        }
+        word = clear_string(word);
+        word_length = 0;
+      }
+      fputc(c, outfile);
+    }
+    fflush(outfile);
+    c = fgetc(infile);
+  }
+  
+  free(word);
+  return 0;
+}
diff --git a/scramble.dir/Makefile b/scramble.dir/Makefile
deleted file mode 100644 (file)
index 4b4e7cd..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-../scramble: scramble.c
-       $(CC) -o $@ $< -O2 -g
-
-clean:
-       rm -f ../scramble
diff --git a/scramble.dir/scramble.c b/scramble.dir/scramble.c
deleted file mode 100644 (file)
index fc35ff8..0000000
+++ /dev/null
@@ -1,205 +0,0 @@
-/* Scramble the "inner" letters of each word in the input into a random order, and output the result. Non-word (that is, non-alphabetical) characters, and the first and last letters of each word, are left alone.
- * Output to something other than stdout will append to the file instead of overwriting it - this may be undesirable, and can be changed if so.
- */
-
-/* Copyright 2009-07-11 Andrew J. Buehler.
- */
-
-/*   This program is free software: you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation, either version 3 of the License, or
- *   (at your option) any later version.
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *   You should have received a copy of the GNU General Public License
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <ctype.h> // for isalpha()
-#include <stdlib.h> // for malloc()/calloc()/realloc()/free() and rand()/srand()
-#include <string.h> // for strlen()
-#include <time.h> // for time()
-
-#define ALLOW_FILE_IO 0
-
-
-/* strips 'reduction' characters from the end of the input string and returns the result
- * works only if strlen(string> >= reduction, which is the case in the only place it is presently called
- */
-char *shorten_string(char *string, int reduction) {
-  int i;
-  
-  i = strlen(string);
-  
-  for (; reduction > 0; reduction--, i--) {
-    string[i-1] = '\0'; // would it work to use an 'i-reduction' approach instead, similar to what was later done in narrow_string()?
-  }
-  
-  return string;
-}
-
-/* strips 'reduction' characters from the beginning and the end of the input string and returns the result
- * works only if(strlen(string) >= 2*reduction), which is the case in the only place it is presently called
- */
-char *narrow_string(char *string, int reduction) {
-  int i = reduction;
-  
-  while(string[i]) {
-    string[i-reduction] = string[i];
-    i++;
-  }
-  string[i-reduction] = '\0';
-  
-  return shorten_string(string, reduction);
-}
-
-int all_one_letter(char *string) {
-  char c;
-  int i;
-  
-  c = string[0];
-  for(i = 1; string[i] != '\0'; i++) {
-    if(c != string[i]) {
-      return 0; // a nonduplicate letter has been found
-    }
-    c = string[i];
-  }
-  
-  return 1; // reached the end of the string having found only duplicate letters, so it's all one letter
-}
-
-/* randomly reorders the contents of the string
- * WARNING: frees the input string and returns a replacement
- */
-char *scramble_string(char *string) {
-  char *ret, *tmpstr;
-  int len, i, j;
-  
-  len = strlen(string);
-  if(len < 2) return string; // can't scramble a 1-character string or an empty string!
-  if(all_one_letter(string)) return(string); // can't scramble a string which consists entirely of one letter!
-  
-  ret = strdup(string);
-  
-  while(strcmp(string, ret) == 0) {
-    j = 0;
-    tmpstr = strdup(string);
-    while(len > 0) {
-      i = rand() % len;
-      ret[j] = tmpstr[i];
-      j++;
-      while(tmpstr[i] != '\0') {
-        tmpstr[i] = tmpstr[i+1];
-        i++;
-      }
-      len--;
-    }
-    free(tmpstr);
-    len = strlen(string);
-  }
-  
-  
-  free(string);
-  return ret;
-}
-
-char *clear_string(char *string) {
-  int i;
-  
-  i = strlen(string);
-  
-  for(; i >= 0 ; i--) {
-    string[i] = '\0';
-  }
-  
-  return string;
-}
-
-int main(int argc, char **argv) {
-  int word_length;
-  char c, tempchar, *word;
-  FILE *infile, *outfile;
-  
-#if ALLOW_FILE_IO
- /* open files, if any other than stdin and stdout */
-  if(argc > 1) {
-    if(!strcmp(argv[1], "--help") ||
-       !strcmp(argv[1], "-h")) {
-      printf("Usage: %s [INPUT_FILENAME] [OUTPUT_FILENAME]\n", argv[0]);
-      printf("If INPUT_FILENAME is omitted or is '-', read from standard input\nIf OUTPUT_FILENAME is omitted or is '-', print to standard output\n");
-      return 0;
-    }
-    
-    if(strcmp(argv[1], "-")) {
-      infile = fopen(argv[1], "r");
-      if(infile == NULL) {
-        fprintf(stderr, "Unable to open input file %s for reading\n", argv[1]);
-        return 1;
-      }
-    } else {
-      infile = stdin;
-    }
-    
-    if(argc > 2) {
-      if(strcmp(argv[2], "-")) {
-        outfile = fopen(argv[2], "a");
-        if(outfile == NULL) {
-          fprintf(stderr, "Unable to open output file %s for writing\n", argv[2]);
-          return 2;
-        }
-      } else {
-        outfile = stdout;
-      }
-    }
-  } else { // no arguments specified
-    infile = stdin;
-    outfile = stdout;
-  }
-#else
-  infile = stdin;
-  outfile = stdout;
-#endif
-
-  srand(time(NULL)); // needed for scramble_string() to actually be random
-  
-  word_length = 0;
-  word = malloc(sizeof(char));
-  word[0] = '\0';
-  c = fgetc(infile);
-  
-  if(feof(infile)) {
-    printf("Reached EOF while reading the first character of the input file!\n");
-    return 4;
-  }
-  
-  while(!feof(infile)) {
-    if(isalpha(c)) {
-      word = realloc(word, word_length+2); // one for the new character, one for the null
-      word[word_length] = c;
-      word[word_length + 1] = '\0'; // duplicate addition with the next line, but possibly more readable
-      word_length++;
-    } else {
-      if(word_length) {
-        word_length--;
-        fputc(word[0], outfile);
-        if(word_length) {
-          tempchar = word[word_length];
-          word = scramble_string(narrow_string(word, 1));
-          fprintf(outfile, "%s", word);
-          fputc(tempchar, outfile);
-        }
-        word = clear_string(word);
-        word_length = 0;
-      }
-      fputc(c, outfile);
-    }
-    fflush(outfile);
-    c = fgetc(infile);
-  }
-  
-  free(word);
-  return 0;
-}
This page took 0.027566 seconds and 4 git commands to generate.