void check_funcdefinition(node *root){
    node *aux = root->son;
    node *scnd_aux = NULL, *param_aux = NULL;
    char *type = NULL;
    char *f_name = NULL;
    int num_params = 0;
    int n_pointers = 0;
    int i;

    check_funcdeclaration(root);
    type = (char*)calloc(strlen(aux->str_type)+1,sizeof(char));
    strcpy(type,tolower_str(aux->str_type));

    for(aux = aux->brother; strcmp(aux->str_type,"Pointer")==0; aux=aux->brother){
      type = (char*)realloc(type,2);
      strcat(type,"*");
    }

    f_name = (char*)calloc(strlen(aux->value)+1,sizeof(char));
    strcpy(f_name,aux->value);

    insert_table(f_name,type);

    aux = aux->brother;
    /*if(equal_params(aux,f_name)==0){
      remove_table(f_name);
      return;
    }*/

    num_params = aux->n_sons;

    for(i=0,scnd_aux = aux->son; i<num_params; i++,scnd_aux=scnd_aux->brother){

      n_pointers = 0;
      param_aux = scnd_aux->son;

      type = (char*)calloc(strlen(param_aux->str_type)+1,sizeof(char));
      strcpy(type,tolower_str(param_aux->str_type));

      param_aux = param_aux->brother;


      if(param_aux!=NULL){
        for(; param_aux!=NULL && strcmp(param_aux->str_type,"Pointer") == 0; param_aux=param_aux->brother){
          n_pointers++;
        }

        if(param_aux != NULL){
          insert_element(f_name,type,n_pointers,param_aux->value,NULL,0,NULL,1,0);
        }
      }


    }


    aux = aux->brother;
    check_funcbody(aux,f_name);

}
void check_funcdeclaration(node *root){

    char *type = NULL;
    node *aux = root->son;
    node *scnd_aux = NULL;
    int n_pointers = 0;
    char *f_name = NULL;
    char **f_params = NULL;
    int n_params = 0;
    int i;

    if(root == NULL)
      return;

    type = (char*)calloc(strlen(aux->str_type)+1,sizeof(char));
    strcpy(type,aux->str_type);

    for(aux = aux->brother; strcmp(aux->str_type,"Pointer") == 0; aux=aux->brother){
      n_pointers++;
    }

    f_name = aux->value;
    aux = aux->brother;

    for(scnd_aux = aux->son; scnd_aux!=NULL; scnd_aux=scnd_aux->brother){
      n_params++;
    }

    aux->n_sons = n_params;

    f_params = (char**)calloc(n_params,sizeof(char*));
    for(aux=aux->son, i=0; i<n_params; aux=aux->brother,i++){

      f_params[i] = (char*)calloc(strlen(aux->son->str_type)+101,sizeof(char));
      strcpy(f_params[i],tolower_str(aux->son->str_type));
      if(aux->son->brother != NULL){
        for(scnd_aux=aux->son->brother; scnd_aux!=NULL && strcmp(scnd_aux->str_type,"Pointer")==0; scnd_aux=scnd_aux->brother){
          strcat(f_params[i],"*");
        }
      }
    }

    insert_element("Global",type,n_pointers,f_name,NULL,n_params,f_params,0,1);

}
Esempio n. 3
0
/*
 * ParseSize - parse a size argument given in a command option
 *
 * The size can be in one of the following forms:
 *   "40"    = sample counter of 40
 *   "40b"   = byte size of 40
 *   "40Kb"  = byte size of 40*1024 bytes = 40 kilobytes
 *   "40Mb"  = byte size of 40*1024*1024 bytes = 40 megabytes
 *   time-format = time delta in seconds
 *
 */
static int
ParseSize(char *size_arg, int *sample_counter, __int64_t *byte_size, 
          struct timeval *time_delta)
{
    long x = 0; /* the size number */
    char *ptr = NULL;
    char *interval_err;

    *sample_counter = -1;
    *byte_size = -1;
    time_delta->tv_sec = -1;
    time_delta->tv_usec = -1;
  
    x = strtol(size_arg, &ptr, 10);

    /* must be positive */
    if (x <= 0)
	return -1;

    if (*ptr == '\0') {
	/* we have consumed entire string as a long */
	/* => we have a sample counter */
	*sample_counter = x;
	return 1;
    }

    /* we have a number followed by something else */
    if (ptr != size_arg) {
	int len;

	tolower_str(ptr);

	/* chomp off plurals */
	len = strlen(ptr);
	if (ptr[len-1] == 's')
	    ptr[len-1] = '\0';

	/* if bytes */
	if (strcmp(ptr, "b") == 0 ||
	    strcmp(ptr, "byte") == 0) {
	    *byte_size = x;
	    return 1;
	}  

	/* if kilobytes */
	if (strcmp(ptr, "k") == 0 || strcmp(ptr, "kb") == 0 ||
	    strcmp(ptr, "kbyte") == 0 || strcmp(ptr, "kilobyte") == 0) {
	    *byte_size = x*1024;
	    return 1;
	}

	/* if megabytes */
	if (strcmp(ptr, "m") == 0 ||
	    strcmp(ptr, "mb") == 0 ||
	    strcmp(ptr, "mbyte") == 0 ||
	    strcmp(ptr, "megabyte") == 0) {
	    *byte_size = x*1024*1024;
	    return 1;
	}

	/* if gigabytes */
	if (strcmp(ptr, "g") == 0 ||
	    strcmp(ptr, "gb") == 0 ||
	    strcmp(ptr, "gbyte") == 0 ||
	    strcmp(ptr, "gigabyte") == 0) {
	    *byte_size = ((__int64_t)x)*1024*1024*1024;
	    return 1;
	}
    }

    /* Doesn't fit pattern above, try a time interval */
    if (pmParseInterval(size_arg, time_delta, &interval_err) >= 0)
        return 1;
    /* error message not used here */
    free(interval_err);
  
    /* Doesn't match anything, return an error */
    return -1;
}