Exemple #1
0
 int main(int argc, char *argv[]) {


     bool all_pairs = false;
     if(argc > 2) { std::cerr << "Unknown arguments passed in. Pass flag: " <<
         "'-all-pairs' if you want the program to list all pairs of primes."
             << std::endl;
         return 0;
     }

     if(argc == 2) {
         if(strcmp(*(argv + 1), "-all-pairs") == 0) { all_pairs = true; }
         else { std::cerr << "Unknown arguments passed in. Pass flag: " <<
         "'-all-pairs' if you want the program to list all pairs of primes."
             << std::endl;
         return 0;
         }
     }
         
    int input =  user_input();
    std::vector<int> mod_s = modified_sieve(input);
    std::vector<TwoPrimes> tpv = find_goldbachs(mod_s, input, all_pairs);

    std::cout << "found " << tpv.size() << " pairs:" << std::endl;
    for(auto tp : tpv) {
    int p1=tp.get_prime_1();
    int p2=tp.get_prime_2();
    std::cout << p1 << " " << p2 << std::endl;
    }
    return 0;
}
int main(int argc, char *argv[]) {
    int c_num;
    char buf[BUFSIZE];
    command com[MAXCOMMAND];

    while (1) {
        /*初期化*/
        c_num = 0;
        memset(buf, 0, sizeof(buf));
        memset(com, 0, sizeof(com));
        mode = NORMAL;

        print_prompt(stdout);
        user_input(buf, stdin);
        if (is_empty(buf) == -1) {
            continue;
        } else 
        c_num = parse_user_input(buf, com);
        if (mode == PIPE) {
            exec_command_use_pipe(com, c_num);
        } else {
            exec_command(com, c_num);
        }
    }

    exit(EXIT_SUCCESS);
}
Exemple #3
0
/* program execution begins here
 *
 */
int main(int argc, char* argv[]) {
    if( argc != 2 ) {
        fprintf(stderr, "ERROR: useage is ./ticker FILENAME\n");
        return -1;
    }
    struct tree* tree, *tempC = NULL, *tempT = malloc(sizeof(struct tree));
    if (!tempT) {
        fprintf(stderr, "ERROR: could not allocate space.\n");
        return -1;
    }
    memset(tempT, 0, sizeof(struct tree));
    tree = read_file(argv[1]);
    if (!tree) { // allocation or read failed somehow
        return -1;
    }
    user_input(tree);
    while( (tempC = pop_tree(tree)) && tempC != tree) {
        tree_insert(tempT, tempC->data, check_value);
        free(tempC);
    }
    tree_insert(tempT, tree->data, check_value);
    print_tree(tempT);
    free(tree);
    tree_destroy(tempT);

}
Exemple #4
0
struct Scanner *
new_scanner(void) {
    struct Scanner * scanner = malloc(sizeof(struct Scanner));
    char * input = user_input();
    scanner->input = input;
    scanner->forword = input;
    scanner->lexeme = input;
    return scanner;
}
//user input
//prompts the user for a 7 letter length string, if not 7 length or not all chars repromts
//post: returns a 7 letter length string
string texttwist::user_input(){
    cout <<"Please input 7 letters of texttwist game: ";
    string input = "";
    getline(cin, input);
    if (input.length() != 7){
        cout << "Number of characters invalid, please try again"<< endl;
        return user_input();
    }
    for (size_t i = 0; i<7; i++){
        if (!isalpha(input[i])){
            cout << "Not valid character, please try again" <<endl;
            return user_input();
        }
        input[i] = tolower(input[i]);
    }
    return input;
    
}
Exemple #6
0
char menu()
{
	char menu[4];
	menu_arrange(menu);
	do
	{
		print_menu(menu);
		user_input(menu);
		system("cls");
	}while(-1);

}
Exemple #7
0
void start_lines()
{
    std::string repeat;
    do
    {
        UserInput in = line_user_input();
        lineb(get_int("x0", in), get_int("y0", in), get_int("xn", in),
              get_int("yn", in), get_uint("color", in, 16),
              get_int("delay", in), get_int("scale", in), get_int("step", in));

        user_input("What more (y/n): ", "repeat", in);
        repeat = in["repeat"]; 
    }
    while(repeat == "y");
}
Exemple #8
0
static void username_callback(const char *value, gpointer user_data)
{
	struct wispr_session *wispr = user_data;

	g_free(wispr->username);
	wispr->username = g_strdup(value);

	if (wispr->password == NULL) {
		user_input("Password", TRUE, password_callback, wispr);
		return;
	}

	printf("\n");

	execute_login(wispr);
}
Exemple #9
0
/**
 * This will usually process all the input that the KUI has.
 *
 * However, it's possible that one of the keys the user sends to CGDB 
 * switches the state of CGDB in such a way, that CGDB has to do some I/O
 * with GDB before the keys can continue to be sent to CGDB. For this reason,
 * this loop can return before all the KUI's data has been used, in order to
 * give the main loop a chance to run a GDB command.
 *
 * \return
 * 0 on success or -1 on error
 */
