-/* $Id: mandoc.c,v 1.24 2010/07/18 22:55:06 kristaps Exp $ */
+/* $Id: mandoc.c,v 1.34 2010/08/29 11:28:09 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
/* FALLTHROUGH */
case ('x'):
/* FALLTHROUGH */
- case ('w'):
- /* FALLTHROUGH */
- case ('v'):
- /* FALLTHROUGH */
case ('S'):
/* FALLTHROUGH */
case ('R'):
/* FALLTHROUGH */
- case ('o'):
- /* FALLTHROUGH */
case ('N'):
/* FALLTHROUGH */
case ('l'):
term = '\'';
break;
#endif
+ case ('h'):
+ /* FALLTHROUGH */
+ case ('v'):
+ /* FALLTHROUGH */
case ('s'):
if (ASCII_HYPH == *p)
*p = '-';
- if ('+' == *p || '-' == *p)
- p++;
- i = ('s' != *(p - 1));
+ i = 0;
+ if ('+' == *p || '-' == *p) {
+ p++;
+ i = 1;
+ }
switch (*p++) {
case ('('):
case ('\''):
term = '\'';
break;
+ case ('0'):
+ i = 1;
+ /* FALLTHROUGH */
default:
len = 1;
p--;
if (ASCII_HYPH == *p)
*p = '-';
if ('+' == *p || '-' == *p) {
- if (i++)
+ if (i)
return(0);
p++;
}
- if (0 == i)
+ /* Handle embedded numerical subexp or escape. */
+
+ if ('(' == *p) {
+ while (*p && ')' != *p)
+ if ('\\' == *p++) {
+ i = mandoc_special(--p);
+ if (0 == i)
+ return(0);
+ p += i;
+ }
+
+ if (')' == *p++)
+ break;
+
return(0);
+ } else if ('\\' == *p) {
+ if (0 == (i = mandoc_special(p)))
+ return(0);
+ p += i;
+ }
+
break;
#if 0
case ('Y'):
/* FALLTHROUGH */
case ('n'):
/* FALLTHROUGH */
+#endif
case ('k'):
/* FALLTHROUGH */
-#endif
case ('M'):
/* FALLTHROUGH */
case ('m'):
case ('['):
term = ']';
break;
+ case ('z'):
+ len = 1;
+ if ('\\' == *p) {
+ if (0 == (i = mandoc_special(p)))
+ return(0);
+ p += i;
+ return(*p ? (int)(p - sv) : 0);
+ }
+ break;
+ case ('o'):
+ /* FALLTHROUGH */
+ case ('w'):
+ if ('\'' == *p++) {
+ term = '\'';
+ break;
+ }
+ /* FALLTHROUGH */
default:
len = 1;
p--;
ptr = calloc(num, size);
if (NULL == ptr) {
perror(NULL);
- exit(EXIT_FAILURE);
+ exit(MANDOCLEVEL_SYSERR);
}
return(ptr);
ptr = malloc(size);
if (NULL == ptr) {
perror(NULL);
- exit(EXIT_FAILURE);
+ exit(MANDOCLEVEL_SYSERR);
}
return(ptr);
ptr = realloc(ptr, size);
if (NULL == ptr) {
perror(NULL);
- exit(EXIT_FAILURE);
+ exit(MANDOCLEVEL_SYSERR);
}
return(ptr);
p = strdup(ptr);
if (NULL == p) {
perror(NULL);
- exit(EXIT_FAILURE);
+ exit(MANDOCLEVEL_SYSERR);
}
return(p);
*/
found = 0;
- for (q = p + sz - 1; q >= p; q--) {
+ for (q = p + (int)sz - 1; q >= p; q--) {
switch (*q) {
case ('\"'):
/* FALLTHROUGH */
found = 1;
break;
default:
- return(found && (!enclosed || isalnum(*q)));
+ return(found && (!enclosed || isalnum((unsigned char)*q)));
}
}