lib/cfg_parse.c
/**
 * This function performs a key-lookup on a cfg_struct, and returns the associated value.
 * @param cfg Pointer to cfg_struct to search.
 * @param key String containing key to search for.
 * @return String containing associated value, or NULL if key was not found.
 */
This function performs a key-lookup on a cfg_struct, and returns the associated value.
@param cfg Pointer to cfg_struct to search.
@param key String containing key to search for.
@return String containing associated value, or NULL if key was not found.
This function performs a key - lookup on a cfg_struct and returns the associated value . @param cfg Pointer to cfg_struct to search . @param key String containing key to search for . @return String containing associated value or NULL if key was not found .
const char * cfg_get(const struct cfg_struct *cfg, const char *key)
{
  unsigned int i, len;
  char *tkey;
  struct cfg_node *temp;
  if (cfg == NULL || key == NULL) return NULL;
  tkey = cfg_trim(key);
  if (! strcmp(tkey,"")) { free(tkey); return NULL; }
  len = strlen(tkey);
  for (i = 0; i < len; i++)
    tkey[i] = tolower(tkey[i]);
  temp = cfg->head;
  while (temp != NULL)
  {
    if (! strcmp(tkey, temp->key))
    {
      free(tkey);
      return temp->value;
    }
    temp = temp->next;
  }
  free(tkey);
  return NULL;
}
const char * cfg_get ( const struct cfg_struct * cfg , const char * key ) { unsigned int i , len ; char * tkey ; struct cfg_node * temp ; if ( cfg == NULL || key == NULL ) return NULL ; tkey = cfg_trim ( key ) ; if ( ! strcmp ( tkey , " " ) ) { free ( tkey ) ; return NULL ; } len = strlen ( tkey ) ; for ( i = 0 ; i < len ; i ++ ) tkey [ i ] = tolower ( tkey [ i ] ) ; temp = cfg -> head ; while ( temp != NULL ) { if ( ! strcmp ( tkey , temp -> key ) ) { free ( tkey ) ; return temp -> value ; } temp = temp -> next ; } free ( tkey ) ; return NULL ; }
This function performs a key-lookup on a cfg_struct, and returns the associated value.
This function performs a key - lookup on a cfg_struct and returns the associated value .
/* safety check: null input */ /* Trim input search key */ /* Exclude empty key */ /* Lowercase key */ /* set up pointer to start of list */