Reorder the static functions to avoid the need for forward declarations.
authorWayne Davison <wayned@samba.org>
Sun, 27 Jul 2008 00:47:02 +0000 (17:47 -0700)
committerWayne Davison <wayned@samba.org>
Sun, 27 Jul 2008 00:47:02 +0000 (17:47 -0700)
loadparm.c

index 9b7c7e5..d2d4617 100644 (file)
@@ -417,22 +417,6 @@ FN_LOCAL_BOOL(lp_transfer_logging, transfer_logging)
 FN_LOCAL_BOOL(lp_use_chroot, use_chroot)
 FN_LOCAL_BOOL(lp_write_only, write_only)
 
-/* local prototypes */
-static int    strwicmp(char *psz1, char *psz2);
-static int    map_parameter(char *parmname);
-static BOOL   set_boolean(BOOL *pb, char *parmvalue);
-static int    getservicebyname(char *name, service *pserviceDest);
-static void   copy_service(service *pserviceDest, service *pserviceSource);
-static BOOL   do_parameter(char *parmname, char *parmvalue);
-static BOOL   do_section(char *sectionname);
-
-/* Initialise a service to the defaults. */
-static void init_service(service *pservice)
-{
-       memset((char *)pservice, 0, sizeof (service));
-       copy_service(pservice, &sDefault);
-}
-
 /* Assign a copy of v to *s.  Handles NULL strings.  *v must
  * be initialized when this is called, either to NULL or a malloc'd
  * string.
@@ -453,39 +437,50 @@ static void string_set(char **s, const char *v)
                exit_cleanup(RERR_MALLOC);
 }
 
-/* Add a new service to the services array, with defaults set. */
-static int add_a_service(service *pservice, char *name)
+/* Copy a service structure to another. */
+static void copy_service(service *pserviceDest, service *pserviceSource)
 {
        int i;
-       service tservice;
-       int num_to_alloc = iNumServices+1;
-
-       tservice = *pservice;
 
-       /* it might already exist */
-       if (name) {
-               i = getservicebyname(name, NULL);
-               if (i >= 0)
-                       return i;
-       }
+       for (i = 0; parm_table[i].label; i++) {
+               if (parm_table[i].ptr && parm_table[i].class == P_LOCAL) {
+                       void *def_ptr = parm_table[i].ptr;
+                       void *src_ptr = ((char *)pserviceSource) + PTR_DIFF(def_ptr, &sDefault);
+                       void *dest_ptr = ((char *)pserviceDest) + PTR_DIFF(def_ptr, &sDefault);
 
-       i = iNumServices;
-       ServicePtrs = realloc_array(ServicePtrs, service *, num_to_alloc);
+                       switch (parm_table[i].type) {
+                       case P_BOOL:
+                       case P_BOOLREV:
+                               *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
+                               break;
 
-       if (ServicePtrs)
-               pSERVICE(iNumServices) = new(service);
+                       case P_INTEGER:
+                       case P_ENUM:
+                       case P_OCTAL:
+                               *(int *)dest_ptr = *(int *)src_ptr;
+                               break;
 
-       if (!ServicePtrs || !pSERVICE(iNumServices))
-               return -1;
+                       case P_CHAR:
+                               *(char *)dest_ptr = *(char *)src_ptr;
+                               break;
 
-       iNumServices++;
+                       case P_PATH:
+                       case P_STRING:
+                               string_set(dest_ptr, *(char **)src_ptr);
+                               break;
 
-       init_service(pSERVICE(i));
-       copy_service(pSERVICE(i), &tservice);
-       if (name)
-               string_set(&iSERVICE(i).name, name);
+                       default:
+                               break;
+                       }
+               }
+       }
+}
 
-       return i;
+/* Initialise a service to the defaults. */
+static void init_service(service *pservice)
+{
+       memset((char *)pservice, 0, sizeof (service));
+       copy_service(pservice, &sDefault);
 }
 
 /* Do a case-insensitive, whitespace-ignoring string compare. */
@@ -516,6 +511,53 @@ static int strwicmp(char *psz1, char *psz2)
        return *psz1 - *psz2;
 }
 
