X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/blobdiff_plain/4b3c5afb39849b3d0e738248daec9ab7dd8aac6d..515d216bfcf6993e362b520913a05ac69fc99132:/bk_man.c diff --git a/bk_man.c b/bk_man.c index 876ecb5..60157fa 100644 --- a/bk_man.c +++ b/bk_man.c @@ -16,6 +16,7 @@ typedef struct { wchar_t *th; int headnumbers; int mindepth; + char *filename; } manconfig; static manconfig man_configure(paragraph *source) { @@ -27,6 +28,7 @@ static manconfig man_configure(paragraph *source) { ret.th = NULL; ret.headnumbers = FALSE; ret.mindepth = 0; + ret.filename = dupstr("output.1"); for (; source; source = source->next) { if (source->type == para_Config) { @@ -37,12 +39,16 @@ static manconfig man_configure(paragraph *source) { ep = wp; while (*ep) ep = uadv(ep); + sfree(ret.th); ret.th = mknewa(wchar_t, ep - wp + 1); memcpy(ret.th, wp, (ep - wp + 1) * sizeof(wchar_t)); } else if (!ustricmp(source->keyword, L"man-headnumbers")) { ret.headnumbers = utob(uadv(source->keyword)); } else if (!ustricmp(source->keyword, L"man-mindepth")) { ret.mindepth = utoi(uadv(source->keyword)); + } else if (!ustricmp(source->keyword, L"man-filename")) { + sfree(ret.filename); + ret.filename = utoa_dup(uadv(source->keyword)); } } } @@ -53,32 +59,58 @@ static manconfig man_configure(paragraph *source) { static void man_conf_cleanup(manconfig cf) { sfree(cf.th); + sfree(cf.filename); +} + +paragraph *man_config_filename(char *filename) +{ + paragraph *p; + wchar_t *ufilename, *up; + int len; + + p = mknew(paragraph); + memset(p, 0, sizeof(*p)); + p->type = para_Config; + p->next = NULL; + p->fpos.filename = ""; + p->fpos.line = p->fpos.col = -1; + + ufilename = ufroma_dup(filename); + len = ustrlen(ufilename) + 2 + lenof(L"man-filename"); + p->keyword = mknewa(wchar_t, len); + up = p->keyword; + ustrcpy(up, L"man-filename"); + up = uadv(up); + ustrcpy(up, ufilename); + up = uadv(up); + *up = L'\0'; + assert(up - p->keyword < len); + sfree(ufilename); + + return p; } #define QUOTE_INITCTRL 1 /* quote initial . and ' on a line */ #define QUOTE_QUOTES 2 /* quote double quotes by doubling them */ void man_backend(paragraph *sourceform, keywordlist *keywords, - indexdata *idx) { + indexdata *idx, void *unused) { paragraph *p; FILE *fp; - char const *sep; manconfig conf; - IGNORE(keywords); /* we don't happen to need this */ - IGNORE(idx); /* or this */ + IGNORE(unused); + IGNORE(keywords); + IGNORE(idx); conf = man_configure(sourceform); /* - * Determine the output file name, and open the output file - * - * FIXME: want configurable output file names here. For the - * moment, we'll just call it `output.1'. + * Open the output file. */ - fp = fopen("output.1", "w"); + fp = fopen(conf.filename, "w"); if (!fp) { - error(err_cantopenw, "output.1"); + error(err_cantopenw, conf.filename); return; } @@ -90,40 +122,23 @@ void man_backend(paragraph *sourceform, keywordlist *keywords, } /* .TH name-of-program manual-section */ - { + fprintf(fp, ".TH"); + if (conf.th && *conf.th) { char *c; - if (conf.th && *conf.th) { - wchar_t *wp; - fprintf(fp, ".TH"); - - for (wp = conf.th; *wp; wp = uadv(wp)) { - fputs(" \"", fp); - man_convert(wp, 0, &c, QUOTE_QUOTES); - fputs(c, fp); - sfree(c); - fputc('"', fp); - } - fputc('\n', fp); + wchar_t *wp; + + for (wp = conf.th; *wp; wp = uadv(wp)) { + fputs(" \"", fp); + man_convert(wp, 0, &c, QUOTE_QUOTES); + fputs(c, fp); + sfree(c); + fputc('"', fp); } } + fputc('\n', fp); fprintf(fp, ".UC\n"); - /* Do the preamble and copyright */ - sep = ""; - for (p = sourceform; p; p = p->next) - if (p->type == para_Preamble) { - fprintf(fp, "%s", sep); - man_text(fp, p->words, TRUE, 0); - sep = "\n"; - } - for (p = sourceform; p; p = p->next) - if (p->type == para_Copyright) { - fprintf(fp, "%s", sep); - man_text(fp, p->words, TRUE, 0); - sep = "\n"; - } - for (p = sourceform; p; p = p->next) switch (p->type) { /* * Things we ignore because we've already processed them or @@ -133,8 +148,6 @@ void man_backend(paragraph *sourceform, keywordlist *keywords, case para_BR: case para_Biblio: /* only touch BiblioCited */ case para_VersionID: - case para_Copyright: - case para_Preamble: case para_NoCite: case para_Title: break; @@ -147,6 +160,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords, case para_UnnumberedChapter: case para_Heading: case para_Subsect: + { int depth; if (p->type == para_Subsect) @@ -179,6 +193,7 @@ void man_backend(paragraph *sourceform, keywordlist *keywords, * Normal paragraphs. */ case para_Normal: + case para_Copyright: fprintf(fp, ".PP\n"); man_text(fp, p->words, TRUE, 0); break; @@ -224,9 +239,11 @@ void man_backend(paragraph *sourceform, keywordlist *keywords, break; case para_LcontPush: + case para_QuotePush: fprintf(fp, ".RS\n"); break; case para_LcontPop: + case para_QuotePop: fprintf(fp, ".RE\n"); break; }