From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from krisdoz.my.domain (kristaps@localhost [127.0.0.1]) by krisdoz.my.domain (8.14.3/8.14.3) with ESMTP id p3TMIDXa015654 for ; Fri, 29 Apr 2011 18:18:13 -0400 (EDT) Received: (from kristaps@localhost) by krisdoz.my.domain (8.14.3/8.14.3/Submit) id p3TMICbJ031058; Fri, 29 Apr 2011 18:18:12 -0400 (EDT) Date: Fri, 29 Apr 2011 18:18:12 -0400 (EDT) Message-Id: <201104292218.p3TMICbJ031058@krisdoz.my.domain> X-Mailinglist: mdocml-source Reply-To: source@mdocml.bsd.lv MIME-Version: 1.0 From: kristaps@mdocml.bsd.lv To: source@mdocml.bsd.lv Subject: mdocml: Move "chars" interface out of out.h and into mandoc.h. X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Log Message: ----------- Move "chars" interface out of out.h and into mandoc.h. This doesn't change any code but for renaming functions and types to be consistent with other mandoc.h stuff. The reason for moving into libmandoc is that the rendering of special characters is part of mandoc itself---not an external part. From mandoc(1)'s perspective, this changes nothing, but for other utilities, it's important to have these part of libmandoc. Note this isn't documented [yet] in mandoc.3 because there are some parts I'd like to change around beforehand. Modified Files: -------------- mdocml: Makefile chars.c html.c html.h man_term.c mandoc.h mdoc_term.c out.h term.c term.h Revision Data ------------- Index: term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v retrieving revision 1.184 retrieving revision 1.185 diff -Lterm.c -Lterm.c -u -p -r1.184 -r1.185 --- term.c +++ term.c @@ -47,7 +47,7 @@ term_free(struct termp *p) if (p->buf) free(p->buf); if (p->symtab) - chars_free(p->symtab); + mchars_free(p->symtab); free(p); } @@ -350,7 +350,7 @@ numbered(struct termp *p, const char *wo { const char *rhs; - rhs = chars_num2char(word, len); + rhs = mchars_num2char(word, len); if (rhs) encode(p, rhs, 1); } @@ -362,7 +362,7 @@ spec(struct termp *p, const char *word, const char *rhs; size_t sz; - rhs = chars_spec2str(p->symtab, word, len, &sz); + rhs = mchars_spec2str(p->symtab, word, len, &sz); if (rhs) encode(p, rhs, sz); else if (1 == len) @@ -376,7 +376,7 @@ res(struct termp *p, const char *word, s const char *rhs; size_t sz; - rhs = chars_res2str(p->symtab, word, len, &sz); + rhs = mchars_res2str(p->symtab, word, len, &sz); if (rhs) encode(p, rhs, sz); } @@ -623,11 +623,11 @@ term_strlen(const struct termp *p, const switch (esc) { case (ESCAPE_PREDEF): - rhs = chars_res2str + rhs = mchars_res2str (p->symtab, seq, ssz, &rsz); break; case (ESCAPE_SPECIAL): - rhs = chars_spec2str + rhs = mchars_spec2str (p->symtab, seq, ssz, &rsz); if (ssz != 1 || rhs) Index: html.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.h,v retrieving revision 1.40 retrieving revision 1.41 diff -Lhtml.h -Lhtml.h -u -p -r1.40 -r1.41 --- html.h +++ html.h @@ -120,7 +120,7 @@ struct html { struct tagq tags; /* stack of open tags */ struct rofftbl tbl; /* current table */ struct tag *tblt; /* current open table scope */ - void *symtab; /* character-escapes */ + struct mchars *symtab; /* character-escapes */ char *base_man; /* base for manpage href */ char *base_includes; /* base for include href */ char *style; /* style-sheet URI */ Index: chars.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/chars.c,v retrieving revision 1.35 retrieving revision 1.36 diff -Lchars.c -Lchars.c -u -p -r1.35 -r1.36 --- chars.c +++ chars.c @@ -25,7 +25,6 @@ #include #include "mandoc.h" -#include "out.h" #define PRINT_HI 126 #define PRINT_LO 32 @@ -55,32 +54,27 @@ struct ln { #include "chars.in" -struct ctab { - enum chars type; +struct mchars { + enum mcharst type; struct ln **htab; }; static inline int match(const struct ln *, const char *, size_t, int); -static const struct ln *find(struct ctab *, const char *, size_t, int); - +static const struct ln *find(struct mchars *, const char *, size_t, int); void -chars_free(void *arg) +mchars_free(struct mchars *arg) { - struct ctab *tab; - - tab = (struct ctab *)arg; - free(tab->htab); - free(tab); + free(arg->htab); + free(arg); } - -void * -chars_init(enum chars type) +struct mchars * +mchars_init(enum mcharst type) { - struct ctab *tab; + struct mchars *tab; struct ln **htab; struct ln *pp; int i, hash; @@ -92,7 +86,7 @@ chars_init(enum chars type) * (they're in-line re-ordered during lookup). */ - tab = mandoc_malloc(sizeof(struct ctab)); + tab = mandoc_malloc(sizeof(struct mchars)); htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); for (i = 0; i < LINES_MAX; i++) { @@ -118,11 +112,11 @@ chars_init(enum chars type) * Special character to Unicode codepoint. */ int -chars_spec2cp(void *arg, const char *p, size_t sz) +mchars_spec2cp(struct mchars *arg, const char *p, size_t sz) { const struct ln *ln; - ln = find((struct ctab *)arg, p, sz, CHARS_CHAR); + ln = find(arg, p, sz, CHARS_CHAR); if (NULL == ln) return(-1); return(ln->unicode); @@ -133,11 +127,11 @@ chars_spec2cp(void *arg, const char *p, * Reserved word to Unicode codepoint. */ int -chars_res2cp(void *arg, const char *p, size_t sz) +mchars_res2cp(struct mchars *arg, const char *p, size_t sz) { const struct ln *ln; - ln = find((struct ctab *)arg, p, sz, CHARS_STRING); + ln = find(arg, p, sz, CHARS_STRING); if (NULL == ln) return(-1); return(ln->unicode); @@ -149,7 +143,7 @@ chars_res2cp(void *arg, const char *p, s * represented as a null-terminated string for additional safety. */ const char * -chars_num2char(const char *p, size_t sz) +mchars_num2char(const char *p, size_t sz) { int i; static char c[2]; @@ -169,11 +163,11 @@ chars_num2char(const char *p, size_t sz) * Special character to string array. */ const char * -chars_spec2str(void *arg, const char *p, size_t sz, size_t *rsz) +mchars_spec2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz) { const struct ln *ln; - ln = find((struct ctab *)arg, p, sz, CHARS_CHAR); + ln = find(arg, p, sz, CHARS_CHAR); if (NULL == ln) return(NULL); @@ -186,11 +180,11 @@ chars_spec2str(void *arg, const char *p, * Reserved word to string array. */ const char * -chars_res2str(void *arg, const char *p, size_t sz, size_t *rsz) +mchars_res2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz) { const struct ln *ln; - ln = find((struct ctab *)arg, p, sz, CHARS_STRING); + ln = find(arg, p, sz, CHARS_STRING); if (NULL == ln) return(NULL); @@ -198,9 +192,8 @@ chars_res2str(void *arg, const char *p, return(ln->ascii); } - static const struct ln * -find(struct ctab *tab, const char *p, size_t sz, int type) +find(struct mchars *tab, const char *p, size_t sz, int type) { struct ln *pp, *prev; struct ln **htab; @@ -242,7 +235,6 @@ find(struct ctab *tab, const char *p, si return(NULL); } - static inline int match(const struct ln *ln, const char *p, size_t sz, int type) Index: term.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.h,v retrieving revision 1.79 retrieving revision 1.80 diff -Lterm.h -Lterm.h -u -p -r1.79 -r1.80 --- term.h +++ term.h @@ -105,7 +105,7 @@ struct termp { #define TERMP_PREKEEP (1 << 15) /* ...starting with the next one. */ char *buf; /* Output buffer. */ enum termenc enc; /* Type of encoding. */ - void *symtab; /* Encoded-symbol table. */ + struct mchars *symtab; /* Encoded-symbol table. */ enum termfont fontl; /* Last font set. */ enum termfont fontq[10]; /* Symmetric fonts. */ int fonti; /* Index of font stack. */ Index: html.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v retrieving revision 1.132 retrieving revision 1.133 diff -Lhtml.c -Lhtml.c -u -p -r1.132 -r1.133 --- html.c +++ html.c @@ -122,7 +122,7 @@ ml_alloc(char *outopts, enum htmltype ty h->type = type; h->tags.head = NULL; - h->symtab = chars_init(CHARS_HTML); + h->symtab = mchars_init(MCHARS_HTML); while (outopts && *outopts) switch (getsubopt(&outopts, UNCONST(toks), &v)) { @@ -172,7 +172,7 @@ html_free(void *p) } if (h->symtab) - chars_free(h->symtab); + mchars_free(h->symtab); free(h); } @@ -214,7 +214,7 @@ print_num(struct html *h, const char *p, { const char *rhs; - rhs = chars_num2char(p, len); + rhs = mchars_num2char(p, len); if (rhs) putchar((int)*rhs); } @@ -226,7 +226,7 @@ print_spec(struct html *h, const char *p const char *rhs; size_t sz; - if ((cp = chars_spec2cp(h->symtab, p, len)) > 0) { + if ((cp = mchars_spec2cp(h->symtab, p, len)) > 0) { printf("&#%d;", cp); return; } else if (-1 == cp && 1 == len) { @@ -235,7 +235,7 @@ print_spec(struct html *h, const char *p } else if (-1 == cp) return; - if (NULL != (rhs = chars_spec2str(h->symtab, p, len, &sz))) + if (NULL != (rhs = mchars_spec2str(h->symtab, p, len, &sz))) fwrite(rhs, 1, sz, stdout); } @@ -247,13 +247,13 @@ print_res(struct html *h, const char *p, const char *rhs; size_t sz; - if ((cp = chars_res2cp(h->symtab, p, len)) > 0) { + if ((cp = mchars_res2cp(h->symtab, p, len)) > 0) { printf("&#%d;", cp); return; } else if (-1 == cp) return; - if (NULL != (rhs = chars_res2str(h->symtab, p, len, &sz))) + if (NULL != (rhs = mchars_res2str(h->symtab, p, len, &sz))) fwrite(rhs, 1, sz, stdout); } Index: out.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/out.h,v retrieving revision 1.19 retrieving revision 1.20 diff -Lout.h -Lout.h -u -p -r1.19 -r1.20 --- out.h +++ out.h @@ -31,11 +31,6 @@ enum roffscale { SCALE_MAX }; -enum chars { - CHARS_ASCII, /* 7-bit ascii representation */ - CHARS_HTML /* unicode values */ -}; - struct roffcol { size_t width; /* width of cell */ size_t decimal; /* decimal position in cell */ @@ -71,14 +66,6 @@ __BEGIN_DECLS int a2roffsu(const char *, struct roffsu *, enum roffscale); void time2a(time_t, char *, size_t); void tblcalc(struct rofftbl *tbl, const struct tbl_span *); - -void *chars_init(enum chars); -const char *chars_num2char(const char *, size_t); -const char *chars_spec2str(void *, const char *, size_t, size_t *); -int chars_spec2cp(void *, const char *, size_t); -const char *chars_res2str(void *, const char *, size_t, size_t *); -int chars_res2cp(void *, const char *, size_t); -void chars_free(void *); __END_DECLS Index: mandoc.h =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v retrieving revision 1.70 retrieving revision 1.71 diff -Lmandoc.h -Lmandoc.h -u -p -r1.70 -r1.71 --- mandoc.h +++ mandoc.h @@ -302,10 +302,16 @@ enum mandoc_esc { ESCAPE_NOSPACE /* suppress space if the last on a line */ }; +enum mcharst { + MCHARS_ASCII, /* 7-bit ascii representation */ + MCHARS_HTML /* unicode values */ +}; + typedef void (*mandocmsg)(enum mandocerr, enum mandoclevel, const char *, int, int, const char *); struct mparse; +struct mchars; struct mdoc; struct man; @@ -325,6 +331,15 @@ void *mandoc_malloc(size_t); void *mandoc_realloc(void *, size_t); enum mandoc_esc mandoc_escape(const char **, const char **, int *); + +struct mchars *mchars_init(enum mcharst); +const char *mchars_num2char(const char *, size_t); +const char *mchars_spec2str(struct mchars *, const char *, size_t, size_t *); +int mchars_spec2cp(struct mchars *, const char *, size_t); +const char *mchars_res2str(struct mchars *, const char *, size_t, size_t *); +int mchars_res2cp(struct mchars *, const char *, size_t); +void mchars_free(struct mchars *); + __END_DECLS Index: man_term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man_term.c,v retrieving revision 1.105 retrieving revision 1.106 diff -Lman_term.c -Lman_term.c -u -p -r1.105 -r1.106 --- man_term.c +++ man_term.c @@ -158,7 +158,7 @@ terminal_man(void *arg, const struct man if (NULL == p->symtab) switch (p->enc) { case (TERMENC_ASCII): - p->symtab = chars_init(CHARS_ASCII); + p->symtab = mchars_init(MCHARS_ASCII); break; default: abort(); Index: mdoc_term.c =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_term.c,v retrieving revision 1.226 retrieving revision 1.227 diff -Lmdoc_term.c -Lmdoc_term.c -u -p -r1.226 -r1.227 --- mdoc_term.c +++ mdoc_term.c @@ -266,7 +266,7 @@ terminal_mdoc(void *arg, const struct md if (NULL == p->symtab) switch (p->enc) { case (TERMENC_ASCII): - p->symtab = chars_init(CHARS_ASCII); + p->symtab = mchars_init(MCHARS_ASCII); break; default: abort(); Index: Makefile =================================================================== RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/Makefile,v retrieving revision 1.332 retrieving revision 1.333 diff -LMakefile -LMakefile -u -p -r1.332 -r1.333 --- Makefile +++ Makefile @@ -154,16 +154,19 @@ LIBROFF_LNS = eqn.ln \ LIBMANDOC_OBJS = $(LIBMAN_OBJS) \ $(LIBMDOC_OBJS) \ $(LIBROFF_OBJS) \ + chars.o \ mandoc.o \ read.o LIBMANDOC_LNS = $(LIBMAN_LNS) \ $(LIBMDOC_LNS) \ $(LIBROFF_LNS) \ + chars.ln \ mandoc.ln \ read.ln arch.o arch.ln: arch.in att.o att.ln: att.in +chars.o chars.ln: chars.in lib.o lib.ln: lib.in msec.o msec.ln: msec.in st.o st.ln: st.in @@ -198,19 +201,15 @@ MANDOC_TERM_LNS = man_term.ln \ MANDOC_OBJS = $(MANDOC_HTML_OBJS) \ $(MANDOC_TERM_OBJS) \ - chars.o \ main.o \ out.o \ tree.o MANDOC_LNS = $(MANDOC_HTML_LNS) \ $(MANDOC_TERM_LNS) \ - chars.ln \ main.ln \ out.ln \ tree.ln -chars.o chars.ln: chars.in - $(MANDOC_HTML_OBJS) $(MANDOC_HTML_LNS): html.h $(MANDOC_TERM_OBJS) $(MANDOC_TERM_LNS): term.h $(MANDOC_OBJS) $(MANDOC_LNS): main.h mandoc.h mdoc.h man.h config.h out.h @@ -322,7 +321,7 @@ mandoc: $(MANDOC_OBJS) libmandoc.a # You'll need -ldb for Linux. mandoc-db: $(MANDOCDB_OBJS) libmandoc.a - $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a + $(CC) -o $@ $(MANDOCDB_OBJS) libmandoc.a -ldb llib-lmandoc.ln: $(MANDOC_LNS) $(LINT) $(LINTFLAGS) -Cmandoc $(MANDOC_LNS) -- To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv