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