Exemplo n.º 1
0
int main(int argc, char *argv[])
{
    info("testing field functions");
    if (test_field() < 0)
        return 1;

    info("testing mode functions");
    if (test_mode() < 0)
        return 1;

    info("testing regime functions");
    if (test_regime() < 0)
        return 1;

    info("testing program functions");
    if (test_program() < 0)
        return 1;

    info("testing learning_data functions");
    if (test_learning_data() < 0)
        return 1;

    printf("completed with %d failure(s) and %d error(s)\n",
           num_failures, num_errors);

    return num_failures;
}
Exemplo n.º 2
0
int main(void) {
  test_field();
  test_schedule_get();
  test_schedule_set();
  test_schedule_valid();
  done_testing();
  return 0;
}
Exemplo n.º 3
0
// handles postfix use by using recursive calls to _search
int Regexpr::handle_postfix(char kind)
{
  char *firstmatch,*oldlineptr,*oldpatptr,*lastlineptr;
  char *begin,*eo_parenthesis,*tmp;
  char mc,c;
  int n,i,err,old_ignore_case;

    if (kind == ELEM_BRACKET) {
        begin = patptr;
        if (!scan_behind(']'))  // go to next ] within pattern string
            return -1;
    }
    else if (kind == ELEM_PARENTHESIS) {
        begin = patptr;
        if ((eo_parenthesis = scan_behind(')')) == 0)
            return -1;
    }

    // Is postfix symbol (?+*) ?
    if ( ((mc = *patptr) == '?') || (mc == '+') || (mc == '*') ) {
        oldlineptr = lineptr;
        oldpatptr = ++patptr;   // skip postfix symbol
        lastlineptr = ((char*)NULLPTR);

        while (1) {
            old_ignore_case = ignore_case;
            err = _search(&firstmatch);
            ignore_case = old_ignore_case;
            if (err == 2) { // pattern element found

                n = firstmatch-oldlineptr;  // number of untested chars
                tmp = lineptr;

                switch (kind) { // for each joker do something special
                    case ELEM_POINT:
                        break;
                    case ELEM_BRACKET:
                        for (i = 0; i < n; i++) {
                            patptr = begin;
                            lineptr = oldlineptr+i;
                            if (test_field() <= 0) { // char doesnt match!
take_prev:
                                if (!lastlineptr) { // no prev match!!
                                    lineptr = oldlineptr;
                                    return 0;
                                }
                                else {
                                    lineptr = lastlineptr; // take prev match
                                    return 2;
                                }
                            }
                        }
                        break;
                    case ELEM_PARENTHESIS:
                        lineptr = oldlineptr;
                        n = 0;
                        while (lineptr < firstmatch) {
                            patptr = begin;
                            if (test_parenthesis_fixed(eo_parenthesis) == -1)
                                goto take_prev;
                            if (lineptr > firstmatch)
                                goto cont_search;
                            n++;
                        }
                        break;
                    default:    // character
                        for (lineptr = oldlineptr, i = 0; i < n; i++) {
                            if (kind != next_line_elem())
                                goto take_prev;  // char doesnt match
                        }
                        break;
                }
                lineptr = tmp;

                if (mc == '+' && !n) {  // n > 0 is ok
                    if (*firstmatch == eol) // we already reached eol
                        return -1;          // thus no success possible
                    goto cont_search;
                }
                else if (mc == '?' && n > 1)    // n = 0,1 is ok
                    goto take_prev;

                // *, + (n > 0), ? (n == 0,1)
                if (*firstmatch == eol) // test if eol reached
                    return 2;   // and if so indicate success

                // use current match as prev and continue searching
                lastlineptr = lineptr;
cont_search:
                lineptr = firstmatch+1; // we must look for biggest
                                        // possible match!!
                patptr = oldpatptr;
            }
            else // pattern didnt match
                if (!lastlineptr) { // no prev match!!
                    lineptr = oldlineptr;
                    return -1;
                }
                else {
                    lineptr = lastlineptr;  // take prev match
                    return 2;
                }
        } // end of while (1)

    } // end of if (is_joker
    else    // without postfix char
        switch (kind) {
            case ELEM_POINT:
                return ((c = next_line_elem()) == eol) ? 0 : 1;
            case ELEM_BRACKET:
                patptr = begin;
                return test_field();
            case ELEM_PARENTHESIS:
                patptr = begin;
                return test_parenthesis(eo_parenthesis);
        }

		return 0;
}