From 8fc785aa243118ed38e6235f5000aea3586306de Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 25 Nov 2023 05:44:42 -0800 Subject: [PATCH 1/2] Second alt version added to 1985/sicherman Since some versions of clang object to the number of args to main() (requiring, supposedly, 0, 2 or 3[0] args) and in the case that it is enforced to not allow 1 I have added a second alt code that will be compiled IF sicherman.c fails to compile (and it'll compile into sicherman, not sicherman.alt2 or something like that). This required another change which also is in sicherman.c. The macros in the code that were C (which only translated to '/**/') and V were changed to lower case letters. Then the 'c' in 'subr()' was changed back to upper case. This also feels better since the 'C' (now 'c') in main() is although used it is not necessary either since it just is an empty comment. The primary reason for this change is that in the new version we obviously want the first arg of main() to be 'C' but with the macro 'C' this would not be possible. The change to 'v' from 'V' is simply to match case as both were in the original main() args (as ints). I am not sure I like having to change the macro names to lower case but at the same time the 'C="..."' in 'subr()' makes more sense to be upper case as it's about the language and it also allows in the new version that main() can have upper case C. Of course I could have made that change in just the new version but it felt better to match style as much as possible. [0] The version that objects to this still seems to allow 1 arg even though it claims that it requires 0, 2 or 3 args. --- 1985/sicherman/Makefile | 7 +++--- 1985/sicherman/README.md | 5 ++++ 1985/sicherman/sicherman.alt2.c | 26 ++++++++++++++++++++ 1985/sicherman/sicherman.c | 16 ++++++------ thanks-for-fixes.md | 43 ++++++++++++++++++++++----------- 5 files changed, 71 insertions(+), 26 deletions(-) create mode 100644 1985/sicherman/sicherman.alt2.c diff --git a/1985/sicherman/Makefile b/1985/sicherman/Makefile index 06424f8bb..2cd4dd6a6 100644 --- a/1985/sicherman/Makefile +++ b/1985/sicherman/Makefile @@ -132,16 +132,15 @@ all: data ${TARGET} clean clobber install love haste waste maker easter_egg \ sandwich supernova deep_magic magic charon pluto -${PROG}: ${PROG}.c - ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} +${PROG}: ${PROG}.c ${PROG}.alt2.c + ${CC} ${CFLAGS} $< -o $@ ${LDFLAGS} || \ + ${CC} ${CFLAGS} ${PROG}.alt2.c -o $@ ${LDFLAGS} # alternative executable # alt: data ${ALT_TARGET} @${TRUE} -${PROG}.alt: ${PROG}.alt.c - ${CC} ${CFLAGS} -traditional-cpp $< -o $@ ${LDFLAGS} # data files # diff --git a/1985/sicherman/README.md b/1985/sicherman/README.md index d4f1a83bd..66cc35005 100644 --- a/1985/sicherman/README.md +++ b/1985/sicherman/README.md @@ -6,6 +6,11 @@ make all NOTE: there is an [alternate version](#alternate-code) for those who have an old enough compiler or have a compiler that supports the option `-traditional-cpp`. +There is also an alternate version that is meant to work in the case that your +version of clang fails to compile it due to the wrong number of args to `main()` +should that ever happen (a compiler error of some versions of clang if `main()` +has four args is that `main()` can only have 0, 2 or 3 args but it does +currently accept 1 arg to `main()` nonetheless). ## To use: diff --git a/1985/sicherman/sicherman.alt2.c b/1985/sicherman/sicherman.alt2.c new file mode 100644 index 000000000..56262fe9f --- /dev/null +++ b/1985/sicherman/sicherman.alt2.c @@ -0,0 +1,26 @@ +#define C_C_(_)~' '&_ +#define _C_C(_)('\b'b'\b'>=C_C>'\t'b'\n') +#define C_C _|_ +#define b * +#define c /**/ +#define v _C_C( +char _,__; +main( +/* C program. (If you don't + * understand it look it + * up.) (In the */C, Manual) +char **Manual; +{ + char _,__; + while (read(0,&__,1) & write((_=(_=C_C_(__), + v))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~ + ' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v)); +} + +subr(C) +char *C; +{ + C="Lint says \"argument Manual isn't used.\" What's that\ + mean?"; while (write((read(('"'-'/*"'))?__:__-_+ + '\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1)); +} diff --git a/1985/sicherman/sicherman.c b/1985/sicherman/sicherman.c index 3df79d1b3..c52aa337f 100644 --- a/1985/sicherman/sicherman.c +++ b/1985/sicherman/sicherman.c @@ -2,24 +2,24 @@ #define _C_C(_)('\b'b'\b'>=C_C>'\t'b'\n') #define C_C _|_ #define b * -#define C /**/ -#define V _C_C( +#define c /**/ +#define v _C_C( char _,__; main( /* C program. (If you don't * understand it look it - * up.) (In the C*/ Manual) + * up.) (In the C*/Manual) { char _,__; while (read(0,&__,1) & write((_=(_=C_C_(__), - V))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~ - ' '&'\t'b'\n')+1),1),&_,1))_=C-V+subr(&V)); + v))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~ + ' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v)); } -subr(c) -char *c; +subr(C) +char *C; { - c="Lint says \"argument Manual isn't used.\" What's that\ + C="Lint says \"argument Manual isn't used.\" What's that\ mean?"; while (write((read(('"'-'/*"'))?__:__-_+ '\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1)); } diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index a8cb099d8..66da85c60 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -56,7 +56,7 @@ Scovell](https://web.archive.org/web/20070120220721/https://thomasscovell.com/ta ## [1984/decot](1984/decot/decot.c) ([README.md](1984/decot/README.md])) Cody fixed this to not require `-traditional-cpp` which some compilers like -clang do not support. Fixing `-traditional-cpp` is, as noted earlier, very +clang do not support. Fixing `-traditional-cpp` is, as noted later on, very complicated, but we encourage you to look at the alternate code (which is the original code with a minor modification made by the judges) and the fixed code, to see what had to be done. @@ -215,7 +215,7 @@ the default). ## [1985/sicherman](1985/sicherman/sicherman.c) ([README.md](1985/sicherman/README.md])) Cody fixed this _very twisted entry_ to not require `-traditional-cpp`. Fixing -`-traditional-cpp` is, as noted earlier, very complicated, but Cody would like +`-traditional-cpp` is, as noted later on, very complicated, but Cody would like to refer you to the original file [sicherman.orig.c](1985/sicherman/sicherman.orig.c) and he suggests that you then compare it to [sicherman.c](1985/sicherman/sicherman.c) for some good old @@ -248,6 +248,19 @@ were actually not what they appear: the only arg that existed in `main()` was { ``` +- The macros `C` and `V` were changed to lower case. This is because it felt +like the `C=" ..`' part in `subr()` would be better to be upper case as it talks +about the language. Also in the second alternate version (the first being the +original code) which is in case a new version of clang ever objects to only one +arg in `main()` (which is not out of the realm of possibility), `main()` can +have `C` as `argc` to `main()` so it would read like it once did: `C manual` +albeit with a `,` separating the two. The second alternate version is compiled +in case the first does not. Originally the macros were kept the same and the +`C` in `subr()` was `c`. It feels better (in some ways) to make it so that the +`C` for the language is upper case though, and since it actually translated to +`/**/` it can just be `c`, not `C`. The `V` was changed to `v` to be the same +case as `c`. + - The code: ```c @@ -259,7 +272,7 @@ were actually not what they appear: the only arg that existed in `main()` was had to be changed to: ```c - c="Lint says \"argument Manual isn't used.\" What's that\ + C="Lint says \"argument Manual isn't used.\" What's that\ mean?"; while (write((read(('"'-'/*"'))?__:__-_+ '\b'b'\b'|((_-52)%('\b'b'\b'+C_C_('\t'b'\n'))+1),1),&_,1)); ``` @@ -273,11 +286,12 @@ were actually not what they appear: the only arg that existed in `main()` was before and actually that there aren't that many changes in the function at all! - Notice also that the parameter `C` had to be changed to `c` due to the macro. + Notice also that the parameter `C` remained the same due to the macro `C` + rename to `c`. - The `char`s `_` and `__` were made file scope so the `subr()` could actually - compile but this does not affect the ones in `main()`. Why is this? You tell - us! + The `char`s `_` and `__` in `main()` were copied to file scope so that + `subr()` could actually compile but this does not affect the ones in + `main()`. Why is this? You tell us! - The code in `main()` is where there are significant changes, changing from: @@ -291,14 +305,15 @@ were actually not what they appear: the only arg that existed in `main()` was ```c while (read(0,&__,1) & write((_=(_=C_C_(__), V))?__:__-_+'\b'b'\b'|((_-52)%('\b'b'\b'+~ - ' '&'\t'b'\n')+1),1),&_,1))_=C-V+subr(&V)); + ' '&'\t'b'\n')+1),1),&_,1))_=c-v+subr(&v)); ``` - Note how numerous of the macros can still be used but some cannot be. Can - you figure out why? Why too is it that the `subr()` function is called but - it appears that some of the code in that function is also in `main()` in the - `while` condition? What happens if you remove it from `main()`? What happens - if you remove it from `subr()` or don't even bother calling `subr()`? + Note how numerous of the macros (though two changed in case) can still be + used but some cannot be. Can you figure out why? Why too is it that the + `subr()` function is called but it appears that some of the code in that + function is also in `main()` in the `while` condition? What happens if you + remove it from `main()`? What happens if you remove it from `subr()` or + don't even bother calling `subr()`? # 1986 @@ -523,7 +538,7 @@ unlikely(?) but nevertheless suggested case that `putchar()` is not available. Cody fixed this twisted entry (as we called it :-) ) for modern compilers, including making it no longer require `-traditional-cpp`. Fixing -`-traditional-cpp` is, as noted earlier, very complicated, but we encourage you +`-traditional-cpp` is, as noted later on, very complicated, but we encourage you to compare the fix from the original entry. There was another problem to resolve as well, however. From 8bda247aa32051876a44cc89a98db8226aedf68a Mon Sep 17 00:00:00 2001 From: Cody Boone Ferguson <53008573+xexyl@users.noreply.github.com> Date: Sat, 25 Nov 2023 05:51:56 -0800 Subject: [PATCH 2/2] Add link in thanks to sicherman.alt2.c --- thanks-for-fixes.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/thanks-for-fixes.md b/thanks-for-fixes.md index 66da85c60..837cc35a2 100644 --- a/thanks-for-fixes.md +++ b/thanks-for-fixes.md @@ -250,11 +250,13 @@ were actually not what they appear: the only arg that existed in `main()` was - The macros `C` and `V` were changed to lower case. This is because it felt like the `C=" ..`' part in `subr()` would be better to be upper case as it talks -about the language. Also in the second alternate version (the first being the +about the language. Also in the second [alternate +version](1985/sicherman/sicherman.alt2.c) (the first being the original code) which is in case a new version of clang ever objects to only one arg in `main()` (which is not out of the realm of possibility), `main()` can have `C` as `argc` to `main()` so it would read like it once did: `C manual` -albeit with a `,` separating the two. The second alternate version is compiled +albeit with a `,` separating the two. The [second +alternate](1985/sicherman/sicherman.alt2.c) version is compiled in case the first does not. Originally the macros were kept the same and the `C` in `subr()` was `c`. It feels better (in some ways) to make it so that the `C` for the language is upper case though, and since it actually translated to