OSDN Git Service

(open_file): Ignore directories only when loading a GUS/patch instrument
authorShoichi Tamuki <tamuki@linet.gr.jp>
Fri, 2 Jun 2006 05:51:10 +0000 (05:51 +0000)
committerShoichi Tamuki <tamuki@linet.gr.jp>
Fri, 2 Jun 2006 05:51:10 +0000 (05:51 +0000)
ChangeLog
timidity/common.c
timidity/common.h
timidity/instrum.c
timidity/timidity.c

index efa7de2..9ff0e7d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2006-06-02  TAMUKI Shoichi <tamuki@linet.gr.jp>
+
+       * timidity/common.c (open_file): Ignore directories only when
+         loading a GUS/patch instrument in order to avoid the trouble
+         in {gtk,motif,tcltk} interface and WRD display
+       * timidity/timidity.c (main): Revert fix supplying suffix '/'
+         to each argv elements when the path *is* a directory but
+         *is not* suffixed by '/'
+
 2006-05-31  TAMUKI Shoichi <tamuki@linet.gr.jp>
 
        * timidity/instrum.c, timidity/readmidi.c:
index 48d28a3..9b5ce42 100644 (file)
@@ -393,90 +393,159 @@ struct timidity_file *open_with_mem(char *mem, int32 memlen, int noise_mode)
     return tf;
 }
 
-/* This is meant to find and open files for reading, possibly piping
-   them through a decompressor. */
+/*
+ * This is meant to find and open files for reading, possibly piping
+ * them through a decompressor.
+ */
 struct timidity_file *open_file(char *name, int decompress, int noise_mode)
 {
-  struct stat st;
-  struct timidity_file *tf;
-  PathList *plp=pathlist;
-  int l;
-
-  open_file_noise_mode = noise_mode;
-  if (!name || !(*name))
-    {
-      if(noise_mode)
-        ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "Attempted to open nameless file.");
-      return 0;
-    }
-
-  /* First try the given name */
-  strncpy(current_filename, url_unexpand_home_dir(name), 1023);
-  current_filename[1023]='\0';
-
-  if(noise_mode)
-    ctl->cmsg(CMSG_INFO, VERB_DEBUG, "Trying to open %s", current_filename);
-  stat(current_filename, &st);
-  if(!S_ISDIR(st.st_mode))
-    if ((tf=try_to_open(current_filename, decompress)))
-      return tf;
-
+       struct timidity_file *tf;
+       PathList *plp = pathlist;
+       int l;
+       
+       open_file_noise_mode = noise_mode;
+       if (!name || !(*name)) {
+               if (noise_mode)
+                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
+                                       "Attempted to open nameless file.");
+               return 0;
+       }
+       /* First try the given name */
+       strncpy(current_filename, url_unexpand_home_dir(name), 1023);
+       current_filename[1023] = '\0';
+       if (noise_mode)
+               ctl->cmsg(CMSG_INFO, VERB_DEBUG, "Trying to open %s",
+                               current_filename);
+       if ((tf = try_to_open(current_filename, decompress)))
+               return tf;
 #ifdef __MACOS__
-  if(errno)
+       if (errno) {
 #else
-  if(errno && errno != ENOENT)
+       if (errno && errno != ENOENT) {
 #endif
-    {
-       if(noise_mode)
-           ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
-                     current_filename, strerror(errno));
+               if (noise_mode)
+                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
+                                       current_filename, strerror(errno));
+               return 0;
+       }
+       if (!is_abs_path(name))
+               while (plp) {   /* Try along the path then */
+                       *current_filename = 0;
+                       if(l = strlen(plp->path)) {
+                               strncpy(current_filename, plp->path,
+                                               sizeof(current_filename));
+                               if (!IS_PATH_SEP(current_filename[l - 1])
+                                               && current_filename[l - 1] != '#'
+                                               && name[0] != '#')
+                                       strncat(current_filename, PATH_STRING,
+                                                       sizeof(current_filename)
+                                                       - strlen(current_filename) - 1);
+                       }
+                       strncat(current_filename, name, sizeof(current_filename)
+                                       - strlen(current_filename) - 1);
+                       if (noise_mode)
+                               ctl->cmsg(CMSG_INFO, VERB_DEBUG,
+                                               "Trying to open %s", current_filename);
+                       if ((tf = try_to_open(current_filename, decompress)))
+                                return tf;
+#ifdef __MACOS__
+                       if(errno) {
+#else
+                       if(errno && errno != ENOENT) {
+#endif
+                               if (noise_mode)
+                                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
+                                                       current_filename, strerror(errno));
+                               return 0;
+                       }
+                       plp = plp->next;
+               }
+       /* Nothing could be opened. */
+       *current_filename = 0;
+       if (noise_mode >= 2)
+               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s", name,
+                               (errno) ? strerror(errno) : "Can't open file");
        return 0;
