=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.8 retrieving revision 1.10 diff -u -p -r1.8 -r1.10 --- texi2mdoc/util.c 2015/02/23 11:56:39 1.8 +++ texi2mdoc/util.c 2015/02/23 15:09:09 1.10 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.8 2015/02/23 11:56:39 kristaps Exp $ */ +/* $Id: util.c,v 1.10 2015/02/23 15:09:09 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -170,6 +170,8 @@ texiputchar(struct texi *p, char c) if ('.' == c && 0 == p->outcol) fputs("\\&", stdout); + if ('\'' == c && 0 == p->outcol) + fputs("\\&", stdout); putchar(c); p->seenvs = 0; @@ -193,6 +195,21 @@ texiputchars(struct texi *p, const char *s) } /* + * This puts all characters onto the output stream but makes sure to + * escape mdoc(7) slashes. + */ +void +texiputbuf(struct texi *p, const char *buf, size_t start, size_t end) +{ + + for ( ; start < end; start++) { + texiputchar(p, buf[start]); + if ('\\' == buf[start]) + texiputchar(p, 'e'); + } +} + +/* * Close an mdoc(7) macro opened with teximacroopen(). * If there are no more macros on the line, prints a newline. */ @@ -527,6 +544,9 @@ texiword(struct texi *p, const char *buf, '\'' == buf[*pos + 1]) { texiputchars(p, "\\(rq"); advance(p, buf, pos); + } else if ('\\' == buf[*pos]) { + texiputchar(p, buf[*pos]); + texiputchar(p, 'e'); } else texiputchar(p, buf[*pos]); advance(p, buf, pos); @@ -1143,8 +1163,30 @@ argparse(struct texi *p, const char *buf, args = NULL; *argsz = 0; - /* Check for no arguments. */ - if ('{' != buf[*pos]) + if ('{' != buf[*pos] && hint) { + /* + * Special case: if we encounter an unbracketed argument + * and we're being invoked with non-zero arguments + * (versus being set, i.e., hint>0), then parse until + * the end of line. + */ + *argsz = 1; + args = calloc(1, sizeof(char *)); + if (NULL == args) + texiabort(p, NULL); + start = *pos; + while (*pos < sz) { + if ('\n' == buf[*pos]) + break; + advance(p, buf, pos); + } + args[0] = malloc(*pos - start + 1); + memcpy(args[0], &buf[start], *pos - start); + args[0][*pos - start] = '\0'; + if (*pos < sz && '\n' == buf[*pos]) + advance(p, buf, pos); + return(args); + } else if ('{' != buf[*pos]) return(args); /* Parse til the closing '}', putting into the array. */