version 1.14, 2010/05/15 06:48:13 |
version 1.18, 2010/06/09 19:22:56 |
|
|
#include <string.h> |
#include <string.h> |
#include <time.h> |
#include <time.h> |
|
|
|
#include "mandoc.h" |
#include "libmandoc.h" |
#include "libmandoc.h" |
|
|
static int a2time(time_t *, const char *, const char *); |
static int a2time(time_t *, const char *, const char *); |
|
static int spec_norm(char *, int); |
|
|
|
|
|
/* |
|
* "Normalise" a special string by converting its ASCII_HYPH entries |
|
* into actual hyphens. |
|
*/ |
|
static int |
|
spec_norm(char *p, int sz) |
|
{ |
|
int i; |
|
|
|
for (i = 0; i < sz; i++) |
|
if (ASCII_HYPH == p[i]) |
|
p[i] = '-'; |
|
|
|
return(sz); |
|
} |
|
|
|
|
int |
int |
mandoc_special(const char *p) |
mandoc_special(char *p) |
{ |
{ |
int terminator; /* Terminator for \s. */ |
int terminator; /* Terminator for \s. */ |
int lim; /* Limit for N in \s. */ |
int lim; /* Limit for N in \s. */ |
int c, i; |
int c, i; |
|
char *sv; |
|
|
|
sv = p; |
|
|
if ('\\' != *p++) |
if ('\\' != *p++) |
return(0); |
return(spec_norm(sv, 0)); |
|
|
switch (*p) { |
switch (*p) { |
case ('\''): |
case ('\''): |
Line 49 mandoc_special(const char *p) |
|
Line 71 mandoc_special(const char *p) |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('q'): |
case ('q'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
case (ASCII_HYPH): |
|
/* FALLTHROUGH */ |
case ('-'): |
case ('-'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('~'): |
case ('~'): |
Line 61 mandoc_special(const char *p) |
|
Line 85 mandoc_special(const char *p) |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (' '): |
case (' '): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
case ('}'): |
|
/* FALLTHROUGH */ |
case ('|'): |
case ('|'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('&'): |
case ('&'): |
Line 70 mandoc_special(const char *p) |
|
Line 96 mandoc_special(const char *p) |
|
case (':'): |
case (':'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('c'): |
case ('c'): |
return(2); |
/* FALLTHROUGH */ |
case ('e'): |
case ('e'): |
return(2); |
return(spec_norm(sv, 2)); |
case ('s'): |
case ('s'): |
if ('\0' == *++p) |
if ('\0' == *++p) |
return(2); |
return(spec_norm(sv, 2)); |
|
|
c = 2; |
c = 2; |
terminator = 0; |
terminator = 0; |
Line 105 mandoc_special(const char *p) |
|
Line 131 mandoc_special(const char *p) |
|
|
|
if (*p == '\'') { |
if (*p == '\'') { |
if (terminator) |
if (terminator) |
return(0); |
return(spec_norm(sv, 0)); |
lim = 0; |
lim = 0; |
terminator = 1; |
terminator = 1; |
++p; |
++p; |
++c; |
++c; |
} else if (*p == '[') { |
} else if (*p == '[') { |
if (terminator) |
if (terminator) |
return(0); |
return(spec_norm(sv, 0)); |
lim = 0; |
lim = 0; |
terminator = 2; |
terminator = 2; |
++p; |
++p; |
++c; |
++c; |
} else if (*p == '(') { |
} else if (*p == '(') { |
if (terminator) |
if (terminator) |
return(0); |
return(spec_norm(sv, 0)); |
lim = 2; |
lim = 2; |
terminator = 3; |
terminator = 3; |
++p; |
++p; |
Line 129 mandoc_special(const char *p) |
|
Line 155 mandoc_special(const char *p) |
|
/* TODO: needs to handle floating point. */ |
/* TODO: needs to handle floating point. */ |
|
|
if ( ! isdigit((u_char)*p)) |
if ( ! isdigit((u_char)*p)) |
return(0); |
return(spec_norm(sv, 0)); |
|
|
for (i = 0; isdigit((u_char)*p); i++) { |
for (i = 0; isdigit((u_char)*p); i++) { |
if (lim && i >= lim) |
if (lim && i >= lim) |
Line 140 mandoc_special(const char *p) |
|
Line 166 mandoc_special(const char *p) |
|
|
|
if (terminator && terminator < 3) { |
if (terminator && terminator < 3) { |
if (1 == terminator && *p != '\'') |
if (1 == terminator && *p != '\'') |
return(0); |
return(spec_norm(sv, 0)); |
if (2 == terminator && *p != ']') |
if (2 == terminator && *p != ']') |
return(0); |
return(spec_norm(sv, 0)); |
++p; |
++p; |
++c; |
++c; |
} |
} |
|
|
return(c); |
return(spec_norm(sv, c)); |
case ('f'): |
case ('f'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('F'): |
case ('F'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('*'): |
case ('*'): |
if (0 == *++p || ! isgraph((u_char)*p)) |
if ('\0' == *++p || isspace((u_char)*p)) |
return(0); |
return(spec_norm(sv, 0)); |
switch (*p) { |
switch (*p) { |
case ('('): |
case ('('): |
if (0 == *++p || ! isgraph((u_char)*p)) |
if ('\0' == *++p || isspace((u_char)*p)) |
return(0); |
return(spec_norm(sv, 0)); |
return(4); |
return(spec_norm(sv, 4)); |
case ('['): |
case ('['): |
for (c = 3, p++; *p && ']' != *p; p++, c++) |
for (c = 3, p++; *p && ']' != *p; p++, c++) |
if ( ! isgraph((u_char)*p)) |
if (isspace((u_char)*p)) |
break; |
break; |
return(*p == ']' ? c : 0); |
return(spec_norm(sv, *p == ']' ? c : 0)); |
default: |
default: |
break; |
break; |
} |
} |
return(3); |
return(spec_norm(sv, 3)); |
case ('('): |
case ('('): |
if (0 == *++p || ! isgraph((u_char)*p)) |
if ('\0' == *++p || isspace((u_char)*p)) |
return(0); |
return(spec_norm(sv, 0)); |
if (0 == *++p || ! isgraph((u_char)*p)) |
if ('\0' == *++p || isspace((u_char)*p)) |
return(0); |
return(spec_norm(sv, 0)); |
return(4); |
return(spec_norm(sv, 4)); |
case ('['): |
case ('['): |
break; |
break; |
default: |
default: |
return(0); |
return(spec_norm(sv, 0)); |
} |
} |
|
|
for (c = 3, p++; *p && ']' != *p; p++, c++) |
for (c = 3, p++; *p && ']' != *p; p++, c++) |
if ( ! isgraph((u_char)*p)) |
if (isspace((u_char)*p)) |
break; |
break; |
|
|
return(*p == ']' ? c : 0); |
return(spec_norm(sv, *p == ']' ? c : 0)); |
} |
} |
|
|
|
|
Line 320 mandoc_eos(const char *p, size_t sz) |
|
Line 346 mandoc_eos(const char *p, size_t sz) |
|
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('\''): |
case ('\''): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
|
case (']'): |
|
/* FALLTHROUGH */ |
case (')'): |
case (')'): |
break; |
break; |
case ('.'): |
case ('.'): |
Line 337 mandoc_eos(const char *p, size_t sz) |
|
Line 365 mandoc_eos(const char *p, size_t sz) |
|
} |
} |
|
|
return(0); |
return(0); |
|
} |
|
|
|
|
|
int |
|
mandoc_hyph(const char *start, const char *c) |
|
{ |
|
|
|
/* |
|
* Choose whether to break at a hyphenated character. We only |
|
* do this if it's free-standing within a word. |
|
*/ |
|
|
|
/* Skip first/last character of buffer. */ |
|
if (c == start || '\0' == *(c + 1)) |
|
return(0); |
|
/* Skip first/last character of word. */ |
|
if ('\t' == *(c + 1) || '\t' == *(c - 1)) |
|
return(0); |
|
if (' ' == *(c + 1) || ' ' == *(c - 1)) |
|
return(0); |
|
/* Skip double invocations. */ |
|
if ('-' == *(c + 1) || '-' == *(c - 1)) |
|
return(0); |
|
/* Skip escapes. */ |
|
if ('\\' == *(c - 1)) |
|
return(0); |
|
|
|
return(1); |
} |
} |