Simply
if a line starts with @ the rest is assumed to be a netgroup
if a line starts with + the rest is assumed to be a "dsh" group
if a line starts with < the rest is assumed to be a filename
for the last one, filenames that start with "/" are taken as is
otherwise they're assumed to be relative to the file where they're
listed.

Craig

diff -u dsh-0.25.10.orig/parameter.c dsh-0.25.10
--- dsh-0.25.10.orig/parameter.c        2007-08-15 00:23:42.000000000 +0100
+++ dsh-0.25.10/parameter.c     2011-03-09 14:34:54.000000000 +0000
@@ -46,6 +46,12 @@
 #include "gettext.h"
 #define _(A) gettext(A)

+/*
+ * Forward declare as used by add_machine_group and uses add_machine_group
+ *
+ */
+linkedlist* read_machinelist(linkedlist *, const char *, const char*);
+
 /**
  * allocate memory, and abort with error
  *
@@ -154,6 +160,37 @@

 }

+static
+linkedlist* add_machine_group (linkedlist* machinelist, int
is_netgroup, const char* group_name)
+{
+  if (is_netgroup)
+    {                  /* using libc call for using netgroup. */
+      /* +1 to skip @ */
+      if (verbose_flag) printf (_("Adding netgroup %s to the
list\n"), group_name);
+      machinelist = read_machinenetgroup(machinelist, group_name);
+    }
+  else
+    {
+      char * buf1, *buf2;
+      if (verbose_flag) printf (_("Adding group %s to the list\n"),
group_name);
+      if (asprintf(&buf1, DSHCONFDIR"/group/%s", group_name) < 0)
+        {
+          fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE);
+          return NULL;
+        }
+
+      if (asprintf(&buf2, "%s/.dsh/group/%s", getenv("HOME"), group_name)<0)
+        {
+          fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE);
+          return NULL;
+        }
+
+      machinelist = read_machinelist (machinelist, buf2, buf1);
+      free(buf1);free(buf2);
+    }
+  return machinelist;
+}
+
 /**
  * read the machine list file from file.
  */
@@ -163,14 +200,59 @@
   FILE * f;
   size_t bufferlen = 1024;
   char * buf = malloc_with_error(bufferlen);
+  const char* reading = listfile;

-  if ((f = fopen (listfile, "r")) || ((NULL != alternatelistfile) &&
(f=fopen(alternatelistfile, "r"))))
+  if ((f = fopen (listfile, "r")) || ((NULL != alternatelistfile) &&
(f=fopen(reading=alternatelistfile, "r"))))
     {
       while (-1 != getline (&buf, &bufferlen, f))
        {
          const char * strippedstring = stripwhitespace(buf);
          if (strippedstring)
-           machinelist=machinelist_lladd(machinelist,strippedstring);
+            {
+              switch (strippedstring[0])
+                {
+                  case '@':
+                    if (!(machinelist =
add_machine_group(machinelist, 1, &strippedstring[1])))
+                      exit (1);
+                    break;
+
+                  case '+':
+                    if (!(machinelist =
add_machine_group(machinelist, 0, &strippedstring[1])))
+                      exit (1);
+                    break;
+
+                  case '<':
+                    if ('/' == strippedstring[1])
+                      {
+                        /* absolute path */
+                        machinelist = read_machinelist (machinelist,
&strippedstring[1], NULL);
+                      }
+                      else
+                      {
+                        /* relative path */
+                        /* includING file has a slash, get that dir,
use with includED file */
+                        const char* slash = strrchr(reading, '/');
+                        if (slash)
+                          {
+                            size_t dirlen = slash - reading + 1; /*
includes the / */
+                            char* path = malloc_with_error(dirlen +
strlen(&strippedstring[1]) + 1 /* NUL */);
+                            strncpy(path, reading, dirlen);
+                            strcpy(path + dirlen, &strippedstring[1]);
+                            machinelist = read_machinelist
(machinelist, path, NULL);
+                            free(path);
+                          }
+                        else
+                          {
+                            machinelist = read_machinelist
(machinelist, &strippedstring[1], NULL);
+                          }
+                      }
+                    break;
+
+                  default:
+                    machinelist=machinelist_lladd(machinelist,strippedstring);
+                    break;
+                }
+            }
        }
       fclose(f);
     }
@@ -452,28 +534,11 @@
          {
             if ('@' == *optarg)
               {                        /* using libc call for using
netgroup. */
-                /* +1 to skip @ */
-               if (verbose_flag) printf (_("Adding netgroup %s to the
list\n"), optarg + 1);
-                machinelist = read_machinenetgroup(machinelist, optarg+1);
+                machinelist = add_machine_group(machinelist, 1, optarg + 1);
               }
             else
               {                        /* using dsh's own method. */
-               char * buf1, *buf2;
-               if (verbose_flag) printf (_("Adding group %s to the
list\n"), optarg);
-               if (asprintf(&buf1, DSHCONFDIR"/group/%s", optarg) < 0)
-                 {
-                   fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE);
-                   return 1;
-                 }
-
-               if (asprintf(&buf2, "%s/.dsh/group/%s",
getenv("HOME"), optarg)<0)
-                 {
-                   fprintf (stderr, _("%s: asprintf failed\n"), PACKAGE);
-                   return 1;
-                 }
-
-               machinelist = read_machinelist (machinelist, buf2, buf1);
-               free(buf1);free(buf2);
+                machinelist = add_machine_group(machinelist, 0, optarg);
              }
          }
          break;



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to