delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/09/15/10:20:31

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT sources DOT redhat DOT com
Delivered-To: mailing list cygwin AT sources DOT redhat DOT com
Message-ID: <C2D7D58DBFE9D111B0480060086E9635023D5361@mail.gft.de>
From: "Schaible, Joerg" <Joerg DOT Schaible AT gft DOT de>
To: Randall R Schulz <rschulz AT teknowledge DOT com>
Cc: cygwin-list <cygwin AT sources DOT redhat DOT com>
Subject: RE: set HOME environment
Date: Fri, 15 Sep 2000 16:19:17 +0200
MIME-Version: 1.0
X-Mailer: Internet Mail Service (5.5.2650.21)

------_=_NextPart_000_01C01F1F.EEBFAC40
Content-Type: text/plain;
	charset="iso-8859-1"

Hi Randall,

I already contributed the attached patch some times ago, that enhances
cygpath for the proper functionality. Meanwhile my disclaimer for the
contribution has reached Red Hat and the patch will be applied soon. With
the new option -s HOME could be set ignoring the blanks, since the filename
is converted into 8.3 format:

HOME=`cygpath -ws $USERPROFILE`
HOME=`cygpath -u $HOME`
export HOME

> 
> The presence of spaces in file name and path variables is indeed
> problematic. In particular, the PATH variable inherited by the shell
> from the Windows environment is rather likely to contain them, and
> programs that try to manipulate these variables assuming that they
> have no spaces will surely break.
> 
> Here's something I've done in lieu of fixing all the scripts I wrote
> with the tacit assumption of a space-less PATH variable:
> 
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--=
> =--==--==-
> if [ -z "$SYSPATH" ]; then
>     export            SYSPATH="$PATH"
>     export            SAFE_SYSPATH="$(echo "$PATH" |sed -e 
> 's/^[^:]* [^:]*://g' \
>                                                       -e 
> 's/:[^:]* [^:]*//g' )"
> 
>     syspath()        { echo "$SYSPATH" |tr ':' $'\n'; }
>     safesyspath()    { echo "$SAFE_SYSPATH" |tr ':' $'\n'; }
> fi
> 
> 
> resetPATH() {
>     # /usr/local/bin is first to give precedence to CygUtils
>     #    (see <http://cygutils.netpedia.net/>)
> 
>     FULL_PATH=":$HOME/bin:/usr/sbin://c/jdk1.3/bin:$SYSPATH"
>     SAFE_PATH=":$HOME/bin:/usr/sbin://c/jdk1.3/bin:$SAFE_SYSPATH"
> }
> 
> safePATH()            { PATH="$SAFE_PATH"; }
> fullPATH()            { PATH="$FULL_PATH"; }
> 
> resetSafePATH()        { resetPATH; safePATH; }
> resetFullPATH()        { resetPATH; fullPATH; }
> -==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--=
> =--==--==-
> 
> I keep this code in a file called ~/.PATH, source that file in my
> .bash_profile and immediately thereafter invoke "resetSafePATH". If I
> ever need access to the directories excised from SAFE_PATH, I can
> issue "resetFullPATH" to get them back.
> 
> I hope some might find this useful.
> 


------_=_NextPart_000_01C01F1F.EEBFAC40
Content-Type: application/octet-stream;
	name="cygpath.cc-patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="cygpath.cc-patch"

--- cygpath.orig.cc	Fri May 19 17:06:28 2000=0A=
+++ cygpath.cc	Fri Sep 15 13:26:01 2000=0A=
@@ -23,6 +23,7 @@ static char *prog_name;=0A=
 static char *file_arg;=0A=
 static char *close_arg;=0A=
 static int path_flag, unix_flag, windows_flag, absolute_flag;=0A=
