1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
Netvideo version 3.2
Written by Ron Frederick <frederick@parc.xerox.com>
Simple hack to translate a Tcl/Tk init file into a C string constant
Extra hacks added by mhandley based on idea from vic
*/
/*
* Copyright (c) Xerox Corporation 1992. All rights reserved.
*
* License is granted to copy, to use, and to make and to use derivative
* works for research and evaluation purposes, provided that Xerox is
* acknowledged in all documentation pertaining to any such copy or derivative
* work. Xerox grants no other licenses expressed or implied. The Xerox trade
* name should not be used in any advertising without its written permission.
*
* XEROX CORPORATION MAKES NO REPRESENTATIONS CONCERNING EITHER THE
* MERCHANTABILITY OF THIS SOFTWARE OR THE SUITABILITY OF THIS SOFTWARE
* FOR ANY PARTICULAR PURPOSE. The software is provided "as is" without
* express or implied warranty of any kind.
*
* These notices must be retained in any copies of any part of this software.
*/
#include <stdio.h>
int
main(int argc, char **argv)
{
int c, n;
FILE* in = stdin;
FILE* out = stdout;
int genstrings = 1;
const char* prog = argv[0];
if (argc > 1 && strcmp(argv[1], "-c") == 0) {
--argc;
++argv;
genstrings = 0;
}
if (argc < 2) {
fprintf(stderr, "Usage: %s [-c] stringname\n", prog);
exit(1);
}
if (genstrings) {
fprintf(out, "char %s[] = \"\"\n\"", argv[1]);
while ((c = getc(in)) != EOF) {
switch (c) {
case '\n':
fprintf(out, "\\n\"\n\"");
break;
case '\"':
fprintf(out, "\\\"");
break;
case '\\':
fprintf(out, "\\\\");
break;
default:
putc(c, out);
break;
}
}
fprintf(out, "\";\n");
} else {
fprintf(out, "static char %s[] = {\n", argv[1]);
for (n = 0; (c = getc(in)) != EOF;)
fprintf(out, "%u,%c", c, ((++n & 0xf) == 0) ? '\n' : ' ');
fprintf(out, "0\n};\n");
}
fclose(out);
exit(0);
/*NOTREACHED*/
}
|