Changeset: 4b8403864365 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4b8403864365
Modified Files:
        MonetDB5/src/mal/mal_linker.mx
Branch: default
Log Message:

Merged from Jun2010


diffs (96 lines):

diff -r f3c2b85025ce -r 4b8403864365 MonetDB5/src/mal/mal_linker.mx
--- a/MonetDB5/src/mal/mal_linker.mx    Thu May 27 20:00:37 2010 +0200
+++ b/MonetDB5/src/mal/mal_linker.mx    Thu May 27 22:12:16 2010 +0200
@@ -329,6 +329,7 @@
        return strcmp(*(char* const*)p1, *(char* const*)p2);
 }
 
+#define MAXMULTISCRIPT 48
 static char *
 locate_file(const char *basename, const char *ext, const bit recurse)
 {
@@ -336,6 +337,8 @@
        char *fullname;
        size_t fullnamelen;
        size_t filelen = strlen(basename) + strlen(ext);
+       str strs[MAXMULTISCRIPT]; /* hardwired limit */
+       int lasts = 0;
 
        if (mod_path == NULL)
                return NULL;
@@ -374,9 +377,7 @@
                /* see if this is a directory, if so, recurse */
                if (recurse == 1 && (rdir = opendir(fullname)) != NULL) {
                        struct dirent *e;
-                       str strs[48]; /* hardwired limit */
-                       int lasts = 0;
-                       int c;
+                       int ps = lasts;
                        /* list *ext, sort, return */
                        while ((e = readdir(rdir)) != NULL) {
                                if (strcmp(e->d_name, "..") == 0 || 
strcmp(e->d_name, ".") == 0)
@@ -394,38 +395,42 @@
                                                        fullname, DIR_SEP, 
GDKstrdup(e->d_name));
                                        lasts++;
                                }
-                               if (lasts >= 48)
+                               if (lasts >= MAXMULTISCRIPT)
                                        break;
                        }
+                       if (lasts - ps > 0) {
+                               /* assure that an ordering such as 10_first, 
20_second works */
+                               qsort(strs + ps, lasts - ps, sizeof(char *), 
cmpstr);
+                       }
                        (void)closedir(rdir);
-                       if (lasts > 0) {
-                               /* assure that an ordering such as 10_first, 
20_second works */
-                               qsort(strs, lasts, sizeof(char *), cmpstr);
-                               i = 0;
-                               for (c = 0; c < lasts; c++)
-                                       i += strlen(strs[c]) + 1; /* PATH_SEP 
or \0 */
-                               fullname = GDKrealloc(fullname, i);
-                               i = 0;
-                               for (c = 0; c < lasts; c++) {
-                                       strcpy(fullname + i, strs[c]);
-                                       i += strlen(strs[c]);
-                                       fullname[i++] = PATH_SEP;
-                                       GDKfree(strs[c]);
-                               }
-                               fullname[i - 1] = '\0';
-                               return fullname;
+               } else {
+                       strcat(fullname + i + 1, ext);
+                       if ((fd = open(fullname, O_RDONLY)) >= 0) {
+                               close(fd);
+                               return GDKrealloc(fullname, strlen(fullname) + 
1);
                        }
                }
-               strcat(fullname + i + 1, ext);
-               if ((fd = open(fullname, O_RDONLY)) >= 0) {
-                       close(fd);
-                       return GDKrealloc(fullname, strlen(fullname) + 1);
-               }
                if ((mod_path = p) == NULL)
                        break;
                while (*mod_path == PATH_SEP)
                        mod_path++;
        }
+       if (lasts > 0) {
+               int i = 0;
+               int c;
+               for (c = 0; c < lasts; c++)
+                       i += strlen(strs[c]) + 1; /* PATH_SEP or \0 */
+               fullname = GDKrealloc(fullname, i);
+               i = 0;
+               for (c = 0; c < lasts; c++) {
+                       strcpy(fullname + i, strs[c]);
+                       i += strlen(strs[c]);
+                       fullname[i++] = PATH_SEP;
+                       GDKfree(strs[c]);
+               }
+               fullname[i - 1] = '\0';
+               return fullname;
+       }
        /* not found */
        GDKfree(fullname);
        return NULL;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to