File indexing completed on 2024-04-28 11:21:09
0001 /* block-level tags for passing html blocks through the blender 0002 */ 0003 #include "config.h" 0004 0005 #define __WITHOUT_AMALLOC 1 0006 #include "cstring.h" 0007 #include "tags.h" 0008 0009 STRING(struct kw) extratags; 0010 0011 /* the standard collection of tags are built and sorted when 0012 * discount is configured, so all we need to do is pull them 0013 * in and use them. 0014 * 0015 * Additional tags still need to be allocated, sorted, and deallocated. 0016 */ 0017 #include "blocktags" 0018 0019 0020 /* define an additional html block tag 0021 */ 0022 void 0023 mkd_define_tag(char *id, int selfclose) 0024 { 0025 struct kw *p; 0026 0027 /* only add the new tag if it doesn't exist in 0028 * either the standard or extra tag tables. 0029 */ 0030 if ( !(p = mkd_search_tags(id, strlen(id))) ) { 0031 /* extratags could be deallocated */ 0032 if ( S(extratags) == 0 ) 0033 CREATE(extratags); 0034 p = &EXPAND(extratags); 0035 p->id = id; 0036 p->size = strlen(id); 0037 p->selfclose = selfclose; 0038 } 0039 } 0040 0041 0042 /* case insensitive string sort (for qsort() and bsearch() of block tags) 0043 */ 0044 static int 0045 casort(struct kw *a, struct kw *b) 0046 { 0047 if ( a->size != b->size ) 0048 return a->size - b->size; 0049 return strncasecmp(a->id, b->id, b->size); 0050 } 0051 0052 0053 /* stupid cast to make gcc shut up about the function types being 0054 * passed into qsort() and bsearch() 0055 */ 0056 typedef int (*stfu)(const void*,const void*); 0057 0058 0059 /* sort the list of extra html block tags for later searching 0060 */ 0061 void 0062 mkd_sort_tags() 0063 { 0064 qsort(T(extratags), S(extratags), sizeof(struct kw), (stfu)casort); 0065 } 0066 0067 0068 /* look for a token in the html block tag list 0069 */ 0070 struct kw* 0071 mkd_search_tags(char *pat, int len) 0072 { 0073 struct kw key; 0074 struct kw *ret; 0075 0076 key.id = pat; 0077 key.size = len; 0078 0079 if ( (ret=bsearch(&key,blocktags,NR_blocktags,sizeof key,(stfu)casort)) ) 0080 return ret; 0081 0082 if ( S(extratags) ) 0083 return bsearch(&key,T(extratags),S(extratags),sizeof key,(stfu)casort); 0084 0085 return 0; 0086 } 0087 0088 0089 /* destroy the extratags list (for shared libraries) 0090 */ 0091 void 0092 mkd_deallocate_tags() 0093 { 0094 if ( S(extratags) > 0 ) 0095 DELETE(extratags); 0096 } /* mkd_deallocate_tags */