patch to force POSIX pathname conversion (mostly on win32)

Chris Faylor cgf@cygnus.com
Fri Apr 23 18:44:00 GMT 1999


A couple of questions:

1) Do you really want to use conv_to_posix_path_list rather than conv_to_posix_path,
   i.e., are all of the strings being created UNIX PATH format like /bin:/usr/bin:?
   It doesn't seem to be that way.  If you use the path_list variant you won't be
   able to handle file names with semicolons in them.  Dunno if that is even valid
   under Windows but why go through the extra overhead?

2) I normally don't like to use static buffers but the
   conv_to_posix_path_list_buf_size call is sort of expensive.  Doesn't gcc have a
   maximum path length?  If so, could you just set aside a buffer to hold this and
   malloc enough space after the conversion?  Actually you could just make this a
   dynamic array...

-chris
   
On Fri, Apr 23, 1999 at 07:57:04PM -0500, Mumit Khan wrote:
>This is the first pass at adding macro to modify filenames that are passed 
>to the GCC driver into POSIX form. Much needed by various POSIX emulations
>running on top of window32.
>
>This defines a new macro, MAKE_POSIX, that is essentially a no-op for
>hosts that don't override it. I've provided a sample one for Cygwin in
>this patch. 
>
>This is incomplete -- yet to handle cpplib -- but I'd like to know first
>if this is an acceptable approach before going forward. Please comment.
>
>Diff against 1999-04-22 CVS. Bootstrap tested (native bootstraps on 
>i686-pc-linux-gnu and i586-pc-cygwin32, as well as cross and canadian 
>cross for Cygwin). Some testing to check that it doesn't screw up on
>hosts that don't provide MAKE_POSIX and on cygwin which does.
>
>Fri Apr 23 18:43:40 1999  Mumit Khan  <khan@xraylith.wisc.edu>
>
>	* gcc.c (MAKE_POSIX): Define.
>	(process_command): Use.
>
>	* cccp.c (MAKE_POSIX): Define.
>	(main): Use.
>	(read_name_map): Use.
>	(new_include_prefix): Use.
>
>	* i386/xm-cygwin.h (MAKE_POSIX): Define.
>	(GET_ENV_PATH_LIST): Use.
>
>Index: gcc.c
>===================================================================
>RCS file: /homes/khan/src/CVSROOT/egcs-1.2-dev2/gcc/gcc.c,v
>retrieving revision 1.2
>diff -u -3 -p -r1.2 gcc.c
>--- gcc.c	1999/04/22 21:40:05	1.2
>+++ gcc.c	1999/04/23 21:36:46
>@@ -89,6 +89,11 @@ static char dir_separator_str[] = {DIR_S
> #define GET_ENV_PATH_LIST(VAR,NAME)	do { (VAR) = getenv (NAME); } while (0)
> #endif
> 
>+/* Macro to possibly convert file/pathnames into POSIX form. */
>+#ifndef MAKE_POSIX
>+#define MAKE_POSIX(POSIX_PATH,PATH) do { (POSIX_PATH) = (PATH); } while (0)
>+#endif
>+
> #ifndef HAVE_KILL
> #define kill(p,s) raise(s)
> #endif
>@@ -3156,6 +3161,7 @@ process_command (argc, argv)
> 		  value = argv[++i];
> 		else
> 		  value = p + 1;
>+		MAKE_POSIX (value, value);
> 		add_prefix (&exec_prefixes, value, NULL_PTR, 1, 0, &warn_B);
> 		add_prefix (&startfile_prefixes, value, NULL_PTR,
> 			    1, 0, &warn_B);
>@@ -3285,9 +3291,9 @@ process_command (argc, argv)
> #endif
> #if defined(HAVE_EXECUTABLE_SUFFIX) || defined(HAVE_OBJECT_SUFFIX)
> 	      if (p[1] == 0)
>-		argv[i+1] = convert_filename (argv[i+1], ! have_c);
>+		MAKE_POSIX (argv[i+1], convert_filename (argv[i+1], ! have_c));
> 	      else
>-		argv[i] = convert_filename (argv[i], ! have_c);
>+		MAKE_POSIX (argv[i], convert_filename (argv[i], ! have_c));
> #endif
> 	      goto normal_switch;
> 
>@@ -3446,23 +3452,23 @@ process_command (argc, argv)
> 	    if (argv[i][j] == ',')
> 	      {
> 		infiles[n_infiles].language = "*";
>-		infiles[n_infiles++].name
>-		  = save_string (argv[i] + prev, j - prev);
>+		MAKE_POSIX (infiles[n_infiles++].name,
>+		            save_string (argv[i] + prev, j - prev));
> 		prev = j + 1;
> 	      }
> 	  /* Record the part after the last comma.  */
> 	  infiles[n_infiles].language = "*";
>-	  infiles[n_infiles++].name = argv[i] + prev;
>+	  MAKE_POSIX (infiles[n_infiles++].name, (argv[i] + prev));
> 	}
>       else if (strcmp (argv[i], "-Xlinker") == 0)
> 	{
> 	  infiles[n_infiles].language = "*";
>-	  infiles[n_infiles++].name = argv[++i];
>+	  MAKE_POSIX (infiles[n_infiles++].name, argv[++i]);
> 	}
>       else if (strncmp (argv[i], "-l", 2) == 0)
> 	{
> 	  infiles[n_infiles].language = "*";
>-	  infiles[n_infiles++].name = argv[i];
>+	  MAKE_POSIX (infiles[n_infiles++].name, argv[i]);
> 	}
>       else if (strcmp (argv[i], "-specs") == 0)
> 	i++;
>@@ -3548,7 +3554,7 @@ process_command (argc, argv)
>       else
> 	{
> #ifdef HAVE_OBJECT_SUFFIX
>-	  argv[i] = convert_filename (argv[i], 0);
>+	  MAKE_POSIX (argv[i], convert_filename (argv[i], 0));
> #endif
> 
> 	  if (strcmp (argv[i], "-") != 0 && access (argv[i], R_OK) < 0)
>@@ -3559,7 +3565,7 @@ process_command (argc, argv)
> 	  else
> 	    {
> 	      infiles[n_infiles].language = spec_lang;
>-	      infiles[n_infiles++].name = argv[i];
>+	      MAKE_POSIX (infiles[n_infiles++].name, argv[i]);
> 	    }
> 	}
>     }
>Index: cccp.c
>===================================================================
>RCS file: /homes/khan/src/CVSROOT/egcs-1.2-dev2/gcc/cccp.c,v
>retrieving revision 1.1.1.1
>diff -u -3 -p -r1.1.1.1 cccp.c
>--- cccp.c	1999/04/22 21:34:41	1.1.1.1
>+++ cccp.c	1999/04/23 21:27:20
>@@ -42,6 +42,11 @@ typedef unsigned char U_CHAR;
> #define GET_ENV_PATH_LIST(VAR,NAME)	do { (VAR) = getenv (NAME); } while (0)
> #endif
> 
>+/* Macro to possibly convert file/pathnames into POSIX form. */
>+#ifndef MAKE_POSIX
>+#define MAKE_POSIX(POSIX_PATH,PATH) do { (POSIX_PATH) = (PATH); } while (0)
>+#endif
>+
> #ifndef STANDARD_INCLUDE_DIR
> # define STANDARD_INCLUDE_DIR "/usr/include"
> #endif
>@@ -1326,7 +1331,10 @@ main (argc, argv)
> 	  if (i + 1 == argc)
> 	    fatal ("Filename missing after `-include' option");
> 	  else
>-	    simplify_filename (pend_includes[temp] = argv[++i]);
>+	    {
>+	      MAKE_POSIX (pend_includes[temp], argv[++i]);
>+	      simplify_filename (pend_includes[temp]);
>+	    }
> 	}
> 	if (!strcmp (argv[i], "-imacros")) {
> 	  int temp = i;
>@@ -1334,7 +1342,8 @@ main (argc, argv)
> 	  if (i + 1 == argc)
> 	    fatal ("Filename missing after `-imacros' option");
> 	  else
>-	    simplify_filename (pend_files[temp] = argv[++i]);
>+	    MAKE_POSIX (pend_files[temp], argv[++i]);
>+	    simplify_filename (pend_files[temp]);
> 	}
> 	if (!strcmp (argv[i], "-iprefix")) {
> 	  if (i + 1 == argc)
>@@ -4381,7 +4390,8 @@ get_filename:
> 	  int n;
> 	  char *nam;
> 
>-	  if ((nam = fp->nominal_fname) != NULL) {
>+	  MAKE_POSIX (nam, fp->nominal_fname);
>+	  if (nam != NULL) {
> 	    /* Found a named file.  Figure out dir of the file,
> 	       and put it in front of the search list.  */
> 	    dsp = ((struct file_name_list *)
>@@ -4512,6 +4522,7 @@ get_filename:
>   }
> 
>   *fend = 0;
>+  MAKE_POSIX (fbeg, fbeg);
>   flen = simplify_filename (fbeg);
> 
>   if (flen == 0)
>@@ -4980,7 +4991,9 @@ read_name_map (dirname)
> 	    ;
> 	  to = read_filename_string (ch, f);
> 
>+	  MAKE_POSIX (from, from);
> 	  simplify_filename (from);
>+	  MAKE_POSIX (to, to);
> 	  tolen = simplify_filename (to);
> 
> 	  ptr = ((struct file_name_map *)
>@@ -10368,7 +10381,7 @@ new_include_prefix (prev_file_name, comp
>     return 0;
> 
>   prefix = update_path (prefix, component);
>-  name = update_path (name, component);
>+  MAKE_POSIX (name, update_path (name, component));
> 
>   {
>     struct file_name_list *dir
>Index: config/i386/xm-cygwin.h
>===================================================================
>RCS file: /homes/khan/src/CVSROOT/egcs-1.2-dev2/gcc/config/i386/xm-cygwin.h,v
>retrieving revision 1.1.1.1
>diff -u -3 -p -r1.1.1.1 xm-cygwin.h
>--- xm-cygwin.h	1999/04/22 21:34:45	1.1.1.1
>+++ xm-cygwin.h	1999/04/23 20:57:34
>@@ -31,23 +31,29 @@ Boston, MA 02111-1307, USA. */
> #define DIR_SEPARATOR '/'
> #define DIR_SEPARATOR_2 '\\'
> 
>-/* Convert win32 style path lists to POSIX style for consistency. */ 
>-#undef GET_ENV_PATH_LIST
>-#define GET_ENV_PATH_LIST(VAR,NAME)					\
>+/* Convert win32 style path/filenames into POSIX style. */
>+#undef MAKE_POSIX
>+#define MAKE_POSIX(POSIX_PATH,PATH)					\
> do {									\
>-  char *_epath;								\
>-  char *_posixepath;							\
>-  _epath = _posixepath = getenv (NAME);					\
>+  char *_posixepath = PATH;						\
>   /* if we have a posix path list, convert to posix path list */	\
>-  if (_epath != NULL && *_epath != 0					\
>-      && ! cygwin_posix_path_list_p (_epath))				\
>+  if ((PATH) != NULL && *(PATH) != 0					\
>+      && ! cygwin_posix_path_list_p (PATH))				\
>     {									\
>       char *p;								\
>       _posixepath = (char *) xmalloc					\
>-	(cygwin_win32_to_posix_path_list_buf_size (_epath));		\
>-      cygwin_win32_to_posix_path_list (_epath, _posixepath);		\
>+	(cygwin_win32_to_posix_path_list_buf_size (PATH));		\
>+      cygwin_win32_to_posix_path_list (PATH, _posixepath);		\
>     }									\
>-  (VAR) = _posixepath;							\
>+  (POSIX_PATH) = _posixepath;						\
>+} while (0)
>+
>+
>+/* Convert win32 style path lists to POSIX style for consistency. */ 
>+#undef GET_ENV_PATH_LIST
>+#define GET_ENV_PATH_LIST(VAR,NAME)					\
>+do {									\
>+  MAKE_POSIX (VAR, getenv (NAME));					\
> } while (0)
> 
> #define PATH_SEPARATOR ':'
>
>Regards,
>Mumit
>

-- 
cgf@cygnus.com
http://www.cygnus.com/


More information about the Gcc-patches mailing list