Exemplo n.º 1
0
int cmd_arg(char *param)
{
	char **argv;
	int argc, opts;
	unsigned to_del, base, shiftlevel;

	if((argv = scanCmdline(param, 0, 0, &argc, &opts)) == 0)
		return 1;

	/* Because no option was passed into scanCmdline() no
		option can have been processed */
	assert(opts == 0);

	shiftlevel = base = to_del = 0;		/* for argc == 0 */
	if(argc == 0 
	 || argc == 3 && is_num(argv[0], &base) && is_num(argv[1], &to_del)
	     && is_num(argv[2], &shiftlevel) && base <= to_del) {
	     	ctxtPopTo(CTXT_TAG_ARG, to_del);
			gflag_shiftlevel = shiftlevel;
			gflag_base_shiftlevel = base;
			freep(argv);
			return 0;
	}

	error_syntax(0);
	freep(argv);
	return 1;
}
Exemplo n.º 2
0
int tokenize(char* p) {
    int len;
    switch (*p) {
    case '\0':
    case '\r':
    case '\n':
        return 0;
    case ' ':
    case '*':
    case '+':
    case '/':
        return 1;
    case '-':
        if(is_num(*(p+1))) {
            len = 0;
            while(is_num(*(p+len+1))) {
                len++;
            }
            return len+1; /*sign*/
        } else {
            return 1;
        }
        break;
    default: /*0-9*/
        len = 0;
        while(is_num(*(p+len))) {
            len++;
        }
        return len;
        break;
    }
    return 0;
}
Exemplo n.º 3
0
int exec_settime(tParams * params) {

	if(params->args_amount != 4) {
		error_set(INVALID_ENTRY, (params->args)[0]);
		return 1;
	}
	
	if(!is_num(params->args[1]) || !is_num(params->args[2]) || !is_num(params->args[3])) {
		error_set(INVALID_ENTRY, (params->args)[0]);
		return 1;
	}
	
	int h, m, s;
	
	h = atoi(params->args[1]);
	m = atoi(params->args[2]);
	s = atoi(params->args[3]);
	
	if(!IS_HOUR(h) || !IS_MINUTE(m) || !IS_SECOND(s)) {
		error_set(INVALID_ENTRY, (params->args)[0]);
		return 1;
	}
	
	time_set_time(s,m,h);
	
	return 0;
}
Exemplo n.º 4
0
Arquivo: num.cpp Projeto: avigad/lean
bool is_signed_num(expr const & e) {
    if (is_num(e))
        return true;
    else if (auto r = is_neg(e))
        return is_num(*r);
    else
        return false;
}
Exemplo n.º 5
0
/*******************************************************************************
 * Fonction principale de l'analyseur lexical, lit les caractères de yyin et
 * renvoie les tokens sous forme d'entier. Le code de chaque unité est défini 
 * dans symboles.h sinon (mot clé, idententifiant, etc.). Pour les tokens de 
 * type ID_FCT, ID_VAR et NOMBRE la valeur du token est dans yytext, visible 
 * dans l'analyseur syntaxique.
 ******************************************************************************/