+/* Find a service by name. Otherwise works like get_service. */
+static int getservicebyname(char *name, service *pserviceDest)
+{
+       int i;
+
+       for (i = iNumServices - 1; i >= 0; i--) {
+               if (strwicmp(iSERVICE(i).name, name) == 0) {
+                       if (pserviceDest != NULL)
+                               copy_service(pserviceDest, pSERVICE(i));
+                       break;
+               }
+       }
+
+       return i;
+}
+
+/* Add a new service to the services array, with defaults set. */
+static int add_a_service(char *name)
+{
+       int i;
+       int num_to_alloc = iNumServices+1;
+
+       /* it might already exist */
+       if (name) {
+               i = getservicebyname(name, NULL);
+               if (i >= 0)
+                       return i;
+       }
+
+       i = iNumServices;
+       ServicePtrs = realloc_array(ServicePtrs, service *, num_to_alloc);
+
+       if (ServicePtrs)
+               pSERVICE(iNumServices) = new(service);
+
+       if (!ServicePtrs || !pSERVICE(iNumServices))
+               return -1;
+
+       iNumServices++;
+
+       init_service(pSERVICE(i));
+       if (name)
+               string_set(&iSERVICE(i).name, name);
+
+       return i;
+}
+
 /* Map a parameter's string representation to something we can use.
  * Returns False if the parameter string is not recognised, else TRUE. */
 static int map_parameter(char *parmname)
@@ -554,63 +596,8 @@ static BOOL set_boolean(BOOL *pb, char *parmvalue)
        return True;
 }
 
-/* Find a service by name. Otherwise works like get_service. */
-static int getservicebyname(char *name, service *pserviceDest)
-{
-       int i;
-
-       for (i = iNumServices - 1; i >= 0; i--) {
-               if (strwicmp(iSERVICE(i).name, name) == 0) {
-                       if (pserviceDest != NULL)
-                               copy_service(pserviceDest, pSERVICE(i));
-                       break;
-               }
-       }
-
-       return i;
-}
-
-/* Copy a service structure to another. */
-static void copy_service(service *pserviceDest, service *pserviceSource)
-{
-       int i;
-
-       for (i = 0; parm_table[i].label; i++) {
-               if (parm_table[i].ptr && parm_table[i].class == P_LOCAL) {
-                       void *def_ptr = parm_table[i].ptr;
-                       void *src_ptr = ((char *)pserviceSource) + PTR_DIFF(def_ptr, &sDefault);
-                       void *dest_ptr = ((char *)pserviceDest) + PTR_DIFF(def_ptr, &sDefault);
-
-                       switch (parm_table[i].type) {
-                       case P_BOOL:
-                       case P_BOOLREV:
-                               *(BOOL *)dest_ptr = *(BOOL *)src_ptr;
-                               break;
-
-                       case P_INTEGER:
-                       case P_ENUM:
-                       case P_OCTAL:
-                               *(int *)dest_ptr = *(int *)src_ptr;
-                               break;
-
-                       case P_CHAR:
-                               *(char *)dest_ptr = *(char *)src_ptr;
-                               break;
-
-                       case P_PATH:
-                       case P_STRING:
-                               string_set(dest_ptr, *(char **)src_ptr);
-                               break;
-
-                       default:
-                               break;
-                       }
-               }
-       }
-}
-
 /* Process a parameter. */
-static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue)
+static BOOL do_parameter(char *parmname, char *parmvalue)
 {
        int parmnum, i;
        void *parm_ptr=NULL; /* where we are going to store the result */
@@ -626,15 +613,14 @@ static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue)
 
        def_ptr = parm_table[parmnum].ptr;
 
-       /* we might point at a service, the default service or a global */
-       if (snum < 0)
+       if (bInGlobalSection)
                parm_ptr = def_ptr;
        else {
                if (parm_table[parmnum].class == P_GLOBAL) {
                        rprintf(FLOG, "Global parameter %s found in service section!\n", parmname);
                        return True;
                }
-               parm_ptr = ((char *)pSERVICE(snum)) + PTR_DIFF(def_ptr, &sDefault);
+               parm_ptr = ((char *)pSERVICE(iServiceIndex)) + PTR_DIFF(def_ptr, &sDefault);
        }
 
        /* now switch on the type of variable it is */
@@ -696,12 +682,6 @@ static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue)
        return True;
 }
 
-/* Process a parameter.  */
-static BOOL do_parameter(char *parmname, char *parmvalue)
-{
-       return lp_do_parameter(bInGlobalSection?-2:iServiceIndex, parmname, parmvalue);
-}
-
 /* Process a new section (rsync module).
  * Returns True on success, False on failure. */
 static BOOL do_section(char *sectionname)
@@ -733,8 +713,9 @@ static BOOL do_section(char *sectionname)
                return False;
        }
 
-       if ((iServiceIndex = add_a_service(&sDefault, sectionname)) < 0) {
+       if ((iServiceIndex = add_a_service(sectionname)) < 0) {
                rprintf(FLOG, "Failed to add a new module\n");
+               bInGlobalSection = True;
                return False;
        }