Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/util/gen.pl
34878 views
1
# -*- perl -*-
2
3
# Crude template instantiation hack.
4
#
5
# The template named on the command line maps to a perl module t_$foo
6
# which defines certain methods including variable processing and
7
# output generation. It can also suck in additional template modules
8
# for internal use. One output file is generated, which typically
9
# contains structures and inline functions, and should be included by
10
# other files which will define, for example, the typedefname
11
# parameters supplied to this script.
12
13
# To do:
14
# Find a way to make dependency generation automatic.
15
# Make it less gross.
16
17
sub usage {
18
print STDERR "usage: $0 TemplateName [-oOutputFile] PARM=value ...\n";
19
print STDERR " where acceptable PARM values depend on the template\n";
20
exit(1);
21
}
22
23
my $orig_args = join(" ", @ARGV);
24
my $templatename = shift @ARGV || &usage;
25
my $outfile = shift @ARGV || &usage;
26
my $x;
27
28
eval "require t_$templatename;" || die;
29
eval "\$x = new t_$templatename;" || die;
30
31
sub getparms {
32
my $arg;
33
my $outfile;
34
my %allowed_parms = ();
35
36
foreach $arg (@ARGV) {
37
my @words = split '=', $arg;
38
if ($#words != 1) {
39
print STDERR "$0: $arg : #words = $#words\n";
40
&usage;
41
}
42
$x->setparm($words[0], $words[1]);
43
}
44
}
45
46
sub generate {
47
open OUTFILE, ">$outfile" || die;
48
print OUTFILE "/*\n";
49
print OUTFILE " * This file is generated, please don't edit it.\n";
50
print OUTFILE " * script: $0\n";
51
print OUTFILE " * args: $orig_args\n";
52
print OUTFILE " * The rest of this file is copied from a template, with\n";
53
print OUTFILE " * substitutions. See the template for copyright info.\n";
54
print OUTFILE " */\n";
55
$x->output(\*OUTFILE);
56
close OUTFILE;
57
}
58
59
&getparms;
60
&generate;
61
exit (0);
62
63