xref: /trueos/contrib/less/mkhelp.c (revision b972b67ed72b5687a023c92602aaef64163b2f59)
1 /*
2  * Copyright (C) 1984-2012  Mark Nudelman
3  *
4  * You may distribute under the terms of either the GNU General Public
5  * License or the Less License, as specified in the README file.
6  *
7  * For more information, see the README file.
8  */
9 
10 
11 /*
12  * Silly little program to generate the help.c source file
13  * from the less.hlp text file.
14  * help.c just contains a char array whose contents are
15  * the contents of less.hlp.
16  */
17 
18 #include <stdio.h>
19 
20 	int
main(argc,argv)21 main(argc, argv)
22 	int argc;
23 	char *argv[];
24 {
25 	int ch;
26 	int prevch;
27 
28 	printf("/* This file was generated by mkhelp from less.hlp */\n");
29 	printf("#include \"less.h\"\n");
30 	printf("constant char helpdata[] = {\n");
31 	ch = 0;
32 	while (prevch = ch, (ch = getchar()) != EOF)
33 	{
34 		switch (ch)
35 		{
36 		case '\'':
37 			printf("'\\'',");
38 			break;
39 		case '\\':
40 			printf("'\\\\',");
41 			break;
42 		case '\b':
43 			printf("'\\b',");
44 			break;
45 		case '\t':
46 			printf("'\\t',");
47 			break;
48 		case '\n':
49 			if (prevch != '\r')
50 				printf("'\\n',\n");
51 			break;
52 		case '\r':
53 			if (prevch != '\n')
54 				printf("'\\n',\n");
55 			break;
56 		default:
57 			if (ch >= ' ' && ch < 0x7f)
58 				printf("'%c',", ch);
59 			else
60 				printf("0x%02x,", ch);
61 			break;
62 		}
63 	}
64 	/* Add an extra null char to avoid having a trailing comma. */
65 	printf(" 0 };\n");
66 	printf("constant int size_helpdata = sizeof(helpdata) - 1;\n");
67 	return (0);
68 }
69