Fix missing episode numbers in MHz

Fix missing episode numbers in MHz

--- getMHzFrom-episodePages.awk
+++ getMHzFrom-episodePages.awk
@@ -82,6 +82,8 @@
     gsub (/'/,"'")
     split ($0,fld,"\"")
     episodeURL = fld[2]
+    if (episodeURL ~ /-c-[[:digit:]]{5}$/)
+        episodeNumberFromURL = substr (episodeURL, length(episodeURL)-1, 2)
     episodeTitle = fld[4]
     gsub (/"/,"\"\"",episodeTitle)
     sub (/.*season:/,"")
@@ -102,14 +104,23 @@
 # Extract the episode description and print the composed info
 /<div class="transparent padding-top-medium"/,/<\/div>/ {
     if ($0 ~ /
 Episode number is 00: " episodeURL >> ERROR_FILE
+        if ((episodeNumber + 0) == 0) {
+            if ((episodeNumberFromURL + 0) != 0) {
+                episodeNumber = episodeNumberFromURL
+                print "==> Corrected E00: " episodeURL " to E" episodeNumber >> ERROR_FILE
+            } else {
+                print "==> Episode number is 00: " episodeURL >> ERROR_FILE
+            }
+        }
         printf ("%d\t=HYPERLINK(\"%s\";\"%s, S%02dE%02d, %s\"\)\t\t\t%s\t\t\t\t\t", \
             SERIES_NUMBER, episodeURL, seriesTitle, seasonNumber, episodeNumber, episodeTitle, \
             episodeDuration) >> EPISODE_INFO_FILE
         # Need to account for multiple lines of description
         descriptionLinesFound = 0
         episodeDescription = ""
+        # make sure there is no carryforward
+        episodeNumber = ""
+        episodeNumberFromURL = ""
     }
     if ($0 ~ /
/) {
         split ($0,fld,"[<>]")


Oops, don't why I missed out 'mode=remove' changes. Fixed remove mode for static interface


cleaning global.e1.params.ttl with bin/util/update-e-params-subject-discrim.awk

--- bin/util/update-e-params-subject-discrim.awk
+++ bin/util/update-e-params-subject-discrim.awk
@@ -10,11 +10,11 @@
 {
    if( $1 == "@prefix" && $2 == ":" ) {
       # Fix up default namespace.
-      printf("@prefix :           <%s/source/%s/dataset/%s/version/%s/params/enhancement/%s/> .",baseURI,sourceID,dataset_identifier,datasetVersion,layerID);
+      printf("@prefix :           <%s/source/%s/dataset/%s/version/%s/params/enhancement/%s/> .\n",baseURI,sourceID,dataset_identifier,datasetVersion,layerID);

    }else if( $0 == ":dataset a void:Dataset;" ) {
       # Change subject to name of layer dataset itself.
-      printf("%s/source/%s/dataset/%s/version/%s/conversion/enhancement/%s",baseURI,sourceID,dataset_identifier,datasetVersion,layerID);
+      printf("<%s/source/%s/dataset/%s/version/%s/conversion/enhancement/%s>\n",baseURI,sourceID,dataset_identifier,datasetVersion,layerID);

    }else if( $0~"conversion:subject_discriminator" ) {
       printf("      conversion:subject_discriminator \"%s\";\n",subjectDiscriminator)


A script to convert regexps to reperf format test cases, one per line.


Update min/maxx to be inclusive

Update min/maxx to be inclusive

see: https://trello.com/c/RU4BWrYA/340-as-a-data-manager-adding-min-max-values-in-the-jts-they-should-be-inclusive

--- bin/bawlk.awk
+++ bin/bawlk.awk
@@ -140,7 +140,7 @@
         msg         = "Field " field " in \" CSVFILENAME \" line \" NR \" is a duplicate and should be unique"

     } else if (rule_type ~ /^minimum|maximum$/) {
-        comparator  = $2 == "maximum" ? ">" : "<"
+        comparator  = $2 == "maximum" ? ">=" : "<="
         limit       = params[2]
         term        = $2 == "maximum" ? "less" : "greater"


Translators/GoogleTranslate: ignore JSON null, fix #171

--- include/Translators/GoogleTranslate.awk
+++ include/Translators/GoogleTranslate.awk
@@ -125,6 +125,8 @@
     saveSortedIn = PROCINFO["sorted_in"]
     PROCINFO["sorted_in"] = "@ind_num_asc"
     for (i in ast) {
+        if (ast[i] == "null") continue
+
         if (i ~ "^0" SUBSEP "0" SUBSEP "[[:digit:]]+" SUBSEP "0$")
             append(translations, postprocess(literal(ast[i])))
         if (i ~ "^0" SUBSEP "0" SUBSEP "[[:digit:]]+" SUBSEP "1$")


Initialization in BEGIN block.

Initialization in BEGIN block.

--- src/cloudfront.awk
+++ src/cloudfront.awk
@@ -29,6 +29,7 @@
 }

 BEGIN {
+    logLineSeen = 0
     print "{";
 }

@@ -38,7 +39,6 @@

 /^#Version: / {
     printf "\t\"version\": \"%s\",\n", substr($0, length("#Version: ") + 1)
-    logLineSeen = 0
 }

 /^#Fields: / {


Another tentative waypoint before any sensible commits begin. This introduces splines through the intersection points of the graphviz edge and node circles.


print full inheritance

print full inheritance

Change-Id: Ia53fcbde6b3ff4d38b477069a1f956c9aef84f78

--- i18npool/source/localedata/data/list-dateacceptancepattern.awk
+++ i18npool/source/localedata/data/list-dateacceptancepattern.awk
@@ -80,7 +80,7 @@
         for (i in LocaleList)
         {
             if (LocaleList[i][offinherit] && LocaleList[i][offpatterns])
-                print LocaleList[i][offlocale] " = " LocaleList[i][offinherit] "    "
+                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "    "
         }
         print "\n<p>"
     }
@@ -89,7 +89,7 @@
         for (i in LocaleList)
         {
             if (LocaleList[i][offinherit] && LocaleList[i][offpatterns])
-                print LocaleList[i][offlocale] " = " LocaleList[i][offinherit]
+                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
         }
         print "\n"
     }
@@ -105,7 +105,7 @@
         for (i in LocaleList)
         {
             if (!LocaleList[i][offpatterns])
-                print LocaleList[i][offlocale] "    "
+                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale]) "    "
         }
     }
     else
@@ -113,13 +113,13 @@
         for (i in LocaleList)
         {
             if (!LocaleList[i][offpatterns])
-                print LocaleList[i][offlocale]
+                print getInheritance( LocaleList[i][offlocale], LocaleList[i][offlocale])
         }
     }
 }

-function endFile() {
+function endFile(       locale ) {
     locale =  getLocale( file)
     LocaleList[locale][offlocale] = locale
     LocaleList[locale][offpatterns] = patterns
@@ -172,4 +172,11 @@
     }
 }

+
+function getInheritance( str, locale ) {
+    if (LocaleList[locale][offinherit])
+        str = getInheritance( str " = " LocaleList[locale][offinherit], LocaleList[locale][offinherit])
+    return str
+}
+
 # vim:set shiftwidth=4 softtabstop=4 expandtab:


add subnet statistics

add subnet statistics

--- src/condor_ckpt_server/xfer_log.awk
+++ src/condor_ckpt_server/xfer_log.awk
@@ -1,5 +1,6 @@
 BEGIN {
     num_hosts = 0;
+    num_subnets = 0;
     num_users = 0;
 }
 {
@@ -15,6 +16,12 @@
 	    Hosts[num_hosts] = $9;
 	    num_hosts++;
 	}
+	split($9, ip_tmp, ".");
+	Subnet = sprintf("%s.%s.%s", ip_tmp[1], ip_tmp[2], ip_tmp[3]);
+	if (AttemptedSends[Subnet] == 0 && AttemptedRecvs[Subnet] == 0) {
+	    Subnets[num_subnets] = Subnet;
+	    num_subnets++;
+	}
 	split($10, user_tmp, "\@");
 	User = user_tmp[1];
 	if (AttemptedSends[User] == 0 && AttemptedRecvs[User] == 0) {
@@ -23,30 +30,41 @@
 	}
 	if ($3 == "S") {
 	    AttemptedSends[$9]++;
+	    AttemptedSends[Subnet]++;
 	    AttemptedSends[User]++;
 	    if ($4 != "F") {
 		CompletedSends[$9]++;
+		CompletedSends[Subnet]++;
 		CompletedSends[User]++;
 		BytesSent[$9] += $5;
+		BytesSent[Subnet] += $5;
 		BytesSent[User] += $5;
 		TimeSending[$9] += $7;
+		TimeSending[Subnet] += $7;
 		TimeSending[User] += $7;
 	    }
 	} else {
 	    AttemptedRecvs[$9]++;
+	    AttemptedRecvs[Subnet]++;
 	    AttemptedRecvs[User]++;
 	    if ($4 != "F") {
 		CompletedRecvs[$9]++;
+		CompletedRecvs[Subnet]++;
 		CompletedRecvs[User]++;
 		BytesRecvd[$9] += $5;
+		BytesRecvd[Subnet] += $5;
 		BytesRecvd[User] += $5;
 		TimeReceiving[$9] += $7;
+		TimeReceiving[Subnet] += $7;
 		TimeReceiving[User] += $7;
 	    }
 	}
     }
 }
 END {
+    qsort(Hosts, 0, num_hosts-1);
+    qsort(Subnets, 0, num_subnets-1);
+    qsort(Users, 0, num_users-1);
     printf("\nCheckpoint Server Transfer Log Data from %s %s to %s %s\n\n",
 	   StartDate, StartTime, EndDate, EndTime);
     printf("%-16.16s %9.9s %7.7s %9.9s %7.7s %9.9s %7.7s\n",
@@ -99,6 +117,24 @@
 	TotalCompletedSends += CompletedSends[Host];
 	TotalCompletedRecvs += CompletedRecvs[Host];
     }
+    printf("\n");
+    for (i=0; i < num_subnets; i++) {
+	Subnet = Subnets[i];
+	Bytes = BytesSent[Subnet] + BytesRecvd[Subnet];
+	Time = TimeSending[Subnet] + TimeReceiving[Subnet];
+	Attempted = AttemptedSends[Subnet] + AttemptedRecvs[Subnet];
+	Completed = CompletedSends[Subnet] + CompletedRecvs[Subnet];
+	if (TimeSending[Subnet] > 0 && TimeReceiving[Subnet] > 0) {
+	    printf("%-16.16s %9.2f %6.0f%% %9.2f %6.0f%% %9.2f %6.0f%%\n",
+		   Subnet,
+		   BytesSent[Subnet]*8/TimeSending[Subnet]/1024000,
+		   CompletedSends[Subnet]/AttemptedSends[Subnet]*100,
+		   BytesRecvd[Subnet]*8/TimeReceiving[Subnet]/1024000,
+		   CompletedRecvs[Subnet]/AttemptedRecvs[Subnet]*100,
+		   Bytes*8/Time/1024000,
+		   Completed/Attempted*100);
+	}
+    }
     TotalBytes = TotalBytesSent + TotalBytesRecvd;
     TotalTime = TotalTimeSending + TotalTimeReceiving;
     TotalAttempted = TotalAttemptedSends + TotalAttemptedRecvs;
@@ -122,3 +158,19 @@
     printf("\n%-16.16s %25.0f %25.0f\n",
 	   "Total", TotalBytesSent/1024000, TotalBytesRecvd/1024000);
 }
