int Connected_OPEN(client_t *client, textbuf *buf, CTP_head_t head) { CTP_OPEN_t mesg; int rv = recv_mesg(client->sockfd, &mesg, head); if (rv < 1) return rv; /* check for correct client id */ if (mesg.client_id != client->id) { free_mesg(mesg); return -1; } /* check file id * this server only supports a "default" file */ if (mesg.file_id != 0) { free_mesg(mesg); send_err(client, BAD_FILE_ID); return 1; } free_mesg(mesg); /* transient... */ client->state = Opening; /* build ACKOPEN response */ CTP_ACKOPEN_t response; response.options = new_options(); /* send response */ rv = send_ACKOPEN(client->sockfd, response); free_options(response.options); client->state = Open; if (rv < 1) return rv; /* send STATUS message to all clients */ CTP_STATUS_t status = get_status(buf); client_t *c; for (c = clients; c <= max_active_client; ++c) { if (c->active) send_STATUS(c->sockfd, status); } free_options(status.options); return 1; }
/* * read_config_file - main configuration parsing function. */ int read_config_file( const char *filename, Options *options ) { FILE *f; char line[1024]; int active; int err = 0; int linenum; int bad_options = 0; /* open the configuration file */ if ( (f = fopen( filename, "r" ) ) == NULL ) { free_options( options ); error( "unable to open file '%s': %s", filename, strerror( errno ) ); return(0); } /* initialize the options structure */ initialize_options( options ); active = 1; linenum = 0; /* read the configuration file line by line */ while ( fgets( line, (int)sizeof( line ), f ) ) { /* Update line number counter. */ linenum++; err = process_config_line(options, line, filename, linenum, &active ); if ( err != 0 ) { bad_options++; } if ( err == -1 ) { break; } } /* close the file */ if ( fclose( f ) != 0 ) { error( "unable to close '%s': %s", filename, strerror(errno)); } /* throw an error and exit if we have bad configuration options */ if ( bad_options > 0 ) { error( "%s: terminating, %d bad configuration options", filename, bad_options ); free_options( options ); return(0); } /* set any unset options to their defaults */ fill_default_options( options ); return(1); }
double label_sentence(APPROX_PARAMS *ap, MODEL_PARAMS *mp, SENTENCE *sent) { ASSERT(ap->beam >= 1 && ap->beam < MAX_BEAM); ASSERT(ap->search_br_factor >= 1); OPTION *best_options[MAX_SENT_LEN + 1][MAX_BEAM + 1]; best_options[0][0] = root_prediction(ap, mp, sent); int cand_num = 1; int t; for (t = 1; t < sent->len + 1; t++) { cand_num = search_options(ap, mp, sent, best_options[t-1], cand_num, best_options[t]); ASSERT(cand_num <= ap->beam); } double best_lprob = best_options[sent->len][0]->lprob; pt_fill_sentence(best_options[sent->len][0]->pt, mp, sent); ps_fill_sentence(best_options[sent->len][0]->ps, mp, sent); save_candidates(ap, mp, sent, best_options[sent->len], cand_num); int i; for (i = 0; i < cand_num; i++) { pt_free(&(best_options[sent->len][i]->pt)); ps_free(&(best_options[sent->len][i]->ps)); free_options(best_options[sent->len][i]); } return best_lprob; }
int main(int argc, char **argv) { option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION); option_define_bool("verbose", OPT_OPTIONAL, 0, &verbose, NULL, "verbose output (to stderr)"); option_define_str("blacklist_fields", OPT_OPTIONAL, NULL, NULL, parse_blacklisted_fields, "comma separated list of fields to remove"); option_define_str("encrypted_fields", OPT_OPTIONAL, NULL, NULL, parse_encrypted_fields, "comma separated list of fields to encrypt"); option_define_str("expected_key", OPT_OPTIONAL, NULL, &expected_key, NULL, "key to expect in messages before echoing to clients"); option_define_str("expected_value", OPT_OPTIONAL, NULL, &expected_value, NULL, "value to expect in --expected-key field in messages before echoing to clients"); if (!option_parse_command_line(argc, argv)) { return 1; } if ( !!expected_key ^ !!expected_value ) { fprintf(stderr, "--expected-key and --expected-value must be used together\n"); exit(1); } while (fgets(buf, BUF_SZ, stdin)) { msgRecv++; process_message(buf); } fprintf(stderr, "processed %lu lines, failed to parse %lu of them\n", msgRecv, msgFail); free_options(); free_fields(blacklisted_fields, num_blacklisted_fields); free_fields(encrypted_fields, num_encrypted_fields); return 0; }
void add_to_best_list(APPROX_PARAMS *ap, OPTION **new_b_options, int *new_cand_num, OPTION *to_add) { ASSERT(*new_cand_num < ap->beam || to_add->lprob > new_b_options[ap->beam - 1]->lprob); int i; for (i = *new_cand_num - 1; i >= 0; i--) { if (new_b_options[i]->lprob < to_add->lprob) { new_b_options[i + 1] = new_b_options[i]; } else { new_b_options[i + 1] = to_add; break; } } //should be inserted on the first position if (i == -1) { new_b_options[0] = to_add; } if (*new_cand_num == ap->beam) { pt_free(&(new_b_options[ap->beam]->pt)); ps_free(&(new_b_options[ap->beam]->ps)); free_options(new_b_options[ap->beam]); } else { (*new_cand_num)++; } return; }
static int cleanup(struct archive_read *a) { struct mtree *mtree; struct mtree_entry *p, *q; mtree = (struct mtree *)(a->format->data); p = mtree->entries; while (p != NULL) { q = p->next; free(p->name); free_options(p->options); free(p); p = q; } archive_string_free(&mtree->line); archive_string_free(&mtree->current_dir); archive_string_free(&mtree->contents_name); archive_entry_linkresolver_free(mtree->resolver); free(mtree->buff); free(mtree); (a->format->data) = NULL; return (ARCHIVE_OK); }
int select_profile(struct interface *ifp, const char *profile) { struct if_options *ifo; int ret; ret = 0; ifo = read_config(cffile, ifp->name, ifp->ssid, profile); if (ifo == NULL) { syslog(LOG_DEBUG, "%s: no profile %s", ifp->name, profile); ret = -1; goto exit; } if (profile != NULL) { strlcpy(ifp->profile, profile, sizeof(ifp->profile)); syslog(LOG_INFO, "%s: selected profile %s", ifp->name, profile); } else *ifp->profile = '\0'; free_options(ifp->options); ifp->options = ifo; exit: if (profile) configure_interface1(ifp); return ret; }
/* ARGSUSED */ static void sig_reboot(void *arg) { siginfo_t *siginfo = arg; struct if_options *ifo; int i; syslog(LOG_INFO, "received SIGALRM from PID %d, rebinding", (int)siginfo->si_pid); for (i = 0; i < ifac; i++) free(ifav[i]); free(ifav); ifav = NULL; ifac = 0; for (i = 0; i < ifdc; i++) free(ifdv[i]); free(ifdv); ifdc = 0; ifdv = NULL; ifo = read_config(cffile, NULL, NULL, NULL); add_options(ifo, margc, margv); /* We need to preserve these two options. */ if (options & DHCPCD_MASTER) ifo->options |= DHCPCD_MASTER; if (options & DHCPCD_DAEMONISED) ifo->options |= DHCPCD_DAEMONISED; options = ifo->options; free_options(ifo); reconf_reboot(1, ifc, ifv, 0); }
int Init_CONNECT(client_t *client, textbuf *buf, CTP_head_t head) { /* get the message body */ CTP_CONNECT_t mesg; int rv = recv_mesg(client->sockfd, &mesg, head); if (rv < 1) return rv; /* check version: only support current version */ if (mesg.version != PROTOCOL_VERSION) { free_mesg(mesg); err_and_close(client, UNSUPPORTED_VERSION); return 0; } free_mesg(mesg); /* transient... */ client->state = Version; /* build ACKCONNECT response */ CTP_ACKCONNECT_t response; response.version = PROTOCOL_VERSION; response.client_id = client->id; response.options = new_options(); /* send response */ rv = send_ACKCONNECT(client->sockfd, response); free_options(response.options); client->state = Connected; return rv; }
void free_opt_test(void) { free_options(); CU_ASSERT(options[0] == NULL); CU_ASSERT(options[1] == NULL); CU_ASSERT(options[2] == NULL); }
int Any_SYNC(client_t *client, textbuf *buf, CTP_head_t head) { client_t c; CTP_MOVE_t mesg; int rv = recv_mesg(client->sockfd, &mesg, head); if (rv < 1) return rv; /* check for correct client id */ if (mesg.client_id != client->id) { free_mesg(mesg); return -1; } free_mesg(mesg); /* get STATUS response */ CTP_STATUS_t response = get_STATUS(buf); /* send response */ rv = send_STATUS(client->sockfd, response); free_options(response.options); return rv; }
int main(int argc, char **argv) { if (argc < 3) { usage(); exit(EXIT_FAILURE); } options_t *options = parse_options(argc, argv); // opcoes const char *path = argv[argc-1]; pe_ctx_t ctx; pe_err_e err = pe_load_file(&ctx, path); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } err = pe_parse(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } if (!pe_is_pe(&ctx)) EXIT_ERROR("not a valid PE file"); NODE_PERES *node = discoveryNodesPeres(&ctx); if (node == NULL) { fprintf(stderr, "this file has no resources\n"); return EXIT_SUCCESS; } if (options->all) { showInformations(node); showStatistics(node); extractResources(&ctx, node); } else { if (options->extract) extractResources(&ctx, node); if (options->info) showInformations(node); if (options->statistics) showStatistics(node); } freeNodes(node); // libera a memoria free_options(options); // free err = pe_unload(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } return EXIT_SUCCESS; }
static int process_global_unset(struct archive_read *a, struct mtree_option **global, const char *line) { const char *next; size_t len; line += 6; if (strchr(line, '=') != NULL) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, "/unset shall not contain `='"); return ARCHIVE_FATAL; } for (;;) { next = line + strspn(line, " \t\r\n"); if (*next == '\0') return (ARCHIVE_OK); line = next; len = strcspn(line, " \t\r\n"); if (len == 3 && strncmp(line, "all", 3) == 0) { free_options(*global); *global = NULL; } else { remove_option(global, line, len); } line += len; } }
void print_rep(t_op options) { t_files *tmp; int len; t_op o; tmp = options.files; len = 0; while (tmp != NULL) { if ((tmp->type == 0 || (tmp->type == 3 && options.flag == 0)) && (ft_strcmp(tmp->file_name, ".") != 0 || options.flag == 0) && ft_strcmp(tmp->file_name, "..") != 0) { copy_options(&o, options, tmp->file_name); if (options.flag == 1 || count_files2(options) > 1) ft_printf("\n%s:\n", o.path); get_rep_files(o.path, &o); if (options.maj_r == 1) { print_rep(o); free_options(&o); } } tmp = tmp->next; } }
int main(int argc, char ** argv) { chain_options * ops = parse_ops(argc, argv); corpus_root * root = generate_chain(ops); output_chain(root); free_options(ops); free_chain(root); return EXIT_SUCCESS; }
void tfree_struct(t_tetris *tetris) { free_list_tetri(tetris); delwin(tetris->wgame); delwin(tetris->wscore); delwin(tetris->wnext); free_board(tetris); free_options(tetris); free(tetris->key_tab); }
void free_interface(struct interface *iface) { if (!iface) return; if (iface->state) { free_options(iface->state->options); free(iface->state->old); free(iface->state->new); free(iface->state->offer); free(iface->state); }
void free_interface(struct interface *ifp) { if (ifp == NULL) return; ipv4_free(ifp); dhcp_free(ifp); ipv6_free(ifp); dhcp6_free(ifp); ipv6nd_free(ifp); free_options(ifp->options); free(ifp); }
int Locked_EDIT(client_t *client, textbuf *buf, CTP_head_t head) { CTP_EDIT_t mesg; int rv = recv_mesg(client->sockfd, &mesg, head); if (rv < 1) return rv; /* check for correct client id */ if (mesg.client_id != client->id) { free_mesg(mesg); return -1; } switch (mesg.edit_action) { case INS: rv = tboverwrite(buf, mesg.pos, 0, mesg.data, mesg.datalen); break; case OVR: rv = tboverwrite(buf, mesg.pos, mesg.len, mesg.data, mesg.datalen); break; case DEL: rv = tboverwrite(buf, mesg.pos, mesg.len, NULL, 0); break; } if (rv < 0) { /* reject the edit */ free_mesg(mesg); rv = send_err(client, REJECT_EDIT); } else { /* prepare and send ACKEDIT */ CTP_ACKEDIT_t response; response.options = new_options(); rv = send_ACKEDIT(client->sockfd, response); free_options(response.options); /* relay EDIT to other clients */ client_t *c; for (c = clients; c <= max_active_client; ++c) { if (c != client && c->active) send_EDIT(c->sockfd, mesg); } } free_mesg(mesg); return rv; }
int main (int argc, char **argv) { int error = 1; fence_kdump_opts_t opts; init_options (&opts); if (argc > 1) { get_options (argc, argv, &opts); } else { get_options_stdin (&opts); } openlog ("fence_kdump", LOG_CONS|LOG_PID, LOG_DAEMON); if (opts.action == FENCE_KDUMP_ACTION_OFF) { if (opts.nodename == NULL) { log_error (0, "action 'off' requires nodename\n"); exit (1); } if (get_options_node (&opts) != 0) { log_error (0, "failed to get node '%s'\n", opts.nodename); exit (1); } } if (verbose != 0) { print_options (&opts); } switch (opts.action) { case FENCE_KDUMP_ACTION_OFF: error = do_action_off (&opts); break; case FENCE_KDUMP_ACTION_METADATA: error = do_action_metadata (argv[0]); break; case FENCE_KDUMP_ACTION_MONITOR: error = do_action_monitor (); break; default: break; } free_options (&opts); return (error); }
int main(int ac, char **av) { int ret; struct ospfd *ospfd; int ev_flags = 0; ospfd = alloc_ospfd(); ret = parse_cli_options(ospfd, ac, av); if (ret != SUCCESS) err_msg_die(EXIT_FAILURE, "Can't parse command line"); msg(ospfd, GENTLE, PROGRAMNAME " - " VERSIONSTRING); /* seed pseudo number randon generator */ init_pnrg(ospfd); /* initialize event subsystem. In this case this belongs * to open a epoll filedescriptor */ ospfd->ev = ev_new(); if (!ospfd->ev) err_msg_die(EXIT_FAILURE, "Can't initialize event subsystem"); ret = parse_rc_file(ospfd); if (ret != SUCCESS) err_msg_die(EXIT_FAILURE, "Can't parse configuration file"); ret = init_network(ospfd); if (ret != SUCCESS) err_msg_die(EXIT_FAILURE, "Can't initialize network subsystem"); /* and branch into the main loop * This loop will never return (with the exception of SIGINT or failure * condition) */ ret = ev_loop(ospfd->ev, ev_flags); if (ret != SUCCESS) err_msg_die(EXIT_FAILURE, "Main loop returned unexpected - exiting now"); fini_network(ospfd); free_options(ospfd); ev_free(ospfd->ev); free_ospfd(ospfd); return EXIT_SUCCESS; }
void vpr_free_vpr_data_structures(INOUTP t_arch Arch, INOUTP t_options options, INOUTP t_vpr_setup vpr_setup) { if (vpr_setup.Timing.SDCFile != NULL) { free(vpr_setup.Timing.SDCFile); vpr_setup.Timing.SDCFile = NULL; } free_options(&options); free_circuit(); free_arch(&Arch); free_echo_file_info(); free_output_file_names(); free_timing_stats(); free_sdc_related_structs(); }
static void cleanup(void) { #ifdef DEBUG_MEMORY struct interface *ifp; int i; free(duid); free_options(if_options); if (ifaces) { while ((ifp = TAILQ_FIRST(ifaces))) { TAILQ_REMOVE(ifaces, ifp, next); free_interface(ifp); } free(ifaces); } for (i = 0; i < ifac; i++) free(ifav[i]); free(ifav); for (i = 0; i < ifdc; i++) free(ifdv[i]); free(ifdv); #endif if (!(options & DHCPCD_FORKED)) dev_stop(); if (linkfd != -1) close(linkfd); if (pidfd > -1) { if (options & DHCPCD_MASTER) { if (control_stop() == -1) syslog(LOG_ERR, "control_stop: %m"); } close(pidfd); unlink(pidfile); } #ifdef DEBUG_MEMORY free(pidfile); #endif if (options & DHCPCD_STARTED && !(options & DHCPCD_FORKED)) syslog(LOG_INFO, "exited"); }
void free_search(struct search_t *search) { struct entry_t *ptr = search->result->start; struct entry_t *p; while (ptr) { p = ptr; ptr = ptr->next; free_entry(p); } free(search->result); if (search->options) { free_options(search->options); } free(search); }
int main(int argc, char **argv) { char *pubsub_url; char *address; int port; char *path; char *filename_format = NULL; struct output_metadata *data; define_simplehttp_options(); option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION); option_define_str("pubsub_url", OPT_REQUIRED, "http://127.0.0.1:80/sub?multipart=0", &pubsub_url, NULL, "url of pubsub to read from"); option_define_str("filename_format", OPT_REQUIRED, NULL, &filename_format, NULL, "/var/log/pubsub.%%Y-%%m-%%d_%%H.log"); if (!option_parse_command_line(argc, argv)){ return 1; } data = calloc(1, sizeof(struct output_metadata)); data->filename_format = filename_format; data->current_filename[0] = '\0'; data->temp_filename[0] = '\0'; data->output_file = NULL; if (simplehttp_parse_url(pubsub_url, strlen(pubsub_url), &address, &port, &path)) { pubsubclient_main(address, port, path, process_message_cb, error_cb, data); if (data->output_file) { fclose(data->output_file); } free(address); free(path); } else { fprintf(stderr, "ERROR: failed to parse pubsub_url\n"); } free(data); free_options(); free(pubsub_url); free(filename_format); return 0; }
iface_t *get_config(FILE *fp, unsigned int *line, enum itype type) { char *var,*val; struct kopts **opt; iface_t *ifp; int ret; if((ifp = (iface_t *) malloc(sizeof(iface_t))) == NULL) { *line = 0; return(NULL); } memset((void *) ifp,0,sizeof(iface_t)); ifp->direction = BOTH; ifp->checksum=-1; ifp->strict=-1; ifp->type=type; /* Set defaults */ switch (type) { case FILEIO: flag_set(ifp,F_NOCR); break; default: break; } for(opt = &ifp->options;next_config(fp,line,&var,&val) == 0;) { if (!var) return(ifp); if ((ret = add_common_opt(var,val,ifp)) == 0) continue; if ((ret < 0) || (((*opt) = add_option(var,val)) == NULL && (ret=-1))) { if (ret == -1) *line=0; break; } opt=&(*opt)->next; } free_options(ifp->options); free(ifp); return(NULL); }
static foreign_t process_create(term_t exe, term_t options) { p_options info; int rc = FALSE; memset(&info, 0, sizeof(info)); if ( !get_exe(exe, &info) ) goto out; if ( !parse_options(options, &info) ) goto out; if ( !create_pipes(&info) ) goto out; rc = do_create_process(&info); out: free_options(&info); return rc; }
int Open_REQLOCK(client_t *client, textbuf *buf, CTP_head_t head) { CTP_OPEN_t mesg; int rv = recv_mesg(client->sockfd, &mesg, head); if (rv < 1) return rv; /* check for correct client id */ if (mesg.client_id != client->id) { free_mesg(mesg); return -1; } /* only one client may lock at a time */ if (locking_client != NULL) { free_mesg(mesg); send_err(client, CANT_LOCK); return 1; } free_mesg(mesg); /* transient... */ client->state = WaitLock; /* build ACKLOCK response */ CTP_ACKLOCK_t response; response.options = new_options(); /* send response */ rv = send_ACKOPEN(client->sockfd, response); free_options(response.options); client->state = Locked; locking_client = client; return rv; }
int main(int argc, char **argv) { option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION); option_define_str("db_file", OPT_REQUIRED, NULL, NULL, NULL, "path to leveldb file"); option_define_bool("create_db_if_missing", OPT_OPTIONAL, 1, NULL, NULL, "Create leveldb file if missing"); option_define_bool("error_if_db_exists", OPT_OPTIONAL, 0, NULL, NULL, "Error out if leveldb file exists"); option_define_bool("paranoid_checks", OPT_OPTIONAL, 1, NULL, NULL, "leveldb paranoid checks"); option_define_int("write_buffer_size", OPT_OPTIONAL, 4 << 20, NULL, NULL, "write buffer size"); option_define_int("cache_size", OPT_OPTIONAL, 4 << 20, NULL, NULL, "cache size (frequently used blocks)"); option_define_int("block_size", OPT_OPTIONAL, 4096, NULL, NULL, "block size"); option_define_bool("compression", OPT_OPTIONAL, 1, NULL, NULL, "snappy compression"); option_define_bool("verify_checksums", OPT_OPTIONAL, 1, NULL, NULL, "verify checksums at read time"); option_define_int("leveldb_max_open_files", OPT_OPTIONAL, 4096, NULL, NULL, "leveldb max open files"); option_define_str("input_file", OPT_OPTIONAL, NULL, NULL, NULL, "path to output file (default:stdin)"); option_define_bool("quiet", OPT_OPTIONAL, 0, NULL, NULL, "quiet mode"); option_define_int("stats_every", OPT_OPTIONAL, 1000, NULL, NULL, "show a status after processing x records"); option_define_str("input_deliminator", OPT_OPTIONAL, ",", NULL, NULL, "input deliminator"); if (!option_parse_command_line(argc, argv)) { return 1; } if (!db_open()) { return 1; } if (!read_csv()) { return 1; } db_close(); free_options(); return 0; }
int main(int argc, char *argv[]) { if (argc < 2) { usage(); exit(EXIT_FAILURE); } options_t *options = parse_options(argc, argv); // opcoes const char *path = argv[argc-1]; pe_ctx_t ctx; pe_err_e err = pe_load_file(&ctx, path); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } err = pe_parse(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } if (!pe_is_pe(&ctx)) EXIT_ERROR("not a valid PE file"); const uint64_t pe_size = pe_filesize(&ctx); const uint8_t *pe_raw_data = ctx.map_addr; uint64_t pe_raw_offset = 0; unsigned char buff[LINE_BUFFER]; memset(buff, 0, LINE_BUFFER); uint64_t buff_index = 0; uint32_t ascii = 0; uint32_t utf = 0; while (pe_raw_offset < pe_size) { const uint8_t byte = pe_raw_data[pe_raw_offset]; if (isprint(byte)) { ascii++; buff[buff_index++] = byte; pe_raw_offset++; continue; } else if (ascii == 1 && byte == '\0') { utf++; buff[buff_index++] = byte; ascii = 0; pe_raw_offset++; continue; } else { if (ascii >= (options->strsize ? options->strsize : 4)) { printb(&ctx, options, buff, 0, ascii, pe_raw_offset - ascii); } else if (utf >= (options->strsize ? options->strsize : 4)) { printb(&ctx, options, buff, 0, utf*2, pe_raw_offset - utf*2); } ascii = utf = buff_index = 0; memset(buff, 0, LINE_BUFFER); } pe_raw_offset++; } // libera a memoria free_options(options); // free err = pe_unload(&ctx); if (err != LIBPE_E_OK) { pe_error_print(stderr, err); return EXIT_FAILURE; } return EXIT_SUCCESS; }