Exemplo n.º 1
0
static int parse_event_spec(const char *arg, unsigned int *evntsel,
			    unsigned int *pmc)
{
    char *endp;

    *evntsel = my_strtoul(arg, &endp);
    if( endp[0] != '@' ) {
	*pmc = (unsigned int)-1;
    } else {
	arg = endp + 1;
	*pmc = my_strtoul(arg, &endp);
    }
    return endp[0] != '\0';
}
Exemplo n.º 2
0
int32_t getLength(void){
	uint32_t len=0;
	char lenstr[25];
	char* len2;
	for(;;){
		memset(lenstr, 0, 21);
		cli_getsn(lenstr, 20);
		len2 = strstrip(lenstr);
		if(!strncasecmp(len2, "LEN", 3)){
			while(*len2 && *len2!='=')
				len2++;
			if(*len2=='='){
				do{
					len2++;
				}while(*len2 && !isdigit((uint8_t)*len2));
				len = my_strtoul(len2);
				//len=(uint32_t)strtoul(len2, NULL, 10);
				return len;
			}
		} else {
			if(!strncasecmp(len2, "EXIT", 4)){
				return -1;
			}
		}
	}
}
Exemplo n.º 3
0
long  my_strtol(const char *str, char **endptr, int base)
{
    int           sign;
    unsigned long result_long;
    const long    max_long = (long)(((unsigned long)(-1)) / 2);
    const long    min_long = -max_long - 1;

    remove_whitespace(&str);
    sign = 1;

    if (*str == '-')
    {
        sign = -1;
        str++;
    }

    result_long = my_strtoul(str, endptr, base);

    if (sign == 1 && result_long > max_long)
        return max_long;
    else if (sign == -1 && result_long > (max_long - 1))
        return min_long;
    else
        return (sign * (long)result_long);
}
Exemplo n.º 4
0
static int parse_value(const char *arg, unsigned int *value)
{
    char *endp;

    *value = my_strtoul(arg, &endp);
    return endp[0] != '\0';
}
Exemplo n.º 5
0
void determine_type_of_constituent_string (void) {
  bool possible_id, possible_var, possible_sc, possible_ic, possible_fc;
  bool rereadable;

  determine_possible_symbol_types_for_string (current_agent(lexeme).string,
                                              current_agent(lexeme).length,
                                              &possible_id,
                                              &possible_var,
                                              &possible_sc,
                                              &possible_ic,
                                              &possible_fc,
                                              &rereadable);

  /* --- check whether it's a variable --- */
  if (possible_var) {
    current_agent(lexeme).type = VARIABLE_LEXEME;
    return;
  }

  /* --- check whether it's an integer --- */
  if (possible_ic) {
    errno = 0;
    current_agent(lexeme).type = INT_CONSTANT_LEXEME;
    current_agent(lexeme).int_val = strtol (current_agent(lexeme).string,NULL,10);
    if (errno) {
      print ("Error: bad integer (probably too large)\n");
      print_location_of_most_recent_lexeme();
      current_agent(lexeme).int_val = 0;
    }
    return;
  }
    
  /* --- check whether it's a floating point number --- */
  if (possible_fc) {
    errno = 0;
    current_agent(lexeme).type = FLOAT_CONSTANT_LEXEME;
    current_agent(lexeme).float_val = (float) my_strtod (current_agent(lexeme).string,NULL,10); 
    if (errno) {
      print ("Error: bad floating point number\n");
      print_location_of_most_recent_lexeme();
      current_agent(lexeme).float_val = 0.0;
    }
    return;
  }
  
  /* --- check if it's an identifier --- */
  if (current_agent(current_file)->allow_ids && possible_id) {
    current_agent(lexeme).id_letter = toupper(current_agent(lexeme).string[0]);
    errno = 0;
    current_agent(lexeme).type = IDENTIFIER_LEXEME;
    current_agent(lexeme).id_number = my_strtoul (&(current_agent(lexeme).string[1]),NULL,10);
    if (errno) {
      print ("Error: bad number for identifier (probably too large)\n");
      print_location_of_most_recent_lexeme();
      current_agent(lexeme).id_number = 0;
    }
    return;
  }

  /* --- otherwise it must be a symbolic constant --- */
  if (possible_sc) {
    current_agent(lexeme).type = SYM_CONSTANT_LEXEME;
    if (current_agent(sysparams)[PRINT_WARNINGS_SYSPARAM]) {
      if (current_agent(lexeme).string[0] == '<') {
        if (current_agent(lexeme).string[1] == '<') {
           print ("Warning: Possible disjunctive encountered in reading symbolic constant\n");
           print ("         If a disjunctive was intended, add a space after <<\n");
           print ("         If a constant was intended, surround constant with vertical bars\n");
           print_location_of_most_recent_lexeme();
	 } else {
           print ("Warning: Possible variable encountered in reading symbolic constant\n");
           print ("         If a constant was intended, surround constant with vertical bars\n");
           print_location_of_most_recent_lexeme();
         }
      } else {
        if (current_agent(lexeme).string[current_agent(lexeme).length-1] == '>') {
          if (current_agent(lexeme).string[current_agent(lexeme).length-2] == '>') {
           print ("Warning: Possible disjunctive encountered in reading symbolic constant\n");
           print ("         If a disjunctive was intended, add a space before >>\n");
           print ("         If a constant was intended, surround constant with vertical bars\n");
           print_location_of_most_recent_lexeme();
	 } else {
           print ("Warning: Possible variable encountered in reading symbolic constant\n");
           print ("         If a constant was intended, surround constant with vertical bars\n");
           print_location_of_most_recent_lexeme();
         }
	}
      }
    }
    return;
  }

#if defined(USE_TCL)
  current_agent(lexeme).type = QUOTED_STRING_LEXEME;
#else
  char msg[128];
  strcpy (msg, "Internal error: can't determine_type_of_constituent_string\n");
  abort_with_fatal_error(msg);
#endif
}