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