#!/usr/bin/awk -f # # Compiles the given CSV into a table definition # # Copyright (C) 2014-2023 Ryan Specialty, LLC. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program 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 General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ## function columngen( header ) { # output a field constant for each field in the header i = 0 while ( field = header[ ++i ] ) { printf " \n", field, ( i - 1 ), ( seq[ i ] ) ? "true" : "false" } } function seqchk( last ) { # if there's no last row, then do not bother i = 0 while ( i++ < NF ) { if ( seq[ i ] == "" ) seq[ i ] = 1 # this field is sequential if it is greater than or equal to the last field # (we don't check for descending [yet]); note that on the first check, last # will be empty and therefore this check will succeed (properly # initializing seq[i] to 1) seq[ i ] = seq[ i ] && ( $(i) >= last[ i ] ) } } # header BEGIN { rootpath = "../../../" file = ARGV[1] # grab only the filename (remove all preceding directories and the file ext) name = gensub( /^.*\/|\.[^.]+$/, "", "g", file ) # output package header printf \ "\n" \ "\n\n" \ " \n\n" \ " \n" \ " \n\n", \ rootpath, name # the first row of the CSV is the header representing the column identifiers getline split( $0, header, /,/ ) # table constant identifier tconst = toupper( gensub( /-/, "_", "g", name ) ) "_RATE_TABLE" # generate the header for the table constant printf " \n", name printf "%s", " 1 ) ? "," : "" ) $(i) } print ";" seqchk( last ) split( $0, last ) } # footer END { # end of table-rows node print "\" />" # columns can't be generated until after we know which ones represent # sequential data columngen( header ) print " " print "" }