From 070c57c5c4b7fd66a8863b9f0782b4bb4e43d824 Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Fri, 28 Sep 2007 23:38:14 +0000 Subject: [PATCH] pull up r19862 from trunk r19862@cathode-dark-space: jaltman | 2007-08-24 10:41:52 -0400 ticket: new subject: NIM: support include files in schemas component: windows The ccsv.pl and csvschema.cfg scripts are used to generate "C" source code from CSV files containing tabular data. In particular, these are used to define the configuration schema for Network Identity Manager and some of its plug-ins. It is desirable to be able to include arbitrary header files and define macros in the generated C code so that the schema definition can use them. This patch allows the CSV files to contain headers that define lines of text that will be included literally in the generated C code. Lines at the start of schema CSV file that begin with '#@' will be stripped of the '#@' prefix and inserted into the C code. E.g: The following line at the start of a schema CSV file: #@#include ,will result in the following text in the C code: #include Then the schema definition can use macros of the form: ClrHeaderExpSel, KC_INT32, "RGB(195, 94, 94)" ,which use macros such as RGB that are defined in the included header file. ticket: 5683 version_fixed: 1.6.3 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19997 dc483132-0cff-0310-8789-dd5450dbe970 --- src/windows/identity/config/ccsv.pl | 258 +++++++++++----------- src/windows/identity/config/csvschema.cfg | 132 +++++------ 2 files changed, 201 insertions(+), 189 deletions(-) diff --git a/src/windows/identity/config/ccsv.pl b/src/windows/identity/config/ccsv.pl index a3777975a..f23179363 100644 --- a/src/windows/identity/config/ccsv.pl +++ b/src/windows/identity/config/ccsv.pl @@ -1,124 +1,134 @@ -#!/usr/bin/perl - -# -# Copyright (c) 2004 Massachusetts Institute of Technology -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, copy, -# modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - - -# This is a simple script that is used for generating C code from CSV -#files. We expect three arguments, the which is the .csv file -#to be parsed, a which is a configuration file and the -#. - -# The configuration file is a perl file which defines the following -#variables : - -# $skip_lines : the number of lines to skip in the csv. The default is 0 - -# @pquote : an array of boolean integers that specify whether or not -# to quote the specific field using double quotes. The default is to -# not quote anything. - -# $file_prefix : the prefix for the file - -# $record_prefix : the prefix for each record - -# $field_sep : the field separator. The default is ',' - -# $record_postfix : the postfix for each record - -# $record_sep : A record separator. Only shows up between records. - -# $file_postfix : the postfix for the entire file - -use Text::ParseWords; - -sub do_nothingus { -} - -if($#ARGV != 2) { - print "Usage: ccsv.pl \n"; - die; -} - -$infn=$ARGV[0]; -$cfgfn=$ARGV[1]; -$outfn=$ARGV[2]; - -$skip_lines = 0; -@pquote = {}; -$file_prefix = ""; -$record_prefix = ""; -$field_sep = ","; -$record_postfix = ""; -$record_sep = "\n"; -$file_postfix = ""; -$record_parser = \&do_nothingus; - -($inbase) = ($infn =~ m/^(\w*)/); - -do $cfgfn; - -open(IN, "<".$infn) or die "Can't open input file:".$infn; -open(OUT, ">".$outfn) or die "Can't open output file:".$outfn; - -print OUT $file_prefix; - -$first_line = 1; - -while() { - chomp $_; - if (m/^\#/) { - # ignore - } elsif ($skip_lines > 0) { - $skip_lines--; - } else { - if($first_line == 0){ - print OUT $record_sep; - } else { - $first_line = 0; - } - - @fields = &parse_line(',',0,$_); - for(@fields) { - chomp; - s/^\s*//; - } - - &$record_parser(\@fields); - - print OUT $record_prefix; - for(my $i=0; $i <= $#fields; $i++) { - print OUT $field_sep if $i != 0; - print OUT 'L"' if $pquote[$i] == 1; - print OUT $fields[$i]; - print OUT '"' if $pquote[$i] == 1; - } - print OUT $record_postfix; - } -} - -print OUT $file_postfix; - -close INF; -close OUT; +#!/usr/bin/perl + +# +# Copyright (c) 2004 Massachusetts Institute of Technology +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, copy, +# modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +# + + +# This is a simple script that is used for generating C code from CSV +#files. We expect three arguments, the which is the .csv file +#to be parsed, a which is a configuration file and the +#. + +# The configuration file is a perl file which defines the following +#variables : + +# $skip_lines : the number of lines to skip in the csv. The default is 0 + +# @pquote : an array of boolean integers that specify whether or not +# to quote the specific field using double quotes. The default is to +# not quote anything. + +# $file_prefix : the prefix for the file + +# $record_prefix : the prefix for each record + +# $field_sep : the field separator. The default is ',' + +# $record_postfix : the postfix for each record + +# $record_sep : A record separator. Only shows up between records. + +# $file_postfix : the postfix for the entire file + +use Text::ParseWords; + +sub do_nothingus { +} + +if($#ARGV != 2) { + print "Usage: ccsv.pl \n"; + die; +} + +$infn=$ARGV[0]; +$cfgfn=$ARGV[1]; +$outfn=$ARGV[2]; + +$skip_lines = 0; +@pquote = {}; +$file_prefix = ""; +$record_prefix = ""; +$finc = ""; +$field_sep = ","; +$record_postfix = ""; +$record_sep = "\n"; +$file_postfix = ""; +$record_parser = \&do_nothingus; + +($inbase) = ($infn =~ m/^(\w*)/); + +do $cfgfn; + +open(IN, "<".$infn) or die "Can't open input file:".$infn; +open(OUT, ">".$outfn) or die "Can't open output file:".$outfn; + +$first_line = 1; + +while() { + chomp $_; + if (m/^\#/) { + if (m/^\#\@/) { + ($inc) = m/^\#\@(.*)/; + $finc = $finc.$inc."\n"; + } else { + # ignore + } + } elsif ($skip_lines > 0) { + $skip_lines--; + } else { + if($first_line == 0){ + print OUT $record_sep; + } else { + $file_prefix =~ s/\$finc/$finc/; + print OUT $file_prefix; + $first_line = 0; + } + + @fields = &parse_line(',',0,$_); + for(@fields) { + chomp; + s/^\s*//; + } + + &$record_parser(\@fields); + + print OUT $record_prefix; + for(my $i=0; $i <= $#fields; $i++) { + print OUT $field_sep if $i != 0; + print OUT 'L"' if $pquote[$i] == 1; + print OUT $fields[$i]; + print OUT '"' if $pquote[$i] == 1; + } + print OUT $record_postfix; + } +} + +if ($first_line == 1) { + print OUT $file_prefix; +} + +print OUT $file_postfix; + +close INF; +close OUT; diff --git a/src/windows/identity/config/csvschema.cfg b/src/windows/identity/config/csvschema.cfg index cc8acd26b..a21c83c5b 100644 --- a/src/windows/identity/config/csvschema.cfg +++ b/src/windows/identity/config/csvschema.cfg @@ -1,65 +1,67 @@ -# -# Copyright (c) 2004 Massachusetts Institute of Technology -# -# Permission is hereby granted, free of charge, to any person -# obtaining a copy of this software and associated documentation -# files (the "Software"), to deal in the Software without -# restriction, including without limitation the rights to use, copy, -# modify, merge, publish, distribute, sublicense, and/or sell copies -# of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS -# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN -# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. -# - -$file_prefix = < - -kconf_schema schema_$inbase\[] = { -EOS - -$record_prefix = "{"; - -$record_sep = ",\n"; - -$record_postfix = "}"; - -$file_postfix = < + +\$finc + +kconf_schema schema_$inbase\[] = { +EOS + +$record_prefix = "{"; + +$record_sep = ",\n"; + +$record_postfix = "}"; + +$file_postfix = <