#!/usr/bin/gawk -f BEGIN { if(ARGC <= 1) {printf("Use: WLAT_RENUM_MAX \n") > "/dev/stderr"; printf("\tGive the nodes a sequential numbering based on the order in which\n\tthey are opened. Also put all open node commands at the beginning\n\tand all close node commands at the end.\n") > "/dev/stderr"; exit(0); } # Read and convert the word graph fname = ARGV[1]; for(iline=1;(getline "/dev/stderr"; node_time[$2] = $3; } else if($1 == "C") {if($2 in node_time) {if($2 >= 0) delete node_time[$2]; } else printf("ERROR: node %s closed, but never opened\n",$2) > "/dev/stderr"; if($2 in node_xlat) delete node_xlat[$2]; else printf("WARNING: node %s closed, but never used\n",$2) > "/dev/stderr"; } else if($1 ~ "^[AD]$") {if(!($2 in node_xlat)) printf("O %i %s\n",node_xlat[$2]=nr_nodes++,node_time[$2]); $2 = node_xlat[$2]; if(!($3 in node_xlat)) printf("O %i %s\n",node_xlat[$3]=($3>=0)?nr_nodes++:$3,node_time[$3]); $3 = node_xlat[$3]; arcs[nr_arcs++] = $0; } else if($1 == "File:") {if(nr_nodes > 0) {for(i=0;i=-4; ) {if(i in node_time) {printf("C %i\n",i); delete node_time[i]; } } for(i in node_time) printf("ERROR: node %s not closed\n",i); delete node_time; delete node_xlat; for(i=nr_nodes;--i>=0; ) printf("C %i\n",i); nr_nodes = nr_arcs = 0; } if(EOF) break; printf("%s\n",$0); } else printf("Error: unknown command '%s' at line %i\n",$0,iline) > "/dev/stderr"; } close(fname); exit(0); }