Patch: DIR_SEPARATOR usage in jcf-write.c and jcf-io.c

Ranjit Mathew rmathew@hotmail.com
Sun Feb 23 18:50:00 GMT 2003


Hi,

    This is a resubmission of the DIR_SEPARATOR patch for jcf-io.c 
and jcf-write.c in the front-end.

The last time I had submitted this, it was suggested that we 
might be able to use something from libiberty instead - AFAICT, 
the only relevant functions in libiberty seem to be the 
basename( )/lbasename( ) functions. AFAIK, if we are to use them, 
the code will still be as "untidy" as this, as they do not 
directly address the issue we are trying to resolve here.

This patch resolves the bug on Win32 where "gcj -C foo\Bar.java"
produces the class file in the current directory instead of in
"foo" while "gcj -C foo/Bar.java" has the correct behaviour.

Ranjit.


Index: ChangeLog
from  Ranjit Mathew  <rmathew@hotmail.com>

	* jcf-io.c (caching_stat): Account for both DIR_SEPARATOR
	and DIR_SEPARATOR_2 for a target.
	Correct minor typos.

	* jcf-write.c (make_class_file_name): Take both DIR_SEPARATOR
	and DIR_SEPARATOR_2 for a target into account.

Index: jcf-io.c
===================================================================
*** jcf-io.c	Mon Jan 27 21:33:40 2003
--- jcf-io.c	Mon Jan 27 21:44:30 2003
*************** DEFUN(caching_stat, (filename, buf),
*** 344,347 ****
--- 344,348 ----
  #if JCF_USE_SCANDIR
    char *sep;
+   char origsep;
    char *base;
    memoized_dirlist_entry *dent;
*************** DEFUN(caching_stat, (filename, buf),
*** 357,362 ****
--- 358,368 ----
    /* Get the name of the directory.  */
    sep = strrchr (filename, DIR_SEPARATOR);
+ #ifdef DIR_SEPARATOR_2
+   if (! sep)
+     sep = strrchr (filename, DIR_SEPARATOR_2);
+ #endif
    if (sep)
      {
+       origsep = *sep;
        *sep = '\0';
        base = sep + 1;
*************** DEFUN(caching_stat, (filename, buf),
*** 365,369 ****
      base = filename;
  
!   /* Obtain the entry for this directory form the hash table.  */
    slot = htab_find_slot (memoized_dirlists, filename, INSERT);
    if (!*slot)
--- 371,375 ----
      base = filename;
  
!   /* Obtain the entry for this directory from the hash table.  */
    slot = htab_find_slot (memoized_dirlists, filename, INSERT);
    if (!*slot)
*************** DEFUN(caching_stat, (filename, buf),
*** 386,392 ****
      dent = *((memoized_dirlist_entry **) slot);
  
!   /* Put the spearator back.  */
    if (sep)
!     *sep = DIR_SEPARATOR;
  
    /* If the file is not in the list, there is no need to stat it; it
--- 392,398 ----
      dent = *((memoized_dirlist_entry **) slot);
  
!   /* Put the separator back.  */
    if (sep)
!     *sep = origsep;
  
    /* If the file is not in the list, there is no need to stat it; it
Index: jcf-write.c
===================================================================
*** jcf-write.c	Mon Jan 27 21:46:11 2003
--- jcf-write.c	Sun Feb 23 23:41:33 2003
*************** make_class_file_name (clas)
*** 3338,3341 ****
--- 3338,3342 ----
    char *r;
    struct stat sb;
+   char sep;
  
    cname = IDENTIFIER_POINTER (identifier_subst (DECL_NAME (TYPE_NAME (clas)),
*************** make_class_file_name (clas)
*** 3349,3357 ****
        dname = DECL_SOURCE_FILE (TYPE_NAME (clas));
        slash = strrchr (dname, DIR_SEPARATOR);
        if (! slash)
! 	{
! 	  dname = ".";
! 	  slash = dname + 1;
! 	}
        t = strrchr (cname, DIR_SEPARATOR);
        if (t)
--- 3350,3366 ----
        dname = DECL_SOURCE_FILE (TYPE_NAME (clas));
        slash = strrchr (dname, DIR_SEPARATOR);
+ #ifdef DIR_SEPARATOR_2
        if (! slash)
!         slash = strrchr (dname, DIR_SEPARATOR_2);
! #endif
!       if (! slash)
!         {
!           dname = ".";
!           slash = dname + 1;
!           sep = DIR_SEPARATOR;
!         }
!       else
!         sep = *slash;
! 
        t = strrchr (cname, DIR_SEPARATOR);
        if (t)
*************** make_class_file_name (clas)
*** 3360,3364 ****
--- 3369,3386 ----
    else
      {
+       char *s;
+ 
        dname = jcf_write_base_directory;
+ 
+       s = strrchr (dname, DIR_SEPARATOR);
+ #ifdef DIR_SEPARATOR_2
+       if (! s)
+         s = strrchr (dname, DIR_SEPARATOR_2);
+ #endif
+       if (s)
+         sep = *s;
+       else
+         sep = DIR_SEPARATOR;
+ 
        slash = dname + strlen (dname);
      }
*************** make_class_file_name (clas)
*** 3366,3370 ****
    r = xmalloc (slash - dname + strlen (cname) + 2);
    strncpy (r, dname, slash - dname);
!   r[slash - dname] = DIR_SEPARATOR;
    strcpy (&r[slash - dname + 1], cname);
  
--- 3388,3392 ----
    r = xmalloc (slash - dname + strlen (cname) + 2);
    strncpy (r, dname, slash - dname);
!   r[slash - dname] = sep;
    strcpy (&r[slash - dname + 1], cname);
  
*************** make_class_file_name (clas)
*** 3378,3382 ****
    while (1)
      {
!       char *s = strchr (dname, DIR_SEPARATOR);
        if (s == NULL)
  	break;
--- 3400,3404 ----
    while (1)
      {
!       char *s = strchr (dname, sep);
        if (s == NULL)
  	break;
*************** make_class_file_name (clas)
*** 3387,3393 ****
  	fatal_io_error ("can't create directory %s", r);
  
!       *s = DIR_SEPARATOR;
        /* Skip consecutive separators.  */
!       for (dname = s + 1; *dname && *dname == DIR_SEPARATOR; ++dname)
  	;
      }
--- 3409,3415 ----
  	fatal_io_error ("can't create directory %s", r);
  
!       *s = sep;
        /* Skip consecutive separators.  */
!       for (dname = s + 1; *dname && *dname == sep; ++dname)
  	;
      }



More information about the Java-patches mailing list