2 function noident(given) {
6 BEGIN { havesection = 0;
7 version = "Id: skel2c,v 1.3 2014/04/06 19:48:04 tom Exp ";
10 printf "/* This file generated automatically using\n * %s\n */\n\n",
14 printf "%s\n", noident($0);
17 /^%% *insert *VERSION *here/ {
18 printf " CONCAT1(\"#define YYMAJOR \", YYMAJOR),\n";
19 printf " CONCAT1(\"#define YYMINOR \", YYMINOR),\n";
20 printf "#ifdef YYPATCH\n";
21 printf " CONCAT1(\"#define YYPATCH \", YYPATCH),\n";
27 printf "#if defined(%s)\n", $2;
28 printf " \"#if %s\",\n", $2;
31 printf "skel2c: ill-formed %%ifdef in skeleton file on line %d\n", FNR > "/dev/stderr";
35 printf "skel2c: nested %%ifdef in skeleton file on line %d\n", FNR > "/dev/stderr";
44 printf " \"#endif /* %s */\",\n", $2;
45 printf "#endif /* defined(%s) */\n", $2;
47 printf " \"#endif /* %s */\",\n", ifdef;
48 printf "#endif /* defined(%s) */\n", ifdef;
52 printf " \"#endif\",\n";
54 printf "skel2c: unmatched %endif in skeleton file on line %d\n", FNR > "/dev/stderr";
59 /^%%/ { if (havesection) {
65 seclist[nsec] = section;
67 printf "const char *const %s[] =\n{\n", $2;
74 # Could use 'gsub(/\\/, "\\\\")' instead of the following
75 # two lines, but there's a bug in mawk and the original
76 # awk (not in gawk) which is triggered by that.
79 # gsub(/\t/, "\\t"); # change '\t' to "\\t"
81 printf " \"%s\",\n", $0;
86 END { if (_abort_exit)
93 print "write_section(FILE * fp, const char *const section[])";
96 print " const char *s;\n";
97 print " for (i = 0; (s = section[i]) != 0; ++i)";
99 print "\tif (fp == code_file)";
100 print "\t ++outline;";
101 print "\tfprintf(fp, \"%s\\n\", s);";
105 print "skel2c: no sections defined in skeleton file" > "/dev/stderr";
109 printf "skel2c: unmatched %%ifdef %s at end of skeleton file\n", $ifdef > "/dev/stderr";