-    }
+}
 
-  if (!is_abs_path(name))
-    while (plp)  /* Try along the path then */
-      {
-       *current_filename=0;
-       l=strlen(plp->path);
-       if(l)
-         {
-              strncpy(current_filename, plp->path, sizeof(current_filename));
-           if(!IS_PATH_SEP(current_filename[l-1]) &&
-              current_filename[l-1] != '#' &&
-              name[0] != '#')
-               strncat(current_filename, PATH_STRING, sizeof(current_filename) - strlen(current_filename) - 1);
-         }
-       strncat(current_filename, name, sizeof(current_filename) - strlen(current_filename) - 1);
-       if(noise_mode)
-           ctl->cmsg(CMSG_INFO, VERB_DEBUG,
-                     "Trying to open %s", current_filename);
+/*
+ * This is meant to find and open regular files for reading, possibly
+ * piping them through a decompressor.
+ */
+struct timidity_file *open_file_r(char *name, int decompress, int noise_mode)
+{
+       struct stat st;
+       struct timidity_file *tf;
+       PathList *plp = pathlist;
+       int l;
+       
+       open_file_noise_mode = noise_mode;
+       if (!name || !(*name)) {
+               if (noise_mode)
+                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL,
+                                       "Attempted to open nameless file.");
+               return 0;
+       }
+       /* First try the given name */
+       strncpy(current_filename, url_unexpand_home_dir(name), 1023);
+       current_filename[1023] = '\0';
+       if (noise_mode)
+               ctl->cmsg(CMSG_INFO, VERB_DEBUG, "Trying to open %s",
+                               current_filename);
        stat(current_filename, &st);
-       if(!S_ISDIR(st.st_mode))
-         if ((tf=try_to_open(current_filename, decompress)))
-           return tf;
+       if (!S_ISDIR(st.st_mode))
+               if ((tf = try_to_open(current_filename, decompress)))
+                       return tf;
 #ifdef __MACOS__
-       if(errno)
+       if (errno) {
 #else
-       if(errno && errno != ENOENT)
+       if (errno && errno != ENOENT) {
 #endif
-       {
-           if(noise_mode)
-               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
-                         current_filename, strerror(errno));
-           return 0;
-         }
-       plp=plp->next;
-      }
-
-  /* Nothing could be opened. */
-
-  *current_filename=0;
-
-  if (noise_mode>=2)
-      ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s", name,
-               errno ? strerror(errno) : "Can't open file");
-
-  return 0;
+               if (noise_mode)
+                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
+                                       current_filename, strerror(errno));
+               return 0;
+       }
+       if (!is_abs_path(name))
+               while (plp) {   /* Try along the path then */
+                       *current_filename = 0;
+                       if(l = strlen(plp->path)) {
+                               strncpy(current_filename, plp->path,
+                                               sizeof(current_filename));
+                               if (!IS_PATH_SEP(current_filename[l - 1])
+                                               && current_filename[l - 1] != '#'
+                                               && name[0] != '#')
+                                       strncat(current_filename, PATH_STRING,
+                                                       sizeof(current_filename)
+                                                       - strlen(current_filename) - 1);
+                       }
+                       strncat(current_filename, name, sizeof(current_filename)
+                                       - strlen(current_filename) - 1);
+                       if (noise_mode)
+                               ctl->cmsg(CMSG_INFO, VERB_DEBUG,
+                                               "Trying to open %s", current_filename);
+                       stat(current_filename, &st);
+                       if (!S_ISDIR(st.st_mode))
+                               if ((tf = try_to_open(current_filename, decompress)))
+                                        return tf;
+#ifdef __MACOS__
+                       if(errno) {
+#else
+                       if(errno && errno != ENOENT) {
+#endif
+                               if (noise_mode)
+                                       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
+                                                       current_filename, strerror(errno));
+                               return 0;
+                       }
+                       plp = plp->next;
+               }
+       /* Nothing could be opened. */
+       *current_filename = 0;
+       if (noise_mode >= 2)
+               ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s", name,
+                               (errno) ? strerror(errno) : "Can't open file");
+       return 0;
 }
 
 /* This closes files opened with open_file */