+static int shortname_flag, ignore_flag;=0A=
 =0A=
 static struct option long_options[] =3D=0A=
 {=0A=
@@ -35,26 +36,105 @@ static struct option long_options[] =3D=0A=
   { (char *) "file", required_argument, (int *) &file_arg, 'f'},=0A=
   { (char *) "version", no_argument, NULL, 'v' },=0A=
   { (char *) "windows", no_argument, NULL, 'w' },=0A=
+  { (char *) "short-name", no_argument, NULL, 's' },=0A=
   { (char *) "windir", no_argument, NULL, 'W' },=0A=
   { (char *) "sysdir", no_argument, NULL, 'S' },=0A=
+  { (char *) "ignore", no_argument, NULL, 'i' },=0A=
   { 0, no_argument, 0, 0 }=0A=
 };=0A=
 =0A=
 static void=0A=
 usage (FILE *stream, int status)=0A=
 {=0A=
-  fprintf (stream, "\=0A=
-Usage: %s [-p|--path] (-u|--unix)|(-w|--windows) filename\n\=0A=
+  if (!ignore_flag || !status)=0A=
+    fprintf (stream, "\=0A=
+Usage: %s [-p|--path] (-u|--unix)|(-w|--windows [-s|--short-name]) =
filename\n\=0A=
   -a|--absolute		output absolute path\n\=0A=
   -c|--close handle	close handle (for use in captured process)\n\=0A=
   -f|--file file	read file for path information\n\=0A=
   -u|--unix     	print Unix form of filename\n\=0A=
   -w|--windows  	print Windows form of filename\n\=0A=
+  -s|--short-name	print Windows short form of filename\n\=0A=
   -W|--windir 	 	print `Windows' directory\n\=0A=
   -S|--sysdir 	 	print `system' directory\n\=0A=
-  -p|--path     	filename argument is a path\n",=0A=
+  -p|--path     	filename argument is a path\n\=0A=
+  -i|--ignore     	ignore missing argument\n",=0A=
 	   prog_name);=0A=
-  exit (status);=0A=
+  exit (ignore_flag ? 0 : status);=0A=
+}=0A=
+=0A=
+static char *=0A=
+get_short_paths (char *path)=0A=
+{=0A=
+  char *sbuf;=0A=
+  char *sptr;=0A=
+  char *next;=0A=
+  char *ptr =3D path;=0A=
+  char *end =3D strrchr (path, 0);=0A=
+  DWORD acc =3D 0;=0A=
+  DWORD len;=0A=
+=0A=
+  while (ptr !=3D NULL)=0A=
+  {=0A=
+    next =3D ptr;=0A=
+    ptr =3D strchr (ptr, ';');=0A=
+    if (ptr)=0A=
+      *ptr++ =3D 0;=0A=
+    len =3D GetShortPathName (next, NULL, 0);=0A=
+    if (len =3D=3D ERROR_INVALID_PARAMETER)=0A=
+    {=0A=
+      fprintf (stderr, "%s: cannot create short name of %s\n", =
prog_name, next);=0A=
+      exit (2);=0A=
+    }=0A=
+    acc +=3D len+1;=0A=
+  }=0A=
+  sptr =3D sbuf =3D (char *) malloc(acc+1);=0A=
+  if (sbuf =3D=3D NULL)=0A=
+  {=0A=
+    fprintf (stderr, "%s: out of memory\n", prog_name);=0A=
+    exit (1);=0A=
+  }=0A=
+  ptr =3D path;=0A=
+  for(;;)=0A=
+  {=0A=
+    if (GetShortPathName (ptr, sptr, acc) =3D=3D =
ERROR_INVALID_PARAMETER)=0A=
+    {=0A=
+      fprintf (stderr, "%s: cannot create short name of %s\n", =
prog_name, ptr);=0A=
+      exit (2);=0A=
+    }=0A=
+=0A=
+    ptr =3D strrchr (ptr, 0);=0A=
+    sptr =3D strrchr (sptr, 0);=0A=
+    if (ptr =3D=3D end)=0A=
+      break;=0A=
+    *sptr =3D ';';=0A=
+    ++ptr, ++sptr;=0A=
+  }=0A=
+  return sbuf;=0A=
+}=0A=
+=0A=
+static char *=0A=
+get_short_name (const char *filename)=0A=
+{=0A=
+  char *sbuf;=0A=
+  DWORD len =3D GetShortPathName (filename, NULL, 0);=0A=
+  if (len =3D=3D ERROR_INVALID_PARAMETER)=0A=
+  {=0A=
+    fprintf (stderr, "%s: cannot create short name of %s\n", =
prog_name, filename);=0A=
+    exit (2);=0A=
+  }=0A=
+  sbuf =3D (char *) malloc(++len);=0A=
+  if (sbuf =3D=3D NULL)=0A=
+  {=0A=
+    fprintf (stderr, "%s: out of memory\n", prog_name);=0A=
+    exit (1);=0A=
+  }=0A=
+  if (GetShortPathName (filename, sbuf, len) =3D=3D =
ERROR_INVALID_PARAMETER)=0A=
+  {=0A=
+    fprintf (stderr, "%s: cannot create short name of %s\n", =
prog_name, filename);=0A=
+    exit (2);=0A=
+  }=0A=
+  return sbuf;=0A=
 }=0A=
 =0A=
 static void=0A=
@@ -100,14 +180,22 @@ doit (char *filename)=0A=
       if (unix_flag)=0A=
 	cygwin_win32_to_posix_path_list (filename, buf);=0A=
       else=0A=
+      {=0A=
 	cygwin_posix_to_win32_path_list (filename, buf);=0A=
+	if (shortname_flag)=0A=
+	  buf =3D get_short_paths (buf);=0A=
+      }=0A=
     }=0A=
   else=0A=
     {=0A=
       if (unix_flag)=0A=
 	(absolute_flag ? cygwin_conv_to_full_posix_path : =
cygwin_conv_to_posix_path) (filename, buf);=0A=
       else=0A=
-	(absolute_flag ? cygwin_conv_to_full_win32_path : =
cygwin_conv_to_win32_path) (filename, buf);=0A=
+	{=0A=
+	  (absolute_flag ? cygwin_conv_to_full_win32_path : =
cygwin_conv_to_win32_path) (filename, buf);=0A=
+	  if (shortname_flag)=0A=
+	    buf =3D get_short_name (buf);=0A=
+	}=0A=
     }=0A=
 =0A=
   puts (buf);=0A=
