Home | History | Annotate | Line # | Download | only in dist
mkhelp.py revision 1.1
      1 #!/usr/bin/env python
      2 
      3 import time
      4 import sys
      5 
      6 time = time.gmtime()
      7 print("/* This file was generated by mkhelp.py from less.hlp at "\
      8     "%d:%02d GMT on %d/%d/%d */\n" %
      9     (time.tm_hour, time.tm_min, time.tm_year, time.tm_mon, time.tm_mday))
     10 print("#include \"less.h\"")
     11 print("constant char helpdata[] = {")
     12 ch = 0
     13 while True:
     14     prevch = ch
     15     ch = sys.stdin.read(1)
     16     if ch == '':
     17         break
     18     if (ch == "'"):
     19          print("'\\'',", end='')
     20     elif (ch == "\\"):
     21         print("'\\\\',", end='')
     22     elif (ch == "\b"):
     23         print ("'\\b',", end='')
     24     elif (ch == "\t"):
     25         print ("'\\t',", end='')
     26     elif (ch == "\n"):
     27         if prevch != "\r": print("'\\n',")
     28     elif (ch == "\r"):
     29         if prevch != "\n": print("'\\n',")
     30     else:
     31         if ((ord(ch) >= ord(' ')) and (ord(ch) < 0x7f)):
     32             print(f"'{ch}',", end='')
     33         else:
     34             print("0x%02x," % ord(ch), end='')
     35 print(" '\\0' };")
     36 print("constant int size_helpdata = sizeof(helpdata) - 1;")
     37