]> git.sur5r.net Git - bacula/bacula/blob - bacula/patches/testing/breg.h
ebl update
[bacula/bacula] / bacula / patches / testing / breg.h
1 /*
2  * Bacula BREGEXP Structure definition for FileDaemon
3  * Eric Bollengier Mars 2007
4  * Version $Id$
5  */
6 /*
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2006-2006 Free Software Foundation Europe e.V.
10
11    The main author of Bacula is Kern Sibbald, with contributions from
12    many others, a complete list can be found in the file AUTHORS.
13    This program is Free Software; you can redistribute it and/or
14    modify it under the terms of version two of the GNU General Public
15    License as published by the Free Software Foundation plus additions
16    that are listed in the file LICENSE.
17
18    This program is distributed in the hope that it will be useful, but
19    WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public License
24    along with this program; if not, write to the Free Software
25    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26    02110-1301, USA.
27
28    Bacula® is a registered trademark of John Walker.
29    The licensor of Bacula is the Free Software Foundation Europe
30    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
31    Switzerland, email:ftf@fsfeurope.org.
32 */
33
34
35 #ifndef __BREG_H_
36 #define __BREG_H_ 1
37
38
39 #ifndef HAVE_REGEX_H
40 #include "bregex.h"
41 #else
42 #include <regex.h>
43 #endif
44
45 /* Usage:
46  *
47  * #include "lib/breg.h"
48  * 
49  * BREGEXP *breg = new_bregexp("!/prod!/test!");
50  * char *filename = breg->replace("/prod/data.dat");
51  *   or
52  * filename = breg->result;
53  * free_bregexp(breg);
54  */
55
56 /*
57  * Structure for BREGEXP ressource
58  */
59 class BREGEXP {
60 public:
61    POOLMEM *result;             /* match result */
62    char *replace(const char *fname);
63    void debug();
64
65    /* private */
66    POOLMEM *expr;               /* search epression */
67    POOLMEM *subst;              /* substitution */
68    regex_t preg;                /* regex_t result of regcomp() */
69    
70    int nmatch;
71    
72    char *return_fname(const char *fname, int len); /* return fname as result */
73    char *edit_subst(const char *fname, struct re_registers *regs);
74    int compute_dest_len(const char *fname, struct re_registers *regs);
75    bool extract_regexp(const char *motif);
76 };
77
78 /* create new BREGEXP and compile regex_t */
79 BREGEXP *new_bregexp(const char *motif); 
80
81 /* launch each bregexp on filename */
82 int run_bregexp(alist *bregexps, const char *fname); 
83
84 /* free BREGEXP (and all POOLMEM) */
85 void free_bregexp(BREGEXP *script);
86
87 /* foreach_alist free RUNSCRIPT */
88 void free_bregexps(alist *bregexps); /* you have to free alist */
89
90 #endif /* __BREG_H_ */