159969Sbostic /*-
2*60733Sbostic * Copyright (c) 1991, 1993
3*60733Sbostic * The Regents of the University of California. All rights reserved.
459969Sbostic *
559969Sbostic * This code is derived from software contributed to Berkeley by
659969Sbostic * Jim Gillogly at The Rand Corporation.
759969Sbostic *
859969Sbostic * %sccs.include.redist.c%
959969Sbostic */
1059969Sbostic
1159969Sbostic #ifndef lint
12*60733Sbostic static char copyright[] =
13*60733Sbostic "@(#) Copyright (c) 1991, 1993\n\
14*60733Sbostic The Regents of the University of California. All rights reserved.\n";
1559969Sbostic #endif /* not lint */
1659969Sbostic
1759969Sbostic #ifndef lint
18*60733Sbostic static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 05/31/93";
1959969Sbostic #endif /* not lint */
2059969Sbostic
2159969Sbostic /*
2259969Sbostic * Setup: keep the structure of the original Adventure port, but use an
2359969Sbostic * internal copy of the data file, serving as a sort of virtual disk. It's
2459969Sbostic * lightly encrypted to prevent casual snooping of the executable.
2559969Sbostic *
2659969Sbostic * Also do appropriate things to tabs so that bogus editors will do the right
2759969Sbostic * thing with the data file.
2859969Sbostic *
2959969Sbostic */
3059969Sbostic
3159969Sbostic #define SIG1 " * Jim Gillogly"
3259969Sbostic #define SIG2 " * Sterday, 6 Thrimidge S.R. 1993, 15:24"
3359969Sbostic
3459969Sbostic #include <stdio.h>
3559969Sbostic #include "hdr.h" /* SEED lives in there; keep them coordinated. */
3659969Sbostic
3759969Sbostic #define USAGE "Usage: setup file > data.c (file is typically glorkz)\n"
3859969Sbostic
3959969Sbostic #define YES 1
4059969Sbostic #define NO 0
4159969Sbostic
4259969Sbostic void fatal();
4359969Sbostic
4459969Sbostic #define LINE 10 /* How many values do we get on a line? */
4559969Sbostic
main(argc,argv)4659969Sbostic main(argc, argv)
4759969Sbostic int argc;
4859969Sbostic char *argv[];
4959969Sbostic {
5059969Sbostic FILE *infile;
5159969Sbostic int c, count, linestart;
5259969Sbostic
5359969Sbostic if (argc != 2) fatal(USAGE);
5459969Sbostic
5559969Sbostic if ((infile = fopen(argv[1], "r")) == NULL)
5659969Sbostic fatal("Can't read file %s.\n", argv[1]);
5759969Sbostic puts("/*\n * data.c: created by setup from the ascii data file.");
5859969Sbostic puts(SIG1);
5959969Sbostic puts(SIG2);
6059969Sbostic puts(" */");
6159969Sbostic printf("\n\nchar data_file[] =\n{");
6259969Sbostic srandom(SEED);
6359969Sbostic count = 0;
6459969Sbostic linestart = YES;
6559969Sbostic
6659969Sbostic while ((c = getc(infile)) != EOF)
6759969Sbostic {
6859969Sbostic if (linestart && c == ' ') /* Convert first spaces to tab */
6959969Sbostic {
7059969Sbostic printf("0x%02x,", ('\t' ^ random()) & 0xFF);
7159969Sbostic while ((c = getc(infile)) == ' ' && c != EOF);
7259969Sbostic /* Drop the non-whitespace character through */
7359969Sbostic linestart = NO;
7459969Sbostic }
7559969Sbostic switch(c)
7659969Sbostic {
7759969Sbostic case '\t':
7859969Sbostic linestart = NO; /* Don't need to convert spaces */
7959969Sbostic break;
8059969Sbostic case '\n':
8159969Sbostic linestart = YES; /* Ready to convert spaces again */
8259969Sbostic break;
8359969Sbostic }
8459969Sbostic if (count++ % LINE == 0) /* Finished a line? */
8559969Sbostic printf("\n\t");
8659969Sbostic printf("0x%02x,", (c ^ random()) & 0xFF);
8759969Sbostic }
8859969Sbostic puts("\n\t0\n};");
8959969Sbostic fclose(infile);
9059969Sbostic exit(0);
9159969Sbostic }
9259969Sbostic
9359969Sbostic
fatal(format,arg)9459969Sbostic void fatal(format, arg)
9559969Sbostic char *format;
9659969Sbostic {
9759969Sbostic fprintf(stderr, format, arg);
9859969Sbostic exit(1);
9959969Sbostic }
100