builtins.awk
1.24 KB
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
#
# "$Revision: 1.2 $"
#
# Generate a C structure from a table of commands
#
BEGIN {
fname=FILENAME;
sub("[.]awk", "", fname);
print "#include \"ide.h\"";
count = 0;
}
/^[^#]/ {
name[count] = $1;
type[count] = $2;
addr[count] = $3;
if ( NF > 3 )
help[count] = $4;
else
help[count] = "";
count++;
}
END {
for ( i = 0; i < count; i++ )
if ( type[i] == "CMD" || type[i] == "SCMD" || type[i] == "DCMD" )
printf("extern int %s();\n", addr[i]);
printf("\nbuiltin_t %s[] = {\n", fname);
for ( i = 0; i < count; i++ )
if ( type[i] == "CMD" )
printf("\t\"%s\",\t(char *)%s,\tB_CMD,\"%s\",\n",name[i],addr[i],help[i]);
else
if ( type[i] == "STR" )
printf("\t\"%s\",\t%s,\tB_STR,\"%s\",\n",name[i],addr[i],help[i]);
else
if ( type[i] == "INT" )
printf("\t\"%s\",\t(char *)%s,\tB_INT,\"%s\",\n",name[i],addr[i],help[i]);
else
if ( type[i] == "SCMD" )
printf("\t\"%s\",\t(char *)%s,\tB_SCMD,\"%s\",\n",name[i],addr[i],help[i]);
else
if ( type[i] == "DCMD" )
printf("\t\"%s\",\t(char *)%s,\tB_DCMD,\"%s\",\n",name[i],addr[i],help[i]);
else
exit 1;
printf("};\n");
printf("%sinit(){syminit(sizeof(%s)/sizeof(builtin_t),%s);}\n",fname,fname,fname);
printf("%shelp(){symhelp(sizeof(%s)/sizeof(builtin_t),%s);}\n",fname,fname,fname);
}