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