+function qsort(v, left, right) {
+  if (left >= right) return;
+  swap(v, left, int((left + right)/2));
+  last = left;
+  for (i=left+1; i <= right; i++) {
+    if (v[i] < v[left]) swap(v, ++last, i);
+  }
+  swap(v, left, last);
+  qsort(v, left, last-1);
+  qsort(v, last+1, right);
+}
+function swap(v, i, j) {
+  temp = v[i];
+  v[i] = v[j];
+  v[j] = temp;
+}


r11552/sofa-dev : missing double-slashes in filter-qmake-pro.awk

Former-commit-id: 1325c1b6b009cc1e080200429d891be5c8aaa556

--- scripts/filter-qmake-pro.awk
+++ scripts/filter-qmake-pro.awk
@@ -39,7 +39,7 @@
 # Note that we now count the brackets in the source file to find the
 # SOFA_DEV closing one instead of relying on the presence of a comment

-blk_filtered==0 && $0 ~ "contains[ \t]*\([ \t]*DEFINES[ \t]*,[ \t]*"FILTER_TAG"[ \t]*\)[ \t]*{" {
+blk_filtered==0 && $0 ~ "contains[ \t]*\\([ \t]*DEFINES[ \t]*,[ \t]*"FILTER_TAG"[ \t]*\\)[ \t]*{" {
     blk_filtered=blk_after;
     infilelist=0;
 }


TestUtils: mark as gawk5-compatible (close #297)

--- test/TestUtils.awk
+++ test/TestUtils.awk
@@ -6,7 +6,7 @@
     T("GawkVersion", 1)
     {
         initGawk()
-        assertTrue(GawkVersion ~ "^4.")
+        assertTrue(GawkVersion ~ "^(4|5).")
     }

     T("Rlwrap", 1)


build.awk: use ManTemplate to generate ManMarkdown

--- build.awk
+++ build.awk
@@ -34,8 +34,9 @@

     ManPath              = "man/"
     Man                  = ManPath Command ".1"
-    ManSource            = Man ".md"
-    ManTemplate          = Man ".template.html"
+    ManTemplate          = Man ".template.md"
+    ManMarkdown          = Man ".md"
+    ManHtmlTemplate      = Man ".template.html"
     ManHtml              = Man ".html"

     PagesPath            = "gh-pages/"
@@ -58,10 +59,15 @@
     MainRegistry         = RegistryPath "index.trans"
 }

-function man() {
-    if (fileExists(ManTemplate))
-        system("pandoc -s -t html --toc --toc-depth 1 --template " ManTemplate " " ManSource " -o " ManHtml)
-    return system("pandoc -s -t man " ManSource " -o " Man)
+function man(    text) {
+    text = readFrom(ManTemplate)
+    gsub(/\$Version\$/, Version, text)
+    gsub(/\$ReleaseDate\$/, ReleaseDate, text)
+    writeTo(text, ManMarkdown)
+
+    if (fileExists(ManHtmlTemplate))
+        system("pandoc -s -t html --toc --toc-depth 1 --template " ManHtmlTemplate " " ManMarkdown " -o " ManHtml)
+    return system("pandoc -s -t man " ManMarkdown " -o " Man)
 }

 function readme(    code, col, cols, content, group, i, j, language, r, rows, text) {


fix: sanitize_text() may create trailing whitespaces that must be removed

--- scripts/lib/awk/utils.awk
+++ scripts/lib/awk/utils.awk
@@ -27,7 +27,7 @@
   # set of results we have so far.
   gsub(/[^[\x00-\x7F]]|[\(\)]/, "", text);
   gsub(/[[:space:]]{2,}/, " ", text);
-  return text;
+  return trim(text);
 }

 #


Scale also the job counts

Scale also the job counts

--- creation/web_base/parse_starterlog.awk
+++ creation/web_base/parse_starterlog.awk
@@ -31,6 +31,14 @@
   }
 }

+# divide and rund up anything that is not an onteger
+# e.g. 1.1 becomes 2
+function updiv(x,y) {
+  t=1.0*x/y;
+  dstr=sprintf("%d",t+0.99);
+  return int(dstr);
+}
+
 ########################################################################
 / Communicating with shadow /{
   # 7/17 10:42:20 (pid:26855) Communicating with shadow <131.225.204.208:34839>
@@ -138,10 +146,27 @@
 }
 ########################################################################
 END {
+  tj=updiv(ended_jobs,parallelism);
+
+  #since it is rounded, the sum could exceed tj
+  tcnt=0;
+  tgnz=updiv(goodjobsNZ,parallelism);tcnt=tcnt+tgnz;
+  while (tcnt>tj) {tgnz=tgnz-1; tcnt=tcnt-1;}
+  tbjs=updiv(badjobsSignal,parallelism);tcnt=tcnt+tbjs;
+  while (tcnt>tj) {tbjs=tbjs-1; tcnt=tcnt-1;}
+  tbjo=updiv(badjobsOther,parallelism);tcnt=tcnt+tbjo;
+  while (tcnt>tj) {tbjo=tbjo-1; tcnt=tcnt-1;}
+
+  # if needed, penalize the "good jobs" the most
+  # we mostly want to monitor failures
+  tgz=updiv(goodjobsZ,parallelism); tcnt=tcnt+tgz;
+  while (tcnt>tj) {tgz=tgz-1; tcnt=tcnt-1;}
+  # please notice that the percentages will still be accurate
+
   print "=================";
-  print "Total jobs",ended_jobs,"utilization",int(total_used/parallelism);
-  print "Total goodZ jobs",goodjobsZ " (" percent(goodjobsZ,ended_jobs) "%)","utilization",int(goodputZ/parallelism) " (" percent(goodputZ,total_used) "%)";
-  print "Total goodNZ jobs",goodjobsNZ " (" percent(goodjobsNZ,ended_jobs) "%)","utilization",int(goodputNZ/parallelism) " (" percent(goodputNZ,total_used) "%)";
-  print "Total badSignal jobs",badjobsSignal " (" percent(badjobsSignal,ended_jobs) "%)","utilization",int(badputSignal/parallelism) " (" percent(badputSignal,total_used) "%)";
-  print "Total badOther jobs",badjobsOther " (" percent(badjobsOther,ended_jobs) "%)","utilization",int(badputOther/parallelism) " (" percent(badputOther,total_used) "%)";
+  print "Total jobs",tj,"utilization",int(total_used/parallelism);
+  print "Total goodZ jobs",tgz, " (" percent(goodjobsZ,ended_jobs) "%)","utilization",int(goodputZ/parallelism) " (" percent(goodputZ,total_used) "%)";
+  print "Total goodNZ jobs",tgnz, " (" percent(goodjobsNZ,ended_jobs) "%)","utilization",int(goodputNZ/parallelism) " (" percent(goodputNZ,total_used) "%)";
+  print "Total badSignal jobs",tbjs, " (" percent(badjobsSignal,ended_jobs) "%)","utilization",int(badputSignal/parallelism) " (" percent(badputSignal,total_used) "%)";
+  print "Total badOther jobs",tbjo, " (" percent(badjobsOther,ended_jobs) "%)","utilization",int(badputOther/parallelism) " (" percent(badputOther,total_used) "%)";
 }


added bibo prefix.

added bibo prefix.

--- bin/util/header2params2.awk
+++ bin/util/header2params2.awk
@@ -60,6 +60,7 @@
       print "@prefix muo:           <http://purl.oclc.org/NET/muo/muo#> ."
       print "@prefix vs:            <http://www.w3.org/2003/06/sw-vocab-status/ns#> ."
       print "@prefix frbr:          <http://purl.org/vocab/frbr/core#> ."
+      print "@prefix bibo:          <http://purl.org/ontology/bibo/> ."
       print "@prefix dgtwc:         <http://data-gov.tw.rpi.edu/2009/data-gov-twc.rdf#> ."
    }
    print "@prefix dcterms:       <http://purl.org/dc/terms/> ."


Handle mscorwks_unixexports.src with better regexp operator for compatibility

