Example #1
0
File: hash.c Project: SySof/sysof
int hash_add_string(hash h, stralloc sa) {
    hash_elem* elem = h[get_hash(sa)];
    if(elem == NULL) {
        hash_elem* nh = (hash_elem*) malloc(sizeof(hash_elem));
        if(nh == NULL) {
            return 0;
        } else {
            nh->sa = sa;
            nh->next = NULL;
            h[get_hash(sa)] = nh;
            return 1;
        }
    }
    while(elem->next != NULL) {
        if(stralloc_equal(&(elem->sa), &sa)) {
            return 1;
        }
        elem = elem->next;
    }
    if(stralloc_equal(&(elem->sa), &sa)) {
        return 1;
    }
    hash_elem* nh = (hash_elem*) malloc(sizeof(hash_elem));
    if(nh == NULL) {
        return 0;
    } else {
        nh->sa = sa;
        nh->next = NULL;
        elem->next = nh;
        return 1;
    }
}
Example #2
0
File: hash.c Project: SySof/sysof
int hash_contains_string(hash h, stralloc sa) {
    hash_elem* elem = h[get_hash(sa)];
    if(elem == NULL) {
        return 0;
    }
    while(elem != NULL) {
        if(stralloc_equal(&(elem->sa), &sa)) {
            return 1;
        }
        elem = elem->next;
    }
    return 0;
}
Example #3
0
int
xml_read_function(xmlreader* reader, xmlnodeid id, stralloc* name, stralloc* value, HMAP_DB** attrs) {
  switch(id) {
    case XML_TEXT: {
      buffer_putsa(buffer_1, value);
      break;
    }
    case XML_ELEMENT: {
      int closing = reader->closing || reader->self_closing;

      if(reader->closing)
        --depth;

      if(!(reader->closing && !prev_closing && stralloc_equal(&prev_element, name)) && stralloc_length(&prev_element)) {
        buffer_puts(buffer_1, "\n");
        buffer_putnspace(buffer_1, depth * 2);
      }

      buffer_putm_3(buffer_1, "<", reader->closing ? "/" : "", name->s);

      if(attrs && *attrs && (*attrs)->list_tuple) {
        buffer_putspace(buffer_1);
        xml_print_attributes(*attrs, buffer_1, " ", "=", "\"");
      }

      buffer_puts(buffer_1, reader->self_closing ? (name->s[0] == '?' ? "?>" : "/>") : ">");

      stralloc_copy(&prev_element, name);
      prev_closing = closing;

      if(!reader->closing && !reader->self_closing)
        ++depth;
      break;
    }
    default: break;
  }
  return 1;
}