]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/less/mkhelp.c
MFV 316896
[FreeBSD/FreeBSD.git] / contrib / less / mkhelp.c
1 /*
2  * Copyright (C) 1984-2015  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
21 main(int argc, char *argv[])
22 {
23         int ch;
24         int prevch;
25
26         printf("/* This file was generated by mkhelp from less.hlp */\n");
27         printf("#include \"less.h\"\n");
28         printf("constant char helpdata[] = {\n");
29         ch = 0;
30         while (prevch = ch, (ch = getchar()) != EOF)
31         {
32                 switch (ch)
33                 {
34                 case '\'':
35                         printf("'\\'',");
36                         break;
37                 case '\\':
38                         printf("'\\\\',");
39                         break;
40                 case '\b':
41                         printf("'\\b',");
42                         break;
43                 case '\t':
44                         printf("'\\t',");
45                         break;
46                 case '\n':
47                         if (prevch != '\r') 
48                                 printf("'\\n',\n");
49                         break;
50                 case '\r':
51                         if (prevch != '\n') 
52                                 printf("'\\n',\n");
53                         break;
54                 default:
55                         if (ch >= ' ' && ch < 0x7f)
56                                 printf("'%c',", ch);
57                         else
58                                 printf("0x%02x,", ch);
59                         break;
60                 }
61         }
62         /* Add an extra null char to avoid having a trailing comma. */
63         printf(" 0 };\n");
64         printf("constant int size_helpdata = sizeof(helpdata) - 1;\n");
65         return (0);
66 }