aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/out.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-11-07 08:26:45 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-11-07 08:26:45 +0000
commit65f8ae861f5855669ce4473e9c89a5a2003a89ac (patch)
tree70c464cf8da965560c87ef417609215e457f0ff1 /out.c
parent8ad740fe8ad995712855434d547231994296ed6b (diff)
downloadmandoc-65f8ae861f5855669ce4473e9c89a5a2003a89ac.tar.gz
mandoc-65f8ae861f5855669ce4473e9c89a5a2003a89ac.tar.zst
mandoc-65f8ae861f5855669ce4473e9c89a5a2003a89ac.zip
Initial abstraction of front-end decoration events (special characters, text decorations, etc.).
Diffstat (limited to 'out.c')
-rw-r--r--out.c194
1 files changed, 193 insertions, 1 deletions
diff --git a/out.c b/out.c
index e92a5842..307af614 100644
--- a/out.c
+++ b/out.c
@@ -1,4 +1,4 @@
-/* $Id: out.c,v 1.7 2009/10/22 18:59:00 kristaps Exp $ */
+/* $Id: out.c,v 1.8 2009/11/07 08:26:45 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -166,3 +166,195 @@ time2a(time_t t, char *dst, size_t sz)
(void)strftime(p, sz, "%Y", &tm);
}
+
+/* Returns length of parsed string. */
+int
+a2roffdeco(enum roffdeco *d,
+ const char **word, size_t *sz)
+{
+ int j, type, sv, t, lim;
+ const char *wp;
+
+ *d = DECO_NONE;
+
+ wp = *word;
+ type = 1;
+
+ switch (*wp) {
+ case ('\0'):
+ return(0);
+
+ case ('('):
+ wp++;
+ if ('\0' == *wp)
+ return(1);
+ if ('\0' == *(wp + 1))
+ return(2);
+
+ *d = DECO_SPECIAL;
+ *sz = 2;
+ *word = wp;
+ return(3);
+
+ case ('*'):
+ wp++;
+
+ switch (*wp) {
+ case ('\0'):
+ return(1);
+
+ case ('('):
+ wp++;
+ if ('\0' == *wp)
+ return(2);
+ if ('\0' == *(wp + 1))
+ return(3);
+
+ *d = DECO_RESERVED;
+ *sz = 2;
+ *word = wp;
+ return(4);
+
+ case ('['):
+ type = 0;
+ break;
+
+ default:
+ *d = DECO_RESERVED;
+ *sz = 1;
+ *word = wp;
+ return(3);
+ }
+ break;
+
+#if 0
+ case ('s'):
+ wp++;
+
+ /* This closely follows mandoc_special(). */
+ if ('\0' == *wp)
+ return(1);
+
+ t = 0;
+ lim = 1;
+
+ if (*wp == '\'') {
+ lim = 0;
+ t = 1;
+ ++wp;
+ } else if (*wp == '[') {
+ lim = 0;
+ t = 2;
+ ++wp;
+ } else if (*wp == '(') {
+ lim = 2;
+ t = 3;
+ ++wp;
+ }
+
+ if (*wp == '+' || *wp == '-')
+ ++wp;
+
+ if (*wp == '\'') {
+ if (t) {
+ *word = wp;
+ return;
+ }
+ lim = 0;
+ t = 1;
+ ++wp;
+ } else if (*wp == '[') {
+ if (t) {
+ *word = wp;
+ return;
+ }
+ lim = 0;
+ t = 2;
+ ++wp;
+ } else if (*wp == '(') {
+ if (t) {
+ *word = wp;
+ return;
+ }
+ lim = 2;
+ t = 3;
+ ++wp;
+ }
+
+ if ( ! isdigit((u_char)*wp)) {
+ *word = --wp;
+ return;
+ }
+
+ for (j = 0; isdigit((u_char)*wp); j++) {
+ if (lim && j >= lim)
+ break;
+ ++wp;
+ }
+
+ if (t && t < 3) {
+ if (1 == t && *wp != '\'') {
+ *word = --wp;
+ return;
+ }
+ if (2 == t && *wp != ']') {
+ *word = --wp;
+ return;
+ }
+ ++wp;
+ }
+ *word = --wp;
+ return;
+#endif
+
+ case ('f'):
+ wp++;
+
+ switch (*wp) {
+ case ('\0'):
+ return(1);
+ case ('3'):
+ /* FALLTHROUGH */
+ case ('B'):
+ *d = DECO_BOLD;
+ break;
+ case ('2'):
+ /* FALLTHROUGH */
+ case ('I'):
+ *d = DECO_ITALIC;
+ break;
+ case ('P'):
+ *d = DECO_PREVIOUS;
+ break;
+ case ('1'):
+ /* FALLTHROUGH */
+ case ('R'):
+ *d = DECO_ROMAN;
+ break;
+ default:
+ break;
+ }
+
+ return(2);
+
+ case ('['):
+ break;
+
+ default:
+ *d = DECO_SPECIAL;
+ *word = wp;
+ *sz = 1;
+ return(1);
+ }
+
+ *word = ++wp;
+ for (j = 0; *wp && ']' != *wp; wp++, j++)
+ /* Loop... */ ;
+
+ if ('\0' == *wp)
+ return(j + 1);
+
+ *d = type ? DECO_SPECIAL : DECO_RESERVED;
+ *sz = j;
+ return (j + 2);
+}