int yylex(void) {
    char c;
    int i;
    yytext[yyleng = 0] = '\0';

    if (mange_espaces() == -1)
        return FIN;

    c = lire_car();

    for (i = 0; i < nb_symboles; i++)
        if (table_symboles[i] == c)
            return code_symboles[i];

    if (is_num(c)) {
        do {
            c = lire_car();
        } while (is_num(c));
        delire_car();

        return NOMBRE;
    }

    if (is_maj(c) || is_min(c)) {
        do {
            if (yyleng >= YYTEXT_MAX - 1) {
                printf("Erreur ligne %d: un nom de fonction fait plus de 99 caractères\n", nb_ligne);
                exit(1);
            }

            c = lire_car();
        } while (is_maj(c) || is_min(c) || (c) == '_');
        delire_car();

        for (i = 0; i < nb_mots_clefs; i++)
            if (strcasecmp(table_mots_clefs[i], yytext) == 0)
                return code_mot_clefs[i];

        return ID_FCT;
    }

    if ((c) == '$') {
        do {
            if (yyleng >= YYTEXT_MAX - 1) {
                printf("Erreur ligne %d: un nom de variable fait plus de 99 caractères\n", nb_ligne);
                exit(1);
            }

            c = lire_car();
        } while (is_maj(c) || is_min(c) || is_num(c) || (c) == '_');
        delire_car();

        return ID_VAR;
    }

    printf("Erreur inconnue ligne %d.\n", nb_ligne);
    exit(1);
}
Exemplo n.º 6
0
/**
  Internal function to test retrieving a SQL_NUMERIC_STRUCT value.

  @todo Printing some additional output (sqlnum->val as hex, dec)

  @param[in]  hstmt       Statement handle
  @param[in]  numstr      String to retrieve as SQL_NUMERIC_STRUCT
  @param[in]  prec        Precision to retrieve
  @param[in]  scale       Scale to retrieve
  @param[in]  sign        Expected sign (1=+,0=-)
  @param[in]  expdata     Expected byte array value (need this or expnum)
  @param[in]  expnum      Expected numeric value (if it fits)
  @param[in]  overflow    Whether to expect a retrieval failure (22003)
  @return OK/FAIL just like a test.
*/
int sqlnum_test_from_str(SQLHANDLE Stmt,
                         const char *numstr, SQLCHAR prec, SQLSCHAR scale,
                         SQLCHAR sign, SQLCHAR *expdata, int expnum,
                         int overflow)
{
  SQL_NUMERIC_STRUCT *sqlnum= malloc(sizeof(SQL_NUMERIC_STRUCT));
  SQLCHAR buf[512];
  SQLHANDLE ard;
  unsigned long numval;

  sprintf((char *)buf, "select %s", numstr);
  /* OK_SIMPLE_STMT(Stmt, buf); */
  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLExecDirect(Stmt, buf, SQL_NTS));

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLGetStmtAttr(Stmt, SQL_ATTR_APP_ROW_DESC, &ard, 0, NULL));

  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_TYPE,
                               (SQLPOINTER) SQL_C_NUMERIC, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_PRECISION,
                               (SQLPOINTER)(SQLLEN) prec, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_SCALE,
                               (SQLPOINTER)(SQLLEN) scale, SQL_IS_INTEGER));
  CHECK_HANDLE_RC(SQL_HANDLE_DESC, ard, SQLSetDescField(ard, 1, SQL_DESC_DATA_PTR,
                               sqlnum, SQL_IS_POINTER));

  if (overflow)
  {
    FAIL_IF(SQLFetch(Stmt) != SQL_ERROR, "expected SQL_ERROR");
    FAIL_IF(check_sqlstate(Stmt, "22003") != OK, "expected error 22003");
  }
  else
    CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFetch(Stmt));

  is_num(sqlnum->precision, prec);
  is_num(sqlnum->scale, scale);
  is_num(sqlnum->sign, sign);
  if (expdata)
  {
    IS(!memcmp(sqlnum->val, expdata, SQL_MAX_NUMERIC_LEN));
  }
  else
  {
    /* only use this for <=32bit values */
    int i;
    numval= 0;
    for (i= 0; i < 8; ++i)
      numval += sqlnum->val[7 - i] << (8 * (7 - i));
    
    if (numval != expnum)
      diag("compare %d %d", numval, expnum);
    is_num(numval, expnum);
  }

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

  free(sqlnum);
  return OK;
}
int analyser_mot(char c) {
	int count = 1;
	
	if (c == '$') {
	//	printf("analyser_mot VARIABLE c = %c \n", c);
		while(count < YYTEXT_MAX - 80) {
			c = lireCar();

			if (count < YYTEXT_MAX && !(is_num(c) || is_min(c) || is_maj(c) || c == '_')) {
				/*//printf("BEFORE, count = %i\n", count);
				for (int i = 0; i < YYTEXT_MAX - 1; i++) 
					printf("%c",yytext[i]);
				printf("\n");*/
				delireCar();
				/*printf("AFTER\n");
				for (int i = 0; i < YYTEXT_MAX - 1; i++) 
					printf("%c",yytext[i]);
				printf("\n");*/
				return ID_VAR;
			}
			else if (count >= YYTEXT_MAX) {
				delireCar();
				return -1;
			}
			count++;	
		} 
	}
	if (is_num(c)) {
		//printf("analyser_mot NUMBER c = %c \n", c);
		while(1) {
			c = lireCar();
			//printf("%c\n", c);
			if (!is_num(c)) {
				delireCar();
				return NOMBRE;
			} 
		}
	}
	//printf("analyser_mot FUNCTION/KEYWORD c = %c \n", c);
	while(count < YYTEXT_MAX) {
		c = lireCar();
		//printf("%c\n", c);
		if (count == YYTEXT_MAX - 1 && c != '(') {
			delireCar();
			return -1;
		}
		//printf("test1\n");
		if (!(is_num(c) || is_min(c) || is_maj(c) || c == '_')) {
			delireCar();
			int resultat = estMotClef();
			if (resultat != -1)
				return resultat;
			return ID_FCT;
		}
		count++;
	}
	return -1;
}
Exemplo n.º 8
0
Arquivo: main.c Projeto: tcolgate/test
int
shunt(opstack_t* out, int argc, char** argv){
  for(int i = 0; i < argc; i++){
    char* t = argv[i];
    if (is_num(t)){
    } else if (is_num(t)){
    } else {
      return -1;
    }
  }
}
Exemplo n.º 9
0
int get_num( int num[] )
{
	int c, sign;
	unsigned total = 0;

	/* Chomp & get first integer character */
	while( ( c = getchar() ) != EOF && c != '-' && !is_num( c ) );
	/* Negative integer */
	if( c == '-' )
	{
		sign = -1;
		total = 0;
	}
	/* Positive integer */
	else if( is_num( c ) )
	{
		sign = 1;
		total = c - '0';
	}
	/* Errors */
	else if( c == EOF )
	{
		num[ 1 ] = EOF; // tells main() to quit loop
		return ERROR; // no input
	}
	else
	{
		return ERROR; // not an integer
	}

	/* Get the rest of the integer characters */
	while( ( c = getchar() ) != EOF && is_num( c ) )
	{
		total = total * 10 + c - '0';
	}
	num[ 0 ] = total * sign; // assign sign (hehehe)

	/* Determine if integer entry has any errors */
	if( c == EOF )
	{
		num[ 1 ] = EOF;
		return NOERR; // final integer before end of file
	}
	else if( is_ws( c ) )
	{
		return NOERR; // integer separated by white space
	}
	else
	{
		return ERROR; // not an integer
	}
}
Exemplo n.º 10
0
END_TEST




