From: Marius Gavrilescu Date: Sat, 18 Jul 2015 08:26:13 +0000 (+0300) Subject: Don't give special treatement to kraut and scramble X-Git-Tag: debian/2.54~12 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=027a076285666ab63987cfeef204543963684359;p=filters.git Don't give special treatement to kraut and scramble --- diff --git a/Makefile b/Makefile index a30c64e..a59b5ab 100644 --- 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 diff --git a/debian/copyright b/debian/copyright index 900ee9e..bdb27fa 100644 --- a/debian/copyright +++ b/debian/copyright @@ -12,7 +12,7 @@ Copyright: 1993 Duane Paulson 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 index 4390437..0000000 --- a/kraut.dir/destructions +++ /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 index e09ba5f..0000000 --- a/kraut.dir/kraut.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -/* 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 index e46acde..0000000 --- a/kraut.dir/kraut.l +++ /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 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"); + +%% + + diff --git a/ky00te.dir/makefile b/ky00te.dir/makefile index 47d1f64..715559e 100644 --- a/ky00te.dir/makefile +++ b/ky00te.dir/makefile @@ -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 index 0000000..fc35ff8 --- /dev/null +++ b/scramble.c @@ -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 . + */ + +#include +#include // for isalpha() +#include // for malloc()/calloc()/realloc()/free() and rand()/srand() +#include // for strlen() +#include // 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 index 4b4e7cd..0000000 --- a/scramble.dir/Makefile +++ /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 index fc35ff8..0000000 --- a/scramble.dir/scramble.c +++ /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 . - */ - -#include -#include // for isalpha() -#include // for malloc()/calloc()/realloc()/free() and rand()/srand() -#include // for strlen() -#include // 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; -}