当前位置: 首页>>代码示例>>C++>>正文


C++ parse_num函数代码示例

本文整理汇总了C++中parse_num函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_num函数的具体用法?C++ parse_num怎么用?C++ parse_num使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了parse_num函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: parse_line_column

/* Read two ssize_t's, separated by a comma, from str, and store them in
 * *line and *column (if they're not both NULL).  Return FALSE on error,
 * or TRUE otherwise. */
bool parse_line_column(const char *str, ssize_t *line, ssize_t *column)
{
    bool retval = TRUE;
    const char *comma;

    assert(str != NULL);

    comma = strchr(str, ',');

    if (comma != NULL && column != NULL) {
	if (!parse_num(comma + 1, column))
	    retval = FALSE;
    }

    if (line != NULL) {
	if (comma != NULL) {
	    char *str_line = mallocstrncpy(NULL, str, comma - str + 1);
	    str_line[comma - str] = '\0';

	    if (str_line[0] != '\0' && !parse_num(str_line, line))
		retval = FALSE;

	    free(str_line);
	} else if (!parse_num(str, line))
	    retval = FALSE;
    }

    return retval;
}
开发者ID:sria91,项目名称:nano,代码行数:32,代码来源:utils.c

示例2: parse_hunk_header

int parse_hunk_header(char *line, int len,
		      int *ob, int *on,
		      int *nb, int *nn)
{
	char *cp;
	cp = line + 4;
	if (parse_num(&cp, ob)) {
	bad_line:
		return error("malformed diff output: %s", line);
	}
	if (*cp == ',') {
		cp++;
		if (parse_num(&cp, on))
			goto bad_line;
	}
	else
		*on = 1;
	if (*cp++ != ' ' || *cp++ != '+')
		goto bad_line;
	if (parse_num(&cp, nb))
		goto bad_line;
	if (*cp == ',') {
		cp++;
		if (parse_num(&cp, nn))
			goto bad_line;
	}
	else
		*nn = 1;
	return -!!memcmp(cp, " @@", 3);
}
开发者ID:chidveer,项目名称:git,代码行数:30,代码来源:xdiff-interface.c

示例3: uforth_interpret

