|
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: 5156 (0x1424) Types: TextFile Names: »main.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/General/Dots/main.c«
/* MAIN.C */ #include "dots.h" char *error_msg[] = { "usages:\n", "%s -s gives top scores.\n", "%s -d reads the directions\n", "%s -r [file] restart saved game (from file if given).\n", "%s L W D [C] plays a game using integer arguments as\n", " Length, Width and Difficulty levels, respectively.\n", " 'C' is inital for boxes.\n", "%s 2 user [tty] send request/reply to play someone else (2-user).\n", "\nsetenv DOTSOPTS \"name=whoareyou,savefile=path,initial=X,prize=whatever\"\n", 0 }; char *getusername(); bus_n_seg(sig) { if (sig == SIGBUS) fprintf(stderr, "Bus error.\n"); else fprintf(stderr, "Segmentation Fault.\n"); die(); } main(argc, argv) int argc; char **argv; { register char *p; extern char *UP; setbuf(stdout, (char *)NULL); setbuf(stderr, (char *)NULL); username = getusername(); savetty(); initscr(); (void) signal(SIGBUS, bus_n_seg); (void) signal(SIGSEGV, bus_n_seg); (void) signal(SIGINT, onintr); (void) signal(SIGPIPE, onintr); (void) signal(SIGCHLD, SIG_IGN); /* to return from shell esc */ (void) signal(SIGQUIT, redraw); if (argc > 1 && argv[1][0] == '-' && argv[1][1] != 'r') if (argv[1][1] == 'd') readinst(1), exit(0); else if (argv[1][1] == 's') high_score(TRUE, FALSE), die(); else if (argv[1][1] == 'x') high_score(TRUE, TRUE), die(); else do_error(argv[0]), die(); if (COLS < 4 * H_MINL || LINES < 2 * H_MINW) { printf("Window must be at least %d by %d.\n", 4 * H_MINL, 2 * H_MINW); die(); } if (!*UP) { printf("You need cursor movement capability on your terminal.\n"); die(); } srandom(getpid()); mover = US, Initial[THEM] = '$'; getopts(); noecho(), crmode(); if (argc > 1) parse_command(argc, argv); else menu(); } do_error(arg) char *arg; { int count = 0; while (error_msg[count]) fprintf(stderr, error_msg[count++], arg); die(); } Dots(which) /* which? recovered game, start from command line, or menu */ int which; /* 0 = start from beginning, 1 = recovered game */ { Upper(Initial[US]); Lower(Initial[THEM]); if (mode == TWOPLAYER) { mvprintw(LINES-5,0, "Your label is '%c' and %s's is '%c'.", Initial[US], opponent, Initial[THEM]); mvprintw(LINES-4,0, "%s will go first.", (mover==US)? "You" : opponent); mvaddstr(LINES-3,0, "^Z stops game for you only. \"fg\" resumes game."); mvaddstr(LINES-2,0, "ESC to talk to other player. ^L to redraw board."); msg("--hit any key to continue-- "); getchar(); set_redraw_signal_key_to('\014'); /* change to ^L */ free_board(); } if (!which) /* could be a restart of a saved game or a new game */ setup(), free_board(); drawboard(); while (!board_is_full()) if (mode != DEMO && (mode == TWOPLAYER || mover == US)) mover = (personmove()) ? mover : !mover; /* switch if we got some */ else if (mode != TWOPLAYER && (mode == DEMO || mover == THEM)) if (!board_is_full()) compmove(), mover = !mover; end_of_game(); } getopts() { char *p, *opts, temp[BUFSIZ], *length, *index(); (void) strcpy(prize, PRIZE); (void) strcpy(save_file, SAVE_FILE); if (opts = getenv("DOTSOPTS")) { length = opts + strlen(opts); while (opts < length) { (void) sscanf(opts, "%[^,]", temp); if (p = index(temp, '=')) if (!strncmp(temp, "name", 4)) username = ++p; else if (!(strncmp(temp, "savefile", 8))) (void) strcpy(save_file, ++p); else if (!(strncmp(temp, "prize", 5))) (void) strcpy(prize, ++p); else if (!(strncmp(temp, "initial", 7))) Initial[US] = *++p; opts += 1 + strlen(temp); } } if (!Initial[US]) Initial[US] = *username; } parse_command(argc, argv) int argc; char **argv; { if (!strcmp(argv[1], "2")) { if (argc < 3) printf(error_msg, argv[0]); else mode = TWOPLAYER, sockit(argc, argv); die(); } mode = INTERACTIVE; if (!strcmp(argv[1], "-r")) { if (argc == 3) (void) strcpy(save_file, argv[2]); if (recover(1)) Dots(1); else die(); menu(); } if (argc < 4) do_error(argv[0]); if ((level = atoi(argv[3])) < DUMB || level > KILLER) { printf("%s: Invalid Difficulty Level (0,1, or 2)\n", argv[0]); die(); } if ((Length = atoi(argv[1])) > MAXL || Length < (level? H_MINL : MINL)) { printf("%s: (%d) Invalid Length.\n", argv[0], Length); die(); } if ((Width = atoi(argv[2])) > MAXW || Width < (level? H_MINW : MINW)) { printf("%s: (%d) Invalid Width.\n", argv[0], Width); die(); } if (argc > 4) Initial[US] = *argv[4]; comptally = persontally = 0; xposit = 2, yposit = 1; y_start = 1 + LINES / 2 - Width; x_start = 1 + COLS / 2 - Length * 2; Dots(2); } #include <pwd.h> char * getusername() { struct passwd *entry; extern char *getlogin(); register char *p; if ((p = getenv("NAME")) || (p = getenv("SIGNATURE")) || (p = getenv("USER")) || (p = getlogin())) return p; if (!(entry = getpwuid(getuid()))) puts("Who the hell are you?"), die(); endpwent(); return entry->pw_name; }