/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ readboard() { if (lopen(scorefile)<0) { lprcat("Can't read scoreboard\n"); lflush(); return(-1); } lrfill((char*)sco,sizeof(sco)); lrfill((char*)winr,sizeof(winr)); lrclose(); lcreat((char*)0); return(0); }
/* * routine to open the help file and return the first character - '0' */ static int openhelp(void) { if (lopen(helpfile) < 0) { lprintf("Can't open help file \"%s\" ", helpfile); lflush(); sleep(4); drawscreen(); setscroll(); return (-1); } resetscroll(); return (lgetc() - '0'); }
/* * diedlog() Subroutine to read a log file and print it out in ascii format */ void diedlog (void) { int n; char *p; struct stat stbuf; lcreat ((char *) 0); if (lopen (logfile) < 0) { lprintf ("Can't locate log file <%s>\n", logfile); return; } if (fstat (fd, &stbuf) < 0) { lprintf ("Can't stat log file <%s>\n", logfile); return; } for (n = stbuf.st_size / sizeof (struct log_fmt); n > 0; --n) { lrfill ((char *) &logg, sizeof (struct log_fmt)); p = ctime ((time_t *) & logg.diedtime); p[16] = '\n'; p[17] = 0; lprintf ("Score: %d, Diff: %d, %s %s on %d at %s", (int) (logg.score), (int) (logg.diff), logg.who, logg.what, (int) (logg.cavelev), p + 4); #ifdef EXTRA if (logg.moves <= 0) logg.moves = 1; lprintf (" Experience Level: %d, AC: %d, HP: %d/%d, Elapsed Time: %d minutes\n", (int) (logg.lev), (int) (logg.ac), (int) (logg.hp), (int) (logg.hpmax), (int) (logg.elapsedtime)); lprintf (" BYTES in: %d, out: %d, moves: %d, deaths: %d, spells cast: %d\n", (int) (logg.bytin), (int) (logg.bytout), (int) (logg.moves), (int) (logg.killed), (int) (logg.spused)); lprintf (" out bytes per move: %d", (int) (logg.bytout / logg.moves)); lprintf ("\n"); #endif } lflush (); lrclose (); return; }
int getplid (char *nam) { int fd7, high = 999, no; char *p, *p2; char name[80]; if (havepid != -1) return (havepid); /* already did it */ lflush (); /* flush any pending I/O */ sprintf (name, "%s\n", nam); /* append a \n to name */ if (lopen (playerids) < 0) /* no file, make it */ { if ((fd7 = _creat (playerids, _S_IWRITE)) < 0) return (-1); /* can't make it */ _close (fd7); goto addone; /* now append new playerid record to file */ } for (;;) /* now search for the name in the player id file */ { p = lgetl (); if (p == NULL) break; /* EOF? */ no = atoi (p); /* the id # */ p2 = lgetl (); if (p2 == NULL) break; /* EOF? */ if (no > high) high = no; /* accumulate highest id # */ if (strcmp (p2, name) == 0) /* we found him */ { return (no); /* his id number */ } } lrclose (); /* if we get here, we didn't find him in the file -- put him there */ addone: if (lappend (playerids) < 0) return (-1); /* can't open file for append */ lprintf ("%d\n%s", (int) ++high, name); /* new id # and name */ lwclose (); lcreat ((char *) 0); /* re-open terminal channel */ return (high); }
/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ int readboard() { int i; setegid(egid); i = lopen(scorefile); setegid(gid); if (i < 0) { lprcat("Can't read scoreboard\n"); lflush(); return (-1); } lrfill((char *) sco, sizeof(sco)); lrfill((char *) winr, sizeof(winr)); lrclose(); lcreat((char *) 0); return (0); }
/* * readboard() Function to read in the scoreboard into a static buffer * * returns -1 if unable to read in the scoreboard, returns 0 if all is OK */ static int readboard (void) { if (lopen (scorefile) < 0) { lprcat ("Can't read scoreboard\n"); lflush (); return -1; } lrfill ((char *) sco, sizeof (sco)); lrfill ((char *) winr, sizeof (winr)); lrclose (); lcreat ((char *) 0); return 0; }
/* * diedlog() Subroutine to read a log file and print it out in ascii format */ void diedlog(void) { int n; char *p; static char q[] = "?"; struct stat stbuf; time_t t; lcreat((char *) 0); if (lopen(logfile) < 0) { lprintf("Can't locate log file <%s>\n", logfile); return; } if (fstat(io_infd, &stbuf) < 0) { lprintf("Can't stat log file <%s>\n", logfile); return; } for (n = stbuf.st_size / sizeof(struct log_fmt); n > 0; --n) { lrfill((char *) &logg, sizeof(struct log_fmt)); t = logg.diedtime; if ((p = ctime(&t)) == NULL) p = q; else { p[16] = '\n'; p[17] = 0; } lprintf("Score: %ld, Diff: %ld, %s %s on %ld at %s", (long) (logg.score), (long) (logg.diff), logg.who, logg.what, (long) (logg.cavelev), p + 4); #ifdef EXTRA if (logg.moves <= 0) logg.moves = 1; lprintf(" Experience Level: %ld, AC: %ld, HP: %ld/%ld, Elapsed Time: %ld minutes\n", (long) (logg.lev), (long) (logg.ac), (long) (logg.hp), (long) (logg.hpmax), (long) (logg.elapsedtime)); lprintf(" CPU time used: %ld seconds, Machine usage: %ld.%02ld%%\n", (long) (logg.cputime), (long) (logg.usage / 100), (long) (logg.usage % 100)); lprintf(" BYTES in: %ld, out: %ld, moves: %ld, deaths: %ld, spells cast: %ld\n", (long) (logg.bytin), (long) (logg.bytout), (long) (logg.moves), (long) (logg.killed), (long) (logg.spused)); lprintf(" out bytes per move: %ld, time per move: %ld ms\n", (long) (logg.bytout / logg.moves), (long) ((logg.cputime * 1000) / logg.moves)); #endif } lflush(); lrclose(); return; }
/* function to read and process the larn options file */ void readopts(void) { char *i; int j, k; int flag; flag = 1; /* set to 0 if a name is specified */ if (lopen(optsfile) < 0) { strcpy(logname, loginname); return; /* user name if no character name */ } do { if ((i = (char *)lgetw()) == 0) break; /* check for EOF */ while ((*i == ' ') || (*i == '\t')) i++; /* eat leading whitespace */ switch (*i) { case 'b': if (strcmp(i, "bold-objects") == 0) boldon = 1; break; case 'e': if (strcmp(i, "enable-checkpointing") == 0) ckpflag = 1; break; case 'i': if (strcmp(i, "inverse-objects") == 0) boldon = 0; break; case 'f': if (strcmp(i, "female") == 0) sex = 0; /* male or female */ break; case 'm': if (strcmp(i, "monster:") == 0) { /* name favorite monster */ if ((i = lgetw()) == 0) break; if (strlen(i) >= MAXMNAME) i[MAXMNAME - 1] = 0; strcpy(usermonster[(int)usermpoint], i); if (usermpoint >= MAXUM) break; /* defined all of em */ if (isalpha(j = usermonster[(int)usermpoint][0])) { for (k = 1; k < MAXMONST + 8; k++) /* find monster */ if (monstnamelist[k] == j) { monster[k].name = &usermonster[(int)usermpoint++][0]; break; } } } else if (strcmp(i, "male") == 0) sex = 1; break; case 'n': if (strcmp(i, "name:") == 0) { /* defining players name */ if ((i = lgetw()) == 0) break; if (strlen(i) >= LOGNAMESIZE) i[LOGNAMESIZE - 1] = 0; strcpy(logname, i); flag = 0; } else if (strcmp(i, "no-introduction") == 0) nowelcome = 1; else if (strcmp(i, "no-beep") == 0) nobeep = 1; break; case 'p': if (strcmp(i, "process-name:") == 0) { if ((i = lgetw()) == 0) break; if (strlen(i) >= PSNAMESIZE) i[PSNAMESIZE - 1] = 0; strcpy(psname, i); } else if (strcmp(i, "play-day-play") == 0) dayplay = 1; break; case 's': if (strcmp(i, "savefile:") == 0) { /* defining savefilename */ if ((i = lgetw()) == 0) break; strcpy(savefilename, i); flag = 0; } break; } } while (*i); if (flag) strcpy(logname, loginname); }
NODE *lopenupdate(NODE *arg) { return(lopen(arg,"a+")); }
NODE *lopenappend(NODE *arg) { return(lopen(arg,"a")); }
NODE *lopenwrite(NODE *arg) { return(lopen(arg,"w")); }
NODE *lopenread(NODE *arg) { return(lopen(arg,"r")); }