parameter_error_t(state_t &state, std::string && msg, int index) : state_(state) , msg_(std::move(msg)) { std::ostringstream os; os << " lua parameter--"; parse_parameter(state_, index, os); os << std::endl << "lua stack: " << std::endl; dump(os); msg_ += os.str(); }
/* The db handler */ static int db_handler(request_rec *r) { apr_hash_t *hash = parse_parameter(r); if( hash == NULL ) { r->status = HTTP_BAD_REQUEST; return DECLINED; } char *id = get_parameter(r, hash, "id"); if( id == NULL ) { r->status = HTTP_BAD_REQUEST; return DECLINED; } getDBContents(r, atoi(id)); return OK; }
/**Check touch module*/ bool is_touch_pcba_function(module_info * mod) { hash_map < string, string > params; if(mod == NULL || mod->config_list[KEY_LIB_NAME].empty()) return false; if(!strcmp(LOCAL_TOUCH, mod->config_list[KEY_LIB_NAME].c_str())) { parse_parameter(mod->config_list["parameter"], params); if(!strcmp(params["level"].c_str(), PCBA_FUNCTION)) { return true; } } return false; }
static void parse_function(rapidxml::xml_node<>* node, configuration const& config, std::string const& parent, function& f) { if (node != NULL) { std::string name = node->name(); std::string full = parent + "." + name; if (full == ".name") f.name = node->value(); else if (full == ".argsstring") f.argsstring = node->value(); else if (full == ".definition") { f.definition = node->value(); if (! config.skip_namespace.empty()) { boost::replace_all(f.definition, config.skip_namespace, ""); } } else if (full == ".param") { parameter p; parse_parameter(node->first_node(), p); add_or_set(f.parameters, p); } else if (full == ".type") { get_contents(node->first_node(), f.return_type); } else if (full == ".detaileddescription.para.simplesect") { std::string kind = get_attribute(node, "kind"); if (kind == "return") { get_contents(node->first_node(), f.return_description); } /*else if (kind == "param") { get_contents(node->first_node(), f.paragraphs); }*/ } else if (full == ".detaileddescription.para.image") { } parse_function(node->first_node(), config, full, f); parse_function(node->next_sibling(), config, parent, f); } }
// media-type = type "/" subtype *( ";" parameter ) // type = token // subtype = token const char* parse_media_type(unsigned char** p) { if (parse_token(p)) return ERR; if (parse_char(p, '/')) return ERR; if (parse_token(p)) return ERR; while (0 != (char)**p) { if (parse_char(p, ';')) break; if (parse_parameter(p)) return ERR; } return NULL; }
void test_parameter() { char tmp; FILE *inn = fopen("tests/test_parameter.txt", "r"); while (!feof(inn)) { in = fopen("test.txt", "w+"); while ((tmp = fgetc(inn)) != '}' && tmp != -1) fprintf(in, "%c", tmp); if (tmp == EOF) break; if (tmp <= 31) continue; fseek(in, 0, SEEK_SET); idx = 0; printf("******************\n"); get_token_with_history(); parse_parameter(); fclose(in); remove("test.txt"); } }
int ctx_set ( ctx_t *ctx_p, const char *const parameter_name, const char *const parameter_value ) { int ret = ENOENT; const struct option *lo_ptr = long_options; while ( lo_ptr->name != NULL ) { if ( !strcmp ( lo_ptr->name, parameter_name ) ) { ret = parse_parameter ( ctx_p, lo_ptr->val, strdup ( parameter_value ), PS_CONTROL ); break; } lo_ptr++; } ret = ctx_check ( ctx_p ); if ( ret ) critical ( "Cannot continue with this setup" ); return ret; }
gboolean claws_init(int *argc, char ***argv) { if (claws_initialized) return TRUE; #ifdef USE_GNUTLS ssl_init(); #endif startup_dir = g_get_current_dir(); parse_parameter(argc, argv); debug_print("Starting Claws Mail version %s\n", PROG_VERSION); setlocale(LC_ALL, ""); #ifdef ENABLE_NLS bindtextdomain(PACKAGE, get_locale_dir () ); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain(PACKAGE); #endif /*ENABLE_NLS*/ putenv("G_BROKEN_FILENAMES=1"); putenv("LIBOVERLAY_SCROLLBAR=0"); /* backup if old rc file exists */ if (is_file_exist(RC_DIR)) { if (g_rename(RC_DIR, RC_DIR ".bak") < 0) { FILE_OP_ERROR(RC_DIR, "rename"); return FALSE; } } srand((gint) time(NULL)); claws_initialized = TRUE; return TRUE; }
void gkf_parse ( ctx_t *ctx_p, GKeyFile *gkf, paramsource_t paramsource ) { debug ( 9, "" ); char *config_group = ( char * ) ctx_p->config_group; while ( config_group != NULL ) { const struct option *lo_ptr = long_options; if ( config_group != ctx_p->config_group ) { ctx_p->flags_values_raw[CONFIG_GROUP_INHERITS] = NULL; ctx_p->flags_set[CONFIG_GROUP_INHERITS] = 0; } while ( lo_ptr->name != NULL ) { gchar *value = g_key_file_get_value ( gkf, config_group, lo_ptr->name, NULL ); if ( value != NULL ) { int ret = parse_parameter ( ctx_p, lo_ptr->val, value, paramsource ); if ( ret ) exit ( ret ); } lo_ptr++; } if ( config_group != ctx_p->config_group ) free ( config_group ); config_group = ctx_p->flags_values_raw[CONFIG_GROUP_INHERITS]; if ( config_group != NULL ) debug ( 2, "Next block is: %s", config_group ); }; return; }
int main ( int _argc, char *_argv[] ) { struct ctx *ctx_p = xcalloc ( 1, sizeof ( *ctx_p ) ); argv = _argv; argc = _argc; int ret = 0, nret; //SAFE ( posixhacks_init(), errno = ret = _SAFE_rc ); ctx_p->config_group = DEFAULT_CONFIG_GROUP; ctx_p->vms_min = DEFAULT_VMS_MIN; ctx_p->vms_max = DEFAULT_VMS_MAX; ctx_p->vms_spare_min = DEFAULT_VMS_SPARE_MIN; ctx_p->vms_spare_max = DEFAULT_VMS_SPARE_MAX; strncpy ( ctx_p->listen_addr, strdup ( DEFAULT_LISTEN ), 256 ); ctx_p->flags[KILL_ON_DISCONNECT] = DEFAULT_KILL_ON_DISCONNECT; ncpus = sysconf ( _SC_NPROCESSORS_ONLN ); // Get number of available logical CPUs memory_init(); ctx_p->pid = getpid(); int quiet = 0, verbose = 3; error_init ( &ctx_p->flags[OUTPUT_METHOD], &quiet, &verbose, &ctx_p->flags[DEBUG] ); nret = arguments_parse ( argc, argv, ctx_p ); if ( nret ) ret = nret; if ( !ret ) { nret = configs_parse ( ctx_p, PS_CONFIG ); if ( nret ) ret = nret; } if ( !ctx_p->kvm_args[SHARGS_PRIMARY].c ) { char *args_line = strdup ( DEFAULT_KVM_ARGS ); parse_parameter ( ctx_p, KVM_ARGS, args_line, PS_DEFAULTS ); } debug ( 4, "ncpus == %u", ncpus ); debug ( 4, "debugging flags: %u 0 3 %u", ctx_p->flags[OUTPUT_METHOD], ctx_p->flags[DEBUG] ); { int n = 0; while ( n < SHARGS_MAX ) { kvm_args_t *args_p = &ctx_p->kvm_args[n++]; debug ( 9, "Custom arguments %u count: %u", n - 1, args_p->c ); int i = 0; while ( i < args_p->c ) { int macros_count = -1, expanded = -1; args_p->v[i] = parameter_expand ( ctx_p, args_p->v[i], 4, ¯os_count, &expanded, parameter_get, ctx_p ); debug ( 12, "args_p->v[%u] == \"%s\" (t: %u; e: %u)", i, args_p->v[i], macros_count, expanded ); if ( macros_count == expanded ) args_p->isexpanded[i]++; i++; } } } ctx_p->state = STATE_STARTING; nret = main_rehash ( ctx_p ); if ( nret ) ret = nret; { int rc = ctx_check ( ctx_p ); if ( !ret ) ret = rc; } debug ( 3, "Current errno is %i.", ret ); // == RUNNING == if ( ret == 0 ) ret = kvmpool ( ctx_p ); // == /RUNNING == main_cleanup ( ctx_p ); error_deinit(); ctx_cleanup ( ctx_p ); debug ( 1, "finished, exitcode: %i: %s.", ret, strerror ( ret ) ); free ( ctx_p ); #ifndef __FreeBSD__ // Hanging up with 100%CPU eating, https://github.com/xaionaro/clsync/issues/97 //SAFE ( posixhacks_deinit(), errno = ret = _SAFE_rc ); #endif return ret; }
int main(int argc, char *argv[]) { int i; int ret; char input_file[100]; char output_file[100]; off_t bs = 1, seek = 0, skip = 0, count = 0; assert(argc >= 3); for (i = 1; i < argc; i++) { char c, *p; parse_parameter(argv[i]); c = para_option[0]; p = para_option + 1; switch (c) { case 'i': if (strcmp(p, "f") == 0) { strcpy(input_file, para_value); } else { goto out_unknown_option; } break; case 'o': if (strcmp(p, "f") == 0) { strcpy(output_file, para_value); } else { goto out_unknown_option; } break; case 'b': if (strcmp(p, "s") == 0) { bs = text2size(para_value, NULL); } else { goto out_unknown_option; } break; case 's': if (strcmp(p, "kip") == 0) { skip = text2size(para_value, NULL); } else if (strcmp(p, "eek") == 0) { seek = text2size(para_value, NULL); } else { goto out_unknown_option; } break; case 'c': if (strcmp(p, "ount") == 0) { count = text2size(para_value, NULL); } else { goto out_unknown_option; } break; default: goto out_unknown_option; } } ret = cavan_dd(input_file, output_file, skip * bs, seek * bs, count * bs); if (ret < 0) { pr_err_info("cavan_dd"); return ret; } return 0; out_unknown_option: pr_err_info("unknown option \"%s\"", para_option); return -EINVAL; }
static bool get_next_test_vector(test_vector_t *test) { param_t param = PARAM_UNKNOWN; char line[512]; memset(test, 0, sizeof(test_vector_t)); while (fgets(line, sizeof(line), ctx.in)) { enumerator_t *enumerator; chunk_t value = chunk_empty; char *token; int i; switch (line[0]) { case '\n': case '\r': case '#': case '\0': /* copy comments, empty lines etc. directly to the output */ if (param != PARAM_UNKNOWN) { /* seems we got a complete test vector */ return TRUE; } fputs(line, ctx.out); continue; case '[': /* control directives */ fputs(line, ctx.out); if (strpfx(line, "[ENCRYPT]")) { ctx.decrypt = FALSE; } else if (strpfx(line, "[DECRYPT]")) { ctx.decrypt = TRUE; } else if (strcasepfx(line, "[IVlen = ")) { ctx.ivlen = atoi(line + strlen("[IVlen = ")); } else if (strcasepfx(line, "[Taglen = ")) { ctx.icvlen = atoi(line + strlen("[Taglen = ")); } continue; default: /* we assume the rest of the lines are PARAM = VALUE pairs*/ fputs(line, ctx.out); break; } i = 0; enumerator = enumerator_create_token(line, "=", " \n\r"); while (enumerator->enumerate(enumerator, &token)) { switch (i++) { case 0: /* PARAM */ param = parse_parameter(token); continue; case 1: /* VALUE */ if (param != PARAM_UNKNOWN && param != PARAM_COUNT) { value = chunk_from_hex(chunk_from_str(token), NULL); } else { value = chunk_empty; } continue; default: break; } break; } enumerator->destroy(enumerator); if (i < 2) { value = chunk_empty; } switch (param) { case PARAM_KEY: test->key = value; break; case PARAM_IV: test->iv = value; test->external_iv = TRUE; break; case PARAM_PLAINTEXT: test->plain = value; break; case PARAM_CIPHERTEXT: test->cipher = value; break; case PARAM_AAD: test->aad = value; break; case PARAM_ICV: test->icv = value; break; default: chunk_free(&value); break; } } if (param != PARAM_UNKNOWN) { /* could be that the file ended with a complete test vector */ return TRUE; } return FALSE; }
/* Check whether the DIE is a function */ static int process_one_DIE(Dwarf_Debug dbg, Dwarf_Die die, int *is_func) { Dwarf_Half tag; int ret; ret = dwarf_tag(die, &tag, NULL); if (ret != DW_DLV_OK) { fprintf(stderr, "SET dwarf: Error in dwarf_tag()\n"); return 1; } if (tag != DW_TAG_subprogram) { *is_func = 0; } else /* The DIE is a function */ { Dwarf_Attribute attr; Dwarf_Die child; Dwarf_Die sib_die; char *name; Dwarf_Addr pc; uint32_t *match_addr; *is_func = 1; /* Function name */ ret = dwarf_diename(die, &name, NULL); if (ret == DW_DLV_ERROR) { fprintf(stderr, "SET dwarf: Error in dwarf_diename()\n"); return 1; } if (ret == DW_DLV_NO_ENTRY) return 0; /* The DIE is a concrete inlined instance? */ /* Entry PC */ ret = dwarf_attr(die, DW_AT_low_pc, &attr, NULL); if (ret == DW_DLV_ERROR) { fprintf(stderr, "SET dwarf: Error in dwarf_attr()\n"); return 1; } if (ret == DW_DLV_NO_ENTRY) return 0; /* The DIE is an inlined function */ ret = dwarf_formaddr(attr, &pc, NULL); dwarf_dealloc(dbg, attr, DW_DLA_ATTR); if (ret != DW_DLV_OK) { fprintf(stderr, "SET dwarf: Error in dwarf_formaddr()\n"); return 1; } /* Get the index of "func_addr" */ pc += local_offset; match_addr = (uint32_t*) bsearch(&pc, local_func_addr, local_func_len, sizeof(uint32_t), compare_u32); if (match_addr) local_func_idx = (match_addr - local_func_addr); else return 0; dwarf_dealloc(dbg, name, DW_DLA_STRING); /* Get the parameter(s) of this function */ ret = dwarf_child(die, &child, NULL); if (ret == DW_DLV_ERROR) { fprintf(stderr, "SET dwarf: Error in dwarf_child()\n"); return 1; } if (ret == DW_DLV_NO_ENTRY) return 0; while (1) { /* Check whether the DIE is a formal parameter */ ret = dwarf_tag(child, &tag, NULL); if (ret != DW_DLV_OK) { fprintf(stderr, "SET dwarf: Error in dwarf_tag()\n"); dwarf_dealloc(dbg, child, DW_DLA_DIE); return 1; } /* FIXME: break or continue? */ if (tag != DW_TAG_formal_parameter) break; ret = parse_parameter(dbg, child); if(ret != 0) { dwarf_dealloc(dbg, child, DW_DLA_DIE); return 1; } ret = dwarf_siblingof(dbg, child, &sib_die, NULL); if (ret == DW_DLV_ERROR) { fprintf(stderr, "SET dwarf: Error in dwarf_siblingof()\n"); dwarf_dealloc(dbg, child, DW_DLA_DIE); return 1; } if (ret == DW_DLV_NO_ENTRY) break; dwarf_dealloc(dbg, child, DW_DLA_DIE); child = sib_die; } dwarf_dealloc(dbg, child, DW_DLA_DIE); } return 0; }
/* * Read configuration file and setup target parameters. */ void target_configure() { FILE *fp; int c; /* * Find the configuration file, if any. * (1) First, try a path from PIC32PROG_CONF_FILE environment variable. * (2) Otherwise, look for a file in the local directory. * (3) Otherwise, use /usr/local/etc/ directory (on Unix) * or a directory where pic32prog.exe resides (on Windows) */ confname = getenv("PIC32PROG_CONF_FILE"); if (! confname) confname = "pic32prog.conf"; if (access(confname, 0) < 0) { #if defined(__CYGWIN32__) || defined(MINGW32) char *p = strrchr(progname, '\\'); if (p) { char *buf = malloc(p - progname + 16); if (! buf) { fprintf(stderr, "%s: out of memory\n", progname); exit(-1); } strncpy(buf, progname, p - progname); strcpy(buf + (p - progname), "\\pic32prog.conf"); confname = buf; } else confname = "c:\\pic32prog.conf"; #else confname = "/usr/local/etc/pic32prog.conf"; #endif } fp = fopen(confname, "r"); if (! fp) { /* No config file available: that's OK. */ return; } bsize = 1024; bufr = (char*) malloc(bsize); if (! bufr) { fprintf(stderr, "%s: malloc failed\n", confname); fclose(fp); exit(-1); } /* Parse file. */ c = eat_whitespace(fp); while (c > 0) { switch (c) { case '\n': /* blank line */ c = eat_whitespace(fp); break; case ';': /* comment line */ case '#': c = eat_comment(fp); break; case '[': /* section header */ parse_section(fp); c = eat_whitespace(fp); break; case '\\': /* bogus backslash */ c = eat_whitespace(fp); break; default: /* parameter line */ parse_parameter(fp, configure_parameter, c); c = eat_whitespace(fp); break; } } configure_parameter("", 0, 0); /* Final call: end of file. */ fclose(fp); if (cursec) { free(cursec); cursec = 0; } free(bufr); bufr = 0; bsize = 0; }
int pack_update(const char* srcdir, const char* dstfile) { struct update_header header; FILE *fp; int i; char buf[PATH_MAX]; printf("------ PACKAGE ------\n"); memset(&header, 0, sizeof(header)); snprintf(buf, sizeof(buf), "%s/%s", srcdir, "parameter"); if (parse_parameter(buf)) return -1; snprintf(buf, sizeof(buf), "%s/%s", srcdir, "package-file"); if (get_packages(buf)) return -1; fp = fopen(dstfile, "w"); if (!fp) return -1; fwrite(&header, sizeof(header), 1, fp); for (i = 0; i < package_image.num_package; ++i) { strcpy(header.parts[i].name, package_image.packages[i].name); strcpy(header.parts[i].filename, package_image.packages[i].filename); header.parts[i].nand_addr = package_image.packages[i].nand_addr; header.parts[i].nand_size = package_image.packages[i].nand_size; if (strcmp(package_image.packages[i].filename, "SELF") == 0) continue; snprintf(buf, sizeof(buf), "%s/%s", srcdir, header.parts[i].filename); printf("Add file: %s\n", buf); import_package(fp, &header.parts[i], buf); } strcpy(header.magic, "RKAF"); strcpy(header.manufacturer, package_image.manufacturer); strcpy(header.model, package_image.machine_model); strcpy(header.id, package_image.machine_id); header.length = ftell(fp); header.num_parts = package_image.num_package; header.version = package_image.version; for (i = header.num_parts - 1; i >= 0; --i) { if (strcmp(header.parts[i].filename, "SELF") == 0) { header.parts[i].size = header.length + 4; header.parts[i].padded_size = (header.parts[i].size + 511) / 512 *512; } } fseek(fp, 0, SEEK_SET); fwrite(&header, sizeof(header), 1, fp); fclose(fp); append_crc(dstfile); printf("------ OK ------\n"); return 0; }
int pack_update(const char* srcdir, const char* dstfile) { struct update_header header; FILE *fp = NULL; unsigned int i; printf("------ PACKAGE ------\n"); memset(&header, 0, sizeof(header)); fp = fopen(dstfile, "wb+"); if (!fp) { printf("Can't open destination file \"%s\": %s\n", dstfile, strerror(errno)); return -1; } if (chdir(srcdir)) return -1; if (parse_parameter("parameter")) return -1; if (get_packages("package-file")) return -1; fwrite(&header, sizeof(header), 1, fp); for (i = 0; i < package_image.num_package; ++i) { strcpy(header.parts[i].name, package_image.packages[i].name); strcpy(header.parts[i].filename, package_image.packages[i].filename); header.parts[i].nand_addr = package_image.packages[i].nand_addr; header.parts[i].nand_size = package_image.packages[i].nand_size; if (strcmp(package_image.packages[i].filename, "SELF") == 0) continue; printf("Add file: %s\n", header.parts[i].filename); import_package(fp, &header.parts[i], header.parts[i].filename); } memcpy(header.magic, RKAFP_MAGIC, sizeof(header.magic)); strcpy(header.manufacturer, package_image.manufacturer); strcpy(header.model, package_image.machine_model); strcpy(header.id, package_image.machine_id); header.length = ftell(fp); header.num_parts = package_image.num_package; header.version = package_image.version; for (i = 0; i < header.num_parts; i++) { if (strcmp(header.parts[i].filename, "SELF") == 0) { header.parts[i].size = header.length + 4; header.parts[i].padded_size = (header.parts[i].size + 511) / 512 *512; } } fseek(fp, 0, SEEK_SET); fwrite(&header, sizeof(header), 1, fp); append_crc(fp); fclose(fp); printf("------ OK ------\n"); return 0; }