]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.8 1997/11/24 01:47:26 mrg 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 (!strcmp(*filename
, _PATH_SCORE
))
102 /* do not reset score file if it already exists */
108 if (unlink(path
) < 0)
109 Error("Cannot unlink %s.\n", path
);
113 if ((fd
= creat(path
, 0660)) < 0)
114 Error("Cannot create %s.\n", path
);
117 close(fd
); /* close newly created file */
119 ++filename
; /* process next file */
122 /* put holy grail info into energy void file */
123 Enrgyvoid
.ev_active
= TRUE
;
124 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
125 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
126 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_VOID
);
127 if ((fp
= fopen(path
, "w")) == NULL
)
128 Error("Cannot update %s.\n", path
);
131 fwrite(&Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
135 /* create binary monster data base */
136 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MONST
);
137 if ((Monstfp
= fopen(path
, "w")) == NULL
)
138 Error("Cannot update %s.\n", path
);
141 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
144 Error("cannot open %s to create monster database.\n", "monsters.asc");
148 Curmonster
.m_o_strength
=
149 Curmonster
.m_o_speed
=
150 Curmonster
.m_maxspeed
=
151 Curmonster
.m_o_energy
=
153 Curmonster
.m_skirmish
= 0.0;
155 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
156 /* read in text file, convert to binary */
158 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
159 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
160 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
161 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
162 &Curmonster
.m_type
, &Curmonster
.m_flock
);
164 strcpy(Curmonster
.m_name
, Databuf
);
165 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
172 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
173 /* write to motd file */
174 printf("One line 'motd' ? ");
175 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
177 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MOTD
);
178 if ((fp
= fopen(path
, "w")) == NULL
)
179 Error("Cannot update %s.\n", path
);
182 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
186 /* report compile-time options */
187 printf("Compiled options:\n\n");
188 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
189 printf("Wizard: root UID: 0\n");
192 printf("Compiled for BSD 4.1\n");
196 printf("Compiled for BSD 4.2\n");
200 printf("Compiled for System III\n");
204 printf("Compiled for System V\n");
212 /************************************************************************
214 / FUNCTION NAME: Error()
216 / FUNCTION: print an error message, and exit
218 / AUTHOR: E. A. Estes, 12/4/85
221 / char *str - format string for printf()
222 / char *file - file which caused error
226 / MODULES CALLED: exit(), perror(), fprintf()
228 / GLOBAL INPUTS: _iob[]
230 / GLOBAL OUTPUTS: none
233 / Print an error message, then exit.
235 /************************************************************************/
240 fprintf(stderr
, "Error: ");
241 fprintf(stderr
, str
, file
);
247 /************************************************************************
249 / FUNCTION NAME: drandom()
251 / FUNCTION: return a random number
253 / AUTHOR: E. A. Estes, 2/7/86
259 / MODULES CALLED: random()
261 / GLOBAL INPUTS: none
263 / GLOBAL OUTPUTS: none
267 /************************************************************************/
272 if (sizeof(int) != 2)
273 return((double) (random() & 0x7fff) / 32768.0);
275 return((double) random() / 32768.0);