dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnet/csant csant_fileset.c,1.15,1.16


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnet/csant csant_fileset.c,1.15,1.16
Date: Sat, 22 Feb 2003 20:24:46 -0500

Update of /cvsroot/dotgnu-pnet/pnet/csant
In directory subversions:/tmp/cvs-serv32237/csant

Modified Files:
        csant_fileset.c 
Log Message:


Rearrange the code for CSAntFileSetLoad so that ".." directory
includes are handled correctly.


Index: csant_fileset.c
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnet/csant/csant_fileset.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** csant_fileset.c     31 Jan 2003 10:57:15 -0000      1.15
--- csant_fileset.c     23 Feb 2003 01:24:42 -0000      1.16
***************
*** 51,54 ****
--- 51,55 ----
  {
        char          *dirName;
+       const char    *regex;
        CSAntDirStack *next;
  
***************
*** 96,262 ****
  
  /*
!  * Build a regular expression from a set of include or exclude names.
   * Returns non-zero if recursion into sub-directories is specified.
   */
  typedef regex_t RegexState;
! static int BuildIncludeRegex(CSAntTask *node, const char *name,
!                                                        RegexState *state)
  {
-       CSAntTask *subNode;
-       const char *arg;
        char *regex = 0;
        int regexLen = 0;
        int regexMax = 0;
-       int haveCase = 0;
        int recursive = 0;
        char ch;
  
        /* Build the regular expression */
!       subNode = node->taskChildren;
!       while(subNode != 0)
        {
!               if(!CheckIf(subNode))
                {
!                       subNode=subNode->next;
!                       continue;
!               }
!               if(!strcmp(subNode->name, name) &&
!                  (arg = CSAntTaskParam(subNode, "name")) != 0)
!               {
!                       if(haveCase)
                        {
                                REGEX_CHAR('|');
                        }
                        else
                        {
!                               haveCase = 1;
                        }
                        REGEX_CHAR('^');
!                       while(*arg != 0)
                        {
!                               ch = *arg++;
!                               if(ch == '*' && *arg == '*')
!                               {
!                                       /* Recursive regular expression 
definition */
!                                       recursive = 1;
!                                       if(arg[1] == '/' || arg[1] == '\\')
!                                       {
!                                               REGEX_CHAR('(');
!                                               REGEX_CHAR('.');
!                                               REGEX_CHAR('*');
!                                       #ifdef IL_WIN32_NATIVE
!                                               REGEX_CHAR('\\');
!                                               REGEX_CHAR('\\');
!                                       #else
!                                               REGEX_CHAR('/');
!                                       #endif
!                                               REGEX_CHAR('|');
!                                               REGEX_CHAR('(');
!                                               REGEX_CHAR(')');
!                                               REGEX_CHAR(')');
!                                               arg += 2;
!                                       }
!                                       else
!                                       {
!                                               REGEX_CHAR('.');
!                                               REGEX_CHAR('*');
!                                               ++arg;
!                                       }
!                               }
!                               else if(ch == '*')
!                               {
!                                       /* Match anything that doesn't involve 
a separator */
!                                       REGEX_CHAR('[');
!                                       REGEX_CHAR('^');
!                               #ifdef IL_WIN32_NATIVE
!                                       REGEX_CHAR('\\');
!                                       REGEX_CHAR('\\');
!                               #else
!                                       REGEX_CHAR('/');
!                               #endif
!                                       REGEX_CHAR(']');
!                                       REGEX_CHAR('*');
!                               }
!                               else if(ch == '?')
!                               {
!                                       /* Match a single character */
!                                       REGEX_CHAR('.');
!                               }
!                               else if(ch == '/' || ch == '\\')
!                               {
!                                       /* Match a directory separator */
!                                       recursive = 1;
!                               #ifdef IL_WIN32_NATIVE
!                                       REGEX_CHAR('\\');
!                                       REGEX_CHAR('\\');
!                               #else
!                                       REGEX_CHAR('/');
!                               #endif
!                               }
!                               else if(ch == '[')
!                               {
!                                       /* Match a set of characters */
!                                       REGEX_CHAR('[');
!                                       while(*arg != 0 && *arg != ']')
!                                       {
!                                               REGEX_CHAR(*arg);
!                                               ++arg;
!                                       }
!                                       REGEX_CHAR(']');
!                                       if(*arg != '\0')
!                                       {
!                                               ++arg;
!                                       }
!                               }
!                               else if(ch == '.' || ch == '^' || ch == '$' ||
!                                               ch == ']' || ch == '\\' || ch 
== '(' || ch == ')')
!                               {
!                                       /* Match a special character */
!                                       REGEX_CHAR('\\');
!                                       REGEX_CHAR(ch);
!                               }
!                               else
!                               {
!                                       /* Match an ordinary character */
!                               #ifdef _WIN32
!                                       if(ch >= 'A' && ch <= 'Z')
!                                       {
!                                               REGEX_CHAR('[');
!                                               REGEX_CHAR(ch);
!                                               REGEX_CHAR(ch - 'A' + 'a');
!                                               REGEX_CHAR(']');
!                                       }
!                                       else if(ch >= 'a' && ch <= 'z')
!                                       {
!                                               REGEX_CHAR('[');
!                                               REGEX_CHAR(ch - 'a' + 'A');
!                                               REGEX_CHAR(ch);
!                                               REGEX_CHAR(']');
!                                       }
!                                       else
!                                       {
!                                               REGEX_CHAR(ch);
!                                       }
!                               #else
!                                       REGEX_CHAR(ch);
!                               #endif
!                               }
                        }
-                       REGEX_CHAR('$');
                }
!               subNode = subNode->next;
        }
  
!       /* If there are no cases, then construct a regex that is
!          guaranteed never to match any filenames */
!       if(!haveCase)
        {
!               REGEX_CHAR('^');
                REGEX_CHAR('(');
                REGEX_CHAR(')');
-               REGEX_CHAR('$');
        }
! 
!       /* Terminate the regular expression */
        REGEX_CHAR('\0');
  
--- 97,233 ----
  
  /*
!  * Build a regular expression from a wildcard argument specification.
   * Returns non-zero if recursion into sub-directories is specified.
   */
  typedef regex_t RegexState;
! static int BuildIncludeRegex(const char *arg, RegexState *state)
  {
        char *regex = 0;
        int regexLen = 0;
        int regexMax = 0;
        int recursive = 0;
        char ch;
  
        /* Build the regular expression */
!       REGEX_CHAR('^');
!       while(*arg != 0)
        {
!               ch = *arg++;
!               if(ch == '*' && *arg == '*')
                {
!                       /* Recursive regular expression definition */
!                       recursive = 1;
!                       if(arg[1] == '/' || arg[1] == '\\')
                        {
+                               REGEX_CHAR('(');
+                               REGEX_CHAR('.');
+                               REGEX_CHAR('*');
+                       #ifdef IL_WIN32_NATIVE
+                               REGEX_CHAR('\\');
+                               REGEX_CHAR('\\');
+                       #else
+                               REGEX_CHAR('/');
+                       #endif
                                REGEX_CHAR('|');
+                               REGEX_CHAR('(');
+                               REGEX_CHAR(')');
+                               REGEX_CHAR(')');
+                               arg += 2;
                        }
                        else
                        {
!                               REGEX_CHAR('.');
!                               REGEX_CHAR('*');
!                               ++arg;
                        }
+               }
+               else if(ch == '*')
+               {
+                       /* Match anything that doesn't involve a separator */
+                       REGEX_CHAR('[');
                        REGEX_CHAR('^');
!               #ifdef IL_WIN32_NATIVE
!                       REGEX_CHAR('\\');
!                       REGEX_CHAR('\\');
!               #else
!                       REGEX_CHAR('/');
!               #endif
!                       REGEX_CHAR(']');
!                       REGEX_CHAR('*');
!               }
!               else if(ch == '?')
!               {
!                       /* Match a single character */
!                       REGEX_CHAR('.');
!               }
!               else if(ch == '/' || ch == '\\')
!               {
!                       /* Match a directory separator */
!                       recursive = 1;
!               #ifdef IL_WIN32_NATIVE
!                       REGEX_CHAR('\\');
!                       REGEX_CHAR('\\');
!               #else
!                       REGEX_CHAR('/');
!               #endif
!               }
!               else if(ch == '[')
!               {
!                       /* Match a set of characters */
!                       REGEX_CHAR('[');
!                       while(*arg != 0 && *arg != ']')
                        {
!                               REGEX_CHAR(*arg);
!                               ++arg;
!                       }
!                       REGEX_CHAR(']');
!                       if(*arg != '\0')
!                       {
!                               ++arg;
                        }
                }
!               else if(ch == '.' || ch == '^' || ch == '$' ||
!                               ch == ']' || ch == '\\' || ch == '(' || ch == 
')')
!               {
!                       /* Match a special character */
!                       REGEX_CHAR('\\');
!                       REGEX_CHAR(ch);
!               }
!               else
!               {
!                       /* Match an ordinary character */
!               #ifdef _WIN32
!                       if(ch >= 'A' && ch <= 'Z')
!                       {
!                               REGEX_CHAR('[');
!                               REGEX_CHAR(ch);
!                               REGEX_CHAR(ch - 'A' + 'a');
!                               REGEX_CHAR(']');
!                       }
!                       else if(ch >= 'a' && ch <= 'z')
!                       {
!                               REGEX_CHAR('[');
!                               REGEX_CHAR(ch - 'a' + 'A');
!                               REGEX_CHAR(ch);
!                               REGEX_CHAR(']');
!                       }
!                       else
!                       {
!                               REGEX_CHAR(ch);
!                       }
!               #else
!                       REGEX_CHAR(ch);
!               #endif
!               }
        }
  
!       /* Terminate the regular expression */
!       if(regexLen == 1)
        {
!               /* The regular expression was empty, so match nothing */
                REGEX_CHAR('(');
                REGEX_CHAR(')');
        }
!       REGEX_CHAR('$');
        REGEX_CHAR('\0');
  
***************
*** 299,302 ****
--- 270,295 ----
  
  /*
+  * Remove a pathname from a file set.
+  */
+ static void RemoveFromFileSet(CSAntFileSet *fileset, char *pathname)
+ {
+       unsigned long posn;
+       for(posn = 0; posn < fileset->numFiles; ++posn)
+       {
+               if(!strcmp(fileset->files[posn], pathname))
+               {
+                       ILFree(fileset->files[posn]);
+                       --(fileset->numFiles);
+                       while(posn < fileset->numFiles)
+                       {
+                               fileset->files[posn] = fileset->files[posn + 1];
+                               ++posn;
+                       }
+                       return;
+               }
+       }
+ }
+ 
+ /*
   * Determine if a pathname corresponds to a directory.
   */
***************
*** 318,382 ****
  }
  
! CSAntFileSet *CSAntFileSetLoad(CSAntTask *task, const char *name,
!                                                          const char 
*configBaseDir)
  {
-       CSAntFileSet *fileset;
-       CSAntTask *node;
        const char *arg;
!       const char *arg2;
!       char *baseDir;
!       char *currentDir;
        char *pathname;
!       char *tempName;
!       CSAntDirStack *stack;
!       CSAntDirStack *nextStack;
!       CSAntDir *dir;
!       const char *filename;
!       int recursive;
!       RegexState state;
!       unsigned long posn;
!       unsigned long outposn;
  
!       /* Find the sub-node */
!       node = task->taskChildren;
!       while(node != 0 && strcmp(node->name, name) != 0)
        {
!               node = node->next;
        }
!       if(!node)
        {
!               return 0;
        }
  
!       /* Construct the starting base directory and add it to the stack */
!       arg = CSAntTaskParam(node, "basedir");
!       if(arg)
        {
!               baseDir = CSAntDirCombine(configBaseDir, arg);
        }
        else
        {
!               baseDir = CSAntDirCombine(configBaseDir, 0);
        }
!       stack = (CSAntDirStack *)ILMalloc(sizeof(CSAntDirStack));
!       if(!stack)
        {
                CSAntOutOfMemory();
        }
!       stack->dirName = baseDir;
!       stack->next = 0;
  
!       /* Construct the file set */
!       fileset = (CSAntFileSet *)ILMalloc(sizeof(CSAntFileSet));
!       if(!fileset)
        {
!               CSAntOutOfMemory();
        }
!       fileset->numFiles = 0;
!       fileset->maxFiles = 0;
!       fileset->files = 0;
  
!       /* Compile the "includes" regular expression */
!       recursive = BuildIncludeRegex(node, "includes", &state);
  
        /* Pop items from the directory stack and scan them until
--- 311,452 ----
  }
  
! /*
!  * Add directory and regex information to a directory stack for
!  * a particular "includes" specification.
!  */
! static CSAntDirStack *DirStackAddInclude
!                       (CSAntDirStack *stack, CSAntFileSet *fileset,
!                        CSAntTask *include, const char *baseDir,
!                        int addToFileSet)
  {
        const char *arg;
!       int posn, start;
        char *pathname;
!       char *newBase;
!       CSAntDirStack *item;
  
!       /* Get the name argument */
!       arg = CSAntTaskParam(include, "name");
!       if(!arg)
        {
!               return stack;
        }
! 
!       /* Extract the leading directory information before the wildcards
!          to find the new base to start at */
!       posn = 0;
!       start = 0;
!       while(arg[posn] != '\0')
        {
!               while(arg[posn] != '/' && arg[posn] != '\\' && arg[posn] != 
'\0')
!               {
!                       if(arg[posn] == '*' || arg[posn] == '?' || arg[posn] == 
'[')
!                       {
!                               break;
!                       }
!                       ++posn;
!               }
!               if(arg[posn] == '*' || arg[posn] == '?' || arg[posn] == '[')
!               {
!                       break;
!               }
!               else if(arg[posn] != '\0')
!               {
!                       ++posn;
!               }
!               start = posn;
!       }
!       if(arg[start] == '\0')
!       {
!               /* This is a literal pathname with no wildcards */
!               pathname = CSAntDirCombine(baseDir, arg);
!               if(addToFileSet)
!               {
!                       AddToFileSet(fileset, pathname);
!               }
!               else
!               {
!                       RemoveFromFileSet(fileset, pathname);
!                       ILFree(pathname);
!               }
!               return stack;
        }
  
!       /* Build the new base directory */
!       if(start != 0)
        {
!               pathname = ILDupNString(arg, start - 1);
!               if(!pathname)
!               {
!                       CSAntOutOfMemory();
!               }
!               newBase = CSAntDirCombine(baseDir, pathname);
!               ILFree(pathname);
!               arg += start;
        }
        else
        {
!               newBase = ILDupString(baseDir);
!               if(!newBase)
!               {
!                       CSAntOutOfMemory();
!               }
        }
! 
!       /* Add the directory and regex to the stack */
!       item = (CSAntDirStack *)ILMalloc(sizeof(CSAntDirStack));
!       if(!item)
        {
                CSAntOutOfMemory();
        }
!       item->dirName = newBase;
!       item->regex = arg;
!       item->next = stack;
!       return item;
! }
  
! /*
!  * Add a group of includes to a directory stack.
!  */
! static CSAntDirStack *DirStackAddIncludes(CSAntFileSet *fileset,
!                                                                               
  CSAntTask *task,
!                                                                               
  const char *name,
!                                                                               
  const char *baseDir,
!                                                                               
  int addToFileSet)
! {
!       CSAntDirStack *stack = 0;
!       CSAntTask *subNode;
!       subNode = task->taskChildren;
!       while(subNode != 0)
        {
!               if(CheckIf(subNode))
!               {
!                       if(!strcmp(subNode->name, name))
!                       {
!                               stack = DirStackAddInclude
!                                       (stack, fileset, subNode, baseDir, 
addToFileSet);
!                       }
!               }
!               subNode = subNode->next;
        }
!       return stack;
! }
  
! /*
!  * Scan a directory start to get files to add to or remove from a fileset.
!  */
! static void ProcessDirStack(CSAntFileSet *fileset, CSAntDirStack *stack,
!                                                       int addToFileSet)
! {
!       RegexState state;
!       int haveRegex = 0;
!       char *currentDir;
!       const char *currentRegex;
!       CSAntDirStack *nextStack;
!       int recursive = 0;
!       CSAntDir *dir;
!       const char *filename;
!       char *pathname;
!       char *tempName;
  
        /* Pop items from the directory stack and scan them until
***************
*** 386,393 ****
--- 456,475 ----
                /* Pop the top-most stack item */
                currentDir = stack->dirName;
+               currentRegex = stack->regex;
                nextStack = stack->next;
                ILFree(stack);
                stack = nextStack;
  
+               /* Create a new regular expression block if necessary */
+               if(currentRegex)
+               {
+                       if(haveRegex)
+                       {
+                               IL_regfree(&state);
+                       }
+                       recursive = BuildIncludeRegex(currentRegex, &state);
+                       haveRegex = 1;
+               }
+ 
                /* Scan the directory for inclusions and exclusions */
                dir = CSAntDirOpen(currentDir, (const char *)0);
***************
*** 408,413 ****
                                if(recursive && IsDirectory(pathname))
                                {
!                                       /* Add to the fileset if we have a 
match */
!                                       if(MatchInclude(pathname + 
strlen(baseDir) + 1, &state))
                                        {
                                                tempName = 
ILDupString(pathname);
--- 490,495 ----
                                if(recursive && IsDirectory(pathname))
                                {
!                                       /* Add/Remove to the fileset if we have 
a match */
!                                       if(MatchInclude(pathname + 
strlen(currentDir) + 1, &state))
                                        {
                                                tempName = 
ILDupString(pathname);
***************
*** 416,420 ****
                                                        CSAntOutOfMemory();
                                                }
!                                               AddToFileSet(fileset, tempName);
                                        }
  
--- 498,510 ----
                                                        CSAntOutOfMemory();
                                                }
!                                               if(addToFileSet)
!                                               {
!                                                       AddToFileSet(fileset, 
tempName);
!                                               }
!                                               else
!                                               {
!                                                       
RemoveFromFileSet(fileset, tempName);
!                                                       ILFree(tempName);
!                                               }
                                        }
  
***************
*** 427,430 ****
--- 517,521 ----
                                        }
                                        nextStack->dirName = pathname;
+                                       nextStack->regex = 0;
                                        nextStack->next = stack;
                                        stack = nextStack;
***************
*** 432,439 ****
                                else
                                {
!                                       /* Add the pathname to the file set if 
it matches */
!                                       if(MatchInclude(pathname + 
strlen(baseDir) + 1, &state))
                                        {
!                                               AddToFileSet(fileset, pathname);
                                        }
                                        else
--- 523,538 ----
                                else
                                {
!                                       /* Add/Remove the pathname to the file 
set if it matches */
!                                       if(MatchInclude(pathname + 
strlen(currentDir) + 1, &state))
                                        {
!                                               if(addToFileSet)
!                                               {
!                                                       AddToFileSet(fileset, 
pathname);
!                                               }
!                                               else
!                                               {
!                                                       
RemoveFromFileSet(fileset, pathname);
!                                                       ILFree(pathname);
!                                               }
                                        }
                                        else
***************
*** 447,476 ****
  
                /* Free the current directory name, which we no longer require 
*/
!               if(currentDir != baseDir)
!               {
!                       ILFree(currentDir);
!               }
        }
  
        /* Free the regular expression state */
!       IL_regfree(&state);
  
!       /* Construct a new regular expression for the "excludes" list */
!       BuildIncludeRegex(node, "excludes", &state);
  
!       /* Remove pathnames from the fileset that match the regex */
!       outposn = 0;
!       for(posn = 0; posn < fileset->numFiles; ++posn)
        {
!               if(!MatchInclude(fileset->files[posn] + strlen(baseDir) + 1, 
&state))
!               {
!                       fileset->files[outposn++] = fileset->files[posn];
!               }
!               else
!               {
!                       ILFree(fileset->files[posn]);
!               }
        }
!       fileset->numFiles = outposn;
  
        /* Add simple files that are named using the <file> tag */
--- 546,613 ----
  
                /* Free the current directory name, which we no longer require 
*/
!               ILFree(currentDir);
        }
  
        /* Free the regular expression state */
!       if(haveRegex)
!       {
!               IL_regfree(&state);
!       }
! }
  
! CSAntFileSet *CSAntFileSetLoad(CSAntTask *task, const char *name,
!                                                          const char 
*configBaseDir)
! {
!       CSAntFileSet *fileset;
!       CSAntTask *node;
!       const char *arg;
!       const char *arg2;
!       char *baseDir;
!       char *pathname;
!       CSAntDirStack *stack;
  
!       /* Find the sub-node */
!       node = task->taskChildren;
!       while(node != 0 && strcmp(node->name, name) != 0)
        {
!               node = node->next;
!       }
!       if(!node)
!       {
!               return 0;
!       }
! 
!       /* Construct the starting base directory */
!       arg = CSAntTaskParam(node, "basedir");
!       if(arg)
!       {
!               baseDir = CSAntDirCombine(configBaseDir, arg);
!       }
!       else
!       {
!               baseDir = CSAntDirCombine(configBaseDir, 0);
!       }
! 
!       /* Construct the file set */
!       fileset = (CSAntFileSet *)ILMalloc(sizeof(CSAntFileSet));
!       if(!fileset)
!       {
!               CSAntOutOfMemory();
        }
!       fileset->numFiles = 0;
!       fileset->maxFiles = 0;
!       fileset->files = 0;
! 
!       /* Build the directory stack for the "includes" specification */
!       stack = DirStackAddIncludes(fileset, node, "includes", baseDir, 1);
! 
!       /* Process the directory stack for the "includes" specification */
!       ProcessDirStack(fileset, stack, 1);
! 
!       /* Build the directory stack for the "excludes" specification */
!       stack = DirStackAddIncludes(fileset, node, "excludes", baseDir, 0);
! 
!       /* Process the directory stack for the "excludes" specification */
!       ProcessDirStack(fileset, stack, 0);
  
        /* Add simple files that are named using the <file> tag */
***************
*** 500,506 ****
        /* We don't need the base directory any more */
        ILFree(baseDir);
- 
-       /* Free the regular expression state */
-       IL_regfree(&state);
  
        /* Done */
--- 637,640 ----





reply via email to

[Prev in Thread] Current Thread [Next in Thread]