]> git.cameronkatri.com Git - mandoc.git/commitdiff
Cleaned up presentation with mbuf_putstring & al.
authorKristaps Dzonsons <kristaps@bsd.lv>
Sun, 30 Nov 2008 20:53:34 +0000 (20:53 +0000)
committerKristaps Dzonsons <kristaps@bsd.lv>
Sun, 30 Nov 2008 20:53:34 +0000 (20:53 +0000)
Makefile
libmdocml.c
private.h
roff.c
validate.c

index 0b1bb1896801472ffe2dbbf96fbe16c0515462c7..0dfdb46a92a9f6bf9885f29679310cbc786c1073 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -52,36 +52,25 @@ mdocml.tgz: $(INSTALL)
 llib-lmdocml.ln: mdocml.ln libmdocml.ln html4_strict.ln validate.ln roff.ln
        $(LINT) $(LINTFLAGS) -Cmdocml mdocml.ln libmdocml.ln html4_strict.ln validate.ln roff.ln
 
-mdocml.ln: mdocml.c 
+mdocml.ln: mdocml.c libmdocml.h
 
-mdocml.o: mdocml.c 
-
-mdocml.c: libmdocml.h
+mdocml.o: mdocml.c libmdocml.h
 
 libmdocml.a: libmdocml.o html4_strict.o validate.o roff.o
        $(AR) rs $@ libmdocml.o html4_strict.o validate.o roff.o
 
-validate.ln: validate.c 
-
-validate.o: validate.c 
-
-validate.c: private.h libmdocml.h
-
-html4_strict.ln: html4_strict.c 
-
-html4_strict.o: html4_strict.c 
-
-html4_strict.c: private.h libmdocml.h
+validate.ln: validate.c private.h libmdocml.h
 
-roff.ln: roff.c 
+validate.o: validate.c private.h libmdocml.h
 
-roff.o: roff.c 
+html4_strict.ln: html4_strict.c private.h libmdocml.h
 
-roff.c: private.h libmdocml.h
+html4_strict.o: html4_strict.c private.h libmdocml.h
 
-libmdocml.ln: libmdocml.c 
+roff.ln: roff.c private.h libmdocml.h
 
-libmdocml.o: libmdocml.c 
+roff.o: roff.c private.h libmdocml.h
 
-libmdocml.c: private.h libmdocml.h
+libmdocml.ln: libmdocml.c private.h libmdocml.h
 
+libmdocml.o: libmdocml.c private.h libmdocml.h
index d942f189b4e6a4abcc528d232f9eeba786bf7acf..8f1fd77ed40bba78fef69a3620cacbd580494847 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: libmdocml.c,v 1.14 2008/11/29 14:14:21 kristaps Exp $ */
+/* $Id: libmdocml.c,v 1.15 2008/11/30 20:53:34 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -210,7 +210,7 @@ again:
                        return(md_run_leave(args, mbuf, rbuf, -1, p));
                }
 
-               line[pos] = 0;
+               line[(int)pos] = 0;
                if ( ! (*fp)(p, line))
                        return(md_run_leave(args, mbuf, rbuf, -1, p));
                rbuf->line++;
index 58f0228a391a885a28cfb945a6c07e907093633c..1c1e54e497416cdc10c2e94215d527c79054ce96 100644 (file)
--- a/private.h
+++ b/private.h
@@ -1,4 +1,4 @@
-/* $Id: private.h,v 1.18 2008/11/30 18:50:44 kristaps Exp $ */
+/* $Id: private.h,v 1.19 2008/11/30 20:53:34 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -213,7 +213,7 @@ struct      roffcb {
                        const char *, const char *, char *);
        int     (*roffhead)(void *);
        int     (*rofftail)(void *);
-       int     (*roffin)(void *, int, int *, char **);
+       int     (*roffin)(void *, int, int, int *, char **);
        int     (*roffdata)(void *, int, char *);
        int     (*roffout)(void *, int);
        int     (*roffblkin)(void *, int, int *, char **);
diff --git a/roff.c b/roff.c
index 86a5e199eb917171e0e4c931aab634c93e3c669b..fc65394aaa2a270ad0d9c97acfff686ca688b358 100644 (file)
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.22 2008/11/30 18:53:11 kristaps Exp $ */
+/* $Id: roff.c,v 1.23 2008/11/30 20:53:34 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -307,8 +307,11 @@ const      char *const toknamesp[ROFF_MAX] = {
        "Ic",           "In",           "Li",           "Nd",
        "Nm",           "Op",           "Ot",           "Pa",
        "Rv",           "St",           "Va",           "Vt",
+       /* LINTED */
        "Xr",           "\%A",          "\%B",          "\%D",
