xref: /csrg-svn/games/adventure/setup.c (revision 59969)
1*59969Sbostic /*-
2*59969Sbostic  * Copyright (c) 1991, 1993 The Regents of the University of California.
3*59969Sbostic  * All rights reserved.
4*59969Sbostic  *
5*59969Sbostic  * This code is derived from software contributed to Berkeley by
6*59969Sbostic  * Jim Gillogly at The Rand Corporation.
7*59969Sbostic  *
8*59969Sbostic  * %sccs.include.redist.c%
9*59969Sbostic  */
10*59969Sbostic 
11*59969Sbostic #ifndef lint
12*59969Sbostic char copyright[] =
13*59969Sbostic "@(#) Copyright (c) 1991, 1993 The Regents of the University of California.\n\
14*59969Sbostic  All rights reserved.\n";
15*59969Sbostic #endif /* not lint */
16*59969Sbostic 
17*59969Sbostic #ifndef lint
18*59969Sbostic static char sccsid[] = "@(#)setup.c	5.1 (Berkeley) 05/12/93";
19*59969Sbostic #endif /* not lint */
20*59969Sbostic 
21*59969Sbostic /*
22*59969Sbostic  * Setup: keep the structure of the original Adventure port, but use an
23*59969Sbostic  * internal copy of the data file, serving as a sort of virtual disk.  It's
24*59969Sbostic  * lightly encrypted to prevent casual snooping of the executable.
25*59969Sbostic  *
26*59969Sbostic  * Also do appropriate things to tabs so that bogus editors will do the right
27*59969Sbostic  * thing with the data file.
28*59969Sbostic  *
29*59969Sbostic  */
30*59969Sbostic 
31*59969Sbostic #define SIG1 " *      Jim Gillogly"
32*59969Sbostic #define SIG2 " *      Sterday, 6 Thrimidge S.R. 1993, 15:24"
33*59969Sbostic 
34*59969Sbostic #include <stdio.h>
35*59969Sbostic #include "hdr.h"        /* SEED lives in there; keep them coordinated. */
36*59969Sbostic 
37*59969Sbostic #define USAGE "Usage: setup file > data.c (file is typically glorkz)\n"
38*59969Sbostic 
39*59969Sbostic #define YES 1
40*59969Sbostic #define NO  0
41*59969Sbostic 
42*59969Sbostic void fatal();
43*59969Sbostic 
44*59969Sbostic #define LINE 10         /* How many values do we get on a line? */
45*59969Sbostic 
46*59969Sbostic main(argc, argv)
47*59969Sbostic int argc;
48*59969Sbostic char *argv[];
49*59969Sbostic {
50*59969Sbostic 	FILE *infile;
51*59969Sbostic 	int c, count, linestart;
52*59969Sbostic 
53*59969Sbostic 	if (argc != 2) fatal(USAGE);
54*59969Sbostic 
55*59969Sbostic 	if ((infile = fopen(argv[1], "r")) == NULL)
56*59969Sbostic 		fatal("Can't read file %s.\n", argv[1]);
57*59969Sbostic 	puts("/*\n * data.c: created by setup from the ascii data file.");
58*59969Sbostic 	puts(SIG1);
59*59969Sbostic 	puts(SIG2);
60*59969Sbostic 	puts(" */");
61*59969Sbostic 	printf("\n\nchar data_file[] =\n{");
62*59969Sbostic 	srandom(SEED);
63*59969Sbostic 	count = 0;
64*59969Sbostic 	linestart = YES;
65*59969Sbostic 
66*59969Sbostic 	while ((c = getc(infile)) != EOF)
67*59969Sbostic 	{
68*59969Sbostic 		if (linestart && c == ' ') /* Convert first spaces to tab */
69*59969Sbostic 		{
70*59969Sbostic 			printf("0x%02x,", ('\t' ^ random()) & 0xFF);
71*59969Sbostic 			while ((c = getc(infile)) == ' ' && c != EOF);
72*59969Sbostic 			/* Drop the non-whitespace character through */
73*59969Sbostic 			linestart = NO;
74*59969Sbostic 		}
75*59969Sbostic 		switch(c)
76*59969Sbostic 		{
77*59969Sbostic 		    case '\t':
78*59969Sbostic 			linestart = NO; /* Don't need to convert spaces */
79*59969Sbostic 			break;
80*59969Sbostic 		    case '\n':
81*59969Sbostic 			linestart = YES; /* Ready to convert spaces again */
82*59969Sbostic 			break;
83*59969Sbostic 		}
84*59969Sbostic 		if (count++ % LINE == 0)   /* Finished a line? */
85*59969Sbostic 			printf("\n\t");
86*59969Sbostic 		printf("0x%02x,", (c ^ random()) & 0xFF);
87*59969Sbostic 	}
88*59969Sbostic 	puts("\n\t0\n};");
89*59969Sbostic 	fclose(infile);
90*59969Sbostic 	exit(0);
91*59969Sbostic }
92*59969Sbostic 
93*59969Sbostic 
94*59969Sbostic void fatal(format, arg)
95*59969Sbostic char *format;
96*59969Sbostic {
97*59969Sbostic 	fprintf(stderr, format, arg);
98*59969Sbostic 	exit(1);
99*59969Sbostic }
100