Constant generation needs to handle multiline comments. (dm)

###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2019 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed 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. Please see the file LICENSE-LGPL for details.
#
# Web Page: http://brltty.app/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

BEGIN {
  brlCommandValue = 0
  brlBlockValue = 0
  brlKeyValue = 0

  brlBlockDeprecations["CLIP_NEW"] = "CUTBEGIN"
  brlBlockDeprecations["CLIP_ADD"] = "CUTAPPEND"
  brlBlockDeprecations["COPY_LINE"] = "CUTLINE"
  brlBlockDeprecations["COPY_RECT"] = "CUTRECT"
  brlBlockDeprecations["CLIP_COPY"] = "COPYCHARS"
  brlBlockDeprecations["CLIP_APPEND"] = "APNDCHARS"
}

/^\s*BRL_CMD_/ {
  brlCommand(substr($1, 9), $1, brlCommandValue++, getComment($0))
  next
}

/^\s*BRL_BLK_/ {
  prefix = substr($1, 1, 8)
  name = substr($1, 9)
  value = brlBlockValue++
  help = getComment($0)

  if (help !~ /^\(/) {
    brlBlock(name, $1, value, help)

    if (name in brlBlockDeprecations) {
      alias = brlBlockDeprecations[name]
      brlBlock(alias, prefix alias, value, "deprecated definition of " name " - " help)
    }
  }

  next
}

/^\s*BRL_KEY_/ {
  gsub(",", "", $1)
  key = tolower(substr($1, 9))
  gsub("_", "-", key)
  brlKey(substr($1, 9), $1, brlKeyValue++, key " key")
  next
}

/#define\s+BRL_FLG_/ {
  brlFlag(substr($2, 9), $2, getDefineValue(), getComment($0))
  next
}

/#define\s+BRL_DOT/ {
  value = getDefineValue()
  sub("^.*\\(", "", value)
  sub("\\).*$", "", value)
  value = 2 ^ (value - 1)
  brlDot(substr($2, 8), $2, value, getComment($0))
  next
}

function writeHeaderPrologue(symbol, copyrightFile) {
  writeCopyright(copyrightFile)

  headerSymbol = symbol
  print "#ifndef " headerSymbol
  writeMacroDefinition(headerSymbol)
  print ""

  print "#ifdef __cplusplus"
  print "extern \"C\" {"
  print "#endif /* __cplusplus */"
  print ""
}

function writeCopyright(file) {
  if (length(file) > 0) {
    while (getline line <file == 1) {
      if (match(line, "^ */\\* *$")) {
        print line

        while (getline line <file == 1) {
          print line
          if (match(line, "^ *\\*/ *$")) break
        }

        print ""
        break
      }
    }
  }
}

function writeHeaderEpilogue() {
  print ""
  print "#ifdef __cplusplus"
  print "}"
  print "#endif /* __cplusplus */"

  print ""
  print "#endif /* " headerSymbol " */"
}

function writeMacroDefinition(name, definition, help) {
  statement = "#define " name
  if (length(definition) > 0) statement = statement " " definition

  if (length(help) > 0) print makeDoxygenComment(help)
  print statement
}

function getComment(line,     comment, last) {
  comment = ""

  if (match(line, "/\\*")) {
    line = substr(line, RSTART+2)
    gsub("^\\**<? *", "", line)

    while (1) {
      last = gsub("\\*/.*$", "", line)
      gsub(" *$", "", line)

      if (length(comment) > 0) comment = comment " "
      comment = comment line
      if (last) break

      getline line
      gsub("^\\s*\\**\\s*", "", line)
    }
  } else if (match(line, "//")) {
    comment = substr(line, RSTART+2);
    gsub("^ *", "", comment)

    gsub("\\*/.*$", "", comment)
    gsub(" *$", "", comment)
  }

  return comment
}

function getDefineValue() {
  if ($3 !~ "^\\(") return getNormalizedConstant($3)
  if (match($0, "\\([^)]*\\)")) return substr($0, RSTART, RLENGTH)
  return ""
}

