Also considers introduced var arrays now


some simplifications, checkpoint

some simplifications, checkpoint

BEGIN {
  print "%TCIDATA{Version=5.00.0.2606}";
  print "%TCIDATA{LaTeXparent=0,0,classes.tex}";
  print "                      ";
  print "";
  print "%%%%% BEGINNING OF DOCUMENT BODY %%%%%";
  print "% html: Beginning of file: `clean.html'";
  print "% DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"";
  print "%  This is a (PRE) block.  Make sure it's left aligned or your toc title will be off. ";
  print "";
  quoting = 0;
  itemizing = 0;
  coding = 0;
}

END {
  print "% html: End of file: `clean.html'";
  print "";
  print "%%%%% END OF DOCUMENT BODY %%%%%";
  print "% In the future, we might want to put some additional data here, such";
  print "% as when the documentation was converted from wiki to TeX.";
  print "%";
}

{ origLine = $0; }

## HANDLE CODING
## make sure that control sequences are always at the front
/ *{{{/ { sub(/ */, "") }
/ *}}}/ { sub(/ */, "") }

!coding && /^{{{/ {

  if (quoting) {
    print "\\end{quotation}";
    print ""
    quoting = 0;
  }

  print "\\begin{verbatim}";
  coding = 1;
  next;
}

coding && /^}}}/ {
  sub(/}}}.*$/, "", origLine);
  if (origLine) {
    print origLine
    ##print "{\\small " origLine
    ##print "}"
  }
  print "\\end{verbatim}";
  print ""
  coding = 0;
  next;
}

coding {
  ## sub(/^/, "{\\small ");
  print;
  ## print "}";
  next;
}

## NO CODING BELOW THIS POINT
coding { print "###code???####"; next; }

## pragmas do not count
/^\#labels/ {
  next;
}

## make sure that control sequences are always at the front
/^ *=/ { sub(/^ *=/, "=") }

## check itemness
{ inItem = 0 }
/^   *\*/ {
  inItem = 1
  ## print " ########## ITEM"
}

itemizing && !inItem {
  print "\\end{itemize}";
  print "";
  itemizing = 0;
}

## quoting stops when item appears
## or not indented any more
quoting && (inItem || !/^ /) {
  print "\\end{quotation}";
  print ""
  quoting = 0;
}

## empty lines do not count
/^ *$/ {
  next;
}

/`/ {
  $0 = gensub(/`([^`]*)`/, "\\\\texttt{\\1}", "g");
}

/.#/ {
  gsub(/#/, "\\#");
}
/\[/ {
  gsub(/\[/, "\\mbox{$[$}");
}
/\]/ {
  gsub(/\]/, "\\mbox{$]$}");
}

/^==/ {
  sub(/^==/, "\\subsection*{");
  sub(/==/, "}");
  print;
  next;
}

/^=/ {
  sub(/^=/, "\\section*{");
  sub(/=/, "}");
  print;
  print "";
  print "\\label{f0}";
  print "";
  next;
}

quoting && /^ / {
  sub(/^ /, "");
  print;
  next;
}

!itemizing && inItem {
  print "\\begin{itemize}";
  itemizing = 1;
}

itemizing && inItem {
  sub(/^   *\*/, "\\item");
  print;
  print "";
  next;
}

/^ / {
  print ""
  print "\\begin{quotation}";
  quoting = 1;
  sub(/^ /, "");
  print;
  next;
}

{ print }

BEGIN {
  print "%TCIDATA{Version=5.00.0.2606}";
  print "%TCIDATA{LaTeXparent=0,0,classes.tex}";
  print "                      ";
  print "";
  print "%%%%% BEGINNING OF DOCUMENT BODY %%%%%";
  print "% html: Beginning of file: `clean.html'";
  print "% DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"";
  print "%  This is a (PRE) block.  Make sure it's left aligned or your toc title will be off. ";
  print "";
  quoting = 0;
  itemizing = 0;
  coding = 0;
}

END {
  print "% html: End of file: `clean.html'";
  print "";
  print "%%%%% END OF DOCUMENT BODY %%%%%";
  print "% In the future, we might want to put some additional data here, such";
  print "% as when the documentation was converted from wiki to TeX.";
  print "%";
}

{ origLine = $0; }

## HANDLE CODING
## make sure that control sequences are always at the front
/ *{{{/ { sub(/ */, "") }
/ *}}}/ { sub(/ */, "") }

!coding && /^{{{/ {

  if (quoting) {
    print "\\end{quotation}";
    print ""
    quoting = 0;
  }

  print "\\begin{verbatim}";
  coding = 1;
  next;
}

coding && /^}}}/ {
  sub(/}}}.*$/, "", origLine);
  if (origLine) {
    print "{\\small " origLine
    print "}"
  }
  print "\\end{verbatim}";
  print ""
  coding = 0;
  next;
}

coding {
  sub(/^/, "{\\small ");
  print;
  print "}";
  next;
}

## NO CODING BELOW THIS POINT
coding { print "###code???####"; next; }

## pragmas do not count
/^\#labels/ {
  next;
}

## make sure that control sequences are always at the front
/^ *=/ { sub(/^ *=/, "=") }

## check itemness
{ inItem = 0 }
/^   *\*/ {
  inItem = 1
  ## print " ########## ITEM"
}

itemizing && !inItem {
  print "\\end{itemize}";
  print "";
  itemizing = 0;
}

## quoting stops when item appears
## or not indented any more
quoting && (inItem || !/^ /) {
  print "\\end{quotation}";
  print ""
  quoting = 0;
}

## empty lines do not count
/^ *$/ {
  next;
}