static int user_input_loop()
{
    do {
        /* There are reasons that CGDB should wait to get more info from the kui.
         * See the documentation for kui_input_acceptable */
        if (!kui_input_acceptable)
            return 0;

        if (user_input() == -1) {
            logger_write_pos(logger, __FILE__, __LINE__,
                    "user_input_loop failed");
            return -1;
        }
    } while (kui_manager_cangetkey(kui_ctx));

    return 0;
}
Exemple #10
0
// 1st argument is number of processors
// 2nd argument is Base Case dimension (i.e. 4 => 4x4 is base case)
// 3rd argument is the input file path
int main(int argc, char *argv[]) {
    int nworkers = 
#if defined __cilkplusplus
        cilk::current_worker_count();
#else
    4;
#endif

    if (argc > 1) {
        nworkers = atoi(argv[1]);
    }

    if (argc > 3) {
        freopen(argv[3], "r", stdin);
    }

    user_input();

    base_dimension = 16;
    if (argc > 2) {
        base_dimension = atoi(argv[2]);
    }
    if (base_dimension < 1 || base_dimension > len) {
        base_dimension = 16;
    }

    // printf("Worker Count: %d\n", nworkers);

#if defined CILKVIEWPLOT
    cilk::cilkview cv;
    cv.start();
#endif // CILKVIEWPLOT

    int answer = solve(X, Y, len, nworkers);

#if defined CILKVIEWPLOT
    cv.stop();
    cv.dump("agc");
#endif // CILKVIEWPLOT

    printf("%d\n", answer);

    std::pair<std::string, std::string> rc = reconstruct(X-1, Y-1, len);
    printf("%s\n%s\n", rc.first.c_str(), rc.second.c_str());
}
Exemple #11
0
void start_circles()
{
    std::string repeat;
    do
    {
        UserInput in;
        user_input("Enter xc: ", "xc", in);
        user_input("Enter yc: ", "yc", in);
        user_input("Enter R: ", "R", in);
        user_input("Enter color (hex): ", "color", in);
        user_input("Enter pixel size: ", "scale", in);
        user_input("Enter delay animation: ", "delay", in);
        user_input("Exter simple circle or michener circle (s/m): ",
                   "circle", in);

        if (in["circle"] == "s")
        {
            simple_circle(get_int("xc", in),
                          get_int("yc", in),
                          get_int("R", in),
                          get_uint("color", in, 16),
                          get_int("delay", in),
                          get_int("scale", in)
                         );
        }

        if (in["circle"] == "m")
        {
            michener_circle(get_int("xc", in),
                            get_int("yc", in),
                            get_int("R", in),
                            get_uint("color", in, 16),
                            get_int("delay", in),
                            get_int("scale", in)
                           );
        }

        user_input("What more (y/n): ", "repeat", in);
        repeat = in["repeat"]; 
    }
    while(repeat == "y");
}
Exemple #12
0
int main(int argc, char *argv[]) {
    /*
     * We save 2 hash_table: phone_hash_table and name_hash_table,
     * every time user input new entry, we save it in either
     * hash_table, so that we can search it by name, or search it
     * by phone_num.
     * */
    struct phone_hash_table *phone_table = init_phone_hash_table();
    struct name_hash_table *name_table = init_name_hash_table();
    struct data * entry;
    while (1) {
        entry = user_input();
        if (entry == NULL) {
            break;
        }
        insert_into_phone_hash_table(phone_table, entry);
        insert_into_name_hash_table(name_table, entry);
    }
    int option;
    while (1) {
        struct data *entry;
        printf("option:1 for exit, 2 for search by phone, 3 for search by name\n");
        scanf("%d",&option);
        switch (option) {
        case 1 :
            exit(0);
        case 2 :
            entry = search_by_phone(phone_table);
            break;
        case 3 :
            entry = search_by_name(name_table);
            break;
        }
        if (entry != NULL) {
            print_data(entry);
        } else {
            printf("Not found!\n");
        }
    }
}
Exemple #13
0
int main(int argc, char *argv[])
{
    do
    {
        UserInput user_in;
        user_input("Choose program (lines (l), circles (c), exit (x): ",
                   "choice", user_in);

        std::string choice = user_in["choice"];

        fill(0xFFFFFFFF);
        if (choice == "lines" || choice == "l")
            start_lines();
        if (choice == "circles" || choice == "c")
            start_circles();
//         if (choice == "fill" || choice == "f")
//             simple_circle(200, 200, 20, 0, 3);
//             simple_circle(250, 250, 20, 0, 3);
// 
//             start_fill();
        if (choice == "exit" || choice == "x")
            break;
    }
    while(true);

//     bias
//     int x0 = 300;
//     int y0 = 300;
//     int xn = 100;
//     int yn = 100 - 18 * 3;
//     int color = 0xF0F;
//     int delay = 20;
//     int scale = 5;
//     int step = 6;
//     lineb(x0, y0, xn, yn, color, delay, scale, step);

    free();
    return 0;
}
Exemple #14
0
void own(char* ifname) {
	int rd;
	fd_set fds;
	struct timeval tv;
	int dlt = DLT_IEEE802_11_RADIO;

	hopfreq = 1000;

	setup_if(ifname);
	open_bpf(ifname, dlt);

	while(1) {
		// XXX innefficient all of this...
		if (!chaninfo.locked)
			chanhop(&tv);
		else {
			tv.tv_sec = 1;
			tv.tv_usec = 0;
		}	

		// especially this...
		check_seen(&tv);	

		FD_ZERO(&fds);
		FD_SET(0, &fds);
		FD_SET(bpf_s, &fds);

		rd = select(bpf_s+1, &fds,NULL , NULL, &tv);
		if (rd == -1)
			die(1, "select()");
		if (FD_ISSET(0, &fds))
			user_input();
		if (FD_ISSET(bpf_s, &fds))
			bpf_input();
	}
}
Exemple #15
0
void start_fill()
{
    std::string repeat;
    do
    {
        UserInput in;
        user_input("Enter x: ", "x", in);
        user_input("Enter y: ", "y", in);
        user_input("Enter color (hex): ", "color", in);
        user_input("Enter delay animation: ", "delay", in);
        user_input("Enter scale: ", "scale", in);
        floodfill(get_int("x", in), get_int("y", in),
                  0xFFF,
                  get_uint("color", in, 16),
                  get_int("delay", in),
                  get_int("scale", in));

        user_input("What more (y/n): ", "repeat", in);
        repeat = in["repeat"]; 
    }
    while(repeat == "y");
}
Exemple #16
0
int main(int argc, char **argv)
{

    struct GModule *module;

    /* initialize the GRASS GIS system */
    G_gisinit(argv[0]);

    /* allocate space for the choice data structure */
    choice = (struct CHOICE *)G_calloc(1, sizeof(struct CHOICE));

    module = G_define_module();
    module->keywords = _("raster, landscape structure analysis, patch index");
    module->description =
	_("Contains a set of measures for attributes, diversity, texture, "
	  "juxtaposition, and edge.");

    /* call user_input to read in the parameters */
    user_input(argc, argv);

    /* display the parameter choices */
    fprintf(stdout, "\nPARAMETER CHOICES:\n");
    fprintf(stdout, "\tMAP:\t  %s\n", choice->fn);
    if (choice->wrum == 'r')
	fprintf(stdout, "\tREGION:\t  %s\n", choice->reg);

    fprintf(stdout, "\tSAMPLE:");
    if (choice->wrum == 'w')
	fprintf(stdout, "\t  whole map    \n");
    if (choice->wrum == 'm')
	fprintf(stdout, "\t  moving window\n");
    if (choice->wrum == 'u')
	fprintf(stdout, "\t  units        \n");
    if (choice->wrum == 'r')
	fprintf(stdout, "\t  regions      \n");

    if (choice->edgemap || choice->units || choice->z)
	fprintf(stdout, "\tOUTPUT MAPS:\n");
    if (choice->edgemap)
	fprintf(stdout, "\t\t  edge\n");
    if (choice->units)
	fprintf(stdout, "\t\t  units_x\n");
    if (choice->z)
	fprintf(stdout, "\t\t  zscores\n");

    if (choice->att[0]) {
	fprintf(stdout, "\tATTRIBUTE MEASURES:\n");
	if (choice->att[1])
	    fprintf(stdout, "\t\t  mean pixel attribute\n");
	if (choice->att[2])
	    fprintf(stdout, "\t\t  st. dev. pixel attribute\n");
	if (choice->att[3])
	    fprintf(stdout, "\t\t  minimum pixel attribute\n");
	if (choice->att[4])
	    fprintf(stdout, "\t\t  maximum pixel attribute\n");
    }

    if (choice->div[0]) {
	fprintf(stdout, "\tDIVERSITY MEASURES:\n");
	if (choice->div[1])
	    fprintf(stdout, "\t\t  richness\n");
	if (choice->div[2])
	    fprintf(stdout, "\t\t  Shannon\n");
	if (choice->div[3])
	    fprintf(stdout, "\t\t  dominance\n");
	if (choice->div[4])
	    fprintf(stdout, "\t\t  inverse Simpson\n");
    }

    if (choice->te2[0]) {
	fprintf(stdout, "\tTEXTURE METHOD:\n");
	if (choice->tex == 1)
	    fprintf(stdout, "\t\t  2N-H\n");
	else if (choice->tex == 2)
	    fprintf(stdout, "\t\t  2N-45\n");
	else if (choice->tex == 3)
	    fprintf(stdout, "\t\t  2N-V\n");
	else if (choice->tex == 4)
	    fprintf(stdout, "\t\t  2N-135\n");
	else if (choice->tex == 5)
	    fprintf(stdout, "\t\t  4N-HV\n");
	else if (choice->tex == 6)
	    fprintf(stdout, "\t\t  4N-DIAG\n");
	else if (choice->tex == 7)
	    fprintf(stdout, "\t\t  8N\n");
	fprintf(stdout, "\tTEXTURE MEASURES:\n");
	if (choice->te2[1])
	    fprintf(stdout, "\t\t  contagion\n");
	if (choice->te2[2])
	    fprintf(stdout, "\t\t  ang. sec. mom.\n");
	if (choice->te2[3])
	    fprintf(stdout, "\t\t  inv. diff. mom.\n");
	if (choice->te2[4])
	    fprintf(stdout, "\t\t  entropy\n");
	if (choice->te2[5])
	    fprintf(stdout, "\t\t  contrast\n");
    }

    if (choice->jux[0]) {
	fprintf(stdout, "\tJUXTAPOSITION MEASURES:\n");
	if (choice->jux[1])
	    fprintf(stdout, "\t\t  mean juxtaposition\n");
	if (choice->jux[2])
	    fprintf(stdout, "\t\t  standard deviation of juxtaposition\n");
    }

    if (choice->edg[0]) {
	fprintf(stdout, "\tEDGE MEASURES:\n");
	if (choice->edg[1])
	    fprintf(stdout, "\t\t  sum of edges\n");
	if (choice->edg[2])
	    fprintf(stdout, "\t\t  sum of edges by type\n");
    }

    /* if not moving window, setup the
       r.le.out subdirectory */

    if (choice->wrum != 'm')
	G_mkdir("r.le.out");

    texture_fore();
    G_free(choice);

    return (EXIT_SUCCESS);
}
Exemple #17
0
static gboolean wispr_result(GWebResult *result, gpointer user_data)
{
	struct wispr_session *wispr = user_data;
	const guint8 *chunk;
	gsize length;
	guint16 status;
	gdouble elapsed;

	g_web_result_get_chunk(result, &chunk, &length);

	if (length > 0) {
		//printf("%s\n", (char *) chunk);
		g_web_parser_feed_data(wispr->parser, chunk, length);
		return TRUE;
	}

	g_web_parser_end_data(wispr->parser);

	status = g_web_result_get_status(result);

	g_print("status: %03u\n", status);

	elapsed = g_timer_elapsed(timer, NULL);

	g_print("elapse: %f seconds\n", elapsed);

	if (wispr->msg.message_type < 0) {
		const char *redirect;

		if (status != 302)
			goto done;

		if (g_web_result_get_header(result, "Location",
							&redirect) == FALSE)
			goto done;

		printf("Redirect URL: %s\n", redirect);
		printf("\n");

		wispr->request = g_web_request_get(wispr->web, redirect,
							wispr_result, wispr);

		return FALSE;
	}

	printf("Message type: %s (%d)\n",
			message_type_to_string(wispr->msg.message_type),
						wispr->msg.message_type);
	printf("Response code: %s (%d)\n",
			response_code_to_string(wispr->msg.response_code),
						wispr->msg.response_code);
	if (wispr->msg.access_procedure != NULL)
		printf("Access procedure: %s\n", wispr->msg.access_procedure);
	if (wispr->msg.access_location != NULL)
		printf("Access location: %s\n", wispr->msg.access_location);
	if (wispr->msg.location_name != NULL)
		printf("Location name: %s\n", wispr->msg.location_name);
	if (wispr->msg.login_url != NULL)
		printf("Login URL: %s\n", wispr->msg.login_url);
	if (wispr->msg.abort_login_url != NULL)
		printf("Abort login URL: %s\n", wispr->msg.abort_login_url);
	if (wispr->msg.logoff_url != NULL)
		printf("Logoff URL: %s\n", wispr->msg.logoff_url);
	printf("\n");

	if (status != 200 && status != 302 && status != 404)
		goto done;

	if (wispr->msg.message_type == 100) {
		if (wispr->username == NULL) {
			user_input("Username", FALSE, username_callback, wispr);
			return FALSE;
		}

		if (wispr->password == NULL) {
			user_input("Password", TRUE, password_callback, wispr);
			return FALSE;
		}

		g_idle_add(execute_login, wispr);
		return FALSE;
	} else if (wispr->msg.message_type == 120 ||
					wispr->msg.message_type == 140) {
		int code = wispr->msg.response_code;
		printf("Login process: %s\n",
					code == 50 ? "SUCCESS" : "FAILURE");
	}

	if (status == 302) {
		const char *redirect;

		if (g_web_result_get_header(result, "Location",
							&redirect) == FALSE)
			goto done;

		printf("\n");
		printf("Redirect URL: %s\n", redirect);
		printf("\n");

		wispr->request = g_web_request_get(wispr->web, redirect,
							wispr_result, wispr);

		return FALSE;
	}

done:
	g_main_loop_quit(main_loop);

	return FALSE;
}
Exemple #18
0
int main(int argc, char **argv)
{
    // variables required to read file
    FILE *file;
    char *buffer;
    char argbuffer[256];
    unsigned long fileLen;
    SAVEGAME save;

    //
    // VERIFY THAT FILE EXISTS
    //
    // note! this code allows for buffer overflow!
    struct stat sb;
    if (argc > 1)
    {
        strcpy(argbuffer, argv[1]);
        if (stat(argbuffer, &sb) != 0)
        {
            fprintf(stderr, "ERROR! File not found!\n");
            return 1;
        }
    }
    else
    {
        strcpy(argbuffer, argv[0]);
        usage(argbuffer);
        return 1;
    }
    //
    // READ FILE
    //
    file = fopen(argbuffer, "rb");
    if (!file) // verify that we can open the file
    {
        fprintf(stderr, "ERROR! Unable to open file!");
        fclose(file);
        return 1;
    }
    // get file length
    fseek(file, 0, SEEK_END);
    fileLen=ftell(file);
    fseek(file, 0, SEEK_SET);
    buffer=(char *)malloc(fileLen+1);
    if (!buffer)
    {
        fprintf(stderr, "ERROR! Out of memory!\n");
        return 1;
    }
    fread(buffer, fileLen, 1, file);
    if (read_4_le_bytes_as_int(buffer, 0) != 2) // simple file format verification
    {
        fprintf(stderr, "ERROR! Not an FTL savegame!\n");
        return 1;
    }
    parse_data(&save, buffer, fileLen);
    //print_data(&save);
    user_input(&save);
    save_data(&save);
    fclose(file);

    // garbage collection
    free(buffer);
    free(save.ss_name);
    free(save.ss_type);
    free(save.ss_type2);
    free(save.ss_name2);
    free(save.ss_class);
    free(save.remaining);
    free(save.events);
    return 0;
}
Exemple #19
0
int main(int argc, char **argv)
{
    setbuf(stdout, NULL);
    signal(SIGINT, INThandler);

    unsigned char ply = 6;

    int opt;
    while ((opt = getopt(argc, argv, "p:")) != -1) {
        switch (opt) {
        case 'p':
            ply = atoi(optarg);
            break;
        default:
            fprintf(stderr, "Usage: %s [-p ply]\n", argv[0]);
            exit(EXIT_FAILURE);
        }
    }

    struct position pos;
    init_position(&pos);
    assert(consistency(&pos));

    struct timespec realt_old, realt_new;

    tt = new_trans_tables();

#ifdef _USE_HISTORY
    hist = init_history();
#endif

#ifdef _DEBUG
    testing();
#endif

#ifndef _XBOARD
    print_position(&pos);
#endif

    while (1) {
        if (is_check(&pos)) {
            fprintf(stderr, "check.\n");
        }

        user_input(&pos);
#ifndef _XBOARD
        print_position(&pos);
#endif
        assert(consistency(&pos));

        if (is_check(&pos)) {
            fprintf(stderr, "check.\n");
        }

        current_utc_time(&realt_old);
        computer_move(&pos, ply);
        assert(consistency(&pos));
        current_utc_time(&realt_new);

#ifndef _XBOARD
        fprintf(stderr, "One second: %12llu ns\n",
            (long long unsigned)BILLION);
        fprintf(stderr, "Real  time: %12llu ns\n",
            (long long unsigned)minus_time(&realt_new, &realt_old));

        print_position(&pos);
#endif
    }

    return (0);
}
Exemple #20
0
int main(int argc, char* argv[])
{
  int i,j;

  int   interactive  = 0;
  char* outfile      = 0;
  char* defaultfile  = 0;
  char* module       = 0;

  /* we set up the defaults */

  for (j=0; modules[j].name; j++)
    modules[j].state = modules[j].inc_exc;

  for (i=1; i<argc; i++) {

    /*fprintf(stderr,"argv[%d]\n",i);*/

    if (arg_get_boolean(argv[i],"help"       ,&j /*dummy*/ )) {
      fprintf(stderr,"  \n");
      fprintf(stderr,"usage: %s [options]\n",argv[0]);
      fprintf(stderr,"\n");
      fprintf(stderr,"  This program builds a makefile and a configuration\n");
      fprintf(stderr,"  include file for %s according to a selection\n",prefix);
      fprintf(stderr,"  of modules.\n");
      fprintf(stderr,"  With no options, it builds a configuration according\n");
      fprintf(stderr,"  to built-in default rules. The options are:\n");
      fprintf(stderr,"  variant=<name>        an OSTYPE variant\n");
      /*
      fprintf(stderr,"  makefile=<filename>   overrides the built-in name (%s)\n",makefile);
      fprintf(stderr,"  configfile=<filename> overrides the built-in name (%s)\n",configfile);
      */
      fprintf(stderr,"  win32                 builds a makefile for nmake\n");
      fprintf(stderr,"                        (otherwise to unix/GNU makes)\n");
      fprintf(stderr,"  interactive           asks the users which modules to select\n");
      fprintf(stderr,"  in=<filename>         module selection taken from a file\n");
      fprintf(stderr,"  out=<filename>        module selection stored to a file\n");
      fprintf(stderr,"  module=<modulename>   selects a module\n");
      fprintf(stderr,"  module=!<modulename>  de-selects a module\n");
      fprintf(stderr,"  \n");
      fprintf(stderr,"  There can be several module= options, and they should\n");
      fprintf(stderr,"  normally follow in= options; the module= options can\n");
      fprintf(stderr,"  then override selections that the file makes.\n");
      fprintf(stderr,"  \n");
      fprintf(stderr,"  Configuration files have the following structure:\n");
      fprintf(stderr,"  ...\n");
      fprintf(stderr,"  %s_CONFIG_BEGIN\n",prefix);
      fprintf(stderr,"  %s_CONFIG_DEFAULT [ON/OFF]\n",prefix);
      fprintf(stderr,"  %s_CONFIG_MODULE SOME_MODULE\n",prefix);
      fprintf(stderr,"  %s_CONFIG_MODULE !ANOTHER_MODULE\n",prefix);
      fprintf(stderr,"  %s_CONFIG_MODULE A_THIRD_MODULE\n",prefix);
      fprintf(stderr,"  %s_CONFIG_END\n",prefix);
      fprintf(stderr,"  ...\n");
      fprintf(stderr,"  These lines can be embedded in C comments, etc, but\n");
      fprintf(stderr,"  they must begin at the beginnig of lines. The second\n");
      fprintf(stderr,"  line in the example allows you to select or deselct\n");
      fprintf(stderr,"  all the modules together.\n");
      fprintf(stderr,"  \n");
      fprintf(stderr,"  The list of modules (and whether they are included in\n");
      fprintf(stderr,"  the default configuration is:\n");
      fprintf(stderr,"  \n");
      for (j=0; modules[j].name; j++)
      fprintf(stderr,"  %-20s %s\n",modules[j].name,
	     modules[j].inc_exc ? "included" : "excluded");
      fprintf(stderr,"  \n");
      exit(0);
     }

    if (arg_get_string (argv[i],"variant="   ,&variant     )) continue;
    /*
    if (arg_get_string (argv[i],"makefile="  ,&makefile    )) continue;
    if (arg_get_string (argv[i],"configfile=",&configfile  )) continue;
    */
    if (arg_get_string (argv[i],"out="       ,&outfile     )) continue;

    if (arg_get_boolean(argv[i],"win32"      ,&win32       )) {
      if (win32) pathsep = '\\';
      continue;
    }

    if (arg_get_boolean(argv[i],"interactive",&interactive )) {
      continue;
    }

    if (arg_get_string (argv[i],"in="        ,&defaultfile )) {
      parse_infile(defaultfile);
      mark_dependants();
      continue;
    }

    if (arg_get_string (argv[i],"module="    ,&module      )) {
      parse_modulename(module);
      mark_dependants();
      continue;
    }

    fprintf(stderr,"error: command line argument <%s> is invalid\n",argv[i]);
    exit(1);
  }

  ostype = getenv("OSTYPE");
  if (!ostype) {
    fprintf(stderr,"error: the environment variable OSTYPE is not set\n");
    exit(1);
  }

  if (interactive) user_input();

  for (i=0; modules[i].name; i++)
    if (modules[i].state)
      build_flags |= modules[i].build_flags;

  map_sources_to_targets();

  emit_configfile(get_configuration_name(defaultfile));

  emit_makefile(get_configuration_name(defaultfile));

  if (outfile)
    emit_outfile(outfile);

  printf("%s%s\n",ostype,variant?variant:"");

  return 0;
}
Exemple #21
0
int main(int argc, char** argv){
  int i;
  char buffer[256];
  char* tk;
  FILTERCHAIN* tmp_chn;
  FILTERCHAIN* del_chn;  
	HARNESS_INSTANCE* hinstance;

	if(harness_init(argc,argv,&hinstance)){
		printf("Error: Initialization failed.\n");
		skygw_log_write(LOGFILE_ERROR,"Error: Initialization failed.\n");
		skygw_logmanager_done();
		skygw_logmanager_exit();
		return 1;
	}

  if(instance.verbose){
    printf("\n\n\tFilter Test Harness\n\n");
  }
  

  while(instance.running){
    printf("Harness> ");
    memset(buffer,0,256);
    fgets(buffer,256,stdin);
    tk = strtok(buffer," \n");
    switch(user_input(tk))
      {
      case RUNFILTERS:
	if(instance.head->next == NULL){
	  printf("No filters loaded.\n");
	  break;
	}
	if(instance.buffer == NULL){
	  if(instance.infile<0){
	    manual_query();
	  }else{
	    load_query();
	  }
	}
	
	route_buffers();
	break;

      case LOAD_FILTER:

	tk = strtok(NULL," \n");
	tmp_chn = load_filter_module(tk);
	if(!tmp_chn || !load_filter(tmp_chn,instance.conf)){
	  printf("Error creating filter instance.\n");	  
	  skygw_log_write(LOGFILE_ERROR,"Error: Error creating filter instance.\n");
	}else{
	  instance.head =  tmp_chn;
	}
	break;

      case DELETE_FILTER:

	tk = strtok(NULL," \n\0");
	tmp_chn = instance.head;
	del_chn = instance.head;
	if(tk){
	  if(strcmp(instance.head->name,tk) == 0){

	    instance.head = instance.head->next;

	  }else{
	
	    while(del_chn->next){

	      if(strcmp(del_chn->name,tk) == 0){

		tmp_chn->next = del_chn->next;
		break;
	      
	      }else{
		tmp_chn = del_chn;
		del_chn = del_chn->next;
	      

	      }

	    }
	  }

	  if(del_chn && del_chn->next){

	    printf("Deleted %s.\n",del_chn->name);

	    if(del_chn->instance){

	      del_chn->instance->freeSession(del_chn->filter,del_chn->session);

	    }

	    free(del_chn->filter);
	    free(del_chn->down);
	    free(del_chn->name);
	    free(del_chn);
	  }else{
	    printf("No matching filter found.\n");
	  }
	}
	break;

      case LOAD_CONFIG:
	tk = strtok(NULL,"  \n\0");
	if(!load_config(tk)){
	  free_filters();
	}
	break;

      case SET_INFILE:

	tk = strtok(NULL,"  \n\0");
	if(instance.infile >= 0){
	  close(instance.infile);
	  free(instance.infile_name);
	}
	if(tk!= NULL){
	  free_buffers();
	  instance.infile = open_file(tk,0);
	  if(instance.infile >= 0){
	    load_query();
	    instance.infile_name = strdup(tk);
	    if(instance.verbose){
	      printf("Loaded %d queries from file '%s'\n",instance.buffer_count,instance.infile_name);
	    }
	  }
	}else{
	  instance.infile = -1;
	  printf("Queries are read from: command line\n");
	}

	break;

      case SET_OUTFILE:

	tk = strtok(NULL,"  \n\0");
	if(instance.outfile >= 0){
	  close(instance.outfile);
	  free(instance.outfile_name);
	}
	if(tk!= NULL){
	  
	  instance.outfile = open_file(tk,1);
	  if(instance.outfile >= 0){
	    instance.outfile_name = strdup(tk);
	    printf("Output is logged to: %s\n",tk);
	  }
	}else{
	  instance.outfile = -1;
	  printf("Output logging disabled.\n");
	}

	break;

      case SESS_COUNT:

	tk = strtok(NULL,"  \n\0");
	free_buffers();
	free_filters();
	instance.session_count = atoi(tk);
	printf("Sessions set to: %d\n", instance.session_count);
	break;

      case THR_COUNT:

	instance.running = 0;
	pthread_mutex_unlock(&instance.work_mtx);
	for(i = 0;i<instance.thrcount;i++){
	  pthread_join(instance.thrpool[i],NULL);
	}
	pthread_mutex_lock(&instance.work_mtx);

	instance.running = 1;
	tk = strtok(NULL,"  \n\0");
	instance.thrcount = atoi(tk);
	void* t_thr_pool;

	if(!(t_thr_pool = realloc(instance.thrpool,instance.thrcount * sizeof(pthread_t)))){
	  printf("Error: Out of memory\n");
	  skygw_log_write(LOGFILE_ERROR,"Error: Out of memory\n");
	  instance.running = 0;
	  break;
	}

	instance.thrpool = t_thr_pool;
	int thr_num = 1;

	for(i = 0;i<instance.thrcount;i++){

	  pthread_create(&instance.thrpool[i],
			 NULL,
			 (void*)work_buffer,
			 (void*)thr_num++);

	}
	printf("Threads set to: %d\n", instance.thrcount);

	break;

      case QUIT:

	instance.running = 0;
	pthread_mutex_unlock(&instance.work_mtx);
	for(i = 0;i<instance.thrcount;i++){
	  pthread_join(instance.thrpool[i],NULL);
	}
	break;
      case UNDEFINED:

	printf("Command not found, enter \"help\" for a list of commands\n");

	break;
      default:
	
	break;
	
      }  
  }

  if(instance.infile >= 0){
    close(instance.infile);
  }
  if(instance.outfile >= 0){
    close(instance.outfile);
  }

  free_buffers();
  free_filters();
  skygw_logmanager_done();
  skygw_logmanager_exit();
  free(instance.head);

  return 0;
}