-
-
- /* Duping the pattern for our internal work */
- new_str = strdup(pattern);
- if(!new_str)
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
- new_str_free = new_str;
- pt = new_str;
-
-
-
- /* Getting the number of sub patterns */
- while(*pt != '\0')
- {
- /* The pattern must be always lower case if
- * case sensitive is set
- */
- if(!(flags & OS_CASE_SENSITIVE))
- {
- *pt = charmap[(uchar)*pt];
- }
-
- /* Number of sub patterns */
- if(*pt == OR)
- {
- count++;
- }
- else if(*pt == -29)
- {
- usstrstr = 1;
- }
- pt++;
- }
-
-
- /* For the last pattern */
- count++;
- reg->patterns = calloc(count +1, sizeof(char *));
- reg->size = calloc(count +1, sizeof(int));
- reg->match_fp = calloc(count +1, sizeof(void *));
-
-
- /* Memory allocation error check */
- if(!reg->patterns || !reg->size || !reg->match_fp)
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
-
-
- /* Initializing each sub pattern */
- for(i = 0; i<=count; i++)
- {
- reg->patterns[i] = NULL;
- reg->match_fp[i] = NULL;
- reg->size[i] = 0;
- }
- i = 0;
-
-
- /* Reassigning pt to the beginning of the string */
- pt = new_str;
-
-
- /* Getting the sub patterns */
- do
- {
- if((*pt == OR) || (*pt == '\0'))
- {
- if(*pt == '\0')
- {
- end_of_string = 1;
- }
-
- *pt = '\0';
-
- /* Dupping the string */
- if(*new_str == BEGINREGEX)
- reg->patterns[i] = strdup(new_str +1);
- else
- reg->patterns[i] = strdup(new_str);
-
- /* Memory error */
- if(!reg->patterns[i])
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
-