version 1.52, 2015/02/28 00:03:20 |
version 1.58, 2015/03/02 18:12:53 |
|
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <time.h> |
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "extern.h" |
#include "extern.h" |
Line 269 static const struct texitok __texitoks[TEXICMD__MAX] = |
|
Line 268 static const struct texitok __texitoks[TEXICMD__MAX] = |
|
{ doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */ |
{ doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */ |
{ doinline, "samp", 4 }, /* TEXICMD_SAMP */ |
{ doinline, "samp", 4 }, /* TEXICMD_SAMP */ |
{ doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */ |
{ doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */ |
{ dobracket, "sc", 2 }, /* TEXICMD_SC */ |
{ doinline, "sc", 2 }, /* TEXICMD_SC */ |
{ dosection, "section", 7 }, /* TEXICMD_SECTION */ |
{ dosection, "section", 7 }, /* TEXICMD_SECTION */ |
{ dovalue, "set", 3 }, /* TEXICMD_SET */ |
{ dovalue, "set", 3 }, /* TEXICMD_SET */ |
{ doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */ |
{ doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */ |
Line 498 dodefn(struct texi *p, enum texicmd cmd, size_t *pos) |
|
Line 497 dodefn(struct texi *p, enum texicmd cmd, size_t *pos) |
|
abort(); |
abort(); |
} |
} |
|
|
texivspace(p); |
if (NULL == blk) |
if (NULL != blk) |
return; |
parseto(p, pos, blk); |
|
|
/* |
|
* All "block" definitions have their block bodies indented |
|
* unless they have the "x" form of the command following. |
|
* E.g., |
|
* @deffn some function |
|
* @deffnx another |
|
* An explanation. |
|
* @end deffn |
|
* With this loop, we delay opening the indented block until we |
|
* skipped past conformant macros. |
|
*/ |
|
for (;;) { |
|
switch (peekcmd(p, *pos)) { |
|
case (TEXICMD_DEFFNX): |
|
case (TEXICMD_DEFMACX): |
|
case (TEXICMD_DEFTPX): |
|
case (TEXICMD_DEFTYPEFNX): |
|
case (TEXICMD_DEFTYPEFUNX): |
|
case (TEXICMD_DEFTYPEMETHODX): |
|
case (TEXICMD_DEFTYPEVARX): |
|
case (TEXICMD_DEFTYPEVRX): |
|
case (TEXICMD_DEFUNX): |
|
case (TEXICMD_DEFVARX): |
|
case (TEXICMD_DEFVRX): |
|
texivspace(p); |
|
parseeoln(p, pos); |
|
continue; |
|
default: |
|
break; |
|
} |
|
break; |
|
} |
|
teximacro(p, "Bd -filled -offset indent"); |
|
p->seenvs = 1; |
|
parseto(p, pos, blk); |
|
teximacro(p, "Ed"); |
} |
} |
|
|
static void |
static void |
Line 690 doinline(struct texi *p, enum texicmd cmd, size_t *pos |
|
Line 725 doinline(struct texi *p, enum texicmd cmd, size_t *pos |
|
} |
} |
|
|
if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) { |
if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) { |
parsebracket(p, pos); |
if (TEXICMD_SC == cmd) |
|
p->uppercase++; |
|
parsebracket(p, pos, 0); |
|
if (TEXICMD_SC == cmd) |
|
p->uppercase--; |
return; |
return; |
} |
} |
|
|
teximacroopen(p, macro); |
teximacroopen(p, macro); |
p->seenws = 0; |
p->seenws = 0; |
parsebracket(p, pos); |
if (TEXICMD_SC == cmd) |
|
p->uppercase++; |
|
parsebracket(p, pos, 0); |
|
if (TEXICMD_SC == cmd) |
|
p->uppercase--; |
texipunctuate(p, pos); |
texipunctuate(p, pos); |
teximacroclose(p); |
teximacroclose(p); |
} |
} |
|
|
dobracket(struct texi *p, enum texicmd cmd, size_t *pos) |
dobracket(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
|
|
parsebracket(p, pos); |
parsebracket(p, pos, 0); |
} |
} |
|
|
static void |
static void |
dodisplay(struct texi *p, enum texicmd cmd, size_t *pos) |
dodisplay(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
|
|
|
advanceeoln(p, pos, 1); |
|
|
switch (cmd) { |
switch (cmd) { |
case (TEXICMD_FORMAT): |
case (TEXICMD_FORMAT): |
case (TEXICMD_SMALLFORMAT): |
case (TEXICMD_SMALLFORMAT): |
Line 918 dodisplay(struct texi *p, enum texicmd cmd, size_t *po |
|
Line 963 dodisplay(struct texi *p, enum texicmd cmd, size_t *po |
|
} |
} |
|
|
p->seenvs = 1; |
p->seenvs = 1; |
/* FIXME: ignore and parseeoln. */ |
|
advanceeoln(p, pos, 1); |
|
parseto(p, pos, texitoks[cmd].tok); |
parseto(p, pos, texitoks[cmd].tok); |
teximacro(p, "Ed"); |
teximacro(p, "Ed"); |
} |
} |
|
|
doexample(struct texi *p, enum texicmd cmd, size_t *pos) |
doexample(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
|
|
teximacro(p, "Bd -literal -offset indent"); |
|
/* FIXME: ignore and parseeoln. */ |
|
advanceeoln(p, pos, 1); |
advanceeoln(p, pos, 1); |
|
|
|
teximacro(p, "Bd -literal -offset indent"); |
p->literal++; |
p->literal++; |
parseto(p, pos, texitoks[cmd].tok); |
parseto(p, pos, texitoks[cmd].tok); |
p->literal--; |
p->literal--; |
Line 948 dobye(struct texi *p, enum texicmd cmd, size_t *pos) |
|
Line 991 dobye(struct texi *p, enum texicmd cmd, size_t *pos) |
|
static void |
static void |
dotitle(struct texi *p, enum texicmd cmd, size_t *pos) |
dotitle(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
size_t start, end; |
size_t start; |
|
|
while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) |
while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) |
advance(p, pos); |
advance(p, pos); |
start = end = *pos; |
|
while (end < BUFSZ(p) && '\n' != BUF(p)[end]) |
/* We want to suck down the entire line, inclusive \n. */ |
end++; |
start = *pos; |
advanceeoln(p, pos, 1); |
while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) { |
|
if ('@' == BUF(p)[*pos]) |
|
advance(p, pos); |
|
advance(p, pos); |
|
} |
|
if (*pos < BUFSZ(p)) |
|
advance(p, pos); |
|
|
|
/* Copy this into a buffer. */ |
free(p->subtitle); |
free(p->subtitle); |
p->subtitle = malloc(end - start + 1); |
if (NULL == (p->subtitle = malloc(*pos - start + 1))) |
if (NULL == p->subtitle) |
|
texiabort(p, NULL); |
texiabort(p, NULL); |
memcpy(p->subtitle, &BUF(p)[start], end - start); |
memcpy(p->subtitle, &BUF(p)[start], *pos - start); |
p->subtitle[end - start] = '\0'; |
p->subtitle[*pos - start] = '\0'; |
} |
} |
|
|
static void |
static void |
Line 1328 doquotation(struct texi *p, enum texicmd cmd, size_t * |
|
Line 1378 doquotation(struct texi *p, enum texicmd cmd, size_t * |
|
static void |
static void |
domath(struct texi *p, enum texicmd cmd, size_t *pos) |
domath(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
size_t nest, start; |
|
|
|
/* |
parsebracket(p, pos, 1); |
* Math handling is different from everything else. |
|
* We don't allow any subcomponents, and we ignore the rules in |
|
* terms of @-commands. |
|
* This departs from GNU's rules, but whatever. |
|
*/ |
|
while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) |
|
advance(p, pos); |
|
if (*pos == BUFSZ(p) || '{' != BUF(p)[*pos]) |
|
return; |
|
advance(p, pos); |
|
if (p->seenws && p->outcol && 0 == p->literal) |
|
texiputchar(p, ' '); |
|
p->seenws = 0; |
|
for (nest = 1, start = *pos; *pos < BUFSZ(p) && nest > 0; ) { |
|
if ('{' == BUF(p)[*pos]) |
|
nest++; |
|
else if ('}' == BUF(p)[*pos]) |
|
if (0 == --nest) |
|
continue; |
|
advance(p, pos); |
|
} |
|
if (*pos == BUFSZ(p)) |
|
return; |
|
assert('}' == BUF(p)[*pos]); |
|
texiputbuf(p, start, *pos); |
|
advance(p, pos); |
|
} |
} |
|
|
static void |
static void |
Line 1402 dovalue(struct texi *p, enum texicmd cmd, size_t *pos) |
|
Line 1425 dovalue(struct texi *p, enum texicmd cmd, size_t *pos) |
|
texiputchar(p, ' '); |
texiputchar(p, ' '); |
p->seenws = 0; |
p->seenws = 0; |
if (NULL != (cp = valueblookup(p, pos))) |
if (NULL != (cp = valueblookup(p, pos))) |
texisplice(p, cp, strlen(cp), pos); |
texisplice(p, cp, strlen(cp), *pos); |
else |
else |
texiputchars(p, "{No value}"); |
texiputchars(p, "{No value}"); |
} else if (TEXICMD_IFCLEAR == cmd) { |
} else if (TEXICMD_IFCLEAR == cmd) { |
Line 1544 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
Line 1567 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
int sec; |
int sec; |
|
|
switch (cmd) { |
switch (cmd) { |
|
case (TEXICMD_TOP): |
|
sec = 0; |
|
break; |
case (TEXICMD_APPENDIX): |
case (TEXICMD_APPENDIX): |
case (TEXICMD_CHAPTER): |
case (TEXICMD_CHAPTER): |
case (TEXICMD_TOP): |
|
case (TEXICMD_UNNUMBERED): |
case (TEXICMD_UNNUMBERED): |
sec = sectioner(p, 0); |
sec = sectioner(p, 0); |
break; |
break; |
Line 1565 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
Line 1590 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
else if (p->literal) |
else if (p->literal) |
texierr(p, "\"%s\" in a literal scope!?", sects[sec]); |
texierr(p, "\"%s\" in a literal scope!?", sects[sec]); |
|
|
|
if (0 == sec && NULL != p->chapters) { |
|
teximdocclose(p, 0); |
|
teximdocopen(p, pos); |
|
} |
|
|
teximacroopen(p, sects[sec]); |
teximacroopen(p, sects[sec]); |
parseeoln(p, pos); |
parseeoln(p, pos); |
teximacroclose(p); |
teximacroclose(p); |
Line 1572 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
Line 1602 dosection(struct texi *p, enum texicmd cmd, size_t *po |
|
} |
} |
|
|
static void |
static void |
dosp(struct texi *p, enum texicmd cmd, size_t *pos) |
|
{ |
|
|
|
if (p->literal) |
|
texiputchar(p, '\n'); |
|
else |
|
texivspace(p); |
|
/* FIXME: ignore and parseeoln. */ |
|
advanceeoln(p, pos, 1); |
|
} |
|
|
|
static void |
|
dotop(struct texi *p, enum texicmd cmd, size_t *pos) |
dotop(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
const char *cp; |
|
time_t t; |
|
char date[32]; |
|
|
|
if (--p->ign) |
if (--p->ign) |
texierr(p, "@top command while ignoring"); |
texierr(p, "@top command while ignoring"); |
|
|
/* |
if (NULL == p->chapters) |
* Here we print our standard mdoc(7) prologue. |
teximdocopen(p, pos); |
* We use the title set with @settitle for the `Nd' description |
dosection(p, cmd, pos); |
* and the source document filename (the first one as invoked on |
} |
* the command line) for the title. |
|
* The date is set to the current date. |
|
*/ |
|
t = time(NULL); |
|
strftime(date, sizeof(date), "%F", localtime(&t)); |
|
|
|
teximacroopen(p, "Dd"); |
static void |
texiputchars(p, date); |
dosp(struct texi *p, enum texicmd cmd, size_t *pos) |
teximacroclose(p); |
{ |
teximacroopen(p, "Dt"); |
|
for (cp = p->title; '\0' != *cp; cp++) |
advanceeoln(p, pos, 1); |
texiputchar(p, toupper((unsigned int)*cp)); |
if (p->literal) |
texiputchars(p, " 7"); |
texiputchar(p, '\n'); |
teximacroclose(p); |
|
teximacro(p, "Os"); |
|
teximacro(p, "Sh NAME"); |
|
teximacroopen(p, "Nm"); |
|
for (cp = p->title; '\0' != *cp; cp++) |
|
texiputchar(p, *cp); |
|
teximacroclose(p); |
|
teximacroopen(p, "Nd"); |
|
if (NULL != p->subtitle) |
|
for (cp = p->subtitle; '\0' != *cp; cp++) |
|
texiputchar(p, *cp); |
|
else |
else |
texiputchars(p, "Unknown description"); |
texivspace(p); |
teximacroclose(p); |
|
p->seenvs = 1; |
|
dosection(p, cmd, pos); |
|
} |
} |
|
|
static void |
static void |
Line 1697 domultitable(struct texi *p, enum texicmd cmd, size_t |
|
Line 1693 domultitable(struct texi *p, enum texicmd cmd, size_t |
|
|
|
/* Make sure we don't print anything when scanning. */ |
/* Make sure we don't print anything when scanning. */ |
p->ign++; |
p->ign++; |
if ('@' == BUF(p)[*pos]) { |
if (*pos < BUFSZ(p) && '@' == BUF(p)[*pos]) { |
/* |
/* |
* Look for @columnfractions. |
* Look for @columnfractions. |
* We ignore these, but we do use the number of |
* We ignore these, but we do use the number of |
Line 1749 dotable(struct texi *p, enum texicmd cmd, size_t *pos) |
|
Line 1745 dotable(struct texi *p, enum texicmd cmd, size_t *pos) |
|
{ |
{ |
enum texilist sv = p->list; |
enum texilist sv = p->list; |
|
|
|
advanceeoln(p, pos, 1); |
|
|
p->list = TEXILIST_ITEM; |
p->list = TEXILIST_ITEM; |
teximacro(p, "Bl -tag -width Ds"); |
teximacro(p, "Bl -tag -width Ds"); |
/* FIXME: ignore and parseeoln. */ |
|
advanceeoln(p, pos, 1); |
|
p->seenvs = 1; |
p->seenvs = 1; |
parseto(p, pos, texitoks[cmd].tok); |
parseto(p, pos, texitoks[cmd].tok); |
teximacro(p, "El"); |
teximacro(p, "El"); |
Line 1770 doend(struct texi *p, enum texicmd cmd, size_t *pos) |
|
Line 1766 doend(struct texi *p, enum texicmd cmd, size_t *pos) |
|
while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) |
while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) |
advance(p, pos); |
advance(p, pos); |
|
|
texiwarn(p, "unexpected \"end\": %.*s", (int)(*pos - start), &BUF(p)[start]); |
texiwarn(p, "unexpected \"end\": %.*s", |
|
(int)(*pos - start), &BUF(p)[start]); |
advanceeoln(p, pos, 1); |
advanceeoln(p, pos, 1); |
} |
} |
|
|
Line 1779 doenumerate(struct texi *p, enum texicmd cmd, size_t * |
|
Line 1776 doenumerate(struct texi *p, enum texicmd cmd, size_t * |
|
{ |
{ |
enum texilist sv = p->list; |
enum texilist sv = p->list; |
|
|
|
advanceeoln(p, pos, 1); |
|
|
p->list = TEXILIST_NOITEM; |
p->list = TEXILIST_NOITEM; |
teximacro(p, "Bl -enum"); |
teximacro(p, "Bl -enum"); |
p->seenvs = 1; |
p->seenvs = 1; |
/* FIXME: ignore and parseeoln. */ |
parseto(p, pos, texitoks[cmd].tok); |
advanceeoln(p, pos, 1); |
|
parseto(p, pos, "enumerate"); |
|
teximacro(p, "El"); |
teximacro(p, "El"); |
p->list = sv; |
p->list = sv; |
} |
} |
Line 1794 doitemize(struct texi *p, enum texicmd cmd, size_t *po |
|
Line 1791 doitemize(struct texi *p, enum texicmd cmd, size_t *po |
|
{ |
{ |
enum texilist sv = p->list; |
enum texilist sv = p->list; |
|
|
|
advanceeoln(p, pos, 1); |
|
|
p->list = TEXILIST_NOITEM; |
p->list = TEXILIST_NOITEM; |
teximacro(p, "Bl -bullet"); |
teximacro(p, "Bl -bullet"); |
p->seenvs = 1; |
p->seenvs = 1; |
/* FIXME: ignore and parseeoln. */ |
parseto(p, pos, texitoks[cmd].tok); |
advanceeoln(p, pos, 1); |
|
parseto(p, pos, "itemize"); |
|
teximacro(p, "El"); |
teximacro(p, "El"); |
p->list = sv; |
p->list = sv; |
} |
} |
Line 1809 doignbracket(struct texi *p, enum texicmd cmd, size_t |
|
Line 1806 doignbracket(struct texi *p, enum texicmd cmd, size_t |
|
{ |
{ |
|
|
p->ign++; |
p->ign++; |
parsebracket(p, pos); |
parsebracket(p, pos, 0); |
p->ign--; |
p->ign--; |
} |
} |
|
|
|
|
doignline(struct texi *p, enum texicmd cmd, size_t *pos) |
doignline(struct texi *p, enum texicmd cmd, size_t *pos) |
{ |
{ |
|
|
/* FIXME: ignore and parseeoln. */ |
advanceeoln(p, pos, 1); |
advanceeoln(p, pos, 1); |
|
} |
} |
|
|
/* |
/* |
Line 1876 main(int argc, char *argv[]) |
|
Line 1872 main(int argc, char *argv[]) |
|
|
|
memset(&texi, 0, sizeof(struct texi)); |
memset(&texi, 0, sizeof(struct texi)); |
texi.ign = 1; |
texi.ign = 1; |
|
texi.outfile = stdout; |
Idir = NULL; |
Idir = NULL; |
|
|
while (-1 != (c = getopt(argc, argv, "I:"))) |
while (-1 != (c = getopt(argc, argv, "C:I:"))) |
switch (c) { |
switch (c) { |
|
case ('C'): |
|
texi.chapters = optarg; |
|
break; |
case ('I'): |
case ('I'): |
Idir = optarg; |
Idir = optarg; |
break; |
break; |
Line 1913 main(int argc, char *argv[]) |
|
Line 1913 main(int argc, char *argv[]) |
|
} |
} |
|
|
texiexit(&texi); |
texiexit(&texi); |
return(EXIT_FAILURE); |
exit(EXIT_SUCCESS); |
usage: |
usage: |
fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname); |
fprintf(stderr, "usage: %s [-Cdir] [-Idirs] [file]\n", progname); |
return(EXIT_FAILURE); |
return(EXIT_FAILURE); |
} |
} |