diff options
Diffstat (limited to 'parse.awk')
-rw-r--r-- | parse.awk | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/parse.awk b/parse.awk new file mode 100644 index 0000000..fd6e3e7 --- /dev/null +++ b/parse.awk @@ -0,0 +1,97 @@ +BEGIN{ + lnum=0; + cnum=0; + type=""; + FS=":"; + # category is an array of category data + delete category; + # link is an array of link data + delete link; + + ### configurable variables + BASEDIR="./"; + ROOTFILE="./lawn/index.gph"; + ROOTSEL="/lawn/index.gph"; + HOST="localhost"; + PORT="1500"; +} + +function is_empty(a){ + for (i in a) + return 0; + return 1; +} + +function add_link(c){ + lnum+=1; + for (k in c){ + link[lnum,k]=c[k]; + } +} + +function add_category(c){ + cnum+=1; + for (k in c){ + category[cnum,k]=c[k]; + } +} + + +function get_cur(cur){ + #print "cur[Type]:", cur["Type"]; + switch (cur["Type"]) { + case "": { + print "empty type -- skipping record"; + return; + } + case "link": { + add_link(cur); + return; + } + case "category":{ + add_category(cur); + return; + } + default: { + printf("invalid type: %s -- skipping\n", cur["Type"]) ; + return; + } + } +} + + +/^[A-Z][-a-zA-Z]+:/{ + + #print "Field:",$1,"-","Value:",$2 + gsub(/^ +/,"",$2); + gsub(/ *$/,"",$2); + cur[$1]=$2; +} + +/^[[:blank:]]*$/{ + if (!is_empty(cur)){ + get_cur(cur); + delete cur; + } + else{ + print "cur is empty" > /dev/stderr + } +} + +END{ +## for (i=1;i<=cnum;i++){ +## printf("[1%s|%s|%s|%s]\r\n", category[i,"LinkName"], category[i,"Selector"], \ +## category[i,"Host"], category[i,"Port"]); +## } + + render_init(); + render_categories(category, cnum); + render_post_categories(category, cnum); + render_links(category, cnum, link, lnum); + render_finalise(category, cnum, link, lnum); + ##render_links(link, lnum, cfiles); + #for (k in cnames) + # print k, cnames[k]; + + +} |