/`/ {
  line = $0;
  #sub(/`/, "\\texttt{", line);
  #sub(/`/, "}", line);
  $0 = gensub(/`([^`]*)`/,"\\\\texttt{\\1}","g",line)
  #$0 = line
  ## repeat!
}

/.#/ {
  gsub(/#/, "\\#");
}
/\[/ {
  gsub(/\[/, "\\mbox{$[$}");
}
/\]/ {
  gsub(/\]/, "\\mbox{$]$}");
}

/^==/ {
  sub(/^==/, "\\subsection*{");
  sub(/==/, "}");
  print;
  next;
}

/^=/ {
  sub(/^=/, "\\section*{");
  sub(/=/, "}");
  print;
  print "";
  print "\\label{f0}";
  print "";
  next;
}

quoting && /^ / {
  sub(/^ /, "");
  print;
  next;
}

!itemizing && inItem {
  print "\\begin{itemize}";
  itemizing = 1;
}

itemizing && inItem {
  sub(/^   *\*/, "\\item");
  print;
  print "";
  next;
}

/^ / {
  print ""
  print "\\begin{quotation}";
  quoting = 1;
  sub(/^ /, "");
  print;
  next;
}

{ print }


Fix the pair generation and also speed up the sorting

#!/usr/bin/awk -f
BEGIN {
    FS  = "\t";
    OFS = "";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], FS, words[j], ORS, words[j], FS, words[i] | "sort --parallel=$(nproc) -S1G -us";
        }
    }
}

#!/usr/bin/awk -f
BEGIN {
    FS = OFS = "\t";
}
{
    len = split($3, words, ", ");

    if (length(N) > 0 && len >= N) next;

    for (i = 1; i <= len - 1; i++) {
        for (j = i + 1; j <= len; j++) {
            print words[i], words[j], ORS, words[j], words[i] | "sort --parallel=$(nproc) -us";
        }
    }
}


remove debug line

remove debug line

#
# Parse zodiac config
#

action == "config" && (NF == 0 || /^;/) {
  next
}

action  == "config" && match($0, /\[([[:alnum:]_]).*\]/) {
  section = substr($0, (RSTART + 1), (RLENGTH - 2))
  next
}

action == "config" && section == "parse" {
  n = split($0, exts, ",")
  for (i in exts) {
    ext = exts[i]
    gsub(/ /, "", ext)
    filter[ext] = "none"
  }
  next
}

action == "config" && section == "parse_convert" && (NF > 1) {
  ext_list = $1
  cmd = substr($0, length(ext_list) + 1)
  n = split(ext_list, exts, ",")
  for (i in exts) {
    ext = exts[i]
    gsub(/ /, "", ext)
    filter[ext] = cmd
  }
  next
}

action == "config" && section == "ignore" {
  ignore[ignore_count++] = $0
}

#
# Parse zodiac config
#

action == "config" && (NF == 0 || /^;/) {
  next
}

action  == "config" && match($0, /\[([[:alnum:]_]).*\]/) {
  section = substr($0, (RSTART + 1), (RLENGTH - 2))
  next
}

action == "config" && section == "parse" {
  n = split($0, exts, ",")
  for (i in exts) {
    ext = exts[i]
    gsub(/ /, "", ext)
    filter[ext] = "none"
  }
  next
}

action == "config" && section == "parse_convert" && (NF > 1) {
  ext_list = $1
  cmd = substr($0, length(ext_list) + 1)
  n = split(ext_list, exts, ",")
  for (i in exts) {
    ext = exts[i]
    gsub(/ /, "", ext)
    filter[ext] = cmd
    print cmd >> "awk.log"
  }
  next
}

action == "config" && section == "ignore" {
  ignore[ignore_count++] = $0
}


Fix for translating flatzinc where the output variables are indices of a var array.


grammar fix

grammar fix

#
# Render a zodiac page
#

BEGIN {
  action = "none"
  ext = "none"
  main = "_main"
  helpers_loaded = "no"
  layout = ""
}

{
  split(FILENAME, parts, ".")
  ext = parts[length(parts)]
  if (FILENAME == "-") {
    action = "config"
  } else if (ext == "meta") {
    action = "meta"
  } else if (ext == "layout") {
    action = "layout"
  } else {
    action = "page"
    filter_ext = ext
  }
}

# Process lines from meta files
action == "meta" {
  split($0, kv, ": ")
  data[kv[1]] = kv[2]
  next
}

# Done processing meta
# Since data is loaded now, load the helpers
action != "meta" && action != "config" && helpers_loaded == "no" && helpers == "yes" {
  load_helpers()
  helpers_loaded = "yes"
}

# Process lines from the page
action == "page" {
  if (!contents[main]) {
    contents[main] = bind_data($0)

    # save the extension for this content type
    # to find the appropriate filter to render it
    filter_exts[main] = ext
  } else {
    contents[main] = contents[main] "\n" bind_data($0)
  }
  next
}

# Process lines from the layout
action == "layout" {

  # replace yield with rendered content
  if (match($0, /{{{yield}}}/)) {
    sub(/{{{yield}}}/, escape_special_chars(render_content(main)))
  }

  if (layout == "") {
    layout = bind_data($0)
  } else {
    layout = layout "\n" bind_data($0)
  }
}

END {
  if (layout != "") {
    print layout
  } else {
    print render_content(main)
  }
}

function bind_data(txt,   tag, key) {
  if (match(txt, /{{([^}]*)}}/)) {
    tag = substr(txt, RSTART, RLENGTH)
    match(tag, /([[:alnum:]_]|[?]).*[^}]/)
    key = substr(tag, RSTART, RLENGTH)
    gsub(tag, data[key], txt)
    return bind_data(txt, data)
  } else {
    return txt
  }
}

function render_content(type,     ext_key, filter_ext, filter_cmd, txt) {
  ext_key = type "_ext"

  # Get the extension of the content type
  filter_ext = filter_exts[type]

  # Get the appropriate filter command for this extension
  filter_cmd = filter[filter_ext]

  # Get the text of the content for the given type
  txt = contents[type]

  if (filter_cmd != "none") {
    return run_filter(filter_cmd, txt)
  } else {
    return txt
  }
}

function run_filter(cmd, txt,   rand_date, tmpfile, rendered_txt, date_cmd, filter_cmd, line) {
  date_cmd = "date +%Y%m%d%H%M%S"
  date_cmd | getline rand_date
  close(date_cmd)

  tmpfile = "/tmp/awk_render" rand_date
  filter_cmd = cmd " > " tmpfile

  # pipe content to filter command
  print txt | filter_cmd
  close(filter_cmd)

  # pull out the filtered page
  while((getline line < tmpfile) > 0) {
    rendered_txt = rendered_txt "\n" line
  }
  close(tmpfile)

  system("rm " tmpfile)

  return rendered_txt
}

# Prevent awk from replacing ampersands with matched text
function escape_special_chars(  txt) {
  gsub(/&/, "\\\\&", txt)
  return txt
}

#
# Render a zodiac page
#

BEGIN {
  action = "none"
  ext = "none"
  main = "_main"
  helpers_loaded = "no"
  layout = ""
}

{
  split(FILENAME, parts, ".")
  ext = parts[length(parts)]
  if (FILENAME == "-") {
    action = "config"
  } else if (ext == "meta") {
    action = "meta"
  } else if (ext == "layout") {
    action = "layout"
  } else {
    action = "page"
    filter_ext = ext
  }
}

# Process lines from meta files
action == "meta" {
  split($0, kv, ": ")
  data[kv[1]] = kv[2]
  next
}

# Done processing meta
# Since data is loaded now, load the helpers
action != "meta" && action != "config" && helpers_loaded == "no" && helpers == "yes" {
  load_helpers()
  helpers_loaded = "yes"
}

# Process lines from the page
action == "page" {
  if (!contents[main]) {
    contents[main] = bind_data($0)

    # save the extension for this content type
    # to find the appropriate filter to render it
    filter_exts[main] = ext
  } else {
    contents[main] = contents[main] "\n" bind_data($0)
  }
  next
}

# Process lines from the layout
action == "layout" {

  # replace yield with rendered content
  if (match($0, /{{{yield}}}/)) {
    sub(/{{{yield}}}/, escape_special_chars(render_content(main)))
  }

  if (layout == "") {
    layout = bind_data($0)
  } else {
    layout = layout "\n" bind_data($0)
  }
}

END {
  if (layout != "") {
    print layout
  } else {
    print render_content(main)
  }
}

function bind_data(txt,   tag, key) {
  if (match(txt, /{{([^}]*)}}/)) {
    tag = substr(txt, RSTART, RLENGTH)
    match(tag, /([[:alnum:]_]|[?]).*[^}]/)
    key = substr(tag, RSTART, RLENGTH)
    gsub(tag, data[key], txt)
    return bind_data(txt, data)
  } else {
    return txt
  }
}

function render_content(type,     ext_key, filter_ext, filter_cmd, txt) {
  ext_key = type "_ext"

  # Get the extension of the content type
  filter_ext = filter_exts[type]

  # Get the appropriate filter command for this extension
  filter_cmd = filter[filter_ext]

  # Get the text of the content for the given type
  txt = contents[type]

  if (filter_cmd != "none") {
    return run_filter(filter_cmd, txt)
  } else {
    return txt
  }
}

function run_filter(cmd, txt,   rand_date, tmpfile, rendered_txt, date_cmd, filter_cmd, line) {
  date_cmd = "date +%Y%m%d%H%M%S"
  date_cmd | getline rand_date
  close(date_cmd)

  tmpfile = "/tmp/awk_render" rand_date
  filter_cmd = cmd " > " tmpfile

  # pipe content to filter command
  print txt | filter_cmd
  close(filter_cmd)

  # pull out the filtered page
  while((getline line < tmpfile) > 0) {
    rendered_txt = rendered_txt "\n" line
  }
  close(tmpfile)

  system("rm " tmpfile)

  return rendered_txt
}

# Prevent awk from replacing ampersand's with matched text
function escape_special_chars(  txt) {
  gsub(/&/, "\\\\&", txt)
  return txt
}


parse: add data validation to parser.

parse: add data validation to parser.

function validate_time(s) {
	if (s !~ /^[0-9]+:[0-9]+/) {
		printf "ERROR: Wrong input data! [%s]\n", s;
		exit 1
	}
}

BEGIN {
	skipped_first = 0
	skipped_first_right = 0
	found_div = 0
}

/
/ {
	if (skipped_first == 0) {
		skipped_first = 1
		next
	}
	found_div = 1
}

/
/ {
	if (found_div == 0) { next }

	getline

	print $1 " - " $3
}

/
/ {
	if (skipped_first_right == 0) {
		skipped_first_right = 1
		next
	}

	getline
	while ($1 != "
") {
		validate_time($1);
		validate_time($3);
		print $1 " - " substr($3, 0, length($3)-4)
		getline
	}
}

BEGIN {
	skipped_first = 0
	skipped_first_right = 0
	found_div = 0
}

/
/ {
	if (skipped_first == 0) {
		skipped_first = 1
		next
	}
	found_div = 1
}

/
/ {
	if (found_div == 0) { next }

	getline

	print $1 " - " $3
}

/
/ {
	if (skipped_first_right == 0) {
		skipped_first_right = 1
		next
	}

	getline
	while ($1 != "
") {
		print $1 " - " substr($3, 0, length($3)-4)
		getline
	}
}


Allow -d and -h as command line flags.  These are used to generate only the .h or _data.h files respectively.  Restructure code to allow for this.

#! /usr/bin/awk -f
#	$NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
#  $FreeBSD$
#
# Copyright (c) 1995, 1996 Christopher G. Demetriou
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#      This product includes software developed by Christopher G. Demetriou.
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
function usage()
{
	print "usage: usbdevs2h.awk <srcfile> [-d|-h]";
	exit 1;
}

BEGIN {

nproducts = nvendors = 0
# Process the command line
for (i = 1; i < ARGC; i++) {
	arg = ARGV[i];
	if (arg !~ /^-[dh]+$/ && arg !~ /devs$/)
		usage();
	if (arg ~ /^-.*d/)
		dfile="usbdevs_data.h"
	if (arg ~ /^-.*h/)
		hfile="usbdevs.h"
	if (arg ~ /devs$/)
		srcfile = arg;
}
ARGC = 1;
line=0;

while ((getline < srcfile) > 0) {
    line++;
    if (line == 1) {
	VERSION = $0
	gsub("\\$", "", VERSION)

	if (dfile) {
		if (os == "NetBSD")
			printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
		else if (os == "FreeBSD")
			printf("/* \$FreeBSD\$ */\n\n") > dfile
		else if (os == "OpenBSD")
			printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
		else
			printf("/* ??? */\n\n") > dfile
		printf("/*\n") > dfile
		printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
		    > dfile
		printf(" *\n") > dfile
		printf(" * generated from:\n") > dfile
		printf(" *\t%s\n", VERSION) > dfile
		printf(" */\n") > dfile
	}

	if (hfile) {
		if (os == "NetBSD")
			printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
		else if (os == "FreeBSD")
			printf("/* \$FreeBSD\$ */\n\n") > hfile
		else if (os == "OpenBSD")
			printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
		else
			printf("/* ??? */\n\n") > hfile
		printf("/*\n") > hfile
		printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
		    > hfile
		printf(" *\n") > hfile
		printf(" * generated from:\n") > hfile
		printf(" *\t%s\n", VERSION) > hfile
		printf(" */\n") > hfile
	}
	continue;
    }
   if ($1 == "vendor") {
	nvendors++

	vendorindex[$2] = nvendors;		# record index for this name, for later.
	vendors[nvendors, 1] = $2;		# name
	vendors[nvendors, 2] = $3;		# id
	if (hfile)
		printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
		    vendors[nvendors, 2]) > hfile
	i = 3; f = 4;

	# comments
	ocomment = oparen = 0
	if (f <= NF) {
		if (hfile)
			printf("\t/* ") > hfile
		ocomment = 1;
	}
	while (f <= NF) {
		if ($f == "#") {
			if (hfile)
				printf("(") > hfile
			oparen = 1
			f++
			continue
		}
		if (oparen) {
			if (hfile)
				printf("%s", $f) > hfile
			if (f < NF && hfile)
				printf(" ") > hfile
			f++
			continue
		}
		vendors[nvendors, i] = $f
		if (hfile)
			printf("%s", vendors[nvendors, i]) > hfile
		if (f < NF && hfile)
			printf(" ") > hfile
		i++; f++;
	}
	if (oparen && hfile)
		printf(")") > hfile
	if (ocomment && hfile)
		printf(" */") > hfile
	if (hfile)
		printf("\n") > hfile

	continue;
    }
    if ($1 == "product") {
	nproducts++

	products[nproducts, 1] = $2;		# vendor name
	products[nproducts, 2] = $3;		# product id
	products[nproducts, 3] = $4;		# id
	if (hfile)
		printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", \
		  products[nproducts, 1], products[nproducts, 2], \
		  products[nproducts, 3]) > hfile

	i=4; f = 5;

	# comments
	ocomment = oparen = 0
	if (f <= NF) {
		if (hfile)
			printf("\t/* ") > hfile
		ocomment = 1;
	}
	while (f <= NF) {
		if ($f == "#") {
			if (hfile)
				printf("(") > hfile
			oparen = 1
			f++
			continue
		}
		if (oparen) {
			if (hfile)
				printf("%s", $f) > hfile
			if (f < NF && hfile)
				printf(" ") > hfile
			f++
			continue
		}
		products[nproducts, i] = $f
		if (hfile)
			printf("%s", products[nproducts, i]) > hfile
		if (f < NF && hfile)
			printf(" ") > hfile
		i++; f++;
	}
	if (oparen && hfile)
		printf(")") > hfile
	if (ocomment && hfile)
		printf(" */") > hfile
	if (hfile)
		printf("\n") > hfile

	continue;
    }
	if ($0 == "")
		blanklines++
	if (hfile)
		print $0 > hfile
	if (blanklines < 2 && dfile)
	    print $0 > dfile
}
	# print out the match tables

	if (dfile) {
		printf("\n") > dfile

		printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
		for (i = 1; i <= nproducts; i++) {
			printf("\t{\n") > dfile
			printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
			    products[i, 1], products[i, 1], products[i, 2]) \
			    > dfile
			printf("\t    ") > dfile
			printf("0") > dfile
			printf(",\n") > dfile

			vendi = vendorindex[products[i, 1]];
			printf("\t    \"") > dfile
			j = 3;
			needspace = 0;
			while (vendors[vendi, j] != "") {
				if (needspace)
					printf(" ") > dfile
				printf("%s", vendors[vendi, j]) > dfile
				needspace = 1
				j++
			}
			printf("\",\n") > dfile

			printf("\t    \"") > dfile
			j = 4;
			needspace = 0;
			while (products[i, j] != "") {
				if (needspace)
					printf(" ") > dfile
				printf("%s", products[i, j]) > dfile
				needspace = 1
				j++
			}
			printf("\",\n") > dfile
			printf("\t},\n") > dfile
		}
		for (i = 1; i <= nvendors; i++) {
			printf("\t{\n") > dfile
			printf("\t    USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
			    > dfile
			printf("\t    USB_KNOWNDEV_NOPROD,\n") \
			    > dfile
			printf("\t    \"") > dfile
			j = 3;
			needspace = 0;
			while (vendors[i, j] != "") {
				if (needspace)
					printf(" ") > dfile
				printf("%s", vendors[i, j]) > dfile
				needspace = 1
				j++
			}
			printf("\",\n") > dfile
			printf("\t    NULL,\n") > dfile
			printf("\t},\n") > dfile
		}
		printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
		printf("};\n") > dfile
	}
}

#! /usr/bin/awk -f
#	$NetBSD: usb/devlist2h.awk,v 1.9 2001/01/18 20:28:22 jdolecek Exp $
#  $FreeBSD$
#
# Copyright (c) 1995, 1996 Christopher G. Demetriou
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#      This product includes software developed by Christopher G. Demetriou.
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
BEGIN {
	nproducts = nvendors = 0
	dfile="usbdevs_data.h"
	hfile="usbdevs.h"
}
NR == 1 {
	VERSION = $0
	gsub("\\$", "", VERSION)

	if (os == "NetBSD")
		printf("/*\t\$NetBSD\$\t*/\n\n") > dfile
	else if (os == "FreeBSD")
		printf("/* \$FreeBSD\$ */\n\n") > dfile
	else if (os == "OpenBSD")
		printf("/*\t\$OpenBSD\$\t*/\n\n") > dfile
	else
		printf("/* ??? */\n\n") > dfile
	printf("/*\n") > dfile
	printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
	    > dfile
	printf(" *\n") > dfile
	printf(" * generated from:\n") > dfile
	printf(" *\t%s\n", VERSION) > dfile
	printf(" */\n") > dfile

	if (os == "NetBSD")
		printf("/*\t\$NetBSD\$\t*/\n\n") > hfile
	else if (os == "FreeBSD")
		printf("/* \$FreeBSD\$ */\n\n") > hfile
	else if (os == "OpenBSD")
		printf("/*\t\$OpenBSD\$\t*/\n\n") > hfile
	else
		printf("/* ??? */\n\n") > hfile
	printf("/*\n") > hfile
	printf(" * THIS FILE IS AUTOMATICALLY GENERATED.  DO NOT EDIT.\n") \
	    > hfile
	printf(" *\n") > hfile
	printf(" * generated from:\n") > hfile
	printf(" *\t%s\n", VERSION) > hfile
	printf(" */\n") > hfile

	next
}
$1 == "vendor" {
	nvendors++

	vendorindex[$2] = nvendors;		# record index for this name, for later.
	vendors[nvendors, 1] = $2;		# name
	vendors[nvendors, 2] = $3;		# id
	printf("#define\tUSB_VENDOR_%s\t%s\t", vendors[nvendors, 1],
	    vendors[nvendors, 2]) > hfile

	i = 3; f = 4;

	# comments
	ocomment = oparen = 0
	if (f <= NF) {
		printf("\t/* ") > hfile
		ocomment = 1;
	}
	while (f <= NF) {
		if ($f == "#") {
			printf("(") > hfile
			oparen = 1
			f++
			continue
		}
		if (oparen) {
			printf("%s", $f) > hfile
			if (f < NF)
				printf(" ") > hfile
			f++
			continue
		}
		vendors[nvendors, i] = $f
		printf("%s", vendors[nvendors, i]) > hfile
		if (f < NF)
			printf(" ") > hfile
		i++; f++;
	}
	if (oparen)
		printf(")") > hfile
	if (ocomment)
		printf(" */") > hfile
	printf("\n") > hfile

	next
}
$1 == "product" {
	nproducts++

	products[nproducts, 1] = $2;		# vendor name
	products[nproducts, 2] = $3;		# product id
	products[nproducts, 3] = $4;		# id
	printf("#define\tUSB_PRODUCT_%s_%s\t%s\t", products[nproducts, 1],
	    products[nproducts, 2], products[nproducts, 3]) > hfile

	i=4; f = 5;

	# comments
	ocomment = oparen = 0
	if (f <= NF) {
		printf("\t/* ") > hfile
		ocomment = 1;
	}
	while (f <= NF) {
		if ($f == "#") {
			printf("(") > hfile
			oparen = 1
			f++
			continue
		}
		if (oparen) {
			printf("%s", $f) > hfile
			if (f < NF)
				printf(" ") > hfile
			f++
			continue
		}
		products[nproducts, i] = $f
		printf("%s", products[nproducts, i]) > hfile
		if (f < NF)
			printf(" ") > hfile
		i++; f++;
	}
	if (oparen)
		printf(")") > hfile
	if (ocomment)
		printf(" */") > hfile
	printf("\n") > hfile

	next
}
{
	if ($0 == "")
		blanklines++
	print $0 > hfile
	if (blanklines < 2)
		print $0 > dfile
}
END {
	# print out the match tables

	printf("\n") > dfile

	printf("const struct usb_knowndev usb_knowndevs[] = {\n") > dfile
	for (i = 1; i <= nproducts; i++) {
		printf("\t{\n") > dfile
		printf("\t    USB_VENDOR_%s, USB_PRODUCT_%s_%s,\n",
		    products[i, 1], products[i, 1], products[i, 2]) \
		    > dfile
		printf("\t    ") > dfile
		printf("0") > dfile
		printf(",\n") > dfile

		vendi = vendorindex[products[i, 1]];
		printf("\t    \"") > dfile
		j = 3;
		needspace = 0;
		while (vendors[vendi, j] != "") {
			if (needspace)
				printf(" ") > dfile
			printf("%s", vendors[vendi, j]) > dfile
			needspace = 1
			j++
		}
		printf("\",\n") > dfile

		printf("\t    \"") > dfile
		j = 4;
		needspace = 0;
		while (products[i, j] != "") {
			if (needspace)
				printf(" ") > dfile
			printf("%s", products[i, j]) > dfile
			needspace = 1
			j++
		}
		printf("\",\n") > dfile
		printf("\t},\n") > dfile
	}
	for (i = 1; i <= nvendors; i++) {
		printf("\t{\n") > dfile
		printf("\t    USB_VENDOR_%s, 0,\n", vendors[i, 1]) \
		    > dfile
		printf("\t    USB_KNOWNDEV_NOPROD,\n") \
		    > dfile
		printf("\t    \"") > dfile
		j = 3;
		needspace = 0;
		while (vendors[i, j] != "") {
			if (needspace)
				printf(" ") > dfile
			printf("%s", vendors[i, j]) > dfile
			needspace = 1
			j++
		}
		printf("\",\n") > dfile
		printf("\t    NULL,\n") > dfile
		printf("\t},\n") > dfile
	}
	printf("\t{ 0, 0, 0, NULL, NULL, }\n") > dfile
	printf("};\n") > dfile
}


INTEGRATION: CWS changefileheader (1.5.1038); FILE MERGED 2008/03/28 15:55:26 rt 1.5.1038.1: #i87441# Change license header to LPGL v3.

#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2008 by Sun Microsystems, Inc.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# $RCSfile: getcsym.awk,v $
#
# $Revision: 1.6 $
#
# This file is part of OpenOffice.org.
#
# OpenOffice.org is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License version 3
# only, as published by the Free Software Foundation.
#
# OpenOffice.org is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License version 3 for more details
# (a copy is included in the LICENSE file that accompanied this code).
#
# You should have received a copy of the GNU Lesser General Public License
# version 3 along with OpenOffice.org.  If not, see
# <http://www.openoffice.org/license.html>
# for a copy of the LGPLv3 License.
#
#*************************************************************************

BEGIN { global_found = "false" }
/[ \t]*#/ { sub( substr( $0, index($0, "#")),"" ) }
/[ \t]*local:/ { global_found = "false" }
/[ \t]*}/ { global_found = "false" }
/^[ \t]*$/ { next }
global_found == "true"  { print $0 }
/[ \t]*global:/ { global_found = "true" }

#*************************************************************************
#
#   OpenOffice.org - a multi-platform office productivity suite
#
#   $RCSfile: getcsym.awk,v $
#
#   $Revision: 1.5 $
#
#   last change: $Author: rt $ $Date: 2005-09-07 22:09:22 $
#
#   The Contents of this file are made available subject to
#   the terms of GNU Lesser General Public License Version 2.1.
#
#
#     GNU Lesser General Public License Version 2.1
#     =============================================
#     Copyright 2005 by Sun Microsystems, Inc.
#     901 San Antonio Road, Palo Alto, CA 94303, USA
#
#     This library is free software; you can redistribute it and/or
#     modify it under the terms of the GNU Lesser General Public
#     License version 2.1, as published by the Free Software Foundation.
#
#     This library is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#     MA  02111-1307  USA
#
#*************************************************************************

BEGIN { global_found = "false" }
/[ \t]*#/ { sub( substr( $0, index($0, "#")),"" ) }
/[ \t]*local:/ { global_found = "false" }
/[ \t]*}/ { global_found = "false" }
/^[ \t]*$/ { next }
global_found == "true"  { print $0 }
/[ \t]*global:/ { global_found = "true" }


accumulate hints and print lookup at the end of hinter

BEGIN {
  n_matches = 0;
  line_pos = 0;
  col_pos = 0;

  HINTS[0] = "p"
  HINTS[1] = "o"
  HINTS[2] = "i"
  HINTS[3] = "u"
  HINTS[4] = "l"
  HINTS[5] = "k"
  HINTS[6] = "j"
  HINTS[7] = "t"
  HINTS[8] = "r"
  HINTS[9] = "e"
  HINTS[10] = "wj"
  HINTS[11] = "wt"
  HINTS[12] = "wr"
  HINTS[13] = "we"
  HINTS[14] = "ww"
  HINTS[15] = "wq"
  HINTS[16] = "wf"
  HINTS[17] = "wd"
  HINTS[18] = "ws"
  HINTS[19] = "wa"
  HINTS[20] = "qp"
  HINTS[21] = "qo"
  HINTS[22] = "qi"
  HINTS[23] = "qu"
  HINTS[24] = "ql"
  HINTS[25] = "qk"
  HINTS[26] = "qj"
  HINTS[27] = "qt"
  HINTS[28] = "qr"
  HINTS[29] = "qe"
  HINTS[30] = "qw"
  HINTS[31] = "qq"
  HINTS[32] = "qf"
  HINTS[33] = "qd"
  HINTS[34] = "qs"
  HINTS[35] = "qa"
  HINTS[36] = "fp"
  HINTS[37] = "fo"
  HINTS[38] = "fi"
  HINTS[39] = "fu"
  HINTS[40] = "fl"
  HINTS[41] = "fk"
  HINTS[42] = "fj"
  HINTS[43] = "ft"
  HINTS[44] = "fr"
  HINTS[45] = "fe"
  HINTS[46] = "fw"
  HINTS[47] = "fq"
  HINTS[48] = "ff"
  HINTS[49] = "fd"
  HINTS[50] = "fs"
  HINTS[51] = "fa"
  HINTS[52] = "dp"
  HINTS[53] = "do"
  HINTS[54] = "di"
  HINTS[55] = "du"
  HINTS[56] = "dl"
  HINTS[57] = "dk"
  HINTS[58] = "dj"
  HINTS[59] = "dt"
  HINTS[60] = "dr"
  HINTS[61] = "de"
  HINTS[62] = "dw"
  HINTS[63] = "dq"
  HINTS[64] = "df"
  HINTS[65] = "dd"
  HINTS[66] = "ds"
  HINTS[67] = "da"
  HINTS[68] = "sp"
  HINTS[69] = "so"
  HINTS[70] = "si"
  HINTS[71] = "su"
  HINTS[72] = "sl"
  HINTS[73] = "sk"
  HINTS[74] = "sj"
  HINTS[75] = "st"
  HINTS[76] = "sr"
  HINTS[77] = "se"
  HINTS[78] = "sw"
  HINTS[79] = "sq"
  HINTS[80] = "sf"
  HINTS[81] = "sd"
  HINTS[82] = "ss"
  HINTS[83] = "sa"
  HINTS[84] = "ap"
  HINTS[85] = "ao"
  HINTS[86] = "ai"
  HINTS[87] = "au"
  HINTS[88] = "al"
  HINTS[89] = "ak"
  HINTS[90] = "aj"
  HINTS[91] = "at"
  HINTS[92] = "ar"
  HINTS[93] = "ae"
  HINTS[94] = "aw"
  HINTS[95] = "aq"
  HINTS[96] = "af"
  HINTS[97] = "ad"
  HINTS[98] = "as"
  HINTS[99] = "aa"

  finger_patterns = ENVIRON["FINGER_PATTERNS"];

  hint_format = "\033[1;33m[%s]\033[0m"
  highlight_format = "\033[1;33m%s\033[0m "
  printf "%s\n", finger_patterns | "cat 1>&4"
  hint_lookup = ""
}

{
  line = $0;
  pos = 0;
  col_pos = 0;
	col_pos_correction = 0;

	output_line = line;

  while (match(line, finger_patterns)) {
    n_matches += 1;

		hint = HINTS[n_matches - 1]
    pos += RSTART;

    col_pos = pos;
    line_match = substr(line, RSTART, RLENGTH);

    col_pos = col_pos + col_pos_correction

    line_pos = NR;

		pre_match = substr(output_line, 0, col_pos - 1);
    hint_match = sprintf(highlight_format hint_format, line_match, hint);
		post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);

    output_line = pre_match hint_match post_match;

    line = post_match;

    col_pos_correction += (length(sprintf(highlight_format, line_match)) - 1 + length(sprintf(hint_format, hint)) - 1) + 1;

    hint_lookup = hint_lookup hint ":" line_match "\n"
  }

  printf "\n%s", output_line
}

END {
  print hint_lookup | "cat 1>&3"
}

BEGIN {
  n_matches = 0;
  line_pos = 0;
  col_pos = 0;

  HINTS[0] = "p"
  HINTS[1] = "o"
  HINTS[2] = "i"
  HINTS[3] = "u"
  HINTS[4] = "l"
  HINTS[5] = "k"
  HINTS[6] = "j"
  HINTS[7] = "t"
  HINTS[8] = "r"
  HINTS[9] = "e"
  HINTS[10] = "wj"
  HINTS[11] = "wt"
  HINTS[12] = "wr"
  HINTS[13] = "we"
  HINTS[14] = "ww"
  HINTS[15] = "wq"
  HINTS[16] = "wf"
  HINTS[17] = "wd"
  HINTS[18] = "ws"
  HINTS[19] = "wa"
  HINTS[20] = "qp"
  HINTS[21] = "qo"
  HINTS[22] = "qi"
  HINTS[23] = "qu"
  HINTS[24] = "ql"
  HINTS[25] = "qk"
  HINTS[26] = "qj"
  HINTS[27] = "qt"
  HINTS[28] = "qr"
  HINTS[29] = "qe"
  HINTS[30] = "qw"
  HINTS[31] = "qq"
  HINTS[32] = "qf"
  HINTS[33] = "qd"
  HINTS[34] = "qs"
  HINTS[35] = "qa"
  HINTS[36] = "fp"
  HINTS[37] = "fo"
  HINTS[38] = "fi"
  HINTS[39] = "fu"
  HINTS[40] = "fl"
  HINTS[41] = "fk"
  HINTS[42] = "fj"
  HINTS[43] = "ft"
  HINTS[44] = "fr"
  HINTS[45] = "fe"
  HINTS[46] = "fw"
  HINTS[47] = "fq"
  HINTS[48] = "ff"
  HINTS[49] = "fd"
  HINTS[50] = "fs"
  HINTS[51] = "fa"
  HINTS[52] = "dp"
  HINTS[53] = "do"
  HINTS[54] = "di"
  HINTS[55] = "du"
  HINTS[56] = "dl"
  HINTS[57] = "dk"
  HINTS[58] = "dj"
  HINTS[59] = "dt"
  HINTS[60] = "dr"
  HINTS[61] = "de"
  HINTS[62] = "dw"
  HINTS[63] = "dq"
  HINTS[64] = "df"
  HINTS[65] = "dd"
  HINTS[66] = "ds"
  HINTS[67] = "da"
  HINTS[68] = "sp"
  HINTS[69] = "so"
  HINTS[70] = "si"
  HINTS[71] = "su"
  HINTS[72] = "sl"
  HINTS[73] = "sk"
  HINTS[74] = "sj"
  HINTS[75] = "st"
  HINTS[76] = "sr"
  HINTS[77] = "se"
  HINTS[78] = "sw"
  HINTS[79] = "sq"
  HINTS[80] = "sf"
  HINTS[81] = "sd"
  HINTS[82] = "ss"
  HINTS[83] = "sa"
  HINTS[84] = "ap"
  HINTS[85] = "ao"
  HINTS[86] = "ai"
  HINTS[87] = "au"
  HINTS[88] = "al"
  HINTS[89] = "ak"
  HINTS[90] = "aj"
  HINTS[91] = "at"
  HINTS[92] = "ar"
  HINTS[93] = "ae"
  HINTS[94] = "aw"
  HINTS[95] = "aq"
  HINTS[96] = "af"
  HINTS[97] = "ad"
  HINTS[98] = "as"
  HINTS[99] = "aa"

  finger_patterns = ENVIRON["FINGER_PATTERNS"];

  hint_format = "\033[1;33m[%s]\033[0m"
  highlight_format = "\033[1;33m%s\033[0m "
  printf "%s\n", finger_patterns | "cat 1>&4"
}

{
  line = $0;
  pos = 0;
  col_pos = 0;
	col_pos_correction = 0;

	output_line = line;

  while (match(line, finger_patterns)) {
    n_matches += 1;

		hint = HINTS[n_matches - 1]
    pos += RSTART;

    col_pos = pos;
    line_match = substr(line, RSTART, RLENGTH);

    col_pos = col_pos + col_pos_correction

    line_pos = NR;

		pre_match = substr(output_line, 0, col_pos - 1);
    hint_match = sprintf(highlight_format hint_format, line_match, hint);
		post_match = substr(output_line, col_pos + RLENGTH, length(line) - 1);

    output_line = pre_match hint_match post_match;

    line = post_match;

    col_pos_correction += (length(sprintf(highlight_format, line_match)) - 1 + length(sprintf(hint_format, hint)) - 1) + 1;

    printf hint ":" line_match "\n" | "cat 1>&3"
  }

  printf "\n%s", output_line
}


Fix missing braces

Fix missing braces

# WebScraper has problems getting incomplete data.
#
# Crosscheck the info in EPISODES with the info in SEASONS. Count up episodes
# and compare with the number of episodes listed in the seasons file.

# For now these seem more likely a problem in scraping SEASONS than EPISODES
# so it could be these are false positives in generating spreadsheets.
# Problems listed in BBox_anomalies files are more likely to be real.

# Generate a list of shows that might assist in repair

# INVOCATION
#    awk -v REPAIR_SHOWS=$REPAIR_SHOWS -f verifyBBoxInfoFrom-webscraper.awk \
#        $EPISODE_INFO_FILE >>$ERROR_FILE

/ movie / {
    if (NF < 5) {
        print "    Bad input line " NR ":\n          " $0
        next
    }
    gsub ("'", "", $3)
    title = $3
    numEpisodes = $5
    if (numEpisodes != 1)
        print "    " substr ($0,11)
}

/ show / {
    numShows += 1
    gsub ("'", "", $3)
    title = $3
    numEpisodes = $5
    numSeasons = $8
    if (NF < 8) {
        print "    Bad input line " NR ":\n          " $0
        next
    }

    if (numEpisodes == 0) {
        zeroEpisodes += 1
        print "    " substr ($0,10)
        print title >> REPAIR_SHOWS
    }

    showTitle[numShows] = title
    seas[numShows] = numSeasons
    episodesInShow[numShows] = numEpisodes
    episodesInSeasons[numShows] = 0
    seasonsFound[numShows] = 0
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/) {
        print "    Bad input line " NR ":\n" $0
    } else {
        seasonsFound[numShows] += 1
        episodesInSeasons[numShows] += $epis
    }
}

END {
    if (zeroEpisodes > 0 ) {
        printf ("==> %2d shows with 0 episodes in %s\n", zeroEpisodes, FILENAME) > "/dev/stderr"
        print ""
    }
    for ( i = 1; i <= numShows; i++ ) {
        if (seas[i] != 1 && episodesInShow[i] != episodesInSeasons[i]) {
            badEpisodes += 1
            print "    "showTitle[i] "'s " seasonsFound[i] " seasons claim "\
                  episodesInSeasons[i] " episodes, found "\
                  episodesInShow[i] " in " seas[i] " seasons."
            print showTitle[i] >> REPAIR_SHOWS
        }
    }
    if (badEpisodes > 0 ) {
        badEpisodes == 1 ? field = "URL" : field = "URLs"
        printf ("==> %2d shows with wrong number of episodes in %s\n", badEpisodes, FILENAME) \
                > "/dev/stderr"
    }
}

# WebScraper has problems getting incomplete data.
#
# Crosscheck the info in EPISODES with the info in SEASONS. Count up episodes
# and compare with the number of episodes listed in the seasons file.

# For now these seem more likely a problem in scraping SEASONS than EPISODES
# so it could be these are false positives in generating spreadsheets.
# Problems listed in BBox_anomalies files are more likely to be real.

# Generate a list of shows that might assist in repair

# INVOCATION
#    awk -v REPAIR_SHOWS=$REPAIR_SHOWS -f verifyBBoxInfoFrom-webscraper.awk \
#        $EPISODE_INFO_FILE >>$ERROR_FILE

/ movie / {
    if (NF < 5) {
        print "    Bad input line " NR ":\n          " $0
        next
    }
    gsub ("'", "", $3)
    title = $3
    numEpisodes = $5
    if (numEpisodes != 1)
        print "    " substr ($0,11)
}

/ show / {
    numShows += 1
    gsub ("'", "", $3)
    title = $3
    numEpisodes = $5
    numSeasons = $8
    if (NF < 8) {
        print "    Bad input line " NR ":\n          " $0
        next
    }

    if (numEpisodes == 0) {
        zeroEpisodes += 1
        print "    " substr ($0,10)
        print title >> REPAIR_SHOWS
    }

    showTitle[numShows] = title
    seas[numShows] = numSeasons
    episodesInShow[numShows] = numEpisodes
    episodesInSeasons[numShows] = 0
    seasonsFound[numShows] = 0
}

/^         / {
    epis  = NF-1
    if ($epis !~ /^[[:digit:]]*$/)
        print "    Bad input line " NR ":\n" $0
    else
        seasonsFound[numShows] += 1
    episodesInSeasons[numShows] += $epis
}

END {
    if (zeroEpisodes > 0 ) {
        printf ("==> %2d shows with 0 episodes in %s\n", zeroEpisodes, FILENAME) > "/dev/stderr"
        print ""
    }
    for ( i = 1; i <= numShows; i++ ) {
        if (seas[i] != 1 && episodesInShow[i] != episodesInSeasons[i]) {
            badEpisodes += 1
            print "    "showTitle[i] "'s " seasonsFound[i] " seasons claim "\
                  episodesInSeasons[i] " episodes, found "\
                  episodesInShow[i] " in " seas[i] " seasons."
            print showTitle[i] >> REPAIR_SHOWS
        }
    }
    if (badEpisodes > 0 ) {
        badEpisodes == 1 ? field = "URL" : field = "URLs"
        printf ("==> %2d shows with wrong number of episodes in %s\n", badEpisodes, FILENAME) \
                > "/dev/stderr"
    }
}


Insert \ before # for auto-indent.

Insert \ before # for auto-indent.

# CASE-MAPPING.awk -- awk script to generate CASE-MAPPING.tab
# Copyright (C) 2005
#   National Institute of Advanced Industrial Science and Technology (AIST)
#   Registration Number H15PRO112

# This file is part of the m17n database; a sub-part of the m17n
# library.

# The m17n library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.

# The m17n library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with the m17n library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307, USA.

BEGIN {
  FS = ";";
  FILE = 1;
}

function mtext (str) {
  if (n = split (str, A, " "))
    {
      printf ("\"");
      for (i = 1; i <= n; i++)
	printf ("\\u%s", A[i]);
      printf ("\"");
    }
  else
    printf ("\"\\u%s\"", str);
  printf (" ");
}

FILE == 1 && /^[^\#]/ && NF == 5 {
  printf ("0x%s ( ", $1);
  mtext ($2);
  mtext ($3);
  mtext ($4);
  printf (")\n");
  X[$1] = 1;
  next;
}

/^0000;/ {
  FILE = 2;
}

FILE == 2 && /^[^\#]/ && ($13 || $14 || $15) && ! X[$1] {
  if (! $13) $13 = $1;
  if (! $14) $14 = $1;
  if (! $15) $15 = $1;
  printf ("0x%s ( \"\\u%s\" \"\\u%s\" \"\\u%s\" )\n",
	  $1, $14, $15, $13);
}

# CASE-MAPPING.awk -- awk script to generate CASE-MAPPING.tab
# Copyright (C) 2005
#   National Institute of Advanced Industrial Science and Technology (AIST)
#   Registration Number H15PRO112

# This file is part of the m17n database; a sub-part of the m17n
# library.

# The m17n library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation; either version 2.1 of
# the License, or (at your option) any later version.

# The m17n library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with the m17n library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307, USA.

BEGIN {
  FS = ";";
  FILE = 1;
}

function mtext (str) {
  if (n = split (str, A, " "))
    {
      printf ("\"");
      for (i = 1; i <= n; i++)
	printf ("\\u%s", A[i]);
      printf ("\"");
    }
  else
    printf ("\"\\u%s\"", str);
  printf (" ");
}

FILE == 1 && /^[^#]/ && NF == 5 {
		printf ("0x%s ( ", $1);
		mtext ($2);
		mtext ($3);
		mtext ($4);
		printf (")\n");
		X[$1] = 1;
		}

/^0000;/ {
  FILE = 2;
}

FILE == 2 && /^[^#]/ && ($13 || $14 || $15) && ! X[$1] {
		if (! $13) $13 = $1;
		if (! $14) $14 = $1;
		if (! $15) $15 = $1;
		printf ("0x%s ( \"\\u%s\" \"\\u%s\" \"\\u%s\" )\n",
			$1, $14, $15, $13);
}


the content we define, decide for names and labels includer is

#	$OpenBSD: devlist2h.awk,v 1.4 2001/03/29 00:43:00 mickey Exp $

#
# Copyright (c) 1998-2001 Michael Shalayeff
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by Michael Shalayeff.
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND,
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

BEGIN	{
	ncpu = 0;
	cpuh="cpudevs.h";
	cpud="cpudevs_data.h";
	SUBSEP = "_";
}

/^[ \t]*$/	{next}

/^[ \t]*\/\*/	{busted++}

/^[ \t]*#/	{next}

busted	{
	cp = match($0, /\*\//);
	if(!cp) {
		next;
	} else if (cp + 1 == length($0)) {
		busted = 0;
		next;
	} else {
		sub(/.*\*\//, "");
		busted = 0;
	}
}

# first line is rcsid, beware
NR == 1	{
	VERSION = $0;
	gsub("\\$", "", VERSION);

	printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
	       " * generated from:\n *\t%s\n */\n\n", VERSION) > cpud;
	printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
	       " * generated from:\n *\t%s\n */\n\n", VERSION) > cpuh;
}

$1 == "type"	{
	printf("#define\tHPPA_TYPE_%s\t%s\n", toupper($2), $3) > cpuh;
	types[tolower($2)] = toupper($2);
	next;
}

NR > 1 {
	if (tolower($1) in types) {
		printf("#define\tHPPA_%s_%s\t%s\n", toupper($1),
		       toupper($2), $3) > cpuh;
		printf("{HPPA_TYPE_%s,\tHPPA_%s_%s,\t\"", toupper($1),
		       toupper($1), toupper($2), $3) > cpud;
		f = 4;
		while (f <= NF) {
			sub(/[ \t]*/, "", $f);
			ep = match($f, /\*\//);
			if (busted && !ep) {
				f++;
				continue;
			}
			if (match($f, /\/\*/)) {
				if (ep) {
					sub(/\/\*/, "", $f);
				} else {
					sub(/\/\*.*$/, "", $f);
					busted++;
				}
			}
			if (ep) {
				gsub(/^.*\*\//, "", $f);
				busted = 0;
			}
			if (length($f)) {
				if (f > 4)
					printf (" ") > cpud;
				printf ("%s", $f) > cpud;
			}
			f++;
		}
		printf("\" },\n") > cpud;
	} else {
		printf("WHA at line %d\n", NR);
		exit(1);
	}
}

END	{
	if (busted) {
		print("unteminated comment at the EOF\n");
		exit(1);
	}
	printf("{ -1 }\n") > cpud;
}

#	$OpenBSD: devlist2h.awk,v 1.3 2000/02/09 07:23:19 mickey Exp $

#
# Copyright (c) 1998-2000 Michael Shalayeff
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by Michael Shalayeff.
# 4. The name of the author may not be used to endorse or promote products
#    derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND,
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

BEGIN	{
	ncpu = 0;
	cpuh="cpudevs.h";
	cpud="cpudevs_data.h";
	SUBSEP = "_";
}

/^[ \t]*$/	{next}

/^[ \t]*\/\*/	{busted++}

/^[ \t]*#/	{next}

busted	{
	cp = match($0, /\*\//);
	if(!cp) {
		next;
	} else if (cp + 1 == length($0)) {
		busted = 0;
		next;
	} else {
		sub(/.*\*\//, "");
		busted = 0;
	}
}

# first line is rcsid, beware
NR == 1	{
	VERSION = $0;
	gsub("\\$", "", VERSION);

	printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
	       " * generated from:\n *\t%s\n */\n\n", VERSION) > cpud;
	printf("/*\n * THIS FILE AUTOMATICALLY GENERATED. DO NOT EDIT.\n" \
	       " * generated from:\n *\t%s\n */\n\n", VERSION) > cpuh;

	printf("static const struct hppa_mod_info hppa_knownmods[] = {\n")\
		> cpud;
}

$1 == "type"	{
	printf("#define\tHPPA_TYPE_%s\t%s\n", toupper($2), $3) > cpuh;
	types[tolower($2)] = toupper($2);
	next;
}

NR > 1 {
	if (tolower($1) in types) {
		printf("#define\tHPPA_%s_%s\t%s\n", toupper($1),
		       toupper($2), $3) > cpuh;
		printf("\t{HPPA_TYPE_%s,\tHPPA_%s_%s,\t\"", toupper($1),
		       toupper($1), toupper($2), $3) > cpud;
		f = 4;
		while (f <= NF) {
			sub(/[ \t]*/, "", $f);
			ep = match($f, /\*\//);
			if (busted && !ep) {
				f++;
				continue;
			}
			if (match($f, /\/\*/)) {
				if (ep) {
					sub(/\/\*/, "", $f);
				} else {
					sub(/\/\*.*$/, "", $f);
					busted++;
				}
			}
			if (ep) {
				gsub(/^.*\*\//, "", $f);
				busted = 0;
			}
			if (length($f)) {
				if (f > 4)
					printf (" ") > cpud;
				printf ("%s", $f) > cpud;
			}
			f++;
		}
		printf("\" },\n") > cpud;
	} else {
		printf("WHA at line %d\n", NR);
		exit(1);
	}
}

END	{
	if (busted) {
		print("unteminated comment at the EOF\n");
		exit(1);
	}
	printf("\t{ -1 }\n};\n") > cpud;
}


Handle cases where system time is adjusted backwards (e.g. by NTP).

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
        currentTimeOffset = 0.0
    }
    else
    {
        previousTimeOffset = currentTimeOffset
        currentTimestamp = substr($1, 2, length($1) - 2)
        currentTimeOffset = currentTimestamp - startTimestamp
        if (currentTimeOffset < 0)
        {
            startTimestamp = currentTimestamp + currentTimeOffset
            currentTimeOffset = previousTimeOffset
        }
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, currentTimeOffset * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}

{
    if (1==NR)
    {
        startTimestamp = substr($1, 2, length($1) - 2)
        printf(";$FILEVERSION=1.3\n")
        printf(";$STARTTIME=%u.%u\n", mktime(strftime("%Y %m %d 0 0 0", startTimestamp)) / 86400 + 25569, \
                10000000000 / 86400 * (mktime(strftime("%Y %m %d %H %M %S", startTimestamp)) - mktime(strftime("%Y %m %d 0 0 0", startTimestamp))))
    }
    printf("%u) %.3f 1 Rx %s - %s", NR, (substr($1, 2, length($1) - 2) - startTimestamp) * 1000, $3, substr($4, 2, length($4) - 2))
    if (5<=NF)
    {
        for(i=5;i<=NF;i++)
        {
            printf " "$i
        }
    }
    printf "\n"
}