ver3:
According to the gawk manual, The '\S' operator (as shorthand for '[^[:space:]]')
matches any character that is not whitespace. However, '[ \t]' is better than
'\S' for Mac OSX.
(source - https://www.gnu.org/software/gawk/manual/html_node/GNU-Regexp-Operators.html )

ver2:
With ver1, the build-break is caused by different awk versions (by @jkotas).
(Revert PR - https://github.com/dotnet/coreclr/pull/4005)
To resolve the limitation of the ver1, @janvorli proposed that the
\S expression is better than [:space:] for the most compatible solution.

There are a lot of different AWK software (e.g. awk, gawk, mawk, nawk, etc)
and versions among the popular Linux distributions. This patch is a simply
way to handle 'mscorwks_unixexports.src' file with \S operator for more
compatibility amon the different awk versions.

ver1:
It's must be modified by gawk implementation that check it exactly
as a plain character (e.g., space, alnum) within the bracket expression
at ./coreclr/generateversionscript.awk. The [[:space:]] is more appropriate than
the [:space:]]. (PR - https://github.com/dotnet/coreclr/pull/3943)

Signed-off-by: Geunsik Lim <acd8f4539166019ed6425de5f67e6d834f46e5a4@samsung.com>
Signed-off-by: MyungJoo Ham <84146178f7c201fa3079bfc93fccba71d81dffe3@samsung.com>
Signed-off-by: Prajwal A N <b9045b1f56dab106e820d6cda13049bcd6c9e3af@samsung.com>

--- generateversionscript.awk
+++ generateversionscript.awk
@@ -8,7 +8,7 @@
 	gsub(/\r/,"", $0);

 	# Skip empty lines and comment lines starting with semicolon
-	if (NF && !match($0, /^[:space:]*;/))
+	if (NF && !match($0, /^[ \t]*;/))
 	{
 		print "        "  $0 ";";
 	}


port.dispatch: disable ENVIRON["TERMINAL"]... something else should happen here, but what?

--- src/port.dispatch.awk
+++ src/port.dispatch.awk
@@ -45,7 +45,7 @@
 # we get a file as argument:
 attr["from"] == "BROWSER" ||
 attr["from"] == "EDITOR" ||
-attr["from"] == "TERMINAL" ||
+# attr["from"] == "TERMINAL" ||
 attr["from"] == "irc-user" ||
 attr["from"] == "gnome-desktop-menu" {
     run(nest($0, "open", DEFAULT_MENU))


changed Tool to Thing in default template

--- bin/util/header2params2.awk
+++ bin/util/header2params2.awk
@@ -184,11 +184,11 @@
                                     printf("      ];                          \n");
    }
                                     printf("      #conversion:enhance [\n");
-                                    printf("      #   conversion:domain_template \"tool_[r]\";\n");
-                                    printf("      #   conversion:domain_name     \"Tool\";\n");
+                                    printf("      #   conversion:domain_template \"thing_[r]\";\n");
+                                    printf("      #   conversion:domain_name     \"Thing\";\n");
                                     printf("      #];\n");
                                     printf("      #conversion:enhance [\n");
-                                    printf("      #   conversion:class_name \"Tool\";\n");
+                                    printf("      #   conversion:class_name \"Thing\";\n");
                                     printf("      #   conversion:subclass_of <http://purl.org/...>;\n");
                                     printf("      #];\n");
 }


bundle example in template maker

bundle example in template maker

--- bin/util/header2params2.awk
+++ bin/util/header2params2.awk
@@ -99,6 +99,12 @@
                                     printf("<%s> dcterms:identifier \"%s\" .\n",person_uri,whoami);
    }

+   if( length(conversionID)) {
+                                    printf(":a_bundle\n");
+                                    printf("   conversion:property_name \"a_property\"; # Can also be a URI, e.g. dcterms:title.\n");
+                                    printf("   conversion:type_name     \"My Class\";   # Can also be a URI, e.g. foaf:Person.\n");
+                                    printf(".");
+   }
    #
    # Describe the dataset.
    #


moved to Transdipporator for now

moved to Transdipporator for now

--- scripts/turtlel_merge.awk
+++ scripts/turtlel_merge.awk
@@ -1,62 +0,0 @@
-#! /usr/bin/awk -f
-# turtle_merge.awk  t_1.ttl t_2.ttl > t_3.ttl
-#
-# Notes:
-# You could merge more than two files
-#
-# Written to merge some small turtle formatted _METADATA_ files
-# that is "small", as in maybe a page long files (i.e. a few kb)
-
-# This script does not know anything about IRI or curies
-# just plain ol' string pattern matching.
-
-# If multiple prefixes have different base-uri then the last one wins
-#
-# Order is neither preserved nor reliably repeated.
-#
-# There may be room to reduce redundancy in object lists in some cases
-
-BEGIN{RS= " \\.\n*"}
-
-# rdf prefix declarations
-/^@prefix /{prefix[$2]=$3}
-
-# rdf record
-/^<[^>].*> / {
-    # isolate subject
-    s = $1; $1 = "";
-    # strip newlines
-    gsub("\n", "")
-    # collapse space
-    gsub("  ", " ")
-    # partition predicates list
-    split(substr($0,2), plist, " ; ")
-    for(pos in plist){
-        prdobjs = plist[pos]
-        p = substr(prdobjs, 1, index(prdobjs, " "))
-        prdobjs = substr(prdobjs, length(p)+1)
-        # what remains are objects
-        record[s,p] = prdobjs
-    }
-}
-
-END {
-    for(x in prefix){print "@prefix " x " " prefix[x] " ."}
-    print ""
-    # regroup by subjects
-    for(r in record){
-        split(r, sp, SUBSEP)
-        s = sp[1]; p = sp[2]
-        subject[s] = subject[s] "\t" p " " record[r] " ;\n"
-    }
-
-    # resorting could happen here
-
-    for(s in subject){
-        print s
-        print substr(subject[s],1, length(subject[s])-3) " .\n"
-    }
-}
-
-
-


Finish out tmp bed for paired end

Finish out tmp bed for paired end

This is based on the mpavis.sh form hichip method of making the
temporary bed file using the tlen for the end

--- lib/optical/bam_to_insert_size_bed.awk
+++ lib/optical/bam_to_insert_size_bed.awk
@@ -7,13 +7,25 @@
     exit 1;
   }
   if ("" == endness) {
-    print "Missing endness style (se|pe) via -v endness="
+    print "Missing endness style (se|pe) via -v endness=";
+    exit 1;
+  } else if ( ("se" == endness) && (""==size) ) {
+    print "Missing fragment size since single end via -v size=";
     exit 1;
   }
 }

 function pe_bedder(path) {
-
+  start=($4-1)
+  if ( (($2==83) || ($2==147)) && ($9>0) ) {
+    print $3,start,(start+$9),".","1","-" > path;
+  } else if ( ((2==83) || ($2==147)) && ($9<0) ) {
+    print $3,start,(start-$9),".","1","-" > path;
+  } else if ( (($2==99) || ($2==163)) && ($9>0) ) {
+    print $3,start,(start+$9),".","1","+" > path;
+  } else if ( (($2==99) || ($2==163)) && ($9<0) ) {
+    print $3,start,(start-$9),".","1","+" > path;
+  }
 }

 function se_bedder(path,size) {
@@ -24,6 +36,7 @@
   if ("pe" == endness) {
     sub(/-/,"",$9);
     tlens[$9]++;
+    pe_bedder(base"_tmp.bed");
   } else if ("se" == endness) {
   }
 }


Define a specific map for the Apple portuguese USB keyboards.

Based on input from Manuel Pata and Rodolfo Gouveia on tech@.

--- dev/usb/makemap.awk
+++ dev/usb/makemap.awk
@@ -1,5 +1,5 @@
 #! /usr/bin/awk -f
-#	$OpenBSD: makemap.awk,v 1.1 2005/05/09 05:08:32 miod Exp $
+#	$OpenBSD: makemap.awk,v 1.2 2005/05/12 09:28:21 miod Exp $
 #
 # Copyright (c) 2005, Miodrag Vallat
 #