+       /* LINTED */
        "\%I",          "\%J",          "\%N",          "\%O",
+       /* LINTED */
        "\%P",          "\%R",          "\%T",          "\%V",
        "Ac",           "Ao",           "Aq",           "At",
        "Bc",           "Bf",           "Bo",           "Bq",
@@ -671,7 +674,7 @@ static int
 rofffindtok(const char *buf)
 {
        char             token[4];
-       size_t           i;
+       int              i;
 
        for (i = 0; *buf && ! isspace(*buf) && i < 3; i++, buf++)
                token[i] = *buf;
@@ -976,7 +979,7 @@ roff_layout(ROFFCALL_ARGS)
        if (NULL == *argv)
                return(1);
 
-       if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp))
+       if ( ! (*tree->cb.roffin)(tree->arg, tok, 0, argcp, argvp))
                return(0);
 
        if ( ! (ROFF_PARSED & tokens[tok].flags)) {
@@ -1030,6 +1033,7 @@ roff_layout(ROFFCALL_ARGS)
                assert(0 != i);
                i++;
 
+               /* LINTED */
                while (argv[i])
                        if ( ! (*tree->cb.roffdata)(tree->arg, 0, argv[i++]))
                                return(0);
@@ -1071,7 +1075,7 @@ roff_text(ROFFCALL_ARGS)
        argcp[i] = ROFF_ARGMAX;
        argvp[i] = NULL;
 
-       if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp))
+       if ( ! (*tree->cb.roffin)(tree->arg, tok, 1, argcp, argvp))
                return(0);
 
        if ( ! (ROFF_PARSED & tokens[tok].flags)) {
@@ -1148,6 +1152,7 @@ roff_text(ROFFCALL_ARGS)
                assert(0 != i);
                i++;
 
+               /* LINTED */
                while (argv[i])
                        if ( ! (*tree->cb.roffdata)(tree->arg, 0, argv[i++]))
                                return(0);
index 189122fb48b2c9ce82450e15f1243cadb1cb8d2c..7eb584dd661e2d6657e332a10395b447e4291be6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: validate.c,v 1.5 2008/11/30 20:00:08 kristaps Exp $ */
+/* $Id: validate.c,v 1.6 2008/11/30 20:53:34 kristaps Exp $ */
 /*
  * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
  *
 #include "private.h"
 
 #define        INDENT           4
+#define        COLUMNS          72
 
 #ifdef __linux__ /* FIXME */
 #define        strlcat          strncat
 #endif
 
+enum   md_tok {
+       MD_BLKIN,
+       MD_BLKOUT,
+       MD_IN,
+       MD_OUT,
+       MD_TEXT
+};
+
 struct md_valid {
        const struct md_args    *args;
        const struct md_rbuf    *rbuf;
+
        struct md_mbuf  *mbuf;
        struct rofftree *tree;
-
        size_t           indent;
        size_t           pos;
-
+       enum md_tok      last;
        int              flags;
-#define        MD_LITERAL      (1 << 0)
+#define        MD_LITERAL      (1 << 0) /* FIXME */
 };
 
 static void             roffmsg(void *arg, enum roffmsg, 
                                const char *, const char *, char *);
 static int              roffhead(void *);
 static int              rofftail(void *);
-static int              roffin(void *, int, int *, char **);
+static int              roffin(void *, int, int, int *, char **);
 static int              roffdata(void *, int, char *);
 static int              roffout(void *, int);
 static int              roffblkin(void *, int, int *, char **);
@@ -61,6 +70,27 @@ static       int              roffspecial(void *, int);
 static int              mbuf_newline(struct md_valid *);
 static int              mbuf_indent(struct md_valid *);
 static int              mbuf_data(struct md_valid *, int, char *);
+static int              mbuf_putstring(struct md_valid *, 
+                               const char *);
+static int              mbuf_nputstring(struct md_valid *, 
+                               const char *, size_t);
+
+
+static int
+mbuf_putstring(struct md_valid *p, const char *buf)
+{
+
+       return(mbuf_nputstring(p, buf, strlen(buf)));
+}
+
+
+static int
+mbuf_nputstring(struct md_valid *p, const char *buf, size_t sz)
+{
+
+       p->pos += sz;
+       return(md_buf_puts(p->mbuf, buf, sz));
+}
 
 
 static int
@@ -101,8 +131,13 @@ mbuf_data(struct md_valid *p, int space, char *buf)
        assert(p->mbuf);
        assert(0 != p->indent);
 
+       /* 
+        * FIXME: punctuation/no-space stuff shouldn't have a newline
+        * before it.
+        */
+
        if (MD_LITERAL & p->flags)
-               return(md_buf_putstring(p->mbuf, buf));
+               return(mbuf_putstring(p, buf));
 
        while (*buf) {
                while (*buf && isspace(*buf))
@@ -118,44 +153,32 @@ mbuf_data(struct md_valid *p, int space, char *buf)
                if (0 != *buf)
                        *buf++ = 0;
 
-               /* Process word. */
-
                sz = strlen(bufp);
 
                if (0 == p->pos) {
                        if ( ! mbuf_indent(p))
                                return(0);
-                       if ( ! md_buf_putstring(p->mbuf, bufp))
+                       if ( ! mbuf_nputstring(p, bufp, sz))
                                return(0);
-
-                       if (p->indent * INDENT + sz >= 72) {
+                       if (p->indent * INDENT + sz >= COLUMNS) {
                                if ( ! mbuf_newline(p))
                                        return(0);
                                continue;
                        }
-
-                       p->pos += sz;
                        continue;
                }
 
-               /* 
-                * FIXME: punctuation shouldn't have a newline before
-                * it! 
-                */
-
-               if (sz + p->pos >= 72) {
+               if (sz + p->pos >= COLUMNS) {
                        if ( ! mbuf_newline(p))
                                return(0);
                        if ( ! mbuf_indent(p))
                                return(0);
                } else if (space) 
-                       if ( ! md_buf_putchar(p->mbuf, ' '))
+                       if ( ! mbuf_nputstring(p, " ", 1))
                                return(0);
 
-               if ( ! md_buf_putstring(p->mbuf, bufp))
+               if ( ! mbuf_nputstring(p, bufp, sz))
                        return(0);
-
-               p->pos += sz + (size_t)(space ? 1 : 0);
        }
 
        return(1);
@@ -230,14 +253,13 @@ roffhead(void *arg)
        assert(arg);
        p = (struct md_valid *)arg;
 
-       if ( ! md_buf_putstring(p->mbuf, "<?xml version=\"1.0\" "
+       if ( ! mbuf_putstring(p, "<?xml version=\"1.0\" "
                                "encoding=\"UTF-8\"?>\n"))
                return(0);
-
-       if ( ! md_buf_putstring(p->mbuf, "<mdoc>"))
+       if ( ! mbuf_nputstring(p, "<mdoc>", 6))
                return(0);
-       p->indent++;
 
+       p->indent++;
        return(mbuf_newline(p));
 }
 
@@ -252,7 +274,10 @@ rofftail(void *arg)
 
        if (0 != p->pos && ! mbuf_newline(p))
                return(0);
-       return(md_buf_putstring(p->mbuf, "</mdoc>\n"));
+
+       if ( ! mbuf_nputstring(p, "</mdoc>", 7))
+               return(0);
+       return(mbuf_newline(p));
 }
 
 
@@ -282,26 +307,25 @@ roffblkin(void *arg, int tok, int *argc, char **argv)
        } else if ( ! mbuf_indent(p))
                return(0);
 
-       if ( ! md_buf_putchar(p->mbuf, '<'))
+       if ( ! mbuf_nputstring(p, "<", 1))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, toknames[tok]))
+       if ( ! mbuf_putstring(p, toknames[tok]))
                return(0);
 
        for (i = 0; ROFF_ARGMAX != argc[i]; i++) {
-               if ( ! md_buf_putchar(p->mbuf, ' '))
+               if ( ! mbuf_nputstring(p, " ", 1))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, tokargnames[argc[i]]))
+               if ( ! mbuf_putstring(p, tokargnames[argc[i]]))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, "=\""))
+               if ( ! mbuf_nputstring(p, "=\"", 2))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, argv[i] ? 
-                                       argv[i] : "true"))
+               if ( ! mbuf_putstring(p, argv[i] ? argv[i] : "true"))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, "\""))
+               if ( ! mbuf_nputstring(p, "\"", 1))
                        return(0);
        }
 
