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