static SGML_dtd *load_flatfile(FILE *input) { AttrType *attr_types = 0; SGML_dtd *result = 0; size_t n; size_t number_of_attrs = 0; size_t number_of_tags = 0; HTTag *tag; int code; code = fscanf(input, "%d attr_types\n", &number_of_attrs); if (code && number_of_attrs && (attr_types = typecallocn(AttrType, number_of_attrs + 1)) != 0) { for (n = 0; n < number_of_attrs; ++n) { if (!load_flat_AttrType(input, attr_types + n, n)) { break; } } } code = fscanf(input, "%d tags\n", &number_of_tags); if (code == 1) { if ((result = typecalloc(SGML_dtd)) != 0 && (result->tags = typecallocn(HTTag, (number_of_tags + 2))) != 0) { for (n = 0; n < number_of_tags; ++n) { if (load_flat_HTTag(input, n, &(result->tags[n]), attr_types)) { result->number_of_tags = (n + 1); } else { break; } } tag = 0; for (n = 0; n < number_of_tags; ++n) { if (result->tags[n].name != 0 && !strcmp(result->tags[n].name, "OBJECT")) { tag = result->tags + number_of_tags; *tag = result->tags[n]; tag->contents = SGML_MIXED; tag->flags = Tgf_strict; break; } } if (tag == 0) { fprintf(stderr, "Did not find OBJECT tag\n"); result = 0; } } } return result; }
/* * (Re)allocate the l_cell[] array for the current line */ static void extend_line(void) { size_t have = cur_line->l_last; size_t want = cur_line->l_this; if (want >= have) { CHARCELL *c = cur_line->l_cell; want += 80; if (c == 0) { c = typecallocn(CHARCELL,want); } else { c = typereallocn(CHARCELL,c,want); } if (c == 0) failed("extend_line"); while (have < want) { c[have].link = 0; c[have].c_value = SPACE; c[have].c_level = 0; c[have].c_ident = CS_NORMAL; have++; } cur_line->l_last = want; cur_line->l_cell = c; } }
PRIVATE void append_close_tag ARGS3( char*, tagname, HT_tagspec**, head, HT_tagspec**, tail) { int idx, nattr; HTTag* tag; HT_tagspec* subj; idx = html_src_tag_index(tagname); tag = HTML_dtd.tags+idx; nattr = tag->number_of_attributes; if (idx == -1) { fprintf(stderr, "internal error: previous check didn't find bad HTML tag %s", tagname); exit_immediately(EXIT_FAILURE); } subj = typecalloc(HT_tagspec); subj->element = idx; subj->present = typecallocn(BOOL, nattr); subj->value = typecallocn(char *, nattr); subj->start = FALSE; #ifdef USE_COLOR_STYLE subj->class_name = NULL; #endif if (!*head) { *head = subj; *tail = subj; } else { (*tail)->next = subj; *tail = subj; } }
/* * Allocate a CHARCELL struct */ static CHARCELL * allocate_cell(void) { CHARCELL *p = typecallocn(CHARCELL,1); if (p == 0) failed("allocate_cell"); return p; }
void flt_make_symtab(const char *table_name) { if (*table_name == '\0') { table_name = default_table; } if (!set_symbol_table(table_name)) { CLASS *p; if ((p = typecallocn(CLASS, (size_t) 1)) == 0) { CannotAllocate("flt_make_symtab"); return; } p->name = strmalloc(table_name); if (p->name == 0) { free(p); CannotAllocate("flt_make_symtab"); return; } #if !USE_TSEARCH p->data = typecallocn(KEYWORD *, HASH_LENGTH); if (p->data == 0) { free(p->name); free(p); CannotAllocate("flt_make_symtab"); return; } #endif p->next = classes; classes = p; my_table = p->data; current_class = p; VERBOSE(1, ("flt_make_symtab(%s)", table_name)); /* * Mark all of the standard predefined classes when we first create a * symbol table. Some filters may define their own special classes, * and not all filters use all of these classes, but it's a lot simpler * than putting the definitions into every ".key" file. */ insert_keyword(NAME_ACTION, ATTR_ACTION, 1); insert_keyword(NAME_COMMENT, ATTR_COMMENT, 1); insert_keyword(NAME_ERROR, ATTR_ERROR, 1); insert_keyword(NAME_IDENT, ATTR_IDENT, 1); insert_keyword(NAME_IDENT2, ATTR_IDENT2, 1); insert_keyword(NAME_KEYWORD, ATTR_KEYWORD, 1); insert_keyword(NAME_KEYWRD2, ATTR_KEYWRD2, 1); insert_keyword(NAME_LITERAL, ATTR_LITERAL, 1); insert_keyword(NAME_NUMBER, ATTR_NUMBER, 1); insert_keyword(NAME_PREPROC, ATTR_PREPROC, 1); insert_keyword(NAME_TYPES, ATTR_TYPES, 1); }
/* * Allocate a LINEDATA struct */ static LINEDATA * allocate_line(void) { LINEDATA *p = typecallocn(LINEDATA,1); if (p == 0) failed("allocate_line"); if (all_lines == 0) all_lines = p; if (total_lines++ > MAX_LINES) flush_line(); return p; }
static AttrType *sorted_AttrTypes(const AttrType * source) { AttrType *result = 0; unsigned number = len_AttrTypes(source); if (number != 0) { result = typecallocn(AttrType, number + 1); if (result != 0) { memcpy(result, source, number * sizeof(*result)); qsort(result, number, sizeof(*result), compare_attr_types); } } return result; }
void vl_ctype_clr(int ch, CHARTYPE cclass) { TRACE(("vl_ctype_clr %d:%#lx\n", ch, (ULONG) cclass)); if (ctype_clrs == 0) { ctype_clrs = typecallocn(CHARTYPE, N_chars); } if (ctype_clrs != 0) { ctype_clrs[ch] |= cclass; vlCTYPE(ch) &= ~cclass; } if (ctype_sets != 0) { ctype_sets[ch] &= ~cclass; } }
/* * Set the given character class for the given character. */ void vl_ctype_set(int ch, CHARTYPE cclass) { TRACE(("vl_ctype_set %d:%#lx\n", ch, (ULONG) cclass)); if (ctype_sets == 0) { ctype_sets = typecallocn(CHARTYPE, (size_t) N_chars); } if (ctype_sets != 0) { ctype_sets[ch] |= cclass; addVlCTYPE(ch, cclass); } if (ctype_clrs != 0) { ctype_clrs[ch] &= ~cclass; } }
static void dump_flatfile(FILE *output, const SGML_dtd * dtd) { AttrType *attr_types = 0; int pass; unsigned count = 0; unsigned n; /* merge all of the attr_types data */ for (pass = 0; pass < 2; ++pass) { for (n = 0; (int) n < dtd->number_of_tags; ++n) { count += count_attr_types(attr_types, &(dtd->tags[n])); } if (pass == 0) { attr_types = typecallocn(AttrType, count + 1); count = 0; } else { count = len_AttrTypes(attr_types); qsort(attr_types, count, sizeof(*attr_types), compare_attr_types); fprintf(output, "%d attr_types\n", count); for (n = 0; n < count; ++n) { fprintf(output, "\t%d:%s\n", n, attr_types[n].name); dump_flat_attrs(output, attr_types[n].list, len_AttrList(attr_types[n].list)); } } } fprintf(output, "%d tags\n", dtd->number_of_tags); for (n = 0; (int) n < dtd->number_of_tags; ++n) { dump_flat_HTTag(output, n, &(dtd->tags[n])); } #if 0 fprintf(output, "%d entities\n", dtd->number_of_entities); for (n = 0; n < dtd->number_of_entities; ++n) { } #endif }
static int load_flat_AttrList(FILE *input, AttrList * attrs, int *length) { attr *attributes; int j, jcmp, code; int result = 1; char name[1024]; #ifdef USE_PRETTYSRC int atype; #endif if (fscanf(input, FMT_NUM_ATTRS, length) == 1 && *length > 0 && (attributes = typecallocn(attr, (size_t) (*length + 1))) != 0) { *attrs = attributes; for (j = 0; j < *length; ++j) { code = fscanf(input, FMT_ONE_ATTR, &jcmp, &atype, name ); if (code == NUM_ONE_ATTR && (j == jcmp)) { attributes[j].name = strdup(name); #ifdef USE_PRETTYSRC attributes[j].type = atype; #endif } else { fprintf(stderr, "Did not find attributes\n"); result = 0; break; } } if (*length > 1) qsort(attributes, *length, sizeof(attributes[0]), compare_attr); } return result; }
static void unfilter(FILE *src, FILE *dst) { int ch; int count = 0; int attrs = 0; STATES state = Default; unsigned n; begin_unfilter(dst); while ((ch = vl_getc(src)) != EOF) { ch = CharOf(ch); if (state == Default) { if (ch == CTL_A) { state = Repeat; count = 0; attrs = 0; } else { int changed = 0; write_unfilter(dst, ch, attrs); for (n = 0; n < my_length; ++n) { if (my_counts[n].length > 0) { my_counts[n].length -= 1; if (my_counts[n].length == 0) changed = 1; } } if (changed) { attrs = 0; for (n = 0; n < my_length; ++n) { if (my_counts[n].length > 0) { attrs |= my_counts[n].attrib & (ATR_BOLD | ATR_UNDERLINE | ATR_REVERSE | ATR_ITALIC); if ((attrs & ATR_COLOR) == 0) { attrs |= my_counts[n].attrib & (ATR_COLOR | 0xff); } } } markup_unfilter(dst, attrs); } } } else if (ch == ':') { if (count == 0) count = 1; if (attrs != 0) { markup_unfilter(dst, attrs); if (my_length == 0) { my_length = 10; if ((my_counts = typecallocn(COUNTS, my_length)) == 0) failed("malloc"); } for (n = 0; n < my_length; ++n) { if (my_counts[n].length == 0) { my_counts[n].length = count; my_counts[n].attrib = attrs; break; } } } state = Default; } else { switch (state) { case Repeat: if (isdigit(ch)) { count = (count * 10) + (ch - '0'); break; } else { state = Attribs; } /* FALLTHRU */ case Attribs: switch (ch) { case 'C': state = Color; attrs |= ATR_COLOR; break; case 'U': attrs |= ATR_UNDERLINE; break; case 'B': attrs |= ATR_BOLD; break; case 'R': attrs |= ATR_REVERSE; break; case 'I': attrs |= ATR_ITALIC; break; } break; case Color: if (isxdigit(ch)) { int color = 0; if (isdigit(ch)) { color = ch - '0'; } else if (isupper(ch) && ch <= 'F') { color = ch - 'A' + 10; } else if (islower(ch) && ch <= 'f') { color = ch - 'a' + 10; } attrs |= color; } state = Attribs; break; case Markup: case Default: break; } } } end_unfilter(dst); }
static int load_flat_HTTag(FILE *input, unsigned nref, HTTag * tag, AttrType * allTypes) { int result = 0; unsigned ncmp = 0; char name[1024]; int code; int j; code = fscanf(input, "%d:%s\n", &ncmp, name); if (code == 2 && (nref == ncmp)) { result = 1; tag->name = strdup(name); #ifdef USE_COLOR_STYLE tag->name_len = strlen(tag->name); #endif #ifdef EXP_JUSTIFY_ELTS if (fscanf(input, "%s\n", name) == 1) { tag->can_justify = !strcmp(name, "justify"); } else { fprintf(stderr, "Did not find can_justify\n"); result = 0; } #endif if (result) { result = load_flat_AttrList(input, &(tag->attributes), &(tag->number_of_attributes)); } if (result) { AttrType *myTypes; int k, count; char *next = get_line(input); if (next != 0 && sscanf(next, "%d attr_types\n", &count) && (myTypes = typecallocn(AttrType, (size_t) (count + 1))) != 0) { tag->attr_types = myTypes; for (k = 0; k < count; ++k) { next = get_line(input); if (next != 0 && sscanf(next, "%s\n", name)) { for (j = 0; allTypes[j].name != 0; ++j) { if (!strcmp(allTypes[j].name, name)) { myTypes[k].name = strdup(name); myTypes[k].list = allTypes[j].list; break; } } } else { result = 0; break; } } if (result && count > 1) qsort(myTypes, count, sizeof(myTypes[0]), compare_attr_types); } } if (result) { char *next = get_line(input); if (next != 0 && sscanf(next, "\t\tcontents: %s\n", name)) { tag->contents = s2SGMLContent(name); free(next); } else { fprintf(stderr, "Did not find contents\n"); result = 0; } } if (result) { result = load_flat_TagClass(input, "tagclass", &(tag->tagclass)); } if (result) { result = load_flat_TagClass(input, "contains", &(tag->contains)); } if (result) { result = load_flat_TagClass(input, "icontains", &(tag->icontains)); } if (result) { result = load_flat_TagClass(input, "contained", &(tag->contained)); } if (result) { result = load_flat_TagClass(input, "icontained", &(tag->icontained)); } if (result) { result = load_flat_TagClass(input, "canclose", &(tag->canclose)); } if (result) { result = load_flat_TagFlags(input, "flags", &(tag->flags)); } } else { fprintf(stderr, "load_flat_HTTag error\n"); } return result; }