* [PATCH] implement .Bk
@ 2010-06-26 13:38 Ingo Schwarze
2010-06-26 13:54 ` Kristaps Dzonsons
0 siblings, 1 reply; 3+ messages in thread
From: Ingo Schwarze @ 2010-06-26 13:38 UTC (permalink / raw)
To: tech
Hi,
yesterday night, i arrived at Edmonton for the c2k10, the OpenBSD
yearly general hackathon. I plan to spend this week on mandoc.
Here is the first patch i hacked up on the plane,
implementing proper .Bk support.
It is based on OpenBSD-current and can probably go in more or less
as it is after merging bsd.lv HEAD into OpenBSD.
Yours,
Ingo
Index: mdoc_term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/mdoc_term.c,v
retrieving revision 1.87
diff -u -p -r1.87 mdoc_term.c
--- mdoc_term.c 10 Jun 2010 22:50:10 -0000 1.87
+++ mdoc_term.c 26 Jun 2010 11:38:21 -0000
@@ -71,6 +71,7 @@ static void termp____post(DECL_ARGS);
static void termp_an_post(DECL_ARGS);
static void termp_aq_post(DECL_ARGS);
static void termp_bd_post(DECL_ARGS);
+static void termp_bk_post(DECL_ARGS);
static void termp_bl_post(DECL_ARGS);
static void termp_bq_post(DECL_ARGS);
static void termp_brq_post(DECL_ARGS);
@@ -95,6 +96,7 @@ static int termp_ap_pre(DECL_ARGS);
static int termp_aq_pre(DECL_ARGS);
static int termp_bd_pre(DECL_ARGS);
static int termp_bf_pre(DECL_ARGS);
+static int termp_bk_pre(DECL_ARGS);
static int termp_bl_pre(DECL_ARGS);
static int termp_bold_pre(DECL_ARGS);
static int termp_bq_pre(DECL_ARGS);
@@ -234,7 +236,7 @@ static const struct termact termacts[MDO
{ NULL, NULL }, /* Fc */
{ termp_op_pre, termp_op_post }, /* Oo */
{ NULL, NULL }, /* Oc */
- { NULL, NULL }, /* Bk */
+ { termp_bk_pre, termp_bk_post }, /* Bk */
{ NULL, NULL }, /* Ek */
{ termp_bt_pre, NULL }, /* Bt */
{ NULL, NULL }, /* Hf */
@@ -2157,6 +2159,24 @@ termp_lk_pre(DECL_ARGS)
return(0);
}
+
+/* ARGSUSED */
+static int
+termp_bk_pre(DECL_ARGS)
+{
+
+ p->flags |= TERMP_PREKEEP;
+ return(1);
+}
+
+
+/* ARGSUSED */
+static void
+termp_bk_post(DECL_ARGS)
+{
+
+ p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP);
+}
/* ARGSUSED */
static int
Index: term.c
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term.c,v
retrieving revision 1.37
diff -u -p -r1.37 term.c
--- term.c 10 Jun 2010 22:50:10 -0000 1.37
+++ term.c 26 Jun 2010 11:38:21 -0000
@@ -480,9 +480,15 @@ term_word(struct termp *p, const char *w
}
if ( ! (TERMP_NOSPACE & p->flags)) {
- bufferc(p, ' ');
- if (TERMP_SENTENCE & p->flags)
+ if (TERMP_KEEP & p->flags)
+ bufferc(p, ASCII_NBRSP);
+ else {
+ if (TERMP_PREKEEP & p->flags)
+ p->flags |= TERMP_KEEP;
bufferc(p, ' ');
+ if (TERMP_SENTENCE & p->flags)
+ bufferc(p, ' ');
+ }
}
if ( ! (p->flags & TERMP_NONOSPACE))
Index: term.h
===================================================================
RCS file: /cvs/src/usr.bin/mandoc/term.h,v
retrieving revision 1.20
diff -u -p -r1.20 term.h
--- term.h 10 Jun 2010 22:50:10 -0000 1.20
+++ term.h 26 Jun 2010 11:38:21 -0000
@@ -76,6 +76,8 @@ struct termp {
#define TERMP_NOSPLIT (1 << 11) /* See termp_an_pre/post(). */
#define TERMP_SPLIT (1 << 12) /* See termp_an_pre/post(). */
#define TERMP_ANPREC (1 << 13) /* See termp_an_pre(). */
+#define TERMP_KEEP (1 << 14) /* Keep words together. */
+#define TERMP_PREKEEP (1 << 15) /* ...starting with the next one. */
char *buf; /* Output buffer. */
enum termenc enc; /* Type of encoding. */
void *symtab; /* Encoded-symbol table. */
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] implement .Bk
2010-06-26 13:54 ` Kristaps Dzonsons
@ 2010-06-26 13:53 ` Ingo Schwarze
0 siblings, 0 replies; 3+ messages in thread
From: Ingo Schwarze @ 2010-06-26 13:53 UTC (permalink / raw)
To: tech
Hi Kristaps,
> I like it with one nit noted in-line.
Good, thanks for looking!
> Also, can you document this in mdoc.7?
Sure.
> In general, I try to have the "else" not have braces---most of the code
> is structured as such. Can you flip this to
>
> if ( ! (TERMP_KEEP & p->flags)) {
> multi-line
> } else
> buffer(p, ASCII_NBRSP);
Yes, no problem, consistent style is helpful.
Myself, i do not really like
unless( condition ){
do something;
} else {
do something else;
}
in Perl, but perhaps "if (!) else" in C is not that bad.
Anyway, i will merge bsd.lv HEAD to OpenBSD, then apply your
points and commit to both trees.
Yours,
Ingo
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] implement .Bk
2010-06-26 13:38 [PATCH] implement .Bk Ingo Schwarze
@ 2010-06-26 13:54 ` Kristaps Dzonsons
2010-06-26 13:53 ` Ingo Schwarze
0 siblings, 1 reply; 3+ messages in thread
From: Kristaps Dzonsons @ 2010-06-26 13:54 UTC (permalink / raw)
To: tech
> yesterday night, i arrived at Edmonton for the c2k10, the OpenBSD
> yearly general hackathon. I plan to spend this week on mandoc.
>
> Here is the first patch i hacked up on the plane,
> implementing proper .Bk support.
> It is based on OpenBSD-current and can probably go in more or less
> as it is after merging bsd.lv HEAD into OpenBSD.
I like it with one nit noted in-line. Also, can you document this in
mdoc.7?
Other than that, ok kristaps.
> if ( ! (TERMP_NOSPACE & p->flags)) {
> - bufferc(p, ' ');
> - if (TERMP_SENTENCE & p->flags)
> + if (TERMP_KEEP & p->flags)
> + bufferc(p, ASCII_NBRSP);
> + else {
> + if (TERMP_PREKEEP & p->flags)
> + p->flags |= TERMP_KEEP;
> bufferc(p, ' ');
> + if (TERMP_SENTENCE & p->flags)
> + bufferc(p, ' ');
> + }
In general, I try to have the "else" not have braces---most of the code
is structured as such. Can you flip this to
if ( ! (TERMP_KEEP & p->flags)) {
multi-line
} else
buffer(p, ASCII_NBRSP);
I'm pretty dumb in this regard: seeing the else-brace without the
if-brace just plain confuses me.
Good work!
Kristaps
--
To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-06-26 13:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-26 13:38 [PATCH] implement .Bk Ingo Schwarze
2010-06-26 13:54 ` Kristaps Dzonsons
2010-06-26 13:53 ` Ingo Schwarze
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).