jed-users mailing list

[2003 Date Index] [2003 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: dircat vs. path_concat


begin  "John E. Davis" <davis@xxxxxxxxxxxxx> wrote:
> Joerg Sommer <joerg@xxxxxxxxxxxx> wrote:
>>And why not fix path_concat for slang only scripts?
>
> It needs tested on VMS.  Since I nolonger have access to such a system for
> development and testing, I feel that it would be irresponsible of me to

Maybe this can help you: http://www.testdrive.compaq.com/

> release a version of jed that makes use of an untested version of
> path_concat when dircat is known to work.  As soon as someone provides
> verification that path_concat on VMS is equivalent to dircat, then I
> will replace dircat by path_concat.

Do you have a slang script for testing? And why not port dircat to C?

This should be a one to one translation with a little bit cleanup of the
old C function.

#v+
diff -ur slang-1.4.9/src/slpath.c /home/joerg/programmieren/slang-1.4.9/src/slpath.c
--- slang-1.4.9/src/slpath.c	2003-03-23 08:06:40.000000000 +0100
+++ /home/joerg/programmieren/slang-1.4.9/src/slpath.c	2003-10-04 01:14:34.000000000 +0200
@@ -209,47 +209,58 @@
 /* This returns a MALLOCED string */
 char *SLpath_dircat (char *dir, char *name)
 {
-   unsigned int len, dirlen;
    char *file;
-#ifndef VMS
-   int requires_fixup;
-#endif
 
    if (name == NULL)
      name = "";
 
-   if ((dir == NULL) || (SLpath_is_absolute_path (name)))
-     dir = "";
-
-   /* Both VMS and MSDOS have default directories associated with each drive.
-    * That is, the meaning of something like C:X depends upon more than just
-    * the syntax of the string.  Since this concept has more power under VMS
-    * it will be honored here.  However, I am going to treat C:X as C:\X
-    * under MSDOS.
-    *
-    * Note!!!
-    * VMS has problems of its own regarding path names, so I am simply
-    * going to strcat.  Hopefully the VMS RTL is smart enough to deal with
-    * the result.
-    */
-   dirlen = strlen (dir);
-#ifndef VMS
-   requires_fixup = (dirlen && (0 == IS_PATH_SEP(dir[dirlen - 1])));
-#endif
-
-   len = dirlen + strlen (name) + 2;
-   if (NULL == (file = SLmalloc (len)))
-     return NULL;
-
-   strcpy (file, dir);
-
-#ifndef VMS
-   if (requires_fixup)
-     file[dirlen++] = PATH_SEP;
+   if ((dir != NULL) && (*dir != '\0') && !(SLpath_is_absolute_path (name))) {
+      /* Both VMS and MSDOS have default directories associated with each
+       * drive. That is, the meaning of something like C:X depends upon
+       * more than just the syntax of the string.  Since this concept
+       * has more power under VMS it will be honored here.  However, I
+       * am going to treat C:X as C:\X under MSDOS. * Note!!! VMS has
+       * problems of its own regarding path names, so I am simply going
+       * to strcat.  Hopefully the VMS RTL is smart enough to deal with
+       * the result. */
+      size_t dirlen = strlen (dir);
+#ifdef VMS
+      char *pos;
+#endif
+      
+      if (NULL == (file = SLmalloc ( dirlen + strlen (name) + 2 )))
+	//! why this isn't an error or is this handled anywhere else?
+	return NULL;
+
+      strcpy (file, dir);
+
+#ifdef VMS
+      // assume dir = d:[dir]a.dir;1
+      // convert a.dir;1 to [.a] first
+      if ( (pos=strchr(file, ';')) )
+	*pos = '\0';                           // file = d:[dir]a.dir
+      
+      if ( (pos=strchr(file, PATH_SEP)) && *(pos+1) != '\0') {
+	 *pos = '.';
+	 if ( (pos=strchr(pos+1, '.')) )
+	   *pos = '\0';
+	                                       // file = d:[dir.a
+      }
+      
+      if ( (dirlen=strlen (file)) && dir[dirlen-1] != DRIVE_SPECIFIER ) {
+	 file[dirlen-1] = PATH_SEP;
+	 ++dirlen;
+      }
+#else
+      if ( dirlen && ! IS_PATH_SEP(dir[dirlen - 1]) )
+	file[dirlen++] = PATH_SEP;
 #endif
 
-   strcpy (file + dirlen, name);
-
+      //! why not strcat()?
+      strcpy (file + dirlen, name);
+   } else
+     file = name;
+   
 #if defined(IBMPC_SYSTEM)
    convert_slashes (file);
 #endif
#v-

But I would write it a little bit different:

#v+
+#ifdef VMS
+      // assume dir = d:[dir]a.dir;1
+      // convert a.dir;1 to [.a] first
+      if ( (pos=strchr(file, ';')) )
+       *pos = '\0';                           // file = d:[dir]a.dir
+      
+      dirlen = strlen(file);
+      
+      if (dirlen && dir[dirlen-1] != DRIVE_SPECIFIER) {
+        if ( (pos=strchr(file, PATH_SEP)) && *(pos+1) != '\0') {
+           *pos = '.';
+           if ( (pos=strchr(pos+1, '.')) )
+             *pos = '\0';
+                                              // file = d:[dir.a
+           dirlen = strlen(file);
+        }
+      
+        file[dirlen-1] = PATH_SEP;
+        ++dirlen;
+      }
+#else
#v-

I don't know the syntax of VMS paths and I don't know what is valid, but
dircat("d:foo.bar", "") brings "d:foo.bar]"

HTH, Jörg.
end.
-- 
Es gibt nichts schöneres, als dem Schweigen eines Dummkopfes zuzuhören.
   	       		      	  	        (Helmut Quatlinger)

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2003 date index] [2003 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]