[eliz@is.elta.co.il: DOSish filenames and CRLF source files]

DJ Delorie dj@delorie.com
Sun Jun 27 10:48:00 GMT 1999


------- Start of forwarded message -------
Date: Sun, 27 Jun 1999 18:51:28 +0300 (IDT)
From: Eli Zaretskii <eliz@is.elta.co.il>
X-Sender: eliz@is
To: gdb-patches@sourceware.cygnus.com
cc: DJ Delorie <dj@delorie.com>
Subject: DOSish filenames and CRLF source files
Content-Type: TEXT/PLAIN; charset=US-ASCII

The following patches solve some problems with DOS/Windows file names and 
with source files which have CRLF EOLs:

1999-06-26  Eli Zaretskii  <eliz@is.elta.co.il>

	* source.c (mod_path) [_WIN32 || __DJGPP__]: Don't remove trailing
	slash from "d:/".  Don't overstep the beginning of name.
	[_WIN32 || __MSDOS__]: Convert "d:" to "d:.", otherwise appending
	a slash changes its meaning.
	(openp): Use SLASH_P, not equality with SLASH_CHAR.
	(print_source_lines_base) [CRLF_SOURCE_FILES]: Skip \r only before
	a \n.
	(forward_search_command) [CRLF_SOURCE_FILES]: Remove \r at the end
	of all lines.
	(reverse_search_command) [CRLF_SOURCE_FILES]: Likewise.

*** cvs/gdb/source.c	Mon Jun 21 16:26:06 1999
- --- ./gdb/source.c	Sat Jun 26 15:12:08 1999
***************
*** 338,352 ****
  	  }
        }
  
! #ifndef _WIN32 
!       /* On win32 h:\ is different to h: */
!       if (SLASH_P (p[-1]))
  	/* Sigh. "foo/" => "foo" */
  	--p;
- - #endif
        *p = '\0';
  
!       while (p[-1] == '.')
  	{
  	  if (p - name == 1)
  	    {
- --- 338,354 ----
  	  }
        }
  
!       if (!(SLASH_P (*name) && p <= name + 1) /* "/" */
! #if defined(_WIN32) || defined(__MSDOS__)
! 	   /* On MS-DOS and MS-Windows, h:\ is different from h: */
! 	   && !(!SLASH_P (*name) && ROOTED_P (name) && p <= name + 3)/* d:/ */
! #endif
! 	  && SLASH_P (p[-1]))
  	/* Sigh. "foo/" => "foo" */
  	--p;
        *p = '\0';
  
!       while (p > name && p[-1] == '.')
  	{
  	  if (p - name == 1)
  	    {
***************
*** 354,360 ****
  	      name = current_directory;
  	      goto append;
  	    }
! 	  else if (SLASH_P (p[-2]))
  	    {
  	      if (p - name == 2)
  		{
- --- 356,362 ----
  	      name = current_directory;
  	      goto append;
  	    }
! 	  else if (p > name + 1 && SLASH_P (p[-2]))
  	    {
  	      if (p - name == 2)
  		{
***************
*** 376,381 ****
- --- 378,387 ----
  
        if (name[0] == '~')
  	name = tilde_expand (name);
+ #if defined(_WIN32) || defined(__MSDOS__)
+       else if (ROOTED_P (name) && p == name + 2) /* "d:" => "d:." */
+ 	name = concat (name, ".", NULL);
+ #endif
        else if (!ROOTED_P (name) && name[0] != '$') 
  	  name = concat (current_directory, SLASH_STRING, name, NULL);
        else
***************
*** 410,415 ****
- --- 416,429 ----
  	p = *which_path;
  	while (1)
  	  {
+ 	    /* FIXME: strncmp loses in interesting ways on MS-DOS and
+ 	       MS-Windows because of case-insensitivity and two different
+ 	       but functionally identical slash characters.  We need a
+ 	       special filesystem-dependent file-name comparison function.
+ 
+ 	       Actually, even on Unix I would use realpath() or its work-
+ 	       alike before comparing.  Then all the code above which
+ 	       removes excess slashes and dots could simply go away.  */
  	    if (!strncmp (p, name, len)
  		&& (p[len] == '\0' || p[len] == DIRNAME_SEPARATOR))
  	      {
***************
*** 598,605 ****
  	  /* Beware the // my son, the Emacs barfs, the botch that catch... */
  	  
  	  *filename_opened = concat (current_directory, 
! 				     SLASH_CHAR
! 				     == current_directory[strlen(current_directory)-1] 
    				     ? "": SLASH_STRING,
  				     filename, NULL);
          }
- --- 612,618 ----
  	  /* Beware the // my son, the Emacs barfs, the botch that catch... */
  	  
  	  *filename_opened = concat (current_directory, 
! 				     SLASH_P (current_directory[strlen(current_directory)-1])
    				     ? "": SLASH_STRING,
  				     filename, NULL);
          }
***************
*** 1058,1064 ****
  #ifdef CRLF_SOURCE_FILES
  	  else if (c == '\r')
  	    {
! 	      /* Just skip \r characters.  */
  	    }
  #endif
  	  else
- --- 1071,1083 ----
  #ifdef CRLF_SOURCE_FILES
  	  else if (c == '\r')
  	    {
! 	      /* Skip a \r character, but only before a \n.  */
! 	      int c1 = fgetc (stream);
! 
! 	      if (c1 != '\n')
! 		printf_filtered ("^%c", c + 0100);
! 	      if (c1 != EOF)
! 		ungetc (c1, stream);
  	    }
  #endif
  	  else
***************
*** 1496,1501 ****
- --- 1515,1530 ----
  	}
      } while (c != '\n' && (c = getc (stream)) >= 0);
  
+ #ifdef CRLF_SOURCE_FILES
+     /* Remove the \r, if any, at the end of the line, otherwise
+        regular expressions that end with $ or \n won't work.  */
+     if (p - buf > 1 && p[-2] == '\r')
+       {
+ 	p--;
+ 	p[-1] = '\n';
+       }
+ #endif
+ 
      /* we now have a source line in buf, null terminate and match */
      *p = 0;
      if (re_exec (buf) > 0)
***************
*** 1594,1599 ****
- --- 1623,1638 ----
  	*p++ = c;
        } while (c != '\n' && (c = getc (stream)) >= 0);
  
+ #ifdef CRLF_SOURCE_FILES
+       /* Remove the \r, if any, at the end of the line, otherwise
+ 	 regular expressions that end with $ or \n won't work.  */
+       if (p - buf > 1 && p[-2] == '\r')
+ 	{
+ 	  p--;
+ 	  p[-1] = '\n';
+ 	}
+ #endif
+ 
        /* We now have a source line in buf; null terminate and match.  */
        *p = 0;
        if (re_exec (buf) > 0)
------- End of forwarded message -------


More information about the Gdb-patches mailing list