START_TEST(is_num_test)
  {
  fail_unless(is_num("") == 0, "empty string isn't a number");
  fail_unless(is_num("1a") == 0, "1a isn't a number");
  fail_unless(is_num("a1") == 0, "a1 isn't a number");
  fail_unless(is_num("1234") == 1, "1234 is a number");
  fail_unless(is_num("12143141324132434") == 1, "12143141324132434 is a number");
  }
Exemplo n.º 11
0
/* identify the fractional part of a number */
static statefn fractional(scanner_t *s) {
  if (!is_num(scanner_peek(s))) {
    fprintf(stderr, "lexer error: expected fractional part\n");
    return error;
  }

  while (is_num(scanner_advance(s)));

  if (scanner_current(s) == 'e' ||
      scanner_current(s) == 'E')
    return (statefn)exponent;

  scanner_backup(s);
  return done;
}
Exemplo n.º 12
0
static obj_t make_string_fn(obj_t args, Reporter rep)
{
	size_t nargs, i, k;
	char ch;
	string str;

	nargs = list_length(args);
	if (nargs == 0 || nargs > 2) {
		reportf(rep, "make-string: "
			"length and optional fill char expected");
		return unspecific;
	}
	if (!is_num(list_ref(args, 0))) {
		reportf(rep, "make-string: "
			"first argument must be a non-negative integer");
		return unspecific;
	}
	if (nargs == 2 && !is_char(list_ref(args, 1))) {
		reportf(rep, "make-string: "
			"second argument must be a character");
		return unspecific;
	}

	k = fetch_num(list_ref(args, 0));
	ch  = (nargs == 1) ? 0 : fetch_char(list_ref(args, 1));

	str = string_alloc(k);
	for (i = 0; i < str->len; i++)
		str->data[i] = ch;
	return make_string(str);
}
Exemplo n.º 13
0
void	resolv(char *base, char *opers, int *i, char **tabexpr, t_list **op, t_list **nb)
{
  char		*expr1;
  char		*operator;
  char		*expr2;
  
  my_put_in_list(op, tabexpr[*i]);
  *i = *i + 1;
  if (is_num(base, opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, tabexpr[*i]);
  if (is_open_parent(opers, tabexpr[*i]) == 1)
    my_put_in_list(nb, parenthesis_mode(base, opers, i, tabexpr));
  if (is_low_op(opers, tabexpr[*i]))
    my_put_in_list(nb, check_sp_low(base, opers, i, tabexpr));
  if ((expr2 = malloc(sizeof(*expr2) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr2 = (*nb)->data;
  depile(nb);
  operator = malloc(sizeof(*operator) * (my_strlen((*op)->data) + 1));
  operator = (*op)->data;
  depile(op);
  if ((expr1 = malloc(sizeof(*expr1) * (my_strlen((*nb)->data) + 1))) == 0)
    exit(-1);
  expr1 = (*nb)->data;
  depile(nb);
  my_put_in_list(nb, operations(base, opers, expr1, operator, expr2));
}
Exemplo n.º 14
0
char		*eval_expr(char *base, char *operators, char *expr, int size)
{
  char		**tabexpr;
  t_list	*op;
  t_list	*nb;
  int		i;
  
  tabexpr = str_to_tab_string(base, expr, operators);
  op = 0;
  nb = 0;
  i = 0;
  while (tabexpr[i] != 0)
    {
      if (is_open_parent(operators, tabexpr[i]) == 1)
	my_put_in_list(&nb, parenthesis_mode(base, operators, &i, tabexpr));
      if (is_num(base, operators, tabexpr[i]) == 1)
	my_put_in_list(&nb, tabexpr[i]);
      if (is_low_op(operators, tabexpr[i]) == 1)
	my_put_in_list(&op, tabexpr[i]);
      if (is_high_op(operators, tabexpr[i]) == 1)
	resolv(base, operators, &i, tabexpr, &op, &nb);
      i = i + 1;
    }
  return (depile_all(base, operators, op, nb));
}
Exemplo n.º 15
0
int alm_print_term(ATERM t) {
    int count = 0;
    if (is_num(t))
	count += printf("%.1lf", num_val(t));
    else if (is_nil(t))
	count += printf("[]");
    else if (is_cons(t)) {
	count += printf("[");
	ATERM tmp = t;
	while (is_cons(tmp)) {
	    count += alm_print_term(CAR(tmp));
	    if (is_cons(CDR(tmp))) {
		count += printf(",");
	    } else if (!is_nil(CDR(tmp))) {
		count += printf("|");
		count += alm_print_term(CDR(tmp));
	    }
	    tmp = CDR(tmp);
	}
	count += printf("]");
    } else if (is_boxed(t)) {
	ATERM *box = boxed_ptr(t);
	if (is_atom(*box))
	    count += printf("%.*s", (int) box[1].bin, (char*) (box + 2));
    } else if (is_frame(t)) {
	count += printf("<frame/0x%.3llX>",frame_val(t));
    }
    return count;
}
Exemplo n.º 16
0
void ps_command(int argc, char ** argv)
{
    DIR * dir;
    struct dirent * entry;
    if ((dir = opendir("/proc")) == NULL)
    {
        perror("Unable to open /proc");
    }
    printf("%.12s%25s\n", "PPID", "COMM");
    char * proc_path = (char*) malloc(MAX_PATH);
    while((entry = readdir(dir)) != NULL)
        if (entry->d_type == DT_DIR && is_num(entry->d_name)) {

            sprintf(proc_path, "%s/%s/comm", "/proc",entry->d_name);
            int comm;
            comm = open(proc_path, O_RDONLY);
            if (comm < 0) {
                perror("Unable to open comm");
                return;
            };
            char buffer[BUFFER_SIZE + 1];
            ssize_t read_bytes;

            while ((read_bytes = read(comm, buffer, BUFFER_SIZE)) > 0) {
                buffer[read_bytes] = 0;
                printf("%.12s%25s", entry->d_name,buffer);
            }
            close(comm);
        }
    free(proc_path);
}
Exemplo n.º 17
0
Arquivo: plv.c Projeto: GhaisB/Zappy
void			plv(t_server *server, t_client *client,
			    char *cmd, char **av)
{
  int			fd;
  t_client		*cl;

  (void) cmd;
  if (tablen(av) != 2)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  if (!is_num(av[1]))
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  fd = atoi(av[1]);
  if (fd <= 0)
    {
      add_client_response(&(client), "sbp\n");
      return ;
    }
  cl = client_by_id(server, fd);
  send_level(client, cl);
}
Exemplo n.º 18
0
/* identify the exponent of a number */
static statefn exponent(scanner_t *s) {
  /* accept exponent signs if any */
  char c = scanner_peek(s);
  if (c == '+' || c == '-')
    scanner_advance(s);

  if (!is_num(scanner_peek(s))) {
    fprintf(stderr, "lexer error: expected exponent\n");
    return error;
  }

  while (is_num(scanner_advance(s)));

  scanner_backup(s);
  return done;
}
Exemplo n.º 19
0
/*
  	Search the version string in the ROM
	Arguments:
  	- ptr: a ROM or update image
  	- size: the size of the buffer
  	- version: the returned string version
*/
static int get_rom_version(char *ptr, int size, char *version)
{
  	int i;

  	strcpy(version, "?.??");

  	for (i = SPP; i < size-16; i += 2)
    {
      if (is_num(ptr[i])&&(ptr[i+1]=='.') && is_num(ptr[i+2]) &&
	  (ptr[i+3]==0)&&is_alnum(ptr[i+4]) && is_alnum(ptr[i+5]) &&
	  (ptr[i+6]=='/')&&is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) &&
	  (ptr[i+9]=='/')&&is_alnum(ptr[i+10]) && is_alnum(ptr[i+11]))
	  	break;

      if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && 
	  is_num(ptr[i+3]) && (ptr[i+4]==0) && is_alnum(ptr[i+5]) && 
	  is_alnum(ptr[i+6]) && (ptr[i+7]=='/') && is_alnum(ptr[i+8]) && 
	  is_alnum(ptr[i+9]) && (ptr[i+10]=='/') && is_alnum(ptr[i+11]) && 
	  is_alnum(ptr[i+12]))
		break;
	
	  if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && 
	  (ptr[i+3]==0) && is_alnum(ptr[i+4]) && is_alnum(ptr[i+5]) && 
	  is_alnum(ptr[i+6]) && is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) && 
	  is_alnum(ptr[i+9]) && is_alnum(ptr[i+10]) && is_alnum(ptr[i+11]))
	  	break;

      if (is_num(ptr[i]) && (ptr[i+1]=='.') && is_num(ptr[i+2]) && 
	  is_alnum(ptr[i+3]) && (ptr[i+4]==0) && is_alnum(ptr[i+5]) && 
	  is_alnum(ptr[i+6]) && is_alnum(ptr[i+7]) && is_alnum(ptr[i+8]) && 
	  is_alnum(ptr[i+9]) && is_alnum(ptr[i+10]) && is_alnum(ptr[i+11]))
	  	break;
    }
  
  	if (i < size-16) 
    {
      	int n;
      
      	for(n = i; n < i+16; n++) 
		{
	  		if (ptr[n]==0) 
	    	{
	      		strcpy(version, ptr+i);
	      		(version)[n-i]=0;

	      		return 0;
	    	}
		}
    }
    
  	return 0;
}
Exemplo n.º 20
0
void sub_func(void)
{
	double a = get_value(VAL_1);
	double b = get_value(VAL_2);

	if (!is_num(a) || !is_num(b)) {
		fprintf(stderr, STR_ERROR("incorrect values"));
		return;
	}

	double r = a - b;

	if (!is_num(r))
		fprintf(stderr, STR_ERROR_RESULT(r));
	else
		fprintf(stdout, STR_RESULT(a-b));
}
Exemplo n.º 21
0
Arquivo: num.cpp Projeto: avigad/lean
static bool is_num(expr const & e, bool first) {
    buffer<expr> args;
    expr const & f = get_app_args(e, args);
    if (!is_constant(f))
      return false;
    if (const_name(f) == get_has_one_one_name())
        return args.size() == 2;
    else if (const_name(f) == get_has_zero_zero_name())
        return first && args.size() == 2;
    else if (const_name(f) == get_nat_zero_name())
        return first && args.size() == 0;
    else if (const_name(f) == get_bit0_name())
        return args.size() == 3 && is_num(args[2], false);
    else if (const_name(f) == get_bit1_name())
        return args.size() == 4 && is_num(args[3], false);
    return false;
}
Exemplo n.º 22
0
/***********************************************************************
* function	:	fill_manual()
* purpose	:	ask user to fill in a coupon
* argument	:
*   — int cpn_id	:	coupons id
*	— bool *nums	:	pointer to boolean array representing coupon
* return	:	pointer to struct of type coupon
* notes		:
*   — returnes pointer returned from cpn_gen()
***********************************************************************/
cpn_ptr fill_manual(int cpn_id, bool *nums){

	char tmp[BUFSIZ];
	int gss_ctr, guess;

	for (gss_ctr = 0; gss_ctr < 6;){

		printf("\n Please give your guess for ");
		/* make guess for joker */
		if (gss_ctr == 5){
			printf("joker\t:\t");
			fflush(stdin);
			scanf("%s", &tmp);
			getchar();
			if (is_num(tmp) && (atoi(tmp) < (MAXJ + 1)) && (atoi(tmp) > (MINV - 1))){
				guess = atoi(tmp);
				gss_ctr++;
			}
			else{
				printf("\a Invalid input\n Please try again within 1 and 20");
			}
		}
		/* make guesses for winning numbers */
		else{
			printf("number #%d\t:\t", gss_ctr + 1);
			fflush(stdin);
			scanf("%s", &tmp);
			getchar();
			if (is_num(tmp) && (atoi(tmp) <= MAXV) && (atoi(tmp) >= MINV)){
				guess = atoi(tmp);
			}
			else{
				printf("\a Invalid input\n Please try again within 1 and 45");
			}

			/* validate guess */
			if (nums[guess - 1] == false){
				nums[guess - 1] = true;
				gss_ctr++;
			}
		}
	}

	return(cpn_gen(cpn_id, nums, guess));
}
Exemplo n.º 23
0
char		is_alphanum(char c)
{
  char		ret;

  ret = 0;
  if (is_num(c) == 1 || is_alpha(c) == 1)
    ret = 1;
  return (ret);
}
Exemplo n.º 24
0
void phone_book_create(Phone_Book *pb, char *name, char *num) {
    if (!is_name(name) || !is_num(num)) {
        print_wrong_input_msg();
        return;
    }
    phone_book_init_from_file(pb);
    record_set(&pb->v[pb->used++], phone_book_find_free_id(pb), name, num);
    phone_book_unload_to_file(pb);
}
Exemplo n.º 25
0
/* judge if d_name is process name */
boolean is_process_name(char * d_name)
{
	while(*d_name != '\0') {
		if (! is_num(*d_name)) return FALSE;
		d_name++;
	}
     
	return TRUE;
}
Exemplo n.º 26
0
int             my_getnbr(char *str)
{
  int           i;
  int           nbr;

  nbr = 0;
  i = 0;
  while (is_num(str[i]) == 0)
    i++;
  while (is_num(str[i]) == 1)
    {
      nbr = ((nbr * 10) + (str[i] - 48));
      i++;
    }
  if (is_neg(str) == 1)
    nbr = -nbr;
  return (nbr);
}
Exemplo n.º 27
0
/**
  Internal function to test sending a SQL_NUMERIC_STRUCT value.

  @todo Printing some additional output (sqlnum->val as hex, dec)

  @param[in]  hstmt       Statement handle
  @param[in]  numdata     Numeric data
  @param[in]  prec        Precision to send
  @param[in]  scale       Scale to send
  @param[in]  sign        Sign (1=+,0=-)
  @param[in]  outstr      Expected result string
  @param[in]  exptrunc    Expected truncation failure
  @return OK/FAIL just like a test.
*/
int sqlnum_test_to_str(SQLHANDLE Stmt, SQLCHAR *numdata, SQLCHAR prec,
                       SQLSCHAR scale, SQLCHAR sign, char *outstr,
                       char *exptrunc)
{
  SQL_NUMERIC_STRUCT *sqlnum= malloc(sizeof(SQL_NUMERIC_STRUCT));
  SQLCHAR obuf[30];
  SQLRETURN exprc= SQL_SUCCESS;

  /* TODO until sqlnum errors are supported */
  /*
  if (!strcmp("01S07", exptrunc))
    exprc= SQL_SUCCESS_WITH_INFO;
  else if (!strcmp("22003", exptrunc))
    exprc= SQL_ERROR;
  */

  sqlnum->sign= sign;
  memcpy(sqlnum->val, numdata, SQL_MAX_NUMERIC_LEN);

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLBindParameter(Stmt, 1, SQL_PARAM_INPUT, SQL_C_NUMERIC,
                                  SQL_DECIMAL, prec, scale, sqlnum, 0, NULL));

  OK_SIMPLE_STMT(Stmt, "select ?");

  exprc= SQLFetch(Stmt);
  if (exprc != SQL_SUCCESS)
  {
    IS(check_sqlstate(Stmt, (char *)exptrunc) == OK);
  }
  if (exprc == SQL_ERROR)
    return OK;
  is_num(sqlnum->precision, prec);
  is_num(sqlnum->scale, scale);
  is_num(sqlnum->sign, sign);
  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLGetData(Stmt, 1, SQL_C_CHAR, obuf, sizeof(obuf), NULL));
  diag("compare %s - %s", obuf, outstr);
  IS_STR(obuf, outstr, strlen(outstr));
  FAIL_IF(memcmp(sqlnum->val, numdata, SQL_MAX_NUMERIC_LEN), "memcmp failed");

  CHECK_HANDLE_RC(SQL_HANDLE_STMT, Stmt, SQLFreeStmt(Stmt, SQL_CLOSE));

  free(sqlnum);
  return OK;
}
Exemplo n.º 28
0
int	check_live(char **params)
{
  if (params[0][0] == DIRECT_CHAR && params[0][1] == LABEL_CHAR);
  else if (params[0][0] == DIRECT_CHAR);
  else if ((params[0][0] == DIRECT_CHAR) && (is_num(&params[0][1])))
    return (1);
  else
    return (0);
  return (1);
}
Exemplo n.º 29
0
lexcomp_t tokenize_number(scanner_t *s) {
  if (!is_num(scanner_peek(s)))
    return tokNoMatch;

  nextstate state = integer;
  while ((statefn)state != done &&
         (statefn)state != error)
    state = (nextstate)(*state)(s);

  return ((statefn)state == error ? tokNoMatch : tokNumber);
}
Exemplo n.º 30
0
void phone_book_find(Phone_Book *pb, char *key) {
    if (!is_name(key) && !is_num(key)) {
        printf(MSG_UNRECOGNIZED_NAME_NUMBER);
        fflush(stdout);
        return;
    }
    phone_book_init_from_file(pb);
    phone_book_find_name(pb, key);
    phone_book_find_num(pb, key);
    phone_book_free(pb);
}