uforth_stat uforth_interpret(char *str) {
  uforth_stat stat;
  char *word;
  CELL wd_idx;
  char immediate = 0;
  char primitive = 0;

  uforth_iram->inbufptr = str;
  while(*(word = uforth_next_word()) != 0) {
    wd_idx = find_word(word,uforth_iram->currwordlen,0,&immediate,&primitive);
    switch (uforth_iram->compiling) {
    case 0:                     /* interpret mode */
      if (wd_idx == 0) {        /* number or trash */
        DCELL num = parse_num(word,uforth_uram->base);
        if (num == 0 && word[0] != '0') {
          uforth_abort_request(ABORT_NAW);
          uforth_abort();
          return E_NOT_A_WORD;
        }
        if (abs32(num) > (int32_t)MAX_CELL_NUM){
          dpush32(num);
        } else {
          dpush(num);
        }
      } else {
        stat = exec(wd_idx,primitive,uforth_uram->ridx-1);
        if (stat != OK) {
          uforth_abort();
          uforth_abort_clr();
          return stat;
        }
      }
      break;
    case 1:                     /* in the middle of a colon def */
      if (wd_idx == 0) {        /* number or trash */
        DCELL num = parse_num(word,uforth_uram->base);
        if (num == 0 && word[0] != '0') {
          uforth_abort_request(ABORT_NAW);
          uforth_abort();
          dict_end_def();
          return E_NOT_A_WORD;
        }
        /* OPTIMIZATION: Only DLIT big numbers */
        if (num < 0 || abs32(num) > (int32_t)MAX_CELL_NUM){
          dict_append(DLIT);
          dict_append(((uint32_t)num)>>16);
          dict_append(((uint16_t)num)&0xffff);
        } else {
          dict_append(LIT);
          dict_append(num);
        }
      } else if (word[0] == ';') { /* exit from a colon def */
开发者ID:item28,项目名称:tosqa-ssb,代码行数:52,代码来源:uforth.c

示例4: parse_real

/* int parse_real(char *str, double *v)
*   check whether str[] starts with a number, or number/number. If yes,
*   store the value in *v and return the length of the matching part.
*   Return value is the same as for the previous routine.
*/
static int parse_real(char *str, double *v)
{int i,ret; double d;
    i=0; if(*str==' '){ str++; i++; }
    ret=parse_num(str,v);
    if(ret<=0) return ret; // 0 or -1
    i+=ret; str+=ret;
    if(*str=='/'){
        str++; i++; d=*v;
        ret=parse_num(str,v);
        if(ret<=0) return -1; // syntax error
        i+=ret; *v = d/(*v);
    }
    return i;
}
开发者ID:lcsirmaz,项目名称:inner,代码行数:19,代码来源:data.c

示例5: act_width

static void act_width (void) {
    char buffer[80];
    char prompt[80];
    fileoffset_t w;
    fileoffset_t new_top;
    int error;

    sprintf (prompt, "Enter screen width in bytes (now %"OFF"d): ", width);
    if (!get_str (prompt, buffer, FALSE))
	return;
    w = parse_num (buffer, &error);
    if (error) {
	display_beep();
	strcpy (message, "Unable to parse width value");
	return;
    }
    if (w > 0) {
	width = w;
	fix_offset();
	new_top = cur_pos - (scrlines-1) * width;
	new_top = begline(new_top);
	if (top_pos < new_top)
	    top_pos = new_top;
    }
}
开发者ID:rdebath,项目名称:sgt,代码行数:25,代码来源:actions.c

示例6: act_goto

static void act_goto (void) {
    char buffer[80];
    fileoffset_t position, new_top;
    int error;

    if (!get_str("Enter position to go to: ", buffer, FALSE))
	return;			       /* user break */

    position = parse_num (buffer, &error);
    if (error) {
	display_beep();
	strcpy (message, "Unable to parse position value");
	return;
    }

    if (position < 0 || position > file_size) {
	display_beep();
	strcpy (message, "Position is outside bounds of file");
	return;
    }

    cur_pos = position;
    edit_type = !!edit_type;
    new_top = cur_pos - (scrlines-1) * width;
    if (new_top < 0)
	new_top = 0;
    new_top = begline(new_top);
    if (top_pos > cur_pos)
	top_pos = begline(cur_pos);
    if (top_pos < new_top)
	top_pos = new_top;
}
开发者ID:rdebath,项目名称:sgt,代码行数:32,代码来源:actions.c

示例7: parse_cryptofunction

static int
parse_cryptofunction(ocra_suite * ocra, const char *in)
{
	int ret, l;
	char *token, *string, *tofree;

	if (NULL == (tofree = string = strdup(in)))
		return RFC6287_ERR_POSIX;

	if ((NULL == (token = strsep(&string, "-"))) ||
	    (0 != strcmp(token, "HOTP")) ||
	    (NULL == (token = strsep(&string, "-"))) ||
	    (none == (ocra->hotp_alg = parse_alg(token))) ||
	    (NULL == (token = strsep(&string, "-"))) ||
	    (2 < (l = strlen(token))) ||
	    (-1 == (ocra->hotp_trunc = parse_num(token))) ||
	    ((0 != ocra->hotp_trunc) &&
	    ((4 > ocra->hotp_trunc) || (11 < ocra->hotp_trunc))) ||
	    ((10 > ocra->hotp_trunc) && (2 == l)))
		ret = RFC6287_INVALID_SUITE;
	else
		ret = 0;
	free(tofree);
	return ret;
}
开发者ID:sg2342,项目名称:pam_ocra,代码行数:25,代码来源:rfc6287.c

示例8: get_second_value

int
get_second_value(longint_t vars[], char *rhsarg,
			longint_t *second_value) {
	char *p;
	int varnum2;
	if (strchr(NUMCHRS, *rhsarg) != NULL ||
				strchr(SGNCHRS, *rhsarg) != NULL) {
		/* first character is a digit or a sign, so RHS 
		 * should be a number
		 */
		p = rhsarg+1;
		while (*p) {
			if (strchr(NUMCHRS, *p) == NULL) {
				/* nope, found an illegal character */
				return ERROR;
			}
			p++;
		}
		*second_value = parse_num(rhsarg);
		return !ERROR;
	} else {
		/* argument is not a number, so might be a variable */
		varnum2 = to_varnum(*rhsarg);
		if (varnum2==ERROR || strlen(rhsarg)!=1) {
			/* nope, not a variable either */
			return ERROR;
		}
		/* is a variable, so can use its value to assign to
		 * second_value
		 */
		*second_value = vars[varnum2];
		return !ERROR;
	}
	return ERROR;
}
开发者ID:ShreyashPatodia,项目名称:MyC,代码行数:35,代码来源:assignment2013comp10002.c

示例9: parse_timecmp

static struct expr *
parse_timecmp()
{
	enum prop prop;
	enum op op;

	if (token("atime"))
		prop = PROP_ATIME;
	else if (token("ctime"))
		prop = PROP_CTIME;
	else if (token("mtime"))
		prop = PROP_MTIME;
	else if (token("date"))
		prop = PROP_DATE;
	else
		return parse_cmp();

	op = parse_op();
	if (!op)
		parse_error("invalid comparison at '%.15s'", pos);

	int64_t n;
	if (parse_num(&n) || parse_dur(&n)) {
		struct expr *e = mkexpr(op);
		e->a.prop = prop;
		e->b.num = n;
		return e;
	}

	return 0;
}
开发者ID:Duncaen,项目名称:mblaze,代码行数:31,代码来源:mpick.c

示例10: act_offset

static void act_offset (void) {
    char buffer[80];
    char prompt[80];
    fileoffset_t o;
    fileoffset_t new_top;
    int error;

    sprintf (prompt, "Enter start-of-file offset in bytes (now %"OFF"d): ",
	     realoffset);
    if (!get_str (prompt, buffer, FALSE))
	return;
    o = parse_num (buffer, &error);
    if (error) {
	display_beep();
	strcpy (message, "Unable to parse offset value");
	return;
    }
    if (o >= 0) {
	realoffset = o;
	fix_offset();
	new_top = cur_pos - (scrlines-1) * width;
	new_top = begline(new_top);
	if (top_pos < new_top)
	    top_pos = new_top;
    }
}
开发者ID:rdebath,项目名称:sgt,代码行数:26,代码来源:actions.c

示例11: parse_row

/* parses a line of the file
 * tries to set the corresponding row in the matrix
 * returns false on error
 */
bool parse_row(char* s, int row, LinearProgram* lp) {
    assert(lp_is_valid(lp));
    assert(row >= 0);
    assert(row < get_rows(lp));

    char* end_ptr;
    int cols = get_cols(lp);

    int i;
    for (i = 0; i < cols; i++) {
        num_t num = parse_num(s, &end_ptr);

        if (!is_num_valid(num, s, end_ptr)) {
            return false;
        }

        set_coef(lp, row, i, num);
        s = end_ptr;
    }


    s = parse_type(s, row, lp);

    if (NULL == s) {
        return false;
    }

    num_t num = parse_num(s, &end_ptr);
    if (!is_num_valid(num, s, end_ptr)) {
        return false;
    }
    s = end_ptr;

    s = skip_spaces(s);

    if ('\0' != *s) {
        return false;
    }

    set_rhs(lp, row, num);

    assert(lp_is_valid(lp));
    return true;
}
开发者ID:hensc,项目名称:appfs,代码行数:48,代码来源:read_lp.c

示例12: sendhup

static void sendhup(char *str)
{
	int pid;

	if (parse_num(str, "PPPD_PID=", &pid) && pid != getpid()) {
		if (debug)
			dbglog("sending SIGHUP to process %d", pid);
		kill(pid, SIGHUP);
	}
}
开发者ID:AdrianHuang,项目名称:rt-thread-for-vmm,代码行数:10,代码来源:multilink.c

示例13: sophon_time_parse

Sophon_Result
sophon_time_parse (Sophon_VM *vm, Sophon_String *str, Sophon_Time *time)
{
	Sophon_Char *ptr;
	Sophon_Date date;
	Sophon_Result r;

	SOPHON_ASSERT(str && time);

	sophon_memset(&date, 0, sizeof(date));

	ptr = sophon_string_chars(vm, str);
	while (*ptr && sophon_isspace(*ptr))
		ptr++;

	if ((r = parse_num(vm, ptr, &date.year)) < 0)
		return r;
	date.year -= 1900;
	ptr += r;
	if (*ptr++ != '-')
		return SOPHON_ERR_PARSE;
	if ((r = parse_num(vm, ptr, &date.mon)) < 0)
		return r;
	date.mon--;
	ptr += r;
	if (*ptr++ != '-')
		return SOPHON_ERR_PARSE;
	if ((r = parse_num(vm, ptr, &date.mday)) < 0)
		return r;
	ptr += r;

	if ((*ptr == 'T') || (*ptr == ' ')) {
		ptr++;
		if ((r = parse_num(vm, ptr, &date.hour)) < 0)
			return r;
		ptr += r;
		if (*ptr++ != ':')
			return SOPHON_ERR_PARSE;
		if ((r = parse_num(vm, ptr, &date.min)) < 0)
			return r;
		ptr += r;
		if (*ptr++ != ':')
			return SOPHON_ERR_PARSE;
		if ((r = parse_num(vm, ptr, &date.sec)) < 0)
			return r;
		ptr += r;
		if (*ptr++ == '.') {
			if ((r = parse_num(vm, ptr, &date.msec)) < 0)
				return r;
			ptr += r;
		}
	} else {
		date.mday = 1;
	}

	return sophon_date_to_time(vm, &date, time);
}
开发者ID:sharpglasses,项目名称:SophonJS,代码行数:57,代码来源:sophon_date.c

示例14: parse_row

/* parses a line of the file
 * tries to set the corresponding row in the matrix
 * returns false on error
 */
bool parse_row(char* s, int row, LinearProgram* lp) {
    assert(lp_is_valid(lp));
    assert(row >= 0);
    assert(row < lp->rows);

    int i;
    char* end_ptr;
    for (i = 0; i < lp->cols; i++) {
        num_t num = parse_num(s, &end_ptr);

        if (!is_num_valid(num, s, end_ptr)) {
            return false;
        }

        lp->matrix[row][i] = num;
        s = end_ptr;
    }


    s = parse_type(s, row, lp);

    if (NULL == s) {
        return false;
    }

    num_t num = parse_num(s, &end_ptr);
    if (!is_num_valid(num, s, end_ptr)) {
        return false;
    }
    s = end_ptr;

    s = skip_spaces(s);

    if ('\0' != *s) {
        return false;
    }

    lp->vector[row] = num;

    assert(lp_is_valid(lp));
    return true;
}
开发者ID:AndreG-P,项目名称:appfs,代码行数:46,代码来源:linear_program.c

示例15: write_byte

/*----------------------------------------------------------------------
 * Write this byte into current packet
 */
static void
write_byte (const char *str)
{
    guint32 num;

    num = parse_num(str, FALSE);
    packet_buf[curr_offset] = (guint8) num;
    curr_offset ++;
    if (curr_offset >= max_offset) /* packet full */
        start_new_packet();
}
开发者ID:GerardGarcia,项目名称:wireshark,代码行数:14,代码来源:text_import.c


注:本文中的parse_num函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。