Fix 1991/dds for clang
Looking at the author's remarks (which I hadn't checked yet) I was able
to determine how to get the code to disable warnings when compiling the
generated C code. The text
!.Xop.fssps!.Xop.sfuvso.uzqf!.Xop.jnqmjdju.gvodujpo.efdmbsbujpo
had to be added to the string 'q' and then
system(q-6);
had to be changed to
system(q-69);
to disable the warnings that clang (at least in macOS - not sure
elsewhere) ended up being errors due to the forcing of -Wno-error.
An important point is that the placement of that text does matter due to
the code:
*o=fopen(q-3,"w");
If the file name is not at the end then what will happen is the 'a.c' file
will not be created as the end of the string 's' will not be (when
decrypted) 'a.c'. At that point the compilation would fail as there is
no file to compile that is created. Thus the end of the string has to
be:
!.Xop.fssps!.Xop.sfuvso.uzqf!.Xop.jnqmjdju.gvodujpo.efdmbsbujpo!b/d
With this the file can be generated and compiled with both gcc and clang
even if -Werror would otherwise cause problems.
The alt code has been removed and the Makefile no longer has alt code
nor does it have the 'a' rule.
This commit is contained in:
1 parent
365bd6cba7
commit
7257727dfa
7 files changed
+50
-103
No files matched your search
@@ -1,6 +1,4 @@
|
||||
dds
|
||||
dds.alt
|
||||
a
|
||||
a.c
|
||||
a.out
|
||||
dds.orig
|
||||
|
||||
+2
-5
@@ -114,8 +114,8 @@ OBJ= ${PROG}.o
|
||||
DATA=
|
||||
TARGET= ${PROG}
|
||||
#
|
||||
ALT_OBJ= ${PROG}.alt.o
|
||||
ALT_TARGET= ${PROG}.alt
|
||||
ALT_OBJ=
|
||||
ALT_TARGET=
|
||||
|
||||
|
||||
#################
|
||||
@@ -132,9 +132,6 @@ all: data ${TARGET}
|
||||
${PROG}: ${PROG}.c
|
||||
${CC} ${CFLAGS} $< -o $@ ${LDFLAGS}
|
||||
|
||||
a: a.c
|
||||
${CC} ${CFLAGS} -Wno-return-type $< -o a.out ${LDFLAGS}
|
||||
|
||||
# alternative executable
|
||||
#
|
||||
alt: data ${ALT_TARGET}
|
||||
|
||||
+1
-61
@@ -12,9 +12,6 @@ Mastodon: <https://mstdn.social/@DSpinellis>
|
||||
make all
|
||||
```
|
||||
|
||||
There is an alt version for those who use `clang`. See [Alternate
|
||||
code](#alternate-code) below.
|
||||
|
||||
## To run:
|
||||
|
||||
```sh
|
||||
@@ -22,23 +19,9 @@ code](#alternate-code) below.
|
||||
./a.out 2>/dev/null
|
||||
```
|
||||
|
||||
The segfault which was always triggered was due to the code `*q>' '&&(*q)--;`.
|
||||
This seems odd at first glance but it's pointing to `s` which was read-only
|
||||
memory as a `char *s`. It's now a `char s[]`.
|
||||
|
||||
|
||||
NOTE: for `clang` you'll likely have to use the alternate code described below.
|
||||
|
||||
|
||||
## Try:
|
||||
|
||||
With gcc, make and run as follows:
|
||||
|
||||
```sh
|
||||
make dds
|
||||
```
|
||||
|
||||
For example, the author suggests trying:
|
||||
The author suggests trying:
|
||||
|
||||
```sh
|
||||
./dds LANDER.BAS 2>/dev/null
|
||||
@@ -55,49 +38,6 @@ You'll get errors yes but what does the generated file look like? What about
|
||||
other types of files?
|
||||
|
||||
|
||||
### Alternate code:
|
||||
|
||||
This alternate code allows this entry to work successfully even with clang.
|
||||
Unfortunately it's something of a hack or maybe even a kludge. This however
|
||||
seems important because it works well and allows for not messing with the `s`
|
||||
string which is quite complicated. Even changing the length could break
|
||||
functionality and indeed the length would have to be longer for this to work
|
||||
with clang.
|
||||
|
||||
How does it work? The original code (which you will see in [dds.c](dds.c)) does
|
||||
a `return system(q-6);` which equates to `return system("cc a.c");` but clang by
|
||||
default, at least in macOS, has default `-Werror` and there were some warnings.
|
||||
This means that the compilation failed with clang (because it didn't use `make`
|
||||
so no [Makefile](Makefile) was used). In particular it would fail (at least with
|
||||
[LANDER.BAS](LANDER.BAS)) due to a return from `main()` without a return value
|
||||
and the use of functions not yet declared.
|
||||
|
||||
Now as noted since the string `s` is complicated and to not inadvertently mess
|
||||
something up it was changed so that the code uses `system("make a");` and then an
|
||||
appropriate rule was added to the Makefile. Thus for the alternative version you
|
||||
now need both `make` and `cc`. If you use gcc you can just use the original
|
||||
version.
|
||||
|
||||
#### To build:
|
||||
|
||||
```sh
|
||||
make alt
|
||||
```
|
||||
|
||||
#### To run:
|
||||
|
||||
```sh
|
||||
./dds.alt some_basic_program.bas 2>/dev/null
|
||||
./a.out 2>/dev/null
|
||||
```
|
||||
|
||||
#### Try:
|
||||
|
||||
```sh
|
||||
./dds LANDER.BAS 2>/dev/null
|
||||
./a.out 2>/dev/null
|
||||
```
|
||||
|
||||
### INABIAF - it's not a bug it's a feature! :-)
|
||||
|
||||
Please note that if the BASIC file cannot be opened for reading or the output
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#define Q r=R[*p++-'0'];while(
|
||||
#define B ;break;case
|
||||
char s[]="Qjou!s\\311^-g\\311^-n\\311^-c\\::^-q-ma%mO1JBHm%BQ-aP1J[O1HB%[Q<nbj\
|
||||
o)*|gps)<<*txjudi)m*|aQdbtf!::::;sfuvso<aQefgbvmu;aQ<m,,a%CQ<csfbla%bQ<aN2!Q\
|
||||
\ndbtf!aP2Q;m>aP2Q<a%!D12J!JGJHJOJQJFJSJJJMHS%HD12D12N3!N4\nJUJT%UQm>aP4HC%T\
|
||||
Qs\\q,,^>m,2<m>aP4HC%SD12N1\nJNQm>s\\..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H\
|
||||
R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
|
||||
\\(aP3Q(^*m>g\\(aP3Q(^<fmtf!m,,aHC%QN1!N1\nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut)\
|
||||
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
|
||||
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";int k;char R[4][99]
|
||||
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
|
||||
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
|
||||
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system("make a");}*r=0
|
||||
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
|
||||
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
|
||||
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
+3
-2
@@ -8,10 +8,11 @@ Qs\\q,,^>m,2<m>aP4HC%SD12N1\nJNQm>s\\..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H\
|
||||
R%PN4\nQ<g\\(aP3Q(^>aP2Q,2<n\\(aP3Q(^>aP4Hb%OD12D12N2!N3\nJVP3Q,,<jg)aP3Q=>n\
|
||||
\\(aP3Q(^*m>g\\(aP3Q(^<fmtf!m,,aHC%QN1!N1\nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut)\
|
||||
aP1Q*aHb%FN1\nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa\
|
||||
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!b/d";int k;char R[4][99]
|
||||
P1HL%IQ*m>aN2!N2\nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2\nP2Hbdd!.Xop.fssps!.Xop.sfu\
|
||||
vso.uzqf!.Xop.jnqmjdju.gvodujpo.efdmbsbujpo!b/d";int k;char R[4][99]
|
||||
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
|
||||
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
|
||||
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system(q-6);}*r=0
|
||||
&&k!=*p)*r++=k;if(k==EOF){fputs("}}\n",o);fclose(o);return system(q-69);}*r=0
|
||||
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
|
||||
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
|
||||
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
|
||||
Reference in new issue
Block a user