aboutsummaryrefslogtreecommitdiff
path: root/src/reglinux.cpp
blob: 854d1b46c38032e9a400ee7d9840730f6e5fb88b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
    Copyright (C) 2014 BARRATERO Laurent                                   

    AeroUp is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by 
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    Aeroup 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. 
*/

/*
 *       Filename:  reglinux.cpp
 *
 *    Description:  Regex lib (linux version) 
 *
 *        Version:  0.2
 *        Created:  18/01/2014 01:16:04
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  BARATTERO Laurent, laurentba<at>larueluberlu.net
 *   Organization:  La rue Luberlu
 */
#include <stdlib.h>
#include "reglinux.hpp"

/*
 *       Class:  RegLinux
 *      Method:  RegLinux :: RegLinux
 * Description:  Constructor
 */
RegLinux::RegLinux()
{
    comp();
}


/*
 *--------------------------------------------------------------------------------------
 *       Class:  RegLinux
 *      Method:  RegLinux :: comp
 * Description:  Compile Regex
 *--------------------------------------------------------------------------------------
 */
    void
RegLinux::comp(void)
{
    int err = regcomp (reg, str_regex[0], REG_NOSUB | REG_EXTENDED);
    if (err != 0)
    {
       printf("ERROR");
       exit (EXIT_FAILURE);
    }

    for (int i = 0; i < REG_TAB_LEN  ; i++, preg++)
    {

       err = regcomp (preg, str_regex[i], REG_NOSUB | REG_EXTENDED);
       if (err != 0)
       {
           printf("ERROR");
           exit (EXIT_FAILURE);
       }
    }
}


/*
 *--------------------------------------------------------------------------------------
 *       Class:  RegLinux
 *      Method:  RegLinux :: isValidSyntax
 * Description:  Compile Regex
 *--------------------------------------------------------------------------------------
 */
  int
RegLinux::isValidSyntax ( std::string &rline )
{
  preg = &reg[0];
  int match;
  for (int i = 0; i < REG_TAB_LEN; i++, preg++)
  {
    match = regexec (preg, rline.c_str(), 0, NULL, 0);
    if (match == 0)
      return i;
  }
  return -1;
}		/* -----  end of method RegLinux::isValidSyntax  ----- */