mkhelp.c revision 60786
160786Sps/*
260786Sps * Copyright (C) 1984-2000  Mark Nudelman
360786Sps *
460786Sps * You may distribute under the terms of either the GNU General Public
560786Sps * License or the Less License, as specified in the README file.
660786Sps *
760786Sps * For more information about less, or for information on how to
860786Sps * contact the author, see the README file.
960786Sps */
1060786Sps
1160786Sps
1260786Sps/*
1360786Sps * Silly little program to generate the help.c source file
1460786Sps * from the less.hlp text file.
1560786Sps * help.c just contains a char array whose contents are
1660786Sps * the contents of less.hlp.
1760786Sps */
1860786Sps
1960786Sps#include <stdio.h>
2060786Sps
2160786Sps	int
2260786Spsmain(argc, argv)
2360786Sps	int argc;
2460786Sps	char *argv[];
2560786Sps{
2660786Sps	int ch;
2760786Sps	int prevch;
2860786Sps
2960786Sps	printf("/* This file was generated by mkhelp from less.hlp */\n");
3060786Sps	printf("#include \"less.h\"\n");
3160786Sps	printf("constant char helpdata[] = {\n");
3260786Sps	ch = 0;
3360786Sps	while (prevch = ch, (ch = getchar()) != EOF)
3460786Sps	{
3560786Sps		switch (ch)
3660786Sps		{
3760786Sps		case '\'':
3860786Sps			printf("'\\'',");
3960786Sps			break;
4060786Sps		case '\\':
4160786Sps			printf("'\\\\',");
4260786Sps			break;
4360786Sps		case '\b':
4460786Sps			printf("'\\b',");
4560786Sps			break;
4660786Sps		case '\t':
4760786Sps			printf("'\\t',");
4860786Sps			break;
4960786Sps		case '\n':
5060786Sps			if (prevch != '\r')
5160786Sps				printf("'\\n',\n");
5260786Sps			break;
5360786Sps		case '\r':
5460786Sps			if (prevch != '\n')
5560786Sps				printf("'\\n',\n");
5660786Sps			break;
5760786Sps		default:
5860786Sps			if (ch >= ' ' && ch < 0x7f)
5960786Sps				printf("'%c',", ch);
6060786Sps			else
6160786Sps				printf("0x%02x,", ch);
6260786Sps			break;
6360786Sps		}
6460786Sps	}
6560786Sps	/* Add an extra null char to avoid having a trailing comma. */
6660786Sps	printf(" 0 };\n");
6760786Sps	printf("constant int size_helpdata = sizeof(helpdata) - 1;\n");
6860786Sps	return (0);
6960786Sps}
70