File: staglib.c

package info (click to toggle)
libdata-stag-perl 0.14-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,480 kB
  • sloc: perl: 6,394; lisp: 141; xml: 116; ansic: 55; makefile: 17; sh: 2
file content (79 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>                                                             
#include <glib.h>
#include "staglib.h"

#define q2s g_quark_to_string
#define s2q g_quark_from_string

void* stag_throw(gchar *msg) {
  printf "EXCEPTION:%s\n", msg);
}

stag* stag_new() {
    stag *stag = g_malloc(sizeof(stag));
    stag->nameq = s2q("");
    stag->data = g_slist_alloc();
    stag->isterminal = FALSE;
    return stag;
}

G_CONST_RETURN gchar* stag_name(stag *node, gchar *name) {
  GQuark q;
  if (name != NULL) {
    node->nameq = s2q(name);
  }

  q = node->nameq;
  return g_quark_to_string(q);
}

G_CONST_RETURN gchar* stag_getname(stag *node) {
  return q2s(node->nameq);
}

char* stag_data(stag *node, void *data, gboolean isterminal) {
  if (data != NULL) {
    node->data = data;
    node->isterminal = isterminal;
  }
  return node->data;
}

GSList* stag_kids(stag *node) {
  if (node->isterminal) {
    stag_throw(stag, "terminal");
  }
  return (GSList*)node->data;
}

/*

GSList* stag_findnode(stag *node, 
                     gchar *name, 
                     stag *replacement_node) {

  int i;
  GQuark nameq = s2q(name);
  GSList* matchlist = g_slist_alloc();

  if (node->nameq == nameq) {
    g_slist_append(matchlist, node);
  }
  else if (node->isterminal) {
    return;
  }
  else {
    for (i=0; i < g_slist_length_foreach(node->data); i++) {
      stag* subnode = (stag*)g_slist_nth(node->data, i);
      GSList* sublist = stag_findnode(subnode, name, replacement_node);
      g_slist_concat(matchlist, sublist);
    }
  }
  return matchlist;
}
*/