]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.7 1997/10/13 02:18:37 lukem Exp $ */
4 * setup.c - set up all files for Phantasia
10 /************************************************************************
12 / FUNCTION NAME: main()
14 / FUNCTION: setup files for Phantasia 3.3.2
16 / AUTHOR: E. A. Estes, 12/4/85
22 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
23 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
24 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
26 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
28 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
32 / This program tries to verify the parameters specified in
35 / Create all necessary files. Note that nothing needs to be
37 / Also, the monster binary data base is created here.
39 /************************************************************************/
41 static char *files
[] = { /* all files to create */
53 char *monsterfile
="monsters.asc";
60 register char **filename
; /* for pointing to file names */
61 register int fd
; /* file descriptor */
62 FILE *fp
; /* for opening files */
63 struct stat fbuf
; /* for getting files statistics */
65 char path
[MAXPATHLEN
], *prefix
;
67 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
79 srandom((unsigned) time(NULL
)); /* prime random numbers */
81 umask(0117); /* only owner can read/write created files */
83 prefix
= getenv("DESTDIR");
85 /* try to create data files */
87 while (*filename
!= NULL
)
88 /* create each file */
90 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", *filename
);
91 if (stat(path
, &fbuf
) == 0)
92 /* file exists; remove it */
94 if (!strcmp(*filename
, _PATH_PEOPLE
))
95 /* do not reset character file if it already exists */
101 if (unlink(path
) < 0)
102 Error("Cannot unlink %s.\n", path
);
106 if ((fd
= creat(path
, 0660)) < 0)
107 Error("Cannot create %s.\n", path
);
110 close(fd
); /* close newly created file */
112 ++filename
; /* process next file */
115 /* put holy grail info into energy void file */
116 Enrgyvoid
.ev_active
= TRUE
;
117 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
118 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
119 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_VOID
);
120 if ((fp
= fopen(path
, "w")) == NULL
)
121 Error("Cannot update %s.\n", path
);
124 fwrite(&Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
128 /* create binary monster data base */
129 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MONST
);
130 if ((Monstfp
= fopen(path
, "w")) == NULL
)
131 Error("Cannot update %s.\n", path
);
134 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
137 Error("cannot open %s to create monster database.\n", "monsters.asc");
141 Curmonster
.m_o_strength
=
142 Curmonster
.m_o_speed
=
143 Curmonster
.m_maxspeed
=
144 Curmonster
.m_o_energy
=
146 Curmonster
.m_skirmish
= 0.0;
148 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
149 /* read in text file, convert to binary */
151 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
152 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
153 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
154 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
155 &Curmonster
.m_type
, &Curmonster
.m_flock
);
157 strcpy(Curmonster
.m_name
, Databuf
);
158 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
165 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
166 /* write to motd file */
167 printf("One line 'motd' ? ");
168 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
170 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MOTD
);
171 if ((fp
= fopen(path
, "w")) == NULL
)
172 Error("Cannot update %s.\n", path
);
175 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
179 /* report compile-time options */
180 printf("Compiled options:\n\n");
181 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
182 printf("Wizard: root UID: 0\n");
185 printf("Compiled for BSD 4.1\n");
189 printf("Compiled for BSD 4.2\n");
193 printf("Compiled for System III\n");
197 printf("Compiled for System V\n");
205 /************************************************************************
207 / FUNCTION NAME: Error()
209 / FUNCTION: print an error message, and exit
211 / AUTHOR: E. A. Estes, 12/4/85
214 / char *str - format string for printf()
215 / char *file - file which caused error
219 / MODULES CALLED: exit(), perror(), fprintf()
221 / GLOBAL INPUTS: _iob[]
223 / GLOBAL OUTPUTS: none
226 / Print an error message, then exit.
228 /************************************************************************/
233 fprintf(stderr
, "Error: ");
234 fprintf(stderr
, str
, file
);
240 /************************************************************************
242 / FUNCTION NAME: drandom()
244 / FUNCTION: return a random number
246 / AUTHOR: E. A. Estes, 2/7/86
252 / MODULES CALLED: random()
254 / GLOBAL INPUTS: none
256 / GLOBAL OUTPUTS: none
260 /************************************************************************/
265 if (sizeof(int) != 2)
266 return((double) (random() & 0x7fff) / 32768.0);
268 return((double) random() / 32768.0);