Esempio n. 1
0
void destroy_selector(selector* s){
  if(s->id && s->id->value) free(s->id->value);
  if(s->id) free(s->id);

  int i;
  for(i = 0; i < s->attrs->count; i++)
    destroy_attr_selector((attr_selector*) get_element_at(s->attrs, i));
  destroy_generic_list(s->attrs);

  for(i = 0; i < s->filters->count; i++)
    destroy_filter_selector((filter_selector*) get_element_at(s->filters, i));
  destroy_generic_list(s->filters);

  free(s);
}
Esempio n. 2
0
/* Dump DOT code to vizualize specified NFA */
void NFA_dump_graphviz_code(const struct NFA *nfa, FILE *fp)
{
    struct generic_list visited_state;
    create_generic_list(struct NFA_state*, &visited_state);

    fprintf(fp, 
        "digraph finite_state_machine {\n"
        "    rankdir=LR;\n"
        "    size=\"8,5\"\n"
        "    node [shape = doublecircle label=\"\"]; addr_%p\n"
        "    node [shape = circle]\n", (void*)nfa->terminate);

    /* dump the finite state machine recursively */
    generic_list_push_back(&visited_state, &nfa->start);
    __NFA_reachable_states_dump_graphviz(nfa->start, &visited_state, fp);

    /* dump start mark */
    fprintf(fp, "    node [shape = none label=\"\"]; start\n");
    fprintf(fp, "    start -> addr_%p [ label = \"start\" ]\n", 
        (void*)nfa->start);

    /* done */
    fprintf(fp, "}\n");
    destroy_generic_list(&visited_state);
}
Esempio n. 3
0
File: dfa.c Progetto: FaneZhao/reviz
/* Destroy the entire DFA */
void DFA_dispose(struct DFA_state *start)
{
    struct generic_list state_list;
    struct DFA_state **cur;
    int i_state = 0;

    create_generic_list(struct DFA_state*, &state_list);
    generic_list_push_back(&state_list, &start);
    DFA_traverse(start, &state_list);

    for (cur = (struct DFA_state**) state_list.p_dat; 
         i_state < state_list.length; i_state++, cur++)
    {
        free_DFA_state(*cur);
    }

    destroy_generic_list(&state_list);
}
Esempio n. 4
0
int main(int argc, char** argv){
    int i;
    char *filename, *query_string, *node;

    if(argc == 2){
        filename = "-";
    }
    else if(argc != 3){
        printf("usage: %s \"query\" \"xml_file\"\n", argv[0]);
        return 0;
    }
    else{
        filename = argv[2];
    }

    query_string = argv[1];

    doc* document = parse_xml(filename);
    if(document == NULL) exit(1);

    register_extended_operators();
    list* result = query(query_string, document->root);

    if(result == NULL) exit(1);

    for(i=0; i < result->count; i++){
        dom_node* t = (dom_node*)get_element_at(result, i);
        node = node_to_string(t, XML);
        printf("%s", node);
        free(node);
    }

    if(result)
    destroy_generic_list(result);

    if(document != NULL)
    destroy_dom_tree(document);

    destroy_dictionary();
    destroy_custom_filters();
    destroy_custom_operators();
    return 0;
}
Esempio n. 5
0
doc* parse_xml_from_string(const char* xmlstring){
  doc* document;

  trash_bin = new_stack(16);

  parse_string(xmlstring);

  while(trash_bin->count > 0){
    free(pop_stack(trash_bin));
  }
  destroy_generic_list(trash_bin);

  if(lxq_document == NULL)
    return NULL;

  document = alloc(doc, 1);
  memcpy(document, lxq_document, sizeof(doc));
  free(lxq_document);
  lxq_document = NULL;
  return document;
}
Esempio n. 6
0
list* parse_query(const char* query){
  list* sles;

  trash_bin = new_stack(16);

  parse_string(query);

  while(trash_bin->count > 0){
    free(pop_stack(trash_bin));
  }
  destroy_generic_list(trash_bin);

  if(lxq_selected_elements == NULL)
    return NULL;

  sles = alloc(list, 1);
  memcpy(sles, lxq_selected_elements, sizeof(list));
  free(lxq_selected_elements);
  lxq_selected_elements = NULL;
  return sles;
}
Esempio n. 7
0
File: dfa.c Progetto: FaneZhao/reviz
/* Generate DOT code to vizualize the DFA */
void DFA_dump_graphviz_code(const struct DFA_state *start_state, FILE *fp)
{
    struct generic_list visited_state;
    create_generic_list(struct DFA_state *, &visited_state);

    fprintf(fp, 
        "digraph finite_state_machine {\n"
        "    rankdir=LR;\n"
        "    size=\"8,5\"\n"
        "    node [shape = circle label=\"\"]\n");

    generic_list_push_back(&visited_state, &start_state);
    __DFA_reachable_states_dump_graphviz(start_state, &visited_state, fp);

    /* dump start mark */
    fprintf(fp, "    node [shape = none label=\"\"]; start\n");
    fprintf(fp, "    start -> addr_%p [ label = \"start\" ]\n", (void*)start_state);

    /* done */
    fprintf(fp, "}\n");
    destroy_generic_list(&visited_state);
}