@@ -130,8 +218,10 @@ main (int argc, char **argv)=0A=
   path_flag =3D 0;=0A=
   unix_flag =3D 0;=0A=
   windows_flag =3D 0;=0A=
+  shortname_flag =3D 0;=0A=
+  ignore_flag =3D 0;=0A=
   options_from_file_flag =3D 0;=0A=
-  while ((c =3D getopt_long (argc, argv, (char *) "hac:f:opSuvwW", =
long_options, (int *) NULL))=0A=
+  while ((c =3D getopt_long (argc, argv, (char *) "hac:f:opsSuvwWi", =
long_options, (int *) NULL))=0A=
 	 !=3D EOF)=0A=
     {=0A=
       switch (c)=0A=
@@ -168,6 +258,12 @@ main (int argc, char **argv)=0A=
 	  windows_flag =3D 1;=0A=
 	  break;=0A=
 =0A=
+	case 's':=0A=
+	  if (unix_flag)=0A=
+	    usage (stderr, 1);=0A=
+	  shortname_flag =3D 1;=0A=
+	  break;=0A=
+=0A=
 	case 'W':=0A=
 	  GetWindowsDirectory(buf, MAX_PATH);=0A=
 	  cygwin_conv_to_posix_path(buf, buf2);=0A=
@@ -180,6 +276,10 @@ main (int argc, char **argv)=0A=
 	  printf("%s\n", buf2);=0A=
 	  exit(0);=0A=
 =0A=
+	case 'i':=0A=
+	  ignore_flag =3D 1;=0A=
+	  break;=0A=
+=0A=
 	case 'h':=0A=
 	  usage (stdout, 0);=0A=
 	  break;=0A=
@@ -245,6 +345,12 @@ main (int argc, char **argv)=0A=
 		  {=0A=
 		  case 'a':=0A=
 		    absolute_flag =3D 1;=0A=
+		    break;=0A=
+		  case 'i':=0A=
+		    ignore_flag =3D 1;=0A=
+		    break;=0A=
+		  case 's':=0A=
+		    shortname_flag =3D 1;=0A=
 		    break;=0A=
 		  case 'w':=0A=
 		    unix_flag =3D 0;=0A=


------_=_NextPart_000_01C01F1F.EEBFAC40
Content-Type: text/plain; charset=us-ascii

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com
------_=_NextPart_000_01C01F1F.EEBFAC40--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019