function getNormalizedConstant(value) {
   if (value ~ "^UINT64_C\\(.+\\)$") value = substr(value, 10, length(value)-10)
   return value
}

function makeDoxygenComment(text) {
  return "/** " text " */"
}

function beginDoxygenFile() {
  print "/** \\file"
  print " */"
  print ""
}

function getBrlapiKeyName(name) {
  if (name == "ENTER") return "LINEFEED"
  if (name ~ /^CURSOR_/) return substr(name, 8)
  return name
}

###############################################################################
# BRLTTY - A background process providing access to the console screen (when in
#          text mode) for a blind person using a refreshable braille display.
#
# Copyright (C) 1995-2019 by The BRLTTY Developers.
#
# BRLTTY comes with ABSOLUTELY NO WARRANTY.
#
# This is free software, placed 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. Please see the file LICENSE-LGPL for details.
#
# Web Page: http://brltty.app/
#
# This software is maintained by Dave Mielke <dave@mielke.cc>.
###############################################################################

BEGIN {
  brlCommandValue = 0
  brlBlockValue = 0
  brlKeyValue = 0

  brlBlockDeprecations["CLIP_NEW"] = "CUTBEGIN"
  brlBlockDeprecations["CLIP_ADD"] = "CUTAPPEND"
  brlBlockDeprecations["COPY_LINE"] = "CUTLINE"
  brlBlockDeprecations["COPY_RECT"] = "CUTRECT"
  brlBlockDeprecations["CLIP_COPY"] = "COPYCHARS"
  brlBlockDeprecations["CLIP_APPEND"] = "APNDCHARS"
}

/^\s*BRL_CMD_/ {
  brlCommand(substr($1, 9), $1, brlCommandValue++, getComment($0))
  next
}

/^\s*BRL_BLK_/ {
  prefix = substr($1, 1, 8)
  name = substr($1, 9)
  value = brlBlockValue++
  help = getComment($0)

  if (help !~ /^\(/) {
    brlBlock(name, $1, value, help)

    if (name in brlBlockDeprecations) {
      alias = brlBlockDeprecations[name]
      brlBlock(alias, prefix alias, value, "deprecated definition of " name " - " help)
    }
  }

  next
}

/^\s*BRL_KEY_/ {
  gsub(",", "", $1)
  key = tolower(substr($1, 9))
  gsub("_", "-", key)
  brlKey(substr($1, 9), $1, brlKeyValue++, key " key")
  next
}

/#define\s+BRL_FLG_/ {
  brlFlag(substr($2, 9), $2, getDefineValue(), getComment($0))
  next
}

/#define\s+BRL_DOT/ {
  value = getDefineValue()
  sub("^.*\\(", "", value)
  sub("\\).*$", "", value)
  value = 2 ^ (value - 1)
  brlDot(substr($2, 8), $2, value, getComment($0))
  next
}

function writeHeaderPrologue(symbol, copyrightFile) {
  writeCopyright(copyrightFile)

  headerSymbol = symbol
  print "#ifndef " headerSymbol
  writeMacroDefinition(headerSymbol)
  print ""

  print "#ifdef __cplusplus"
  print "extern \"C\" {"
  print "#endif /* __cplusplus */"
  print ""
}

function writeCopyright(file) {
  if (length(file) > 0) {
    while (getline line <file == 1) {
      if (match(line, "^ */\\* *$")) {
        print line

        while (getline line <file == 1) {
          print line
          if (match(line, "^ *\\*/ *$")) break
        }

        print ""
        break
      }
    }
  }
}

function writeHeaderEpilogue() {
  print ""
  print "#ifdef __cplusplus"
  print "}"
  print "#endif /* __cplusplus */"

  print ""
  print "#endif /* " headerSymbol " */"
}

function writeMacroDefinition(name, definition, help) {
  statement = "#define " name
  if (length(definition) > 0) statement = statement " " definition

  if (length(help) > 0) print makeDoxygenComment(help)
  print statement
}