-       if ( ! md_buf_putchar(p->mbuf, '>'))
+       if ( ! mbuf_nputstring(p, ">", 1))
                return(0);
        if ( ! mbuf_newline(p))
                return(0);
@@ -329,11 +353,11 @@ roffblkout(void *arg, int tok)
        } else if ( ! mbuf_indent(p))
                return(0);
 
-       if ( ! md_buf_putstring(p->mbuf, "</"))
+       if ( ! mbuf_nputstring(p, "</", 2))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, toknames[tok]))
+       if ( ! mbuf_putstring(p, toknames[tok]))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, ">"))
+       if ( ! mbuf_nputstring(p, ">", 1))
                return(0);
        if ( ! mbuf_newline(p))
                return(0);
@@ -343,7 +367,7 @@ roffblkout(void *arg, int tok)
 
 
 static int
-roffin(void *arg, int tok, int *argc, char **argv)
+roffin(void *arg, int tok, int space, int *argc, char **argv)
 {
        struct md_valid *p;
        int              i;
@@ -354,39 +378,31 @@ roffin(void *arg, int tok, int *argc, char **argv)
        if (0 == p->pos && ! mbuf_indent(p))
                return(0);
 
-       /* FIXME: put into a buffer before writing (line length). */
+       /* 
+        * FIXME: put into a buffer before writing (check line length).
+        */
 
-       /* FIXME: not always with a space... */
-
-       if ( ! md_buf_putstring(p->mbuf, " <"))
+       if (space && ! mbuf_nputstring(p, " ", 1))
+               return(0);
+       if ( ! mbuf_nputstring(p, "<", 1))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, toknames[tok]))
+       if ( ! mbuf_putstring(p, toknames[tok]))
                return(0);
 
        for (i = 0; ROFF_ARGMAX != argc[i]; i++) {
-               if ( ! md_buf_putchar(p->mbuf, ' '))
+               if ( ! mbuf_nputstring(p, " ", 1))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, tokargnames[argc[i]]))
+               if ( ! mbuf_putstring(p, tokargnames[argc[i]]))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, "=\""))
+               if ( ! mbuf_nputstring(p, "=\"", 2))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, argv[i] ? 
-                                       argv[i] : "true"))
+               if ( ! mbuf_putstring(p, argv[i] ? argv[i] : "true"))
                        return(0);
