Ejemplo n.º 1
0
/** Will loose tagging .... */
int subst_list_add_from_string( subst_list_type * subst_list , const char * arg_string, bool append) {
  int     error_count = 0;
  if (arg_string != NULL) {
    char ** key_value_list;
    int     num_arg, iarg;
    
    util_split_string(arg_string , "," , &num_arg , &key_value_list);
    for (iarg = 0; iarg < num_arg; iarg++) {
      if (strchr(key_value_list[iarg] , '=') == NULL)
        //util_abort("%s: could not find \'=\' in argument string:%s \n",__func__ , key_value_list[iarg]);
        /*
          Could not find '=' in the argument string, this argument will
          be ignored, and the error_count will be increased by one.
        */
        error_count += 1;
      else {
        char * key , * value;
        char * tmp     = key_value_list[iarg];
        int arg_length , value_length;
        while (isspace(*tmp))  /* Skipping initial space */
          tmp++;
        
        arg_length = strcspn(tmp , " =");
        key  = util_alloc_substring_copy(tmp , 0 , arg_length);
        tmp += arg_length;
        while ((*tmp == ' ') || (*tmp == '='))
          tmp++;
        
        value_length = strcspn(tmp , " ");
        value = util_alloc_substring_copy( tmp , 0 , value_length);
        
        /* Setting the argument */
        if (append)
          subst_list_append_copy( subst_list , key , value , NULL);
        else
          subst_list_prepend_copy( subst_list , key , value , NULL);
        
        free(key);
        free(value);
        tmp += value_length;
        
        
        /* Accept only trailing space - any other character indicates a failed parsing. */
        while (*tmp != '\0') {
          if (!isspace(*tmp))
            util_abort("%s: something wrong with:%s  - spaces are not allowed in key or value part.\n",__func__ , key_value_list[iarg]);
          tmp++;
        }
      }
    }
    util_free_stringlist(key_value_list , num_arg);
  }
  return error_count;
}
Ejemplo n.º 2
0
static void smspec_node_set_keyword( smspec_node_type * smspec_node , const char * keyword ) {
  // ECLIPSE Standard: Max eight characters - everything beyond is silently dropped
  // This function can __ONLY__ be called on time; run-time chaning of keyword is not
  // allowed.
  if (smspec_node->keyword == NULL)
    smspec_node->keyword = util_alloc_substring_copy( keyword , 0 , 8);
  else
    util_abort("%s: fatal error - attempt to change keyword runtime detected - aborting\n",__func__);
}
Ejemplo n.º 3
0
char * util_alloc_envvar( const char * value ) {
  if (value == NULL)
    return NULL;
  else {
    buffer_type * buffer = buffer_alloc( 1024 );               /* Start by filling up a buffer instance with 
                                                                  the current content of @value. */
    buffer_fwrite_char_ptr( buffer , value );
    buffer_fwrite_char( buffer , '\0' );
    buffer_rewind( buffer );
    
    
    while (true) {
      if (buffer_strchr( buffer , '$')) {
        const char * data = buffer_get_data( buffer );
        int offset        = buffer_get_offset( buffer ) + 1;    /* Points at the first character following the '$' */
        int var_length = 0;
        
        /* Find the length of the variable name */
        while (true) {
          char c;
          c = data[offset + var_length];
          if (!(isalnum( c ) || c == '_'))      /* Any character which is NOT in the set [a-Z,0-9_] marks the end of the variable. */
            break;             
          
          if (c == '\0')                        /* The end of the string. */
            break;
          
          var_length += 1;
        }

        {
          char * var_name        = util_alloc_substring_copy( data , offset - 1 , var_length + 1);  /* Include the leading $ */
          const char * var_value = getenv( &var_name[1] );
          
          if (var_value != NULL)
            buffer_search_replace( buffer , var_name , var_value);                                      /* The actual string replacement. */
          else  
            buffer_fseek( buffer , var_length , SEEK_CUR );                                      /* The variable is not defined, and we leave the $name. */
          
          free( var_name );
        }
      } else break;  /* No more $ to replace */
    }
    
    
    buffer_shrink_to_fit( buffer );
    {
      char * expanded_value = buffer_get_data( buffer );
      buffer_free_container( buffer );
      return expanded_value;
    }
  }
}
Ejemplo n.º 4
0
static void subst_list_eval_funcs____(const subst_list_type * subst_list , const parser_type * parser , buffer_type * buffer) {
  {
    int index;
    for (index = 0; index < vector_get_size( subst_list->func_data); index++) {
      const subst_list_func_type * subst_func = vector_iget_const( subst_list->func_data , index );
      const char                 * func_name  = subst_func->name;
      
      bool match;
      buffer_rewind( buffer );
      do {
        size_t match_pos;
        match     = buffer_strstr( buffer , func_name );
        match_pos = buffer_get_offset( buffer );
        
        if (match) {
          bool   update     = false;
          char * arg_start  = buffer_get_data( buffer );
          arg_start        += buffer_get_offset( buffer ) + strlen( func_name );
          
          if (arg_start[0] == '(') {  /* We require that an opening paren follows immediately behind the function name. */
            char * arg_end = strchr( arg_start , ')');
            if (arg_end != NULL) {
              /* OK - we found an enclosing () pair. */
              char            * arg_content = util_alloc_substring_copy( arg_start, 1 , arg_end - arg_start - 1);
              stringlist_type * arg_list    = parser_tokenize_buffer( parser , arg_content , true);
              char            * func_eval   = subst_list_func_eval( subst_func , arg_list );
              int               old_len     = strlen(func_name) + strlen( arg_content) + 2;       
              
              if (func_eval != NULL) {
                buffer_memshift( buffer , match_pos + old_len , strlen( func_eval ) - old_len);
                buffer_fwrite( buffer , func_eval , strlen( func_eval ) , sizeof * func_eval );
                free( func_eval );
                update = true;
              }
              
              free( arg_content );
              stringlist_free( arg_list );
            } 
          } 
          
          if (!update) 
            buffer_fseek( buffer , match_pos + strlen( func_name ) , SEEK_SET);
        }
      } while (match);
    }
  }
  if (subst_list->parent != NULL) 
    subst_list_eval_funcs____( subst_list->parent , parser , buffer );
}
Ejemplo n.º 5
0
static char * __alloc_tag_content( const char * xml_buffer , const char * tag) {
  char * open_tag    = util_alloc_sprintf("<%s>"  , tag);
  char * close_tag   = util_alloc_sprintf("</%s>" , tag);

  char * start_ptr   = strstr( xml_buffer , open_tag );
  char * end_ptr     = strstr( xml_buffer , close_tag );
  char * tag_content = NULL;

  if ((start_ptr != NULL) && (end_ptr != NULL)) {
    int length;
    start_ptr += strlen(open_tag);

    length = end_ptr - start_ptr;
    tag_content = util_alloc_substring_copy( start_ptr , 0 , length );
  }

  free( open_tag );
  free( close_tag );
  return tag_content;
}
Ejemplo n.º 6
0
static void util_addr2line_lookup(const char * executable , const char * bt_symbol , char ** func_name , char ** file_line) {
  char *tmp_file = util_alloc_tmp_file("/tmp" , "addr2line" , true);
  char * adress;
  {
    int start_pos = 0;
    int end_pos;   
    while ( bt_symbol[start_pos] != '[')
      start_pos++;
    
      end_pos = start_pos;
      while ( bt_symbol[end_pos] != ']') 
        end_pos++;
      
      adress = util_alloc_substring_copy( bt_symbol , start_pos + 1 , end_pos - start_pos - 1 );
  }
  
  {
    char ** argv;
    
    argv    = util_calloc(3 , sizeof * argv );
    argv[0] = util_alloc_string_copy("--functions");
    argv[1] = util_alloc_sprintf("--exe=%s" , executable);
    argv[2] = util_alloc_string_copy(adress);
    
    util_fork_exec("addr2line" , 3  , (const char **) argv , true , NULL , NULL , NULL , tmp_file , NULL);
    util_free_stringlist(argv , 3);
  }
  
  {
    bool at_eof;
    FILE * stream = util_fopen(tmp_file , "r");
    *func_name = util_fscanf_alloc_line(stream , &at_eof);
    *file_line = util_fscanf_alloc_line(stream , &at_eof);
    fclose(stream);
  }
  util_unlink_existing(tmp_file);
  free(adress);
  free(tmp_file);
}
Ejemplo n.º 7
0
static char * util_bt_alloc_current_executable(const char * bt_symbol) {
  if (__current_executable != NULL) 
    return util_alloc_string_copy(__current_executable );
  else {
    if (bt_symbol != NULL) {
      int paren_pos = 0;
      char * path;
      while (bt_symbol[paren_pos] != '(' && bt_symbol[paren_pos] != ' ')
        paren_pos++;
      
      path = util_alloc_substring_copy(bt_symbol , 0 , paren_pos);
      if (util_is_abs_path(path))
        return path;
      else {
        char * full_path = util_alloc_PATH_executable( path );
        free(path);
        return full_path;
      }
    } else 
      return NULL;
  }
}
Ejemplo n.º 8
0
void split_name(const char * arg, char **_old_name , char **_new_name) {
  char * new_name;
  char * old_name;
  int i;
  int old_name_len = 0;

  for (i=0; i < strlen(arg); i++) {
    if (arg[i] == '=')
      old_name_len = i;
  }

  if (old_name_len > 0) {
    old_name = util_alloc_substring_copy(arg , 0 , old_name_len);
    new_name = util_alloc_string_copy(&arg[old_name_len + 1]);
  } else {
    old_name = util_alloc_string_copy(arg);
    new_name = old_name;
  }
  
  *_old_name = old_name;
  *_new_name = new_name;
}
Ejemplo n.º 9
0
void smspec_node_set_unit( smspec_node_type * smspec_node , const char * unit ) {
  // ECLIPSE Standard: Max eight characters - everything beyond is silently dropped
  util_safe_free( smspec_node->unit );
  smspec_node->unit = util_alloc_substring_copy( unit , 0 , 8);
}