mkhelpmsgs.pl 1.8 KB

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