本文整理汇总了C++中parse_uint函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_uint函数的具体用法?C++ parse_uint怎么用?C++ parse_uint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_uint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse_version
/* Parses version string of the form <int>.<int> */
static bool parse_version(const char **string)
{
return
parse_uint(string, &major_version) &&
parse_char(string, '.') &&
parse_uint(string, &minor_version);
}
示例2: parse_lineno
static mrb_bool
parse_lineno(mrb_state *mrb, char **sp, listcmd_parser_state *st)
{
if (*sp == NULL || **sp == '\0') {
return FALSE;
}
st->has_line_min = FALSE;
st->has_line_max = FALSE;
if (parse_uint(sp, &st->line_min)) {
st->has_line_min = TRUE;
}
else {
return FALSE;
}
if (skip_char(sp, ',')) {
if (parse_uint(sp, &st->line_max)) {
st->has_line_max = TRUE;
}
else {
st->parse_error = TRUE;
return FALSE;
}
}
return TRUE;
}
示例3: parse_wrap_args
static int parse_wrap_args(const struct option *opt, const char *arg, int unset)
{
struct shortlog *log = opt->value;
log->wrap_lines = !unset;
if (unset)
return 0;
if (!arg) {
log->wrap = DEFAULT_WRAPLEN;
log->in1 = DEFAULT_INDENT1;
log->in2 = DEFAULT_INDENT2;
return 0;
}
log->wrap = parse_uint(&arg, ',', DEFAULT_WRAPLEN);
log->in1 = parse_uint(&arg, ',', DEFAULT_INDENT1);
log->in2 = parse_uint(&arg, '\0', DEFAULT_INDENT2);
if (log->wrap < 0 || log->in1 < 0 || log->in2 < 0)
return error(wrap_arg_usage);
if (log->wrap &&
((log->in1 && log->wrap <= log->in1) ||
(log->in2 && log->wrap <= log->in2)))
return error(wrap_arg_usage);
return 0;
}
示例4: perf_opt_parse
void
perf_opt_parse(int argc, char **argv)
{
int c;
opt_t *opt;
isc_result_t result;
unsigned int i;
progname = isc_file_basename(argv[0]);
perf_opt_add('h', perf_opt_boolean, NULL, "print this help",
NULL, NULL);
while ((c = getopt(argc, argv, optstr)) != -1) {
for (i = 0; i < nopts; i++) {
if (opts[i].c == c)
break;
}
if (i == nopts) {
perf_opt_usage();
exit(1);
}
if (c == 'h') {
perf_opt_usage();
exit(0);
}
opt = &opts[i];
result = ISC_R_SUCCESS;
switch (opt->type) {
case perf_opt_string:
*opt->u.stringp = optarg;
break;
case perf_opt_boolean:
*opt->u.boolp = ISC_TRUE;
break;
case perf_opt_uint:
*opt->u.uintp = parse_uint(opt->desc, optarg,
1, 0xFFFFFFFF);
break;
case perf_opt_timeval:
*opt->u.uint64p = parse_timeval(opt->desc, optarg);
break;
case perf_opt_double:
*opt->u.doublep = parse_double(opt->desc, optarg);
break;
case perf_opt_port:
*opt->u.portp = parse_uint(opt->desc, optarg,
0, 0xFFFF);
break;
}
}
if (optind != argc) {
fprintf(stderr, "unexpected argument %s\n", argv[optind]);
perf_opt_usage();
exit(1);
}
}
示例5: http_response_on_header
static int http_response_on_header(nghttp2_stream *stream, nghttp2_nv *nv,
int token, int trailer) {
if (nv->name[0] == ':') {
if (trailer ||
(stream->http_flags & NGHTTP2_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED)) {
return NGHTTP2_ERR_HTTP_HEADER;
}
}
switch (token) {
case NGHTTP2_TOKEN__STATUS: {
if (!check_pseudo_header(stream, nv, NGHTTP2_HTTP_FLAG__STATUS)) {
return NGHTTP2_ERR_HTTP_HEADER;
}
if (nv->valuelen != 3) {
return NGHTTP2_ERR_HTTP_HEADER;
}
stream->status_code = parse_uint(nv->value, nv->valuelen);
if (stream->status_code == -1) {
return NGHTTP2_ERR_HTTP_HEADER;
}
break;
}
case NGHTTP2_TOKEN_CONTENT_LENGTH: {
if (stream->content_length != -1) {
return NGHTTP2_ERR_HTTP_HEADER;
}
stream->content_length = parse_uint(nv->value, nv->valuelen);
if (stream->content_length == -1) {
return NGHTTP2_ERR_HTTP_HEADER;
}
break;
}
/* disallowed header fields */
case NGHTTP2_TOKEN_CONNECTION:
case NGHTTP2_TOKEN_KEEP_ALIVE:
case NGHTTP2_TOKEN_PROXY_CONNECTION:
case NGHTTP2_TOKEN_TRANSFER_ENCODING:
case NGHTTP2_TOKEN_UPGRADE:
return NGHTTP2_ERR_HTTP_HEADER;
case NGHTTP2_TOKEN_TE:
if (!lstrieq("trailers", nv->value, nv->valuelen)) {
return NGHTTP2_ERR_HTTP_HEADER;
}
break;
default:
if (nv->name[0] == ':') {
return NGHTTP2_ERR_HTTP_HEADER;
}
}
if (nv->name[0] != ':') {
stream->http_flags |= NGHTTP2_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED;
}
return 0;
}
示例6: application_function_flash_receive
app_action_t application_function_flash_receive(string_t *src, string_t *dst)
{
unsigned int chunk_offset, chunk_length;
if(string_size(&flash_sector_buffer) < SPI_FLASH_SEC_SIZE)
{
string_format(dst, "ERROR flash-receive: flash sector buffer too small: %d\n", string_size(&flash_sector_buffer));
return(app_action_error);
}
if(parse_uint(1, src, &chunk_offset, 0, ' ') != parse_ok)
{
string_append(dst, "ERROR flash-receive: chunk offset required\n");
return(app_action_error);
}
if(parse_uint(2, src, &chunk_length, 0, ' ') != parse_ok)
{
string_append(dst, "ERROR flash-receive: chunk chunk_length required\n");
return(app_action_error);
}
if((chunk_length == 0) || ((chunk_offset % chunk_length) != 0))
{
string_append(dst, "ERROR: flash-receive: chunk offset should be divisible by chunk size");
return(app_action_error);
}
if((chunk_length == 0) || ((SPI_FLASH_SEC_SIZE % chunk_length) != 0))
{
string_append(dst, "ERROR: flash-receive: chunk length should be divisible by flash sector size");
return(app_action_error);
}
if((chunk_offset + chunk_length) > SPI_FLASH_SEC_SIZE)
{
string_format(dst, "ERROR flash-receive: chunk_length(%u) + chunk_offset(%u) > sector size(%d)\n", chunk_length, chunk_offset, SPI_FLASH_SEC_SIZE);
return(app_action_error);
}
if((flash_sector_buffer_use != fsb_free) && (flash_sector_buffer_use != fsb_config_cache) && (flash_sector_buffer_use != fsb_ota))
{
string_format(dst, "ERROR: flash_send: sector buffer in use: %u\n", flash_sector_buffer_use);
return(app_action_error);
}
flash_sector_buffer_use = fsb_ota;
string_format(dst, "OK flash-receive: sending bytes: %u, from offset: %u, data: @", chunk_length, chunk_offset);
string_splice(dst, -1, &flash_sector_buffer, chunk_offset, chunk_length);
string_append(dst, "\n");
if((chunk_offset + chunk_length) >= SPI_FLASH_SEC_SIZE)
flash_sector_buffer_use = fsb_free;
return(app_action_normal);
}
示例7: application_function_flash_checksum
app_action_t application_function_flash_checksum(string_t *src, string_t *dst)
{
unsigned int address, current, length, done;
SHA_CTX sha_context;
unsigned char sha_result[SHA_DIGEST_LENGTH];
string_new(, sha_string, SHA_DIGEST_LENGTH * 2 + 2);
if(parse_uint(1, src, &address, 0, ' ') != parse_ok)
{
string_append(dst, "ERROR flash-checksum: address required\n");
return(app_action_error);
}
if(parse_uint(2, src, &length, 0, ' ') != parse_ok)
{
string_append(dst, "ERROR flash-checksum: length required\n");
return(app_action_error);
}
if((address % SPI_FLASH_SEC_SIZE) != 0)
{
string_append(dst, "ERROR: flash_checksum: address should be divisible by flash sector size");
return(app_action_error);
}
if((length % SPI_FLASH_SEC_SIZE) != 0)
{
string_append(dst, "ERROR: flash_checksum: length should be divisible by flash sector size");
return(app_action_error);
}
SHA1Init(&sha_context);
for(current = address, done = 0; done < length; current += SPI_FLASH_SEC_SIZE, done += SPI_FLASH_SEC_SIZE)
{
spi_flash_read(current, string_buffer_nonconst(dst), SPI_FLASH_SEC_SIZE);
SHA1Update(&sha_context, string_buffer(dst), SPI_FLASH_SEC_SIZE);
}
SHA1Final(sha_result, &sha_context);
string_bin_to_hex(&sha_string, sha_result, SHA_DIGEST_LENGTH);
string_clear(dst);
string_format(dst, "OK flash-checksum: checksummed bytes: %u, from address: %u, checksum: ", done, address);
string_append_string(dst, &sha_string);
string_append(dst, "\n");
return(app_action_normal);
}
示例8: format_str_v
int
format_str_v(const StrFormatContext *ctxt, const char *format, va_list ap)
{
unsigned int written = 0;
const char *pos = format;
while(*pos != '\0') {
FormatFlags flags;
unsigned int minwidth = 0;
int precision = -1; /* Negative means no precision */
char ch;
const char *start = pos;
while( (ch = *pos) != '\0' && ch != '%') pos++;
if (pos != start) {
CHECKCB(ctxt->write_str(ctxt->user_data, start, pos - start));
written += pos - start;
}
if (*pos == '\0') {
va_end(ap);
return written;
}
pos++;
if (*pos == '\0') {
va_end(ap);
return written;
}
flags = parse_flags(&pos);
/* parse width */
if (*pos >= '1' && *pos <= '9') {
minwidth = parse_uint(&pos);
} else if (*pos == '*') {
int w = va_arg(ap,int);
if (w < 0) {
flags |= JUSTIFY_LEFT;
minwidth = w;
} else {
minwidth = w;
}
pos ++;
}
/* parse precision */
if (*pos == '.') {
pos++;
if (*pos >= '0' && *pos <= '9') {
precision = parse_uint(&pos);
} else if (*pos == '*') {
pos++;
precision = va_arg(ap,int);
}
示例9: parse_register_dcl_bracket
static boolean
parse_register_dcl_bracket(
struct translate_ctx *ctx,
struct parsed_dcl_bracket *bracket)
{
uint uindex;
memset(bracket, 0, sizeof(struct parsed_dcl_bracket));
eat_opt_white( &ctx->cur );
if (!parse_uint( &ctx->cur, &uindex )) {
/* it can be an empty bracket [] which means its range
* is from 0 to some implied size */
if (ctx->cur[0] == ']' && ctx->implied_array_size != 0) {
bracket->first = 0;
bracket->last = ctx->implied_array_size - 1;
goto cleanup;
}
report_error( ctx, "Expected literal unsigned integer" );
return FALSE;
}
bracket->first = uindex;
eat_opt_white( &ctx->cur );
if (ctx->cur[0] == '.' && ctx->cur[1] == '.') {
uint uindex;
ctx->cur += 2;
eat_opt_white( &ctx->cur );
if (!parse_uint( &ctx->cur, &uindex )) {
report_error( ctx, "Expected literal integer" );
return FALSE;
}
bracket->last = (int) uindex;
eat_opt_white( &ctx->cur );
}
else {
bracket->last = bracket->first;
}
cleanup:
if (*ctx->cur != ']') {
report_error( ctx, "Expected `]' or `..'" );
return FALSE;
}
ctx->cur++;
return TRUE;
}
示例10: gtp_boardsize
static void gtp_boardsize(
FILE * fp,
int id,
const char * new_size
){
if(new_size == NULL)
{
gtp_answer(fp, id, BOARD_SIZ_AS_STR);
return;
}
u32 ns;
if(!parse_uint(&ns, new_size))
{
gtp_error(fp, id, "syntax error");
return;
}
if(ns != BOARD_SIZ)
{
gtp_error(fp, id, "unacceptable size");
fprintf(stderr, "board size cannot be changed on runtime; please edit t\
he master header file and recompile matilda\n");
char * s = alloc();
snprintf(s, MAX_PAGE_SIZ, "requested board size change to %ux%u", ns,
ns);
flog_info("gtp", s);
release(s);
}
示例11: set_ndots
static void
set_ndots(const char *value) {
isc_uint32_t n;
isc_result_t result = parse_uint(&n, value, 128, "ndots");
if (result == ISC_R_SUCCESS)
ndots = n;
}
示例12: parse_archive_parameters
/* Parses expected server response to CFdDVK command: should be four newline
* terminated numbers and a version string. */
static bool parse_archive_parameters(const char **string)
{
return
parse_double(string, &sample_frequency) &&
parse_char(string, '\n') &&
parse_uint(string, &first_decimation) &&
parse_char(string, '\n') &&
parse_uint(string, &second_decimation) &&
parse_char(string, '\n') &&
parse_version(string) &&
parse_char(string, '\n') &&
parse_uint(string, &fa_entry_count) &&
parse_char(string, '\n') &&
parse_uint(string, &continuous_decimation) &&
parse_char(string, '\n');
}
示例13: set_timeout
static void
set_timeout(const char *value) {
isc_uint32_t n;
isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
if (result == ISC_R_SUCCESS)
timeout = n;
}
示例14: set_tries
static void
set_tries(const char *value) {
isc_uint32_t n;
isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
if (result == ISC_R_SUCCESS)
tries = n;
}
示例15: room_attr_set
/**
* set an attribute on a room.
*/
static int room_attr_set(struct room *r, const char *name, const char *value) {
int res;
assert(r != NULL);
assert(name != NULL);
assert(value != NULL);
if(!r) return 0;
if(!strcasecmp("id", name))
res=parse_uint(name, value, &r->id);
else if(!strcasecmp("name.short", name))
res=parse_str(name, value, &r->name.short_str);
else if(!strcasecmp("name.long", name))
res=parse_str(name, value, &r->name.long_str);
else if(!strcasecmp("desc.short", name))
res=parse_str(name, value, &r->desc.short_str);
else if(!strcasecmp("desc.long", name))
res=parse_str(name, value, &r->desc.long_str);
else if(!strcasecmp("creator", name))
res=parse_str(name, value, &r->creator);
else if(!strcasecmp("owner", name))
res=parse_str(name, value, &r->owner);
else
res=parse_attr(name, value, &r->extra_values);
if(res)
r->dirty_fl=1;
return res;
}