-+-+-+-+-+-+-+-+ START OF PART 22 -+-+-+-+-+-+-+-+ Xint rmst=80; /* random monster creation counter */ Xint userid; /* the players login user id number */ Xchar nowelcome=0,nomove=0; /* if (nomove) then don't count next iteration as V a X move */ Xstatic char viewflag=0; /* if viewflag then we have done a 99 stay here X and don't showcell in the main loop */ Xchar restorflag=0; /* 1 means restore has been done */ Xchar prompt_mode = 0; /* 1 if prompting for actions */ X X#ifdef MSDOS X Xstatic char cmdhelp`5B`5D = "\ XCmd line format: larn `5B-slicnhp`5D `5B-o`5D `5B-##`5D `5B++`5D\n V\ X -s show the scoreboard\n\ X -l show the logfile (wizard id only)\n\ X -i show scoreboard with inventories of dead characters\n\ X -c create new scoreboard (wizard id only)\n\ X -n suppress welcome message on starting game\n\ X -## specify level of difficulty (example: -5)\n\ X -h print this help text\n\ X -p prompt for actions on objects\n\ X ++ restore game from checkpoint file\n\ X -o specify larnopts filename to be used instead of \"larn.opt\ V"\n\ X"; X X# else X Xstatic char cmdhelp`5B`5D = "\ XCmd line format: larn `5B-slicnhp`5D `5B-o`5D `5B-##`5D `5B++`5D\n V\ X -s show the scoreboard\n\ X -l show the logfile (wizard id only)\n\ X -i show scoreboard with inventories of dead characters\n\ X -c create new scoreboard (wizard id only)\n\ X -n suppress welcome message on starting game\n\ X -## specify level of difficulty (example: -5)\n\ X -h print this help text\n\ X -p prompt for actions on objects\n\ X ++ restore game from checkpoint file\n\ X -o specify .larnopts filename to be used instead of \"`7E/.lar Vnopts\"\n\ X"; X X# endif X X#ifdef MSDOS Xint save_mode = 0; /* 1 if doing a save game */ Xjmp_buf save_jbuf; /* To recover from disk full errors */ X#endif X X#ifdef VT100 Xstatic char *termtypes`5B`5D = `7B "vt100", "vt101", "vt102", "vt103", "vt12 V5", X "vt131", "vt140", "vt180", "vt220", "vt240", "vt241", "vt320", "vt340", X "vt341" `7D; X#endif X X#ifdef VMS X# define EXIT_FAILURE X# define EXIT_SUCCESS 1 X#else X# define EXIT_FAILURE 1 X# define EXIT_SUCCESS 0 X#endif X X/* X ************ X MAIN PROGRAM X ************ X*/ Xmain(argc,argv) X int argc; X char **argv; X `7B X register int i,j; X int hard = -1; X char *ptr=0; X#ifdef VT100 X char *ttype; X#endif X#ifndef MSDOS X struct passwd *pwe,*getpwuid(); X#endif X X/* X * first task is to identify the player X */ X#ifndef VT100 X init_term(); /* setup the terminal (find out what type) for termcap * V/ X#endif X#ifdef MSDOS X ptr = "PLAYER"; X#else X#ifdef VMS X ptr = getenv("USER"); X#else X if (((ptr = getlogin()) == 0) `7C`7C (*ptr==0)) /* try to get login name V */ X if (pwe=getpwuid(getuid())) /* can we get it from /etc/passwd? */ X ptr = pwe->pw_name; X else X if ((ptr = getenv("USER")) == 0) X if ((ptr = getenv("LOGNAME")) == 0) X `7B X noone: write(2, "Can't find your logname. Who Are You?\n",39); X exit(); X `7D X if (ptr==0) goto noone; X if (strlen(ptr)==0) goto noone; X#endif X#endif X X/* X * second task is to prepare the pathnames the player will need X */ X strcpy(loginname,ptr); /* save loginname of the user for logging purpose Vs */ X strcpy(logname,ptr); /* this will be overwritten with the players nam Ve */ X X/* Set up the input and output buffers. X */ X lpbuf = (char *)malloc((5* BUFBIG)>>2); /* output buffer */ X inbuffer = (char *)malloc((5*MAXIBUF)>>2); /* output buffer */ X if ((lpbuf==0) `7C`7C (inbuffer==0))`20 X died(-285); /* malloc() failure */ X X# ifdef MSDOS X /* LARNHOME now comes from the options file, so it must be read in X * before constructing the other file names. Unfortunately we have X * to look for the -o option now. X */ X strcpy(optsfile, LARNOPTS); X for (i = 1; i < argc; i++) X if (strncmp(argv`5Bi`5D, "-o", 2) == 0)`20 X `7B X argv`5Bi`5D`5B0`5D = 0; /* remove this argv */ X if (argv`5Bi`5D`5B2`5D != '\0') X strncpy(optsfile, &argv`5Bi`5D`5B2`5D, PATHLEN); X else X `7B X strncpy(optsfile, argv`5Bi + 1`5D, PATHLEN); X argv`5Bi + 1`5D`5B0`5D = 0; /* and this argv */ X `7D X optsfile`5BPATHLEN - 1`5D = 0; X break; X `7D X readopts(); X append_slash(larndir); X X /* Savefile and swapfile can be given explicitly as options X */ X if (!savefilename`5B0`5D) X `7B X strcpy(savefilename, larndir); X strcat(savefilename, SAVEFILE); X `7D X if (!swapfile`5B0`5D) X `7B X strcpy(swapfile, larndir); X strcat(swapfile, SWAPFILE); X `7D X strcpy(scorefile, larndir); X strcpy(logfile, larndir); X strcpy(helpfile, larndir); X strcpy(larnlevels, larndir); X strcpy(fortfile, larndir); X strcpy(playerids, larndir); X strcpy(ckpfile, larndir); X# ifdef EXTRA X strcpy(diagfile,larndir); X# endif X X# else /* MSDOS */ X X if ((ptr = getenv("HOME")) == 0) X ptr = "."; X#ifdef SAVEINHOME X /* save file name in home directory */ X# ifdef VMS X sprintf(savefilename, "%s%s",ptr, SAVEFILE); X# else X sprintf(savefilename, "%s/%s",ptr, SAVEFILE); X# endif VMS X#else X strcat(savefilename,logname); /* prepare savefile name */ X strcat(savefilename,".sav"); /* prepare savefile name */ X#endif X#ifdef VMS X sprintf(optsfile, "%s%s",ptr, LARNOPTS); /* the options filename */ X#else X sprintf(optsfile, "%s/%s",ptr, LARNOPTS); /* the options filename */ X#endif VMS X X# endif /* MSDOS */ X X strcat(scorefile, SCORENAME); /* the larn scoreboard filename */ X strcat(logfile, LOGFNAME); /* larn activity logging filename */ X strcat(helpfile, HELPNAME); /* the larn on-line help file */ X strcat(larnlevels, LEVELSNAME); /* the pre-made cave level data file */ X strcat(fortfile, FORTSNAME); /* the fortune data file name */ X strcat(playerids, PLAYERIDS); /* the playerid data file name */ X strcat(ckpfile, CKPFILE); X X# ifdef TIMECHECK X strcat(holifile, HOLIFILE); /* the holiday data file name */ X# endif X X# ifdef EXTRA X strcat(diagfile, DIAGFILE); X# endif X X#ifdef VT100 X/* X * check terminal type to avoid users who have not vt100 type terminals X */ X ttype = getenv("TERM"); X for (j=1, i=0; i\n",argv`5Bi`5D); X write(1,cmdhelp,sizeof(cmdhelp)); X exit(EXIT_SUCCESS); X `7D; X X if (strcmp(argv`5Bi`5D, "++") == 0) X restorflag = 1; X `7D X X#ifndef MSDOS X readopts(); /* read the options file if there is one */ X#endif X X#ifdef TIMECHECK X/* X * this section of code checks to see if larn is allowed during working hou Vrs X */ X if (dayplay==0) /* check for not-during-daytime-hours */ X if (playable()) X `7B X write(2,"Sorry, Larn can not be played during working hours.\n",52); X exit(EXIT_SUCCESS); X `7D X#endif TIMECHECK X X#ifdef UIDSCORE X userid = geteuid(); /* obtain the user's effective id number */ X#else UIDSCORE X userid = getplid(logname); /* obtain the players id number */ X#endif UIDSCORE X#ifdef VMS X wisid = userid; X#endif VMS X if (userid < 0)`20 X `7B`20 X write(2,"Can't obtain playerid\n",22); X if (userid==-2) printf("Error appending to file\n"); X exit(EXIT_SUCCESS); X `7D X X#ifdef HIDEBYLINK X/* X * this section of code causes the program to look like something else to p Vs X */ X if (strcmp(psname,argv`5B0`5D)) /* if a different process name only */ X `7B X if ((i=access(psname,1)) < 0) X `7B /* link not there */ X if (link(argv`5B0`5D,psname)>=0) X `7B X argv`5B0`5D = psname; execv(psname,argv); X `7D X `7D X else X unlink(psname); X `7D X X for (i=1; i