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