Fix segfault in 1993/schnitzi + update README.md

If no file was specified or could not be opened the program segfaulted.
This has been fixed.

Format fixes in README.md.
This commit is contained in:
Cody Boone Ferguson committed 2023-03-30 12:05:15 -07:00
1 parent 9e07c1ae91
commit a411e62815
2 files changed
+47 -33

No files matched your search

+45 -31
View File
@@ -9,23 +9,45 @@
make all make all
[Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) made this use `fgets()` [Cody Boone Ferguson](/winners.html#Cody_Boone_Ferguson) fixed this to not
not `gets()` to make it safer. Thank you Cody for your assistance! segfault when no file is specified or the file cannot be opened for reading. he
also made this use `fgets()` not `gets()` to make it safer. Thank you Cody for
your assistance!
### To run ### To run:
./schnitzi file ./schnitzi file
where: where:
file a file containing some text file a file containing some text
## Judges' comments ## Try:
./schnitzi schnitzi.info
# ask some questions suggested by the author, noted below
We also suggest you ask the program:
Who is Mark Schnitzus?
Notice how it still manages to answer the question despite there being an
intentional spelling error there.
Try feeding the program source to the program and ask both:
What is cat ?
What is cat?
## Judges' comments:
After this program prints the contents of 'file', ask it After this program prints the contents of 'file', ask it
some questions related to the text. some questions related to the text.
The author suggests the following questions when using schnitzi.info: The author suggests the following questions when using schnitzi.info:
Who is Mark Schnitzius? Who is Mark Schnitzius?
What exactly does this program do? What exactly does this program do?
What language is it written in? What language is it written in?
@@ -38,17 +60,11 @@ not `gets()` to make it safer. Thank you Cody for your assistance!
We suggest you try using the body (minus the header and signature line) We suggest you try using the body (minus the header and signature line)
of a Usenet article. You might want to try something from alt.flame. :-) of a Usenet article. You might want to try something from alt.flame. :-)
If you have a ' in the question this entry may fail. NOTE: If you have a ' in the question this entry may fail.
NOTE: This entry uses `gets()` so you might get a warning when compiling and NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov.
running this entry.
NOTE: this entry will likely segfault if you do not provide it with a data ## Author's comments:
file.
NOTE: The author may also be contacted at: marks@aldrin.ksc.nasa.gov
## Author's comments
I wanted to write a program that would read in a text file in I wanted to write a program that would read in a text file in
natural language (such as English) and answer questions about that natural language (such as English) and answer questions about that
@@ -58,39 +74,37 @@ not `gets()` to make it safer. Thank you Cody for your assistance!
This program accepts the name of a text file as the first This program accepts the name of a text file as the first
parameter. For example, to run it on the supplied data file called parameter. For example, to run it on the supplied data file called
'info' you would type 'schnitzi info'. It echoes the file, then 'info' you would type `./schnitzi info`. It echoes the file, then
gives you a prompt where you may type in questions about that text. gives you a prompt where you may type in questions about that text.
The more words you use which are actually present in the text file, The more words you use which are actually present in the text file,
the better results you get. You'll need to hit <ctrl-c> to break out the better results you get. You'll need to hit `ctrl-c` to break out
of the program. Just hitting <return> at the prompt will reprint the of the program. Just hitting `return` at the prompt will reprint the
paragraph. paragraph.
If you're curious as to how it works, I guess you could feed in the If you're curious as to how it works, I guess you could feed in the
source as the input file and ask "How does this work?" at the prompt, source as the input file and ask "How does this work?" at the prompt,
but I'm not guaranteeing any results... but I'm not guaranteeing any results...
Compilation notes: ### Compilation notes:
o The use of 'strcasecmp' may be non-standard. 'strcmp' - The use of 'strcasecmp' may be non-standard. 'strcmp' can be substituted for
can be substituted for it, with a slight performance penalty. it, with a slight performance penalty.
o This program depends on the first command-line parameter, typically - This program depends on the first command-line parameter, typically called
called argv[0], to hold the name of the executable. It is my under- argv[0], to hold the name of the executable. It is my understanding that this
standing that this property of argv[0] is not guaranteed on some property of argv[0] is not guaranteed on some systems.
systems.
This program is obfuscated in the following ways: ### Obfuscation:
o It uses a hidden string to test for punctuation; - It uses a hidden string to test for punctuation.
o The layout, variable names, and expression format - The layout, variable names, and expression format have been chosen in such a
have been chosen in such a way as to cause visual confusion; way as to cause visual confusion.
o It uses uses external 'system' calls to echo the text - It uses uses external 'system' calls to echo the text file and break up the
file and break up the question into individual words with a question into individual words with a recursive call.
recursive call;
o It uses a clever hack to simulate artificial intelligence. - It uses a clever hack to simulate artificial intelligence.
The text for the info file, by the way, consists largely of headlines The text for the info file, by the way, consists largely of headlines
from the Weekly World News. from the Weekly World News.
+2 -2
View File
@@ -13,9 +13,9 @@
( lll>l1 ) li|=! ( l[3*l1+++3 ( lll>l1 ) li|=! ( l[3*l1+++3
] -ll[strlen ( ll)-1] ) ;return ] -ll[strlen ( ll)-1] ) ;return
( li ) ;}main ( ll,lll ( li ) ;}main ( ll,lll
) char*lll[];{char l1 [ 111][21],li1[111][21 ] ,il1[111],i1l ) char*lll[];{if(ll<2)return 1;char l1 [111][21], li1[111][21],il1[111],i1l
[ 111 ] ;int lli,l11,l1l,li/* ( */,ll1,il,l;FILE*f;if(ll-2 [ 111 ] ;int lli,l11,l1l,li/* ( */,ll1,il,l;FILE*f;if(ll-2
) {f=fopen ( lll[1],"r" ) ;lli=l=ll1=il=!1;while ) {f=fopen ( lll[1],"r" );if(!f)return 1;lli=l=ll1=il=!1;while
( fscanf(f,"%s",l1[lli] ) +1){li=ii ( l1[lli],3 ( fscanf(f,"%s",l1[lli] ) +1){li=ii ( l1[lli],3
) ;iii ( l1[lli] ) ;l1l=l11=!1;while ) ;iii ( l1[lli] ) ;l1l=l11=!1;while
( l1l>-ll ) {iii ( lll[-l1l] ( l1l>-ll ) {iii ( lll[-l1l]