[net.sources.bugs] More minor fixes to the Sun asteroids game.

richb@yarra.OZ (Rich Burridge) (12/18/86)

Context diffs are included below to fix two minor bugs:

  (1) Asteroids will now look in its directory for asteroids.help and
      asteroids.hs, instead of in the user's working directory. This
      should result in one high score file, and not several scattered all
      over the place.

  (2) The game usage message has been corrected.

Thanks to Stephen Page at Sun for pointing these out. These context diffs
should be applied after the ones to fix the function key problem. I wish
I'd discovered Larry Wall`s patch program before I put this on the net.
I'll know next time.

Regards Rich.

Rich Burridge            ISD:  +61 3 267-6222
Sun Australia            STD:  (03) 267-6222
14 Queens Rd,            ARPA: richb%yarra.oz@seismo.css.gov
Melbourne, VIC 3004.     UUCP: seismo!munnari!yarra.oz!richb
AUSTRALIA.               ACS:  richb@yarra.oz


*** ast_main.c~ Thu Dec 18 07:02:56 1986
--- ast_main.c  Thu Dec 18 07:41:35 1986
***************
*** 80,85
         "t"                            /* Hyperspace/teleport - Function key R3. */
       } ;
  
  char progname[MAXLINE] ;          /* Name of this program. */
  char titlestring[MAXLINE] ;
  int c ;                           /* Value returned by wgread. */

--- 80,86 -----
         "t"                            /* Hyperspace/teleport - Function key R3. */
       } ;
  
+ char path[MAXLINE] ;              /* Full path to the asteroids files. */
  char progname[MAXLINE] ;          /* Name of this program. */
  char titlestring[MAXLINE] ;
  int c ;                           /* Value returned by wgread. */
