-/* $Id: chars.c,v 1.37 2011/04/30 22:14:02 kristaps Exp $ */
+/* $Id: chars.c,v 1.43 2011/05/15 22:29:50 kristaps Exp $ */
/*
* Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
#endif
#include <assert.h>
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mandoc.h"
+#include "libmandoc.h"
#define PRINT_HI 126
#define PRINT_LO 32
}
struct mchars *
-mchars_init(void)
+mchars_alloc(void)
{
struct mchars *tab;
struct ln **htab;
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.
return(ln->ascii);
}
-
/*
* Reserved word to string array.
*/