static int choose(struct xml_node *st, struct xml_node *xt, struct xml_node *rt) { struct xml_node *s = NULL; struct xml_node *sc = NULL; int match = 0; /* first try matching 'when' statement */ while ((s = xml_child_each(st, s, XML_ELEMENT)) != NULL) { if (s->xn_namespace && strcmp(s->xn_namespace, "xsl") == 0){ if (strcmp(s->xn_name, "when")==0){ if (choose_test(s, xt, rt, &match) < 0) return -1; if (match) break; } } } if (!match){ /* no match above - find otherwise */ if ((s = xml_xpath(st, "/otherwise")) != NULL && s->xn_namespace && strcmp(s->xn_namespace, "xsl") == 0){ while ((sc = xml_child_each(s, sc, XML_ELEMENT)) != NULL) if (traverse(sc, xt, rt) < 0) return -1; } } return 0; }
/** Main program function @return EXIT_SUCCESS if successful, EXIT_ERROR otherwise */ int main(int argc, char * argv[]) { AK_PRO; // initialize critical sections dbmanFileLock = AK_init_critical_section(); printf("Init: %d, ready: %d", dbmanFileLock->init, dbmanFileLock->ready); AK_check_folder_blobs(); if((argc == 2) && !strcmp(argv[1], "help")) //if we write ./akdb test help, the help will pop up help(); else if((argc == 3) && !strcmp(argv[1], "test") && !strcmp(argv[2], "show")) //if we write ./akdb test test or show, the inputed will start and show show_test(); else { printf( "KALASHNIKOV DB - STARTING\n\n" ); AK_inflate_config(); printf("db_file: %s\n", DB_FILE); testMode = TEST_MODE_OFF; if( AK_init_disk_manager() == EXIT_SUCCESS ) { if( AK_memoman_init() == EXIT_SUCCESS ) { /* component test area --- begin */ if((argc == 2) && !strcmp(argv[1], "test")) { //if we write 2 arguments, choose test will start choose_test(); } else if((argc == 3) && !strcmp(argv[1], "test")) { // argc - number of arguments we inputin in the comand line, which we save in the argv [] // argv - [] pointer , 2D field in which we put and save arguments //if we input ./akdb test "test number", the test we inputed will start int ans; //we define an integer wich we use later ans = strtol(argv[2], NULL, 10)-1; //long int strtol(const char *str, char **endptr, int base) //str - string containing the representation of an integral numbe //endptr - reference to an object of type char* //base - which must be between 2 and 36 inclusive, or be the special value 0 //long int value - min 32 bit velicine, [−2147483647,+2147483647] AK_create_test_tables(); //when we start the inputed test, first the tables will be created set_catalog_constraints(); fun[ans].func(); //after the created tables the test will start, and call the function of the test from fun[], which we defined at the begining } /*component test area --- end */ if ( AK_flush_cache() == EXIT_SUCCESS ){ int ans; ans = strtol(argv[2], NULL, 10)-1; printf("\nTEST:--- %s --- ENDED!\n", fun[ans].name); //if the test started and ended with a success, we will be informed with this message and with the name printf( "\nEverything was fine!\nBye =)\n" ); /* For easyer debugging and GDB usage AK_create_test_tables(); AK_view_test(); */ // pthread_exit(NULL); AK_EPI; return ( EXIT_SUCCESS ); } } printf( "ERROR. Failed to initialize memory manager\n" ); AK_EPI; return ( EXIT_ERROR ); } printf( "ERROR. Failed to initialize disk manager\n" ); AK_EPI; int br = 3; printf("Izaberite broj testa koji želite pokrenuti: \n"); scanf("%i",&br); return ( EXIT_ERROR ); } // delete critical sections AK_destroy_critical_section(dbmanFileLock); AK_EPI; return(EXIT_SUCCESS); }//main