File: skel2c

package info (click to toggle)
btyacc 3.0-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 456 kB
  • ctags: 550
  • sloc: ansic: 6,562; yacc: 1,902; makefile: 103; sh: 13
file content (44 lines) | stat: -rw-r--r-- 1,129 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
BEGIN { havesection = 0;
	nsec = 0;
	printf  "/*\n** This file generated automatically from %s\n*/\n\n",
		FILENAME; 
	printf "#include \"defs.h\"\n";
      }
/^%%/ { if (havesection) {
	    printf "    0\n};\n\n";
	}
	if (NF >= 2) {
	    havesection = 1;
	    section = $2;
	    seclist[nsec] = section;
	    nsec = nsec + 1;
	    printf "char *%s[] =\n{\n", $2;
	    printf "    \"#line %d \\\"%s\\\"\",\n", FNR+1, FILENAME; 
	} else {
	    havesection = 0;
	}
	next; 
      }
      { if (havesection) {
	    # Could use 'gsub(/\\/, "\\\\")' instead of the following
	    # two lines, but there's a bug in mawk and the original
	    # awk (not in gawk) which is triggered by that.
	    gsub(/\\/, "\\\1");
	    gsub(/\1/, "\\");
	    gsub(/\t/, "\\t");
	    gsub(/\"/, "\\\"");
	    printf "    \"%s\",\n", $0; 
        } else {
	    print $0; 
        }
      }
END   { if (havesection) {
            printf "    0\n};\n\n"; 
	}
	if (nsec > 0) {
	    printf "struct section section_list[] = {\n";
	    for (i=0; i<nsec; i++)
		printf "\t{ \"%s\", &%s[0] },\n", seclist[i], seclist[i];
	    printf "\t{ 0, 0 } };\n"
	}
      }