httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sander Temme <scte...@apache.org>
Subject Re: apxs -q [end of statement]
Date Thu, 01 Feb 2007 17:55:20 GMT

On Feb 1, 2007, at 9:37 AM, William A. Rowe, Jr. wrote:

> I'm almost thinking that a --qq or -q -v sort of option could  
> provide the
> pretty-print format.  Once nice thing about the raw version is that  
> it's
> more directly usable as input to other things.

+1

Like below? Hm... my mailer does weird formatting. Attaching as file  
as well.

S.

-- 
sctemme@apache.org            http://www.temme.net/sander/
PGP FP: 51B4 8727 466A 0BC3 69F4  B7B8 B2BE BC40 1529 24AF


Index: support/apxs.in
===================================================================
--- support/apxs.in     (revision 501957)
+++ support/apxs.in     (working copy)
@@ -75,6 +75,7 @@
my $opt_q = 0;
my $opt_h = 0;
my $opt_p = 0;
+my $opt_v = 0;
#   this subroutine is derived from Perl's getopts.pl with the  
enhancement of
#   the "+" metacharacter at the format string to allow a list to be  
built by
@@ -142,7 +143,7 @@
sub usage {
      print STDERR "Usage: apxs -g [-S <var>=<val>] -n <modname>\n";
-    print STDERR "       apxs -q [-S <var>=<val>] <query> ...\n";
+    print STDERR "       apxs -q [-S <var>=<val>] [<query> ...]\n";
      print STDERR "       apxs -c [-S <var>=<val>] [-o <dsofile>] [- 
D <name>[=<value>]]\n";
      print STDERR "               [-I <incdir>] [-L <libdir>] [-l  
<libname>] [-Wc,<flags>]\n";
      print STDERR "               [-Wl,<flags>] [-p] <files> ...\n";
@@ -153,9 +154,9 @@
#   option handling
my $rc;
-($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaAp", @ARGV);
+($rc, @ARGV) = &Getopts("qn:gco:I+D+L+l+W+S+eiaApv", @ARGV);
&usage if ($rc == 0);
-&usage if ($#ARGV == -1 and not $opt_g);
+&usage if ($#ARGV == -1 and not $opt_g and not $opt_q);
&usage if (not $opt_q and not ($opt_g and $opt_n) and not $opt_i and  
not $opt_c and not $opt_e);
#   argument handling
@@ -303,8 +304,35 @@
      ##
      ##  QUERY INFORMATION
      ##
-    my $result = get_vars(@args);
-    print "$result\n";
+    my $result;
+    if ($#args >= 0) {
+        $result = get_vars(@args);
+        print "$result\n";
+    } else {
+        # -q without var name prints all variables and their values
+
+        # Additional -v pretty-prints output
+        if ($opt_v) {
+            # Variable names in alphabetic order
+            my @vars = sort {uc($a) cmp uc($b)} keys %config_vars;
+
+            # Make the left column as wide as the longest variable name
+            my $width = 0;
+            foreach (@vars) {
+                my $l = length $_;
+                $width = $l unless ($l <= $width);
+            }
+
+            foreach (@vars) {
+                printf "%-${width}s = %s\n", $_, $config_vars{$_};
+            }
+        } else {
+            # Unprettified name=value list
+            foreach (keys %config_vars) {
+                print "$_=$config_vars{$_}\n";
+            }
+        }
+    }
}
my $apr_config = get_vars("APR_CONFIG");


Mime
View raw message