function getComment(line) {
  if (!match(line, "/\\*.*\\*/")) return ""
  line = substr(line, RSTART+2, RLENGTH-4)

  match(line, "^\\**<? *")
  line = substr(line, RLENGTH+1)

  match(line, " *$")
  return substr(line, 1, RSTART-1)
}

function getDefineValue() {
  if ($3 !~ "^\\(") return getNormalizedConstant($3)
  if (match($0, "\\([^)]*\\)")) return substr($0, RSTART, RLENGTH)
  return ""
}

function getNormalizedConstant(value) {
   if (value ~ "^UINT64_C\\(.+\\)$") value = substr(value, 10, length(value)-10)
   return value
}

function makeDoxygenComment(text) {
  return "/** " text " */"
}

function beginDoxygenFile() {
  print "/** \\file"
  print " */"
  print ""
}

function getBrlapiKeyName(name) {
  if (name == "ENTER") return "LINEFEED"
  if (name ~ /^CURSOR_/) return substr(name, 8)
  return name
}


Update getAcornFrom-episodePages.awk

Update getAcornFrom-episodePages.awk

Fix site change from "container footer" to "footer"

# Generate an episode description from an Acorn episode file and check for duplicates
#
# INVOCATION:
#       curl -sS --config $EPISODE_CURL_FILE \
#           | awk -v EPISODE_DESCRIPTION_FILE=$EPISODE_DESCRIPTION_FILE \
#           -v ERROR_FILE=$ERROR_FILE -v EPISODE_CURL_FILE=$EPISODE_CURL_FILE \
#           -v EPISODE_NUMBER=$episodeNumber -f getAcornFrom-episodePages.awk
#
# INPUT:
#       <meta itemprop="description" content="Still riddled with guilt after a shooting, \
#       seasoned police officer Nick Barron ... initiates an internal investigation." />
# ---
#       <meta itemprop="numberOfEpisodes" content="1" />
# ---
#       Served from: acorn.tv @ 2017-08-05 20:49:53 by W3 Total Cache
#
# OUTPUT:
#       $EPISODE_DESCRIPTION_FILE
#

# Extract the episode description
/<meta itemprop="description" content="/ {
    sub (/.*content="/,"")
    sub (/..\/>/,"")
    # fix sloppy input spacing
    gsub (/ \./,".")
    gsub (/  */," ")
    sub (/ *$/,"")
    # fix funky HTML characters
    gsub (/‘/,"’")
    gsub (/’/,"’")
    episodeDescription = $0
    next
}

# Extract series with only one episode
/<meta itemprop="numberOfEpisodes" content="1"/ {
    singleEpisode = "yes"
    next
}

# When we get to the bottom of the episode
/<div class="footer"/ {
    printf ("%s\n", episodeDescription) >> EPISODE_DESCRIPTION_FILE
    #
    # Grab the URL from the EPISODE_CURL_FILE - you can't dig it out from here
    cmd = "cat -n " EPISODE_CURL_FILE " | grep ' " EPISODE_NUMBER "\t'"
    #
    # Warn about empty descriptions
    if (episodeDescription == "") {
        while ((cmd | getline url) > 0)
            print "==> No description: " url >> ERROR_FILE
        close (cmd)
    }
    episodeDescription = ""
    #
    # Warn about series with only one episode
    if (singleEpisode != "") {
        while ((cmd | getline url) > 0)
            print "==> Only one episode: " url >> ERROR_FILE
        close (cmd)
    }
    singleEpisode = ""
    #
    # Get ready for next episode
    EPISODE_NUMBER += 1
}

