version 1.17, 2010/06/01 11:47:28 |
version 1.22, 2010/07/18 12:10:08 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#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 *); |
|
|
|
|
int |
int |
mandoc_special(const char *p) |
mandoc_special(char *p) |
{ |
{ |
int terminator; /* Terminator for \s. */ |
int len, i; |
int lim; /* Limit for N in \s. */ |
char term; |
int c, i; |
char *sv; |
|
|
if ('\\' != *p++) |
len = 0; |
return(0); |
term = '\0'; |
|
sv = p; |
|
|
switch (*p) { |
assert('\\' == *p); |
case ('\''): |
p++; |
/* FALLTHROUGH */ |
|
case ('`'): |
switch (*p++) { |
/* FALLTHROUGH */ |
|
case ('q'): |
|
/* FALLTHROUGH */ |
|
case ('-'): |
|
/* FALLTHROUGH */ |
|
case ('~'): |
|
/* FALLTHROUGH */ |
|
case ('^'): |
|
/* FALLTHROUGH */ |
|
case ('%'): |
|
/* FALLTHROUGH */ |
|
case ('0'): |
|
/* FALLTHROUGH */ |
|
case (' '): |
|
/* FALLTHROUGH */ |
|
case ('}'): |
|
/* FALLTHROUGH */ |
|
case ('|'): |
|
/* FALLTHROUGH */ |
|
case ('&'): |
|
/* FALLTHROUGH */ |
|
case ('.'): |
|
/* FALLTHROUGH */ |
|
case (':'): |
|
/* FALLTHROUGH */ |
|
case ('c'): |
|
return(2); |
|
case ('e'): |
|
return(2); |
|
case ('s'): |
case ('s'): |
if ('\0' == *++p) |
if (ASCII_HYPH == *p) |
return(2); |
*p = '-'; |
|
if ('+' == *p || '-' == *p) |
|
p++; |
|
|
c = 2; |
i = ('s' != *(p - 1)); |
terminator = 0; |
|
lim = 1; |
|
|
|
if (*p == '\'') { |
switch (*p++) { |
lim = 0; |
case ('('): |
terminator = 1; |
len = 2; |
++p; |
break; |
++c; |
case ('['): |
} else if (*p == '[') { |
term = ']'; |
lim = 0; |
break; |
terminator = 2; |
case ('\''): |
++p; |
term = '\''; |
++c; |
break; |
} else if (*p == '(') { |
default: |
lim = 2; |
len = 1; |
terminator = 3; |
p--; |
++p; |
break; |
++c; |
|
} |
} |
|
|
if (*p == '+' || *p == '-') { |
if (ASCII_HYPH == *p) |
++p; |
*p = '-'; |
++c; |
if ('+' == *p || '-' == *p) { |
} |
if (i++) |
|
|
if (*p == '\'') { |
|
if (terminator) |
|
return(0); |
return(0); |
lim = 0; |
p++; |
terminator = 1; |
} |
++p; |
|
++c; |
if (0 == i) |
} else if (*p == '[') { |
|
if (terminator) |
|
return(0); |
|
lim = 0; |
|
terminator = 2; |
|
++p; |
|
++c; |
|
} else if (*p == '(') { |
|
if (terminator) |
|
return(0); |
|
lim = 2; |
|
terminator = 3; |
|
++p; |
|
++c; |
|
} |
|
|
|
/* TODO: needs to handle floating point. */ |
|
|
|
if ( ! isdigit((u_char)*p)) |
|
return(0); |
return(0); |
|
break; |
for (i = 0; isdigit((u_char)*p); i++) { |
|
if (lim && i >= lim) |
|
break; |
|
++p; |
|
++c; |
|
} |
|
|
|
if (terminator && terminator < 3) { |
|
if (1 == terminator && *p != '\'') |
|
return(0); |
|
if (2 == terminator && *p != ']') |
|
return(0); |
|
++p; |
|
++c; |
|
} |
|
|
|
return(c); |
|
case ('f'): |
case ('f'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('F'): |
case ('F'): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ('*'): |
case ('*'): |
if (0 == *++p || ! isgraph((u_char)*p)) |
switch (*p++) { |
return(0); |
|
switch (*p) { |
|
case ('('): |
case ('('): |
if (0 == *++p || ! isgraph((u_char)*p)) |
len = 2; |
return(0); |
break; |
return(4); |
|
case ('['): |
case ('['): |
for (c = 3, p++; *p && ']' != *p; p++, c++) |
term = ']'; |
if ( ! isgraph((u_char)*p)) |
break; |
break; |
|
return(*p == ']' ? c : 0); |
|
default: |
default: |
|
len = 1; |
|
p--; |
break; |
break; |
} |
} |
return(3); |
break; |
case ('('): |
case ('('): |
if (0 == *++p || ! isgraph((u_char)*p)) |
len = 2; |
return(0); |
break; |
if (0 == *++p || ! isgraph((u_char)*p)) |
|
return(0); |
|
return(4); |
|
case ('['): |
case ('['): |
|
term = ']'; |
break; |
break; |
default: |
default: |
return(0); |
len = 1; |
|
p--; |
|
break; |
} |
} |
|
|
for (c = 3, p++; *p && ']' != *p; p++, c++) |
if (term) { |
if ( ! isgraph((u_char)*p)) |
for ( ; *p && term != *p; p++) |
break; |
if (ASCII_HYPH == *p) |
|
*p = '-'; |
|
return(*p ? p - sv : 0); |
|
} |
|
|
return(*p == ']' ? c : 0); |
for (i = 0; *p && i < len; i++, p++) |
|
if (ASCII_HYPH == *p) |
|
*p = '-'; |
|
return(i == len ? p - sv : 0); |
} |
} |
|
|
|
|