support delimter separated pathlist
authorMichael Wallner <mike@php.net>
Wed, 18 Nov 2015 10:16:21 +0000 (11:16 +0100)
committerMichael Wallner <mike@php.net>
Wed, 18 Nov 2015 10:16:21 +0000 (11:16 +0100)
src/context.c

index 18e76e4db451b06fdde9f37537a6a1b09608451b..e499c5f0d24052c0f5a32475f0f0878d2a0b1fc2 100644 (file)
@@ -728,47 +728,62 @@ static int psi_select_dirent(const struct dirent *entry)
        return 0 == fnmatch("*.psi", entry->d_name, FNM_CASEFOLD);
 }
 
        return 0 == fnmatch("*.psi", entry->d_name, FNM_CASEFOLD);
 }
 
-void PSI_ContextBuild(PSI_Context *C, const char *path)
+void PSI_ContextBuild(PSI_Context *C, const char *paths)
 {
        int i, n;
 {
        int i, n;
+       char *sep = NULL, *cpy = strdup(paths), *ptr = cpy;
        struct dirent **entries = NULL;
 
        struct dirent **entries = NULL;
 
-       n = php_scandir(path, &entries, psi_select_dirent, alphasort);
 
 
-       if (n < 0) {
-               return;
-       } else for (i = 0; i < n; ++i) {
-               char psi[MAXPATHLEN];
-               PSI_Parser P;
+       do {
+               sep = strchr(ptr, ':');
 
 
-               if (MAXPATHLEN <= slprintf(psi, MAXPATHLEN, "%s/%s", path, entries[i]->d_name)) {
-                       C->error(PSI_WARNING, "Path to PSI file too long: %s/%s",
-                               path, entries[i]->d_name);
+               if (sep) {
+                       *sep = 0;
                }
                }
-               if (!PSI_ParserInit(&P, psi, C->error, 0)) {
-                       C->error(PSI_WARNING, "Failed to init PSI parser (%s): %s",
-                               psi, strerror(errno));
-                       continue;
+
+               n = php_scandir(ptr, &entries, psi_select_dirent, alphasort);
+
+               if (n > 0) {
+                       for (i = 0; i < n; ++i) {
+                               char psi[MAXPATHLEN];
+                               PSI_Parser P;
+
+                               if (MAXPATHLEN <= slprintf(psi, MAXPATHLEN, "%s/%s", ptr, entries[i]->d_name)) {
+                                       C->error(PSI_WARNING, "Path to PSI file too long: %s/%s",
+                                               ptr, entries[i]->d_name);
+                               }
+                               if (!PSI_ParserInit(&P, psi, C->error, 0)) {
+                                       C->error(PSI_WARNING, "Failed to init PSI parser (%s): %s",
+                                               psi, strerror(errno));
+                                       continue;
+                               }
+
+                               while (-1 != PSI_ParserScan(&P)) {
+                                       PSI_ParserParse(&P, PSI_TokenAlloc(&P));
+                               };
+                               PSI_ParserParse(&P, NULL);
+                               PSI_ContextValidate(C, &P);
+                               PSI_ParserDtor(&P);
+                       }
                }
 
                }
 
-               while (-1 != PSI_ParserScan(&P)) {
-                       PSI_ParserParse(&P, PSI_TokenAlloc(&P));
-               };
-               PSI_ParserParse(&P, NULL);
-               PSI_ContextValidate(C, &P);
-               PSI_ParserDtor(&P);
-       }
+               if (entries) {
+                       for (i = 0; i < n; ++i) {
+                               free(entries[i]);
+                       }
+                       free(entries);
+               }
+
+               ptr = sep + 1;
+       } while (sep);
+
 
        if (PSI_ContextCompile(C) && SUCCESS != zend_register_functions(NULL, C->closures, NULL, MODULE_PERSISTENT)) {
                C->error(PSI_WARNING, "Failed to register functions!");
        }
 
 
        if (PSI_ContextCompile(C) && SUCCESS != zend_register_functions(NULL, C->closures, NULL, MODULE_PERSISTENT)) {
                C->error(PSI_WARNING, "Failed to register functions!");
        }
 
-       if (entries) {
-               for (i = 0; i < n; ++i) {
-                       free(entries[i]);
-               }
-               free(entries);
-       }
+       free(cpy);
 
 }
 
 
 }