void test_reshape_algorithm() {

	int num1 = tidfa_num;
	
	reshape();
	
	int num2 = tidfa_num;
	
	printf("%d new states are needed!\n", num2 - num1);

	int p = 0;
	int i = 0;
	bool http_accept = false;
	for (; i < strlen(indata); i++) {
		p = tidfa_newtr[p][indata[i]];
		if (new_tidfa_accept[p] != -1) {
			http_accept = true;
			break;
		}
	}
	if (http_accept) i++;
	printf("Tidfa accept state = %d\n", p);
	printf("Character consump = %d\n", i);
	
	tsNode *t = tidfaState[getfa(p)];
	while(t != NULL) {
		if (t->tidfa_q == p) break;
		t = t->next;
	}

	matches = t->matches;
	run_string(indata + i, t->x);

	printState(t->x);
	printf("matches=%d\n", matches);
	
	printf("----------------run all character all once---------------\n");
	state st;
	matches = 0;
	st.flow_data_length = strlen(indata);
	st.flow_data = (const u_char*)indata;
  	while (st.fdpos < st.flow_data_length && st.q != NULL)
		CALL_MEMBER_FN(st, st.q)();
	printState(st);
	printf("matches=%d\n", matches);

	printf("---------------run_fs function---------\n");
	matches = 0;
	state st1;
	for (int j = 0; j < strlen(indata); j++)
		run_fs(indata[j], st1);
	printState(st1);
	
	printf("matches=%d\n", matches);
	
	return ;
}
void test_subroutine_dfa_algorithm() {
	int num1 = tidfa_num;
	get_subroutine_dfa();
	int num2 = tidfa_num;
	printf("%d new states are needed!\n", num2 - num1);
	
	
		int p = 0;
	int i = 0;
	bool http_accept = false;
	state midst;
	int mid_matches = 0;
	
	for (; i < strlen(indata); i++) {
		char c = indata[i];
		if (tran_edge[p][c] != NULL) {
			mid_matches += tran_edge[p][c]->matches;
			set_result(tran_edge[p][c]->st, midst);
		}
		
		p = tidfa_newtr[p][c];
		
		if (new_tidfa_accept[p] != -1) {
			http_accept = true;
			break;
		}
	}
	if (http_accept) i++;
	printf("Tidfa accept state = %d\n", p);
	printf("Character consump = %d\n", i);
	
	tsNode *t = tidfaState[getfa(p)];
	while(t != NULL) {
		if (t->tidfa_q == p) break;
		t = t->next;
	}
	set_result(midst, t->x);
	matches = t->matches + mid_matches;
	run_string(indata + i, t->x);

	printState(t->x);
	printf("matches=%d\n", matches);
	
	printf("----------------run all character all once---------------\n");
	state st;
	matches = 0;
	st.flow_data_length = strlen(indata);
	st.flow_data = (const u_char*)indata;
  	while (st.fdpos < st.flow_data_length && st.q != NULL)
		CALL_MEMBER_FN(st, st.q)();
	printState(st);
	printf("matches=%d\n", matches);
	
}
Example #3
0
/*
 * Main entry point of the program.
 *
 * @param argc The amount of arguments given.
 * @param argv The array with arguments.
 */
int main(int argc, char *argv[]) {
	int c;
	int i = 1;
	int option_index = 0;
	
	while (1) {
		option_index = 0;
		c = getopt_long (argc, argv, "he:",
                         long_options, &option_index);
		if (c == -1)
			break;
        
		switch (c) {
            case 0:
                if (long_options[option_index].flag != 0)
                    break;
                break;
            case 'h':
                print_usage();
                return EXIT_SUCCESS;
            case 'e':
                return run_string((char *) optarg);
            case '?':
                print_usage();
                return EXIT_FAILURE;
            default:
                abort();
		}
	}
	if (argc > 1) {
		while (i < argc)
			if (run_file(fopen(argv[i++], "r")) == EXIT_FAILURE)
				fprintf(stderr, "error: failed to read file %s\n", argv[i - 1]);
            else
                printf("\n");
	} else {
		// checks if someone is piping code or just calling it the normal way.
		if (isatty(fileno(stdin))) {
			run_interactive_console();
            printf("\n");
		} else {
			if (run_file(stdin) == EXIT_FAILURE) 
				fprintf(stderr, "error: failed to read from stdin\n");
		}
	}
    
	return EXIT_SUCCESS;
}