INN commit: trunk (3 files)

INN Commit rra at isc.org
Fri Jul 22 23:08:58 UTC 2011


    Date: Friday, July 22, 2011 @ 16:08:57
  Author: iulius
Revision: 9288

better documentation of the available variables in INN::Config

Document how to obtain the existing INN::Config variables; provide a Perl
script that gives the list.

Add support for the "undef" value in "innconfval -p" (Perl output) so that
the list could be exhaustive.

Add a way to retrieve the real short version ("x.y.z") instead of a long string
("INN x.y.z (prerelease 20110622)").  $INN::Config::VERSION now contains
the short version.

Modified:
  trunk/doc/pod/innconfval.pod
  trunk/lib/innconf.c
  trunk/perl/INN/Config.pm.in

------------------------+
 doc/pod/innconfval.pod |    4 ++--
 lib/innconf.c          |   43 ++++++++++++++++++++++++++++++++++---------
 perl/INN/Config.pm.in  |   44 +++++++++++++++++++++++++++++++++-----------
 3 files changed, 69 insertions(+), 22 deletions(-)

Modified: doc/pod/innconfval.pod
===================================================================
--- doc/pod/innconfval.pod	2011-07-21 01:52:08 UTC (rev 9287)
+++ doc/pod/innconfval.pod	2011-07-22 23:08:57 UTC (rev 9288)
@@ -45,13 +45,13 @@
 will be the same as the F<inn.conf> parameter, and string values will be
 enclosed in single quotes with appropriate escaping.  Boolean values will
 be mapped to the strings C<true> or C<false>.  List values will be mapped
-to an array of strings.  NULL values are not printed out and will therefore
-be C<undef> in Perl.
+to an array of strings.  NULL values are printed out with the C<undef> value.
 
 Here is an example:
 
     $enableoverview = 'true';
     @extraoverviewadvertised = ( 'Newsgroups', 'Injection-Info' );
+    @extraoverviewhidden = undef;
     $organization = 'Let\'s try nasty "quotes"';
     $maxforks = 10;
 

Modified: lib/innconf.c
===================================================================
--- lib/innconf.c	2011-07-21 01:52:08 UTC (rev 9287)
+++ lib/innconf.c	2011-07-22 23:08:57 UTC (rev 9288)
@@ -752,15 +752,19 @@
     const char *letter;
     static const char tcl_unsafe[] = "$[]{}\"\\";
 