# Generate an episode description from an Acorn episode file and check for duplicates
#
# INVOCATION:
#       curl -sS --config $EPISODE_CURL_FILE \
#           | awk -v EPISODE_DESCRIPTION_FILE=$EPISODE_DESCRIPTION_FILE \
#           -v ERROR_FILE=$ERROR_FILE -v EPISODE_CURL_FILE=$EPISODE_CURL_FILE \
#           -v EPISODE_NUMBER=$episodeNumber -f getAcornFrom-episodePages.awk
#
# INPUT:
#       <meta itemprop="description" content="Still riddled with guilt after a shooting, \
#       seasoned police officer Nick Barron ... initiates an internal investigation." />
# ---
#       <meta itemprop="numberOfEpisodes" content="1" />
# ---
#       Served from: acorn.tv @ 2017-08-05 20:49:53 by W3 Total Cache
#
# OUTPUT:
#       $EPISODE_DESCRIPTION_FILE
#

# Extract the episode description
/<meta itemprop="description" content="/ {
    sub (/.*content="/,"")
    sub (/..\/>/,"")
    # fix sloppy input spacing
    gsub (/ \./,".")
    gsub (/  */," ")
    sub (/ *$/,"")
    # fix funky HTML characters
    gsub (/‘/,"’")
    gsub (/’/,"’")
    episodeDescription = $0
    next
}

# Extract series with only one episode
/<meta itemprop="numberOfEpisodes" content="1"/ {
    singleEpisode = "yes"
    next
}

# When we get to the bottom of the episode
/<div class="container footer"/ {
    printf ("%s\n", episodeDescription) >> EPISODE_DESCRIPTION_FILE
    #
    # Grab the URL from the EPISODE_CURL_FILE - you can't dig it out from here
    cmd = "cat -n " EPISODE_CURL_FILE " | grep ' " EPISODE_NUMBER "\t'"
    #
    # Warn about empty descriptions
    if (episodeDescription == "") {
        while ((cmd | getline url) > 0)
            print "==> No description: " url >> ERROR_FILE
        close (cmd)
    }
    episodeDescription = ""
    #
    # Warn about series with only one episode
    if (singleEpisode != "") {
        while ((cmd | getline url) > 0)
            print "==> Only one episode: " url >> ERROR_FILE
        close (cmd)
    }
    singleEpisode = ""
    #
    # Get ready for next episode
    EPISODE_NUMBER += 1
}


fixed https://github.com/timrdf/csv2rdf4lod-automation/issues/112

# e-params-increment.awk
#
# params: eID

