/** * main */ int main(int argc, char *argv[]) { if(check_arguments(argc, argv[1], argv[2])) { string source = argv[1]; string destination = argv[2]; if(file::check_file(source) && file::check_file(destination)) { if(file::read_file(source)) { try { list::remove_duplicates(); file::write_xml(list::get_root(), destination); list::destroy(list::get_root()); cout << "Fine." << endl; } catch(exception& e) { } } } } return 0; }
int lua_gcs_send_text(lua_State *L) { check_arguments(L, 1, "send_text"); const char* str = lua_tostring(L, -1); gcs().send_text(MAV_SEVERITY_INFO, str); return 0; }
/** * Main */ int main(int argc, char **argv) { gboolean ret = TRUE; _cleanup_sqliterepocmdoptions_free_ SqliterepoCmdOptions *options = NULL; _cleanup_error_free_ GError *tmp_err = NULL; // Parse arguments options = sqliterepocmdoptions_new(); if (!parse_sqliterepo_arguments(&argc, &argv, options, &tmp_err)) { g_printerr("%s\n", tmp_err->message); exit(EXIT_FAILURE); } // Set logging cr_setup_logging(FALSE, options->verbose); // Print version if required if (options->version) { printf("Version: %s\n", cr_version_string_with_features()); exit(EXIT_SUCCESS); } // Check arguments if (!check_arguments(options, &tmp_err)) { g_printerr("%s\n", tmp_err->message); exit(EXIT_FAILURE); } if (argc != 2) { g_printerr("Must specify exactly one repo directory to work on\n"); exit(EXIT_FAILURE); } // Emit debug message with version g_debug("Version: %s", cr_version_string_with_features()); g_thread_init(NULL); // Initialize threading // Gen the databases ret = generate_sqlite_from_xml(argv[1], options->compression_type, options->checksum_type, options->local_sqlite, options->force, options->keep_old, &tmp_err); if (!ret) { g_printerr("%s\n", tmp_err->message); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
int* inform_black_box(int const *series, size_t l, size_t n, size_t m, int const *b, size_t const *r, size_t const *s, int *box, inform_error *err) { if (check_arguments(series, l, n, m, b, r, s, err)) { return NULL; } size_t max_r, max_s; compute_lengths(r, s, l, &max_r, &max_s); bool allocate = (box == NULL); if (allocate) { box = calloc(n * (m - max_r - max_s + 1), sizeof(int)); if (box == NULL) { INFORM_ERROR_RETURN(err, INFORM_ENOMEM, NULL); } } size_t *data = calloc(2 * l, sizeof(size_t)); if (data == NULL) { if (allocate) free(box); INFORM_ERROR_RETURN(err, INFORM_ENOMEM, NULL); } size_t *history = data; if (r == NULL) { for (size_t i = 0; i < l; ++i) history[i] = 1; } else { memcpy(history, r, l * sizeof(size_t)); } size_t *future = data + l; if (s != NULL) { memcpy(future, s, l * sizeof(size_t)); } accumulate(series, l, n, m, b, history, future, max_r, max_s, box, err); if (inform_failed(err)) { if (allocate) free(box); box = NULL; } free(data); return box; }
void set_arguments(char** argv, int argc){ check_arguments(argc); flag_debug = strcmp(argv[1], "on")? 0 : 1; flag_echo = strcmp(argv[2], "on")? 0 : 1; init_stack_size = atoi(argv[3]); init_heap_size = atoi(argv[4]); entry_point = argv[5]; file_init_name = argv[6]; }
int lua_servo_set_output_pwm(lua_State *L) { check_arguments(L, 2, "set_output_pwm"); const SRV_Channel::Aux_servo_function_t servo_function = (SRV_Channel::Aux_servo_function_t)luaL_checkinteger(L, -2); luaL_argcheck(L, ((servo_function >= SRV_Channel::Aux_servo_function_t::k_scripting1) && (servo_function <= SRV_Channel::Aux_servo_function_t::k_scripting16)), 2, "function out of range"); const int output = luaL_checknumber(L, -1); luaL_argcheck(L, ((output >= 0) && (output <= UINT16_MAX)), 2, "output out of range"); SRV_Channels::set_output_pwm((SRV_Channel::Aux_servo_function_t)servo_function, output); return 0; }
int main(int argc, const char *const argv[]) { int memory_to_allocate = 0; int timeout = 0; check_arguments(argc, argv); memory_to_allocate = get_memory_to_allocate(argv); timeout = get_timeout(argv); signal(SIGTERM, kill_handler); on_allocate(memory_to_allocate); sleep(timeout); on_free(); return 0; }
int main(int argc, const char *argv[]) { check_arguments(argc, argv); const char *app_key = argv[1]; const char *app_user = argv[2]; int file_stat; g_session session; g_request *request; get_session(&session); if (validate_session(session) != 0) { terminate("Not a git session!\n"); } request = get_request(session.ssh_command); if (request == NULL) { terminate("Invalid git request.\n"); } file_stat = check_path(request->repo_path); if (file_stat != 0) { free(request); return 1; } if (strlen(GITPROXY_EXEC) == 0) { fprintf(stderr, "No replace command defined\n"); free(request); return 1; } setenv("GITPROXY_USER", app_user, 1); setenv("GITPROXY_KEY", app_key, 1); setenv("GITPROXY_ROOT", GIT_ROOT, 1); setenv("GITPROXY_REPO", request->repo, 1); setenv("GITPROXY_ACTION", request->action, 1); setenv("GITPROXY_COMMAND", request->command, 1); setenv("GITPROXY_IS_READ", request->is_read ? "1" : "0", 1); setenv("GITPROXY_IS_WRITE", request->is_write ? "1" : "0", 1); free(request); int exitcode = execlp(GITPROXY_EXEC, GITPROXY_EXEC, GITPROXY_EXEC_ARG, 0); return exitcode; }
int main(int argc, char* argv[]) { check_arguments(argc, argv); SaveDepth si; string path = argv[1]; if (path[path.size() - 1] == '/'){ path.erase(path.begin() + path.size()-1); } si.save_path_ = path + '/'; si.calib_path_ = argv[2]; si.image_topic_name_ = argv[3]; si.pc2_topic_name_ = argv[4]; si.is_image_ = false; si.is_pc2_ = false; si.read_CalibFile(); si.depthConverter(argc, argv); cout << "finish\n"; return 0; }
static void execute_expression(int line, int check, char *args[], int argcount, mipv6_conf_item_t *items) { mipv6_conf_item_t *item = NULL; int i, count; item = items; while (1) { if (item->name == NULL) { item = NULL; break; } if (strcmp(item->name, args[0]) == 0) break; item++; } if (check) { if (item == NULL) exit_with_error_f(line, "Unknown configuration item " "'%s'", args[0]); count = 0; for (i = 0; i < MIPV6_CONF_MAX_PARAMS; i++) { if (item->params[i] != MIPV6_PARAM_T_NONE) count++; else break; } if (count != (argcount - 1)) exit_with_error_f(line, "Argument count mismatch " "for '%s', expected %i", args[0], count); check_arguments(line, args, count, item); } else { item->handler(item, args, argcount); } }
void main(int argc, char **argv) { /*--- Add rng_type as the argument to the new interface ---*/ int rng_type; int seed, param, block_size, discard_blocks, use_blocks; /****************** Read and check Arguments ********************/ if(argc==8 ) /*--- increase argc by 1 ---*/ { argv++; rng_type = atoi(*argv++); /*--- get rng_type ---*/ seed = atoi(*argv++); param = atoi(*argv++); lattice_size = atoi(*argv++); block_size = atoi(*argv++); discard_blocks = atoi(*argv++); use_blocks = atoi(*argv++); check_arguments(lattice_size, block_size, discard_blocks, use_blocks); #ifdef PARALLEL printf("Wolff Algorithm with Parallel RNG\n"); #else printf("Wolff Algorithm with Serial RNG\n"); #endif printf("lattice_size = %d, block_size = %d, discard_blocks = %d, use_blocks = %d\n", lattice_size, block_size, discard_blocks, use_blocks); } else { printf("USAGE: %s rng_type seed param lattice_size block_size discard_blocks use_blocks\n", argv[0]); exit(-1); } minitialize(rng_type, seed, param, use_blocks); /* initalize data */ /************** 'Thermalize' system so that results are not influenced by the initial onditions *************/ thermalize(block_size, discard_blocks); /********** Perform the actual Wolff algorithm calculations *********/ wolff(block_size, use_blocks); }
int main( int argc, char * const argv[]){ int gai_error = 0; if(check_arguments(argc,argv)!=0) { exit(EXIT_FAILURE); } register_signal_handler(); memset(&hints,0,sizeof(struct addrinfo)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if( (gai_error = getaddrinfo(NULL, port, &hints, &res)) ){ print_error("getaddrinfo: %s",gai_strerror(gai_error)); exit(gai_error); } socket_fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if( socket_fd == -1 ) { print_error("%s",strerror(errno)); exit(EXIT_FAILURE); } if( bind(socket_fd,res->ai_addr, res->ai_addrlen) == -1) { print_error("%s",strerror(errno)); exit(EXIT_FAILURE); } if( listen(socket_fd, BACKLOG) == -1) { print_error("%s",strerror(errno)); exit(EXIT_FAILURE); } while(accept_connection()==0); return 0; }
void main(int argc, char **argv) { int seed, param, block_size, discard_blocks, use_blocks; /****************** Read and check Arguments ********************/ if(argc==7 ) { argv++; seed = atoi(*argv++); param = atoi(*argv++); lattice_size = atoi(*argv++); block_size = atoi(*argv++); discard_blocks = atoi(*argv++); use_blocks = atoi(*argv++); check_arguments(lattice_size, block_size, discard_blocks, use_blocks); #ifdef PARALLEL printf("Wolff Algorithm with Parallel RNG\n"); #else printf("Wolff Algorithm with Serial RNG\n"); #endif printf("lattice_size = %d, block_size = %d, discard_blocks = %d, use_blocks = %d\n", lattice_size, block_size, discard_blocks, use_blocks); } else { printf("USAGE: %s seed param lattice_size block_size discard_blocks use_blocks\n", argv[0]); exit(-1); } initialize(seed, param, use_blocks); /* initalize data */ /************** 'Thermalize' system so that results are not influenced by the initial onditions *************/ thermalize(block_size, discard_blocks); /********** Perform the actual Wolff algorithm calculations *********/ wolff(block_size, use_blocks); }
int main(int argc, char **argv) { gboolean ret = TRUE; RawCmdOptions options; GError *err = NULL; // Parse arguments parse_arguments(&argc, &argv, &options, &err); if (err) { g_printerr("%s\n", err->message); print_usage(); g_error_free(err); exit(EXIT_FAILURE); } // Set logging g_log_set_default_handler(cr_log_fn, NULL); if (options.verbose) { // Verbose mode GLogLevelFlags levels = G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_WARNING; g_log_set_handler(NULL, levels, cr_log_fn, NULL); g_log_set_handler("C_CREATEREPOLIB", levels, cr_log_fn, NULL); } else { // Standard mode GLogLevelFlags levels = G_LOG_LEVEL_DEBUG; g_log_set_handler(NULL, levels, cr_null_log_fn, NULL); g_log_set_handler("C_CREATEREPOLIB", levels, cr_null_log_fn, NULL); } // Print version if required if (options.version) { printf("Version: %d.%d.%d\n", CR_VERSION_MAJOR, CR_VERSION_MINOR, CR_VERSION_PATCH); exit(EXIT_SUCCESS); } // Check arguments check_arguments(&options, &err); if (err) { g_printerr("%s\n", err->message); print_usage(); g_error_free(err); exit(EXIT_FAILURE); } g_thread_init(NULL); // Initialize threading // Prepare list of tasks to do gchar *repodatadir = NULL; GSList *modifyrepotasks = NULL; if (!options.batchfile && !options.remove && argc == 3) { // three arguments (prog, metadata, repodata_dir) repodatadir = argv[2]; ret = cmd_options_to_task(&modifyrepotasks, &options, argv[1], &err); } else if (options.batchfile && argc == 2) { // two arguments (prog, repodata_dir) repodatadir = argv[1]; ret = cr_modifyrepo_parse_batchfile(options.batchfile, &modifyrepotasks, &err); } else if (!options.batchfile && options.remove && argc == 2) { // two arguments (prog, repodata_dir) repodatadir = argv[1]; ret = cmd_options_to_task(&modifyrepotasks, &options, NULL, &err); } else { // Bad arguments print_usage(); exit(EXIT_FAILURE); } if (!ret) { g_printerr("%s\n", err->message); g_error_free(err); exit(EXIT_FAILURE); } // Process the tasks ret = cr_modifyrepo(modifyrepotasks, repodatadir, &err); cr_slist_free_full(modifyrepotasks, (GDestroyNotify)cr_modifyrepotask_free); if (!ret) { g_printerr("%s\n", err->message); g_error_free(err); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
/* main */ int main(int argc, char **argv){ signal(SIGCHLD, SIG_IGN); int i = 0; /*********************************************/ /* Service Table that holds all the services */ /*********************************************/ char *service_table[SERVICE_TABLE_SIZE]; for(i = 0; i<SERVICE_TABLE_SIZE; i++){ service_table[i] = (char*)malloc(500*sizeof(char)); } /* copy each service to the table */ strcpy(service_table[0], "get_int int"); strcpy(service_table[1], "add int int"); strcpy(service_table[2], "sub int int"); strcpy(service_table[3], "mul int int"); strcpy(service_table[4], "a int int"); strcpy(service_table[5], "b int int"); strcpy(service_table[6], "c int int"); strcpy(service_table[7], "d int int"); strcpy(service_table[8], "e int int"); strcpy(service_table[9], "f int int"); /************************/ /* end of Service Table */ /************************/ /******************************************************/ /* service table that hold its own available services */ /******************************************************/ char *own_service_table[SERVICE_TABLE_SIZE]; for(i = 0; i<SERVICE_TABLE_SIZE; i++){ own_service_table[i] = (char*)malloc(500*sizeof(char)); } /* copy each service to the own service table (different in each server) */ int new_argc; char **new_argv; check_arguments(argc, argv, &new_argc, &new_argv, service_table, own_service_table); /************************/ /* end of service table */ /************************/ /****************************************/ /* create service list of other servers */ /****************************************/ struct ServiceList *service_list = new_empty_ServiceList(); /*******************************/ /* end of creating ServiceList */ /*******************************/ /* declaration */ int listening_sockfd, client_sockfd; socklen_t client_sock_len; char* buff; struct sockaddr_in server_address, client_address; int port_no = 20000; /* create listening socket */ if ( (listening_sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 ){ error("error in creating listening socket"); } /* bind option */ int yes = 1; if (setsockopt(listening_sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { error("error in setsockopt"); } server_address.sin_family = AF_INET; server_address.sin_addr.s_addr = htonl(INADDR_ANY); //server_address.sin_addr.s_addr = inet_addr("192.168.1.120"); server_address.sin_port = htons(port_no); /* bind */ while( (bind(listening_sockfd, (struct sockaddr *)&server_address, (socklen_t)sizeof(server_address))) == -1 ){ ++port_no; server_address.sin_port = htons(port_no); if (port_no >1000000){ error("bind error.\n"); } } pthread_mutex_init(&handler_mutex, NULL); pthread_mutex_init(&sender_mutex, NULL); /******************************/ /* get the name of the server */ /******************************/ char host_info[SEND_MAX]; char service_info[SEND_MAX]; //getnameinfo((struct sockaddr*)&server_address, sizeof(server_address),host_info, sizeof host_info, service_info, sizeof service_info, 0); if(gethostname(host_info, SEND_MAX)!=0){ error("error in gethostname"); } to_l_case(host_info); /**********************/ /* end of getnameinfo */ /**********************/ /***********************/ /* print promt message */ /***********************/ print_promt_message(port_no, own_service_table, host_info); /*************/ /* end promt */ /*************/ /*********************************************************/ /* contact and send information to all the other servers */ /*********************************************************/ /* params for contact_all_other_servers */ char *own_server_name = (char*)malloc(500*sizeof(char)); char *port = (char*)malloc(100*sizeof(char)); sprintf(port, "%d", port_no); //strcpy(own_server_name, "localhost:"); strcpy(own_server_name, host_info); strcat(own_server_name, ":"); strcat(own_server_name, port); /* contact_all_other_servers */ contact_all_other_servers(own_server_name, new_argc, new_argv, own_service_table, service_list); free(own_server_name); free(port); /************************************/ /* end of contact_all_other_servers */ /************************************/ /* listening to client */ if (listen(listening_sockfd, 20) == -1) error("error in listen\n"); printf("Listening on port: %d\n\n", port_no); while(TRUE){ client_sock_len = sizeof(client_address); client_sockfd = accept(listening_sockfd, (struct sockaddr*)&client_address, &client_sock_len); printf("a connection established\n"); /********************************/ /* thread to handle the request */ /********************************/ pthread_t tid; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); HandlerArgs *handlerArgs = (HandlerArgs*)malloc(sizeof(HandlerArgs)); handlerArgs->sockfd = client_sockfd; handlerArgs->own_service_table = own_service_table; handlerArgs->service_list = service_list; handlerArgs->own_server_name = (char*)malloc(1000*sizeof(char)); char *port = (char*)malloc(1000*sizeof(char)); sprintf(port, "%d", port_no); //strcpy(handlerArgs->own_server_name, "localhost:"); strcpy(handlerArgs->own_server_name, host_info); strcat(handlerArgs->own_server_name, ":"); strcat(handlerArgs->own_server_name, port); free(port); /* create the thread */ pthread_create(&tid, &attr, (void*)handle_request, (void*)handlerArgs); /*****************************/ /* end of the handler thread */ /*****************************/ } close(listening_sockfd); return 0; }
int *inform_black_box_parts(int const *series, size_t l, size_t n, int const *b, size_t const *parts, size_t nparts, int *box, inform_error *err) { if (check_arguments(series, l, 1, n, b, NULL, NULL, err)) { return NULL; } if (parts == NULL || nparts < 1) { INFORM_ERROR_RETURN(err, INFORM_EPARTS, NULL); } else { size_t *sorted_parts = malloc(l * sizeof(size_t)); memcpy(sorted_parts, parts, l * sizeof(size_t)); qsort(sorted_parts, l, sizeof(size_t), compare_ints); if (sorted_parts[0] != 0) { free(sorted_parts); INFORM_ERROR_RETURN(err, INFORM_EPARTS, NULL); } for (size_t i = 1; i < l; ++i) { int x = (int)(sorted_parts[i] - sorted_parts[i-1]); if (x != 0 && x != 1) { free(sorted_parts); INFORM_ERROR_RETURN(err, INFORM_EPARTS, NULL); } } if (sorted_parts[l-1] + 1 != nparts) { free(sorted_parts); INFORM_ERROR_RETURN(err, INFORM_EPARTS, NULL); } free(sorted_parts); } int allocate = (box == NULL); if (allocate) { box = malloc(nparts * (1 + n) * sizeof(int)); if (box == NULL) { INFORM_ERROR_RETURN(err, INFORM_ENOMEM, NULL); } } int *partitioned = box; int *bases = partitioned + nparts * n; if (nparts == l) { memcpy(partitioned, series, l * n * sizeof(int)); for (size_t i = 0; i < l; ++i) bases[i] = b[i]; } else { size_t *members = malloc(l * sizeof(size_t)); if (members == NULL) { if (allocate) free(box); INFORM_ERROR_RETURN(err, INFORM_ENOMEM, NULL); } for (size_t i = 0; i < l; ++i) members[i] = -1; for (size_t i = 0; i < nparts; ++i) { size_t k = 0; for (size_t j = 0; j < l; ++j) { if (parts[j] == i) { members[k++] = j; } } if (k == 1) { memcpy(partitioned + n*i, series + n*members[0], n*sizeof(int)); bases[i] = b[members[0]]; } else { int *subbases = malloc(k * (1 + n) * sizeof(int)); int *subseries = subbases + k; if (subseries == NULL) { free(members); if (allocate) free(box); INFORM_ERROR_RETURN(err, INFORM_ENOMEM, NULL); } bases[i] = 1; for (size_t j = 0; j < k; ++j) { subbases[j] = b[members[j]]; bases[i] *= subbases[j]; for (size_t p = 0; p < n; ++p) { subseries[p + n*j] = series[p + n*members[j]]; } } inform_black_box(subseries, k, 1, n, subbases, NULL, NULL, partitioned + n*i, err); free(subbases); if (inform_failed(err)) { free(members); if (allocate) free(box); return NULL; } } for (size_t i = 0; i < l; ++i) members[i] = -1; } free(members); } return box; }
int main(int argc, char *argv[]) { int size = 0; int shared_memory_key = -1; int sem_r = -1; int sem_w = -1; int cnt = -1; int buf = -1; int *shared_memory = NULL; errno = 0; /* check command line arguments */ if ((size = check_arguments(argc, argv))==ERROR) { print_usage(); return ERROR; } /* get both semaphores */ if((shared_memory_key = get_shmem(SHMEMKEY, size)) == -1) { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); return ERROR; } attach_shmem(shared_memory_key, &shared_memory, SEMKEY_R); if(shared_memory == NULL) { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); return ERROR; } /* initialize shared memory */ if((sem_r= get_semid(SEMKEY_R, 0)) == ERROR) { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); return ERROR; } /* attach memory to process */ if((sem_w= get_semid(SEMKEY_W, size))==ERROR) { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); return ERROR; } /* start the reader */ do { if(P(sem_r)==-1) { if(errno == EINTR) { /*EINTR sagt uns, dass ein Interrupt vorliegt. */ errno = 0; continue; } else { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); fprintf(stderr, "Error bei P, reader. %s", strerror(errno)); return ERROR; } } cnt++; cnt = cnt%size; buf = (*(shared_memory+cnt)); if(V(sem_w)==-1) { if(errno == EINTR) { /*EINTR sagt uns, dass ein Interrupt vorliegt. */ errno = 0; continue; } else { clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); fprintf(stderr, "Error bei V, reader. %s", strerror(errno)); return ERROR; } } if(buf!=EOF) { /* Do ouput and check for Output error */ if (fputc(buf, stdout) == EOF) { fprintf(stderr, "Fehler fputc"); clean_up(sem_r, &shared_memory, shared_memory_key, ERROR); return ERROR; } } }while(buf!=EOF); errno = 0; if(fflush(stdout)!=0) { fprintf(stderr, "fflush failed"); if(errno != 0) { fprintf(stderr, "%s", strerror(errno)); return ERROR; } } detach_shmem(shared_memory_key,SEMKEY_R); clean_up(sem_r, &shared_memory, shared_memory_key, SEMKEY_R); return 0; }
void parse_arguments(int argc, char *argv[]) { int opt; while ((opt = getopt(argc, argv, "s:p:t:m:l:w:d:D:j:c:")) != -1) { switch (opt) { case 's': // Solution ID oj_solution.sid = atoi(optarg); break; case 'p': // Problem ID oj_solution.pid = atoi(optarg); break; case 'l': // Language ID oj_solution.lang = atoi(optarg); break; case 'j': // judge type oj_solution.judge_type = atoi(optarg); break; case 't': // Time limit oj_solution.time_limit = (unsigned int) atoi(optarg); break; case 'm': // Memory limit oj_solution.memory_limit = (unsigned int) atoi(optarg); break; case 'w': case 'd': // Work directory if (realpath(optarg, work_dir_root) == nullptr) { fprintf(stderr, "resolve work dir failed:%s\n", strerror(errno)); exit(EXIT_BAD_PARAM); } break; case 'D': // Data directory if (realpath(optarg, data_dir_root) == nullptr) { fprintf(stderr, "resolve data dir failed: %s\n", strerror(errno)); exit(EXIT_BAD_PARAM); } break; case 'c': // Contest ID oj_solution.cid = atoi(optarg); break; default: fprintf(stderr, "unknown option provided: -%c %s\n", opt, optarg); exit(EXIT_BAD_PARAM); } } char buff[PATH_SIZE]; snprintf(buff, PATH_SIZE, "%s/oj-judge.log", work_dir_root); check_and_rename_log(buff); log_open(buff); check_arguments(); snprintf(oj_solution.work_dir, PATH_SIZE, "%s/%d", work_dir_root, oj_solution.sid); snprintf(oj_solution.data_dir, PATH_SIZE, "%s/%d", data_dir_root, oj_solution.pid); char source_file[PATH_SIZE]; snprintf(source_file, PATH_SIZE, "%s/Main.%s", oj_solution.work_dir, lang_ext[oj_solution.lang]); if (access(source_file, F_OK) == -1) { FM_LOG_FATAL("Source code file is missing."); exit(EXIT_NO_SOURCE_CODE); } if (oj_solution.lang == LANG_JAVA) { oj_solution.memory_limit *= java_memory_factor; oj_solution.time_limit *= java_time_factor; } else if (oj_solution.lang == LANG_PYTHON27 || oj_solution.lang == LANG_PYTHON3) { oj_solution.memory_limit *= python_memory_factor; oj_solution.time_limit *= python_time_factor; } else if (oj_solution.lang == LANG_KOTLIN) { oj_solution.memory_limit *= kotlin_memory_factor; oj_solution.time_limit *= kotlin_time_factor; } snprintf(buff, PATH_SIZE, "%s/last", work_dir_root); unlink(buff); if (symlink(oj_solution.work_dir, buff) == -1) { FM_LOG_NOTICE("make symlink for %s failed: %s", buff, strerror(errno)); } print_solution(); }
int main(int argc,char* argv[]){ char host_name[AM_MAX_MESSAGE]; BZERO(host_name,AM_MAX_MESSAGE); char num_avatars_str[AM_MAX_MESSAGE]; BZERO(num_avatars_str,AM_MAX_MESSAGE); char maze_difficulty_str[AM_MAX_MESSAGE]; BZERO(maze_difficulty_str,AM_MAX_MESSAGE); int num_avatars; int maze_difficulty; //calling function that will retrieve the arguments from the command line retrieve_arguments(argc,argv,host_name,num_avatars_str, maze_difficulty_str); //checking validity of those arguments int check = check_arguments(argc,host_name,num_avatars_str, maze_difficulty_str); if (check!=0){ printf("-n Usage: [nAvatars (0-10)]\n"); printf("-d [maze difficulty (0-9)]\n"); printf("-h [hostname (stratton.cs.dartmouth.edu)]\n"); return 1; } num_avatars=atoi(num_avatars_str); maze_difficulty=atoi(maze_difficulty_str); int sockfd; struct sockaddr_in servaddr; //establishing connection with the server and //constructing AM_INITIALIZE message AM_MESSAGE* sendline=malloc(sizeof(AM_MESSAGE)); MALLOC_CHECK(sendline); sendline->message_type=htonl(AM_INITIALIZE); sendline->msg.initialize.nAvatars=htonl(num_avatars); sendline->msg.initialize.Difficulty=htonl(maze_difficulty); AM_MESSAGE* recvline=malloc(sizeof(AM_MESSAGE)); MALLOC_CHECK(recvline); //creating a socket if ((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){ printf("Failed to create the socket\n"); return 1; } //retrieve server IP from the hostname char serverIP[AM_MAX_MESSAGE]; BZERO(serverIP,AM_MAX_MESSAGE); check=retrieveIP(host_name,serverIP); if (check!=0){ return 1; } //creation of the socket memset(&servaddr,0,sizeof(servaddr)); servaddr.sin_family=AF_INET; servaddr.sin_addr.s_addr=inet_addr(serverIP); servaddr.sin_port=htons(AM_SERVER_PORT); //establishing connection with the server if (connect(sockfd,(struct sockaddr *) &servaddr,sizeof(servaddr))<0){ printf("Could not connect to the server\n"); return 1; } //sending initialization message to the server send(sockfd,sendline,sizeof(AM_MESSAGE),0); //need to add more params if (recv(sockfd,recvline,sizeof(AM_MESSAGE),0)==0){ printf("Server terminated\n"); free(sendline); return 1; } if (ntohs(recvline->message_type) & AM_ERROR_MASK){ printf("Corrupted message from the server\n"); return 1; } free(sendline); //retrieving MazePort unsigned int maze_port=ntohl(recvline->msg.initialize_ok.MazePort); char MazePort[AM_MAX_MESSAGE]; BZERO(MazePort,AM_MAX_MESSAGE); snprintf(MazePort,AM_MAX_MESSAGE,"%d",maze_port); //getting maze dimensions unsigned int width=ntohl(recvline->msg.initialize_ok.MazeWidth); unsigned int height=ntohl(recvline->msg.initialize_ok.MazeHeight); //Creating shared map object //so that all of the avatars could share knowledge of the maze create_shared_map(width,height); free(recvline); //preparing to create a log file char logFileCommand[AM_MAX_MESSAGE]; BZERO(logFileCommand,AM_MAX_MESSAGE); char fileName[AM_MAX_MESSAGE]; BZERO(fileName,AM_MAX_MESSAGE); char *userName; userName=getenv("USER"); //getting user name to output in the log file if (userName==NULL){ printf("failed to retrieve user name\n"); return 1; }else{ strncpy(fileName,"Amazing_",AM_MAX_MESSAGE); strncat(fileName,userName,AM_MAX_MESSAGE); strncat(fileName,"_",AM_MAX_MESSAGE); strncat(fileName,num_avatars_str,AM_MAX_MESSAGE); strncat(fileName,"_",AM_MAX_MESSAGE); strncat(fileName,maze_difficulty_str,AM_MAX_MESSAGE); strncat(fileName,".log",AM_MAX_MESSAGE); } //creating a log file strncpy(logFileCommand,"echo -n "" > ",AM_MAX_MESSAGE); strncat(logFileCommand,fileName,AM_MAX_MESSAGE); system(logFileCommand); char date[AM_MAX_MESSAGE]; BZERO(date,AM_MAX_MESSAGE); time_t rawtime; struct tm *timeinfo; //getting current data and time time(&rawtime); timeinfo=localtime(&rawtime); strftime(date,AM_MAX_MESSAGE,"%Y-%m-%d-%H-%M-%S",timeinfo); //adding first line to the log file BZERO(logFileCommand,AM_MAX_MESSAGE); strncpy(logFileCommand,"echo ' ",AM_MAX_MESSAGE); strncat(logFileCommand,userName,AM_MAX_MESSAGE); strncat(logFileCommand,", ",AM_MAX_MESSAGE); strncat(logFileCommand,MazePort,AM_MAX_MESSAGE); strncat(logFileCommand,", ",AM_MAX_MESSAGE); strncat(logFileCommand,date,AM_MAX_MESSAGE); strncat(logFileCommand,";'",AM_MAX_MESSAGE); strncat(logFileCommand," >> ",AM_MAX_MESSAGE); strncat(logFileCommand,fileName,AM_MAX_MESSAGE); system(logFileCommand); //launching amazing client as many times as the number of avatars that //the iser inputted in the command line int avatar_id=0; for (int i=0;i<num_avatars;i++){ char amazingCommand[AM_MAX_MESSAGE]; BZERO(amazingCommand,AM_MAX_MESSAGE); char avatar_id_str[AM_MAX_MESSAGE]; BZERO(avatar_id_str,AM_MAX_MESSAGE); snprintf(avatar_id_str,AM_MAX_MESSAGE,"%d",avatar_id); strncpy(amazingCommand,"./amazing_client ",AM_MAX_MESSAGE); strncat(amazingCommand,avatar_id_str,AM_MAX_MESSAGE); strncat(amazingCommand," ",AM_MAX_MESSAGE); strncat(amazingCommand,num_avatars_str,AM_MAX_MESSAGE); strncat(amazingCommand," ",AM_MAX_MESSAGE); strncat(amazingCommand,maze_difficulty_str,AM_MAX_MESSAGE); strncat(amazingCommand," ",AM_MAX_MESSAGE); strncat(amazingCommand,serverIP,AM_MAX_MESSAGE); strncat(amazingCommand," ",AM_MAX_MESSAGE); strncat(amazingCommand,MazePort,AM_MAX_MESSAGE); strncat(amazingCommand," ",AM_MAX_MESSAGE); strncat(amazingCommand,fileName,AM_MAX_MESSAGE); strncat(amazingCommand," &",AM_MAX_MESSAGE); system(amazingCommand); avatar_id++; } //waits a little bit for children to terminate system("sleep 1"); return 0; }
int main(int argc, char **argv) { int ret_status; /* Initialize some global values */ /* fprintf(stderr,"hyper:main:entered\n");*/ gArgc = argc; gArgv = argv; gIsEndOfOutput = 1; /* fprintf(stderr,"hyper:main:calling check_arguments\n");*/ check_arguments(); /* fprintf(stderr,"hyper:main:returned check_arguments\n");*/ /* * initialize the hash tables for the files and the windows and images */ /* fprintf(stderr,"hyper:main:calling init_hash\n");*/ init_hash(); /* fprintf(stderr,"hyper:main:returned init_hash\n");*/ /* * initialize the parser keyword hash table */ /* fprintf(stderr,"hyper:main:calling parser_init\n");*/ parser_init(); /* fprintf(stderr,"hyper:main:returned parser_init\n");*/ /* fprintf(stderr,"hyper:main:calling read_ht_db\n");*/ read_ht_db(&init_page_hash, &init_macro_hash, &init_patch_hash); /* fprintf(stderr,"hyper:main:returned read_ht_db\n");*/ /* * Now initialize x. This includes opening the display, setting the * screen and display global values, and also gets all the fonts and * colors we will need. */ if (!make_input_file && !gmake_record_file && !gverify_record_file) { /* fprintf(stderr,"hyper:main:calling initializeWindowSystem\n");*/ initializeWindowSystem(); /* fprintf(stderr,"hyper:main:returned initializeWindowSystem\n");*/ /* * Initialize some of the global values used by the input string * routines */ /* fprintf(stderr,"hyper:main:calling init_keyin\n");*/ init_keyin(); /* fprintf(stderr,"hyper:main:returned init_keyin\n");*/ /* * regardless of what else happened, we should always pop up an * initial window. */ /* fprintf(stderr,"hyper:main:calling init_top_window\n");*/ ret_status = init_top_window("RootPage"); /* fprintf(stderr,"hyper:main:returned init_top_window\n");*/ gParentWindow = gWindow; if (ret_status == -1) { fprintf(stderr, "(HyperDoc) Could not find RootPage for top-level window.\n"); exit(-1); } /* * Tell it how to handle the user defined signals I may get */ bsdSignal(SIGUSR2, sigusr2_handler,RestartSystemCalls); bsdSignal(SIGUSR1, SIG_IGN,RestartSystemCalls); #if defined(BSDplatform) || defined(MACOSXplatform) bsdSignal(SIGCHLD, sigcld_handler,RestartSystemCalls); #else bsdSignal(SIGCLD, sigcld_handler,RestartSystemCalls); #endif bsdSignal(SIGINT, SIG_IGN,RestartSystemCalls); /* * Now go to the main event loop. I will never return, so just end * the main routine after that */ /* * make an input file if requested */ } else { /* * Try to establish all the socket connections I need. If I am an * is_fricas_server and the routine fails, it will exit for me */ /* fprintf(stderr,"hyper:main:in else case\n");*/ /* fprintf(stderr,"hyper:main:calling make_server_connections\n");*/ make_server_connections(); /* fprintf(stderr,"hyper:main:returned make_server_connections\n");*/ if (make_input_file) ht2_input(); if (gmake_record_file) make_record(); if (gverify_record_file) verify_record(); exit(0); } /* * Try to establish all the socket connections I need. If I am an * is_fricas_server and the routine fails, it will exit for me */ /* fprintf(stderr,"hyper:main:calling make_server_connections\n");*/ make_server_connections(); /* fprintf(stderr,"hyper:main:returned make_server_connections\n");*/ /* fprintf(stderr,"hyper:main:calling mainEventLoop\n");*/ mainEventLoop(); /* fprintf(stderr,"hyper:main:returned mainEventLoop\n");*/ return 0; }
int main(int argc, char **argv) { gboolean ret = TRUE; RawCmdOptions options; GError *err = NULL; // Parse arguments parse_arguments(&argc, &argv, &options, &err); if (err) { g_printerr("%s\n", err->message); print_usage(); g_error_free(err); exit(EXIT_FAILURE); } // Set logging cr_setup_logging(FALSE, options.verbose); // Print version if required if (options.version) { printf("Version: %s\n", cr_version_string_with_features()); exit(EXIT_SUCCESS); } // Check arguments check_arguments(&options, &err); if (err) { g_printerr("%s\n", err->message); print_usage(); g_error_free(err); exit(EXIT_FAILURE); } // Emit debug message with version g_debug("Version: %s", cr_version_string_with_features()); // Prepare list of tasks to do gchar *repodatadir = NULL; GSList *modifyrepotasks = NULL; if (!options.batchfile && !options.remove && argc == 3) { // three arguments (prog, metadata, repodata_dir) repodatadir = argv[2]; ret = cmd_options_to_task(&modifyrepotasks, &options, argv[1], &err); } else if (options.batchfile && argc == 2) { // two arguments (prog, repodata_dir) repodatadir = argv[1]; ret = cr_modifyrepo_parse_batchfile(options.batchfile, &modifyrepotasks, &err); } else if (!options.batchfile && options.remove && argc == 2) { // two arguments (prog, repodata_dir) repodatadir = argv[1]; ret = cmd_options_to_task(&modifyrepotasks, &options, NULL, &err); } else { // Bad arguments print_usage(); exit(EXIT_FAILURE); } if (!ret) { g_printerr("%s\n", err->message); g_error_free(err); exit(EXIT_FAILURE); } // Process the tasks ret = cr_modifyrepo(modifyrepotasks, repodatadir, &err); cr_slist_free_full(modifyrepotasks, (GDestroyNotify)cr_modifyrepotask_free); if (!ret) { g_printerr("%s\n", err->message); g_error_free(err); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
void DigitalSequence_advanced::init(C_matrix *C, UL_int dim, UL_int offset) { L_int i,k; UL_int base; UL_int times; UL_int base_pow_times; #ifdef DEBUG check_own_types(); #endif R = C->R; base = R->base; times = get_times_for_base(base); VCM = new VectorMatrix(C,times); VR = new VectorRing(R,times); base_pow_times = VR->base_pow_times; inv_base_pow_times = 1.0/((double)base_pow_times); CM = C; NumDigits = VCM->NumDigits; NumVectors = VCM->NumVectors; dimension = dim; check_arguments(); n0 = offset; n = n0; BufferFull = 0; BufferLen = get_BufferLenForBase(base_pow_times); log_BufferLen = get_log_BufferLenForBase(base);//base_pow_times); init_psi_and_eta(); ////////////////////////////////////////////////////////////////////////////// // get new Counter and DigitBuffer ////////////////////////////////////////////////////////////////////////////// N = new Counter(R,NumDigits,psi); DigitBuffer = new RVector ** [BufferLen]; if(!(N&&DigitBuffer)) { cerr << "Error: Out of memory!" << endl; exit(1); } for(k=0;k<BufferLen;k++) { DigitBuffer[k] = new RVector * [dimension]; if(!(DigitBuffer[k])) { cerr << "Error: Out of memory! "; cerr << "(DigitalSequence_advanced::init())" << endl; exit(1); } for(i=0;i<dimension;i++) { DigitBuffer[k][i] = new RVector[NumVectors]; if(!(DigitBuffer[k][i])) { cerr << "Error: Out of memory! "; cerr << "(DigitalSequence_advanced::init())" << endl; exit(1); } } } clear_DigitBuffer(); ////////////////////////////////////////////////////////////////////////////// // calculate the next vector, actualize memory consumption ////////////////////////////////////////////////////////////////////////////// N->set(n0); operator++(); memory += sizeof(DigitalSequence_advanced); memory += sizeof(UL_int)*dimension*NumVectors*BufferLen; }