|
|
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: 4094 (0xffe)
Types: TextFile
Names: »menu.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/General/Dots/menu.c«
/* MENU.C */
#include "dots.h"
#include <utmp.h>
#include <sys/stat.h>
#define ever (;;)
menu()
{
int c, command = 1;
jmpbuf_set = 1;
(void) setjmp(menu_jmp);
disp_menu();
for ever {
while ((c = getchar()) != '\n')
if (c > '0' && c < '9')
putchar(c), putchar('\b'), command = c;
switch (command - '0') {
case 1: readinst(0), disp_menu();
when 2: level = DUMB, mode = INTERACTIVE, Dots(0);
when 3: level = HARD, mode = INTERACTIVE, Dots(0);
when 4: level = KILLER, mode = INTERACTIVE, Dots(0);
when 5: level = DUMB, mode = DEMO, Dots(0);
when 6: if (recover(0)) Dots(1);
when 7: challenge();
when 8: goodbye(1);
}
}
}
disp_menu()
{
int partition = LINES / 10, lines;
clear();
mvaddstr((lines = partition + LINES - 10 * partition), COLS / 2 - 10, ". . . D O T S . . .");
mvaddstr((lines += partition), COLS / 6, "1. Read instructions.");
mvaddstr((lines += partition), COLS / 6, "2. Easy game.");
mvaddstr((lines += partition), COLS / 6, "3. Hard game.");
mvaddstr((lines += partition), COLS / 6, "4. Killer game.");
mvaddstr((lines = partition + LINES - 9 * partition), 4 * COLS / 6, "5. Demo game.");
mvaddstr((lines += partition), 4 * COLS / 6, "6. Recover saved game.");
mvaddstr((lines += partition), 4 * COLS / 6, "7. Play someone else.");
mvaddstr((lines += partition), 4 * COLS / 6, "8. Leave game.");
mvaddstr((lines += partition), COLS / 2 - 9, "Enter command. [ ]\b\b");
refresh();
}
readinst(before)
bool before; /* before or after curses mode has been set */
{
int c, line_count = 0;
FILE *fp2;
if (!before)
clear(), refresh();
else
noecho(), crmode();
if ((fp2 = fopen(DOCFILE, "r")) == NULL)
perror(DOCFILE);
else {
while ((c = getc(fp2)) != EOF) {
putchar(c);
if (c == '\n')
line_count++;
if (line_count == LINES - 1) {
printf("--more--(or 'q' to return)");
if (getchar() == 'q') {
fclose(fp2);
if (before)
echo(), nocrmode();
return;
}
printf("\015 \015");
line_count = 0;
}
}
fclose(fp2);
}
if (!before) {
printf("Hit return to continue [ ]\b\b");
while (getchar() != '\n');
} else
echo(), nocrmode();
}
writable(line)
char *line;
{
char ttyno[20];
sprintf(ttyno, "/dev/%s", line);
return !access(ttyno, 02);
}
challenge()
{
struct utmp buf;
int count = 0, col = LINES / 3, l_len = 0;
char *p, *index(), *victim[4], string[20], *ttyname(), *tty = ttyname(0)+5;
FILE *file;
victim[0] = "Dots";
victim[1] = "2";
clear();
mvaddstr(col, 0, "Here are your potential opponents: ");
move(++col, 0);
if ((file = fopen("/etc/utmp", "r")) == NULL) {
disp_menu();
msg("/etc/utmp: %s", sys_errlist[errno]);
return;
}
while (fread((char *)&buf, sizeof(struct utmp), 1, file) > 0)
if (buf.ut_name[0] && writable(buf.ut_line)) {
if (!strncmp(buf.ut_name, username, 8) && !strcmp(buf.ut_line, tty))
continue;
if (count++)
addstr(", ");
if ((l_len + 10 + min(strlen(buf.ut_name), 8)) > COLS - 1)
clrtoeol(), move(++col, 0), l_len = 0;
l_len += 10 + min(strlen(buf.ut_name), 8);
printw("%-.8s (%s)", buf.ut_name, buf.ut_line);
}
(void) fclose(file);
if (!count) {
disp_menu();
msg("There doesn't seem to be anyone who can play.");
return;
}
mvaddstr(col += 2, 0, "RETURN for menu.");
mvaddstr(++col, 0, "Whom would you like to play (user [ttyxx])? ");
refresh();
count = 2;
Getstr(string, min(20, COLS - 1));
if (string[0] == NULL) {
disp_menu();
return;
}
move(++col, 0);
refresh();
victim[count++] = string;
if ((p = index(string, ' ')) != NULL) {
*(p++) = '\0';
victim[count - 1] = string;
victim[count++] = p;
}
mode = TWOPLAYER;
sockit(count, victim); /* shouldn't return. If so, there was an error */
mode = DEMO;
putchar('\n'); /* don't overwrite any error messages */
msg("Hit any key to continue.");
getchar();
disp_menu();
}