public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: set HOME environment
@ 2000-09-13 12:38 Earnie Boyd
  2000-09-14  3:22 ` David Starks-Browning
  0 siblings, 1 reply; 8+ messages in thread
From: Earnie Boyd @ 2000-09-13 12:38 UTC (permalink / raw)
  To: Guansong Zhang; +Cc: cygwin users

--- Guansong Zhang <guansong@hotmail.com> wrote:
> I can do different things to make it work, but the right thing seems to let
> cygwin system understand that when it converts path format it should put a \
> before a space. So one can use set HOME=%USERPROFILE% in the .bat file. and
> HOME *should* be considered a Window envrionment, right?
> 

Maybe, there's more than one way to do it; however, Patches Gratefully
Considered (TM).

Cheers,

=====
--- < http://earniesystems.safeshopper.com > ---
   Earnie Boyd: < mailto:earnie_boyd@yahoo.com >
            __Cygwin: POSIX on Windows__
Cygwin Newbies: < http://gw32.freeyellow.com/ >
           __Minimalist GNU for Windows__
  Mingw32 List: < http://www.egroups.com/group/mingw32/ >
    Mingw Home: < http://www.mingw.org/ >

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: set HOME environment
@ 2000-09-15  7:19 Schaible, Joerg
  0 siblings, 0 replies; 8+ messages in thread
From: Schaible, Joerg @ 2000-09-15  7:19 UTC (permalink / raw)
  To: Randall R Schulz; +Cc: cygwin-list

[-- Attachment #1: Type: text/plain, Size: 2153 bytes --]

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.
> 


[-- Attachment #2: cygpath.cc-patch --]
[-- Type: text/x-diff, Size: 5169 bytes --]

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


^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: set HOME environment
@ 2000-09-13 12:13 Earnie Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: Earnie Boyd @ 2000-09-13 12:13 UTC (permalink / raw)
  To: Guansong Zhang; +Cc: cygwin users

*You* modify *your* /etc/profile to put quotes in the HOME variable.

HOME=\"/home/$USER\"

Cheers,
Earnie.

--- Guansong Zhang <guansong@hotmail.com> wrote:
> I put an echo $HOME before it is used in /etc/profile
> and found the result is
> 
> /cygdrive/e/Documents and Settings/zgs
> 
> it did not put any back slash before a space.
> 
> It should be a problem in algorithm to convert dir format in bash. I think
> you can reproduce the problem by set your HOME as a dir with a space in its
> name.
> 
> Regards,
> 
> Guansong
> 
> ----- Original Message -----
> From: "Earnie Boyd" <earnie_boyd@yahoo.com>
> To: "Guansong Zhang" <guansong@hotmail.com>
> Cc: "cygwin users" <cygwin@sourceware.cygnus.com>
> Sent: Wednesday, September 13, 2000 8:14 AM
> Subject: Re: set HOME environment
> 
> 
> > --- Guansong Zhang <guansong@hotmail.com> wrote:
> > > I quoted as
> > >
> > > set HOME="%USERPROFILE%"
> > >
> > > but it does not help.
> > >
> > > Besides, HOME is an environment in DOS, right? at least in previous
> cygwin
> > > version. This works before, only when I add
> > >
> > > --login -i
> > >
> > > as bash arguments. The problem comes. The new system seems specify the
> > > /home/$USER as the default home.
> > >
> >
> > See the /etc/profile file.  It modifies these variables when --login is
> used.
> >
> > Cheers,
> >
> > =====
> > --- < http://earniesystems.safeshopper.com > ---
> >    Earnie Boyd: < mailto:earnie_boyd@yahoo.com >
> >             __Cygwin: POSIX on Windows__
> > Cygwin Newbies: < http://gw32.freeyellow.com/ >
> >            __Minimalist GNU for Windows__
> >   Mingw32 List: < http://www.egroups.com/group/mingw32/ >
> >     Mingw Home: < http://www.mingw.org/ >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Yahoo! Mail - Free email you can access from anywhere!
> > http://mail.yahoo.com/
> >


__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: set HOME environment
@ 2000-09-13  8:14 Earnie Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: Earnie Boyd @ 2000-09-13  8:14 UTC (permalink / raw)
  To: Guansong Zhang; +Cc: cygwin users

--- Guansong Zhang <guansong@hotmail.com> wrote:
> I quoted as
> 
> set HOME="%USERPROFILE%"
> 
> but it does not help.
> 
> Besides, HOME is an environment in DOS, right? at least in previous cygwin
> version. This works before, only when I add
> 
> --login -i
> 
> as bash arguments. The problem comes. The new system seems specify the
> /home/$USER as the default home.
> 

See the /etc/profile file.  It modifies these variables when --login is used.

Cheers,

=====
--- < http://earniesystems.safeshopper.com > ---
   Earnie Boyd: < mailto:earnie_boyd@yahoo.com >
            __Cygwin: POSIX on Windows__
Cygwin Newbies: < http://gw32.freeyellow.com/ >
           __Minimalist GNU for Windows__
  Mingw32 List: < http://www.egroups.com/group/mingw32/ >
    Mingw Home: < http://www.mingw.org/ >

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* Re: set HOME environment
@ 2000-09-13  6:39 Earnie Boyd
  0 siblings, 0 replies; 8+ messages in thread
From: Earnie Boyd @ 2000-09-13  6:39 UTC (permalink / raw)
  To: Guansong Zhang, cygwin

--- Guansong Zhang <guansong@hotmail.com> wrote:
> Hi,
> 
> I used to used the following line to set HOME and CYGWIN in bash.bat
> 
> set HOME=%USERPROFILE%
> set CYGWIN=tty ntea
> 
> So I don't need to use mouse click to change env
> 
> I don't know when bash.bat is changed to use --login -i
> 
> but it will be a problem if my system dir is not C: it seems bash can not
> set the HOME in this case.
> 
> I modify the bat to this, (in this case e: is my system drive)
> 
> @echo off
> 
> set HOME=%USERPROFILE%
> set CYGWIN=tty ntea
> 
> rem e:
> rem chdir \cygwin\bin
> 
> chdir /d %USERPROFILE%
> 
> e:\cygwin\bin\bash --login -i
> 
> I still get
> 
> [: too many arguments
> bash: cd: /cygdrive/e/Documents: No such file or directory
> 
> As error message. but everything else seems OK. Hope no one need to do this
> change next time.
> 

This appears to be the problem of having white space in your variables.  Make
sure the values are quoted.  See the archives for further discussions.

Is this FAQed yet?

Cheers,

=====
--- < http://earniesystems.safeshopper.com > ---
   Earnie Boyd: < mailto:earnie_boyd@yahoo.com >
            __Cygwin: POSIX on Windows__
Cygwin Newbies: < http://gw32.freeyellow.com/ >
           __Minimalist GNU for Windows__
  Mingw32 List: < http://www.egroups.com/group/mingw32/ >
    Mingw Home: < http://www.mingw.org/ >

__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread
* set HOME environment
@ 2000-09-11 13:22 Guansong Zhang
  0 siblings, 0 replies; 8+ messages in thread
From: Guansong Zhang @ 2000-09-11 13:22 UTC (permalink / raw)
  To: cygwin

Hi,

I used to used the following line to set HOME and CYGWIN in bash.bat

set HOME=%USERPROFILE%
set CYGWIN=tty ntea

So I don't need to use mouse click to change env

I don't know when bash.bat is changed to use --login -i

but it will be a problem if my system dir is not C: it seems bash can not
set the HOME in this case.

I modify the bat to this, (in this case e: is my system drive)

@echo off

set HOME=%USERPROFILE%
set CYGWIN=tty ntea

rem e:
rem chdir \cygwin\bin

chdir /d %USERPROFILE%

e:\cygwin\bin\bash --login -i

I still get

[: too many arguments
bash: cd: /cygdrive/e/Documents: No such file or directory

As error message. but everything else seems OK. Hope no one need to do this
change next time.

Cheers,

Guansong



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2000-09-15  7:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-13 12:38 set HOME environment Earnie Boyd
2000-09-14  3:22 ` David Starks-Browning
2000-09-14  8:50   ` Randall R Schulz
  -- strict thread matches above, loose matches on Subject: below --
2000-09-15  7:19 Schaible, Joerg
2000-09-13 12:13 Earnie Boyd
2000-09-13  8:14 Earnie Boyd
2000-09-13  6:39 Earnie Boyd
2000-09-11 13:22 Guansong Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).