2 Commits
Author SHA1 Message Date
Cody Boone Ferguson 3d9f7763d0 Fix 1989/tromp alt code
Originally I put in the author's code without fixes in place. This is
one of the reasons I did not see the improvements that he suggested.
Several fixes had to be made and now it works. It should be noted I have
not tested more than one user updating the high score file but the file
is now created (I had to make a similar fix to the original entry as
well).

Format/typo check README.md file. Not sure I'm done with this one though
as presentation might be improved.
2023-10-20 10:24:17 -07:00
Cody Boone Ferguson 2c7cc31065 High score file and other bug fixes in 1989/tromp
Previously after the game ran the game segfaulted and the high score
file HI was not created. Now the file is created and sorted so that the
highest score is at the top. This file was not even created because 'd'
was an int and not a FILE * (to show how much has changed over the
years!) which popen() returns.

It seemed that popen() could not have the stty re-enabling of echo
either so it's now in a system() call (it might have been because of a
problem I later fixed as described below).

But reinstating echo did not work right and in fact one could not even
type the character 'u'. The important changes here are:

- 25||i%12<2?7:0;srand(getpid());system("stty cbreak -echo stop u");sigaction(14,v,
+ 25||i%12<2?7:0;srand(getpid());system("stty cbreak -echo");sigaction(14,v,

and

-0);while(getchar()-a[4]);puts("\033[H\033[J\033[7m");sigsetmask(s);}}d=popen(
-"stty -cbreak echo stop \023;cat - HI|sort -rn|head -20>/tmp/$$;mv /tmp/$$ HI\
-;cat HI","w");fprintf(d,"%4d on level %1d by %s\n",w,l,getlogin());pclose(d);}
+8192);printf("\033[H\033[J\033[0m%ld\n",w);if(c==a[5])break;for(j=264;j--;Q[j]=
+0);while(getchar()-a[4]);puts("\033[H\033[J\033[7m");sigsetmask(s);}}system("\
+stty cbreak echo");d=popen("cat - HI 2>/dev/null|sort -rn|head -20>/tmp/$$;mv /tmp/$$ HI\
+;cat HI","w");fprintf(d,"%4d by %s\n",w,getlogin());pclose(d);}

Now a word about these changes and in particularly the assignment to l
and the fprintf(d, ...):

-V;{char *a;*v=(long)t;h[3]=1000000/(l=C>1?atoi(V[1]):2);for(a=C>2?V[2]:"jkl pq";i;i--)*n++=i<
+V;{char *a;*v=(long)t;h[3]=1000000/(C>1?atoi(V[1]):2);for(a=C>2?V[2]:"jkl pq";i;i--)*n++=i<

and

-;cat HI","w");fprintf(d,"%4d on level %1d by %s\n",w,l,getlogin());pclose(d);}
+;cat HI","w");fprintf(d,"%4d by %s\n",w,getlogin());pclose(d);}

If you notice in the fprintf() call the 'l' is no longer referenced - no
level is noted. Why? This is because it was never changed aside from the
initial assignment of

	 l=C>1?atoi(V[1]):2

so there was no point in having the level as the argv was not for a
level but rather drops per second and command string. Thus the high
score (that is now created and updated - up to 20 entries) looks like:

	N by user

where N is the score and user is that from getlogin(). I noted this in
the README.md file.

I also gave a 'Try:' section in the README.md and noted the additional
bug fixes. As well I noted the alternative code which is put in
tromp.alt.c but the unmodified original alternate code which will not
work with modern compilers. Why not fixed? Because doing so the high
score file still was not created even when made to compile okay so I did
not see the point. Perhaps an older compiler will work anyway.

There were two include files that needed to be added which is done via
the compiler option -include: stdio.h and unistd.h.

Now 1989/tromp should work without a segfault, without disabling echo
(or the u key) and with a high score file with up to 20 entries!

One other change with the README is I removed the section 'Bug fix thank
you' as that was redundant: it was already at the top in the how to
build section which seems to be a better place. If nothing else it is
consistent with the others. However I added the links to both Yusuke and
me in the winners.html file like Landon had put int (the other files
with fixes needs the links as well). Of course if it's ideal to have a
separate section (maybe a subsection of how to compile) I will be happy
to find the files that need to be changed and do that.
2023-03-15 08:51:17 -07:00