Blame view
tools/sctk-2.4.10/src/sclite/sgml.c
2.28 KB
8dcb6dfcb first commit |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#include "sctk.h" void init_SGML(SGML *sg) { sg->num_tags=0; } void dump_SGML_tag(SGML *sg, int n, FILE *fp) { int a; fprintf(fp,"TAG: %d %s Atrribs:",n,sg->tags[n].name); for (a=0; a<sg->tags[n].attrib_num; a++) fprintf(fp,"%s=\"%s\" ",sg->tags[n].attrib_name[a], sg->tags[n].attrib_value[a]); fprintf(fp," "); } TEXT *get_SGML_attrib(SGML *sg, int tn, TEXT *sname) { int a; for (a=0; a<sg->tags[tn].attrib_num; a++){ if (TEXT_strcmp(sg->tags[tn].attrib_name[a],sname) == 0) return(sg->tags[tn].attrib_value[a]); } return((TEXT *)""); } TEXT *delete_SGML_tag(SGML *sg, TEXT *str) { TEXT *b; int a; if (sg->num_tags == 0) return(NULL); if (*(str+1) != '/') return(NULL); if ((b = TEXT_strchr(str+2,'>')) == NULL) return(NULL); if (TEXT_strBcmp(sg->tags[sg->num_tags-1].name,str+2,b - (str+2)) != 0) return(NULL); /* delete the last SGML tag */ sg->num_tags --; for (a=0; a<sg->tags[sg->num_tags].attrib_num; a++){ free_singarr(sg->tags[sg->num_tags].attrib_value[a],TEXT); free_singarr(sg->tags[sg->num_tags].attrib_name[a],TEXT); } sg->tags[sg->num_tags].attrib_num = 0; return(sg->tags[sg->num_tags].name); } int add_SGML_tag(SGML *sg, TEXT *str) { TEXT *p, *b=str+1; int *ac, l; if (sg->num_tags >= MAX_TAGS) { fprintf(scfp,"Error: Too many SGML tags < %d ",MAX_TAGS); exit(1); } sg->tags[sg->num_tags].attrib_num = 0; /* load the name */ if ((p = TEXT_strchr(b,' ')) == NULL) return(0); sg->tags[sg->num_tags].name = TEXT_strBdup(b,p - b); p ++; b = p; /* begin with the attributes */ ac = &(sg->tags[sg->num_tags].attrib_num); while (*b != '\0'){ b += TEXT_strspn(b,(TEXT *)" \t "); if ((l = TEXT_strcspn(b,(TEXT *)"= ")) == 0) return (0); sg->tags[sg->num_tags].attrib_name[*ac] = TEXT_strBdup(b,l); b += l+1; if (*(b++) != '"') return(0); if ((l = TEXT_strcspn(b,(TEXT *)"\"")) == 0 && (*b != '"')) return (0); sg->tags[sg->num_tags].attrib_value[*ac] = TEXT_strBdup(b,l); b += l+1; b += TEXT_strspn(b,(TEXT *)" \t >"); /* printf(" Parsed attrib id='%s' value='%s' remaind='%s' ", sg->tags[sg->num_tags].attrib_name[*ac], sg->tags[sg->num_tags].attrib_value[*ac],b); */ (*ac)++; } sg->num_tags ++; return(1); } |