=================================================================== RCS file: /cvs/mandoc/Attic/mlg.c,v retrieving revision 1.16 retrieving revision 1.18 diff -u -p -r1.16 -r1.18 --- mandoc/Attic/mlg.c 2008/12/06 21:10:31 1.16 +++ mandoc/Attic/mlg.c 2008/12/07 16:41:04 1.18 @@ -1,4 +1,4 @@ -/* $Id: mlg.c,v 1.16 2008/12/06 21:10:31 kristaps Exp $ */ +/* $Id: mlg.c,v 1.18 2008/12/07 16:41:04 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -62,6 +62,7 @@ struct md_mlg { static char *mlg_literal(int); static char *mlg_At_literal(const char *); +static char *mlg_fmt(int); static char *mlg_St_literal(int); static void mlg_roffmsg(void *arg, enum roffmsg, const char *, const char *, char *); @@ -200,6 +201,7 @@ mlg_St_literal(int argc) static char * mlg_At_literal(const char *p) { + if (NULL == p) return("AT&T UNIX"); if (0 == strcmp(p, "v6")) @@ -219,8 +221,34 @@ mlg_At_literal(const char *p) static char * +mlg_fmt(int tok) +{ + + switch (tok) { + case (ROFF_Ex): + return ("The %s utility exits 0 on success, and " + ">0 if an error occurs."); + case (ROFF_Rv): + return ("The %s() function returns the value 0 if " + "successful; otherwise the value -1 " + "is returned and the global variable " + "errno " + "is set to indicate the error."); + case (ROFF_In): + return("#include <%s>"); + default: + break; + } + + abort(); + /* NOTREACHED */ +} + + +static char * mlg_literal(int tok) { + switch (tok) { case (ROFF_Bt): return("is currently in beta test."); @@ -564,6 +592,7 @@ mlg_roffspecial(void *arg, int tok, const char *start, const int *argc, const char **argv, char **more) { struct md_mlg *p; + char buf[256]; assert(arg); p = (struct md_mlg *)arg; @@ -587,6 +616,52 @@ mlg_roffspecial(void *arg, int tok, const char *start, break; } + /* + * Handle macros put into different-token tags. + */ + + switch (tok) { + case (ROFF_Fn): + assert(*more); + if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, more)) + return(0); + if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + return(0); + if ( ! mlg_endtag(p, MD_NS_INLINE, tok)) + return(0); + if (*more) { + if ( ! ml_nputs(p->mbuf, "(", 1, &p->pos)) + return(0); + p->flags |= ML_OVERRIDE_ONE; + if ( ! mlg_begintag(p, MD_NS_INLINE, + ROFF_Fa, NULL, more)) + return(0); + if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + return(0); + if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Fa)) + return(0); + while (*more) { + if ( ! ml_nputs(p->mbuf, ", ", 2, &p->pos)) + return(0); + if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Fa, NULL, more)) + return(0); + if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) + return(0); + if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Fa)) + return(0); + } + if ( ! ml_nputs(p->mbuf, ")", 1, &p->pos)) + return(0); + } + return(1); + default: + break; + } + + /* + * Now handle macros in their environments. + */ + if ( ! mlg_begintag(p, MD_NS_INLINE, tok, NULL, more)) return(0); @@ -629,23 +704,21 @@ mlg_roffspecial(void *arg, int tok, const char *start, /* FALLTHROUGH */ case (ROFF_Nm): assert(*more); - if ( ! ml_puts(p->mbuf, *more++, &p->pos)) + if ( ! ml_putstring(p->mbuf, *more++, &p->pos)) return(0); assert(NULL == *more); break; + + case (ROFF_In): + /* NOTREACHED */ case (ROFF_Ex): + /* NOTREACHED */ + case (ROFF_Rv): assert(*more); - if ( ! ml_puts(p->mbuf, "The ", &p->pos)) - return(0); - if ( ! mlg_begintag(p, MD_NS_INLINE, ROFF_Xr, NULL, NULL)) - return(0); - if ( ! ml_puts(p->mbuf, *more++, &p->pos)) - return(0); - if ( ! mlg_endtag(p, MD_NS_INLINE, ROFF_Xr)) - return(0); - if ( ! ml_puts(p->mbuf, " utility exits 0 on success, " - "and >0 if an error " - "occurs.", &p->pos)) + /* FIXME: *more must be ml-filtered. */ + (void)snprintf(buf, sizeof(buf), + mlg_fmt(tok), *more++); + if ( ! ml_puts(p->mbuf, buf, &p->pos)) return(0); assert(NULL == *more); break;