int parenthesis = 0;
int prts_size = 0;
int max_prts_size = 0;
-
+
char *pt;
char *new_str;
char *new_str_free = NULL;
-
+
/* Checking for references not initialized */
if(reg == NULL)
{
return(0);
}
-
+
/* Initializing OSRegex structure */
reg->error = 0;
reg->error = OS_REGEX_MAXSIZE;
goto compile_error;
}
-
-
+
+
/* Duping the pattern for our internal work */
new_str = strdup(pattern);
if(!new_str)
}
new_str_free = new_str;
pt = new_str;
-
-
+
+
/* Getting the number of sub patterns */
do
{
{
pt++;
if(!((*pt == 'w') ||
- (*pt == 'W') ||
- (*pt == 's') ||
- (*pt == 'S') ||
- (*pt == 'd') ||
- (*pt == 'D') ||
- (*pt == '.') ||
+ (*pt == 'W') ||
+ (*pt == 's') ||
+ (*pt == 'S') ||
+ (*pt == 'd') ||
+ (*pt == 'D') ||
+ (*pt == '.') ||
(*pt == '(') ||
(*pt == ')') ||
(*pt == 'p') ||
parenthesis--;
prts_size++;
}
-
+
/* We only allow one level of parenthesis */
if(parenthesis != 0 && parenthesis != 1)
{
reg->error = OS_REGEX_BADPARENTHESIS;
goto compile_error;
}
-
- /* The pattern must be always lower case if
+
+ /* The pattern must be always lower case if
* case sensitive is set
*/
if(!(flags & OS_CASE_SENSITIVE))
{
*pt = charmap[(uchar)*pt];
}
-
+
if(*pt == OR)
{
/* Each sub pattern must be closed on parenthesis */
}
count++;
}
- pt++;
+ pt++;
}while(*pt != '\0');
-
+
/* After the whole pattern is read, the parenthesis must all be closed */
if(parenthesis != 0)
reg->error = OS_REGEX_BADPARENTHESIS;
goto compile_error;
}
-
-
+
+
/* Allocating the memory for the sub patterns */
count++;
reg->patterns = calloc(count +1, sizeof(char *));
reg->flags = calloc(count +1, sizeof(int));
-
-
+
+
/* For the substrings */
if((prts_size > 0) && (flags & OS_RETURN_SUBSTRING))
{
goto compile_error;
}
}
-
-
+
+
/* Memory allocation error check */
if(!reg->patterns || !reg->flags)
{
}
}
i = 0;
-
-
+
+
/* Reassigning pt to the beginning of the string */
pt = new_str;
-
+
/* Getting the sub patterns */
do
{
{
max_prts_size = prts_size;
}
-
+
/* Allocating the memory */
reg->prts_closure[i] = calloc(prts_size + 1, sizeof(char *));
reg->prts_str[i] = calloc(prts_size + 1, sizeof(char *));
reg->error = OS_REGEX_OUTOFMEMORY;
goto compile_error;
}
-
+
/* Success return */
free(new_str_free);
return(1);
-
-
+
+
/* Error handling */
compile_error:
-
+
if(new_str_free)
{
free(new_str_free);
}
-
+
OSRegex_FreePattern(reg);
return(0);