|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 7377 (0x1cd1) Types: TextFile Names: »main.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Tetris/main.c.orig«
/* ** written by adam margulies vespa@ssyx.ucsc.edu ** {...}!ucbvax!ucscc!ssyx!vespa ** ** permission is granted to freely distribute this code provided that you: ** ** 1) don't charge for it ** 2) leave my name and header on it ** 3) clearly document your changes and place your name on them ** */ /* Tetris: a game supposedly written by some Soviet kid. */ /* */ /* Last kludge: February 23, 1989 */ /* Guilty party: adam margulies, vespa@ssyx.ucsc.edu */ /* */ /* This program contains some hopelessly inbred array operations. */ /* It also is a monster to behold. */ /* */ /* All hope abandon, ye who enter here. */ /* */ /* Tetris: main.c */ /* */ /* main loop, waits for keypress and then passes it to process_input() */ /* */ #include "tetris.h" int opterr = 1; int optind = 1; int optopt; char *optarg; main(argc, argv, envp) int argc; char **argv, **envp; { /* I do a lot of voids, so that lint doesn't complain */ void init_tetris(), print_shape(), setup_next(), drop_block(); char c, input; /* holds user's keypresses */ char tetrisenv[1024]; char buf[1024]; int i=0, j=0, k=0, disp_score; opterr = 0; disp_next = 1; disp_open = 1; shadow = 1; if(argv[1] && !strcmp(argv[1], "-")){ fprintf(stderr, "Usage: %s [-] [-whotnbsa] [-L level] [-N name] [-O oblev] [-K keys]\n", argv[0]); fprintf(stderr, "\t- - give this summary of usage\n"); fprintf(stderr, "\tw - makes you unwritable for duration of game\n"); fprintf(stderr, "\th - suppress printing of high score list\n"); fprintf(stderr, "\to - suppress opening screen selection box\n"); fprintf(stderr, "\tt - display roguelike tombstone\n"); fprintf(stderr, "\tn - turn off next block display\n"); fprintf(stderr, "\tb - turn off shadowing\n"); fprintf(stderr, "\ts - display high score list and exit\n"); fprintf(stderr, "\ta - addict option, logs you out when game is over\n"); fprintf(stderr, "\tN [name] - use [name] for high score list\n"); fprintf(stderr, "\tL [level] - start at [level] of difficulty\n"); fprintf(stderr, "\tO [oblev] - generate [oblev]s of debris\n"); fprintf(stderr, "\tK [keys] - map control keys to [keys]\n"); fprintf(stderr, "\t\tmail suggestions to vespa@ssyx.ucsc.edu\n"); fprintf(stderr, "\t\t {...}!ucbvax!ucscc!ssyx!vespa\n"); exit(0); } /* if the user has set an environment variable "TETRIS" then process it */ if(argc<2 && getenv("TETRIS") == NULL) { i=0, j=0, k=0; strcpy(tetrisenv, getenv("TETRIS")); argc = 1; while(i < strlen(tetrisenv) + 1) { if(tetrisenv[i] == ' ' || tetrisenv[i] == '\0') { buf[k] = '\0'; argv[++j] = (char *)malloc(100 * sizeof(char)); strcpy(argv[j], buf); argc++; i++; k = 0; } else { buf[k] = tetrisenv[i]; i++; k++; } } } else if(argc<2) argv[1] = (char *)malloc(100 * sizeof(char *)); /* process the arguments to the program */ while((c = getopt(argc, argv, "wtohnbsaL:N:O:K:")) != EOF) { switch(c) { case 'w': nowrite = 1; break; case 'a': addict = 1; break; case 't': disp_tomb = 1; break; case 'o': disp_open = 0; break; case 'h': disp_high = 1; break; case 'n': disp_next = 0; break; case 'b': shadow = 0; break; case 's': disp_score = 1; break; case 'N': strcpy(username, optarg); break; case 'L': level = (int)atoi(optarg); if(level>20) level = 20; break; case 'O': rubble = (int)atoi(optarg); if(rubble>13) rubble = 13; break; case 'K': if(strlen(optarg) == 7) strcpy(keystr, optarg); if(strlen(optarg) == 7) break; default: fprintf(stderr, "Unknown flag or improper usage:\n"); fprintf(stderr, "\tuse '%s -' for usage\n", argv[0]); exit(1); } } if(!init_csr()) { exit(1); } if(disp_score) { display_high(); exit(0); } init_tetris(); /* inits stuff */ /* make unwritable */ if(nowrite & 1) { ttystat->st_mode &= 495; chmod(ttyname(0), ttystat->st_mode); } while (1) { /* main loop, soon to be replaced */ while (read(0, &input, 1) == -1) /* wait for input */ ; sprintf(argv[1], "%7.7d", points); process_input(input); /* call to input processor */ SIGRELSE(14); /* this is an attempt to fix a rare bug. ignore it */ } } /* * Here's something you've all been waiting for: the AT&T public domain * source for getopt (3). It is the code which was given out at the 1985 * UNIFORUM conference in Dallas. I obtained it by electronic mail * directly from AT&T. The people there assure me that it is indeed * in the public domain. * * There is no manual page. That is because the one they gave out at * UNIFORUM was slightly different from the current System V Release 2 * manual page. The difference apparently involved a note about the * famous rules 5 and 6, recommending using white space between an option * and its first argument, and not grouping options that have arguments. * Getopt itself is currently lenient about both of these things. White * space is allowed, but not mandatory, and the last option in a group can * have an argument. That particular version of the man page evidently * has no official existence, and my source at AT&T did not send a copy. * The current SVR2 man page reflects the actual behavor of this getopt. * However, I am not about to post a copy of anything licensed by AT&T. */ /*LINTLIBRARY*/ #define NULL 0 #define EOF (-1) #define ERR(s, c) if (opterr){\ extern int write();\ char errbuf[2];\ errbuf[0] = c; errbuf[1] = '\n';\ (void) write (2, argv[0], (unsigned)strlen (argv[0]));\ (void) write (2, s, (unsigned)strlen (s));\ (void) write (2, errbuf, 2);} extern char *index(); int getopt(argc, argv, opts) int argc; char **argv, *opts; { static int sp = 1; register int c; register char *cp; if (sp == 1) if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0') return (EOF); else if (strcmp (argv[optind], "--") == NULL) { optind++; return (EOF); } optopt = c = argv[optind][sp]; if (c == ':' || (cp=index (opts, c)) == NULL) { ERR (": illegal option -- ", c); if (argv[optind][++sp] == '\0') { optind++; sp = 1; } return ('?'); } if (*++cp == ':') { if (argv[optind][sp+1] != '\0') optarg = &argv[optind++][sp+1]; else if (++optind >= argc) { ERR (": option requires an argument -- ", c); sp = 1; return ('?'); } else optarg = argv[optind++]; sp = 1; } else { if (argv[optind][++sp] == '\0') { sp = 1; optind++; } optarg = NULL; } return (c); }