-
Notifications
You must be signed in to change notification settings - Fork 88
/
mkhelp.pl
executable file
·44 lines (42 loc) · 1.36 KB
/
mkhelp.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env perl
use strict;
# Silly little program to generate the help.c source file
# from the less.hlp text file.
# The output of this script is a C program defining a char array
# whose content is the input to this script.
{
my ($sec,$min,$hour,$mday,$mon,$year) = gmtime();
printf "/* This file was generated by mkhelp.pl from less.hlp at %d:%02d on %d/%d/%d */\n",
$hour, $min, $year+1900, $mon+1, $mday;
print "#include \"less.h\"\n";
print "constant char helpdata[] = {\n";
my $ch = 0;
my $prevch;
for (;;) {
$prevch = $ch;
$ch = getc();
last if not defined $ch;
if ($ch eq "'") {
print "'\\'',";
} elsif ($ch eq "\\") {
print "'\\\\',";
} elsif ($ch eq "\b") {
print "'\\b',";
} elsif ($ch eq "\t") {
print "'\\t',";
} elsif ($ch eq "\n") {
print "'\\n',\n" if $prevch ne "\r";
} elsif ($ch eq "\r") {
print "'\\n',\n" if $prevch ne "\n";
} else {
if (ord($ch) >= ord(' ') && ord($ch) < 0x7f) {
print "'$ch',";
} else {
printf "0x%02x,", ord($ch);
}
}
}
# Add an extra null char to avoid having a trailing comma.
print " 0 };\n";
print "constant int size_helpdata = sizeof(helpdata) - 1;\n";
}