File: pass1.awk

package info (click to toggle)
libticables3 3.8.9-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,660 kB
  • ctags: 2,190
  • sloc: ansic: 16,302; sh: 9,292; makefile: 517; yacc: 288; awk: 145; sed: 16
file content (165 lines) | stat: -rw-r--r-- 4,044 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#! /usr/bin/awk
# pass1 - generate an html file starting at a text file
# Copyright (C) Romain Lievin 2002
# Contact: roms@tilp.info
#

function write(s) {
    print s > dest;
}

BEGIN {
    if (ARGC < 2) {
	print "usage: cat <src_file> |pass1.awk src=<file> dst=<folder>";
	exit;
    }

    Keywords["Name"] = "";
    Keywords["Type"] = "";
    Keywords["Header"] = "";
    Keywords["Definition"] = "";

    Types["Structure"] = "";
    Types["Function"] = "";
    Types["Define"] = "";
    Types["Enum"] = ""
	Types["Macro"] = "";

    Main = "";

    Name = "";
    Type = "";
    Header = "";
    Definition = "";
}

# Get destination filename
/\[Main\]/ {
    Main = "Main";

    nf = split(src, array, /\//); 
    sub(/.txt/, "", array[nf]);
    dest = dst "/" array[nf] ".html";
}

# Get name and check
/Name=/ {
    nf = split($0, expr, /=/);	
    if ((nf < 2) || (!(expr[1] in Keywords))) {
	print "Illegal keyword !"; print $0; exit;
    }

    Name = expr[2];
}

# Get type and check
/Type=/ {
    nf = split($0, expr, /=/);
    if ((nf < 2) || (!(expr[1] in Keywords))) {
        print "Illegal keyword !"; print $0; exit;
    }

    if(!(expr[2] in Types)) {
	print "Illegal type !"; print $0; exit;
    }

    Type = expr[2];
}

# Get header and check
/Header=/ {
    nf = split($0, expr, /=/);
    if ((nf < 2) || (!(expr[1] in Keywords))) {
        print "Illegal keyword !"; print $0; exit;
    }

    Header = expr[2];
}

# Get definition and write html header
/Definition=/ {
    nf = split($0, expr, /=/);
    if ((nf < 2) || (!(expr[1] in Keywords))) {
        print "Illegal keyword !"; print $0; exit;
    }

    Definition = expr[2];

    write("<html>");
    print "<head>" > dest;
    print "<title>" Name "</title>" > dest;
    print "<link rel=\"stylesheet\" type=\"text/css\" HREF=\"style.css\">" > dest;
    print "</head>" > dest;
    print "<body bgcolor=\"#FFFFF8\">" > dest;
    print "<table class=\"INVTABLE\" width=\"100%\">" > dest;
    print "<tr>" > dest;
    print "<td class=\"NOBORDER\" width=\"40\"><img src=\"function.gif\" width=\"32\" height=\"32\" border=\"0\"></td>" > dest;
    print "<td class=\"TITLE\">" Name "</td>" > dest;
    print "<td class=\"DESCRIPTION\">" Type "</td>" > dest;
    print "</tr>" > dest;
    print "</table>" > dest;
    print "<hr>" > dest;
    print "<table class=\"NOBORDER\" width=\"100%\"><tr>" > dest;
    print "<td class=\"HEADER\" align=\"right\">" Header > dest;
    print "</td>" > dest;
    print "</tr></table>" > dest;
    print "<p><table class=\"DEFTABLE\"><tr><td class=\"DEFINITION\">" Definition "</td></tr></table>" > dest;
}

# Parse parameters and put them into a table
/\[Parameters\]/ ||  /\[Fields\]/ {
    if ($0 ~ /Parameters/)
	print "<p class=\"ITEMDESC\">" "Parameters" "<p>" > dest;
    else
	print "<p class=\"ITEMDESC\">" "Fields"     "<p>" > dest;

    print "<table class=\"NOBORDER\" width=\"100%\"><tr>" > dest;
    
    while ((getline > 0) && !(($0 ~ /\[/) && ($0 ~ /\]/))) {
        nf = split($0, expr, / : /);
	
	print "<tr>" > dest;
	print "<td valign=\"top\" align=\"left\">" expr[1] "<br>" > dest;
	print "</td>" > dest;
	print "<td valign=\"top\">" expr[2] "<br>" > dest;
	print "</td>" > dest;
	print "</tr>" > dest;	    
    }

    print "</table>" > dest;
}

# Copies summary
/\[Summary\]/ { 
    print "<p class=\"ITEMDESC\"> Summary <p>" > dest;

    while ((getline > 0) && !(($0 ~ /\[/) && ($0 ~ /\]/))) {
	print $0 > dest; 
    }
}

# Copies description
/\[Description\]/ { 
    print "<p class=\"ITEMDESC\"> Description <p>" > dest;

    while ((getline > 0) && !(($0 ~ /\[/) && ($0 ~ /\]/))) {
        print $0 > dest;
    }
}    

# Copies misc
/\[See also\]/ {
    print "<p class=\"ITEMDESC\"> See also <p>" > dest;

    while ((getline > 0) && !(($0 ~ /\[/) && ($0 ~ /\]/))) {
        print $0 > dest;
    }
}

# Write end of file
END { 
    print "<hr>" > dest;
    print "<h3> <a href=\"apiindex.html\"> Return to the API index </a></h3>" > dest;
    print "</body>" > dest;
    print "</html>" > dest;
}