1
0
Files
irix-657m-src/eoe/cmd/fx/menucvt.awk
2022-09-29 17:59:04 +03:00

129 lines
2.9 KiB
Awk

#! /usr/bin/awk -f
# awk script to convert menu tree info to c code
# in the menu tree, menus are like directories, items are like
# directory entries, and funcvals are like inodes.
#
# lines are of the form
#
# DRIVER drivername
# defines the driver that this menufile is for
# FUNC valtag [menu]
# defines a funcval
# <tab> help string
# adds help string to preceding FUNC
# MENU menutag [menuname] [initial function]
# defines a menu
# If initial function is present, it is called
# every time the menu is displayed, just before
# the menu is displayed.
# ITEM valtag [itemname]
# addes item to preceding MENU
# XITEM valtag [itemname]
# same as above, except item is marked restricted
# to expert users.
BEGIN {
printf("/* This file was generated by Menucvt.awk */\n")
printf("extern const char menu_title[];\n");;
nvallist = 0
title = "menu_title"
closer = ""
decl = ""
drivername = ""
}
# a driver
/^DRIVER/ {
drivername = $2
if (drivername == "scsi")
updrivername = "SCSI";
else {
printf("Error: Unrecognized driver name %s\n", drivername);
exit(1);
}
#no longer necesary/desirable printf("# ifdef %s\n", updrivername);
printf("# include \"%s\"\n", "fx.h")
}
# a function
/^FUNC/ {
printf(closer)
printf(decl)
t = $2
f = t "_func"
m = "0"
if ( NF >= 3 )
{
f = "dot_func"
m = drivername "_" $3 "_menu"
printf("extern MENU %s;\n", m);
m = "&" m
}
printf("void %s(void);\n", f)
printf("static char *%s_h[] = {\n", t)
taglist[t] = nvallist
vallist[nvallist++] = t
closer = "\t0\n};\n"
decl = sprintf("static FUNCVAL %s_v = {%s, %s_h, %s};\n", t, f, t, m)
}
# a help command
/^ /{
printf("\t\"%s\",\n", substr($0, 2, length($0)-1))
}
# a menu
/^MENU/ {
printf(closer)
printf(decl)
t = drivername "_" $2
m = t
if ( NF >= 3 )
m = $3
if ( NF >= 4 ) {
i = $4
printf("extern void %s(void);\n", i)
}
else
i = 0;
printf("static ITEM %s_items[] =\n{\n", t)
closer = "\t{0}\n};\n"
decl = sprintf("MENU %s_menu = {%s_items, %s, \"%s\", %s};\n", t, t, title, m, i)
}
# a menu item
/^ITEM/ {
t = $2
f = t
if ( NF >= 3 )
f = $3
printf("\t{\"%s\", %s, 0},\n", f, taglist[t])
}
# an expert-only menu item
/^XITEM/ {
t = $2
f = t
if ( NF >= 3 )
f = $3
printf("\t{\"%s\", %s, 1},\n", f, taglist[t])
}
# the last time
END {
printf(closer)
printf(decl)
closer = ""
decl = ""
printf("FUNCVAL *%s_funcvallist[] =\n{\n", drivername)
for ( j = 0; j < nvallist; j++ )
printf("\t&%s_v,\n", vallist[j])
printf("\t0\n};\n")
t = "dot"
tag = drivername "_" t
f = "."
printf("ITEM %s_item = {\"%s\", %d};\n", tag, f, taglist[t])
t = "dotdot"
tag = drivername "_" t
f = ".."
printf("ITEM %s_item = {\"%s\", %d};\n", tag, f, taglist[t])
t = "help"
tag = drivername "_" t
f = "?"
printf("ITEM %s_item = {\"%s\", %d};\n", tag, f, taglist[t])
#no longer necesary/desirable printf("# endif /* %s */\n", updrivername);
}