On Thu, Jan 07, 2010 at 11:25:29AM -0500, [email protected] wrote:
> I don't think using CWD is part of documented behavior...

Hmm -- Do What I Mean (DWIM) approach here.  It doesn't say it isn't part of
documented behaviour either.  :P

> Making CWD the new default...hmm.

Not the default unless specified as such, see below.

> All of my config files start with a dot.
> 
> At first I thought testing for './' or '../' would
> be the right fix.  Does that seem right to you?

I think so.  See the patch attached.  The comment block in the patch
hopefully is self-explanatory.

It does mean though that, whilst:

fvwm -f ../../some_file

... makes sense, if it appears in a config file as:

Read ../../some_file

... that FVWM will no longer find it, as it's never then expanded out to
look in FVWM_USERDIR and FVWM_DATADIR.  I personally don't consider *that*
to be a bug, as the explicit action of "../../" is relative to something to
the user -- what that might be is unknown, but I wouldn't want to suggest we
then exapand it out to:

FVWM_USERDIR/../../some_file

Users doing this in their config file will have already made use of "$."
anyway, I'd have hoped.

What do you think?

-- Thomas Adam

-- 
"It was the cruelest game I've ever played and it's played inside my head."
-- "Hush The Warmth", Gorky's Zygotic Mynci.
Index: fvwm/read.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/read.c,v
retrieving revision 1.65
diff -u -r1.65 read.c
--- fvwm/read.c	5 Jan 2010 19:34:39 -0000	1.65
+++ fvwm/read.c	7 Jan 2010 20:20:21 -0000
@@ -204,24 +204,55 @@
 	char *filename, const exec_context_t *exc)
 {
 	char *full_filename;
-	FILE* f;
+	FILE* f = NULL;
 
-	if (filename[0] == '.' || filename[0] == '/')
-	{             /* if absolute path */
-		f = fopen(filename,"r");
-		full_filename = filename;
-	}
-	else
-	{             /* else its a relative path */
+	/* We attempt to open the filename by doing the following:
+	 *
+	 * - If the file starts with "./" or "../" then try and 
+	 *   open the file exactly as specified which means 
+	 *   things like:
+	 *
+	 *   ../.././foo is catered for.
+	 *
+	 * - If the file does start with a "/" then it's treated as an
+	 *   absolute path if it wasn't already opened.
+	 *
+	 *  - Otherwise, it's assumed to be in FVWM_USERDIR OR FVWM_DATADIR,
+	 *    whichever comes first.
+	 *
+	 *  - *Hidden* files in the CWD would have to be specified as:
+	 *    
+	 *    ./.foo
+	 */
+
+	if ((filename[0] == '.') &&
+		(filename[1] != '.' && filename[1] != '/'))
+	{
+		/* It's a relative path. */
 		full_filename = CatString3(fvwm_userdir, "/", filename);
-		f = fopen(full_filename, "r");
-		if (f == NULL)
+		if((f = fopen(full_filename, "r")) == NULL)
 		{
 			full_filename = CatString3(
-				FVWM_DATADIR, "/", filename);
+					FVWM_DATADIR, "/", filename);
 			f = fopen(full_filename, "r");
 		}
 	}
+	else
+	{
+		/* Open the file as specified. */
+		if ((f = fopen(filename, "r")) == NULL) 
+		{
+			/* Which failed.
+			 * T`ry looking for an absolute path. */
+			if (filename[0] == '/')
+			{
+				/* It's an absolute path */
+				full_filename = filename;
+				f = fopen(filename,"r");
+			}
+		}
+	}
+
 	if (f == NULL)
 	{
 		return 0;

Reply via email to