@@ -31,10 +31,11 @@
 #

 BEGIN {
-	rcsid = "$OpenBSD: makemap.awk,v 1.1 2005/05/09 05:08:32 miod Exp $"
+	rcsid = "$OpenBSD: makemap.awk,v 1.2 2005/05/12 09:28:21 miod Exp $"
 	ifdepth = 0
 	ignore = 0
 	declk = 0
+	haskeys = 0

 	# PS/2 id -> UKBD conversion table, or "sanity lossage 102"
 	# (101 is for GSC keyboards!)
@@ -227,8 +228,7 @@

 /pckbd/ {
 	gsub("pckbd", "ukbd", $0)
-	print $0
-	next
+	mapname = $4
 }

 /KC/ {
@@ -237,6 +237,8 @@

 	if (declk)
 		next
+
+	haskeys = 1

 	sidx = substr($1, 4, length($1) - 5)
 	orig = int(sidx)
@@ -288,16 +290,40 @@
 		next
 	}

-	# Duplicate 42 (backspace) as 76
-	# XXX maybe not correct anymore?
-	lines[76] = lines[42]
-	sub("42", "76", lines[76])
-
-	for (i = 0; i < 256; i++)
-		if (lines[i]) {
-			print lines[i]
-			lines[i] = ""
+	if (haskeys) {
+		# Duplicate 42 (backspace) as 76
+		# XXX maybe not correct anymore?
+		lines[76] = lines[42]
+		sub("42", "76", lines[76])
+
+		for (i = 0; i < 256; i++)
+			if (lines[i]) {
+				print lines[i]
+				lines[i] = ""
+			}
+
+		haskeys = 0
+
+		#
+		# Apple portuguese USB keyboards use a slightly different
+		# layout. We define it here.
+		#
+		if (mapname == "ukbd_keydesc_pt[]") {
+			print $0
+			print "\nstatic const keysym_t ukbd_keydesc_pt_apple[] = {"
+			print "/*  pos\t\tnormal\t\tshifted */"
+			print "    KC(46),\tKS_plus,\tKS_asterisk,"
+			print "    KC(47),\tKS_masculine,\tKS_ordfeminine,"
+			print "    KC(50),\tKS_backslash,\tKS_bar,"
+			print "    KC(52),\tKS_dead_tilde,\tKS_dead_circumflex"
 		}
+
+	}
+}
+/KB_PT/ {
+	print $0
+	print "\tKBD_MAP(KB_PT | KB_APPLE,\tKB_PT,\tukbd_keydesc_pt_apple),"
+	next
 }
 {
 	if (ignore)


cut deadwood, add exceptions, split bnodes into their own pattern rules

--- scripts/ntriple2dot.awk
+++ scripts/ntriple2dot.awk
@@ -28,10 +28,10 @@
 # this leaves the namespace of a removed identifier

 # this may need to be called more than once since
-# some identifiers may have embedded delimiters
+# some identifiers may have embedded delimiters other uri use differently
 function stripid(uri){
 	# <_:blanknode> are not allowed in ntriples (but may happen anyway)
-	if(1 == match(uri, /^_:/))
+	if(0 < match(uri, /^_:/))
 		return "BNODE"
 	# perspective endpoints, choose the longest
 	delim["_"]=0; delim["/"]=0;
@@ -65,12 +65,14 @@
 function contract(uri){
 	u = uri
 	# shorten till longest uri in curi map is found (or not)
-	while(!(u in prefix))
+	while(!(u in prefix) &&  length(u))
 		u = stripid(substr(u,1,length(u)-1))
 	if(u in prefix)
 		return prefix[u]
-	else
+	else{
+		# printf("WARN  %s\n", uri) > "/dev/stderr"
 		return simplify(uri)
+	}
 }

 # get the final (incl fragment identifier) portion of a slashed path
@@ -89,7 +91,9 @@
 	prefix["https://monarchinitiative.org/_"]="BNODE"
 	# just until skolemized bnodes get in the curie map?
 	prefix["https://monarchinitiative.org/.well-known/genid"]="BNODE"
-	# revisit if exceptions are still necessary
+	############################################################
+	# revisit whether these exceptions are still necessary often
+	# they may have been moved into the  prefix mapping file
 	prefix["http://www.w3.org/1999/02/22-rdf-syntax-ns#"]="rdf"
 	prefix["http://www.w3.org/2000/01/rdf-schema#"]="rdfs"
 	prefix["http://www.w3.org/2002/07/owl#"]="owl"
@@ -97,17 +101,25 @@
 	prefix["https://www.mousephenotype.org"]="IMPC"
 	# in panther
 	prefix["http://identifiers.org/wormbase"]="WormBase"
+	# in IMPC
+	prefix["http://www.mousephenotype.org"]="IMPC"
+	# in GWAScatalog
+	prefix["http://www.ncbi.nlm.nih.gov/SNP/"]="dbSNP"
 	# till all non httpS: are purged
 	prefix["http://monarchinitiative.org/"]="BASE"
 	prefix["http://www.monarchinitiative.org/"]="BASE"
 	prefix["http://monarchinitiative.org/MONARCH_"]="MONARCH"
+	prefix["http://www.monarchinitiative.org/MONARCH"]=""
 	prefix["http://www.monarchinitiative.org/MONARCH_"]="MONARCH"
+	prefix["http://data.monarchinitiative.org/ttl"]="MonarchData"
+	prefix["http://archive.monarchinitiative.org/ttl"]="MonarchArchive"
 }

 # main loop
 # parse and stash the curie yaml file (first file)
 # YAML format is tic delimited word (the curi prefix)
-# optional whitespace, a colon, then a tic delimited url
+# optional whitespace, a colon, optional whitespace
+# then a tic delimited url
 # (FNR == NR) && /^'[^']*' *: 'http[^']*'.*/ { # loosing some?
 (FNR == NR) && /^'.*/ {
 	split($0, arr, "'")
@@ -115,29 +127,67 @@
 		arr[2]="BASE"
 	prefix[arr[4]]=arr[2]
 }
+
 # process the ntriple file(s)  which are not the first file
-### case when subject predicate and object are all uri
+
+### subject predicate and object are all uri
 (FNR != NR) && /^<[^>]*> <[^>]*> <[^>]*> \.$/ {
-	### Subject (uri)
 	s = contract(stripid(trim($1)))
-	### Predicate (uri)
+	p =  final(trim($2))
+	ns = contract(stripid(trim($2)))
+	o = contract(stripid(trim($3)))
+	edgelist[s,ns ":" p,o]++
+	done[NR]=1
+}
+### subject & predicate are uri but the object is a literal
+(FNR != NR) && /^<[^>]*> <[^>]*> "[^"]*".*\.$/ {
+	s = contract(stripid(trim($1)))
+	p = final(trim($2))
+	ns = contract(stripid(trim($2)))
+	edgelist[s, ns ":" p, "LITERAL"]++
+	done[NR]=1
+}
+### subject is a bare blank node, predicate and object are uri
+(FNR != NR) && /^_:[^ ]* <[^>]*> <[^>]*> \.$/ {
+	# once our bnode syntax is uniform we may want more info out of it
+	# s = contract(stripid($1))
 	p =  final(trim($2))
 	ns = contract(stripid(trim($2)))
 	### Object (like subject)
 	o = contract(stripid(trim($3)))
-	edgelist[s,ns ":" p,o]++
-}
-### case when the object is a literal
-(FNR != NR) && /^<[^>]*> <[^>]*> "[^"]*" \.$/ {
-	### Subject (uri)
+	edgelist["BNODE",ns ":" p,o]++
+	done[NR]=1
+}
+### subject & predicate are uri & object is a bare blank node
+(FNR != NR) && /^<[^>]*> <[^>]*> _:[^ ]* \.$/ {
 	s = contract(stripid(trim($1)))
-	### Predicate (uri)
+	p =  final(trim($2))
+	ns = contract(stripid(trim($2)))
+	#o = contract(stripid($3))
+	edgelist[s,ns ":" p,"BNODE"]++
+	done[NR]=1
+}
+### subject and object are a bare blank nodes, predicate is a uri
+(FNR != NR) && /^_:[^ ]* <[^>]*> _:[^ ]* \.$/ {
+	# s = contract(stripid($1))
+	p =  final(trim($2))
+	ns = contract(stripid(trim($2)))
+	# o = contract(stripid($3))
+	edgelist["BNODE",ns ":" p,"BNODE"]++
+	done[NR]=1
+}
+### subject is a bare blank node, predicate is a uri & the object is a literal
+(FNR != NR) && /^_:[^ ]* <[^>]*> "[^"]*".*\.$/ {
+	# s = contract(stripid($1))
 	p = final(trim($2))
 	ns = contract(stripid(trim($2)))
-	### not a uri
-	o = "LITERAL"
-	edgelist[s, ns ":" p, o]++
-	nodelist[o " [shape=record];"]++
+	edgelist["BNODE", ns ":" p, "LITERAL"]++
+	done[NR]=1
+}
+
+# print anything else so it makes itself known
+(FNR != NR) && (done[NR]<1) && (NF>1){
+	printf("ERROR? line %i  %s", FNR, $0) > "/dev/stderr"
 }

 # output dot file, include edge counts
@@ -150,7 +200,7 @@
 		print simplify(spo[1]) " -> " simplify(spo[3]) \
 		" [label=\"" spo[2] " (" edgelist[edge] ")\"];"
 	}
-	for(node in nodelist) print node
+	print "LITERAL [shape=record];"
 	print "labelloc=\"t\";"
 	title = final(FILENAME)
 	datestamp = strftime("%Y%m%d", systime())


Removes the first space after the leading `*` in a comment, because some parsers *cough*markdeep*cough* don't like it if there is a space before the `[link]: www.example.com`


c++: Fix for symbol table demangled names with spaces


Filter out --with-* in tool/.configure.awk

--- tool/.configure.awk
+++ tool/.configure.awk
@@ -4,6 +4,7 @@
     print "#!/command/mawk" "\n\n" "BEGIN { OFS = \"=\" }"
 }

+$1 ~ /^--with-/ { next }
 $1 !~ /dir$/ { next }
 { OPTION = $0 }
 { gsub("-","",OPTION) }


#105425# filter comments

#105425# filter comments

--- solenv/bin/getcsym.awk
+++ solenv/bin/getcsym.awk
@@ -2,9 +2,9 @@
 #
 #   $RCSfile: getcsym.awk,v $
 #
-#   $Revision: 1.1 $
+#   $Revision: 1.2 $
 #
-#   last change: $Author: hjs $ $Date: 2001-04-27 12:46:32 $
+#   last change: $Author: hjs $ $Date: 2002-11-21 16:50:30 $
 #
 #   The Contents of this file are made available subject to the terms of
 #   either of the following licenses
@@ -60,6 +60,7 @@
 #
 #*************************************************************************
 BEGIN { global_found = "false" }
+/[ \t]*#/ { sub( substr( $0, index($0, "#")),"" ) }
 /[ \t]*local:/ { global_found = "false" }
 /^[ \t]*$/ { next }
 global_found == "true"  { print $0 }


Fixed indentation

Fixed indentation

--- CsvToSql.awk
+++ CsvToSql.awk
@@ -1,27 +1,27 @@
 BEGIN { FS="," }
 {
-  num_fields = csv_parse($0, row, ",", "\"", "''", "\\n", 1);
-  # get header row names
-  if (NR == 1) {
-    num_fields = csv_parse($0, col, ",", "\"", "''", "\\n", 1);
-  }
-  # process every other row
+    num_fields = csv_parse($0, row, ",", "\"", "''", "\\n", 1);
+    # get header row names
+    if (NR == 1) {
+        num_fields = csv_parse($0, col, ",", "\"", "''", "\\n", 1);
+    }
+    # process every other row
 	else {
-    # start with select text
+        # start with select text
 		printf "%s", "SELECT "

-    # iterate each column value
-    for (i = 1; i<=num_fields; i++) {
-      printf "%s", "'" row[i] "' AS '" col[i] "'"
+        # iterate each column value
+        for (i = 1; i<=num_fields; i++) {
+            printf "%s", "'" row[i] "' AS '" col[i] "'"

-      # add a comma except for last row
-      if (i < num_fields) printf "%s", ", "
-    }
+            # add a comma except for last row
+            if (i < num_fields) printf "%s", ", "
+        }

-    # nlines is the number of lines in the file
-    # so that we know when not to union
-		if (NR != nlines) print " UNION ALL"
-    else print "" # end with new line
+        # nlines is the number of lines in the file
+        # so that we know when not to union
+    	if (NR != nlines) print " UNION ALL"
+        else print "" # end with new line
 	}
 }


add processing for twiki

add processing for twiki

--- tools/hierarchy.awk
+++ tools/hierarchy.awk
@@ -38,6 +38,43 @@
     next
 }

