Debian Codegraph @

ext/tags.c

raw symbols SCIP
1 /* block-level tags for passing html blocks through the blender
2 */
3 #include "config.h"
4
5 #define __WITHOUT_AMALLOC 1
6 #include "cstring.h"
7 #include "tags.h"
8
9 STRING(struct kw) extratags;
10
11 /* the standard collection of tags are built and sorted when
12 * discount is configured, so all we need to do is pull them
13 * in and use them.
14 *
15 * Additional tags still need to be allocated, sorted, and deallocated.
16 */
17 #include "blocktags"
18
19
20 /* define an additional html block tag
21 */
22 void
23 mkd_define_tag(char *id, int selfclose)
24 {
25 struct kw *p;
26
27 /* only add the new tag if it doesn't exist in
28 * either the standard or extra tag tables.
29 */
30 if ( !(p = mkd_search_tags(id, strlen(id))) ) {
31 /* extratags could be deallocated */
32 if ( S(extratags) == 0 )
33 CREATE(extratags);
34 p = &EXPAND(extratags);
35 p->id = id;
36 p->size = strlen(id);
37 p->selfclose = selfclose;
38 }
39 }
40
41
42 /* case insensitive string sort (for qsort() and bsearch() of block tags)
43 */
44 static int
45 casort(struct kw *a, struct kw *b)
46 {
47 if ( a->size != b->size )
48 return a->size - b->size;
49 return strncasecmp(a->id, b->id, b->size);
50 }
51
52
53 /* stupid cast to make gcc shut up about the function types being
54 * passed into qsort() and bsearch()
55 */
56 typedef int (*stfu)(const void*,const void*);
57
58
59 /* sort the list of extra html block tags for later searching
60 */
61 void
62 mkd_sort_tags()
63 {
64 qsort(T(extratags), S(extratags), sizeof(struct kw), (stfu)casort);
65 }
66
67
68 /* look for a token in the html block tag list
69 */
70 struct kw*
71 mkd_search_tags(char *pat, int len)
72 {
73 struct kw key;
74 struct kw *ret;
75
76 key.id = pat;
77 key.size = len;
78
79 if ( (ret=bsearch(&key,blocktags,NR_blocktags,sizeof key,(stfu)casort)) )
80 return ret;
81
82 if ( S(extratags) )
83 return bsearch(&key,T(extratags),S(extratags),sizeof key,(stfu)casort);
84
85 return 0;
86 }
87
88
89 /* destroy the extratags list (for shared libraries)
90 */
91 void
92 mkd_deallocate_tags()
93 {
94 if ( S(extratags) > 0 )
95 DELETE(extratags);
96 } /* mkd_deallocate_tags */