=================================================================== RCS file: /cvs/mandoc/chars.c,v retrieving revision 1.31 retrieving revision 1.35 diff -u -p -r1.31 -r1.35 --- mandoc/chars.c 2011/01/02 10:10:57 1.31 +++ mandoc/chars.c 2011/04/20 22:50:22 1.35 @@ -1,6 +1,7 @@ -/* $Id: chars.c,v 1.31 2011/01/02 10:10:57 kristaps Exp $ */ +/* $Id: chars.c,v 1.35 2011/04/20 22:50:22 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons + * Copyright (c) 2011 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -24,7 +25,7 @@ #include #include "mandoc.h" -#include "chars.h" +#include "out.h" #define PRINT_HI 126 #define PRINT_LO 32 @@ -40,7 +41,7 @@ struct ln { #define CHARS_BOTH (CHARS_CHAR | CHARS_STRING) }; -#define LINES_MAX 351 +#define LINES_MAX 353 #define CHAR(in, ch, code) \ { NULL, (in), (ch), (code), CHARS_CHAR }, @@ -91,18 +92,9 @@ chars_init(enum chars type) * (they're in-line re-ordered during lookup). */ - tab = malloc(sizeof(struct ctab)); - if (NULL == tab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } + tab = mandoc_malloc(sizeof(struct ctab)); + htab = mandoc_calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); - htab = calloc(PRINT_HI - PRINT_LO + 1, sizeof(struct ln **)); - if (NULL == htab) { - perror(NULL); - exit((int)MANDOCLEVEL_SYSERR); - } - for (i = 0; i < LINES_MAX; i++) { hash = (int)lines[i].code[0] - PRINT_LO; @@ -149,6 +141,27 @@ chars_res2cp(void *arg, const char *p, size_t sz) if (NULL == ln) return(-1); return(ln->unicode); +} + + +/* + * Numbered character to literal character, + * represented as a null-terminated string for additional safety. + */ +const char * +chars_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); }