index 5d37d17..d5ed02d 100644 (file)
@@ -51,10 +51,12 @@ struct timidity_file
 extern void add_to_pathlist(char *s);
 extern void clean_up_pathlist(void);
 extern int is_url_prefix(const char *name);
-extern struct timidity_file *open_file(char *name,
-                                      int decompress, int noise_mode);
+extern struct timidity_file *open_file(char *name, int decompress,
+               int noise_mode);
+extern struct timidity_file *open_file_r(char *name, int decompress,
+               int noise_mode);
 extern struct timidity_file *open_with_mem(char *mem, int32 memlen,
-                                          int noise_mode);
+               int noise_mode);
 extern void close_file(struct timidity_file *tf);
 extern void skip(struct timidity_file *tf, size_t len);
 extern char *tf_gets(char *buff, int n, struct timidity_file *tf);
index ed93213..4fbeb94 100644 (file)
@@ -662,7 +662,7 @@ static Instrument *load_gus_instrument(char *name,
                        return ip;
                }
        /* Open patch file */
-       if (! (tf = open_file(name, 2, OF_NORMAL))) {
+       if (! (tf = open_file_r(name, 2, OF_NORMAL))) {
 #ifdef PATCH_EXT_LIST
                int name_len, ext_len;
                static char *patch_ext[] = PATCH_EXT_LIST;
@@ -680,7 +680,7 @@ static Instrument *load_gus_instrument(char *name,
                                        continue;       /* duplicated ext. */
                                strcpy((char *) tmp, name);
                                strcat((char *) tmp, patch_ext[i]);
-                               if ((tf = open_file((char *) tmp, 1, OF_NORMAL))) {
+                               if ((tf = open_file_r((char *) tmp, 1, OF_NORMAL))) {
                                        noluck = 0;
                                        break;
                                }
index 2ab0ec7..4635622 100644 (file)
@@ -50,9 +50,6 @@
 #  include <time.h>
 # endif
 #endif  /* TIME_WITH_SYS_TIME */
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif /* NAVE_SYS_STAT_H */
 #include <fcntl.h> /* for open */
 
 #ifdef BORLANDC_EXCEPTION
@@ -5523,29 +5520,6 @@ extern int volatile save_playlist_once_before_exit_flag;
 static int CoInitializeOK = 0;
 #endif
 
-static inline int directory_p(const char* path)
-{
-#if defined ( IA_W32GUI ) || defined ( IA_W32G_SYN )
-    return is_directory(path);
-#else
-    struct stat st;
-    if(stat(path, &st) != -1) return S_ISDIR(st.st_mode);
-    return 0;
-#endif
-}
-
-static inline void canonicalize_path(char* path)
-{
-#if defined ( IA_W32GUI ) || defined ( IA_W32G_SYN )
-    directory_form(path);
-#else
-    int len = strlen(path);
-    if(!len || path[len-1]==PATH_SEP) return;
-    path[len] = PATH_SEP;
-    path[len+1] = '\0';
-#endif
-}
-
 #if !defined(ANOTHER_MAIN) || defined(__W32__)
 #ifdef __W32__ /* Windows */
 #if ( (!defined(IA_W32GUI) || defined(__CYGWIN32__) || defined(__MINGW32__)) && !defined(IA_W32G_SYN) )
@@ -5649,18 +5623,19 @@ int main(int argc, char **argv)
                return 0;
        }
 #endif
-#endif
+       
     for(c = 1; c < argc; c++)
     {
-       if(directory_p(argv[c]))
+       if(is_directory(argv[c]))
        {
            char *p;
            p = (char *)safe_malloc(strlen(argv[c]) + 2);
            strcpy(p, argv[c]);
-           canonicalize_path(p);
+           directory_form(p);
            argv[c] = p;
        }
     }
+#endif
 
 #if defined(IA_WINSYN) || defined(IA_PORTMIDISYN) || defined(IA_W32G_SYN)
        opt_sf_close_each_file = 0;