+## this is for twiki conventions
+hunt && heading && /^<a\ name="/ {
+    hier[heading] = $0
+    sub(/<\/a>/, "", hier[heading])
+
+    if (heading == 2)
+    {
+      here = "⋅ " hier[heading]
+    }
+    else if (heading == 3)
+    {
+      here = "– " hier[heading]
+    }
+    else if (heading >= 4)
+    {
+      here = "— " hier[heading]
+    }
+    else
+    {
+      here = hier[heading]
+    }
+
+    if (slide) print "
"
+    print "
"
+    slide = 1
+    if (heading > 1) {
+      print "
" here "
"
+    }
+    for (i=1; i < heading; ++i) {
+      print "<h" i " style='color: #C0C0C0;'>" hier[i] "</h" i ">"
+    }
+    print "<h" heading ">" hier[heading]
+    hunt = 0
+    next
+}
+
+
 /
/ {
     heading = 1
     hunt = 1


Make convenience init's public

Make convenience init's public

--- Gtk-3.0.awk
+++ Gtk-3.0.awk
@@ -13,7 +13,7 @@
 /^[^ ]/ { slist = 0 }
 / UnsafeMutablePointer<GSList>! {/ {
 	slist = 1
-	gsub("UnsafeMutablePointer.GSList..", "SListRef?")
+	gsub("UnsafeMutablePointer.GSList..", "SListRef!")
 }
 /return cast.rv.$/ {
 	if (slist) {
@@ -45,7 +45,7 @@
 	print "    /// creating a new group."
 	print "    ///"
 	print "    /// - Parameter label: the label to use for the button"
-	print "    convenience init(label: UnsafePointer<gchar>) {"
+	print "    public convenience init(label: UnsafePointer<gchar>) {"
 	print "        let rv = gtk_radio_button_new_with_label(nil, label)"
 	print "        self.init(cast(rv))"
 	print "    }"
@@ -55,7 +55,7 @@
 	print "    /// indicate the mnemonic for the button."
 	print "    ///"
 	print "    /// - Parameter label: the label (including mnemonic) to use for the button"
-	print "    convenience init(mnemonic label: UnsafePointer<gchar>) {"
+	print "    public convenience init(mnemonic label: UnsafePointer<gchar>) {"
 	print "        let rv = gtk_radio_button_new_with_mnemonic(nil, label)"
 	print "        self.init(cast(rv))"
 	print "    }"
@@ -68,7 +68,7 @@
 	print "    /// creating a new group."
 	print "    ///"
 	print "    /// - Parameter label: the label to use for the button"
-	print "    convenience init(label: UnsafePointer<gchar>) {"
+	print "    public convenience init(label: UnsafePointer<gchar>) {"
 	print "        let rv = gtk_radio_menu_item_new_with_label(nil, label)"
 	print "        self.init(cast(rv))"
 	print "    }"
@@ -78,7 +78,7 @@
 	print "    /// indicate the mnemonic for the button."
 	print "    ///"
 	print "    /// - Parameter label: the label (including mnemonic) to use for the button"
-	print "    convenience init(mnemonic label: UnsafePointer<gchar>) {"
+	print "    public convenience init(mnemonic label: UnsafePointer<gchar>) {"
 	print "        let rv = gtk_radio_menu_item_new_with_mnemonic(nil, label)"
 	print "        self.init(cast(rv))"
 	print "    }"
@@ -88,7 +88,7 @@
 /^open class RadioToolButton:/ {
 	print
 	print "    /// Convenience constructor for creating a RadioToolButton group."
-	print "    convenience init() {"
+	print "    public convenience init() {"
 	print "        let rv = gtk_radio_tool_button_new(nil)"
 	print "        self.init(cast(rv))"
 	print "    }"


Remove no longer needed doxygen-related awk functions. (dm)

git-svn-id: 30a5f035a20f1bc647618dbad7eea2a951b61b7c@2834 91a5dbb7-01b9-0310-9b5f-b28072856b6e

--- Programs/brldefs.awk
+++ Programs/brldefs.awk
@@ -124,21 +124,9 @@
   return "/** " text " */"
 }

-function beginDoxygenFile(brief) {
+function beginDoxygenFile() {
   print "/** \\file"
-  print " * \\brief " brief
   print " */"
-  print ""
-}
-
-function beginDoxygenGroup(name, brief) {
-  print "/** \\defgroup " name " " brief
-  print " * @{ */"
-  print ""
-}
-
-function endDoxygenGroup() {
-  print "/** @} */"
   print ""
 }


Don't fail on build warnings

Don't fail on build warnings

--- xcodebuild.awk
+++ xcodebuild.awk
@@ -19,7 +19,6 @@

 /[0-9]+: (error|warning):/ {
     errors = errors $0 "\n";
-    status = 1;
 }

 /(TEST|BUILD) FAILED/ {


var/mapr: BUGFIX: avoid infinite loop on empty input

lib/modernish/aux/var/mapr.awk:
- If the input was empty, the awk helper script didn't write the
  expected _Msh_M_NR=RET0 shell assignment, because the NR awk
  variable (number of records) never exceeded 0. This resulted in
  lib/modernish/mdl/aux/mapr.mm calling awk in an infinite loop.
  The fix is to write the assignment regardless of the value of NR.
- While we're at it, do this in a more efficient way, in one line
  instead of five.

--- lib/modernish/aux/var/mapr.awk
+++ lib/modernish/aux/var/mapr.awk
@@ -115,10 +115,6 @@
 END {
 	if (NR) {
 		printsh("||_Msh_mapr_ckE \"$@\"||break");
-		if (cont) {
-			print ("\n_Msh_M_NR=") (NR+1) ("\n");
-		} else {
-			print ("\n_Msh_M_NR=RET0") ("\n");
-		}
 	}
+	print ("\n_Msh_M_NR=") (cont ? NR + 1 : "RET0") ("\n");
 }


This has been rewritten in perl as parse_structinfo.pl

ok miod@

--- ddb/parse_structinfo.awk
+++ ddb/parse_structinfo.awk
@@ -1,318 +0,0 @@
-#	$OpenBSD: parse_structinfo.awk,v 1.1 2009/08/09 23:04:49 miod Exp $
-#
-# Copyright (c) 2009 Miodrag Vallat.
-#
-# Permission to use, copy, modify, and distribute this software for any
-# purpose with or without fee is hereby granted, provided that the above
-# copyright notice and this permission notice appear in all copies.
-#
-# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
-# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
-# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
-# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-#
-
-# This ugly script parses the output of objdump -g in order to extract
-# structure layout information, to be used by ddb.
-#
-# The output of this script is the following static data:
-# - for each struct:
-#   - its name
-#   - its size (individual element size if an array)
-#   - the number of elements in the array (1 if not)
-#   - its first and last field indexes
-# - for each field:
-#   - its name
-#   - its offset and size
-#   - the index of the struct it is member of
-# This allows fast struct -> field information retrieval.
-#
-# To retrieve information from a field size or offset, we also output
-# the following reverse arrays:
-# - for each offset, in ascending order, a variable length list of field
-#   indexes.
-# - for each size, in ascending order, a variable length list of field
-#   indexes.
-#
-# The compromise here is that I want to minimize linear searches. Memory
-# use is considered secondary, hence the back `pointer' to the struct in the
-# fields array.
-#
-# No attempt is made to share name pointers when multiple fields share
-# the same name. Rewriting this script in perl, or any other language
-# with hash data structures, would be a good time to add this.
-
-BEGIN {
-	depth = 0;
-	ignore = 0;
-	scnt = 0;	# current struct count
-	sidx = -1;	# current struct index
-	# field index #0 is used as a sentinel.
-	fcnt = 1;	# current field count
-	fidx = 0;	# current field index
-	ocnt = 0;	# current offset count
-	zcnt = 0;	# current size count
-
-}
-/^struct / {
-	depth = 1;
-	sidx = scnt;
-	sname[sidx] = $2;
-	ssize[sidx] = $6;
-	sfieldmin[sidx] = fcnt;
-	scnt++;
-	#printf("struct %d %s (size %d)\n", sidx, $2, $6);
-	next;
-}
-/^};/ {
-	if (depth != 0) {
-		depth = 0;
-		if (fcnt == sfieldmin[sidx])	# empty struct, ignore it
-			scnt--;
-		else
-			sfieldmax[sidx] = fidx;
-	} else
-		ignore--;
-	next;
-}
-/{.*}/ {
-	# single line enum
-	next;
-}
-/{/ {
-	# subcomponent
-	if (depth != 0) {
-		depth++;
-	} else {
-		ignore++;
-	}
-	next;
-}
-/}/ {
-	if (ignore != 0) {
-		ignore--;
-		next;
-	} else {
-		depth--;
-	}
-	if (depth != 1)
-		next;
-	# FALLTHROUGH
-}
-/bitsize/ {
-	if (ignore != 0)
-		next;
-	if (depth != 1)
-		next;
-
-	# Bitfields are a PITA... From a ddb point of view, we can't really
-	# access storage units smaller than a byte.
-	# So we'll report all bitfields as having size 0, and the
-	# rounded down byte position where they start.
-	cursize = int($(NF - 3));
-	curoffs = int($(NF - 1) / 8);
-	if ((cursize % 8) != 0)
-		cursize = 0;
-	else
-		cursize /= 8;
-
-	# try and gather the field name.
-	field = $(NF - 6);
-	if (field == "};") {
-		# anonymous union. discard it.
-		next;
-	}
-	if (field == "*/);") {
-		field = $(NF - 9);	# function pointer
-		# remove enclosing braces
-		field = substr(field, 2, length(field) - 2);
-	}
-	colon = index(field, ":");
-	if (colon != 0)
-		field = substr(field, 1, colon - 1);
-	else if (substr(field, length(field), 1) == ";")
-		field = substr(field, 1, length(field) - 1);
-
-	while (index(field, "*") == 1)
-		field = substr(field, 2);
-
-	# This could be an array. If it is, we need to trim the field
-	# name and update its size to a single member size.
-	obracket = index(field, "[");
-	cbracket = index(field, "]");
-	if (obracket != 0) {
-		obracket++;
-		nitems = substr(field, obracket, cbracket - obracket);
-		field = substr(field, 1, obracket - 2);
-		cursize /= nitems;
-	} else
-		nitems = 1;
-
-	fidx = fcnt;
-	fname[fidx] = field;
-	foffs[fidx] = curoffs;
-	fsize[fidx] = cursize;
-	fitems[fidx] = nitems;
-	fstruct[fidx] = sidx;
-	fcnt++;
-	#printf("  %s at %d len %d\n", field, curoffs, cursize);
-
-	# Remember size and offset if not found yet
-
-	for (i = 0; i < ocnt; i++)
-		if (offs[i] == curoffs)
-			break;
-	if (i == ocnt) {
-		# keep array sorted
-		for (i = 0; i < ocnt; i++)
-			if (offs[i] > curoffs)
-				break;
-		if (i < ocnt) {
-			for (j = ocnt + 1; j > i; j--)
-				offs[j] = offs[j - 1];
-		}
-		offs[i] = curoffs;
-		ocnt++;
-	}
-
-	for (i = 0; i < zcnt; i++)
-		if (sizes[i] == cursize)
-			break;
-	if (i == zcnt) {
-		# keep array sorted
-		for (i = 0; i < zcnt; i++)
-			if (sizes[i] > cursize)
-				break;
-		if (i < zcnt) {
-			for (j = zcnt + 1; j > i; j--)
-				sizes[j] = sizes[j - 1];
-		}
-		sizes[i] = cursize;
-		zcnt++;
-	}
-}
-END {
-	printf("/*\n");
-	printf(" * THIS IS A GENERATED FILE.  DO NOT EDIT!\n");
-	printf(" */\n\n");
-
-	printf("#include <sys/param.h>\n");
-	printf("#include <sys/types.h>\n");
-	printf("\n");
-
-	# structure definitions
-
-	printf("struct ddb_struct_info {\n");
-	printf("\tconst char *name;\n");
-	printf("\tsize_t size;\n");
-	printf("\tuint fmin, fmax;\n");
-	printf("};\n");
-
-	printf("struct ddb_field_info {\n");
-	printf("\tconst char *name;\n");
-	printf("\tuint sidx;\n");
-	printf("\tsize_t offs;\n");
-	printf("\tsize_t size;\n");
-	printf("\tuint nitems;\n");
-	printf("};\n");
-
-	printf("struct ddb_field_offsets {\n");
-	printf("\tsize_t offs;\n");
-	printf("\tconst uint *list;\n");
-	printf("};\n");
-
-	printf("struct ddb_field_sizes {\n");
-	printf("\tsize_t size;\n");
-	printf("\tconst uint *list;\n");
-	printf("};\n");
-
-	# forward arrays
-
-	printf("#define NSTRUCT %d\n", scnt);
-	printf("static const struct ddb_struct_info ddb_struct_info[NSTRUCT] = {\n");
-	for (i = 0; i < scnt; i++) {
-		printf("\t{ \"%s\", %d, %d, %d },\n",
-		    sname[i], ssize[i], sfieldmin[i], sfieldmax[i]);
-	}
-	printf("};\n\n");
-
-	printf("#define NFIELD %d\n", fcnt);
-	printf("static const struct ddb_field_info ddb_field_info[NFIELD] = {\n");
-	printf("\t{ NULL, 0, 0, 0 },\n");
-	for (i = 1; i < fcnt; i++) {
-		printf("\t{ \"%s\", %d, %d, %d, %d },\n",
-		    fname[i], fstruct[i], foffs[i], fsize[i], fitems[i]);
-	}
-	printf("};\n\n");
-
-	# reverse arrays
-
-	printf("static const uint ddb_fields_by_offset[] = {\n");
-	w = 0;
-	for (i = 0; i < ocnt; i++) {
-		cmp = offs[i];
-		ohead[i] = w;
-		for (f = 1; f < fcnt; f++)
-			if (foffs[f] == cmp) {
-				if ((w % 10) == 0)
-					printf("\t");
-				printf("%d, ", f);
-				w++;
-				if ((w % 10) == 0)
-					printf("\n");
-			}
-		if ((w % 10) == 0)
-			printf("\t");
-		printf("0, ");
-		w++;
-		if ((w % 10) == 0)
-			printf("\n");
-	}
-	if ((w % 10) != 0)
-		printf("\n");
-	printf("};\n\n");
-
-	printf("#define NOFFS %d\n", ocnt);
-	printf("static const struct ddb_field_offsets ddb_field_offsets[NOFFS] = {\n");
-	for (i = 0; i < ocnt; i++) {
-		printf("\t{ %d, ddb_fields_by_offset + %d },\n",
-		    offs[i], ohead[i]);
-	}
-	printf("};\n\n");
-
-	printf("static const uint ddb_fields_by_size[] = {\n");
-	w = 0;
-	for (i = 0; i < zcnt; i++) {
-		cmp = sizes[i];
-		zhead[i] = w;
-		for (f = 1; f < fcnt; f++)
-			if (fsize[f] == cmp) {
-				if ((w % 10) == 0)
-					printf("\t");
-				printf("%d, ", f);
-				w++;
-				if ((w % 10) == 0)
-					printf("\n");
-			}
-		if ((w % 10) == 0)
-			printf("\t");
-		printf("0, ");
-		w++;
-		if ((w % 10) == 0)
-			printf("\n");
-	}
-	if ((w % 10) != 0)
-		printf("\n");
-	printf("};\n\n");
-
-	printf("#define NSIZES %d\n", zcnt);
-	printf("static const struct ddb_field_sizes ddb_field_sizes[NSIZES] = {\n");
-	for (i = 0; i < zcnt; i++) {
-		printf("\t{ %d, ddb_fields_by_size + %d },\n",
-		    sizes[i], zhead[i]);
-	}
-	printf("};\n");
-}


Help: getVersion(): use 'uname -s' (-o is not a valid option on OS X)

--- include/Help.awk
+++ include/Help.awk
@@ -6,7 +6,7 @@
 function getVersion(    build, gitHead, platform) {
     initAudioPlayer()
     initPager()
-    platform = detectProgram("uname", "-o", 1)
+    platform = detectProgram("uname", "-s", 1)
     if (ENVIRON["TRANS_BUILD"])
         build = "-" ENVIRON["TRANS_BUILD"]
     else {


ndc hardcodes 'named' instead of using $named_program from rc.conf

PR:		7425
Reviewed by:	phk
Submitted by:	frf <frf@xocolatl.com>

--- usr.sbin/ndc/ndcedit.awk
+++ usr.sbin/ndc/ndcedit.awk
@@ -1,4 +1,4 @@
-# $Id: ndcedit.awk,v 1.6 1997/06/18 01:55:19 jkh Exp $
+# $Id: ndcedit.awk,v 1.7 1998/05/03 05:14:04 peter Exp $
 NR == 3 {
 	print "#"
 	print "# This file is generated automatically, do not edit it here!"
@@ -15,7 +15,7 @@
 	if ($1 == "named") {
 		printf "\t\t# $named_flags is imported from /etc/rc.conf\n"
 		printf "\t\tif [ \"X${named_enable}\" = X\"YES\" ]; then\n"
-		printf "\t\t\tnamed ${named_flags} && {\n"
+		printf "\t\t\t${named_program} ${named_flags} && {\n"
 		getline
 		printf "\t%s\n", $0
 		getline


Changing back to "sleep 1"

Changing back to "sleep 1"

--- mockping.awk
+++ mockping.awk
@@ -34,6 +34,6 @@

 	for (i = 0; i < LEN; i++) {
 		print ARRAY[i]
-		system("sleep 0")
+		system("sleep 1")
 	}
 }


Error for no seasons in MHz

Error for no seasons in MHz

--- getMHzFrom-browsePage.awk
+++ getMHzFrom-browsePage.awk
@@ -34,6 +34,8 @@
 /h4 class="transparent.*media-count/ {
     sub (/.*media-count'>/,"")
     sub (/ season.*$/,"")
+    if ((numSeasons + 0) == 0)
+        print "==> No seasons: " TITLE >> ERROR_FILE
     print $0 >> NUM_SEASONS_FILE
 }


works with Apples variable column count

works with Apples variable column count

--- report.awk
+++ report.awk
@@ -6,12 +6,10 @@
 BEGIN {
 	FS=",";
   sum = 0;
-  targetCurrency = "";
 }

 # first line
-match($0, /iTunes Connect - Payments and Financial Reports/){
-
+(NR == 1) {
   strContainingPeriod = unquote($0);
   periodParanthesisOpen = index(strContainingPeriod, "(");
   periodParanthesisClose = index(strContainingPeriod, ")");
@@ -21,12 +19,28 @@
   printf "Region oder Typ & Stückzahl & Gesamtpreis & Quellensteuern und Abgaben & Gesamtpreis \\\\ \\hline \\hline\n";
 }

-match($3, /\"[0-9]*\.[0-9]+\"/) {
-  regionOrType = unquote($1);
-  localCurrency = substr(regionOrType, index(regionOrType, "(") + 1, 3);
-  targetCurrency = unquote($11);
-  printf "%s & %i & %.2f %s & %.2f %s & %.2f %s \\\\ \\hline \n", regionOrType, unquote($2), unquote($4), localCurrency, unquote($5) + unquote($6) + unquote($7), localCurrency, unquote($10), targetCurrency;
-  sum += unquote($10);
+# column labels
+(NR == 3) {
+	for (i = 1; i <= NF; i++) {
+		col[$i] = i;
+	}
+}
+
+(NR > 3) {
+	unitsSold = unquote($col["Units Sold"]);
+	if (length(unitsSold) > 0 && (unitsSold > 0 || unitsSold == "-")) {
+	  regionOrType = unquote($col["Region (Currency)"]);
+	  localCurrency = substr(regionOrType, index(regionOrType, "(") + 1, 3);
+		earned = unquote($col["Earned"]);
+		inputTax = unquote($col["Input Tax"]);
+		adjustments = unquote($col["Adjustments"]);
+		withholdingTax = unquote($col["Withholding Tax"]);
+		taxTotal = inputTax + adjustments + withholdingTax;
+		proceeds = unquote($col["Proceeds"]);
+		targetCurrency = unquote($col["Bank Account Currency"]);
+	  printf "%s & %s & %.2f %s & %.2f %s & %.2f %s \\\\ \\hline \n", regionOrType, unitsSold, earned, localCurrency, taxTotal, localCurrency, proceeds, targetCurrency;
+	  sum += proceeds;
+	}
 }

 END {


fixed bug that incorrect computed dash times

--- lib/dash_utils.awk
+++ lib/dash_utils.awk
@@ -56,12 +56,12 @@

 function DU_job_in_dash(b_job, e_job, b_dash, e_dash,   bj_min, ej_min, bd_min, ed_min) {

-	bj_min = 60 * substr(b_job, 1, 2) + substr(b_job, 3, 2)
+	bj_min = 60 * substr(b_job, 1, 2) + substr(b_job, 4, 2)
 	if(e_job != "")
-		ej_min = 60 * substr(e_job, 1, 2) + substr(e_job, 3, 2)
+		ej_min = 60 * substr(e_job, 1, 2) + substr(e_job, 4, 2)

-	bd_min = 60 * substr(b_dash, 1, 2) + substr(b_dash, 3, 2)
-	ed_min = 60 * substr(e_dash, 1, 2) + substr(e_dash, 3, 2)
+	bd_min = 60 * substr(b_dash, 1, 2) + substr(b_dash, 4, 2)
+	ed_min = 60 * substr(e_dash, 1, 2) + substr(e_dash, 4, 2)

 	if(e_job != "")
 		return bj_min >= bd_min && ej_min <= ed_min


Languages: add Interlingue language

Languages: add Interlingue language

--- include/Languages.awk
+++ include/Languages.awk
@@ -130,6 +130,19 @@
     Locale["gn"]["iso"]                = "grn"
     Locale["gn"]["glotto"]             = "para1311"
     Locale["gn"]["script"]             = "Latn"
+
+    #? Interlingue
+    Locale["ie"]["name"]               = "Interlingue"
+    Locale["ie"]["endonym"]            = "Interlingue"
+    #Locale["ie"]["translations-of"]
+    #Locale["ie"]["definitions-of"]
+    #Locale["ie"]["synonyms"]
+    #Locale["ie"]["examples"]
+    #Locale["ie"]["see-also"]
+    Locale["ie"]["family"]             = "Artificial Language"
+    Locale["ie"]["iso"]                = "ile"
+    Locale["ie"]["glotto"]             = "occi1241"
+    Locale["ie"]["script"]             = "Latn"

     #1 Afrikaans
     Locale["af"]["name"]               = "Afrikaans"


very basic color legend; &tabs2spaces

very basic color legend; &tabs2spaces

--- scripts/deltadot.awk
+++ scripts/deltadot.awk
@@ -34,59 +34,76 @@
     n = match($0, / [(][[:digit:]]*[)]>];$/)
     if(n>0)
         arr[substr($0,1,n)] = substr($0, n+2, length($0)-n-5)
-	else
-		arr[$1 " " $2 " " $3 " "]++
+    else
+        arr[$1 " " $2 " " $3 " "]++
 }

 # strip metadata from filename
 function de_path_ext(pth){
-	split(pth, a, "/")
-	return substr(a[length(a)], 1, index(a[length(a)], ".")-1)
+    split(pth, a, "/")
+    return substr(a[length(a)], 1, index(a[length(a)], ".")-1)
 }

-BEGIN { NOCOUNTS=0}
+BEGIN {
+    NOCOUNTS=0
+    DFLT="black"
+    GAIN="blue"
+    DROP="orange"
+    LESS="pink"
+}

 # collect the edges from both files
 NR==FNR && /^[^ ]+ -> [^ ]+ / {
-	label1 = FILENAME;
-	parse($0, edge1)
+    label1 = FILENAME;
+    parse($0, edge1)
 }
 NR!=FNR && /^[^ ]+ -> [^ ]+ / {
-	label2 = FILENAME;
-	parse($0, edge2)
+    label2 = FILENAME;
+    parse($0, edge2)
 }

 END{
-	for(e in edge1){
-		if(!(e in edge2)) edges[e "(" edge1[e] ")>, color=\"orange\"];"];
-		else {
-			# edge is in both graphs
-			if(NOCOUNTS)
-				edges[e "()>, color=\"black\"];"]
-			else {
-				diff = edge2[e] - edge1[e];
-				if(diff < 0)
-					# diff = "" diff "" #  breaks svg
-					edges[e "(" diff ")>, color=\"pink\"];"]
-				else
-					edges[e "(" diff ")>, color=\"black\"];"]
-			}
-			delete edge2[e]
-		}
-	}
-	# only edges not in first file
-	for(e in edge2)
-		edges[e "(" edge2[e] ")>, color=\"blue\"];"];  # expects label=<tag> to close
+    for(e in edge1){
+        if(!(e in edge2)) edges[e "(-" edge1[e] ")>, color=\"" DROP "\"];"];
+        else {
+            # edge is in both graphs
+            if(NOCOUNTS)
+                edges[e "()>, color=\"" DELT "\"];"]
+            else {
+                diff = edge2[e] - edge1[e];
+                if(diff < 0)
+                    # diff = "" diff "" #  breaks svg
+                    edges[e "(" diff ")>, color=\"" DROP "\"];"]
+                else
+                    edges[e "(" diff ")>, color=\"" DFLT "\"];"]
+            }
+            delete edge2[e]
+        }
+    }
+    # only edges not in first file
+    for(e in edge2)
+        edges[e "(" edge2[e] ")>, color=\"" GAIN "\"];"];  # expects label=<tag> to close

-	print "digraph {"
-	print "rankdir=LR;"
-	print "charset=\"utf-8\";"
-	print "LITERAL [shape=record];"
-	print "labelloc=\"t\";"
-	print "label=\"" de_path_ext(label1) " <=> " de_path_ext(label2) "\""
+    print "digraph {"
+    print "rankdir=LR;"
+    print "charset=\"utf-8\";"
+    print "LITERAL [shape=record];"
+    print "labelloc=\"t\";"
+    print "label=\"" de_path_ext(label1) " <=> " de_path_ext(label2) "\""

-	n = asorti(edges,output)
-	for(i=1;i<=n;i++ ){print output[i]}
-	print "\n}\n"
+    n = asorti(edges,output)
+    for(i=1;i<=n;i++ ){print output[i]}
+
+    # include a Legend  rank [min,max,sink]
+    print "\n\tnode[shape=plaintext];\n\tsubgraph cluster_key{rank=max;label=\"Color Legend\";"
+    print "\tdflt [label=< Typical Case >];"
+    print "\tgain [label=< New Edge >];"
+    print "\tdrop [label=< Lost Edge >];"
+    print "\tless [label=< Diminished Count >];"
+    print "\tdflt -> dflt [color=\"" DFLT "\"];"
+    print "\tgain -> gain [color=\"" GAIN "\"];"
+    print "\tdrop -> drop [color=\"" DROP "\"];"
+    print "\tless -> less [color=\"" LESS "\"];"
+
+    print "\t}\n}\n"
 }
-


Languages: update

Languages: update

--- include/Languages.awk
+++ include/Languages.awk
@@ -1301,7 +1301,7 @@
 # Detect external bidirectional algorithm utility (fribidi);
 # Fallback to Unix `rev` if not found.
 function initBiDi() {
-    "fribidi --version 2>/dev/null" |& getline FriBidi
+    "fribidi --version" SUPERR |& getline FriBidi
     BiDiNoPad = FriBidi ? "fribidi --nopad" : "rev"
     BiDi = FriBidi ? "fribidi --width %s" : "rev | sed \"s/'/\\\\\\'/\" | xargs printf '%%s '"
 }


Accept underscores in path names.

Accept underscores in path names.

--- tests/genmain.awk
+++ tests/genmain.awk
@@ -31,7 +31,7 @@
 {
     suitename = $2;
     sub("^.*tests/", "", suitename);
-    sub("/[a-z0-9-]+\\.c$", "", suitename);
+    sub("/[_a-z0-9-]+\\.c$", "", suitename);
     testname = $1;
     sub("test_", "", testname);


Improve robustness for poor data

Improve robustness for poor data

If a block is incomplete, don't print partial data

--- vwinfo-pivot.awk
+++ vwinfo-pivot.awk
@@ -40,10 +40,6 @@
 #2016-04-26 10:56:23,7626673992,9839545026,21,51811414
 #2016-04-26 11:00:06,13600321807,7441402489,3,25461059
 #2016-04-26 11:26:26,8259696240,12566530678,3,34660155
-
-# Note that for loading into Excel, the date format needs adjusting before it will be
-# recognised properly. Excel likes data like this : 10/Mar/2016 HH:MM:SS
-

 BEGIN {
@@ -110,14 +106,14 @@
 	fields["%log"]  = (fields["log_file_size"]/fields["threshold_log_condense"])*100;
 	fields["%memcontext"] = (fields["memcontext_allocated"]/fields["memcontext_maximum"])*100;

+	# Only print the row if there is decent data. Log condense threshold value is never really 1.
+	if (fields["threshold_log_condense"] > 1 ) {
+		# Start printing the output record for this block of time
+		printf record_date;

-	# Start printing the output record for this block of time
-	printf record_date;
+		for (field in fields) printf ",%d", fields[field];

-	for (field in fields) {
-		printf ",%d", fields[field];
+		# Cleanly terminate each line
+		printf "\r\n";
 	}
-
-	# Cleanly terminate each line
-	printf "\r\n";
 }


check for vendor name dups

check for vendor name dups

--- dev/pci/devlist2h.awk
+++ dev/pci/devlist2h.awk
@@ -1,5 +1,5 @@
 #! /usr/bin/awk -f
-#	$OpenBSD: devlist2h.awk,v 1.3 1997/11/07 08:07:26 niklas Exp $
+#	$OpenBSD: devlist2h.awk,v 1.4 1998/07/21 20:35:18 mickey Exp $
 #	$NetBSD: devlist2h.awk,v 1.2 1996/01/22 21:08:09 cgd Exp $
 #
 # Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 BEGIN {
-	nproducts = nvendors = 0
+	nproducts = nvendor_dup = nvendors = 0
 	dfile="pcidevs_data.h"
 	hfile="pcidevs.h"
 }
@@ -60,6 +60,11 @@
 $1 == "vendor" {
 	nvendors++

+	if ($2 in vendorindex) {
+		printf("duplicate vendor name %s\n", $2);
+		nvendor_dup++;
+	}
+
 	vendorindex[$2] = nvendors;		# record index for this name, for later.
 	vendors[nvendors, 1] = $2;		# name
 	vendors[nvendors, 2] = $3;		# id
@@ -158,6 +163,9 @@
 	# print out the match tables

 	printf("\n") > dfile
+
+	if (nvendor_dup > 0)
+		exit(1);

 	printf("struct pci_knowndev pci_knowndevs[] = {\n") > dfile
 	for (i = 1; i <= nproducts; i++) {


rnc2rng: Properly handle things with - in the name

--- rnc2rng.awk
+++ rnc2rng.awk
@@ -267,7 +267,7 @@
     stack[++stack_i] = "<anyName>";
     parse_name_class(substr(line, 2));
   }
-  else if (c == "-") {
+  else if (c == "-" && stack[stack_i] == "<anyName>") {
     stack[++stack_i] = "<except>"
     parse_name_class(substr(line, 2));
   }
@@ -310,7 +310,7 @@
   }
   else if (match(line, /^[A-Za-z_]/)) {
     name = substr(line, 1);
-    sub(/[^A-Za-z_]+.*/, "", name);
+    sub(/[^A-Za-z_-]+.*/, "", name);
     if (length(line) >= length(name) + 1)
       aft = substr(line, length(name) + 1);
     else


Fixing awk --lint errors on rnc2rng.awk

Fixing awk --lint errors on rnc2rng.awk

--- rng/mallard/rnc2rng.awk
+++ rng/mallard/rnc2rng.awk
@@ -1,5 +1,5 @@
 #!/bin/awk
-# -*- indent-tabs-mode: nil -*-
+# -*- indent-tabs-mode: nil; c-basic-offset: 2 -*-
 # rnc2rng.awk - Convert RELAX NG Compact Syntax to XML Syntax
 # Copyright (C) 2007 Shaun McCance <shaunm@gnome.org>
 #
@@ -34,11 +34,13 @@

 function parse_pattern (line) {
   sub(/^ */, "", line)
+  if (length(line) == 0) return;
   c = substr(line, 1, 1);
   if (c == "(" || c == "{") {
     stack[++stack_i] = substr(line, 1, 1);
     paren[++paren_i] = stack_i;
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == ")" || c == "}") {
     open = stack[paren[paren_i]];
@@ -75,7 +77,7 @@
     paren_i--;

     if (oc == "{}") {
-      if (substr(stack[stack_i - 1], 1, 8) == "<element") {
+      if (match(stack[stack_i - 1], "^<element")) {
         tmp = stack[stack_i - 1] "\n";
         if (stack[stack_i] != "") {
           tmp = tmp stack[stack_i] "\n";
@@ -85,7 +87,7 @@
         tmp = tmp "</element>";
         stack[--stack_i] = tmp;
       }
-      else if (substr(stack[stack_i - 1], 1, 10) == "<attribute") {
+      else if (match(stack[stack_i - 1], "^<attribute")) {
         tmp = stack[stack_i - 1] "\n";
         if (stack[stack_i] != "") {
           tmp = tmp stack[stack_i] "\n";
@@ -111,38 +113,44 @@
     if (paren_i == 0) {
       mode = "grammar";
     }
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == "|" || c == "&" || c == ",") {
     if (length(stack[paren[paren_i]]) == 1) {
       stack[paren[paren_i]] = stack[paren[paren_i]] c;
     }
-    else if (substr(stack[paren[paren_i]], 2) != c) {
+    else if (length(stack[paren[paren_i]]) < 2 || substr(stack[paren[paren_i]], 2) != c) {
       print "Mismatched infix operators on line " FNR | "cat 1>&2";
       error = 1;
       exit 1
     }
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == "?") {
     stack[stack_i] = "<optional>" stack[stack_i] "</optional>"
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == "*") {
     stack[stack_i] = "<zeroOrMore>" stack[stack_i] "</zeroOrMore>"
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == "+") {
     stack[stack_i] = "<oneOrMore>" stack[stack_i] "</oneOrMore>"
-    parse_pattern(substr(line, 2));
+    if (length(line) >= 2)
+      parse_pattern(substr(line, 2));
   }
   else if (c == "\"") {
     txt = substr(line, 2);
     sub(/".*/, "", txt)
     stack[++stack_i] = "<value>" txt "</value>";
-    parse_pattern(substr(line, length(txt) + 3));
-  }
-  else if (substr(line, 1, 8) == "element ") {
+    if (length(line) >= length(txt) + 3)
+      parse_pattern(substr(line, length(txt) + 3));
+  }
+  else if (match(line, "^element ")) {
     aft = substr(line, 8);
     sub(/^ */, "", aft);
     name = aft;
@@ -151,7 +159,7 @@
     name_class_i = stack_i;
     parse_name_class(name);
   }
-  else if (substr(line, 1, 10) == "attribute ") {
+  else if (match(line, "^attribute ")) {
     aft = substr(line, 10);
     sub(/^ */, "", aft);
     name = aft;
@@ -160,13 +168,13 @@
     name_class_i = stack_i;
     parse_name_class(name);
   }
-  else if (substr(line, 1, 5) == "list ") {
+  else if (match(line, "^list ")) {
     aft = substr(line, 5);
     sub(/^ */, "", aft);
     stack[++stack_i] = "<list>";
     if (aft != "") { parse_pattern(aft); }
   }
-  else if (substr(line, 1, 6) == "mixed ") {
+  else if (match(line, "^mixed ")) {
     aft = substr(line, 6);
     sub(/^ */, "", aft);
     stack[++stack_i] = "<mixed>";
@@ -178,17 +186,17 @@
     sub(/^ */, "", aft);
     if (aft != "") { parse_pattern(aft); }
   }
-  else if (substr(line, 1, 18) == "default namespace ") {
+  else if (match(line, "^default namespace ")) {
     print "default namespace appeared out of context on line " FNR | "cat 1>&2";
     error = 1;
     exit 1
   }
-  else if (substr(line, 1, 10) == "namespace ") {
+  else if (match(line, "^namespace ")) {
     print "namespace appeared out of context on line " FNR | "cat 1>&2";
     error = 1;
     exit 1
   }
-  else if (substr(line, 1, 6) == "start ") {
+  else if (match(line, "^start ")) {
     print "start appeared out of context on line " FNR | "cat 1>&2";
     error = 1;
     exit 1
@@ -197,17 +205,21 @@
     name = substr(line, 1);
     sub(/^xsd:/, "", name);
     sub(/[^A-Za-z_]+.*/, "", name);
-    aft = substr(line, length(name) + 5);
     stack[++stack_i] = sprintf("<data type='%s' datatypeLibrary='http://www.w3.org/2001/XMLSchema-datatypes'/>",
                                name);
-    parse_pattern(aft);
+    if (length(line) >= length(name) + 5) {
+      aft = substr(line, length(name) + 5);
+      parse_pattern(aft);
+    }
   }
   else if (match(line, /^[A-Za-z_]/)) {
     name = substr(line, 1);
     sub(/[^A-Za-z_]+.*/, "", name);
-    aft = substr(line, length(name) + 1);
     stack[++stack_i] = sprintf("<ref name='%s'/>", name);
-    parse_pattern(aft);
+    if (length(line) >= length(name) + 1) {
+      aft = substr(line, length(name) + 1);
+      parse_pattern(aft);
+    }
   }
 }

@@ -335,6 +347,7 @@
   stack_i = 0;
   paren_i = 0;
   namespaces_i = 0;
+  error = 0;
 }

 END {
@@ -355,9 +368,7 @@

 mode == "pattern" && paren_i == 0 && /.*=/ { mode = "grammar"; }
 mode == "grammar" && /.*=/ {
-  name = substr($0, 1, index($0, "=") - 1);
-  sub(/ /, "", name);
-  if (substr($0, 1, 18) == "default namespace ") {
+  if (match($0, "^default namespace ")) {
     namespace = substr($0, index($0, "=") + 1);
     nsname = substr($0, 19, index($0, "=") - 19);
     sub(/^ */, "", nsname);
@@ -370,7 +381,7 @@
     }
     default_namespace = namespace
   }
-  else if (substr($0, 1, 10) == "namespace ") {
+  else if (match($0, "^namespace ")) {
     namespace = substr($0, index($0, "=") + 1);
     nsname = substr($0, 11, index($0, "=") - 11);
     sub(/^ */, "", nsname);
@@ -382,15 +393,18 @@
       namespaces[namespaces_i] = namespace;
     }
   }
-  else if (name == "start") {
-    stack[++stack_i] = "<start>"
+  else {
+    nameix = index($0, "=");
+    if (nameix < 1) next;
+    name = substr($0, 1, nameix - 1);
+    sub(/ /, "", name);
+    if (name == "start")
+      stack[++stack_i] = "<start>"
+    else
+      stack[++stack_i] = sprintf("<define name='%s'>", name);
     mode = "pattern";
-    parse_pattern(substr($0, index($0, "=") + 1))
-  }
-  else {
-    stack[++stack_i] = sprintf("<define name='%s'>", name);
-    mode = "pattern";
-    parse_pattern(substr($0, index($0, "=") + 1))
+    if (length($0) >= nameix + 1)
+      parse_pattern(substr($0, nameix + 1))
   }
   next;
 }


add swap command to repl

add swap command to repl

--- include/REPL.awk
+++ include/REPL.awk
@@ -147,6 +147,10 @@
     } else if (command ~ /^:show$/) {
         name = words[2]
         print prettify("welcome-submessage", toString(Option[name], 1, 0, 1))
+    } else if (command ~ /^:swap$/) {
+        tl = Option["tl"][1]
+        Option["tl"][1] = Option["sls"][1]
+        Option["sls"][1] = tl
     } else if (command ~ /^:engine$/) {
         value = words[2]
         Option["engine"] = value