]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean up and simplify
authorAlan T. DeKok <aland@freeradius.org>
Thu, 30 Aug 2018 15:53:56 +0000 (11:53 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 30 Aug 2018 15:53:56 +0000 (11:53 -0400)
so that it looks for commented out config sections, and prints
them as commented out raw text.

scripts/conf2adoc

index 3bf5ecf66868db3a0591d4a3202cb365d3000a6e..9497ea3ee507a57148e9babffa5f22cc910153ed 100755 (executable)
@@ -6,9 +6,9 @@
 #
 #
 
+$was_raw = 0;
 $raw = 0;
-
-$firstcol = 1;
+$blank = 0;
 
 while (<>) {
     #
@@ -27,68 +27,55 @@ while (<>) {
        next;
     }
 
+    # Print one line of blank text, but suppress multiple blank lines.
     if (/^\s*$/) {
+       print "\n" if (!$blank);
+       $blank = 1;
        next;
     }
 
-    $oldcol = $firstcol;
-    if (/^#/) {
-       $firstcol = 1;
-    } else {
-       $firstcol = 0;
-    }
+    $blank = 0;
 
-    if (($firstcol == 1) && ($oldcol == 0) && ($raw == 0)) {
-       s/^#//;
-    }
+    undef $prefix;
+
+    #
+    #  Commented-out config blocks get converted to commented out raw text.
+    #
+    if (/^#[\t]/ || /^#[^\s]/) {
+       $raw = 1;
+#      print "R";
 
     #
     #  Comments in the configuration files get converted to plain
     #  text.
     #
-    if (/^\s*#/) {
+    } elsif (/^\s*#/) {
        s/^\s*#[\t ]{0,2}//;
 
-       #
-       #  If we WERE printing blocks of raw output, end that, and
-       #  reset the "raw" flag.
-       #
-       if ($raw == 1) {
-           print "```\n";
-           $raw = 0;
-       }
+#      print "T";
 
        #
        #  Ensure that lists get formatted correctly
        #
        if (/^\s*\*/) {
-           print "  ";
+           $prefix = "  ";
        }
 
-       #
-       #  @todo - load up www.freeradius.org/rfc/refs
-       #
-       #  Split the input line on spaces, into a hash array (for
-       #  uniqueness) and check each word against "refs".  If found,
-       #  the word is an attribute.  Replace the word in $_ with a
-       #  reference to the attribute definition.
-       #
+       $raw = 0;
 
-       print;
-       next;
+    } else {
+       $raw = 1;
+
+#      print "C";
     }
 
-    #
-    #  No comment at the start of the line.  It must be configuration.
-    #  Convert that to raw text.
-    #
-    #  If we were printing normal text, print out the "raw" header.
-    #
-    if ($raw == 0) {
+    if ($raw != $was_raw) {
        print "```\n";
-       $raw = 1;
+       $was_raw = $raw;
     }
 
+    print $prefix if defined $prefix;
+
     #
     #  And print out the raw text.
     #