***************
*** 192,197
  {
    int hsfile,i ;
    struct hscore nullscore ;
  
    if ((hsfile = open("asteroids.hs",2)) == -1)
      {

--- 193,199 -----
  {
    int hsfile,i ;
    struct hscore nullscore ;
+   char highscname[MAXLINE] ;   /* Full path name of the high score file. */
  
    SPRINTF(highscname,"%sasteroids.hs",path) ;
    if ((hsfile = open(highscname,2)) == -1)
***************
*** 193,199
    int hsfile,i ;
    struct hscore nullscore ;
  
!   if ((hsfile = open("asteroids.hs",2)) == -1)
      {
        if ((hsfile = creat("asteroids.hs",0777)) == -1)
          {

--- 195,202 -----
    struct hscore nullscore ;
    char highscname[MAXLINE] ;   /* Full path name of the high score file. */
  
!   SPRINTF(highscname,"%sasteroids.hs",path) ;
!   if ((hsfile = open(highscname,2)) == -1)
      {
        if ((hsfile = creat(highscname,0777)) == -1)
          {
***************
*** 195,201
  
    if ((hsfile = open("asteroids.hs",2)) == -1)
      {
!       if ((hsfile = creat("asteroids.hs",0777)) == -1)
          {
            PRINTF("\nunable to create highscore file.\n") ;
            exit(1) ;

--- 198,204 -----
    SPRINTF(highscname,"%sasteroids.hs",path) ;
    if ((hsfile = open(highscname,2)) == -1)
      {
!       if ((hsfile = creat(highscname,0777)) == -1)
          {
            PRINTF("\nunable to create highscore file.\n") ;
            exit(1) ;
***************
*** 220,225
  
  {
    int hsfile,i ;
  
    if ((hsfile = open("asteroids.hs",1)) == -1)
      PRINTF("Unable to open highscore file.\n") ;

--- 223,229 -----
  
  {
    int hsfile,i ;
+   char highscname[MAXLINE] ;   /* Full path name of the high score file. */ 
  
    SPRINTF(highscname,"%sasteroids.hs",path) ;
    if ((hsfile = open(highscname,1)) == -1)
***************
*** 221,227
  {
    int hsfile,i ;
  
!   if ((hsfile = open("asteroids.hs",1)) == -1)
      PRINTF("Unable to open highscore file.\n") ;
    else
      {

--- 225,232 -----
    int hsfile,i ;
    char highscname[MAXLINE] ;   /* Full path name of the high score file. */ 
  
!   SPRINTF(highscname,"%sasteroids.hs",path) ;
!   if ((hsfile = open(highscname,1)) == -1)
      PRINTF("Unable to open highscore file.\n") ;
    else
      {
*** ast_stuff.c~        Thu Dec 18 07:02:57 1986
--- ast_stuff.c Thu Dec 18 08:29:05 1986
***************
*** 35,40
  extern char bonusstr[MAXLINE] ;      /* Bonus message. */
  extern char new_key_vals[3][MAXLINE] ;   /* Function key values used by asteroids. */
  extern char old_key_vals[3][MAXLINE] ;   /* Function key string values to save. */
  extern char progname[MAXLINE] ;      /* Name of this program. */
  extern char titlestring[MAXLINE] ;   /* Title string for asteroids window. */
  

--- 35,41 -----
  extern char bonusstr[MAXLINE] ;      /* Bonus message. */
  extern char new_key_vals[3][MAXLINE] ;   /* Function key values used by asteroids. */
  extern char old_key_vals[3][MAXLINE] ;   /* Function key string values to save. */
+ extern char path[MAXLINE] ;              /* Full path name of asteroid files. */
  extern char progname[MAXLINE] ;      /* Name of this program. */
  extern char titlestring[MAXLINE] ;   /* Title string for asteroids window. */
  
***************
*** 109,114
    char line[MAXLINE] ;     /* Current line read from help file. */
    FILE *tf ;               /* File descripter for help file. */
    int texty = 20 ;         /* Initial y coordinate for help message. */
   
    if ((tf = fopen(HELPNAME,"r")) == NULL)
      {

--- 110,116 -----
    char line[MAXLINE] ;     /* Current line read from help file. */
    FILE *tf ;               /* File descripter for help file. */
    int texty = 20 ;         /* Initial y coordinate for help message. */
+   char helpname[MAXLINE] ; /* Full help file pathname. */
   
    SPRINTF(helpname,"%s%s",path,HELPNAME) ;
    if ((tf = fopen(helpname,"r")) == NULL)
***************
*** 110,116
    FILE *tf ;               /* File descripter for help file. */
    int texty = 20 ;         /* Initial y coordinate for help message. */
   
!   if ((tf = fopen(HELPNAME,"r")) == NULL)
      {
        FPRINTF(stderr,"%s: can't open %s for help information.\n",
                progname,HELPNAME) ;

--- 112,119 -----
    int texty = 20 ;         /* Initial y coordinate for help message. */
    char helpname[MAXLINE] ; /* Full help file pathname. */
   
!   SPRINTF(helpname,"%s%s",path,HELPNAME) ;
!   if ((tf = fopen(helpname,"r")) == NULL)
      {
        FPRINTF(stderr,"%s: can't open %s for help information.\n",
                progname,helpname) ;
***************
*** 113,119
    if ((tf = fopen(HELPNAME,"r")) == NULL)
      {
        FPRINTF(stderr,"%s: can't open %s for help information.\n",
!               progname,HELPNAME) ;
        return ;
      }
    while (fgets(line,MAXLINE,tf) != NULL)

--- 116,122 -----
    if ((tf = fopen(helpname,"r")) == NULL)
      {
        FPRINTF(stderr,"%s: can't open %s for help information.\n",
!               progname,helpname) ;
        return ;
      }
    while (fgets(line,MAXLINE,tf) != NULL)
***************
*** 127,133
    y = (height - nolines*15+texty) / 2 ;
    draw_frame(x,y,length*FONT_WIDTH+20,nolines*15+texty) ;
  
!   tf = fopen(HELPNAME,"r") ;
    while (fgets(line,MAXLINE,tf) != NULL)
      {
        line[strlen(line)-1] = '\0' ;

--- 130,136 -----
    y = (height - nolines*15+texty) / 2 ;
    draw_frame(x,y,length*FONT_WIDTH+20,nolines*15+texty) ;
  
!   tf = fopen(helpname,"r") ;
    while (fgets(line,MAXLINE,tf) != NULL)
      {
        line[strlen(line)-1] = '\0' ;
***************
*** 244,249
    char *arg ;
    char *p ;      /* Pointer to string following argument flag. */
  
    width = SWIDTH ;
    height = SHEIGHT ;
    givehelp = 1 ;

--- 247,256 -----
    char *arg ;
    char *p ;      /* Pointer to string following argument flag. */
  
+   STRCPY(path,progname) ;         /* Extract full path name for asteroid files. */
+   if ((arg = rindex(path,'/')) == NULL) path[0] = '\0' ;
+   else *(++arg) = '\0' ;
+ 
    width = SWIDTH ;
    height = SHEIGHT ;
    givehelp = 1 ;
***************
*** 260,266
            case 'y' : height = atoi(p) ;    /* Height of asteroids window. */
                       if (height < 500) height = 500 ;
                       break ;
!           default  : FPRINTF(stderr,"sidtool: USAGE %s [-d]\n",argv[0]) ;
                       exit(1) ;
          }
        argc-- ;

--- 267,273 -----
            case 'y' : height = atoi(p) ;    /* Height of asteroids window. */
                       if (height < 500) height = 500 ;
                       break ;
!           default  : FPRINTF(stderr,"USAGE %s [-h] [-xnnn] [-ynnn]\n",argv[0]) ;
                       exit(1) ;
          }
        argc-- ;

D
D