Re: [AD] Relative paths in the grabber

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> Ok, revised patch attached. I haven't done any unicode optimizations, but
> I've fixed the capitalization in the menu and the missing shortcuts.

+#if (defined ALLEGRO_DOS) || (defined ALLEGRO_WINDOWS)
+   if (strstr(path, DEVICE_SEPARATOR) == NULL) 
+      return 0;
+#endif

You probably meant ustrstr(). But this won't compile because the second 
argument of ustrstr() is a string; what you want is ustrchr() instead.

And I think it's either '!= NULL' or 'return 1'.

+   /* Now cleanup the path strings and strip the filenames from the path */
+   p = malloc(FILENAME_LENGTH);
+   
+   fix_filename_path(p, path1, FILENAME_LENGTH);
+   replace_filename(path1copy, p, "", FILENAME_LENGTH);
+   fix_filename_path(p, path2, FILENAME_LENGTH);
+   replace_filename(path2copy, p, "", FILENAME_LENGTH);   
+   
+   free(p);

We can do better than that:

	path1copy = ustrdup(path1);
	usetc(get_filename(path1copy), 0);

+      /* Different drives, so absolute path == relative path */
+      uszprintf (dest, size, "%s%s", path2copy, file2);

Avoid uszprintf() to concatenate strings, it's highly inefficient. There is 
ustrzcat() for that.

+   while ((ugetc(path1copy+pos1) == ugetc(path2copy+pos2)) && 
+          ugetc(path1copy+pos1) && ugetc(path2copy+pos2)) {
+      if (ugetc(path1copy+pos1) == '/' || ugetc(path1copy+pos1) == 
OTHER_PATH_SEPARATOR) {
+         dirpos1 = pos1+uwidth(path1copy+pos1);
+         dirpos2 = pos2+uwidth(path2copy+pos2);
+      }
+      pos1 += uwidth(path1copy+pos1);
+      pos2 += uwidth(path2copy+pos2);
+   }

p1 = path1copy;
p2 = path2copy;
while (((c1=ugetx(&p)) && (c2=ugetx(&p2)) && (c1==c2))
 ...

+   /* Check if both paths are in fact equal */
+   if (ugetc(path1copy+pos1) == ugetc(path2copy+pos2)) {
+      uszprintf (dest, size, "%s%s", uconvert_ascii("./", scratch), file2);

ustrzcat() again.

+   while (ugetc(path1copy+pos1)) {
+      if (ugetc(path1copy+pos1) == '/' || ugetc(path1copy+pos1) == 
OTHER_PATH_SEPARATOR) {
+         c++;
+      }
+      pos1 += uwidth(path1copy+pos1);
+   }

ugetx() again.

+   w = ustrlen(uconvert_ascii("../", scratch));

You want ustrsize() instead to get the length in bytes.

+   for (n=0; n<c; n++) {
+      uszprintf (p, size-n*w, "%s", uconvert_ascii("../", scratch));
+      p+=w;
+   }
+   uszprintf (p, size-n*w, "%s%s", path2copy+dirpos2, file2);

ustrzcat() again.


I'll do the corrections when merging.

-- 
Eric Botcazou




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