blob: c2628deab464936f565a06fc3a3da9f6cd36b114 (
plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#! /usr/bin/perl
# Convert web .pool file into C source
# Result is an array of chars (bytes) containing the strings,
# each prefixed by a length byte.
# The function initpool() loads this data into TeX's pool.
# usage: perl pool2c.pl NAME.pool
# writes output to ${NAME}_pool.c if only one arg provided
die "expected pool name as argument" unless $#ARGV >= 0;
die "too many arguments" if $#ARGV > 1;
$prog = `basename $ARGV[0] .pool`;
chomp($prog);
$outfile = ($#ARGV == 1) ? $ARGV[1] : "${prog}_pool.c";
open IN, "< $ARGV[0]" or die "can't open input $ARGV[0]";
open OUT, "> $outfile" or die "can't open output $outfile";
print OUT <<__EOT__;
/* This file is auto-generated from $ARGV[0] by pool2c.pl */
#define EXTERN extern
#include "${prog}d.h"
#include <stdio.h>
static unsigned char POOL[] =
__EOT__
$pool_len = 0;
while (<IN>) {
chomp;
if (m/^([0-9]{2})(.*)$/) {
($len, $str) = ($1, $2);
if (length($str) != $len) {
die "*** pool string length error:\n$_\n";
}
$str =~ s/(["\\])/\\$1/g;
$str =~ s/\?\?\?/\\?\\?\\?/g;
printf OUT "\t\"\\x%02X\" \"%s\"\n", $len, $str;
$pool_len += $len + 1;
}
elsif (m/^\*[0-9]+$/) {
last;
}
else {
die "*** unexpected line in pool file:\n$_\n";
}
}
close IN;
print OUT <<__EOT__;
;
#define POOL_LEN $pool_len
int initpool(int limit) {
int g = 0;
unsigned char *s = POOL;
while (s < POOL + POOL_LEN) {
int len = *s++;
if (poolptr + len >= limit)
return 0;
while (len-- > 0)
strpool[poolptr++] = *s++;
g = makestring();
}
return g;
}
__EOT__
close OUT;
|