home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / CMDS / less_332.lzh / less_332 / mkhelp.c < prev    next >
C/C++ Source or Header  |  1998-03-03  |  1KB  |  59 lines

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