]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/bregex.c
Change copyright as per agreement with FSFE
[bacula/bacula] / bacula / src / lib / bregex.c
index dfa1c480021b98bb4a6e6606fcdbe68dd4f32a6e..994b0153bdf1602f18c2265911f074392e701665 100644 (file)
@@ -16,7 +16,6 @@
  *
  * This code draws many ideas from the regular expression packages by
  * Henry Spencer of the University of Toronto and Richard Stallman of
- * the Free Software Foundation.
  *
  * Emacs-specific code and syntax table code is almost directly borrowed
  * from GNU regexp.
  *    Eric Bollengier April 2007
  */
 /*
-   Bacula® - The Network Backup Solution
-
-   Copyright (C) 2006-2010 Free Software Foundation Europe e.V.
-
-   The main author of Bacula is Kern Sibbald, with contributions from
-   many others, a complete list can be found in the file AUTHORS.
-   This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation and included
-   in the file LICENSE.
-
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
-
-   Bacula® is a registered trademark of Kern Sibbald.
-   The licensor of Bacula is the Free Software Foundation Europe
-   (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
-   Switzerland, email:ftf@fsfeurope.org.
+   Bacula(R) - The Network Backup Solution
+
+   Copyright (C) 2000-2016 Kern Sibbald
+
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
+
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
+
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
 */
 
 
@@ -110,13 +100,13 @@ typedef union item_t {
    } cntr;
 } item_t;
 
-#define STACK_PAGE_SIZE 256
+#define B_STACK_PAGE_SIZE 256
 #define NUM_REGISTERS 256
 
 /* A 'page' of stack items. */
 
 typedef struct item_page_t {
-   item_t items[STACK_PAGE_SIZE];
+   item_t items[B_STACK_PAGE_SIZE];
    struct item_page_t *prev;
    struct item_page_t *next;
 } item_page_t;
@@ -154,8 +144,8 @@ typedef struct match_state {
    struct {
       /* index into the current page.  If index == 0 and you need
        * to pop an item, move to the previous page and set index
-       * = STACK_PAGE_SIZE - 1.  Otherwise decrement index to
-       * push a page. If index == STACK_PAGE_SIZE and you need
+       * = B_STACK_PAGE_SIZE - 1.  Otherwise decrement index to
+       * push a page. If index == B_STACK_PAGE_SIZE and you need
        * to push a page move to the next page and set index =
        * 0. If there is no new next page, allocate a new page
        * and link it in. Otherwise, increment index to push a
@@ -215,7 +205,7 @@ while (stack.index < 0) \
    if (stack.current->prev == NULL) \
            on_error; \
    stack.current = stack.current->prev; \
-   stack.index += STACK_PAGE_SIZE; \
+   stack.index += B_STACK_PAGE_SIZE; \
 }
 
 /* Store a pointer to the previous item on the stack. Used to pop an
@@ -227,7 +217,7 @@ if (stack.index == 0) \
         if (stack.current->prev == NULL) \
                 on_error; \
         stack.current = stack.current->prev; \
-        stack.index = STACK_PAGE_SIZE - 1; \
+        stack.index = B_STACK_PAGE_SIZE - 1; \
 } \
 else \
 { \
@@ -239,7 +229,7 @@ top = &(stack.current->items[stack.index])
  * on to the stack. */
 
 #define STACK_NEXT(stack, top, on_error) \
-if (stack.index == STACK_PAGE_SIZE) \
+if (stack.index == B_STACK_PAGE_SIZE) \
 { \
         if (stack.current->next == NULL) \
         { \
@@ -269,7 +259,7 @@ top = &(stack.current->items[stack.index++])
                 if (current->prev == NULL) \
                         on_error; \
                 current = current->prev; \
-                index += STACK_PAGE_SIZE; \
+                index += B_STACK_PAGE_SIZE; \
         } \
         top = &(current->items[index]); \
 }
@@ -282,7 +272,7 @@ if (stack.index == 0) \
 { \
         if (stack.current->prev == NULL) \
                 on_error; \
-        top = &(stack.current->prev->items[STACK_PAGE_SIZE - 1]); \
+        top = &(stack.current->prev->items[B_STACK_PAGE_SIZE - 1]); \
 } \
 else \
 { \
@@ -726,7 +716,7 @@ void re_compile_fastmap(regex_t * bufp)
    bufp->fastmap_accurate = 1;
 }
 
-/* 
+/*
  * star is coded as:
  * 1: failure_jump 2
  *    ... code for operand of star
@@ -1465,7 +1455,7 @@ int regcomp(regex_t * bufp, const char *regex, int cflags)
       char *p, *lcase = bstrdup(regex);
       for( p = lcase; *p ; p++) {
          *p = tolower(*p);
-      } 
+      }
       re_compile_pattern(bufp, (unsigned char *)lcase);
       bfree(lcase);
    } else {
@@ -1477,12 +1467,12 @@ int regcomp(regex_t * bufp, const char *regex, int cflags)
    return 0;
 }
 
-void re_registers_to_regmatch(regexp_registers_t old_regs, 
-                              regmatch_t pmatch[], 
+void re_registers_to_regmatch(regexp_registers_t old_regs,
+                              regmatch_t pmatch[],
                               size_t nmatch)
 {
    size_t i=0;
-   
+
    /* We have to set the last entry to -1 */
    nmatch = nmatch - 1;
    for (i=0; (i < nmatch) && (old_regs->start[i] > -1) ; i++) {
@@ -1491,7 +1481,7 @@ void re_registers_to_regmatch(regexp_registers_t old_regs,
    }
 
    pmatch[i].rm_eo = pmatch[i].rm_so = -1;
-} 
+}
 
 int regexec(regex_t * preg, const char *string, size_t nmatch,
             regmatch_t pmatch[], int eflags)
@@ -1500,10 +1490,10 @@ int regexec(regex_t * preg, const char *string, size_t nmatch,
    int len = strlen(string);
    struct re_registers regs;
    stat = re_search(preg, (unsigned char *)string, len, 0, len, &regs);
-   if (stat >= 0) {
+   if (stat >= 0 && nmatch > 0) {
       re_registers_to_regmatch(&regs, pmatch, nmatch);
    }
-   /* stat is the start position in the string base 0 where       
+   /* stat is the start position in the string base 0 where
     *  the pattern was found or negative if not found.
     */
    return stat < 0 ? -1 : 0;