void get_conf() { FILE *conffile; conffile = fopen ("ws.conf", "r"); int index = 0; while (fgets (conf , 500, conffile)) { //Remove comments and whitespace if((strncmp(conf, "#", 1) == 0)||(strncmp(conf, "\n", 1) == 0)) continue; if(portOpt == NULL) { char* portOption = parse_option(conf, "Listen"); portOpt = strdup(portOption); printf("PORT OPT: %s\n", portOpt); continue; } if(docRootOpt == NULL) { char* docOption = parse_option(conf, "DocumentRoot"); docRootOpt = strdup(docOption); printf("Doc Root OPT: %s\n", docRootOpt); continue; } if(dirOpt == NULL) { int line_length = strlen(conf); char line_cpy[line_length + 1]; strcpy(line_cpy, conf); dirOpt = parse_dir_options(conf, "DirectoryIndex"); dirOptCount = get_num_options(line_cpy); for(int i = 0; i < dirOptCount; i++) { printf("DirIndex %d: %s\n", i, dirOpt[i]); } continue; } if(contentLookup == NULL) { contentLookup = malloc(MAX_DATA * sizeof(char*)); contentOpt = malloc(MAX_DATA * sizeof(char*)); } contentOptCount = parse_content_options(conf, contentLookup, contentOpt); if(contentLookup != NULL) { printf( "Content %d: %s Type: %s\n", index, contentLookup[index], contentOpt[index]); index++; } } fclose (conffile); }
/** Parse options from main's argv. */ void parse_opts(char **argv) { char *current; while ((current= *argv++)) { if (current[0] == '-') { if (current[1] == '-') parse_option(0, current+2, &argv); else for (++current; *current; current++) parse_option(*current, NULL, &argv); } else // if failsafe, will not exit() fatal(EXIT_BAD_OPTIONS, "Unexpected argument \"%s\"\n", current); } }
int main(int const argc, char const * const * const argv) { Option opt; try { opt = parse_option(argv_to_args(argc, argv)); } catch(std::invalid_argument const &e) { std::cout << e.what(); return EXIT_FAILURE; } std::cout << "reading data..." << std::flush; //Problem const Tr = read_data(opt.Tr_path, opt.TrS_path); //Problem const Va = read_data(opt.Va_path, opt.VaS_path); Problem const Tr = read_data(opt.Tr_path); Problem const Va = read_data(opt.Va_path); std::cout << "done\n" << std::flush; omp_set_num_threads(static_cast<int>(opt.nr_thread)); GBDT gbdt(opt.nr_tree); gbdt.fit(Tr, Va); write(Tr, gbdt, opt.Tr_out_path); write(Va, gbdt, opt.Va_out_path); return EXIT_SUCCESS; }
void parse_options() { // Parse command line options, and update the environment to match the // specified options. argp->usage( "Usage: jgdoc [OPTIONS] FILE...\n" "Generates documentation from comments found in Jogo source files.\n\n" " -o, --output DIR Write output to DIR.\n" " -i, --include DIR Add the directory DIR to the search path.\n" " -h, --help Print this help message.\n" " -f, --format FORMAT Set output format to FORMAT.\n" " -v, --verbose Print extra information.\n" " --version Print the compiler version number.\n"); for (ArgToken tok = argp->next(); tok; tok = argp->next()) { // Convert abbreviated flags into the longer descriptive form (e.g., // convert -p to --path) if (ArgToken::SHORT == tok.type()) { parse_short_option(tok.value()); } else if (ArgToken::LONG == tok.type()) { parse_option(tok.value()); } else { env->input(tok.value()); } } std::string gen = env->generator(); if (gen != "Markdown") { argp->error("Invalid output format (options: Markdown"); } }
void fs_uae_read_custom_uae_options(int argc, char **argv) { fs_log("read_custom_uae_options\n"); if (g_fs_uae_config_file_path) { FILE *f = fs_fopen(g_fs_uae_config_file_path, "rb"); read_custom_uae_options_from_file(f); fclose(f); } for (int i = 0; i < argc; i++) { char *arg = argv[i]; if (!fs_str_has_prefix(arg, "--")) { continue; } char *key = arg + 2; char *value = strchr(arg, '='); if (value) { char *k = fs_strndup(key, value - key); fs_strdelimit (k, "-", '_'); char *v = fs_strdup(value + 1); char *key_lower = fs_ascii_strdown(k, -1); free(k); parse_option(key_lower, v); free(key_lower); free(v); } } }
/* Handle/record information received in a transfer vector entry. */ static enum ld_plugin_status parse_tv_tag (struct ld_plugin_tv *tv) { #define SETVAR(x) x = tv->tv_u.x switch (tv->tv_tag) { case LDPT_OPTION: return parse_option (tv->tv_u.tv_string); case LDPT_NULL: case LDPT_GOLD_VERSION: case LDPT_GNU_LD_VERSION: case LDPT_API_VERSION: default: break; case LDPT_OUTPUT_NAME: output_name = tv->tv_u.tv_string; break; case LDPT_LINKER_OUTPUT: linker_output = tv->tv_u.tv_val; break; case LDPT_REGISTER_CLAIM_FILE_HOOK: SETVAR(tv_register_claim_file); break; case LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK: SETVAR(tv_register_all_symbols_read); break; case LDPT_REGISTER_CLEANUP_HOOK: SETVAR(tv_register_cleanup); break; case LDPT_ADD_SYMBOLS: SETVAR(tv_add_symbols); break; case LDPT_GET_SYMBOLS: SETVAR(tv_get_symbols); break; case LDPT_GET_SYMBOLS_V2: tv_get_symbols_v2 = tv->tv_u.tv_get_symbols; break; case LDPT_ADD_INPUT_FILE: SETVAR(tv_add_input_file); break; case LDPT_MESSAGE: SETVAR(tv_message); break; case LDPT_GET_INPUT_FILE: SETVAR(tv_get_input_file); break; case LDPT_RELEASE_INPUT_FILE: SETVAR(tv_release_input_file); break; case LDPT_ADD_INPUT_LIBRARY: SETVAR(tv_add_input_library); break; case LDPT_SET_EXTRA_LIBRARY_PATH: SETVAR(tv_set_extra_library_path); break; } #undef SETVAR return LDPS_OK; }
void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, void (* parse_arg_function)(void *, const char*)) { const char *opt; int optindex, handleoptions = 1, ret; /* perform system-dependent conversions for arguments list */ prepare_app_arguments(&argc, &argv); /* parse options */ optindex = 1; while (optindex < argc) { opt = argv[optindex++]; if (handleoptions && opt[0] == '-' && opt[1] != '\0') { if (opt[1] == '-' && opt[2] == '\0') { handleoptions = 0; continue; } opt++; if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) exit_program(1); optindex += ret; } else { if (parse_arg_function) parse_arg_function(optctx, opt); } } }
/* * Setup parameters for the use case. * Return: 0 succeed; -1 fail. */ static int setup_parameters(int argc, char * const argv[]) { /* use case defaults */ chunksize_g = Chunksize_DFT; use_swmr_g = 1; /* use swmr open */ chunkplanes_g = 1; /* parse options */ if (parse_option(argc, argv) < 0){ return(-1); } /* set chunk dims */ chunkdims_g[0] = chunkplanes_g; chunkdims_g[1]= chunkdims_g[2] = chunksize_g; /* set dataset initial and max dims */ dims_g[0] = 0; max_dims_g[0] = H5S_UNLIMITED; dims_g[1] = dims_g[2] = max_dims_g[1] = max_dims_g[2] = chunksize_g; /* set nplanes */ if (nplanes_g == 0) nplanes_g = chunksize_g; /* show parameters and return */ show_parameters(); return(0); } /* setup_parameters() */
int cmd_opt(char **arg) { const char *opt_text = get_arg(arg); struct opdb_key key; union opdb_value value; if (opt_text) { if (opdb_get(opt_text, &key, &value) < 0) { printc_err("opt: no such option: %s\n", opt_text); return -1; } } if (**arg) { if (parse_option(key.type, &value, *arg) < 0) { printc_err("opt: can't parse option: %s\n", *arg); return -1; } opdb_set(key.name, &value); } else if (opt_text) { display_option(NULL, &key, &value); } else { opdb_enum(display_option, NULL); } return 0; }
static int parse_config_line(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo, const char *opt, char *line, struct dhcp_opt **ldop, struct dhcp_opt **edop) { unsigned int i; for (i = 0; i < sizeof(cf_options) / sizeof(cf_options[0]); i++) { if (!cf_options[i].name || strcmp(cf_options[i].name, opt) != 0) continue; if (cf_options[i].has_arg == required_argument && !line) { fprintf(stderr, PACKAGE ": option requires an argument -- %s\n", opt); return -1; } return parse_option(ctx, ifname, ifo, cf_options[i].val, line, ldop, edop); } syslog(LOG_ERR, "unknown option: %s", opt); return -1; }
int parse(struct file_system_info *fsinfo, int argc, char **argv){ int i = 0; if ((argc == 2) && ((strcmp(argv[1], OPT_VERSION) == 0) || (strcmp(argv[1], OPT_VERSION_FULL) == 0))){ printf(PROGRAM_NAME " - filesystem in userspace for rdiff-backup repositories; version %s\n", PACKAGE_VERSION); exit(0); }; if (argc < 3) fail(ERR_PARAMETRES); for (i = 1; i < argc; i++){ if (isOption(argv[i]) == 1) parse_option(fsinfo, argc, argv, &i); else if (mount == NULL) parse_mount(argv[i]); else parse_repo(fsinfo, argc, argv, &i); }; if (mount == NULL) fail(ERR_NO_MOUNT); if (fsinfo->repo_count == 0) fail(ERR_NO_REPO); if ((layout == LAYOUT_LAST) && (structure != STRUCTURE_FULL)) fail(ERR_FULL_ONLY); return 0; };
static bool read_config(ZString filename) { bool rv = true; io::ReadFile in(filename); if (!in.is_open()) { FPRINTF(stderr, "Monitor config file not found: %s\n", filename); exit(1); } FString line; while (in.getline(line)) { if (is_comment(line)) continue; XString name; ZString value; if (!config_split(line, &name, &value)) { PRINTF("Bad line: %s\n", line); rv = false; continue; } if (!parse_option(name, value)) { PRINTF("Bad key/value: %s\n", line); rv = false; continue; } } return rv; }
int parse_header(parsed_header_t *parse, const gchar *buf, const size_t buf_len) { header_option_t *current; synchro_option_t *opt; const gchar *start = buf; const gchar *end; /* seek the first option -- I need bitstream examples to reverse-engeneer the very first option */ while (*buf != FILENAME) { buf++; if (buf > start + buf_len) return -1; } current = (void *) buf; while (current->code != CODE) { parse_option(parse, current); current = next_option(current); } opt = (void*) current; parse_synchro(opt); end = (void *) opt->data; return (end - start); }
static int flowop_parse_options(char *str_options, flowop_t *flowop) { char *options; /* Temp string to get the token */ char opt_arr[100][100]; /* Array to copy the tokens */ int i = 0, j; /* Iterators */ char *delimiters = " \t"; flowop->options.count = 1; /* Default count */ flowop->options.size = 0; /* Default size */ flowop->options.duration = 0; /* Default duration */ flowop->p_id = UPERF_ANY_CONNECTION; for (options = strtok(str_options, delimiters); options != NULL; options = strtok(NULL, delimiters)) { if (isalpha(options[0])) (void) strlcpy(opt_arr[i++], options, 100); } for (j = 0; j < i; j++) { parse_option(opt_arr[j], flowop); } return (UPERF_SUCCESS); }
int main(int const argc, char const * const * const argv) { Option opt; try { opt = parse_option(argv_to_args(argc, argv)); } catch(std::invalid_argument const &e) { std::cout << e.what(); return EXIT_FAILURE; } std::cout << "reading data..." << std::flush; Problem const Va = read_problem(opt.Va_path); Problem const Tr = read_problem(opt.Tr_path); std::cout << "done\n" << std::flush; std::cout << "initializing model..." << std::flush; Model model(Tr.nr_feature, opt.nr_factor, Tr.nr_field); init_model(model); std::cout << "done\n" << std::flush; omp_set_num_threads(static_cast<int>(opt.nr_threads)); train(Tr, Va, model, opt); omp_set_num_threads(1); if(opt.do_prediction) predict(Va, model, opt.Va_path+".out"); return EXIT_SUCCESS; }
static int parse_config(unsigned int *colopts, const char *value) { const char *sep = " ,"; int group_set = 0; while (*value) { int len = strcspn(value, sep); if (len) { if (parse_option(value, len, colopts, &group_set)) return -1; value += len; } value += strspn(value, sep); } /* * If none of "always", "never", and "auto" is specified, then setting * layout implies "always". * * Current value in COL_ENABLE_MASK is disregarded. This means if * you set column.ui = auto and pass --column=row, then "auto" * will become "always". */ if ((group_set & LAYOUT_SET) && !(group_set & ENABLE_SET)) *colopts = (*colopts & ~COL_ENABLE_MASK) | COL_ENABLED; return 0; }
int main(int argc, char *argv[]) { int i; ipr_sg_required = 1; openlog("iprinit", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER); for (i = 1; i < argc; i++) { if (parse_option(argv[i])) continue; else { printf("Usage: iprinit [options]\n"); printf(" Options: --version [--daemon] Print iprinit version\n"); return -EINVAL; } } init_all(); if (daemonize) { ipr_daemonize(); return handle_events(poll_ioas, 60, kevent_handler); } return 0; }
int main(int argc, char **argv) { int listenfd, connfd, port, clientlen; pid_t pid; struct sockaddr_in clientaddr; char isdaemon = 0, *portp = NULL, *logp = NULL, tmpcwd[MAXLINE]; openlog(argv[0], LOG_NDELAY|LOG_PID, LOG_DAEMON); cwd = (char *)get_current_dir_name(); strcpy(tmpcwd, cwd); strcat(tmpcwd, "/"); parse_option(argc, argv, &isdaemon, &portp, &logp); printf("isdaemon = %d\n", isdaemon); printf("protp = %s\n", portp); printf("logp = %s\n", logp); //printf("cwd = %s\n", cwd); portp == NULL ? (port=atoi(Getconfig("http"))) : (port = atoi(portp)); return 0; }
int cpn_opts_parse(struct cpn_opt *opts, int argc, const char *argv[]) { int i, processed; struct cpn_opt *opt; for (i = 0; i < argc; i++) { for (opt = opts; opt && opt->type != CPN_OPTS_TYPE_END; opt++) { if (opt->short_name && argv[i][0] == '-' && argv[i][1] == opt->short_name && argv[i][2] == '\0') { break; } else if (opt->long_name && !strcmp(argv[i], opt->long_name)) { break; } } if (!opt) { cpn_log(LOG_LEVEL_ERROR, "Unknown option %s", argv[0]); return -1; } if ((processed = parse_option(opt, argc - i, argv + i)) < 0) return -1; opt->set = true; i += processed; } for (opt = opts; opt && opt->type != CPN_OPTS_TYPE_END; opt++) { if (!opt->set && !opt->optional) { cpn_log(LOG_LEVEL_ERROR, "Required argument %s not set", opt->long_name); return -1; } } return 0; }
int GeneratorBase::set_generator_options(const StringList& options) { for (StringList::const_iterator it = options.begin(); it != options.end(); ++it) if (!parse_option(*it)) return EXIT_FAILURE; return EXIT_SUCCESS; }
int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, unsigned flags) { int a = -1; int skip = 0; int i; int n; struct isl_prefixes prefixes = { 0 }; n = n_arg(args->args); for (i = 1; i < argc; ++i) { if ((strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) && any_version(args->args)) print_version_and_exit(args->args); } while (argc > 1 + skip) { int parsed; if (argv[1 + skip][0] != '-') { a = next_arg(args->args, a); if (a >= 0) { char **p; p = (char **)(((char *)opt)+args->args[a].offset); free(*p); *p = strdup(argv[1 + skip]); argc = drop_argument(argc, argv, 1 + skip, 1); --n; } else if (ISL_FL_ISSET(flags, ISL_ARG_ALL)) { fprintf(stderr, "%s: extra argument: %s\n", prog_name(argv[0]), argv[1 + skip]); exit(-1); } else ++skip; continue; } check_help(args, argv[1 + skip], argv[0], opt, flags); parsed = parse_option(args->args, &argv[1 + skip], &prefixes, opt); if (parsed) argc = drop_argument(argc, argv, 1 + skip, parsed); else if (ISL_FL_ISSET(flags, ISL_ARG_ALL)) { fprintf(stderr, "%s: unrecognized option: %s\n", prog_name(argv[0]), argv[1 + skip]); exit(-1); } else ++skip; } if (n > 0) { fprintf(stderr, "%s: expecting %d more argument(s)\n", prog_name(argv[0]), n); exit(-1); } return argc; }
int main(int argc, char **argv) { char **ktapvm_argv; int new_index, i; int ret; if (argc == 1) usage(""); parse_option(argc, argv); if (oneline_src[0] != '\0') script_file = "one-liner"; compile(script_file); ktapvm_argv = (char **)malloc(sizeof(char *)*(script_args_end - script_args_start + 1)); if (!ktapvm_argv) { fprintf(stderr, "canno allocate ktapvm_argv\n"); return -1; } ktapvm_argv[0] = malloc(strlen(script_file) + 1); if (!ktapvm_argv[0]) { fprintf(stderr, "canno allocate memory\n"); return -1; } strcpy(ktapvm_argv[0], script_file); ktapvm_argv[0][strlen(script_file)] = '\0'; /* pass rest argv into ktapvm */ new_index = 1; for (i = script_args_start; i < script_args_end; i++) { ktapvm_argv[new_index] = malloc(strlen(argv[i]) + 1); if (!ktapvm_argv[new_index]) { fprintf(stderr, "canno allocate memory\n"); return -1; } strcpy(ktapvm_argv[new_index], argv[i]); ktapvm_argv[new_index][strlen(argv[i])] = '\0'; new_index++; } uparm.argv = ktapvm_argv; uparm.argc = new_index; uparm.verbose = verbose; uparm.trace_pid = trace_pid; uparm.trace_cpu = trace_cpu; uparm.print_timestamp = print_timestamp; /* start running into kernel ktapvm */ ret = run_ktapvm(); cleanup_event_resources(); return ret; }
static char * parse_dump_tables( char *cmd, const uint64_t own_datapath_id ) { if ( prefixcmp( cmd, "dump_tables" ) ) { return NULL; } char *opt = strchr ( cmd, ' ' ); assert( opt ); uint64_t datapath_val; uint8_t table_id_val = FLOW_TABLE_ID_MAX; struct option opts[] = { OPT_UINT64( "--datapath_id", "datapath_id:", OPT_NO_MASK, &datapath_val ), OPT_UINT8( "--table_id", "table_id:", OPT_NO_MASK, &table_id_val ), OPT_END() }; char *saveptr; const char *sep = " "; for ( opt = strtok_r( opt, sep, &saveptr ); opt; opt = strtok_r( NULL, sep, &saveptr ) ) { parse_option( opt, opts ); if ( *( uint64_t * ) opts[ 0 ].value != own_datapath_id ) { return NULL; } } if ( table_id_val != FLOW_TABLE_ID_MAX ) { flow_table_features table_features; get_flow_table_features( ( uint8_t ) table_id_val, &table_features ); char *reply_buf = xmalloc( PATH_MAX + 1 ); reply_buf[ 0 ] = '\0'; const char *orig = "{ \"table_features\" [ "; const char *term = "] }"; snprintf( reply_buf, PATH_MAX, "%s {" DUMP_TABLE_FIELDS "} %s", orig, table_features.table_id, table_features.name, table_features.config, table_features.max_entries, table_features.metadata_match, table_features.metadata_write, term ); return reply_buf; } else { for ( uint32_t i = 0; i < table_id_val; i++ ) { flow_table_features table_features; get_flow_table_features( ( uint8_t ) i, &table_features ); } } return NULL; }
void Options::add_to_option(const std::string& option, const std::string& arg) { auto iter = m_options.find(option); if (iter == m_options.end()) { throw option_not_exists_exception(option); } parse_option(iter->second, option, arg); }
int main(int argc, char *argv[]) { int i, rc, delay_secs, wait; ipr_sg_required = 1; openlog("iprinit", LOG_PERROR | LOG_PID | LOG_CONS, LOG_USER); for (i = 1; i < argc; i++) { if (parse_option(argv[i])) continue; else { printf("Usage: iprinit [options]\n"); printf(" Options: --version [--daemon] Print iprinit version\n"); return -EINVAL; } } rc = check_sg_module(); if (daemonize) { ipr_daemonize(); if (!rc) rc = init_all(); if (rc) { delay_secs = 2; sleep(delay_secs); for (wait = 0; rc && wait < 300; wait += delay_secs) { rc = check_sg_module(); sleep(delay_secs); if (!rc) rc = init_all(); } if (rc) syslog(LOG_ERR, "Timeout reached. Ensure the sg module is loaded, then " "run iprinit manually to ensure all " "ipr RAID adapters are running optimally\n"); } return handle_events(poll_ioas, 60, kevent_handler); } else if (!rc) rc = init_all(); if (rc) syslog(LOG_ERR, "iprinit failed. Ensure the sg module is loaded, then " "run iprinit again to ensure all " "ipr RAID adapters are running optimally\n"); return rc; }
int Profile::cfg_check(const char *file, int output) { unsigned int line = 0; /* line number */ unsigned int section = 0; unsigned int err = 0; /* error checking */ char buff[MAX_LINE_SIZE]; /* line buffer */ char *sect = NULL; char **res = NULL; FILE *fd; fd = fopen(file,"r"); if(!fd) { error("cfg_check(): can't open %s (%s)",file,strerror(errno)); return(false); } /* let's work */ while (fgets(buff, MAX_LINE_SIZE, fd)) { /* line counting */ line++; chomp(buff); /* ignore comments and blank lines */ if (*buff == '#' || *buff == '\r' || *buff == '\n' || *buff == '\0') continue; if ((sect = is_a_section(buff))) { /* ok, its a section */ section = 1; free(sect); } else if ((res = parse_option(buff))) { if (!section) { /* option without a section */ err = 1; if (output) error("CFG::check_config : %s:%d: option '%s' whithout a section.\n", file, line, res[0]); } free(res[0]); free(res[1]); } else { err = 1; if (output) error("%s:%d: syntax error: '%s'\n", file, line, buff); } } free(res[0]); free(res[1]); fclose(fd); /* return 0 if failed or 1 if ok */ return (err ? 0: 1); }
void parse_short_option(std::string const& flag) { // Parses a short-form option ('-x') switch (flag[0]) { case 'l': parse_option("library"); break; case 'i': parse_option("include"); break; case 'g': parse_option("generator"); break; case 'd': parse_option("debug"); break; case 'o': parse_option("optimize"); break; case 'v': parse_option("verbose"); break; case 'c': parse_option("clean"); break; case 'r': parse_option("reset"); break; default: argp->bad_short_option(flag); break; } }
void SvcConfExporter::parse_category(xercesc::DOMNode* source, xercesc::DOMDocument* target, xercesc::DOMNode* parent) { std::string params; xercesc::DOMNodeList* children = source->getChildNodes(); for (size_t i = 0; i < children->getLength(); ++i) { xercesc::DOMNode* child_node = children->item(i); XMLUnicodeString child_node_name = child_node->getNodeName(); if (child_node_name == "OptionCategory") parse_category(child_node, target, parent); else if (child_node_name == "BooleanOption") params += parse_option(child_node, target); else if (child_node_name == "StringOption") params += parse_option(child_node, target); else if (child_node_name == "IntegerOption") params += parse_option(child_node, target); else if (child_node_name == "EnumOption") params += parse_option(child_node, target); } if (params.size()) { xercesc::DOMNamedNodeMap* attributes = source->getAttributes(); XMLUnicodeString name = attributes->getNamedItem(XMLUnicodeString("name"))->getNodeValue(); XercesAutoPtr<xercesc::DOMElement> result = target->createElement(XMLUnicodeString("static")); result->setAttribute(XMLUnicodeString("id"), name); result->setAttribute(XMLUnicodeString("params"), XMLUnicodeString(params.c_str())); parent->appendChild(result.release()); } }
int main(int argc, char **argv) { bool interactive = false; parse_option(argc,argv,&interactive); argc -= optind; argv += optind; check_operand(argc,argv); do_copy(argc,argv,interactive,data_copy); return EXIT_SUCCESS; }
/* returns: -1 EOF 0 no option in current section OR offset of the option */ off_t Profile::find_option(FILE *fp, const char *option, char *value, off_t section_offset) { char tmp[MAX_LINE_SIZE]; char **res = NULL; off_t offset = -1; off_t bck, pos; // func("find_option(%s)",option); /* backup file pointer */ bck = ftell(fp); /* seek to section */ fseek(fp, section_offset, SEEK_SET); fgets(tmp, MAX_LINE_SIZE, fp); /* goes to the first option line */ while (!feof(fp)) { pos = ftell(fp); if(!fgets(tmp, MAX_LINE_SIZE, fp)) break; chomp(tmp); // fprintf(stderr,"find option : \"%s\"\n",tmp); if (tmp[0] == '#' || tmp[0] == '\r' || tmp[0] == '\n' || tmp[0] == '\0') continue; if (tmp[0] == '[') break;/* END OF SECTION - nothing found */ res = parse_option(tmp); if(res) { if (!strncmp(res[0], option, MAX_OPTION_SIZE)) { /* SUCCESS */ if(value) strncpy(value,res[1],MAX_VALUE_SIZE); offset = pos; // func("find_option() : FOUND at offset %lu\n",offset); break; } // free(res[0]); free(res[1]); } } /* restore backup */ fseek(fp,bck,SEEK_SET); if(res) { free(res[0]); free(res[1]); } return offset; }