mkhelpmsgs.pl 1.8 KB

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