cmd_result_t cmd_xmem(int unit, args_t *a) { char *token; unsigned int addr, data; if ((token = ARG_GET(a)) == NULL) { return CMD_USAGE; } if (sal_strcasecmp(token, "r") == 0) { if ((token = ARG_GET(a)) == NULL) { return CMD_USAGE; } addr = parse_integer(token); cli_out("0x%x: %08x\n", addr, *((unsigned int *)(INT_TO_PTR(addr)))); } else if (sal_strcasecmp(token, "w") == 0) { if ((token = ARG_GET(a)) == NULL) { return CMD_USAGE; } addr = parse_integer(token); if ((token = ARG_GET(a)) == NULL) { return CMD_USAGE; } data = parse_integer(token); *((unsigned int *)(INT_TO_PTR(addr))) = data; } else { cli_out(cmd_xmem_usage); return CMD_FAIL; } return CMD_OK; }
DSA *DSA_parse_private_key(CBS *cbs) { DSA *ret = DSA_new(); if (ret == NULL) { return NULL; } CBS child; uint64_t version; if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) || !CBS_get_asn1_uint64(&child, &version)) { OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR); goto err; } if (version != 0) { OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_VERSION); goto err; } if (!parse_integer(&child, &ret->p) || !parse_integer(&child, &ret->q) || !parse_integer(&child, &ret->g) || !parse_integer(&child, &ret->pub_key) || !parse_integer(&child, &ret->priv_key) || CBS_len(&child) != 0) { OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR); goto err; } return ret; err: DSA_free(ret); return NULL; }
cmd_result_t cmd_setfanspeed(int unit, args_t *a) { char *d = ARG_GET(a); char *s = ARG_GET(a); int devno = -1, speed = -1; int retv; if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; if (d) { devno = parse_integer(d); } if (s) { speed = parse_integer(s); } if ((devno < 0) || (devno > 7) || (speed < 0) || (speed > 15)) { return CMD_USAGE; } retv = soc_bsc_max6653_set(unit, devno, speed); if (retv) { sal_printf("%s failed\n", FUNCTION_NAME()); return CMD_FAIL; } return CMD_OK; }
static cairo_bool_t resource_parse_line (char *name, cairo_xcb_resources_t *resources) { char *value; value = strchr (name, ':'); if (value == NULL) return FALSE; *value++ = 0; name = skip_spaces (name); value = skip_spaces (value); if (strcmp (name, "Xft.antialias") == 0) parse_boolean (value, &(resources->xft_antialias)); else if (strcmp (name, "Xft.lcdfilter") == 0) parse_integer (value, &(resources->xft_lcdfilter)); else if (strcmp (name, "Xft.rgba") == 0) parse_integer (value, &(resources->xft_rgba)); else if (strcmp (name, "Xft.hinting") == 0) parse_boolean (value, &(resources->xft_hinting)); else if (strcmp (name, "Xft.hintstyle") == 0) parse_integer (value, &(resources->xft_hintstyle)); return TRUE; }
/** * Parse environment variables */ void parse_environment_vars(parallel_wrapper *par_wrapper) { char *value = NULL; value = getenv("_CONDOR_PROCNO"); parse_integer(value, &par_wrapper -> this_machine -> rank); value = getenv("_CONDOR_NPROCS"); parse_integer(value, &par_wrapper -> num_procs); return; }
/** * The "pxebs" command * * @v argc Argument count * @v argv Argument list * @ret rc Return status code */ static int pxebs_exec ( int argc, char **argv ) { struct pxebs_options opts; struct net_device *netdev; unsigned int pxe_type; int rc; /* Parse options */ if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 ) return rc; /* Parse net device name */ if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 ) return rc; /* Parse boot server type */ if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 ) return rc; /* Perform Boot Server Discovery */ if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) { printf ( "Could not discover boot server on %s: %s\n", netdev->name, strerror ( rc ) ); return rc; } return 0; }
/** Retrieve the amount of quote remaining to a player. * Figure out a player's quota. Add the RQUOTA attribute if he doesn't * have one already. This function returns the REMAINING quota, not * the TOTAL limit. * \param who player to check. * \return player's remaining quota. */ int get_current_quota(dbref who) { ATTR *a; int i; int limit; int owned = 0; /* if he's got an RQUOTA attribute, his remaining quota is that */ a = atr_get_noparent(Owner(who), "RQUOTA"); if (a) return parse_integer(atr_value(a)); /* else, count up his objects. If he has less than the START_QUOTA, * then his remaining quota is that minus his number of current objects. * Otherwise, it's his current number of objects. Add the attribute * if he doesn't have it. */ for (i = 0; i < db_top; i++) if (Owner(i) == Owner(who)) owned++; owned--; /* don't count the player himself */ if (owned <= START_QUOTA) limit = START_QUOTA - owned; else limit = owned; (void) atr_add(Owner(who), "RQUOTA", tprintf("%d", limit), GOD, 0); return limit; }
static json_t *parse_value(stream_t *stream, size_t flags, json_error_t *error) { json_t *result = NULL; char *string; int c = stream_peek(stream); switch (c) { case 'd': result = parse_dict(stream, flags, error); break; case 'l': result = parse_list(stream, flags, error); break; case 'i': stream_getc(stream); result = parse_integer(stream, flags, error); break; case EOF: error_set(error, stream, "unexpected EOF"); break; default: if (json_isdigit(c)) { string = parse_string(stream, flags, error); if (string) { result = json_string_nocheck(string); jsonp_free(string); } } else { error_set(error, stream, "invalid character: %c", c); } } return result; }
/** * Parse the number term 's' and return its resulting value in 'value'. * Return a pointer behind the last character of the expression. * Return NULL if a syntax error occurred. */ char *parse_number_term(char *s, int *value) { unsigned char token; s = skip_whitespace(s); token = next_token(s); if (token == TOKEN_DIGITS || token == TOKEN_PLUS || token == TOKEN_MINUS) { if (s = parse_integer(s, value)) { return s; } else { syntax_error_invalid_number(); } } else if (token == TOKEN_VAR_NUMBER) { unsigned int var_name; unsigned char var_type; variable *var; s = parse_variable(s, &var_name, &var_type); var = find_variable(var_name, VAR_TYPE_INTEGER, NULL); if (var) { *value = get_integer_variable_value(var); return s; } else { syntax_error_msg("Variable not found"); } } else { syntax_error(); } return NULL; }
/** qsort() comparision routine used by sortby() */ int u_comp(const void *s1, const void *s2) { char result[BUFFER_LEN], *rp; char const *tbuf; int n; /* Our two arguments are passed as %0 and %1 to the sortby u-function. */ /* Note that this function is for use in conjunction with our own * sane_qsort routine, NOT with the standard library qsort! */ global_eval_context.wenv[0] = (char *) s1; global_eval_context.wenv[1] = (char *) s2; /* Run the u-function, which should return a number. */ tbuf = ucomp_buff; rp = result; if (process_expression(result, &rp, &tbuf, ucomp_executor, ucomp_caller, ucomp_enactor, PE_DEFAULT, PT_DEFAULT, ucomp_pe_info)) return 0; n = parse_integer(result); return n; }
uintmax_t parse_integer (const char *str, gboolean * invalid) { uintmax_t n; char *suffix; strtol_error_t e; e = xstrtoumax (str, &suffix, 10, &n, "bcEGkKMPTwYZ0"); if (e == LONGINT_INVALID_SUFFIX_CHAR && *suffix == 'x') { uintmax_t multiplier; multiplier = parse_integer (suffix + 1, invalid); if (multiplier != 0 && n * multiplier / multiplier != n) { *invalid = TRUE; return 0; } n *= multiplier; } else if (e != LONGINT_OK) { *invalid = TRUE; n = 0; } return n; }
static struct buffer parse_value(struct buffer buff, struct rmsgpack_dom_value *value, const char **error) { buff = chomp(buff); if (peek(buff, "nil")) { buff.offset += strlen("nil"); value->type = RDT_NULL; } else if (peek(buff, "true")) { buff.offset += strlen("true"); value->type = RDT_BOOL; value->val.bool_ = 1; } else if (peek(buff, "false")) { buff.offset += strlen("false"); value->type = RDT_BOOL; value->val.bool_ = 0; } else if (peek(buff, "b") || peek(buff, "\"") || peek(buff, "'")) buff = parse_string(buff, value, error); else if (isdigit((int)buff.data[buff.offset])) buff = parse_integer(buff, value, error); return buff; }
RSA *RSA_parse_public_key(CBS *cbs) { RSA *ret = RSA_new(); if (ret == NULL) { return NULL; } CBS child; if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) || !parse_integer(&child, &ret->n) || !parse_integer(&child, &ret->e) || CBS_len(&child) != 0) { OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_ENCODING); RSA_free(ret); return NULL; } return ret; }
DSA_SIG *DSA_SIG_parse(CBS *cbs) { DSA_SIG *ret = DSA_SIG_new(); if (ret == NULL) { return NULL; } CBS child; if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) || !parse_integer(&child, &ret->r) || !parse_integer(&child, &ret->s) || CBS_len(&child) != 0) { OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR); DSA_SIG_free(ret); return NULL; } return ret; }
void OrderPropertyParser::parse(StylePropertySetter *setter, const std::string &name, StyleParser &parser) { auto &tokens = parser.tokens; StyleSetValue order; size_t pos = 0; StyleToken token = next_token(pos, tokens); if (token.type == StyleTokenType::ident && pos == tokens.size()) { if (equals(token.value, "inherit")) order = StyleSetValue::from_keyword("inherit"); else return; } else if (token.type == StyleTokenType::number && pos == tokens.size()) { int value = 0; if (parse_integer(token.value, value)) { order = StyleSetValue::from_number((float)value); } else { return; } } else { return; } setter->set_value("order", order); }
int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "This program expects one argument.\n"); return 1; } int fork_failed = 0; long children_count = parse_integer(argv[1]); for (long i = 0; i < children_count; ++i) { long child = fork(); if (child < 0) { /* parent, fork() failed */ fprintf(stderr, "Failed to fork() child #%zu: %m\n", i + 1); fork_failed = 1; } else if (child == 0) { /* child */ printf("child #%zu pid %ld ppid %ld\n", i + 1, (long)getpid(), (long)getppid()); return 0; } /* parent, fork() succeeded */ } return fork_failed ? 1 : 0; }
extern jobject parser_visible(JNIEnv* env, jclass exception, json_t* root, int is_java_call) { if(NULL == root) { return NULL; } // LOGE("parser_visible"); if(is_java_call) { errno = 0; } jclass visible_class = NULL; jobject visible_obj = NULL; visible_class = (*env) -> FindClass(env, CB_CLASS_VISIBLE); init_fieldid(env, visible_class); init_methodid(env, visible_class); visible_obj = (*env) -> NewObject(env, visible_class, constructor); throw_parse_exception(env, exception, PARSER_VISIBLE_ERROR); int type_value = parse_integer(&root, "type"); int list_id_value = parse_integer(&root, "list_id"); (*env) -> SetIntField(env, visible_obj, type, type_value); throw_parse_exception(env, exception, PARSER_VISIBLE_ERROR); (*env) -> SetIntField(env, visible_obj, list_id, list_id_value); throw_parse_exception(env, exception, PARSER_VISIBLE_ERROR); // clean // LOGE("visible clean"); if(is_java_call) { json_decref(root); } if(errno != 0) { (*env) -> ThrowNew(env, exception, PARSER_VISIBLE_ERROR); } return visible_obj; }
long to_long(const char* p, const char* p_end, const char** p_parse_ended) { long val = parse_integer(p, p_end); if (p_parse_ended) *p_parse_ended = p; return val; }
int integer_() { int result=0; check(parse_integer(result)); return result; }
unsigned char byte_() { int result=0; check(parse_integer(result)); return coerce<unsigned char>(result); }
int parse_bitoperand( char **str, struct rule *rule ) { char *p = rule->operands[rule->operand_count].name; if( rule->operand_count == MAX_OPERANDS ) { fprintf( stderr, "Maximum operands/rule exceeded (%d) at line %d\n", MAX_OPERANDS, yyline ); return -1; } while( isalnum(**str) || **str == '_' ) { *p++ = *(*str)++; } *p = '\0'; CONSUME_CHAR(':'); int size = parse_integer( str ); if( size == -1 ) { return -1; } rule->operands[rule->operand_count].bit_count = size; if( **str == 's' || **str == 'S' ) { (*str)++; rule->operands[rule->operand_count].is_signed = 1; } else if( **str == 'u' || **str == 'U' ) { (*str)++; rule->operands[rule->operand_count].is_signed = 0; } if( **str == '<' ) { (*str)++; CONSUME_CHAR('<'); int lsl = parse_integer(str); if( lsl == -1 ) { return -1; } rule->operands[rule->operand_count].left_shift = lsl; } CONSUME_CHAR(')'); rule->operands[rule->operand_count].bit_shift = rule->bit_count; rule->bit_count += size; rule->bits = rule->bits << size; rule->mask = rule->mask << size; rule->operand_count++; return 0; }
DSA *DSA_parse_public_key(CBS *cbs) { DSA *ret = DSA_new(); if (ret == NULL) { return NULL; } CBS child; if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) || !parse_integer(&child, &ret->pub_key) || !parse_integer(&child, &ret->p) || !parse_integer(&child, &ret->q) || !parse_integer(&child, &ret->g) || CBS_len(&child) != 0) { OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR); DSA_free(ret); return NULL; } return ret; }
cmd_result_t cmd_dpm(int unit, args_t *a) { char *function = ARG_GET(a); char *interval, *p, *v; uint32 delay = 5; /* Report stats every 5 seconds */ int pol = -1; float volt = -1; if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; if (!function) { return CMD_USAGE; } else if (!sal_strncasecmp(function, "show", sal_strlen(function))) { soc_bsc_zm73xx_show(unit); } else if (!sal_strncasecmp(function,"watch",sal_strlen(function)) ){ interval = ARG_GET(a); if (interval) { delay = parse_integer(interval); } soc_bsc_zm73xx_watch(unit, TRUE, delay); } else if (!sal_strncasecmp(function,"nowatch",sal_strlen(function)) ){ soc_bsc_zm73xx_watch(unit, FALSE, delay); } else if (!sal_strncasecmp(function,"setpol",sal_strlen(function))) { p = ARG_GET(a); v = ARG_GET(a); if (p) { pol = parse_integer(p); } if (v) { sscanf(v, "%f", &volt); } if ((pol < 0) || (pol > 31) || (volt < 0.5) || (volt > 5.5)) { return CMD_USAGE; } soc_bsc_zm73xx_set(unit, pol, volt); } else { return CMD_USAGE; } return CMD_OK; }
Atom parse_atom_aux(char *token) { if (is_integer_token(token)) return parse_integer(token); if (is_ratio_token(token)) return parse_ratio(token); if (is_string_token(token)) return parse_string(token); return parse_symbol(token, package); }
static int parse_hdbflags2int(HDBFlags *f, const char *s) { int ret; unsigned int tmp; ret = parse_integer (&tmp, s); if (ret == 1) *f = int2HDBFlags (tmp); return ret; }
/* rsa_parse_additional_prime parses a DER-encoded OtherPrimeInfo from |cbs| and * advances |cbs|. It returns a newly-allocated |RSA_additional_prime| on * success or NULL on error. The |r| and |mont| fields of the result are set to * NULL. */ static RSA_additional_prime *rsa_parse_additional_prime(CBS *cbs) { RSA_additional_prime *ret = OPENSSL_malloc(sizeof(RSA_additional_prime)); if (ret == NULL) { OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE); return 0; } memset(ret, 0, sizeof(RSA_additional_prime)); CBS child; if (!CBS_get_asn1(cbs, &child, CBS_ASN1_SEQUENCE) || !parse_integer(&child, &ret->prime) || !parse_integer(&child, &ret->exp) || !parse_integer(&child, &ret->coeff) || CBS_len(&child) != 0) { OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_ENCODING); RSA_additional_prime_free(ret); return NULL; } return ret; }
STATIC cmd_result_t cmd_esw_dma_fill(int unit, args_t *a) { char *arg; int size; void *laddr; int count; uint32 val; int i; if (cmd_esw_dma_get_size(unit, a, &size) != CMD_OK) { printk("Incorrect size specification\n"); return CMD_USAGE; } if (cmd_esw_dma_get_laddr(unit, a, &laddr) != CMD_OK) { printk("Invalid logical address specified\n"); return CMD_USAGE; } if (cmd_esw_dma_get_count(unit, a, &count) != CMD_OK) { printk("Invalid count specified\n"); return CMD_USAGE; } if ((arg = ARG_GET(a)) == NULL) { printk("No fill value specified\n"); return CMD_USAGE; } val = parse_integer(arg); switch (size) { case 1: sal_memset(laddr, val, count); break; case 2: for(i=0; i < count; i++) { ((uint16 *)laddr)[i] = (uint16)val; } break; case 4: for(i=0; i < count; i++) { ((uint32 *)laddr)[i] = val; } break; default: return CMD_USAGE; } return CMD_OK; }
int main() { m2x_context ctx; struct json_token *arr = NULL, *tok = NULL, *tok2 = NULL; int i, len; m2x_response response; char buf[40]; m2x_open(M2X_KEY, &ctx); response = m2x_device_list(&ctx, ""); printf("Response Status Code: %d\n", response.status); if (m2x_is_success(&response)) { arr = (struct json_token *) response.data; printf("Total: %d\n", parse_integer(find_json_token(arr, "body.total"))); printf("Pages: %d\n", parse_integer(find_json_token(arr, "body.pages"))); printf("Limit: %d\n\n", parse_integer(find_json_token(arr, "body.limit"))); tok = find_json_token(arr, "body.devices"); if (tok) { i = 0; while (1) { sprintf(buf, "[%d].id", i); tok2 = find_json_token(tok, buf); if (!tok2) { break; } print_token_as_string("Device ID: ", tok2); sprintf(buf, "[%d].name", i); tok2 = find_json_token(tok, buf); print_token_as_string("Device Name: ", tok2); printf("\n"); i++; } } } m2x_release_response(&ctx, &response); m2x_close(&ctx); return 0; }
static int parse_integer_alloc (unsigned int **u, const char *s) { unsigned int tmp; int ret; *u = NULL; ret = parse_integer (&tmp, s); if (ret == 1) { *u = malloc (sizeof (**u)); if (*u == NULL) krb5_errx (context, 1, "malloc: out of memory"); **u = tmp; } return ret; }
int main(int count, char * arguments []) { printf("sizeof PointyInt: %zu\n", sizeof(PointyInt)); printf("sizeof void *: %zu\n", sizeof(void *)); printf("size of long long int: %zu\n", sizeof(long long int)); printf("sizeof List: %zu\n", sizeof(List)); for (int i = 0; i < count; i++) { long long int x = parse_integer(arguments[i]); printf("integer value of '%s': %lld (error: %d)\n", arguments[i], x, EINVAL == errno); printf("strlen: %zu utf8_count: %zu\n", strlen(arguments[i]), utf8_count(arguments[i])); } printf("%s\n", format("%p is a goat", main)); return 0; }