-    /* Do not output NULL values.  They are not empty strings. */
-    if (value == NULL)
-        return;
-
     switch (quoting) {
     case INNCONF_QUOTE_NONE:
-        fprintf(file, "%s\n", value != NULL ? value : "");
+        /* Do not output NULL values.  They are not empty strings. */
+        if (value == NULL) {
+            return;
+        }
+        fprintf(file, "%s\n", value);
         break;
     case INNCONF_QUOTE_SHELL:
+        /* Do not output NULL values.  They are not empty strings. */
+        if (value == NULL) {
+            return;
+        }
         upper = xstrdup(key);
         for (p = upper; *p != '\0'; p++)
             *p = toupper(*p);
@@ -777,6 +781,10 @@
         free(upper);
         break;
     case INNCONF_QUOTE_PERL:
+        if (value == NULL) {
+            fprintf(file, "$%s = undef;\n", key);
+            return;
+        }
         fprintf(file, "$%s = '", key);
         for (letter = value; letter != NULL && *letter != '\0'; letter++) {
             if (*letter == '\'' || *letter == '\\')
@@ -786,6 +794,10 @@
         fputs("';\n", file);
         break;
     case INNCONF_QUOTE_TCL:
+        /* Do not output NULL values.  They are not empty strings. */
+        if (value == NULL) {
+            return;
+        }
         fprintf(file, "set inn_%s \"", key);
         for (letter = value; letter != NULL && *letter != '\0'; letter++) {
             if (strchr(tcl_unsafe, *letter) != NULL)
@@ -810,12 +822,12 @@
     unsigned int i;
     static const char tcl_unsafe[] = "$[]{}\"\\";
 
-    /* Do not output NULL values.  They are not empty lists. */
-    if (value == NULL || value->strings == NULL)
-        return;
-
     switch (quoting) {
     case INNCONF_QUOTE_NONE:
+        /* Do not output NULL values.  They are not empty lists. */
+        if (value == NULL || value->strings == NULL) {
+            return;
+        }
         fprintf(file, "[ ");
         if (value != NULL && value->strings != NULL) {
             for (i = 0; i < value->count; i++) {
@@ -827,6 +839,10 @@
         fprintf(file, "]\n");
         break;
     case INNCONF_QUOTE_SHELL:
+        /* Do not output NULL values.  They are not empty lists. */
+        if (value == NULL || value->strings == NULL) {
+            return;
+        }
         upper = xstrdup(key);
         for (p = upper; *p != '\0'; p++)
             *p = toupper(*p);
@@ -859,6 +875,11 @@
         free(upper);
         break;
     case INNCONF_QUOTE_PERL:
+        /* Consider that an empty list is undefined. */
+        if (value == NULL || value->strings == NULL) {
+            fprintf(file, "@%s = undef;\n", key);
+            return;
+        }   
         fprintf(file, "@%s = ( ", key);
         if (value != NULL && value->strings != NULL) {
             for (i = 0; i < value->count; i++) {
@@ -879,6 +900,10 @@
         fprintf(file, ");\n");
         break;
     case INNCONF_QUOTE_TCL:
+        /* Do not output NULL values.  They are not empty lists. */
+        if (value == NULL || value->strings == NULL) {
+            return;
+        }   
         fprintf(file, "set inn_%s { ", key);
         if (value != NULL && value->strings != NULL) {
             for (i = 0; i < value->count; i++) {

Modified: perl/INN/Config.pm.in
===================================================================
--- perl/INN/Config.pm.in	2011-07-21 01:52:08 UTC (rev 9287)
+++ perl/INN/Config.pm.in	2011-07-22 23:08:57 UTC (rev 9288)
@@ -10,7 +10,7 @@
 use Exporter;
 
 our @ISA = qw(Exporter);
-our $VERSION = @PACKAGE_VERSION@;
+our $VERSION = '@PACKAGE_VERSION@';
 
 
 ##  First, two necessary variables (listed below in @DIRVAR).
@@ -21,7 +21,7 @@
 ##  Then, process the variables provided by innconfval.
 my @INNCONFVAR = ();
 my @values = `${exec_prefix}/bin/innconfval -p`;
-foreach $line (@values) {
+foreach my $line (@values) {
   eval 'our '.$line;
   if ($line =~ /^(.*?) = /m) {
     push(@INNCONFVAR, $1);
@@ -186,7 +186,8 @@
 
 ##  This array will contain what it is possible to export.
 our @EXPORT_OK = (@INNCONFVAR, @DIRVAR, @FILESVAR, @PROGVAR,
- at LOCKVAR, @EXTPROGVAR, @EXTCOMPVAR, @SYSVAR, @PARAMVAR);
+ at LOCKVAR, @EXTPROGVAR, @EXTCOMPVAR, @SYSVAR, @PARAMVAR,
+qw($VERSION));
 
 
 ##  Load another script that can override or add variables.
@@ -194,6 +195,7 @@
     do "${pathetc}/innshellvars.pl.local";
 }
 
+
 ##  That's all.
 1;
 
@@ -201,18 +203,38 @@
 
 =head1 NAME
 
-Config.pm - Export all the variables an INN Perl script might need
+INN::Config - Export all the variables an INN Perl script might need
 
 =head1 DESCRIPTION
 
-This Perl module sets up any and all the variables that an INN Perl
-script might need.  More particularly, it allows to use F<inn.conf>
-variables:  they are all provided by B<innconfval>, as well as
-the version of INN (in the variable C<$INN::Config::version>).
-Other useful variables are also provided (directories, files,
-programs, masks, parameters) and you should have a look at the source
-code of the module to see what you can use in your Perl scripts.
+This Perl module sets up any and all the variables that an INN Perl script
+might need.  More particularly, it allows to use F<inn.conf> variables:
+they are all provided by B<innconfval>, as well as the version of INN
+(in the variable C<$INN::Config::VERSION> for its short number form, on in
+C<$INN::Config::version> for its complete form).  Other useful variables
+are also provided (directories, files, programs, masks, parameters).
+The complete list can be obtained with the following script that prints
+them out:
 
+    use lib '<pathnews>/lib/perl';
+    use INN::Config;
+    use Data::Dumper;
+
+    my ($varname, $value);
+    foreach my $var (@INN::Config::EXPORT_OK) {
+        if ($var =~ /^\$(.*)$/) {
+            $varname = "INN::Config::$1";
+            $value = Dumper($$varname);
+            $value =~ s/^\$VAR1 = //;
+            print "\$$varname = $value";
+        } elsif ($var =~ /^\@(.*)$/) {
+            $varname = "INN::Config::$1";
+            $value = Dumper(\@$varname);
+            $value =~ s/^\$VAR1 = //;
+            print "\@$varname = $value";
+        }
+    }
+
 A local Perl script named F<innshellvars.pl.local> in I<pathetc> will be
 loaded, if present and executable, at the end of the run of this module.
 A typical use is to add or override variables.




More information about the inn-committers mailing list