summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2018-09-05 23:13:24 +0100
committerKatolaZ <katolaz@freaknet.org>2018-09-05 23:13:24 +0100
commit53bd0d759ac992125d326b9a95fb1a83a2384574 (patch)
tree40980e457fc7f3e4393a9a94e9d99aee2ea3c343
parent540583a496564328ce5a677ee4bac6491b4a4932 (diff)
now compatible with mawk
-rw-r--r--parse.awk50
-rw-r--r--render.awk28
2 files changed, 39 insertions, 39 deletions
diff --git a/parse.awk b/parse.awk
index db83b49..3e53c29 100644
--- a/parse.awk
+++ b/parse.awk
@@ -38,23 +38,18 @@ function add_category(c){
function get_cur(cur){
- 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;
- }
+ if (cur["Type"] == "") {
+ print "empty type -- skipping record";
+ return;
+ } else if (cur["Type"] == "link"){
+ add_link(cur);
+ return;
+ } else if (cur["Type"] == "category"){
+ add_category(cur);
+ return;
+ } else {
+ printf("invalid type: %s -- skipping\n", cur["Type"]) ;
+ return;
}
}
@@ -67,7 +62,7 @@ function get_cur(cur){
last_field=$1
}
-/^[[:blank:]]*$/{ ## End of stanza
+/^[\ \f\n\r\t\v]*$/{ ## End of stanza
if (!is_empty(cur)){
get_cur(cur);
delete cur;
@@ -75,18 +70,23 @@ function get_cur(cur){
}
}
-/^[[:blank:]]+[^[:blank:]]+/{## Multi-line value
+/^[\ \f\n\r\t\v]+[^\ \f\n\r\t\v]+/{## Multi-line value
if (!is_empty(cur) && last_field!=""){
- gsub(/^[[:blank:]]+/, "", $0);
+ gsub(/^[\ \f\n\r\t\v]+/, "", $0);
cur[last_field]=cur[last_field] "\n" $0;
}
}
END{
render_init();
- render_categories(category, cnum);
- render_post_categories(category, cnum);
- render_links(category, cnum, link, lnum);
- render_finalise(category, cnum, link, lnum);
- dump_links(category, cnum, link, lnum);
+ #print "before render_categories" > /dev/stderr
+ render_categories();
+# print "before render_post_categories" > /dev/stderr
+ render_post_categories();
+# print "before render_links" > /dev/stderr
+ render_links();
+# print "before render_finalise" > /dev/stderr
+ render_finalise();
+# print "before dump_links" > /dev/stderr
+ dump_links();
}
diff --git a/render.awk b/render.awk
index 7ef884a..7707a71 100644
--- a/render.awk
+++ b/render.awk
@@ -6,7 +6,7 @@ function info_line(name, sel, host, port, dst){
function show_link(l, i, dst){
if(l[i,"Category"] == "")
- print "Uncategorised link:", l[i,"Selector"] > /dev/stderr;
+ print "Uncategorised link:", l[i,"Selector"];
else{
printf("[1|%s|%s|%s|%s]\r\n", l[i,"LinkName"], l[i,"Selector"], l[i,"Host"], l[i,"Port"] ) > dst;
split(l[i,"Description"], descr, "\n");
@@ -27,7 +27,7 @@ function show_category_link(category, i, dst){
function get_parents(a){
delete pars;
- split(a, pars, /[:blank:]*,[:blank:]*/);
+ split(a, pars, /\ \f\n\r\t\v*,\ \f\n\r\t\v*/);
for (k in pars){
gsub(/ +/, "", pars[k]);
}
@@ -61,13 +61,10 @@ function category_header(category, i, dst){
function get_link_categories(a){
delete cats;
- split(a, cats, /([[:blank:]*],[[:blank:]]*|,[[:blank:]]*)/);
- printf("%s -> ", a) >/dev/stderr;
+ split(a, cats, /([\ \f\n\r\t\v*],[\ \f\n\r\t\v]*|,[\ \f\n\r\t\v]*)/);
for (k in cats){
- printf("%s ", cats[k])>/dev/stderr;
gsub(/ +/, "", cats[k]);
}
- print > /dev/stderr
}
########################################
@@ -78,13 +75,16 @@ function render_init(){
}
-function render_categories(category, cnum, link, lnum){
+function render_categories(){
for (i=1; i<=cnum; i++){
cname=category[i,"Name"];
cfiles[cname]=BASEDIR category[i,"Selector"];
- "dirname " cfiles[cname] | getline bdir;
- if (system("ls -d " bdir " 2>/dev/null") >0){
- system("mkdir -p " bdir);
+ cmd="dirname " cfiles[cname];
+ cmd | getline bdir;
+ cmd="ls -d " bdir " 2>/dev/null";
+ if (system(cmd) != 0){
+ cmd="mkdir -p " bdir;
+ system(cmd);
}
cmd=sprintf("rm -f %s", cfiles[cname]);
system(cmd);
@@ -93,13 +93,13 @@ function render_categories(category, cnum, link, lnum){
}
}
-function render_post_categories(category, cnum){
+function render_post_categories(){
}
-function render_links(category, cnum, link, lnum){
+function render_links(){
for (i=1;i<=lnum;i++){
get_link_categories(link[i,"Category"]);
@@ -120,7 +120,7 @@ function render_links(category, cnum, link, lnum){
}
-function render_finalise(category, cnum, link, lnum){
+function render_finalise(){
for(i=1;i<=cnum; i++){
info_line("_______________", "Err", HOST, PORT, cfiles[category[i,"Name"]]);
@@ -128,7 +128,7 @@ function render_finalise(category, cnum, link, lnum){
}
}
-function dump_links(category, cnum, link, lnum){
+function dump_links(){
}