home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / less373.zip / mkhelp.c < prev    next >
C/C++ Source or Header  |  2002-01-14  |  1KB  |  70 lines

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