r24525: Add output of synonym information to show_parameter_list().
authorMichael Adam <obnox@samba.org>
Fri, 17 Aug 2007 14:10:49 +0000 (14:10 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:29:53 +0000 (12:29 -0500)
Also simplify lp_canonicalize_parameter by making use of
the new function "is_synonym_of".

Michael

Note: If anything depends on the exact former output format of
show_parameter list, I would trigger the output of synonym information
by a boolean verbose switch (that could be passed to testparm
via the "-v" command line switch).

source/param/loadparm.c

index be06ba90fe36002c371e6bd98e54a369cf22d7ae..c867c5f508297a314f1d368467e1f6a75658ef18 100644 (file)
@@ -2203,6 +2203,7 @@ static BOOL hash_a_service(const char *name, int number);
 static void free_service_byindex(int iService);
 static char * canonicalize_servicename(const char *name);
 static void show_parameter(int parmIndex);
+static BOOL is_synonym_of(int parm1, int parm2, BOOL *inverse);
 
 /* This is a helper function for parametrical options support. */
 /* It returns a pointer to parametrical option value if it exists or NULL otherwise */
@@ -2840,15 +2841,8 @@ BOOL lp_canonicalize_parameter(const char *parm_name, const char **canon_parm,
        }
 
        for (canon_num = 0; parm_table[canon_num].label; canon_num++) {
-               if (!(parm_table[canon_num].flags & FLAG_HIDE) &&
-                   (parm_table[num].ptr == parm_table[canon_num].ptr))
-               {
+               if (is_synonym_of(num, canon_num, inverse)) {
                        *canon_parm = parm_table[canon_num].label;
-                       if ((parm_table[canon_num].type == P_BOOL) &&
-                           (parm_table[num].type == P_BOOLREV))
-                       {
-                               *inverse = True;
-                       }
                        return True;
                }
        }
@@ -2883,6 +2877,31 @@ static int map_parameter(const char *pszParmName)
        return (-1);
 }
 
+/***************************************************************************
+ return true if parameter number parm1 is a synonym of parameter
+ number parm2 (parm2 being the principal name).
+ set inverse to True if parm1 is P_BOOLREV and parm2 is P_BOOL,
+ False otherwise.
+***************************************************************************/
+
+static BOOL is_synonym_of(int parm1, int parm2, BOOL *inverse)
+{
+       if ((parm_table[parm1].ptr == parm_table[parm2].ptr) &&
+           (parm_table[parm1].flags & FLAG_HIDE) &&
+           !(parm_table[parm2].flags & FLAG_HIDE))
+       {
+               if ((parm_table[parm1].type == P_BOOLREV) &&
+                   (parm_table[parm2].type == P_BOOL))
+               {
+                       *inverse = True;
+               } else {
+                       *inverse = False;
+               }
+               return True;
+       }
+       return False;
+}
+
 /***************************************************************************
  Show one parameter's name, type, [values,] and flags.
  (helper functions for show_parameter_list)
@@ -2891,7 +2910,10 @@ static int map_parameter(const char *pszParmName)
 static void show_parameter(int parmIndex)
 {
        int enumIndex, flagIndex;
+       int parmIndex2;
        BOOL hadFlag;
+       BOOL hadSyn;
+       BOOL inverse;
        const char *type[] = { "P_BOOL", "P_BOOLREV", "P_CHAR", "P_INTEGER",
                "P_OCTAL", "P_LIST", "P_STRING", "P_USTRING", "P_GSTRING",
                "P_UGSTRING", "P_ENUM", "P_SEP"};
@@ -2925,6 +2947,28 @@ static void show_parameter(int parmIndex)
                        hadFlag = True;
                }
        }
+
+       /* output synonyms */
+       hadSyn = False;
+       for (parmIndex2=0; parm_table[parmIndex2].label; parmIndex2++) {
+               if (is_synonym_of(parmIndex, parmIndex2, &inverse)) {
+                       printf(" (%ssynonym of %s)", inverse ? "inverse " : "",
+                              parm_table[parmIndex2].label);
+               } else if (is_synonym_of(parmIndex2, parmIndex, &inverse)) {
+                       if (!hadSyn) {
+                               printf(" (synonyms: ");
+                               hadSyn = True;
+                       } else {
+                               printf(", ");
+                       }
+                       printf("%s%s", parm_table[parmIndex2].label,
+                              inverse ? "[i]" : "");
+               }
+       }
+       if (hadSyn) {
+               printf(")");
+       }
+
        printf("\n");
 }