From: Kristaps Dzonsons <kristaps@bsd.lv>
To: tech@mdocml.bsd.lv
Subject: Re: -Tman with -mman
Date: Sun, 02 Oct 2011 21:53:33 +0200 [thread overview]
Message-ID: <4E88C13D.6090708@bsd.lv> (raw)
In-Reply-To: <20111002154058.GA14208@britannica.bec.de>
[-- Attachment #1: Type: text/plain, Size: 1191 bytes --]
On 02/10/2011 17:40, Joerg Sonnenberger wrote:
> On Sun, Oct 02, 2011 at 05:04:18PM +0200, Kristaps Dzonsons wrote:
>> Hi,
>>
>> What sort of behaviour is most reasonable when providing a man
>> manual to the new -Tman? I think this should be ironed out before
>> the release. The mandoc manual says "-Tman only with mdoc" and, if
>> man is provided to -Tman, outputs nothing (like -Tlint).
>>
>> It makes the most sense to me to output the original file (after
>> preprocessing, I guess). All this requires is a duplicate buffer in
>> read.c (conditional on -Tman being present to avoid overhead in
>> normal usage). I don't like the idea of putting out an error (or
>> nothing at all) because it special-cases modes for input.
>
> Agreed, just giving back the original input (maybe reformatted) sounds
> like the best approach.
Putting some code to the idea... (Sorry for the churn, I ordered the
mandoc.h functions. They're the same except for the mandoc_keep() and
mandoc_getkeep() additions). This isn't quite commit-ready, but a
start. Basically, I ask for a keep buffer if OUTT_MAN is specified.
This needed some machinery to expose the parser to the front-end.
Thoughts?
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 5729 bytes --]
Index: main.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/main.h,v
retrieving revision 1.14
diff -u -r1.14 main.h
--- main.h 18 Sep 2011 14:14:15 -0000 1.14
+++ main.h 2 Oct 2011 19:50:23 -0000
@@ -42,6 +42,7 @@
void tree_man(void *, const struct man *);
void man_mdoc(void *, const struct mdoc *);
+void man_man(void *, const struct man *);
void *locale_alloc(char *);
void *utf8_alloc(char *);
Index: man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.c,v
retrieving revision 1.111
diff -u -r1.111 man.c
--- man.c 28 Jul 2011 14:17:11 -0000 1.111
+++ man.c 2 Oct 2011 19:50:27 -0000
@@ -648,3 +648,10 @@
if (m && m->first == n)
m->first = NULL;
}
+
+const struct mparse *
+man_mparse(const struct man *m)
+{
+
+ return(m->parse);
+}
Index: man.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.h,v
retrieving revision 1.58
diff -u -r1.58 man.h
--- man.h 23 Mar 2011 12:33:01 -0000 1.58
+++ man.h 2 Oct 2011 19:50:27 -0000
@@ -105,6 +105,7 @@
const struct man_node *man_node(const struct man *);
const struct man_meta *man_meta(const struct man *);
+const struct mparse *man_mparse(const struct man *);
__END_DECLS
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.95
diff -u -r1.95 mandoc.h
--- mandoc.h 23 Jul 2011 18:44:42 -0000 1.95
+++ mandoc.h 2 Oct 2011 19:50:29 -0000
@@ -400,30 +400,31 @@
__BEGIN_DECLS
-void mparse_free(struct mparse *);
-void mparse_reset(struct mparse *);
-struct mparse *mparse_alloc(enum mparset,
- enum mandoclevel, mandocmsg, void *);
-enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
-void mparse_result(struct mparse *, struct mdoc **, struct man **);
-const char *mparse_strerror(enum mandocerr);
-const char *mparse_strlevel(enum mandoclevel);
-
void *mandoc_calloc(size_t, size_t);
+enum mandoc_esc mandoc_escape(const char **, const char **, int *);
void *mandoc_malloc(size_t);
void *mandoc_realloc(void *, size_t);
char *mandoc_strdup(const char *);
char *mandoc_strndup(const char *, size_t);
-
-enum mandoc_esc mandoc_escape(const char **, const char **, int *);
-
struct mchars *mchars_alloc(void);
+void mchars_free(struct mchars *);
char mchars_num2char(const char *, size_t);
int mchars_num2uc(const char *, size_t);
-const char *mchars_spec2str(struct mchars *, const char *, size_t, size_t *);
-int mchars_spec2cp(struct mchars *, const char *, size_t);
-void mchars_free(struct mchars *);
-
+int mchars_spec2cp(struct mchars *,
+ const char *, size_t);
+const char *mchars_spec2str(struct mchars *,
+ const char *, size_t, size_t *);
+struct mparse *mparse_alloc(enum mparset,
+ enum mandoclevel, mandocmsg, void *);
+void mparse_free(struct mparse *);
+void mparse_keep(struct mparse *);
+enum mandoclevel mparse_readfd(struct mparse *, int, const char *);
+void mparse_reset(struct mparse *);
+void mparse_result(struct mparse *,
+ struct mdoc **, struct man **);
+const char *mparse_getkeep(const struct mparse *);
+const char *mparse_strerror(enum mandocerr);
+const char *mparse_strlevel(enum mandoclevel);
__END_DECLS
Index: mdoc_man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_man.c,v
retrieving revision 1.3
diff -u -r1.3 mdoc_man.c
--- mdoc_man.c 30 Sep 2011 00:13:28 -0000 1.3
+++ mdoc_man.c 2 Oct 2011 19:50:29 -0000
@@ -18,6 +18,7 @@
#include <string.h>
#include "mandoc.h"
+#include "man.h"
#include "mdoc.h"
#include "main.h"
@@ -216,6 +217,13 @@
break;
}
}
+}
+
+void
+man_man(void *arg, const struct man *man)
+{
+
+ puts(mparse_getkeep(man_mparse(man)));
}
void
Index: read.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/read.c,v
retrieving revision 1.23
diff -u -r1.23 read.c
--- read.c 23 Jul 2011 18:41:18 -0000 1.23
+++ read.c 2 Oct 2011 19:50:33 -0000
@@ -63,6 +63,7 @@
mandocmsg mmsg; /* warning/error message handler */
void *arg; /* argument to mmsg */
const char *file;
+ struct buf *secondary;
};
static void resize_buf(struct buf *, size_t);
@@ -411,6 +412,21 @@
of = 0;
+ if (curp->secondary) {
+ curp->secondary->buf =
+ mandoc_realloc
+ (curp->secondary->buf,
+ curp->secondary->sz + pos + 2);
+ memcpy(curp->secondary->buf +
+ curp->secondary->sz,
+ ln.buf, pos);
+ curp->secondary->sz += pos;
+ curp->secondary->buf
+ [curp->secondary->sz] = '\n';
+ curp->secondary->sz++;
+ curp->secondary->buf
+ [curp->secondary->sz] = '\0';
+ }
rerun:
rr = roff_parseln
(curp->roff, curp->line,
@@ -704,6 +720,8 @@
mdoc_reset(curp->mdoc);
if (curp->man)
man_reset(curp->man);
+ if (curp->secondary)
+ curp->secondary->sz = 0;
curp->file_status = MANDOCLEVEL_OK;
curp->mdoc = NULL;
@@ -720,7 +738,10 @@
man_free(curp->pman);
if (curp->roff)
roff_free(curp->roff);
+ if (curp->secondary)
+ free(curp->secondary->buf);
+ free(curp->secondary);
free(curp);
}
@@ -779,4 +800,19 @@
mparse_strlevel(enum mandoclevel lvl)
{
return(mandoclevels[lvl]);
+}
+
+void
+mparse_keep(struct mparse *p)
+{
+
+ p->secondary = mandoc_calloc(1, sizeof(struct buf));
+}
+
+const char *
+mparse_getkeep(const struct mparse *p)
+{
+
+ assert(p->secondary);
+ return(p->secondary->sz ? p->secondary->buf : NULL);
}
next prev parent reply other threads:[~2011-10-02 19:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-02 15:04 Kristaps Dzonsons
2011-10-02 15:40 ` Joerg Sonnenberger
2011-10-02 19:53 ` Kristaps Dzonsons [this message]
2011-10-03 22:00 ` Ingo Schwarze
2011-10-03 22:18 ` Kristaps Dzonsons
2011-10-05 9:36 ` Kristaps Dzonsons
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E88C13D.6090708@bsd.lv \
--to=kristaps@bsd.lv \
--cc=tech@mdocml.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).