Ejemplo n.º 1
0
struct token *expand(struct token *original)
{
    const struct token *list;
    struct token *res;

    /* Do nothing if there is nothing to expand. */
    if (!needs_expansion(original))
        return original;

    list = original;
    res = calloc(1, sizeof(*res));
    res[0] = token_end;
    while (list->token != END) {
        const struct macro *def = definition(*list);
        struct token **args;

        /* Only expand function-like macros if they appear as function
         * invocations, beginning with an open paranthesis. */
        if (def && !is_macro_expanded(def) &&
            (def->type != FUNCTION_LIKE || peek_next(list + 1) == '('))
        {
            args = read_args(list + 1, &list, def);
            res = concat(res, expand_macro(def, args));
        } else {
            res = append(res, *list++);
        }
    }

    free(original);
    return res;
}
Ejemplo n.º 2
0
/****************************************************************************
 * Function implementations
 ****************************************************************************/
int 
main(int argc, char *argv[])
{   
    /* Read program arguments */
    program_name = argv[0];
    read_args(argc, argv);
        
    /* Try and read the problem file and its info */
    arrow_problem problem;
    if(!arrow_problem_read(input_file, &problem))
    {
        arrow_print_error("Could not read input file.\n");
    }
    
    /* Solve TSP */
    arrow_tsp_result result;
    if(!arrow_tsp_result_init(&problem, &result))
        arrow_print_error("Could not initialize result structure.\n");
    
    if(!arrow_tsp_cc_exact_solve(&problem, NULL, &result))
        arrow_print_error("Could not solve TSP on file.\n");
    
    printf("\nFound Tour: %d\n", result.found_tour);
    printf("Tour length: %5.0f\n", result.obj_value);
    printf("Total Time: %5.2f\n", result.total_time);
    
    /* Free up the structures */
    arrow_tsp_result_destruct(&result);
    arrow_problem_destruct(&problem);
    
    return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
int
main(int argc, char **argv)
{
    int ret;

    settings_init();

    if (set_signal_handler(signals) == -1) {
        return -1;
    }

    tc_time_init();

    if (read_args(argc, argv) == -1) {
        return -1;
    }

    if (srv_settings.log_path == NULL) {
        srv_settings.log_path = "error_intercept.log";  
    }

    if (tc_log_init(srv_settings.log_path) == -1) {
        return -1;
    }

    ret = tc_event_loop_init(&s_event_loop, MAX_FD_NUM);
    if (ret == TC_EVENT_ERROR) {
        tc_log_info(LOG_ERR, 0, "event loop init failed");
        return -1;
    }

    /* output debug info */
    output_for_debug();
    if (set_details() == -1) {
        return -1;
    }

    if (interception_init(&s_event_loop, srv_settings.binded_ip,
                          srv_settings.port) == TC_ERROR)
    {
        return -1;
    }

    if (set_timer() == -1) {
        return -1;
    }

#if (INTERCEPT_COMBINED)
    tc_event_timer_add(&s_event_loop, CHECK_INTERVAL, interception_push);
#endif
    tc_event_timer_add(&s_event_loop, OUTPUT_INTERVAL,
            interception_output_stat);

    /* run now */
    tc_event_process_cycle(&s_event_loop);

    server_release_resources();

    return 0;
}
Ejemplo n.º 4
0
void op_sum(const char *p) {
    Mesg request, response;

    request.mesg_type = pid;
    request.op = SUM_GET;

    read_args(p, &request);

    send_request(&request, &response);

    sleep(op_time);

    request.op = SUM_SET;

    int sum = 0;
    size_t i;
    for (i = 1; i < request.args_count; i++) {
        sum += response.args[i];
    }

    request.args[request.args_count++] = sum;

    send_request(&request, &response);

    printf("s %d", request.args[0]);
    for (i = 1; i < request.args_count; i++) {
        printf(" %d", request.args[i]);
    }
    printf("\n");
}
Ejemplo n.º 5
0
/*
 * Main entry point
 */
int
main(int argc ,char **argv)
{
    int             ret;

    /* first, init time */
    tc_time_update();

    /* Set defaults */
    settings_init();
    read_args(argc, argv);
    /* Init log for outputing debug info */
    log_init(clt_settings.log_path);
    /* Output debug info */
    output_for_debug(argc, argv);
    /* Set details for running */
    set_details();

    ret = tc_event_loop_init(&event_loop, MAX_FD_NUM);
    if (ret == TC_EVENT_ERROR) {
        log_info(LOG_ERR, "event loop init failed");
        return -1;
    }

    /* Initiate tcpcopy client*/
    ret = tcp_copy_init(&event_loop);
    if (SUCCESS != ret) {
        exit(EXIT_FAILURE);
    }

    /* Run now */
    tc_event_process_cycle(&event_loop);

    return 0;
}
Ejemplo n.º 6
0
void b_cmd(int pid){
    char *cmds[10], s[100], *endptr;
    long unsigned int address;
    int i = 0;
    while(1){
	printf("->");
	read_args(s, cmds, " \n");
	if(strcmp(cmds[0], "get") == 0){
	    address = strtol(cmds[1], &endptr, 16);
	    int data = ptrace(PTRACE_PEEKDATA, pid, address, 0);
	    printf("Value at %x = %lu\n", address, data);
	}
	else if(strcmp(cmds[0], "set") == 0){
	    address = strtol(cmds[1], &endptr, 16);
	    int dat = strtol(cmds[2], &endptr, 10);
	    ptrace(PTRACE_POKEDATA, pid, address, dat);
	}
	else if(strcmp(cmds[0], "continue") == 0)
	    break;
	else if(strcmp(cmds[0], "exit") == 0)
	    return 0;
	else if(strcmp(cmds[0], "help") == 0){
	    printf("get address : to get data at given address, address should be in hexadecimal format\n");
	    printf("set address data : to set data at given address, data should be in intiger format and  address should be in hexadecimal format\n");
	    printf("continue : to continue running the program\n");
	    printf("exit : to exit mygdb\n");
	}
	else
	    printf("invalid command\n");
    }
}
Ejemplo n.º 7
0
   // constructors
   explicit C_arg(int argc, char** argv, C_time& c_inst_time) :
                                                               random_seed(0),
                                                               target_false_positive_prob(DEFAULT_FPR),
                                                               kmer_length(0),
                                                               kmer_middle_index(0),
                                                               kmer_occurrence_threshold(0),
                                                               num_clusters(NUM_PARTITIONS_FOR_COUNT),
                                                               num_clusters_digit(0),
                                                               residue_kmer(0),
                                                               remainder_kmer(0),
                                                               num_bytes_per_kmer(0),
                                                               extend(MAX_EXTENSION),
                                                               paired_read(true),
                                                               nowrite(false),
                                                               debug(false),
                                                               verify(true),
                                                               set_kmer_occurrence_threshold(false),
                                                               num_args(argc),
                                                               args(argv)
                                                              {
      time_t rawtime;
      time(&rawtime);
      c_inst_time.start_parse_args = asctime(localtime(&rawtime));

      read_args();

      time(&rawtime);
      c_inst_time.end_parse_args = asctime(localtime(&rawtime));
   };
Ejemplo n.º 8
0
Archivo: tm.c Proyecto: mar77i/timerec
int main(int argc, char *argv[]) {
	enum timerec_type t = TIMEREC_SQLITE;
	enum timerec_action action = TIMEREC_NUMACTIONS;
	struct buffer *conn = NULL;
	struct timerec_data *tr;
	char *opt = NULL;
	int ret = EXIT_SUCCESS;
	size_t id = 0;
	if(read_args(argc, argv, &t, &conn, &action, &opt, &id) < 0)
		return EXIT_FAILURE;
	if(conn == NULL)
		default_dbpath(&conn);
	if(action == TIMEREC_NUMACTIONS) {
		usage();
		goto error;
	}
	if(conn == NULL)
		return EXIT_FAILURE;
	if(timerec_init(t, buffer_cstr(conn), &tr) < 0) {
		ret = EXIT_FAILURE;
		goto error;
	}
	timerec_do(tr, action, opt, id);
	timerec_end(tr);
error:
	buffer_end(conn);
	return ret;
	(void)argc;
	(void)argv;
}
Ejemplo n.º 9
0
Archivo: main.c Proyecto: ale-naou/fdf
int			main(int ac, char **av)
{
	t_env	e;

	e.inf.h = 0.2;
	e.div = 2;
	if (ac >= 2 && ac <= 7)
	{
		if (ft_strcmp(av[1], "-help") == 0)
			aff_help();
		e.mlx = mlx_init();
		init_env(&e);
		read_args(&e, ac, av);
		parsing(&e, av[1]);
		e.inf.scale = (((e.arg.winx + e.arg.winy) / (e.p.lenx + e.p.leny)) / 2);
		e.inf.scale = e.inf.scale <= 0 ? 0.8 : e.inf.scale;
		e.orix = e.arg.winx / 2;
		e.oriy = e.arg.winy / e.p.leny;
		backup(&e);
		draw(&e);
	}
	else
		aff_help();
	return (0);
}
Ejemplo n.º 10
0
Archivo: cpp.c Proyecto: rui314/8cc-old
/*
 * Reads a token from a given preprocessing context, expands it if macro, and
 * returns it.
 */
static Token *expand_one(CppContext *ctx) {
    Token *tok = read_cpp_token(ctx);
    if (!tok) return NULL;
    if (tok->toktype != TOKTYPE_IDENT)
        return tok;
    String *name = tok->val.str;
    Macro *macro = dict_get(ctx->defs, name);
    if (!macro)
        return tok;
    if (list_in(tok->hideset, name))
        return tok;

    switch (macro->type) {
    case MACRO_OBJ: {
        List *ts = subst(ctx, macro, make_list(), list_union1(tok->hideset, name));
        pushback(ctx, ts);
        return expand_one(ctx);
    }
    case MACRO_FUNC: {
        List *args = read_args(ctx, macro);
        Token *rparen = read_cpp_token(ctx);
        List *hideset = list_union1(list_intersect(tok->hideset, rparen->hideset), name);
        List *ts = subst(ctx, macro, args, hideset);
        pushback(ctx, ts);
        return expand_one(ctx);
    }
    case MACRO_SPECIAL:
        macro->fn(ctx, tok);
        return expand_one(ctx);
    }
    panic("should not reach here");
}
Ejemplo n.º 11
0
int main(int argc, char *argv[]) {
    char *args_help = "Enter number of signals.\n";
    if (read_args(argc, argv, &signal_num) != 0) {
        printf(args_help);
        return 1;
    }

    struct sigaction act_sigusr;
    act_sigusr.sa_sigaction = sigusr_handler;
    act_sigusr.sa_flags = SA_SIGINFO;
    sigset_t mask_set;
    sigfillset(&mask_set);
    act_sigusr.sa_mask = mask_set;
    sigaction(SIGRTMIN, &act_sigusr, NULL);
    sigaction(SIGRTMIN + 1, &act_sigusr, NULL);


    FILE * catcher_ps = popen("pidof catcher", "r");
    if (catcher_ps == NULL) {
        printf("Error while searching for catcher process occurred.\n");
        return 1;
    }
    if (fscanf(catcher_ps, "%d", &catcher_pid) == EOF) {
        printf("Catcher process not found.\n");
        return 1;
    }
    pclose(catcher_ps);

    send_signals();

    while (1)
        pause();
}
Ejemplo n.º 12
0
//program to implement the game of minesweeper
//user enters the name of the executable, the row and column dimensions, number of mines, and optionally a seed for random number generator 
int main(int argc, char** argv){
	
	Board board; //intitialize the board with struct type Board
	
  	int row = 0; //intialize the number of rows
  	int column = 0; //initialize the number of columns
  	int mine = 0; //intiialize the number of mines
  	read_args(argc, argv, &row, &column, &mine);
  	board.row = row;
  	board.col = column;
  	board.mine = mine;


	board.seed = generate_seed(argv);
	board.tile = create_board(board); //create the board
	mine_location_generator(board);
	print_board(board);
	play_is_valid(board);



	destroy_board(board); //when the game is over destroy the board

  return 0;
}
Ejemplo n.º 13
0
int
main ( int argc, char **argv )
{
    read_args ( argc, argv );
    yyparse ();

#ifdef DUMPTREES
    FILE *pre = fopen ( "pre.tree", "w" ),
        *post = fopen ( "post.tree", "w" );
    print_node ( pre, root, 0 );
#endif

    root = simplify_tree ( root );

#ifdef DUMPTREES
    print_node ( post, root, 0 );
    fclose ( pre );
    fclose ( post );
#endif

    init_scopes ( 256 );

    find_symbols ( root );

    destroy_scopes ();
    destroy_subtree ( root );
    exit ( EXIT_SUCCESS );
}
Ejemplo n.º 14
0
int main(int argc, char **argv) {
  read_args(argc, argv);
  counters timer;
  start_measure(timer);

  // declarations
  Complex ioB(1.0, 1.0);
  ioBuffer = cl::sycl::buffer<Complex,2>(cl::sycl::range<2> {M, N});
  ioABuffer = cl::sycl::buffer<Complex,2>(cl::sycl::range<2> {M, N}); 
  ioBBuffer = cl::sycl::buffer<Complex,1>(&ioB, cl::sycl::range<1> {1}); 

  // initialization
  for (size_t i = 0; i < M; ++i){
    for (size_t j = 0; j < N; ++j){
      float tmp = (float) (i*(j+2) + 10) / N;
      Complex value(tmp, tmp);
      cl::sycl::id<2> id = {i, j};
      ioBuffer.get_access<cl::sycl::access::mode::write>()[id] = value;
      ioABuffer.get_access<cl::sycl::access::mode::write>()[id] = value;
    }
  }

  // our work
  coef_var2D<0, 0> c1;  
  coef_var2D<1, 0> c2;
  coef_var2D<0, 1> c3;
  coef_var2D<-1, 0> c4;
  coef_var2D<0, -1> c5;

  auto st = c1+c2+c3+c4+c5;
  input_var2D<Complex, &ioABuffer, &ioBBuffer, &fdl_in, &fac> work_in;
  output_2D<Complex, &ioBuffer, &fdl_out> work_out;
  auto op_work = work_out << st << work_in;

  auto st_id = c1.toStencil();
  input_var2D<Complex, &ioBuffer, &ioBBuffer, &fdl_in, &fac_id> copy_in;
  output_2D<Complex, &ioABuffer, &fdl_out> copy_out;
  auto op_copy = copy_out << st_id << copy_in;

  end_init(timer);
  auto begin_op = counters::clock_type::now();

  // compute result with "gpu"
  {   
    cl::sycl::queue myQueue; 
    for (unsigned int i = 0; i < NB_ITER; ++i){      
      //op_work.doComputation(myQueue);
      op_work.doLocalComputation(myQueue);
      op_copy.doComputation(myQueue);
    }
  }

  auto end_op = counters::clock_type::now();
  timer.stencil_time = std::chrono::duration_cast<counters::duration_type>(end_op - begin_op);
  // loading time is not watched
  end_measure(timer);

  return 0;
}
/*
 * Function: main
 * Parameter(s): built in parameters that has command line arguments stored in it.
 * Returns: exit status of the program
 * Description: The main controller of the whole program,
 * connects with other functions and accomplishes the given task.
 */
int main(int argc, char* argv[]) {

	read_args(argc, argv);
	read_jobs();
	start_scheduler();

	return EXIT_SUCCESS;
}
Ejemplo n.º 16
0
int main(int argc, char *argv[]){
	while(global_args_t_init(global_args) != 0);
	if(read_args(argc, argv) == -1){print_usage(argv); return -1; }
	if(global_args.i_num == 1){print_info(argc, argv);}
	else if(global_args.l_num == 1){list_directory(argc, argv);}
	else if(global_args.r_num == 1 && global_args.o_num == 1){recover_file(argc, argv);}
	else if(global_args.x_num == 1){cleanse_file(argc, argv);}
	return 0;
}
Ejemplo n.º 17
0
int 
main (unsigned int argc, char **argv)
{
	char **null_argv = (char **) NULL;
	char *mess;

	extern int ch_set;

	ch_set = TRUE;

	print_parse_errors = FALSE;
	quipu_syntaxes();

#ifdef USE_PP
	pp_quipu_init (argv[0]);
#endif

	want_oc_hierarchy();

	namestr[0] = '\0';
	passwd[0] = '\0';

	toplevel = XtInitialize("X-Directory", "Pod", NULL, 0,
							&argc, argv);

	dsap_init((int *) NULL, &null_argv);

#ifdef USE_PP
	pp_quipu_run ();
#endif

	read_args(&argc, &argv);
	user_tailor();
	read_bind_args(&argc, &argv);

	CreateWidgets();
	message((Widget) NULL, "Connecting to Directory. Please Wait...");

	if ((mess = cnnct_bind()) != NULLCP) {
		kill_message();
		displayStartupError(mess);
		XtMainLoop();
	}

	set_attribute_syntax (str2syntax("photo"),
						  (IFP)pe_cpy,    NULLIFP,
						  NULLIFP,        podphoto,
						  (IFP)pe_cpy,    quipu_pe_cmp,
						  pe_free,        NULLCP,
						  NULLIFP,        TRUE );

	kill_message();
	PodLoop();

	return 0;
}
Ejemplo n.º 18
0
// usage: LIMIT soft hard ... -- executable arg1 arg2 ...
int main(int c, char *v[])
{
    check_consistency();

    traced_program p[1];
    read_args(p, c, v);
    run_limited_program(p);

    return p->report_exit_fail ? p->report_exit_status : EXIT_SUCCESS;
}
Ejemplo n.º 19
0
void op_write(const char *p) {
    Mesg request, response;

    request.mesg_type = pid;
    request.op = WRITE;

    read_args(p, &request);

    send_request(&request, &response);

    printf("w %d %d\n", request.args[0], request.args[1]);
}
Ejemplo n.º 20
0
void op_read(const char *p) {
    Mesg request, response;

    request.mesg_type = pid;
    request.op = READ;

    read_args(p, &request);

    send_request(&request, &response);

    printf("r %d %d\n", request.args[0], response.args[0]);
}
Ejemplo n.º 21
0
int		main(int argc, char **argv)
{
	t_command 	*command;

	if (!(command = set_command(argc, argv)))
		exit(EXIT_FAILURE);
	if ((read_args(command->paths, command)) == -1)
	{
		delete_command(command);
		exit(EXIT_FAILURE);
	}
} 
Ejemplo n.º 22
0
Archivo: vam.c Proyecto: perlawk/VSL
int   main( int   argc,
            char *argv[] )

/* vam takes a single argument, the object file, which is loaded at address
   zero. There is an optional flag, -t, which means trace at each step. */

{
	read_args( argc, argv ) ;	 /* Get the arguments */
	init_system() ;			 /* Set up the machine */
	vam() ;				 /* Run it */
	return 0;
}	/* main() */
Ejemplo n.º 23
0
int main(int argc, const char** argv)
{
  int ret;
  arg_t args;
  read_args(argc, argv, &args);

  printf("args width:%i height:%i rounds:%i hotspots:%s selection:%s\n",
      args.width_field,
      args.height_field,
      args.n_rounds,
      args.hotspot_filename,
      argc >= 6 ? args.selection_filename : "empty");

  hotspot_vector_t hotspots;
  hotspot_vector_t coordinates;

  if (ret = read_hotspots(args.hotspot_filename, &hotspots))
  {
    printf("could not read hotspots from: %s (%d)", args.hotspot_filename, ret);
    return -1;
  }


  field_t field;
  init_field(args, &field);

  int current_round = 0;
  set_hotspots(&field, current_round, &hotspots);
  while (current_round++ < args.n_rounds)
  {
    /*print_field(&field);*/
    simulate_round(&field);

    // double buffering
    volatile field_value_t * temp = field.old_values;
    field.old_values = field.new_values;
    field.new_values = temp;

    set_hotspots(&field, current_round, &hotspots);
  }
  if (argc >= 6) {
    if (ret = read_coordinates(args.selection_filename, &coordinates))
    {
      printf("could not read coordinates from: %s (%d)", args.selection_filename, ret);
      return -1;
    }
    print_coordinate_values(&field, &coordinates);}
  else
  {
    print_field(&field);
  }
   return 0;
}
Ejemplo n.º 24
0
int
main(int argc, char *argv[]) {
  server_type_t server_type;
  int port;
  read_args(argc, argv, &port, &server_type);
  server_t *server = server_new(server_type, port);
  server_set_accept_callback(server, on_client_accepted);
  server_set_data_callback(server, on_incoming_data);
  server_set_close_callback(server, on_client_closed);
  server_loop(server);
  server_destroy(server);
  return 0;
}
Ejemplo n.º 25
0
int main(int argc, char *argv[])
{
  int i, iarg;
  Par par;
  char *env;

  par.nblock = 2;
  par.seed = 0;
  par.ntherm = 1000;
  par.nsamp = 100;
  par.deltat = 0.01;
  par.readfile = NULL;
  par.alpha = 0.0;
  

  // Get the program name from the first argument (number 0).
  progname = strrchr(argv[0], '/');	// Skip the directory part (e.g. if called with "./lang").
  if (progname)				// If '/' was found, progname points to this '/'...
    progname++;				// ...now points to first char after '/'.
  else
    progname = argv[0];			// Use the whole argument as program name.

  if (argc == 1) {
    printf("Usage: %s N=50 L=14.0 T=0.1 alpha=1.0\n", argv[0]);
    printf("Optional arguments (with defaults) deltat=%g nblock=%d nsamp=%d ntherm=%d seed=%d\n",
	   par.deltat, par.nblock, par.nsamp, par.ntherm, par.seed);
    exit(EXIT_SUCCESS);
  }

  // Interpret the commands given in the argument list.
  for (iarg = 1; iarg < argc; iarg++)
    if (!read_args(&par, argv[iarg]))
      exit(EXIT_FAILURE);

  
  if (par.alpha > 0.0)
    printf("--- Langevin dynamics of a Lennard-Jones gas ---\n");
  else
    printf("--- Molecular dynamics of a Lennard-Jones gas ---\n");

  printf("Gas with %d particles at T = %g, Delta time = %g.\n", par.n, par.t, par.deltat);
  printf("Box with size %5.3f x %5.3f\n", par.L.x, par.L.y);


  if (par.alpha > 0.0)
    par.noise = sqrt(2*par.t/(par.alpha*par.deltat));

  run(&par);

  exit(EXIT_SUCCESS);
}
Ejemplo n.º 26
0
int main(int argc, char *argv[]) {
    atexit(cleanup);
    struct sigaction act;
    act.sa_handler = sigint_handler;
    sigaction(SIGINT, &act, NULL);
    sigaction(SIGTSTP, &act, NULL);

    char *args_help = "Enter -u x or x where -u means printing only summary, x is a number.\n";
    if (read_args(argc, argv, &x, &only_summary) != 0) {
        printf(args_help);
        return 1;
    }

    srand(time(NULL));

    shm_id = shm_open(SHM_NAME, O_RDWR, 0);
    if (shm_id < 0 || (shm = (struct shm_mem *)mmap(0, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, shm_id, 0)) < 0) {
        printf("Error while opening shared memory occurred.\n");
        return 1;
    }

    sem_id_r = sem_open(SEM_NAME_R, 0);
    if (sem_id_r < 0) {
        printf("Error while opening semaphores occurred.\n");
        return 1;
    }

    int counter;
    struct timeval tval;
    while (1) {
        counter = 0;
        if (sem_wait(sem_id_r) < 0) {
            printf("Error while waiting for semaphore occurred.\n");
            return 1;
        }
        for (int i = 0; i < ARRAY_LEN; i++) {
            if (shm->numbers[i] == x) {
                counter++;
            }
        }
        total += counter;
        gettimeofday(&tval, NULL);
        if (!only_summary)
            printf("%d %ld.%ld Found %d times number: %d.\n", getpid(), tval.tv_sec, tval.tv_usec/1000, counter, x);
        if (sem_post(sem_id_r) < 0) {
            printf("Error while incrementing semaphore occurred.\n");
            return 1;
        }
        nanosleep(&delay, NULL);
    }
}
Ejemplo n.º 27
0
void cmd(char *arg){
    char *cmds[10], s[100], *endptr;
    long unsigned int address[100];
    int i = 0;
    while(1){
	printf(">>");
	read_args(s, cmds, " \n");
	if(strcmp(cmds[0], "break") == 0){
	    address[i++] = strtol(cmds[1], &endptr, 16);
	    printf("break point set at %x\n",address[i-1]);
	}
	else if(strcmp(cmds[0], "exit") == 0)
	    return 0;
	else if(strcmp(cmds[0], "run") == 0)
	    break;
	else if(strcmp(cmds[0], "help") == 0){
	    printf("break address : to set break point, address should be in hexadecimal format\n");
	    printf("run : to start running the program\n");
	    printf("exit : to exit mygdb\n");
	}
	else
	    printf("invalid command\n");
    }
    int j = 0, status = 0, pid;
    struct user_regs_struct uregs;
    printf("running %s...\n",arg);
    if ((pid=fork())==0) {
        ptrace(PTRACE_TRACEME, 0, 0, 0);
        execl(arg, arg, 0);
        printf("execl error...\n");
    } else {
        wait(&status);
	while(1){
	    j = 0;
	    if(WIFEXITED(status)) break;
	    ptrace(PTRACE_SINGLESTEP, pid, 0, 0); 
	    wait(&status);
	    ptrace(PTRACE_GETREGS, pid, 0, &uregs);
	    while(j < i){
		if(address[j++] == uregs.rip){
		    printf("break at %x\n", uregs.rip);
		    b_cmd(pid);
		}
	    }
	}
	printf("Finished running %s...\n", arg);
	cmd(arg);
    }
}
Ejemplo n.º 28
0
//main function that starts the program
//program to execute the game of Connect-4, except the user can define the size of the board and how many pieces are needed to win
int main(int argc, char** argv){
	int num_rows = 0; //initialize variables that will be entered by the user
	int num_columns = 0;
	int plays_to_win = 0;
	int turn_count = 1;


	read_args(argc, argv, &num_rows, &num_columns, &plays_to_win); //pass the variables as pointers so that their values can be updated
	char** board = create_board(num_rows, num_columns);
	execute_game(board, num_rows, num_columns, plays_to_win, turn_count); 
	destroy_board(board, num_rows); //when the game is over, the board can be destroyed


	return 0;
}
Ejemplo n.º 29
0
/* Parses a string into the provided IrcMessage struct. Returns 1 on success, 0 on failure. */
int irc_parse_string(char *msgstr, int len, IrcMessage *msg) {
	//Copy msgstr into the full field
	char *fullcpy = malloc(sizeof(char) * strlen(msgstr));
	msg->full = strcpy(fullcpy, msgstr);

	//Set up all other fields
	msg->prefix = NULL;
	msg->command = IRC_NONE;
	msg->argc = 0;
	msg->argv = NULL;

	//Make parser pointer
	char *ptr = msgstr;

	//If first char is : we have a prefix
	if(msgstr[0] == ':') {
		ptr++;
		msg->prefix = first_word(&ptr);
	}

	if(ptr == NULL) return 1;
	
	//First word after optional prefix is command
	char *commandstr = first_word(&ptr);

	//Convert command string to command const
	int cmdlen = strlen(commandstr);
	if(cmdlen <= 3 && strndigit(commandstr,cmdlen)) {
		msg->command = IRC_NUMERIC;
	} else if(!strncmp(commandstr,"PING",4)) {
		msg->command = IRC_PING;
	} else if(!strncmp(commandstr,"NOTICE",6) || !strncmp(commandstr,"PRIVMSG",7)) {
		msg->command = IRC_MESSAGE;
	} else if(!strncmp(commandstr,"ERROR",5)) {
		msg->command = IRC_ERROR;
	} else if(!strncmp(commandstr,"JOIN",4)) {
		msg->command = IRC_JOIN;
	} else {
		msg->command = IRC_OTHER;
	}

	if(ptr == NULL) return 1;

	//Read additional arguments
	msg->argv = read_args(&ptr, &(msg->argc));

	return 1;
}
Ejemplo n.º 30
0
/*
 * main entry point
 */
int
main(int argc, char **argv)
{
    int ret;

    settings_init();

    tc_time_init();

    if (read_args(argc, argv) == -1) {
        return -1;
    }
    
    if (clt_settings.log_path == NULL) {
        clt_settings.log_path = "error_tcpcopy.log";
    }   

    if (tc_log_init(clt_settings.log_path) == -1) {
        return -1;
    }

    /* output debug info */
    output_for_debug(argc, argv);

    /* set details for running */
    if (set_details() == -1) {
        return -1;
    }

    ret = tc_event_loop_init(&event_loop, MAX_FD_NUM);
    if (ret == TC_EVENT_ERROR) {
        tc_log_info(LOG_ERR, 0, "event loop init failed");
        return -1;
    }

    ret = tcp_copy_init(&event_loop);
    if (ret == TC_ERROR) {
        exit(EXIT_FAILURE);
    }

    /* run now */
    tc_event_process_cycle(&event_loop);

    tcp_copy_release_resources();

    return 0;
}