{
   if(/^@prefix : /){
      # change
      # @prefix :           <http://logd.tw.rpi.edu/source/nitrd-gov/dataset/fed_RD_IT/version/2011-Jan-27/conversion/enhancement/1> .
      # to
      # @prefix :           <http://logd.tw.rpi.edu/source/nitrd-gov/dataset/fed_RD_IT/version/2011-Jan-27/conversion/enhancement/2> .
      sub(/enhancement\/[^\/]*\//,"enhancement/"eID);
      print $0
   }else if(/^</ && /source\// && /dataset\// && /version\// && /conversion\// && /enhancement\/[^\/]*>/){
      sub(/enhancement\/[^\/]*>/,"enhancement/"eID">");
      print $0
   }else if( $0~"conversion:enhancement_identifier" ) {
      printf("      conversion:enhancement_identifier \"%s\";\n",eID)}
   else {
      print
   }
}

# e-params-increment.awk
#
# params: eID

{
   if(/^@prefix : /){
      # change
      # @prefix :           <http://logd.tw.rpi.edu/source/nitrd-gov/dataset/fed_RD_IT/version/2011-Jan-27/conversion/enhancement/1> .
      # to
      # @prefix :           <http://logd.tw.rpi.edu/source/nitrd-gov/dataset/fed_RD_IT/version/2011-Jan-27/conversion/enhancement/2> .
      sub(/enhancement\/[^\/]*\//,"enhancement/"eID);
      print $0
   }else if( $0~"conversion:enhancement_identifier" ) {
      printf("      conversion:enhancement_identifier \"%s\";\n",eID)}
   else {
      print
   }
}


Use \r instead of \x0d in awk pattern for portability

Hex escapes in the regexps are not supported in Solaris nawk, for
instance. \r should match a CR in all cases as far as I know.

#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# 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 {
    CCversion = 0
    compiler_matched = 0
}
# Sun c++ compiler
/Sun WorkShop/ || /Forte Developer/ || /Sun/{
    compiler_matched = 1
    # version number right after "C++"
    x = match( $0, /C\+\+ .*/ )
    btwn = substr( $0, RSTART, RLENGTH)
    # extract version, whitespaces get striped later
    x = match( btwn, / .*\..*[ $\t]/)
    CCversion = substr( btwn, RSTART, RLENGTH)
}
# Microsoft c++ compiler
/Microsoft/ && /..\...\...../ {
    compiler_matched = 1
    # match on the format of the ms versions ( dd.dd.dddd )
    x = match( $0, /..\...\...../ )
    CCversion = substr( $0, RSTART, RLENGTH)
}
# Java
/java version/ || /openjdk version/ {
    compiler_matched = 1
    # match on the format of the java versions ( d[d].d[d].d[d] )
    x = match( $0, /[0-9]*\.[0-9]*\.[0-9]*/ )
    CCversion = substr( $0, RSTART, RLENGTH)
}
/^[0-9]*[.][0-9]*\r*$/ {
    if ( compiler_matched == 0 ) {
# need to blow to x.xx.xx for comparing
    	CCversion = $0 ".0"
    }
}
/^[0-9]*[.][0-9]*[.][0-9]*\r*$/ {
    if ( compiler_matched == 0 ) {
        CCversion = $0
    }
}
/^[0-9]*[.][0-9]*[.][0-9]*-[0-9a-z]*$/ {
    if ( compiler_matched == 0 ) {
        CCversion = substr($0, 0, index($0, "-") - 1)
    }
}
END {
    if ( num == "true" ) {
        tokencount = split (CCversion,vertoken,".")
        for ( i = 1 ; i <= tokencount ; i++ ) {
            printf ("%04d",vertoken[i] )
        }
    } else
        print CCversion
}

#*************************************************************************
#
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# Copyright 2000, 2010 Oracle and/or its affiliates.
#
# OpenOffice.org - a multi-platform office productivity suite
#
# 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 {
    CCversion = 0
    compiler_matched = 0
}
# Sun c++ compiler
/Sun WorkShop/ || /Forte Developer/ || /Sun/{
    compiler_matched = 1
    # version number right after "C++"
    x = match( $0, /C\+\+ .*/ )
    btwn = substr( $0, RSTART, RLENGTH)
    # extract version, whitespaces get striped later
    x = match( btwn, / .*\..*[ $\t]/)
    CCversion = substr( btwn, RSTART, RLENGTH)
}
# Microsoft c++ compiler
/Microsoft/ && /..\...\...../ {
    compiler_matched = 1
    # match on the format of the ms versions ( dd.dd.dddd )
    x = match( $0, /..\...\...../ )
    CCversion = substr( $0, RSTART, RLENGTH)
}
# Java
/java version/ || /openjdk version/ {
    compiler_matched = 1
    # match on the format of the java versions ( d[d].d[d].d[d] )
    x = match( $0, /[0-9]*\.[0-9]*\.[0-9]*/ )
    CCversion = substr( $0, RSTART, RLENGTH)
}
/^[0-9]*[.][0-9]*\x0d*$/ {
    if ( compiler_matched == 0 ) {
# need to blow to x.xx.xx for comparing
    	CCversion = $0 ".0"
    }
}
/^[0-9]*[.][0-9]*[.][0-9]*\x0d*$/ {
    if ( compiler_matched == 0 ) {
        CCversion = $0
    }
}
/^[0-9]*[.][0-9]*[.][0-9]*-[0-9a-z]*$/ {
    if ( compiler_matched == 0 ) {
        CCversion = substr($0, 0, index($0, "-") - 1)
    }
}
END {
    if ( num == "true" ) {
        tokencount = split (CCversion,vertoken,".")
        for ( i = 1 ; i <= tokencount ; i++ ) {
            printf ("%04d",vertoken[i] )
        }
    } else
        print CCversion
}


handling #conversion:label

handling #conversion:label

