]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - phantasia/setup.c
1 /* $NetBSD: setup.c,v 1.6 1997/10/12 14:19:17 lukem Exp $ */
4 * setup.c - set up all files for Phantasia
12 /************************************************************************
14 / FUNCTION NAME: main()
16 / FUNCTION: setup files for Phantasia 3.3.2
18 / AUTHOR: E. A. Estes, 12/4/85
24 / MODULES CALLED: time(), exit(), stat(), Error(), creat(), close(), fopen(),
25 / fgets(), floor(), srandom(), umask(), drandom(), strcpy(), getuid(),
26 / unlink(), fwrite(), fclose(), sscanf(), printf(), strlen(), fprintf()
28 / GLOBAL INPUTS: Curmonster, _iob[], Databuf[], *Monstfp, Enrgyvoid
30 / GLOBAL OUTPUTS: Curmonster, Databuf[], *Monstfp, Enrgyvoid
34 / This program tries to verify the parameters specified in
37 / Create all necessary files. Note that nothing needs to be
39 / Also, the monster binary data base is created here.
41 /************************************************************************/
43 static char *files
[] = { /* all files to create */
55 char *monsterfile
="monsters.asc";
62 register char **filename
; /* for pointing to file names */
63 register int fd
; /* file descriptor */
64 FILE *fp
; /* for opening files */
65 struct stat fbuf
; /* for getting files statistics */
67 char path
[MAXPATHLEN
], *prefix
;
69 while ((ch
= getopt(argc
, argv
, "m:")) != -1)
81 srandom((unsigned) time(NULL
)); /* prime random numbers */
83 umask(0117); /* only owner can read/write created files */
85 prefix
= getenv("DESTDIR");
87 /* try to create data files */
89 while (*filename
!= NULL
)
90 /* create each file */
92 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", *filename
);
93 if (stat(path
, &fbuf
) == 0)
94 /* file exists; remove it */
96 if (!strcmp(*filename
, _PATH_PEOPLE
))
97 /* do not reset character file if it already exists */
103 if (unlink(path
) < 0)
104 Error("Cannot unlink %s.\n", path
);
108 if ((fd
= creat(path
, 0660)) < 0)
109 Error("Cannot create %s.\n", path
);
112 close(fd
); /* close newly created file */
114 ++filename
; /* process next file */
117 /* put holy grail info into energy void file */
118 Enrgyvoid
.ev_active
= TRUE
;
119 Enrgyvoid
.ev_x
= ROLL(-1.0e6
, 2.0e6
);
120 Enrgyvoid
.ev_y
= ROLL(-1.0e6
, 2.0e6
);
121 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_VOID
);
122 if ((fp
= fopen(path
, "w")) == NULL
)
123 Error("Cannot update %s.\n", path
);
126 fwrite(&Enrgyvoid
, SZ_VOIDSTRUCT
, 1, fp
);
130 /* create binary monster data base */
131 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MONST
);
132 if ((Monstfp
= fopen(path
, "w")) == NULL
)
133 Error("Cannot update %s.\n", path
);
136 if ((fp
= fopen(monsterfile
, "r")) == NULL
)
139 Error("cannot open %s to create monster database.\n", "monsters.asc");
143 Curmonster
.m_o_strength
=
144 Curmonster
.m_o_speed
=
145 Curmonster
.m_maxspeed
=
146 Curmonster
.m_o_energy
=
148 Curmonster
.m_skirmish
= 0.0;
150 while (fgets(Databuf
, SZ_DATABUF
, fp
) != NULL
)
151 /* read in text file, convert to binary */
153 sscanf(&Databuf
[24], "%lf%lf%lf%lf%lf%d%d%lf",
154 &Curmonster
.m_strength
, &Curmonster
.m_brains
,
155 &Curmonster
.m_speed
, &Curmonster
.m_energy
,
156 &Curmonster
.m_experience
, &Curmonster
.m_treasuretype
,
157 &Curmonster
.m_type
, &Curmonster
.m_flock
);
159 strcpy(Curmonster
.m_name
, Databuf
);
160 fwrite((char *) &Curmonster
, SZ_MONSTERSTRUCT
, 1, Monstfp
);
167 #ifdef MAKE_INSTALLS_THIS_AND_DOESNT_WANT_TO_HEAR_ABOUT_IT
168 /* write to motd file */
169 printf("One line 'motd' ? ");
170 if (fgets(Databuf
, SZ_DATABUF
, stdin
) == NULL
)
172 snprintf(path
, sizeof(path
), "%s%s", prefix
?prefix
:"", _PATH_MOTD
);
173 if ((fp
= fopen(path
, "w")) == NULL
)
174 Error("Cannot update %s.\n", path
);
177 fwrite(Databuf
, sizeof(char), strlen(Databuf
), fp
);
181 /* report compile-time options */
182 printf("Compiled options:\n\n");
183 printf("Phantasia destination directory: %s\n", _PATH_PHANTDIR
);
184 printf("Wizard: root UID: 0\n");
187 printf("Compiled for BSD 4.1\n");
191 printf("Compiled for BSD 4.2\n");
195 printf("Compiled for System III\n");
199 printf("Compiled for System V\n");
207 /************************************************************************
209 / FUNCTION NAME: Error()
211 / FUNCTION: print an error message, and exit
213 / AUTHOR: E. A. Estes, 12/4/85
216 / char *str - format string for printf()
217 / char *file - file which caused error
221 / MODULES CALLED: exit(), perror(), fprintf()
223 / GLOBAL INPUTS: _iob[]
225 / GLOBAL OUTPUTS: none
228 / Print an error message, then exit.
230 /************************************************************************/
235 fprintf(stderr
, "Error: ");
236 fprintf(stderr
, str
, file
);
242 /************************************************************************
244 / FUNCTION NAME: drandom()
246 / FUNCTION: return a random number
248 / AUTHOR: E. A. Estes, 2/7/86
254 / MODULES CALLED: random()
256 / GLOBAL INPUTS: none
258 / GLOBAL OUTPUTS: none
262 /************************************************************************/
267 if (sizeof(int) != 2)
268 return((double) (random() & 0x7fff) / 32768.0);
270 return((double) random() / 32768.0);