-               if ( ! md_buf_putstring(p->mbuf, "\""))
+               if ( ! mbuf_nputstring(p, "\"", 1))
                        return(0);
-
-               p->pos += strlen(toknames[tok]) + 4 +
-                       strlen(tokargnames[argc[i]]) +
-                       strlen(argv[i] ? argv[i] : "true");
        }
 
-       if ( ! md_buf_putstring(p->mbuf, ">"))
-               return(0);
-
-       p->pos += strlen(toknames[tok]) + 3;
-
-       return(1);
+       return(mbuf_nputstring(p, ">", 1));
 }
 
 
@@ -401,20 +417,14 @@ roffout(void *arg, int tok)
        if (0 == p->pos && ! mbuf_indent(p))
                return(0);
 
-       if ( ! md_buf_putstring(p->mbuf, "</"))
+       if ( ! mbuf_nputstring(p, "</", 2))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, toknames[tok]))
+       if ( ! mbuf_putstring(p, toknames[tok]))
                return(0);
-       if ( ! md_buf_putstring(p->mbuf, ">"))
-               return(0);
-
-       p->pos += strlen(toknames[tok]) + 2;
-
-       return(1);
+       return(mbuf_nputstring(p, ">", 1));
 }
 
 
-
 static void
 roffmsg(void *arg, enum roffmsg lvl, 
                const char *buf, const char *pos, char *msg)
@@ -439,8 +449,9 @@ roffmsg(void *arg, enum roffmsg lvl,
        }
        
        if (pos)
-               (void)fprintf(stderr, "%s:%zu: %s: %s\n", 
-                               p->rbuf->name, p->rbuf->line, level, msg);
+               (void)fprintf(stderr, "%s:%zu: %s: %s (column %zu)\n", 
+                               p->rbuf->name, p->rbuf->line, level, 
+                               msg, pos - buf);
        else
                (void)fprintf(stderr, "%s: %s: %s\n", 
                                p->rbuf->name, level, msg);