Re: [hatari-devel] Bug with Fsfirst("a*.*")

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

Attached patch provides the behavior you want,
which works when host file names are legal
Atari file names.

It fails when Atari-illegal host file names need
to be mapped to legal Atari file names, and then
back to original host names.  For example host
name like this:
	name.with.lots.of.dots

I'll try to come up with round-trip code that
would work both for all kinds of host filenames,
and allow similar matching as TOS.


	- Eero

On 02/20/2016 12:49 PM, Vincent Rivière wrote:
Hello.

There is a bug in Hatari GEMDOS emulation regarding to Fsfirst() file
patterns.

1) Normal operation (tested with Hatari and TOS 1.62 on A:).

- Fsfirst("a*") finds all files and directories starting with A but
without extension.

- Fsfirst("a*.*") finds all files and directories starting with A, with
or without extension.

2) Hatari bug on emulated C:

- Fsfirst("a*.*") only finds files and directories having an extension.

This can be easily tested with TomShell and the dir command:
http://www.wikiberd.de/~dennis/atari/tomshell.lzh

The same occurs with EmuTOS's command line (EmuCON).

dir a*.*

diff -r e73dbd8e8247 src/gemdos.c
--- a/src/gemdos.c	Wed Mar 02 17:15:44 2016 +0100
+++ b/src/gemdos.c	Thu Mar 03 00:14:20 2016 +0200
@@ -346,41 +346,41 @@
  */
 static bool fsfirst_match(const char *pat, const char *name)
 {
-	const char *dot, *p=pat, *n=name;
+	const char *p=pat, *n=name;
 
 	if (name[0] == '.')
-		return false;           /* skip .* files */
-	if (strcmp(pat,"*.*")==0)
-		return true;            /* match everything */
-	if (strcasecmp(pat,name)==0)
-		return true;            /* exact case insensitive match */
-
-	dot = strrchr(name, '.');	/* '*' matches everything except _last_ '.' */
+		return false;           /* ignore unix hidden files */
+
 	while (*n)
 	{
 		if (*p=='*')
 		{
-			while (*n && n != dot)
+			while (*n)
 				n++;
 			p++;
 		}
-		else
+		else if (*p=='?' && *n)
 		{
-			if (*p=='?' && *n)
-			{
-				n++;
-				p++;
-			}
-			else
-			{
-				if (toupper((unsigned char)*p++) != toupper((unsigned char)*n++))
-					return false;
-			}
+			n++;
+			p++;
+		}
+		else if (toupper((unsigned char)*p++) != toupper((unsigned char)*n++))
+		{
+			return false;
 		}
 	}
 
-	/* The name matches the pattern if it ends here, too */
-	return (*p == 0 || (*p == '*' && *(p+1) == 0));
+// printf("'%s': '%s' -> '%s'\n", name, pat, p);
+	/* The name matches if pattern ends here too, */
+	if (!*p)
+		return true;
+
+	/* or if pattern ends in '*' or '*.*' */
+	if ((*p == '*' && *(p+1) == '\0') ||
+	    (*p == '.' && *(p+1) == '*' && *(p+2) == '\0'))
+		return true;
+
+	return false;
 }
 
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/