1: /*
   2:  * Copyright (c) 1987 by Ed James, UC Berkeley.  All rights reserved.
   3:  *
   4:  * Copy permission is hereby granted provided that this notice is
   5:  * retained on all partial or complete copies.
   6:  *
   7:  * For more info on this and all of my stuff, mail edjames@berkeley.edu.
   8:  */
   9: 
  10: #include "include.h"
  11: 
  12: main(ac, av)
  13:     char    *av[];
  14: {
  15:     int         seed;
  16:     int         f_usage = 0, f_list = 0, f_showscore = 0;
  17:     int         f_printpath = 0;
  18:     char            *file = NULL;
  19:     char            *name, *ptr;
  20: #ifdef BSD
  21:     struct itimerval    itv;
  22: #endif
  23:     extern int      update(), quit(), log_score();
  24:     extern char     *default_game(), *okay_game();
  25: 
  26:     start_time = seed = time(0);
  27: 
  28:     name = *av++;
  29:     while (*av) {
  30: #ifndef SAVEDASH
  31:         if (**av == '-')
  32:             *++*av;
  33:         else
  34:             break;
  35: #endif
  36:         ptr = *av++;
  37:         while (*ptr) {
  38:             switch (*ptr) {
  39:             case '?':
  40:             case 'u':
  41:                 f_usage++;
  42:                 break;
  43:             case 'l':
  44:                 f_list++;
  45:                 break;
  46:             case 's':
  47:             case 't':
  48:                 f_showscore++;
  49:                 break;
  50:             case 'p':
  51:                 f_printpath++;
  52:                 break;
  53:             case 'r':
  54:                 seed = atoi(*av);
  55:                 av++;
  56:                 break;
  57:             case 'f':
  58:             case 'g':
  59:                 file = *av;
  60:                 av++;
  61:                 break;
  62:             default:
  63:                 fprintf(stderr, "Unknown option '%c'\n", *ptr,
  64:                     name);
  65:                 f_usage++;
  66:                 break;
  67:             }
  68:             ptr++;
  69:         }
  70:     }
  71:     srandom(seed);
  72: 
  73:     if (f_usage)
  74:         fprintf(stderr,
  75:             "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n",
  76:             name);
  77:     if (f_showscore)
  78:         log_score(1);
  79:     if (f_list)
  80:         list_games();
  81:     if (f_printpath) {
  82:         char    buf[100];
  83: 
  84:         strcpy(buf, SPECIAL_DIR);
  85:         buf[strlen(buf) - 1] = '\0';
  86:         puts(buf);
  87:     }
  88: 
  89:     if (f_usage || f_showscore || f_list || f_printpath)
  90:         exit(0);
  91: 
  92:     if (file == NULL)
  93:         file = default_game();
  94:     else
  95:         file = okay_game(file);
  96: 
  97:     if (file == NULL || read_file(file) < 0)
  98:         exit(1);
  99: 
 100:     init_gr();
 101:     setup_screen(sp);
 102: 
 103:     addplane();
 104: 
 105:     signal(SIGINT, quit);
 106:     signal(SIGQUIT, quit);
 107: #ifdef BSD
 108:     signal(SIGTSTP, SIG_IGN);
 109:     signal(SIGSTOP, SIG_IGN);
 110: #endif
 111:     signal(SIGHUP, log_score);
 112:     signal(SIGTERM, log_score);
 113: 
 114: #ifdef BSD
 115:     ioctl(fileno(stdin), TIOCGETP, &tty_start);
 116:     bcopy(&tty_start, &tty_new, sizeof(tty_new));
 117:     tty_new.sg_flags |= CBREAK;
 118:     tty_new.sg_flags &= ~ECHO;
 119:     ioctl(fileno(stdin), TIOCSETP, &tty_new);
 120: #endif
 121: 
 122: #ifdef SYSV
 123:     ioctl(fileno(stdin), TCGETA, &tty_start);
 124:     bcopy(&tty_start, &tty_new, sizeof(tty_new));
 125:     tty_new.c_lflag &= ~ICANON;
 126:     tty_new.c_lflag &= ~ECHO;
 127:     tty_new.c_cc[VMIN] = 1;
 128:     tty_new.c_cc[VTIME] = 0;
 129:     ioctl(fileno(stdin), TCSETAW, &tty_new);
 130: #endif
 131: 
 132:     signal(SIGALRM, update);
 133: 
 134: #ifdef BSD
 135:     itv.it_value.tv_sec = 0;
 136:     itv.it_value.tv_usec = 1;
 137:     itv.it_interval.tv_sec = sp->update_secs;
 138:     itv.it_interval.tv_usec = 0;
 139:     setitimer(ITIMER_REAL, &itv, NULL);
 140: #endif
 141: #ifdef SYSV
 142:     alarm(sp->update_secs);
 143: #endif
 144: 
 145:     for (;;) {
 146:         if (getcommand() != 1)
 147:             planewin();
 148:         else {
 149: #ifdef BSD
 150:             itv.it_value.tv_sec = 0;
 151:             itv.it_value.tv_usec = 0;
 152:             setitimer(ITIMER_REAL, &itv, NULL);
 153: #endif
 154: #ifdef SYSV
 155:             alarm(0);
 156: #endif
 157: 
 158:             update();
 159: 
 160: #ifdef BSD
 161:             itv.it_value.tv_sec = sp->update_secs;
 162:             itv.it_value.tv_usec = 0;
 163:             itv.it_interval.tv_sec = sp->update_secs;
 164:             itv.it_interval.tv_usec = 0;
 165:             setitimer(ITIMER_REAL, &itv, NULL);
 166: #endif
 167: #ifdef SYSV
 168:             alarm(sp->update_secs);
 169: #endif
 170:         }
 171:     }
 172: }
 173: 
 174: read_file(s)
 175:     char    *s;
 176: {
 177:     extern FILE *yyin;
 178:     int     retval;
 179: 
 180:     file = s;
 181:     yyin = fopen(s, "r");
 182:     if (yyin == NULL) {
 183:         perror(s);
 184:         return (-1);
 185:     }
 186:     retval = yyparse();
 187:     fclose(yyin);
 188: 
 189:     if (retval != 0)
 190:         return (-1);
 191:     else
 192:         return (0);
 193: }
 194: 
 195: char    *
 196: default_game()
 197: {
 198:     FILE        *fp;
 199:     static char file[256];
 200:     char        line[256], games[256];
 201: 
 202:     strcpy(games, SPECIAL_DIR);
 203:     strcat(games, GAMES);
 204: 
 205:     if ((fp = fopen(games, "r")) == NULL) {
 206:         perror(games);
 207:         return (NULL);
 208:     }
 209:     if (fgets(line, sizeof(line), fp) == NULL) {
 210:         fprintf(stderr, "%s: no default game available\n", games);
 211:         return (NULL);
 212:     }
 213:     fclose(fp);
 214:     line[strlen(line) - 1] = '\0';
 215:     strcpy(file, SPECIAL_DIR);
 216:     strcat(file, line);
 217:     return (file);
 218: }
 219: 
 220: char    *
 221: okay_game(s)
 222:     char    *s;
 223: {
 224:     FILE        *fp;
 225:     static char file[256];
 226:     char        *ret = NULL, line[256], games[256];
 227: 
 228:     strcpy(games, SPECIAL_DIR);
 229:     strcat(games, GAMES);
 230: 
 231:     if ((fp = fopen(games, "r")) == NULL) {
 232:         perror(games);
 233:         return (NULL);
 234:     }
 235:     while (fgets(line, sizeof(line), fp) != NULL) {
 236:         line[strlen(line) - 1] = '\0';
 237:         if (strcmp(s, line) == 0) {
 238:             strcpy(file, SPECIAL_DIR);
 239:             strcat(file, line);
 240:             ret = file;
 241:             break;
 242:         }
 243:     }
 244:     fclose(fp);
 245:     if (ret == NULL) {
 246:         test_mode = 1;
 247:         ret = s;
 248:         fprintf(stderr, "%s: %s: game not found\n", games, s);
 249:         fprintf(stderr, "Your score will not be logged.\n");
 250:         sleep(2);   /* give the guy time to read it */
 251:     }
 252:     return (ret);
 253: }
 254: 
 255: list_games()
 256: {
 257:     FILE        *fp;
 258:     char        line[256], games[256];
 259:     int     num_games = 0;
 260: 
 261:     strcpy(games, SPECIAL_DIR);
 262:     strcat(games, GAMES);
 263: 
 264:     if ((fp = fopen(games, "r")) == NULL) {
 265:         perror(games);
 266:         return (-1);
 267:     }
 268:     puts("available games:");
 269:     while (fgets(line, sizeof(line), fp) != NULL) {
 270:         printf("	%s", line);
 271:         num_games++;
 272:     }
 273:     fclose(fp);
 274:     if (num_games == 0) {
 275:         fprintf(stderr, "%s: no games available\n", games);
 276:         return (-1);
 277:     }
 278:     return (0);
 279: }

Defined functions

default_game defined in line 195; used 2 times
list_games defined in line 255; used 1 times
  • in line 80
main defined in line 12; never used
okay_game defined in line 220; used 2 times
read_file defined in line 174; used 1 times
  • in line 97
Last modified: 1987-03-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3797
Valid CSS Valid XHTML 1.0 Strict