- /* 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';
-
- /* If string starts with ^, set the BEGIN SET flag */
- if(*new_str == BEGINREGEX)
- {
- new_str++;
- reg->flags[i]|=BEGIN_SET;
- }
-
- /* If string ends with $, set the END_SET flag */
- if(*(pt-1) == ENDREGEX)
- {
- *(pt-1) = '\0';
- reg->flags[i]|=END_SET;
- }
-
- reg->patterns[i] = strdup(new_str);
-
- if(!reg->patterns[i])
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
-
- }
-
-
- /* Setting the parenthesis closures */
- /* The parenthesis closure if set */
- if(reg->prts_closure)
- {
- unsigned tmp_int = 0;
- char *tmp_str;
-
-
- /* search the whole pattern for parenthesis */
- prts_size = 0;
-
- /* First loop we get the number of parenthesis.
- * We allocate the memory and loop again setting
- * the parenthesis closures.
- */
- tmp_str = reg->patterns[i];
- while(*tmp_str != '\0')
- {
- if(prts(*tmp_str))
- {
- prts_size++;
- }
- tmp_str++;
- }
-
- /* Getting the maximum number of parenthesis for
- * all sub strings. We need that to set up the maximum
- * number of substrings to be returned.
- */
- if(max_prts_size < prts_size)
- {
- max_prts_size = prts_size;
- }
-
- /* Allocating the memory */
- reg->prts_closure[i] = (const char **) calloc(prts_size + 1, sizeof(const char *));
- reg->prts_str[i] = (const char **) calloc(prts_size + 1, sizeof(const char *));
- if((reg->prts_closure[i] == NULL)||(reg->prts_str[i] == NULL))
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
-
- /* Next loop to set the closures */
- tmp_str = reg->patterns[i];
- while(*tmp_str != '\0')
- {
- if(prts(*tmp_str))
- {
- if(tmp_int >= prts_size)
- {
- reg->error = OS_REGEX_BADPARENTHESIS;
- goto compile_error;
- }
-
- /* Setting to the pointer to the string */
- reg->prts_closure[i][tmp_int] = tmp_str;
- reg->prts_str[i][tmp_int] = NULL;
-
- tmp_int++;
- }
-
- tmp_str++;
- }
- }
-
-
- if(end_of_string)
- {
- break;
- }
-
- new_str = ++pt;
- i++;
- continue;
- }
- pt++;
-
- }while(!end_of_string);
-
- /* Allocating sub string for the maximum number of parenthesis */
- reg->sub_strings = (char **) calloc(max_prts_size + 1, sizeof(char *));
- if(reg->sub_strings == NULL)
- {
- reg->error = OS_REGEX_OUTOFMEMORY;
- goto compile_error;
- }
-
- /* Success return */
- free(new_str_free);
- return(1);