summaryrefslogtreecommitdiffstats
path: root/scripts/doxy_filter.awk
blob: 5ec04062985ed977be2c7575ae46392782c5143d (plain)
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
#!/usr/bin/awk

/BAREBOX_CMD_HELP_START[[:space:]]*\((.*)\)/ {

	this_opt = 0;
	my_usage = "";
	my_short = "";
	my_cmd = gensub("BAREBOX_CMD_HELP_START[[:space:]]*\\((.*)\\)", "\\1", "g");
	this_text = 0;
	delete(my_text);
	delete(my_opts);
	next;
}

/BAREBOX_CMD_HELP_USAGE[[:space:]]*\((.*)\)/ {

	$0 = gensub("<", "\\&lt;", "g");
	$0 = gensub(">", "\\&gt;", "g");
	$0 = gensub("BAREBOX_CMD_HELP_USAGE[[:space:]]*\\((.*)\\)", "\\1", "g");
	$0 = gensub("\\\\n", "", "g");
	my_usage = gensub("\"", "", "g");
	next;

}

/BAREBOX_CMD_HELP_SHORT[[:space:]]*\((.*)\)/ {

	$0 = gensub("<", "\\&lt;", "g");
	$0 = gensub(">", "\\&gt;", "g");
	$0 = gensub("BAREBOX_CMD_HELP_SHORT[[:space:]]*\\((.*)\\)", "\\1", "g");
	$0 = gensub("\\\\n", "", "g");
	my_short = gensub("\"", "", "g");
	next;

}

/BAREBOX_CMD_HELP_OPT[[:space:]]*\([[:space:]]*(.*)[[:space:]]*,[[:space:]]*(.*)[[:space:]]*\)/ {

	$0 = gensub("<", "\\&lt;", "g");
	$0 = gensub(">", "\\&gt;", "g");
	$0 = gensub("@", "\\\\@",    "g");	
	$0 = gensub("BAREBOX_CMD_HELP_OPT[[:space:]]*\\([[:space:]]*\"*(.*)\"[[:space:]]*,[[:space:]]*\"(.*)\"[[:space:]]*\\)", \
		"<tr><td><tt> \\1 </tt></td><td>\\&nbsp;\\&nbsp;\\&nbsp;</td><td> \\2 </td></tr>", "g");
	$0 = gensub("\\\\n", "", "g");
	my_opts[this_opt] = gensub("\"", "", "g");
	this_opt ++;
	next;
}

/BAREBOX_CMD_HELP_TEXT[[:space:]]*\((.*)\)/ {

	$0 = gensub("<", "\\&lt;", "g");
	$0 = gensub(">", "\\&gt;", "g");
	$0 = gensub("BAREBOX_CMD_HELP_TEXT[[:space:]]*\\((.*)\\)", "\\1", "g");
	$0 = gensub("\\\\n", "<br>", "g");
	my_text[this_text] = gensub("\"", "", "g");
	this_text ++;
	next;
}

/BAREBOX_CMD_HELP_END/ {

	printf "/**\n";
	printf " * @page " my_cmd "_command " my_cmd "\n";
	printf " *\n";
	printf " * \\par Usage:\n";
	printf " * " my_usage "\n";
	printf " *\n";

	if (this_opt != 0) {
		printf " * \\par Options:\n";
		printf " *\n";
		printf " * <table border=\"0\" cellpadding=\"0\">\n";
		n = asorti(my_opts, my_opts_sorted);
		for (i=1; i<=n; i++) {
			printf " * " my_opts[my_opts_sorted[i]] "\n";
		}
		printf " * </table>\n";
		printf " *\n";
	}

	printf " * " my_short "\n";
	printf " *\n";

	n = asorti(my_text, my_text_sorted);
	if (n > 0) {
		for (i=1; i<=n; i++) {
			printf " * " my_text[my_text_sorted[i]] "\n";
		}
		printf " *\n";
	}

	printf " */\n";

	next;
}

/^.*$/ {

	print $0;

}