[AD] canonicalize_filename()

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


The attached patch adds canonicalize_filename() and deprecates 
fix_filename_path(). Applied to mainline.

-- 
Eric Botcazou
Index: docs/src/allegro._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/allegro._tx,v
retrieving revision 1.154
diff -u -r1.154 allegro._tx
--- docs/src/allegro._tx	17 May 2003 16:47:53 -0000	1.154
+++ docs/src/allegro._tx	20 May 2003 17:05:56 -0000
@@ -6305,20 +6305,21 @@
    argv[0] does not specify the path, we search for our file in $PATH.
 
 @@char *@fix_filename_case(char *path);
-@domain.hid fix_filename_slashes, fix_filename_path
+@xref fix_filename_slashes, canonicalize_filename
    Converts a filename to a standardised case. On DOS platforms, they will 
    be entirely uppercase. Returns a copy of the path parameter.
 
 @@char *@fix_filename_slashes(char *path);
-@domain.hid fix_filename_case, fix_filename_path
+@xref fix_filename_case, canonicalize_filename
    Converts all the directory separators in a filename to a standard 
    character. On DOS platforms, this is a backslash. Returns a copy of the 
    path parameter.
 
-@domain.hid *@fix_filename_path(char *dest, const char *path, int size);
+@@char *@canonicalize_filename(char *dest, const char *filename, int size);
 @xref fix_filename_case, fix_filename_slashes
-   Converts a partial filename into a full path, storing at most size bytes 
-   into the dest buffer. Returns a copy of the dest parameter.
+   Converts any filename into its canonical form, i.e. the minimal absolute
+   filename describing the same file, storing at most size bytes into the
+   dest buffer. Returns a copy of the dest parameter.
 
 @@char *@make_absolute_filename(char *dest, const char *path, const char *filename, int size);
 @xref make_relative_filename, is_relative_filename
Index: docs/src/api._tx
===================================================================
RCS file: /cvsroot/alleg/allegro/docs/src/api._tx,v
retrieving revision 1.24
diff -u -r1.24 api._tx
--- docs/src/api._tx	15 May 2003 21:40:41 -0000	1.24
+++ docs/src/api._tx	20 May 2003 17:05:57 -0000
@@ -158,6 +158,8 @@
    and OLD_FILESEL_HEIGHT if you want the file selector to be displayed with
    the dimensions of the old file selector).
 <li>
