setup.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* $NetBSD: setup.c,v 1.10 2003/08/07 09:36:51 agc Exp $ */
  2. /*-
  3. * Copyright (c) 1991, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Jim Gillogly at The Rand Corporation.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. */
  33. #ifndef lint
  34. static const char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1991, 1993\n\
  35. The Regents of the University of California. All rights reserved.\n";
  36. #if 0
  37. static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
  38. #else
  39. static const char rcsid[] __attribute__((__unused__)) = "$NetBSD: setup.c,v 1.10 2003/08/07 09:36:51 agc Exp $";
  40. #endif
  41. #endif /* not lint */
  42. /*
  43. * Setup: keep the structure of the original Adventure port, but use an
  44. * internal copy of the data file, serving as a sort of virtual disk. It's
  45. * lightly encrypted to prevent casual snooping of the executable.
  46. *
  47. * Also do appropriate things to tabs so that bogus editors will do the right
  48. * thing with the data file.
  49. *
  50. */
  51. #define SIG1 " * Jim Gillogly"
  52. #define SIG2 " * Sterday, 6 Thrimidge S.R. 1993, 15:24"
  53. #include <stdio.h>
  54. #include <errno.h>
  55. #include <string.h>
  56. #include <stdlib.h>
  57. #include "hdr.h" /* SEED lives in there; keep them coordinated. */
  58. #define USAGE "Usage: setup file > data.c (file is typically glorkz)\n"
  59. #define YES 1
  60. #define NO 0
  61. #define LINE 10 /* How many values do we get on a line? */
  62. int main(int, char *[]);
  63. int
  64. main(argc, argv)
  65. int argc;
  66. char *argv[];
  67. {
  68. FILE *infile;
  69. int c, count, linestart;
  70. if (argc != 2) {
  71. fprintf(stderr, USAGE);
  72. exit(1);
  73. }
  74. if ((infile = fopen(argv[1], "r")) == NULL) {
  75. fprintf(stderr, "Can't read file %s: %s\n", argv[1],
  76. strerror(errno));
  77. exit(1);
  78. }
  79. puts("/*\n * data.c: created by setup from the ascii data file.");
  80. puts(SIG1);
  81. puts(SIG2);
  82. puts(" */");
  83. printf("\n\nchar data_file[] =\n{");
  84. srandom(SEED);
  85. count = 0;
  86. linestart = YES;
  87. while ((c = getc(infile)) != EOF) {
  88. if (linestart && c == ' ') { /* Convert first spaces to tab */
  89. printf("0x%02x,", (unsigned int)('\t' ^ random()) & 0xFF);
  90. while ((c = getc(infile)) == ' ' && c != EOF);
  91. /* Drop the non-whitespace character through */
  92. linestart = NO;
  93. }
  94. switch (c) {
  95. case '\t':
  96. linestart = NO; /* Don't need to convert spaces */
  97. break;
  98. case '\n':
  99. linestart = YES; /* Ready to convert spaces
  100. * again */
  101. break;
  102. }
  103. if (count++ % LINE == 0) /* Finished a line? */
  104. printf("\n\t");
  105. printf("0x%02x,", (unsigned int)(c ^ random()) & 0xFF);
  106. }
  107. puts("\n\t0\n};");
  108. fclose(infile);
  109. fflush(stdout);
  110. if (ferror(stdout)) {
  111. perror("error writing standard output");
  112. exit(1);
  113. }
  114. exit(0);
  115. }