Exemplo n.º 1
0
/*!
 * SQL Callback for the SELECT statement.
 *
 * \param data Configuration object.
 * \param argc Number of columns.
 * \param argv Values.
 * \param column Column names.
 * \return Always 0.
 */
static int _config_get_key_value (void *data, int argc, char **argv, char **column)
{
     struct config_t *conf = (struct config_t *) data;

     char *key = argv[0];
     char *val = argv[1];

     int type  = (int) strtol (argv[2], NULL, 10);

     switch (type)
     {
          case 0:
               conf->hashv = hashtable_update (conf->hashv, (void *) key, strlen (key), TYPE_INT, (int) strtol (val, NULL, 10));
               break;

          case 1:
               conf->hashv = hashtable_update (conf->hashv, (void *) key, strlen (key), TYPE_DOUBLE, (double) strtod (val, NULL));
               break;

          case 2:
               if (string_equal (val, "true"))
               {
                    conf->hashv = hashtable_update (conf->hashv, (void *) key, strlen (key), TYPE_BOOLEAN, true);
               }
               else
               {
                    conf->hashv = hashtable_update (conf->hashv, (void *) key, strlen (key), TYPE_BOOLEAN, false);
               }

               break;

          case 3:
               conf->hashv = hashtable_update (conf->hashv, (void *) key, strlen (key), TYPE_STRING, val);
               break;

          default:
               break;
     }

     return 0;
}
Exemplo n.º 2
0
/*
  Add whitespace delimited words from 'words' to the hashtable ht.
  The value given to echo word is the index of it's first character in words.
*/
void add_to_htable(struct hashtable *ht, char *words, size_t sz){
  uint8_t *ptr = (uint8_t*)words;
  uint32_t word_len;
  long i = 0;
  while(i < sz){
    word_len = memcspn(ptr, sz-i, (uint8_t*)" \n\t", 3);
    //hashtable_add(ht, ptr, word_len, (void*)i);
    hashtable_update(ht, ptr, word_len, inc_counter);
    i += word_len;
    ptr += word_len;
    while(isspace(*ptr)){
      ptr++;
      i++;
    }
  }
  return;
}