+   fix_filename_path (canonicalize_filename).
+<li>
    for_each_file (for_each_file_ex).
 <li>
    gui_textout (gui_textout_ex, passing the mode you would have passed to
Index: include/allegro/alcompat.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/alcompat.h,v
retrieving revision 1.13
diff -u -r1.13 alcompat.h
--- include/allegro/alcompat.h	13 May 2003 19:56:18 -0000	1.13
+++ include/allegro/alcompat.h	20 May 2003 17:05:57 -0000
@@ -144,6 +144,10 @@
 #define generate_optimised_pallete     generate_optimised_palette
 
 
+/* a pretty vague name */
+#define fix_filename_path              canonicalize_filename
+
+
 /* the good old file selector */
 #define OLD_FILESEL_WIDTH   -1
 #define OLD_FILESEL_HEIGHT  -1
Index: include/allegro/file.h
===================================================================
RCS file: /cvsroot/alleg/allegro/include/allegro/file.h,v
retrieving revision 1.7
diff -u -r1.7 file.h
--- include/allegro/file.h	17 May 2003 09:09:04 -0000	1.7
+++ include/allegro/file.h	20 May 2003 17:05:59 -0000
@@ -27,7 +27,7 @@
 
 AL_FUNC(char *, fix_filename_case, (char *path));
 AL_FUNC(char *, fix_filename_slashes, (char *path));
-AL_FUNC(char *, fix_filename_path, (char *dest, AL_CONST char *path, int size));
+AL_FUNC(char *, canonicalize_filename, (char *dest, AL_CONST char *filename, int size));
 AL_FUNC(char *, make_absolute_filename, (char *dest, AL_CONST char *path, AL_CONST char *filename, int size));
 AL_FUNC(char *, make_relative_filename, (char *dest, AL_CONST char *path, AL_CONST char *filename, int size));
 AL_FUNC(int, is_relative_filename, (AL_CONST char *filename));
Index: src/file.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/file.c,v
retrieving revision 1.46
diff -u -r1.46 file.c
--- src/file.c	17 May 2003 09:09:05 -0000	1.46
+++ src/file.c	20 May 2003 17:06:06 -0000
@@ -145,10 +145,11 @@
 
 
 
-/* fix_filename_path:
- *  Canonicalizes path.
+/* Canonicalize_filename:
+ *  Returns the canonical form of the specified filename, i.e. the
+ *  minimal absolute filename describing the same file.
  */
-char *fix_filename_path(char *dest, AL_CONST char *path, int size)
+char *canonicalize_filename(char *dest, AL_CONST char *filename, int size)
 {
    int saved_errno = errno;
    char buf[1024], buf2[1024];
@@ -157,19 +158,19 @@
    int drive = -1;
    int c1, i;
    ASSERT(dest);
-   ASSERT(path);
+   ASSERT(filename);
    ASSERT(size >= 0);
 
    #if (DEVICE_SEPARATOR != 0) && (DEVICE_SEPARATOR != '\0')
 
       /* check whether we have a drive letter */
-      c1 = utolower(ugetc(path));
+      c1 = utolower(ugetc(filename));
       if ((c1 >= 'a') && (c1 <= 'z')) {
-	 int c2 = ugetat(path, 1);
+	 int c2 = ugetat(filename, 1);
 	 if (c2 == DEVICE_SEPARATOR) {
 	    drive = c1 - 'a';
-	    path += uwidth(path);
-	    path += uwidth(path);
+	    filename += uwidth(filename);
+	    filename += uwidth(filename);
 	 }
       }
 
@@ -184,9 +185,9 @@
 
    #ifdef ALLEGRO_UNIX
 
-      /* if the path starts with ~ then it's relative to a home directory */
-      if ((ugetc(path) == '~')) {
-	 AL_CONST char *tail = path + uwidth(path); /* could be the username */
+      /* if the filename starts with ~ then it's relative to a home directory */
+      if ((ugetc(filename) == '~')) {
+	 AL_CONST char *tail = filename + uwidth(filename); /* could be the username */
 	 char *home = NULL;                /* their home directory */
 
 	 if (ugetc(tail) == '/' || !ugetc(tail)) {
@@ -236,23 +237,23 @@
 	    }
 	 }
 
-	 /* If we got a home directory, prepend it to the path. Otherwise
-	  * we leave the path alone, like bash but not tcsh; bash is better
+	 /* If we got a home directory, prepend it to the filename. Otherwise
+	  * we leave the filename alone, like bash but not tcsh; bash is better
 	  * anyway. :)
 	  */
 	 if (home) {
 	    do_uconvert(home, U_ASCII, buf+pos, U_CURRENT, sizeof(buf)-pos);
 	    free(home);
 	    pos = ustrsize(buf);
-	    path = tail;
+	    filename = tail;
 	    goto no_relativisation;
 	 }
       }
 
    #endif   /* Unix */
 
-   /* if the path is relative, make it absolute */
-   if ((ugetc(path) != '/') && (ugetc(path) != OTHER_PATH_SEPARATOR) && (ugetc(path) != '#')) {
+   /* if the filename is relative, make it absolute */
+   if ((ugetc(filename) != '/') && (ugetc(filename) != OTHER_PATH_SEPARATOR) && (ugetc(filename) != '#')) {
       _al_getdcwd(drive, buf2, sizeof(buf2) - ucwidth(OTHER_PATH_SEPARATOR));
       put_backslash(buf2);
 
@@ -268,8 +269,8 @@
    no_relativisation:
  #endif
 
-   /* add our path, and clean it up a bit */
-   ustrzcpy(buf+pos, sizeof(buf)-pos, path);
+   /* add our filename, and clean it up a bit */
+   ustrzcpy(buf+pos, sizeof(buf)-pos, filename);
 
    fix_filename_case(buf);
    fix_filename_slashes(buf);
@@ -350,7 +351,7 @@
 
    replace_filename(tmp, path, filename, sizeof(tmp));
 
-   fix_filename_path(dest, tmp, size);
+   canonicalize_filename(dest, tmp, size);
 
    return dest;
 }
Index: src/fsel.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/fsel.c,v
retrieving revision 1.35
diff -u -r1.35 fsel.c
--- src/fsel.c	15 May 2003 21:40:41 -0000	1.35
+++ src/fsel.c	20 May 2003 17:06:09 -0000
@@ -270,7 +270,7 @@
    int i;
 
    if (msg == MSG_START) {
-      fix_filename_path(b, s, sizeof(b));
+      canonicalize_filename(b, s, sizeof(b));
       ustrzcpy(s, size, b);
    }
 
@@ -278,7 +278,7 @@
       if ((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR))
 	 ustrzcat(s, size, uconvert_ascii("./", tmp));
 
-      fix_filename_path(b, s, sizeof(b));
+      canonicalize_filename(b, s, sizeof(b));
       ustrzcpy(s, size - ucwidth(OTHER_PATH_SEPARATOR), b);
 
       ch = ugetat(s, -1);
Index: tests/filetest.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tests/filetest.c,v
retrieving revision 1.10
diff -u -r1.10 filetest.c
--- tests/filetest.c	23 Jan 2003 13:16:15 -0000	1.10
+++ tests/filetest.c	20 May 2003 17:06:11 -0000
@@ -124,7 +124,7 @@
    int i;
 
    if (msg == MSG_START) {
-      fix_filename_path(b, s, sizeof(b));
+      canonicalize_filename(b, s, sizeof(b));
       ustrzcpy(s, size, b);
    }
 
@@ -132,7 +132,7 @@
       if ((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR))
 	 ustrzcat(s, size, uconvert_ascii("./", tmp));
 
-      fix_filename_path(b, s, sizeof(b));
+      canonicalize_filename(b, s, sizeof(b));
       ustrzcpy(s, size - ucwidth(OTHER_PATH_SEPARATOR), b);
 
       ch = ugetat(s, -1);
Index: tools/grabber.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/grabber.c,v
retrieving revision 1.56
diff -u -r1.56 grabber.c
--- tools/grabber.c	20 May 2003 13:23:26 -0000	1.56
+++ tools/grabber.c	20 May 2003 17:06:15 -0000
@@ -1753,7 +1753,7 @@
    }
 
    if (filename) {
-      fix_filename_path(data_file, filename, sizeof(data_file));
+      canonicalize_filename(data_file, filename, sizeof(data_file));
       strcpy(data_file, datedit_pretty_name(data_file, "dat", FALSE));
    }
    else


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