X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/4d1bc0c8c120742600a57c849edf1b2481c45e26..a96cac2f523bff3d1c811444fa013f8d9eca81c9:/chars.c?ds=inline diff --git a/chars.c b/chars.c index 26539832..06a2a923 100644 --- a/chars.c +++ b/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.36 2011/04/29 22:18:12 kristaps Exp $ */ +/* $Id: chars.c,v 1.43 2011/05/15 22:29:50 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -20,11 +20,13 @@ #endif #include +#include #include #include #include #include "mandoc.h" +#include "libmandoc.h" #define PRINT_HI 126 #define PRINT_LO 32 @@ -55,7 +57,6 @@ struct ln { #include "chars.in" struct mchars { - enum mcharst type; struct ln **htab; }; @@ -72,7 +73,7 @@ mchars_free(struct mchars *arg) } struct mchars * -mchars_init(enum mcharst type) +mchars_alloc(void) { struct mchars *tab; struct ln **htab; @@ -103,7 +104,6 @@ mchars_init(enum mcharst type) } tab->htab = htab; - tab->type = type; return(tab); } @@ -137,27 +137,23 @@ mchars_res2cp(struct mchars *arg, const char *p, size_t sz) return(ln->unicode); } - /* - * Numbered character to literal character, - * represented as a null-terminated string for additional safety. + * Numbered character to literal character. + * This can only be a printable character (i.e., alnum, punct, space) so + * prevent the character from ruining our state (backspace, newline, and + * so on). + * If the character is illegal, returns '\0'. */ -const char * +char mchars_num2char(const char *p, size_t sz) { int i; - static char c[2]; - if (sz > 3) - return(NULL); - i = atoi(p); - if (i < 0 || i > 255) - return(NULL); - c[0] = (char)i; - c[1] = '\0'; - return(c); -} + if ((i = mandoc_strntou(p, sz, 10)) < 0) + return('\0'); + return(isprint(i) ? i : '\0'); +} /* * Special character to string array. @@ -175,7 +171,6 @@ mchars_spec2str(struct mchars *arg, const char *p, size_t sz, size_t *rsz) return(ln->ascii); } - /* * Reserved word to string array. */