# cell-ify-eparams.awk
#
# columns 12 to 72 should be cellified: jot -s "," `expr 71 - 12 + 1` 12
#
#
# Parameters:
#    cellify:     What columns?     comma-separated list of column indexes to cellify. e.g. 65,66,67,68,69
#                                     hint: use `jot -s "," 5 65` or seq
#
#    label_up:    Primary label?
#
#    up_object:   Primary object?   Object of up value. If '.', use ov:csvHeader as a literal. If ':', use ov:csvHeader as a resource.
#
#    up_range:    Primary object?   Object of up value
#
#    out_range:   ? e.g. Type of out value.                                        e.g. xsd:gYear
#
#    labels_up:   What range?       comma-separated list of secondary predicate labels.
#
# Example:
#      conversion:enhance [
#         ov:csvCol         65;
#         ov:csvHeader     "BAR00";
#         conversion:label "BAR00";
#         conversion:range  todo:Literal;
#      ];
#
# (params: )
#
#      conversion:enhance [
#          ov:csvCol         65;
#          ov:csvHeader     "BAR00";
#          conversion:label "Year";                      # WAS: BAR00
#          conversion:object "2000"^^xsd:gYear;          # new: value represented by column header
#          conversion:range  rdfs:decimal;               # WAS: todo:Literal
#       ];
#       conversion:enhance [                             # new:
#          ov:csvCol         65;                         # new:
#          conversion:predicate "Place";                 # new:
#          conversion:object    "Bar";                   # new:
#       ];                                               # new:
#
# Example usage:
#
#    (input)
#
#    conversion:enhance [
#       ov:csvCol         12;
#       ov:csvHeader     "Sum_WORK90";
#       conversion:label "Sum_WORK90";
#       conversion:range  todo:Literal;
#    ];
#
#    cat cities-pc-cnty.csv.e1.params.ttl | awk -f $CSV2RDF4LOD_HOME/bin/util/cell-ify-eparams.awk -v cellify=`jot -s "," 60 12` -v label_up="Year" -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue
#
#    (output)
#
#    conversion:enhance [
#       ov:csvCol         12;
#       ov:csvHeader     "Sum_WORK90";
#       a scovo:Item;                                               # :
#       conversion:label  "Year";                                   # : was "Sum_WORK90";
#       conversion:object ""^^xsd:gYear;                            # :
#       conversion:range  xsd:decimal;                              # : was todo:Literal;
#    ];
#    conversion:enhance [                                           # :
#       ov:csvCol            12;                                    # :
#       conversion:predicate "Venue";                               # :
#       conversion:object    "";                                    # :
#    ];                                                             # :
#
# NOTE: The conversion:objects must still be populated.

BEGIN {
   PADDING = 70;

   num_cells = split(cellify,cell_column,",");
   for(i=1; i<=num_cells; i++) {
      c = cell_column[i];
      a_cell[c] = "true";
   }
   num_labels_up = split(labels_up,secondaryPs,",");

   in_cell_enhancement = "false";
}

$1 == "ov:csvCol" && in_cell_enhancement ==  "false" {
   column=$2;
   gsub(/;/,"",column);
   gsub(/\"/,"",column);
   if( a_cell[column] == "true" ) {
      in_cell_enhancement = "true";
   }
}

function annotate(pre,pad,annotation)
{
   line=pre;
   spaces="";
   for(i=1; i<(pad-length(line)); i++) {
      spaces=spaces" ";
   }
   return sprintf("%s%s# : %s",line,spaces,annotation);
}

in_cell_enhancement == "true" {
   if( $1 == "ov:csvCol" ) {
      lastCol=$2;
      gsub(/;/,"",lastCol);
      gsub(/\"/,"",lastCol);
   }
   line=$0;

   if( length(label_up) > 0 && $1 == "conversion:label" || $1 == "#conversion:label" ) {
      print annotate("         conversion:label  \""label_up"\";",PADDING,"was "$2);
   }else if( length(out_range) > 0 && $1 == "conversion:range" ) {
      print annotate("         conversion:range  "out_range";",PADDING,"was "$2);
   }else if( $1 == "];" ) {
      print $0
      for(i=1; i<=num_labels_up; i++) {
          what=sprintf("         conversion:predicate \"%s\";",secondaryPs[i]);
         print annotate(        "      conversion:enhance [",PADDING,"");
         print annotate(        "         ov:csvCol            "lastCol";",PADDING,"");
         print annotate(what ,PADDING,"");
         print annotate(        "         conversion:object    \"\";",PADDING,"");
         print annotate(        "      ];",PADDING,"");
      }
   }else {
      print
   }

   if( $1 == "ov:csvHeader" ) {
      current_header=$2;
      gsub(/"/,"",current_header);
      gsub(/;/,"",current_header);
      print annotate("         a scovo:Item;",PADDING,"");
   }
   if( length(label_up) > 0 && $1 == "conversion:label" ) {
      datatype = length(up_range) > 0 ? "^^"up_range : "";
      if( up_object == ":" ) {
         print annotate("         conversion:object :"current_header";",PADDING,"");
      }else if( up_object == "." ) {
         print annotate("         conversion:object \""current_header"\""datatype";",PADDING,"");
      }else {
         print annotate("         conversion:object \""up_object"\""datatype";",PADDING,"");
      }
   }
}

{
   if( in_cell_enhancement == "true" && $1 == "];" ) {
      in_cell_enhancement = "false";
   }else if( in_cell_enhancement == "false" ) {
      print $0
   }
}

END {
   #if( num_cells == 0 ) {
      print "# params:"
      print "#   -v cellify=`jot -s \",\" 5 10` -v label_up=Year -v up_object={. : Blah} -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue,Another,YAnother"
      print "#   -v cellify=`echo \"\" | awk '{for(i=5;i<=10;i++){printf(\",%s\",i)}}'` -v label_up=Year -v up_object=Blah -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue,Another,YAnother"
   #}
}

# cell-ify-eparams.awk
#
# columns 12 to 72 should be cellified: jot -s "," `expr 71 - 12 + 1` 12
#
#
# Parameters:
#    cellify:     What columns?     comma-separated list of column indexes to cellify. e.g. 65,66,67,68,69
#                                     hint: use `jot -s "," 5 65` or seq
#
#    label_up:    Primary label?
#
#    up_object:   Primary object?   Object of up value. If '.', use ov:csvHeader as a literal. If ':', use ov:csvHeader as a resource.
#
#    up_range:    Primary object?   Object of up value
#
#    out_range:   ? e.g. Type of out value.                                        e.g. xsd:gYear
#
#    labels_up:   What range?       comma-separated list of secondary predicate labels.
#
# Example:
#      conversion:enhance [
#         ov:csvCol         65;
#         ov:csvHeader     "BAR00";
#         conversion:label "BAR00";
#         conversion:range  todo:Literal;
#      ];
#
# (params: )
#
#      conversion:enhance [
#          ov:csvCol         65;
#          ov:csvHeader     "BAR00";
#          conversion:label "Year";                      # WAS: BAR00
#          conversion:object "2000"^^xsd:gYear;          # new: value represented by column header
#          conversion:range  rdfs:decimal;               # WAS: todo:Literal
#       ];
#       conversion:enhance [                             # new:
#          ov:csvCol         65;                         # new:
#          conversion:predicate "Place";                 # new:
#          conversion:object    "Bar";                   # new:
#       ];                                               # new:
#
# Example usage:
#
#    (input)
#
#    conversion:enhance [
#       ov:csvCol         12;
#       ov:csvHeader     "Sum_WORK90";
#       conversion:label "Sum_WORK90";
#       conversion:range  todo:Literal;
#    ];
#
#    cat cities-pc-cnty.csv.e1.params.ttl | awk -f $CSV2RDF4LOD_HOME/bin/util/cell-ify-eparams.awk -v cellify=`jot -s "," 60 12` -v label_up="Year" -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue
#
#    (output)
#
#    conversion:enhance [
#       ov:csvCol         12;
#       ov:csvHeader     "Sum_WORK90";
#       a scovo:Item;                                               # :
#       conversion:label  "Year";                                   # : was "Sum_WORK90";
#       conversion:object ""^^xsd:gYear;                            # :
#       conversion:range  xsd:decimal;                              # : was todo:Literal;
#    ];
#    conversion:enhance [                                           # :
#       ov:csvCol            12;                                    # :
#       conversion:predicate "Venue";                               # :
#       conversion:object    "";                                    # :
#    ];                                                             # :
#
# NOTE: The conversion:objects must still be populated.

BEGIN {
   PADDING = 70;

   num_cells = split(cellify,cell_column,",");
   for(i=1; i<=num_cells; i++) {
      c = cell_column[i];
      a_cell[c] = "true";
   }
   num_labels_up = split(labels_up,secondaryPs,",");

   in_cell_enhancement = "false";
}

$1 == "ov:csvCol" && in_cell_enhancement ==  "false" {
   column=$2;
   gsub(/;/,"",column);
   gsub(/\"/,"",column);
   if( a_cell[column] == "true" ) {
      in_cell_enhancement = "true";
   }
}

function annotate(pre,pad,annotation)
{
   line=pre;
   spaces="";
   for(i=1; i<(pad-length(line)); i++) {
      spaces=spaces" ";
   }
   return sprintf("%s%s# : %s",line,spaces,annotation);
}

in_cell_enhancement == "true" {
   if( $1 == "ov:csvCol" ) {
      lastCol=$2;
      gsub(/;/,"",lastCol);
      gsub(/\"/,"",lastCol);
   }
   line=$0;

   if( length(label_up) > 0 && $1 == "conversion:label" || $1 == "#conversion:label" ) {
      print annotate("         %s  \""label_up"\";",$1,PADDING,"was "$2);
   }else if( length(out_range) > 0 && $1 == "conversion:range" ) {
      print annotate("         conversion:range  "out_range";",PADDING,"was "$2);
   }else if( $1 == "];" ) {
      print $0
      for(i=1; i<=num_labels_up; i++) {
          what=sprintf("         conversion:predicate \"%s\";",secondaryPs[i]);
         print annotate(        "      conversion:enhance [",PADDING,"");
         print annotate(        "         ov:csvCol            "lastCol";",PADDING,"");
         print annotate(what ,PADDING,"");
         print annotate(        "         conversion:object    \"\";",PADDING,"");
         print annotate(        "      ];",PADDING,"");
      }
   }else {
      print
   }

   if( $1 == "ov:csvHeader" ) {
      current_header=$2;
      gsub(/"/,"",current_header);
      gsub(/;/,"",current_header);
      print annotate("         a scovo:Item;",PADDING,"");
   }
   if( length(label_up) > 0 && $1 == "conversion:label" ) {
      datatype = length(up_range) > 0 ? "^^"up_range : "";
      if( up_object == ":" ) {
         print annotate("         conversion:object :"current_header";",PADDING,"");
      }else if( up_object == "." ) {
         print annotate("         conversion:object \""current_header"\""datatype";",PADDING,"");
      }else {
         print annotate("         conversion:object \""up_object"\""datatype";",PADDING,"");
      }
   }
}

{
   if( in_cell_enhancement == "true" && $1 == "];" ) {
      in_cell_enhancement = "false";
   }else if( in_cell_enhancement == "false" ) {
      print $0
   }
}

END {
   #if( num_cells == 0 ) {
      print "# params:"
      print "#   -v cellify=`jot -s \",\" 5 10` -v label_up=Year -v up_object={. : Blah} -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue,Another,YAnother"
      print "#   -v cellify=`echo \"\" | awk '{for(i=5;i<=10;i++){printf(\",%s\",i)}}'` -v label_up=Year -v up_object=Blah -v up_range=xsd:gYear -v out_range=xsd:decimal -v labels_up=Venue,Another,YAnother"
   #}
}