1: /*
   2:  * setfiles.c	Program to set up all files for Phantasia
   3:  *
   4:  *		This program tries to verify the parameters specified in
   5:  *		the Makefile.  Since Phantasia assumes its files exist,
   6:  *		simple errors can result in core dumps.
   7:  *
   8:  *		This program tries to check against this.
   9:  */
  10: 
  11: #include "phant.h"
  12: #include <sys/types.h>
  13: #include <sys/stat.h>
  14: 
  15: main(argc,argv)                 /* program to init. files for Phantasia */
  16: int argc;
  17: char    **argv;
  18: {
  19: FILE    *fp;
  20: struct  stats   sbuf;
  21: struct  nrgvoid grail;
  22: struct  stat    fbuf;
  23: register    int loop;
  24: int foo;
  25: char    stbuf[128];
  26: 
  27: #ifdef notdef
  28:     srand((int) time(NULL));    /* prime random numbers */
  29:     /* try to check RAND definition */
  30:     for (loop = 1000; loop; loop--)
  31:         {
  32:         if ((foo = rand()) > ((int) RAND))
  33:             {
  34:             sprintf(stbuf,"%f %f",(double) RAND, (double) foo);
  35:             Error("%s is a bad value for RAND.\n",stbuf);
  36:             }
  37:         }
  38: #endif
  39:     umask(077);
  40:     /* check where Phantasia lives */
  41:     if (stat(PATH",&fbuf) < 0)
  42:         {
  43:         perror(PATH");
  44:         exit(1);
  45:         /*NOTREACHED*/
  46:         }
  47:     if (fbuf.st_mode & S_IFDIR == 0)
  48:         Error("%s is not a directory.\n",PATH");
  49:     /* try to create data files */
  50:     if ((fp = fopen(goldfile,"w")) == NULL)
  51:         Error("cannot create %s.\n",goldfile);
  52:     else
  53:         fclose(fp);
  54:     if ((fp = fopen(motd,"w")) == NULL)
  55:         Error("cannot create %s.\n",motd);
  56:     else
  57:         fclose(fp);
  58:     if ((fp = fopen(messfile,"w")) == NULL)
  59:         Error("cannot create %s.\n",messfile);
  60:     else
  61:         fclose(fp);
  62:     /* do not reset character file if it already exists */
  63:     if (stat(peoplefile,&fbuf) < 0)
  64:         {
  65:         buildchar(&sbuf);
  66:         strcpy(sbuf.name,"<null>");
  67:         if ((fp = fopen(peoplefile,"w")) == NULL)
  68:             Error("cannot create %s.\n",peoplefile);
  69:         else
  70:             {
  71:             fwrite(&sbuf,sizeof(sbuf),1,fp);
  72:             fclose(fp);
  73:             }
  74:         }
  75:     grail.active = TRUE;
  76:     grail.x = roll(-1.0e6,2.0e6);
  77:     grail.y = roll(-1.0e6,2.0e6);
  78:     if ((fp = fopen(voidfile,"w")) == NULL)
  79:         Error("cannot create %s.\n",voidfile);
  80:     else
  81:         {
  82:         fwrite(&grail,sizeof(grail),1,fp);
  83:         fclose(fp);
  84:         }
  85:     if ((fp = fopen(lastdead,"w")) == NULL)
  86:         Error("cannot create %s.\n",lastdead);
  87:     else
  88:         {
  89:         fputs(" ",fp);
  90:         fclose(fp);
  91:         }
  92: #ifdef ENEMY
  93:     if ((fp = fopen(enemyfile,"w")) == NULL)
  94:         Error("cannot create %s.\n",enemyfile);
  95:     else
  96:         {
  97:         /* comment this out for now
  98: 		fprintf(fp,"# Use this file to restrict access from obnoxious users.\n");
  99: 		fprintf(fp,"# Just put the login names of those restricted, one per\n");
 100: 		fprintf(fp,"# line, below.\n");
 101: 		*/
 102:         fclose(fp);
 103:         }
 104: #endif
 105:     if (getuid() != UID)
 106:         fprintf(stderr,"Warning: UID (%d) is not equal to current uid.\n",UID);
 107: }
 108: 
 109: buildchar(stat)             /* put in some default values */
 110: /* Note that this function is almost the same as initchar().
 111:    It is used to insure that unexpected values will not be found in a
 112:    new character file.							*/
 113: struct  stats   *stat;
 114: {
 115:     stat->x = roll(-125,251);
 116:     stat->y = roll(-125,251);
 117:     stat->exp = stat->lvl = stat->sin = 0;
 118:     stat->crn = stat->psn = 0;
 119:     stat->rng.type = NONE;
 120:     stat->rng.duration = 0;
 121:     stat->pal = FALSE;
 122:     stat->hw = stat->amu = stat->bls = 0;
 123:     stat->chm = 0;
 124:     stat->gem = 0.1;
 125:     stat->gld = roll(25,50) + roll(0,25) + 0.1;
 126:     stat->quks = stat->swd = stat->shd = 0;
 127:     stat->vrg = FALSE;
 128:     stat->typ = 0;
 129: }
 130: 
 131: Error(str,file)     /* print an error message, and exit */
 132: char    *str, *file;
 133: {
 134:     fprintf(stderr,"Error: ");
 135:     fprintf(stderr,str,file);
 136:     exit(1);
 137:     /*NOTREACHED*/
 138: }

Defined functions

Error defined in line 131; used 9 times
buildchar defined in line 109; used 1 times
  • in line 65
main defined in line 15; never used
Last modified: 1986-05-20
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1378
Valid CSS Valid XHTML 1.0 Strict