dpkg (1.2.12); priority=LOW
[dpkg.git] / dselect / mkhelpmsgs.pl
blob878620fe7bee1ca23eaa0f42c6790325045bc83a
1 #!/usr/bin/perl
3 $maxnlines= 22;
5 open(SRC,"helpmsgs.src") || die $!;
6 open(NC,">helpmsgs.cc.new") || die $!;
7 open(NH,">helpmsgs.h.new") || die $!;
9 &autowarn('NC'); &autowarn('NH');
11 print(NC "#include \"helpmsgs.h\"\n") || die $!;
12 print(NH <<'END') || die $!;
13 #ifndef HELPMSGS_H
14 #define HELPMSGS_H
15 struct helpmessage { const char *title; const char *text; };
16 END
18 $state= 'start';
19 $nblanks= 0; $nlines= 0;
20 while (<SRC>) {
21 s/\"/\\\"/g;
22 if (m/^\@\@\@ (\w+)\s+(\S.*\S)\s+$/) {
23 &finishif;
24 $currentname= $1; $currenttitle= $2;
25 print(NH "extern const struct helpmessage hlp_$currentname;\n") || die $!;
26 print(NC
27 "const struct helpmessage hlp_$currentname = {\n".
28 " \"$currenttitle\", \"") || die $!;
29 } elsif (m/^\@\@\@/) {
30 die;
31 } elsif (!m/\S/) {
32 $nblanks++;
33 } else {
34 if ($state ne 'start' && $nblanks) {
35 print(NC ("\\n"x$nblanks)."\\\n") || die $!;
36 $nlines+= $nblanks;
38 $state= 'middle'; $nblanks= 0;
39 s/\s*\n$//;
40 print(NC "\\\n".$_."\\n") || die $!;
41 $nlines++;
45 &finishif;
47 close(NC) || die $!;
48 print(NH "#endif /* HELPMSGS_H */\n") || die $!;
49 close(NH) || die $!;
51 rename("helpmsgs.cc.new","helpmsgs.cc") || die $!;
52 rename("helpmsgs.h.new","helpmsgs.h") || die $!;
54 sub finishif {
55 if ($state ne 'start') {
56 print(NC "\"\n};\n") || die $!;
57 printf "\t\t%s: %d lines\n",$currentname,$nlines;
58 if ($nlines > $maxnlines) { warn "Too many lines in $currentname"; }
60 $state= 'start';
61 $nblanks= 0; $nlines= 0;
65 sub autowarn {
66 $fh= $_[0];
67 print($fh <<'END') || die $!;
69 * WARNING - THIS FILE IS GENERATED AUTOMATICALLY - DO NOT EDIT
70 * It is generated by mkhelpmsgs.pl from helpmsgs.src.
73 END