mkhelp.c revision 221715
153813Simp/* 2118063Simp * Copyright (C) 1984-2011 Mark Nudelman 3100213Simp * 452506Simp * You may distribute under the terms of either the GNU General Public 552506Simp * License or the Less License, as specified in the README file. 652506Simp * 752506Simp * For more information about less, or for information on how to 852506Simp * contact the author, see the README file. 952506Simp */ 1052506Simp 1152506Simp 1252506Simp/* 1352506Simp * Silly little program to generate the help.c source file 1452506Simp * from the less.hlp text file. 1552506Simp * help.c just contains a char array whose contents are 1652506Simp * the contents of less.hlp. 1752506Simp */ 1852506Simp 1952506Simp#include <stdio.h> 2052506Simp 2152506Simp int 2252506Simpmain(argc, argv) 2352506Simp int argc; 2452506Simp char *argv[]; 2552506Simp{ 2652506Simp int ch; 2752506Simp int prevch; 2852506Simp 2952506Simp printf("/* This file was generated by mkhelp from less.hlp */\n"); 3052506Simp printf("#include \"less.h\"\n"); 3152506Simp printf("constant char helpdata[] = {\n"); 3252506Simp ch = 0; 3352506Simp while (prevch = ch, (ch = getchar()) != EOF) 3452506Simp { 3552506Simp switch (ch) 3652506Simp { 3752506Simp case '\'': 3852506Simp printf("'\\'',"); 3952506Simp break; 4052506Simp case '\\': 4152506Simp printf("'\\\\',"); 4286269Simp break; 4352506Simp case '\b': 4452506Simp printf("'\\b',"); 4552506Simp break; 46119213Simp case '\t': 4758545Simp printf("'\\t',"); 4852506Simp break; 4965039Simp case '\n': 5065039Simp if (prevch != '\r') 5152506Simp printf("'\\n',\n"); 52118063Simp break; 5352506Simp case '\r': 5452506Simp if (prevch != '\n') 5552506Simp printf("'\\n',\n"); 5652506Simp break; 5758545Simp default: 5852506Simp if (ch >= ' ' && ch < 0x7f) 5986455Simp printf("'%c',", ch); 6079270Simp else 61107359Snon printf("0x%02x,", ch); 6252506Simp break; 6386269Simp } 6486455Simp } 65119225Simp /* Add an extra null char to avoid having a trailing comma. */ 6652506Simp printf(" 0 };\n"); 6786455Simp printf("constant int size_helpdata = sizeof(helpdata) - 1;\n"); 6858545Simp return (0); 69104854Simp} 7086269Simp