home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
GAMES
/
colossal.lzh
/
advent0.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-11-03
|
4KB
|
179 lines
/* ADVENT0.C
*
* execution will read the four adventure text files
* files; "advent1.txt", "advent2.txt", "advent3.txt" &
* "advent4.txt". it will create the file "advtext.h"
* which is an Index Sequential Access Method (ISAM)
* header to be #included into "advent.c" before the
* header "advdef.h" is #included.
*
* Help option added by M.Gregorie as part of the port to
* OS9/68K. ltoa() calls modified to match Borland C function
* definition.
*
*/
#include <stdio.h>
#include "advent.h"
extern int fclose();
extern char *fgets();
extern FILE *fopen();
extern int fprintf();
extern int fputs();
extern long ftell();
extern int printf();
main(argc, argv)
int argc;
char **argv;
{
FILE *isam, *fd1, *fd2, *fd3, *fd4;
char itxt[255], otxt[80], lstr[12];
int cnt, llen,i;
void showhelp();
if (argc > 1)
{
for (i = 1; i < argc; i++)
if (argv[i][0] == '-' || argv[i][0] == '/')
if (argv[i][1] == '?')
{
showhelp();
exit(0);
}
}
isam = fopen("advtext.h", TEXTWRITE);
if (!isam) {
printf("Sorry, I can't open advtext.h...\n");
exit(0);
}
fd1 = fopen("advent1.txt", TEXTREAD);
if (!fd1) {
printf("Sorry, I can't open advent1.txt...\n");
exit(0);
}
fd2 = fopen("advent2.txt", TEXTREAD);
if (!fd2) {
printf("Sorry, I can't open advent2.txt...\n");
exit(0);
}
fd3 = fopen("advent3.txt", TEXTREAD);
if (!fd3) {
printf("Sorry, I can't open advent3.txt...\n");
exit(0);
}
fd4 = fopen("advent4.txt", TEXTREAD);
if (!fd4) {
printf("Sorry, I can't open advent4.txt...\n");
exit(0);
}
fprintf(isam, "\n/");
fprintf(isam, "*\theader: ADVTEXT.H\t\t\t\t\t*/\n\n\n");
cnt = -1;
lstr[0] = '\0';
fprintf(isam, "long\tidx1[MAXLOC] = {\n\t");
while (fgets(itxt, 255, fd1)) {
printf("%s", itxt);
if (itxt[0] == '#') {
if (lstr[0])
fprintf(isam, "%s,", lstr);
llen = ltoa(ftell(fd1), lstr, 10);
if (!llen) {
printf("ltoa err in advent1.txt\n");
exit(0);
} /* if (!llen) */
if (++cnt == 5) {
fprintf(isam, "\n\t");
cnt = 0;
} /* if (cnt) */
} /* if (itxt[0]) */
} /* while fgets */
fprintf(isam, "%s\n\t};\n\n", lstr);
cnt = -1;
lstr[0] = '\0';
fprintf(isam, "long\tidx2[MAXLOC] = {\n\t");
while (fgets(itxt, 255, fd2)) {
printf("%s", itxt);
if (itxt[0] == '#') {
if (lstr[0])
fprintf(isam, "%s,", lstr);
llen = ltoa(ftell(fd2), lstr, 10);
if (!llen) {
printf("ltoa err in advent2.txt\n");
exit(0);
} /* if (!llen) */
if (++cnt == 5) {
fprintf(isam, "\n\t");
cnt = 0;
} /* if (cnt) */
} /* if (itxt[0]) */
} /* while fgets */
fprintf(isam, "%s\n\t};\n\n", lstr);
cnt = -1;
lstr[0] = '\0';
fprintf(isam, "long\tidx3[MAXOBJ] = {\n\t");
while (fgets(itxt, 255, fd3)) {
printf("%s", itxt);
if (itxt[0] == '#') {
if (lstr[0])
fprintf(isam, "%s,", lstr);
llen = ltoa(ftell(fd3), lstr, 10);
if (!llen) {
printf("ltoa err in advent3.txt\n");
exit(0);
} /* if (!llen) */
if (++cnt == 5) {
fprintf(isam, "\n\t");
cnt = 0;
} /* if (cnt) */
} /* if (itxt[0]) */
} /* while fgets */
fprintf(isam, "%s\n\t};\n\n", lstr);
cnt = -1;
lstr[0] = '\0';
fprintf(isam, "long\tidx4[MAXMSG] = {\n\t");
while (fgets(itxt, 255, fd4)) {
printf("%s", itxt);
if (itxt[0] == '#') {
if (lstr[0])
fprintf(isam, "%s,", lstr);
llen = ltoa(ftell(fd4), lstr, 10);
if (!llen) {
printf("ltoa err in advent4.txt\n");
exit(0);
} /* if (!llen) */
if (++cnt == 5) {
fprintf(isam, "\n\t");
cnt = 0;
} /* if (cnt) */
} /* if (itxt[0]) */
} /* while fgets */
fprintf(isam, "%s\n\t};\n\n", lstr);
} /* main */
void showhelp()
{
printf("\nSyntax : advent0\n");
printf("Function: Generate the Adventure system advtext.h header\n");
printf(" file from the text files advent1.txt .. advent4.txt\n");
printf(" These files must be in the current directory when\n");
printf(" advent0 is run.\n");
printf("Options: none\n");
}