mdoc_man.c revision 95c635efb7c3b86efc493e0447eaec7aecca3f0f
/* $Id: mdoc_man.c,v 1.9 2011/10/24 21:47:59 schwarze Exp $ */
/*
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <string.h>
#include "mandoc.h"
#include "man.h"
#include "mdoc.h"
#include "main.h"
const struct mdoc_node *n, \
struct mman {
int need_space; /* next word needs prior ws */
int need_nl; /* next word needs prior nl */
};
struct manact {
const char *prefix; /* pre-node string constant */
const char *suffix; /* post-node string constant */
};
static void post_percent(DECL_ARGS);
static void print_word(struct mman *, const char *);
static void print_node(DECL_ARGS);
"\\fP\nutility exits 0 on success, and >0 if an error occurs."
}, /* Ex */
"\\fP\nfunction returns the value 0 if successful;\n"
"otherwise the value -1 is returned and the global\n"
"variable \\fIerrno\\fP is set to indicate the error."
}, /* Rv */
};
static void
{
/*
* If we need a newline, print it now and start afresh.
*/
putchar('\n');
mm->need_space = 0;
/*
* If we need a space, only print it before
* (1) a nonzero length word;
* (2) a word that is non-punctuation; and
* (3) if punctuation, non-terminating puncutation.
*/
putchar(' ');
/*
* Reassign needing space if we're not following opening
* punctuation.
*/
mm->need_space =
('(' != s[0] && '[' != s[0]) || '\0' != s[1];
for ( ; *s; s++) {
switch (*s) {
case (ASCII_NBRSP):
printf("\\~");
break;
case (ASCII_HYPH):
putchar('-');
break;
default:
putchar((unsigned char)*s);
break;
}
}
}
void
{
/*
* Dump the keep buffer.
* We're guaranteed by now that this exists (is non-NULL).
* Flush stdout afterward, just in case.
*/
}
void
{
const struct mdoc_meta *m;
const struct mdoc_node *n;
printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"",
print_node(m, n, &mm);
putchar('\n');
}
static void
{
/*
* Break the line if we were parsed subsequent the current node.
* This makes the page structure be more consistent.
*/
cond = 0;
do_sub = 1;
/*
* Make sure that we don't happen to start with a
* control character at the start of a line.
*/
'\'' == *n->string)) {
mm->need_space = 0;
}
} else {
/*
* Conditionally run the pre-node action handler for a
* node.
*/
}
/*
* Conditionally run all child nodes.
* Note that this iterates over children instead of using
* recursion. This prevents unnecessary depth in the stack.
*/
if (do_sub)
/*
* Lastly, conditionally run the post-node handler.
*/
}
static int
{
}
static int
{
}
/*
* Output a font encoding before a node, e.g., \fR.
* This obviously has no trailing space.
*/
static int
{
const char *prefix;
return(1);
mm->need_space = 0;
return(1);
}
/*
* Output a font encoding subsequent a node, e.g., \fP.
*/
static void
{
const char *suffix;
return;
mm->need_space = 0;
}
/*
* Used in listings (percent = %A, e.g.).
* FIXME: this is incomplete.
* It doesn't print a nice ", and" for lists.
*/
static void
{
if (n->next)
else {
}
}
/*
* Print before a section header.
*/
static int
{
return(1);
mm->need_space = 0;
return(1);
}
/*
* Print subsequent a section header.
*/
static void
{
return;
mm->need_space = 0;
}
static int
{
mm->need_space = 0;
mm->need_space = 0;
return(0);
}
static int
{
}
return(1);
}
static void
{
}
}
static int
{
return(0);
}
static int
{
n = n->child;
if (n) {
mm->need_space = 0;
n = n->next;
}
if (NULL == n)
return(0);
mm->need_space = 0;
mm->need_space = 0;
return(0);
}
static int
{
return(1);
}
static void
{
}
static int
{
case (LIST_bullet):
break;
default:
break;
}
}
return(1);
}
static int
{
return(1);
mm->need_space = 0;
return(1);
}
static void
{
return;
mm->need_space = 0;
}
static int
{
mm->need_space = 0;
return(0);
}
static void
{
mm->need_space = 0;
}
static int
{
else
return(1);
}
static int
{
return(1);
}
static void
{
}
static int
{
n = n->child;
if (NULL == n)
return(0);
print_node(m, n, mm);
n = n->next;
if (NULL == n)
return(0);
mm->need_space = 0;
print_node(m, n, mm);
return(0);
}
static int
{
return(0);
mm->need_space = 0;
mm->need_space = 0;
return(1);
}