Remove txt2html and htmldoc from doc build

This commit is contained in:
Richard Berger 2019-11-02 23:07:49 -04:00
parent 8f946b765e
commit 12cb19090a
4 changed files with 3 additions and 1208 deletions

View File

@ -30,7 +30,7 @@ SPHINXEXTRA = -j $(shell $(PYTHON) -c 'import multiprocessing;print(multiprocess
SOURCES=$(filter-out $(wildcard src/lammps_commands*.txt) src/lammps_support.txt src/lammps_tutorials.txt,$(wildcard src/*.txt))
OBJECTS=$(SOURCES:src/%.txt=$(RSTDIR)/%.rst)
.PHONY: help clean-all clean epub mobi rst html pdf old venv spelling anchor_check
.PHONY: help clean-all clean epub mobi rst html pdf venv spelling anchor_check
# ------------------------------------------
@ -38,24 +38,22 @@ help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html create HTML doc pages in html dir"
@echo " pdf create Developer.pdf and Manual.pdf in this dir"
@echo " old create old-style HTML doc pages and Manual.pdf in old dir"
@echo " fetch fetch HTML and PDF files from LAMMPS web site"
@echo " epub create ePUB format manual for e-book readers"
@echo " mobi convert ePUB to MOBI format manual for e-book readers (e.g. Kindle)"
@echo " (requires ebook-convert tool from calibre)"
@echo " clean remove all intermediate RST files"
@echo " clean-all reset the entire build environment"
@echo " txt2html build txt2html tool"
@echo " anchor_check scan for duplicate anchor labels"
@echo " spelling spell-check the manual"
# ------------------------------------------
clean-all: clean
rm -rf $(BUILDDIR)/docenv $(BUILDDIR)/doctrees utils/txt2html/txt2html.exe
rm -rf $(BUILDDIR)/docenv $(BUILDDIR)/doctrees
clean:
rm -rf $(RSTDIR)/{Eqs,JPG,*.rst} html old epub latex
rm -rf $(RSTDIR)/{Eqs,JPG,*.rst} html epub latex
rm -rf spelling
clean-spelling:
@ -154,27 +152,6 @@ pdf: $(OBJECTS) $(ANCHORCHECK)
@rm -rf latex/USER/*/*.[sg]*
@echo "Build finished. Manual.pdf and Developer.pdf are in this directory."
old: utils/txt2html/txt2html.exe
@rm -rf old
@mkdir old; mkdir old/Eqs; mkdir old/JPG; mkdir old/PDF
@cd src; ../utils/txt2html/txt2html.exe -b *.txt; \
mv *.html ../old; \
cp Eqs/*.jpg ../old/Eqs; \
cp JPG/* ../old/JPG; \
cp PDF/* ../old/PDF;
@( set -e;\
cd src/Developer; \
pdflatex developer; \
pdflatex developer; \
mv developer.pdf ../../old/Developer.pdf; \
cd ../../old; \
for s in `echo ../src/*.txt | sed -e 's,\.\./src/,,g' -e 's/ \(pairs\|bonds\|angles\|dihedrals\|impropers\|commands_list\|fixes\|computes\).txt/ /g' | sed -e 's,\.txt,\.html,g'` ; \
do grep -q ^$$s ../src/lammps.book || \
echo WARNING: doc file $$s missing in src/lammps.book; done; \
htmldoc --batch ../src/lammps.book; \
)
fetch:
@rm -rf html_www Manual_www.pdf Developer_www.pdf
@curl -s -o Manual_www.pdf http://lammps.sandia.gov/doc/Manual.pdf
@ -183,8 +160,6 @@ fetch:
@tar xzf lammps-doc.tar.gz
@rm -f lammps-doc.tar.gz
txt2html: utils/txt2html/txt2html.exe
anchor_check : $(ANCHORCHECK)
@(\
. $(VENV)/bin/activate ;\
@ -194,9 +169,6 @@ anchor_check : $(ANCHORCHECK)
# ------------------------------------------
utils/txt2html/txt2html.exe: utils/txt2html/txt2html.cpp
g++ -O -Wall -o $@ $<
$(RSTDIR)/%.rst : src/%.txt $(TXT2RST)
@(\
mkdir -p $(RSTDIR) ; \

View File

@ -1,237 +0,0 @@
<HTML>
<H3>txt2html - a text to HTML conversion tool
</H3>
<P><B>txt2html</B> is a simple tool for converting text files into HTML files.
Text files can contain simple formatting and mark-up commands that
<B>txt2html</B> converts into HTML.
</P>
<P><B>txt2html</B> was written by <A HREF = "http://www.cs.sandia.gov/~sjplimp">Steve Plimpton</A>. I use it for
<A HREF = "http://www.cs.sandia.gov/~sjplimp/lammps.html">documentation</A> and <A HREF = "http://www.cs.sandia.gov/~sjplimp">WWW pages</A>. Anna Reese added the table
formatting options.
</P>
<P>See the <A HREF = "example.txt">example.txt</A> and <A HREF = "example.html">example.html</A>
files in the <B>txt2html</B> directory for examples of what all the
formatting commands and mark-up syntax end up looking like in HTML.
</P>
<HR>
<P><B>Syntax:</B>
</P>
<DL><DT>txt2html file
<DD> read from text file, write HTML to standard output
<DT>txt2html file1 file2 file3 ...
<DD> read each argument as text file, write one HTML file per argument
</DL>
<P>Input files are first opened with the specified name. If that fails,
a ".txt" suffix is added. Output files are created with an ".html"
suffix, which is either added or replaces the ".txt" suffix.
</P>
<HR>
<P><B>Compiling:</B>
</P>
<P>The source for <B>txt2html</B> is a single C++ file. Compile it by typing:
</P>
<PRE>g++ -o txt2html txt2html.cpp
</PRE>
<HR>
<P><B>How the tool works:</B>
</P>
<P><B>txt2html</B> reads a text file, one <I>paragraph</I> at a time. A paragraph
ends with:
</P>
<UL><LI> a blank line
<LI> a line whose final word starts with ":" (a format string)
<LI> the end of the file
</UL>
<P>Any line in the paragraph which ends with "\" is concatenated to the
following line by removing the "\" character and following newline.
This can be useful for some of the formatting commands described below
that operate on individual lines in the paragraph.
</P>
<P>If a paragraph starts with a "&lt;" character and ends with a "&gt;"
character, it is treated as raw HTML and is written directly into the
output file.
</P>
<P>If a paragraph does not end with a format string, then it is
surrounded with HTML paragraph markers (&lt;P&gt; and &lt;/P&gt;),
<A HREF = "#markup">mark-up</A> is performed, and the paragraph is written to the
output file.
</P>
<P>If the paragraph ends with a format string, then <A HREF = "#format">formatting</A>
is performed, <A HREF = "#markup">mark-up</A> is performed, and the paragraph is
written to the output file.
</P>
<HR>
<A NAME = "format"></A><B>Formatting:</B>
<P>A format string is the last word of a paragraph if it starts with a
":" character. A format string contains one or more comma-separated
commands, like ":ulb,l" or ":c,h3". Note that a format string cannot
contain spaces, else it would not be the last word. An individual
command can have 0 or more arguments:
</P>
<UL><LI> <I>b</I> or <I>line()</I> = 0 arguments
<LI> <I>image(file)</I> = 1 argument
<LI> <I>link(alias,value)</I> = 2 or more comma-separated arguments
</UL>
<P>Format commands add HTML markers at the beginning or end of the
paragraph and individual lines. Commands are processed in the order
they appear in the format string. Thus if two commands add HTML
markers to the beginning of the paragraph, the 2nd command's marker
will appear 2nd. The reverse is true at the end of the paragraph; the
2nd command's marker will appear 1st. Some comands, like <I>line</I> or
<I>image</I> make most sense if used as stand-alone commands without an
accompanying paragraph.
</P>
<P>Commands that format the entire paragraph:
</P>
<UL><LI> p --&gt; surround the paragraph with &lt;P&gt; &lt;/P&gt;
<LI> b --&gt; put &lt;BR&gt; at the end of the paragraph
<LI> pre --&gt; surround the paragraph with &lt;PRE&gt; &lt;/PRE&gt;
<LI> c --&gt; surround the paragraph with &lt;CENTER&gt; &lt;/CENTER&gt;
<LI> h1,h2,h3,h4,h5,h6 --&gt; surround the paragraph with &lt;H1&gt; &lt;/H1&gt;, etc
</UL>
<P>Commands that format the lines of the paragraph as a list:
</P>
<UL><LI> ul --&gt; surround the paragraph with &lt;UL&gt; &lt;/UL&gt;, put &lt;LI&gt; at start of every line
<LI> ol --&gt; surround the paragraph with &lt;OL&gt; &lt;/OL&gt;, put &lt;LI&gt; at start of every line
<LI> dl --&gt; surround the paragraph with &lt;DL&gt; &lt;/DL&gt;, alternate &lt;DT&gt; and &lt;DD&gt; at start of every line
</UL>
<P>Commands that treat the paragraph as one entry in a list:
</P>
<UL><LI> l --&gt; put &lt;LI&gt; at the beginning of the paragraph
<LI> dt --&gt; put &lt;DT&gt; at the beginning of the paragraph
<LI> dd --&gt; put &lt;DD&gt; at the beginning of the paragraph
<LI> ulb --&gt; put &lt;UL&gt; at the beginning of the paragraph
<LI> ule --&gt; put &lt;/UL&gt; at the end of the paragraph
<LI> olb --&gt; put &lt;OL&gt; at the beginning of the paragraph
<LI> ole --&gt; put &lt;/OL&gt; at the end of the paragraph
<LI> dlb --&gt; put &lt;DL&gt; at the beginning of the paragraph
<LI> dle --&gt; put &lt;/DL&gt; at the end of the paragraph
</UL>
<P>Commands applied to each line of the paragraph:
</P>
<UL><LI> all(p) --&gt; surround each line with &lt;P&gt; &lt;/P&gt;
<LI> all(c) --&gt; surround each line with &lt;CENTER&gt; &lt;/CENTER&gt;
<LI> all(b) --&gt; append a &lt;BR&gt; to each line
<LI> all(l) --&gt; prepend a &lt;LI&gt; to each line
</UL>
<P>Special commands (all HTML is inserted at beginning of paragraph):
</P>
<UL><LI> line --&gt; insert a horizontal line = &lt;HR&gt;
<LI> image(file) --&gt; insert an image = &lt;IMG SRC = "file"&gt;
<LI> image(file,link) --&gt; insert an image that when clicked on goes to link
<LI> link(name) --&gt; insert a named link that can be referred to elsewhere (see <A HREF = "#markup">mark-up</A>) = &lt;A NAME = "name"&gt;&lt;/A&gt;
<LI> link(alias,value) --&gt; define a link alias that can be used elsewhere in this file (see <A HREF = "#markup">mark-up</A>)
</UL>
<P>Table command:
</P>
<UL><LI> tb(c=3,b=5,w=100%,a=c) --&gt; format the paragraph as a table
</UL>
<P>Arguments within tb() can appear in any order and are all optional,
since they each have default values.
</P>
<UL><LI> c=N --&gt; Make an N-column table. Treat the paragraph as one
long list of entries (separated by the separator character) and put
them into N columns one after the other. If N = 0, treat each line
of the paragraph as one row of the table with as many columns as
there are maximum entries in any line. Default is c=0.
<LI> s=: --&gt; Use the character string following the equal sign as
the separator between entries. Default separator is a comma "," which
you cannot specify directly since the comma delimits the tb() arguments
<LI> b=N --&gt; Create a border N pixels wide. If N is 0, there is no
border between or outside the cells. If N is 1, there is a minimal
border between and outside all cells. For N > 1, the border between
cells does not change but the outside border gets wider. Default is
b=1.
<LI> w=N or w=N% --&gt The first form makes each cell of the table at
least N pixels wide. The second form makes the entire table take up
N% of the width of the browser window. Default is w=0 which means
each cell will be just as wide as the text it contains.
<LI> a=X --&gt Align the entire table at the left, center, or right of the
browser window, for X = "l", "c", or "r". Default is a=c.
<LI> ea=X --&gt Align the text in each entry at the left, center, or
right of its cell, for X = "l", "c", or "r". Default is browser's
default (typically left).
<LI> eva=X --&gt Vertically align the text in each entry at the
top, middle, baseline, or bottom of its cell, for X = "t", "m", "ba",
or "bo". Default is browser's default (typically middle).
<LI> cwM=N or cwM=N% --&gt The first form makes column M be at least
N pixels wide. The second form makes column M take up N% of the
width of the browser window. This setting overrides the "w"
argument for column M. Only one column per table can be tweaked
with this argument. Default is no settings for any column.
<LI> caM=X --&gt Align the text in each entry of column M at the left,
center, or right of its cell, for X = "l", "c", or "r". This
setting overrides the "ea" argument for column M. Only one column
per table can be tweaked with this argument. Default is no settings
for any column.
<LI> cvaM=X --&gt Vertically align the text in each entry of column m
at the top, middle, baseline, or bottom of its cell, for X = "t",
"m", "ba", or "bo". This setting overrides the "eva" argument for
column M. Only one column per table can be tweaked with this
argument. Default is no settings for any column.
</UL>
<HR>
<A NAME = "markup"></A><B>Mark-up:</B>
<P>The text of the paragraph is scanned for special mark-up characters
which are converted into HTML.
</P>
<P>Bold and italic characters:
</P>
<UL> <LI> "[" (left brace) --&gt; turn-on bold by inserting a &lt;B&gt;
<LI> "]" (right brace) --&gt; turn-off bold by inserting a &lt;/B&gt;
<LI> "{" (left bracket) --&gt; turn-on italics by inserting a &lt;I&gt;
<LI> "}" (right bracket) --&gt; turn-off italics by
inserting a &lt;/I&gt; </UL>
<P>If a backspace '\' precedes any of the bold/italic mark-up characters,
then mark-up is not performed; the mark-up character is simply left in
the text.
</P>
<P>Links are inserted by enclosing a section of text in double quotes,
and appending an underscore to the ending quote, followed by the link.
The link ends when whitespace is found, except that trailing
punctuation characters (comma, period, semi-colon, colon, question
mark, exclamation point, parenthesis) are not considered part of the
link.
</P>
<P> A link of the form "text"_link becomes &lt;A HREF =
"link"&gt;text&lt;/A&gt; in the HTML output. The only exception is if
"link" is defined elsewhere in the file as an alias (see the link
command above). In that case, the value is used instead of the alias
name. </P>
<P>With these rules, links can take several forms.
</P>
<UL> <LI> "This links"_#abc to another part of this file which is
labeled with a :link(abc) command. <BR>
<LI> "This links"_other.html to another file named other.html. <BR>
<LI> "This links"_other.html#abc to another file which has an "abc"
location defined internally. <BR>
<LI> "This links"_http://www.google.com to a WWW site. <BR>
<LI> "This"_M12 could be used in place of any of the above forms. It
requires an alias like :link(M12,http://www.google.com) to be defined
elsewhere in the file. </UL>
</HTML>

Binary file not shown.

View File

@ -1,940 +0,0 @@
// txt2html - written by Steve Plimpton, May 2004
// table formatting by Anna Reese, Jul 2004
// Sandia National Labs, www.cs.sandia.gov/~sjplimp
//
// txt2html converts a text file with simple formatting & markup into HTML
// formatting & markup specification is given in README
//
// Syntax: txt2html options file read one file, write to stdout
// txt2html optoins file1 file2 ... read files, write files.html
//
// options:
// -b = add a page-break comment to end of each HTML file
// useful when set of HTML files will be converted to PDF
// -x file = skip a file even if it appears in file list
// specify full file name of input file
// input files are first opened as-is
// if that fails a .txt suffix is added
// output files have an .html suffix added or replaced
// (unless written to stdout)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define MAXLINE 1024
// function prototypes
static int next_paragraph(FILE *fp, string &paragraph);
static int index_of_first_char_of_last_word(string &paragraph);
static void process_commands(int flag, string &s, string &pre, string &post);
static void substitute(string &s);
static string td_tag(int currentc);
static long find_n(string &s, int nend, int &n1);
static void file_open(int npair, string &infile, FILE **in, FILE **out);
// global variables for links, tables, lists, all command
vector<string> alias1;
vector<string> alias2;
int nlink;
int tableflag; // makes a table if tb command specified
int rowquit; // number of cols per row if c=N specified (default = 0)
string dwidth; // width for all of the columns
string tabledelim; // speciallized separator
string tablealign; // alignment for the table as an image
string dataalign; // alignment for data in table
string rowvalign; // vertical alignment for table
int ncnum; // # of columns with specified width
vector<int> cnum; // column IDs
vector<string> cwidth; // column widths
int ncalign; // # of columns with specified alignment
vector<int> acolnum; // column IDs
vector<string> colalign ; // column alignment
int ncvalign; // # of columns with specified vertical alignment
vector<int> vacolnum; // column IDs
vector<string> colvalign ; // column vertical alignment
string listflag;
string allflag;
// main program
int main(int narg, char **arg)
{
int npair;
size_t n;
string *infile;
FILE *in,*out;
int style,ifirst,ilast;
string raw,pre,post,body,commands,final;
// parse command-line options and args
// setup list of files to process
// npair = # of files to process
// infile = input file names
if (narg == 1) {
fprintf(stderr,"Syntax: txt2html options file\n");
fprintf(stderr," txt2html options file1 file2 ...\n");
exit(1);
}
int breakflag = 0;
int nskip = 0;
char **skipfiles = NULL;
int iarg = 1;
while (arg[iarg][0] == '-') {
if (strcmp(arg[iarg],"-b") == 0) breakflag = 1;
else if (strcmp(arg[iarg],"-x") == 0) {
skipfiles = (char **) realloc(skipfiles,(nskip+1)*sizeof(char *));
n = strlen(arg[iarg+1]) + 1;
skipfiles[nskip] = new char[n];
strcpy(skipfiles[nskip],arg[iarg+1]);
nskip++;
iarg++;
} else {
fprintf(stderr,"Syntax: txt2html options file\n");
fprintf(stderr," txt2html options file1 file2 ...\n");
exit(1);
}
iarg++;
}
if (narg-iarg == 1) {
npair = 1;
infile = new string[npair];
infile[0] = arg[narg-1];
} else {
npair = narg-iarg;
infile = new string[npair];
for (int i = 0; i < npair; i++) infile[i] = arg[i+iarg];
}
// loop over files
for (int ipair = 0; ipair < npair; ipair++) {
// skip file if matches -x switch
int flag = 0;
for (int i = 0; i < nskip; i++)
if (strcmp(infile[ipair].c_str(),skipfiles[i]) == 0) flag = 1;
if (flag) continue;
// clear global variables before processing file
alias1.clear();
alias2.clear();
nlink = 0;
tableflag = 0;
listflag = "";
allflag = "";
// open files & message to screen
file_open(0,infile[ipair],&in,&out);
fprintf(stderr,"Converting %s ...\n",infile[ipair].c_str());
// scan file for link definitions
// read file one paragraph at a time
// process commands, looking only for link definitions
while ((style = next_paragraph(in,raw))) {
if (style == 2) {
int n = index_of_first_char_of_last_word(raw);
commands = raw.substr(n+1);
process_commands(0,commands,pre,post);
}
raw.erase();
}
// close & reopen files
fclose(in);
file_open(npair,infile[ipair],&in,&out);
// write leading <HTML>
fprintf(out,"<HTML>\n");
// process entire file
// read file one paragraph at a time
// delete newlines when line-continuation char at end-of-line
// process commands for each paragraph
// substitute text for each paragraph
// write HTML to output file
int rstflag = 0;
while ((style = next_paragraph(in,raw))) {
if (rstflag && raw.find("END_RST -->") != string::npos) {
rstflag = 0;
raw.erase();
continue;
} else if (rstflag == 0 && raw.find("<!-- RST") != string::npos) {
rstflag = 1;
raw.erase();
continue;
} else if (rstflag) {
raw.erase();
continue;
}
n = raw.find("\\\n");
while (n < string::npos) {
raw.erase(n,2);
n = raw.find("\\\n");
}
ifirst = raw.find_first_not_of(" \t\n");
ilast = raw.find_last_not_of(" \t\n");
pre.erase();
post.erase();
if (raw[ifirst] == '<' && raw[ilast] == '>') {
body = raw;
} else if (style == 1) {
body = raw;
commands = "p\n";
process_commands(1,commands,pre,post);
substitute(body);
} else {
int n = index_of_first_char_of_last_word(raw);
body = raw.substr(0,n) + "\n";
commands = raw.substr(n+1);
process_commands(1,commands,pre,post);
substitute(body);
}
final = pre + body + post;
fprintf(out,"%s\n",final.c_str());
raw.erase();
}
// write trailing </HTML>
if (breakflag) fprintf(out,"<!-- PAGE BREAK -->\n");
fprintf(out,"</HTML>\n");
// close files
fclose(in);
if (out != stdout) fclose(out);
}
// clean up memory
for (int i = 0; i < nskip; i++) delete [] skipfiles[i];
if (skipfiles) free(skipfiles);
delete [] infile;
}
// return next paragraph as string
// discard leading blank lines
// paragraph is terminated by:
// EOF or blank line or line ending with command that starts with ":"
// return 0 if EOF and no paragraph
// return 1 if no trailing command
// return 2 if trailing command
int next_paragraph(FILE *fp, string &paragraph)
{
char *ptr;
char str[MAXLINE];
int first = 1;
int len = 0;
while (1) {
ptr = fgets(str,MAXLINE,fp);
if (ptr == NULL && first) return 0;
if (ptr == NULL) return 1;
len = strlen(str);
if (len == MAXLINE-1) {
fprintf(stderr,"ERROR: File has too-long a string - increase MAXLINE\n");
exit(1);
}
// check for valid 7-bit ascii characters
bool nonascii = false;
for (int i=0; i < len; ++i) {
char c = str[i];
if (c != '\n' && c != '\t' && (c < ' ' || c > '~'))
nonascii = true;
}
if (nonascii)
fprintf(stderr,"WARNING: Non-portable characters in line: %s",ptr);
if (strspn(str," \t\n") == strlen(str) && first) continue;
if (strspn(str," \t\n") == strlen(str)) return 1;
first = 0;
paragraph += str;
if (paragraph[index_of_first_char_of_last_word(paragraph)] == ':')
return 2;
}
}
// return index of first char in last word of paragraph string
int index_of_first_char_of_last_word(string &paragraph)
{
size_t n = paragraph.find_last_not_of(" \t\n");
size_t m = paragraph.find_last_of(" \t\n",n);
if (m == string::npos) return 0;
else return m+1;
}
// apply commands one after the other to the paragraph
void process_commands(int flag, string &s, string &pre, string &post)
{
size_t start,stop,last;
int narg;
string command;
vector<string> arg;
start = 0;
last = s.find_last_not_of(" \t\n");
if (last == string::npos) return;
while (start <= last) {
// grab a single command with optional arguments
// command = name of command
// narg = # of args
// arg = list of argument strings
stop = s.find_first_of(",( \t\n",start);
if (s[stop] == '(') {
command = s.substr(start,stop-start);
start = stop+1;
narg = 0;
while (1) {
stop = s.find_first_of(",)",start);
if (stop == string::npos) {
fprintf(stderr,"ERROR: No trailing parenthesis in %s\n",s.c_str());
exit(1);
}
arg.resize(narg+1);
arg[narg] = s.substr(start,stop-start);
narg++;
start = stop+1;
if (s[stop] == ')') {
start++;
break;
}
}
} else {
command = s.substr(start,stop-start);
start = stop+1;
narg = 0;
}
// if only in scan mode, just operate on link command
if (flag == 0) {
if (command == "link" && narg == 2) {
// s.erase(s.length()-1,1);
for (int i = 0; i < nlink; i++)
if (alias1[i] == arg[0]) {
fprintf(stderr,"ERROR: Link %s appears more than once\n",
arg[0].c_str());
exit(1);
}
alias1.resize(nlink+1);
alias2.resize(nlink+1);
alias1[nlink] = arg[0];
alias2[nlink] = arg[1];
nlink++;
} else continue;
}
// process the command
if (command == "line") {
pre.append("<HR>");
} else if (command == "p") {
pre.append("<P>");
post.insert(0,"</P>");
} else if (command == "pre") {
pre.append("<PRE>");
post.insert(0,"</PRE>");
} else if (command == "c") {
pre.append("<CENTER>");
post.insert(0,"</CENTER>");
} else if (command == "h1") {
pre.append("<H1>");
post.insert(0,"</H1>");
} else if (command == "h2") {
pre.append("<H2>");
post.insert(0,"</H2>");
} else if (command == "h3") {
pre.append("<H3>");
post.insert(0,"</H3>");
} else if (command == "h4") {
pre.append("<H4>");
post.insert(0,"</H4>");
} else if (command == "h5") {
pre.append("<H5>");
post.insert(0,"</H5>");
} else if (command == "h6") {
pre.append("<H6>");
post.insert(0,"</H6>");
} else if (command == "b") {
post.insert(0,"<BR>");
} else if (command == "ulb") {
pre.append("<UL>");
} else if (command == "ule") {
post.insert(0,"</UL>");
} else if (command == "olb") {
pre.append("<OL>");
} else if (command == "ole") {
post.insert(0,"</OL>");
} else if (command == "dlb") {
pre.append("<DL>");
} else if (command == "dle") {
post.insert(0,"</DL>");
} else if (command == "l") {
pre.append("<LI>");
} else if (command == "dt") {
pre.append("<DT>");
} else if (command == "dd") {
pre.append("<DD>");
} else if (command == "ul") {
listflag = command;
pre.append("<UL>");
post.insert(0,"</UL>");
} else if (command == "ol") {
listflag = command;
pre.append("<OL>");
post.insert(0,"</OL>");
} else if (command == "dl") {
listflag = command;
pre.append("<DL>");
post.insert(0,"</DL>");
} else if (command == "link") {
if (narg == 1) {
string aname = "<A NAME = \"" + arg[0] + "\"></A>";
pre.append(aname);
}
} else if (command == "image") {
if (narg == 1) {
string img = "<IMG SRC = \"" + arg[0] + "\">";
pre.append(img);
} else if (narg == 2) {
string img = "<A HREF = \"" + arg[1] + "\">" +
"<IMG SRC = \"" + arg[0] + "\">" + "</A>";
pre.append(img);
}
} else if (command == "tb") { // read the table command and set settings
tableflag = 1;
string tableborder = "1"; // these are the table defaults
rowquit = 0;
tablealign = "c";
dataalign = "0";
rowvalign = "0";
ncnum = 0;
ncalign = 0;
ncvalign = 0;
cnum.clear();
acolnum.clear();
vacolnum.clear();
cwidth.clear();
colalign.clear();
colvalign.clear();
tabledelim = ",";
string tw = "";
dwidth = "0";
for (int i = 0; i < narg; i++) { // loop through each tb() arg
int tbstop;
string tbcommand;
tbstop = 0;
tbstop = arg[i].find("=");
tbcommand = arg[i].substr(0,tbstop);
int n = arg[i].length();
if (tbstop == -1) {
continue;
} else if (tbcommand == "c") {
string collumn= arg[i].substr (tbstop+1,n-(tbstop+1));
rowquit = atoi(collumn.c_str());
} else if (tbcommand == "s") {
tabledelim= arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand == "b") {
tableborder= arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand == "w") {
string width = "0";
if (arg[i].substr (n-1,1) == "%") {
string width = arg[i].substr (tbstop+1,n-(tbstop+1));
tw = " WIDTH=\"" + width + "\"";
} else
dwidth = arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand == "ea") {
dataalign= arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand == "eva") {
rowvalign= arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand == "a") {
tablealign= arg[i].substr (tbstop+1,n-(tbstop+1));
} else if (tbcommand.substr(0,2) == "cw") {
string cwnum= tbcommand.substr(2,tbstop-1);
cnum.resize(ncnum+1);
cnum[ncnum] = atoi(cwnum.c_str());
cwidth.resize(ncnum+1);
cwidth[ncnum]= arg[i].substr(tbstop+1,n-(tbstop+1));
ncnum++;
} else if (tbcommand.substr(0,2) == "ca") {
string canum= tbcommand.substr(2,tbstop-1);
acolnum.resize(ncalign+1);
acolnum[ncalign] = atoi(canum.c_str());
colalign.resize(ncalign+1);
colalign[ncalign]= arg[i].substr(tbstop+1,n-(tbstop+1));
ncalign++;
} else if (tbcommand.substr(0,3) == "cva") {
string cvanum= tbcommand.substr(2,tbstop-1);
vacolnum.resize(ncvalign+1);
vacolnum[ncvalign] = atoi(cvanum.c_str());
colvalign.resize(ncvalign+1);
colvalign[ncvalign]= arg[i].substr(tbstop+1,n-(tbstop+1));
ncvalign++;
} else {
fprintf(stderr,
"ERROR: Unrecognized table command %s\n",tbcommand.c_str());
exit(1);
}
tbstop = s.find("=");
}
string align;
if (tablealign=="c") align="center";
else if (tablealign=="r") align="right ";
else if (tablealign=="l") align="left ";
else align="center";
string tablea = "<DIV ALIGN=" + align + ">" ;
pre.append(tablea);
pre.append("<TABLE ");
pre.append(tw);
string border=" BORDER=" + tableborder + " >\n";
pre.append(border);
post.insert(0,"</TD></TR></TABLE></DIV>\n");
} else if (command == "all") {
if (narg == 1) allflag = arg[0];
} else {
fprintf(stderr,"ERROR: Unrecognized command %s\n",command.c_str());
exit(1);
}
}
}
// perform substitutions within text of paragraph
void substitute(string &s)
{
size_t n,m,p;
char c;
string text,link,href;
string punctuation = ".,?!;:()";
// substitute for bold & italic markers
// if preceded by \ char, then leave markers in text
n = s.find_first_of("[]{}");
while (n != string::npos) {
c = s[n];
if (n > 0 && s[n-1] == '\\') s.erase(n-1,1);
else {
s.erase(n,1);
if (c == '[') s.insert(n,"<B>");
else if (c == ']') s.insert(n,"</B>");
else if (c == '{') s.insert(n,"<I>");
else if (c == '}') s.insert(n,"</I>");
}
n = s.find_first_of("[]{}",n);
}
// substitute for links
n = s.find("\"_");
while (n != string::npos) {
m = s.rfind("\"",n-1);
if (m == string::npos) {
fprintf(stderr,"ERROR: Could not find matching \" for \"_ in %s\n",
s.c_str());
exit(1);
}
p = s.find_first_of(" \t\n",n) - 1;
if (p == string::npos) {
fprintf(stderr,"ERROR: Could not find end-of-link in %s\n",s.c_str());
exit(1);
}
while (s.find_first_of(".,?!;:()",p) == p) p--;
text = s.substr(m+1,n-m-1);
link = s.substr(n+2,p-n-1);
for (int i = 0; i < nlink; i++)
if (alias1[i] == link) {
link = alias2[i];
break;
}
s.erase(m,p-m+1);
href = "<A HREF = \"" + link + "\">" + text + "</A>";
s.insert(m,href);
n = s.find("\"_");
}
// format the paragraph as a table
if (tableflag) {
tableflag = 0;
string DT;
// set up <TR> tag
// alignment for data in rows
string tbalign;
if (dataalign != "0"){
string align;
if (dataalign=="c") align="\"center\"";
else if (dataalign=="r") align="\"right\"";
else if (dataalign=="l") align="\"left\"";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for ea=X\n",
dataalign.c_str());
exit(1);
}
tbalign = " ALIGN=" + align;
} else tbalign="";
// set up vertical alignment for particular columns
string va;
if (rowvalign != "0"){
string valign;
if (rowvalign == "t") valign= "top";
else if (rowvalign == "m") valign= "middle";
else if (rowvalign == "ba") valign= "baseline";
else if (rowvalign == "bo") valign= "bottom";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for eva=X\n",
rowvalign.c_str());
exit(1);
}
va = " VALIGN =\"" + valign + "\"";
} else va="";
//tr_tag is keyword for data in rows
string tr_tag= "<TR" + tbalign + va + ">";
//declare integers to help with counting and finding position
int currentc=0; // current column
int nend = 0;
int n1=0;
long n = find_n(s,nend,n1);
// if there are no separators, go to the end of the string
if (n < 0) n = s.length();
// while n exists:
while (n != static_cast<long>(string::npos)) {
// ignore = 0 when pass by \n because looking for delimiters only
// when ignore==0 do not put in a <tr>
int ignore=1;
// For each loop starts nend at n
nend=n;
// current column is 0, (very first loop), insert first <TR>
if (currentc == 0){
currentc++;
DT=td_tag(currentc);
s.insert(0,tr_tag);
s.insert(tr_tag.length(),DT);
nend=nend+tr_tag.length()+DT.length();
n = find_n(s,nend,n1);
if (n==n1) currentc++;
else {
// currentc will remain one if rowquit==0
if (rowquit>0){
s.erase(n,1);
n = find_n(s,nend,n1);
currentc++;
}
}
} else {
// if n is separator
if (n == n1){
s.erase(n,tabledelim.length());
if(currentc==(rowquit+1)&& rowquit!=0){
s.insert(nend,"</TD></TR>\n");
nend=nend+11;
// set current column back to one to start new line
currentc=1;
}else{
DT= td_tag(currentc);
s.insert (nend,"</TD>");
nend=nend+5;
s.insert (nend,DT);
nend=nend+DT.length();
// add one so current column is updated
currentc++;
n = find_n(s,nend,n1);
}
}
//if n is newline character
else{
s.erase(n,1);
// if columns == 0 means ARE searching for newlines
// else erase and ignore insert <tr> later and
// search for next separator
if (rowquit==0){
s.insert(nend,"</TD></TR>\n");
nend=nend+11;
// set current column back to one to start new line
currentc=1;
}else{
ignore=0;
n = find_n(s,nend,n1);
}
}
// if we are at the beginning of the row then insert <TR>
if (currentc==1&&ignore) {
DT = td_tag(currentc); // find DT for currentc=1
s.insert(nend,tr_tag);
nend=nend+tr_tag.length();
s.insert(nend,DT);
n = find_n(s,nend,n1); // search for next separator
currentc++;
}
} // end to else statement
} // end to while loop
} // end to if tableflag
// if listflag is set, put list marker at beginning of every line
if (listflag != "") {
string marker;
int toggle = 0;
n = s.find('\n');
while (n != string::npos) {
m = s.rfind('\n',n-1);
if (listflag == "dl" && toggle == 0) marker = "<DT>";
else if (listflag == "dl" && toggle == 1) marker = "<DD>";
else marker = "<LI>";
if (m == string::npos) s.insert(0,marker);
else s.insert(m+1,marker);
n = s.find('\n',m+1);
n = s.find('\n',n+1);
if (toggle) toggle = 0;
else toggle = 1;
}
listflag = "";
}
// if allflag is set, add markers to every line
if (allflag != "") {
string marker1,marker2;
if (allflag == "p") {
marker1 = "<P>";
marker2 = "</P>";
} else if (allflag == "c") {
marker1 = "<CENTER>";
marker2 = "</CENTER>";
} else if (allflag == "b") {
marker1 = "";
marker2 = "<BR>";
} else if (allflag == "l") {
marker1 = "<LI>";
marker2 = "";
} else marker1 = marker2 = "";
n = s.find('\n');
while (n != string::npos) {
m = s.rfind('\n',n-1);
if (m == string::npos) s.insert(0,marker1);
else s.insert(m+1,marker1);
n = s.find('\n',m+1);
s.insert(n,marker2);
n = s.find('\n',n);
n = s.find('\n',n+1);
}
allflag = "";
}
}
// open input file as-is or as file.txt
// if npair = 0, don't open output file (is just initial pass thru input)
// if npair = 1, open output file as stdout
// if npair > 1, open output file with .html suffix
// either replace .txt in input file, or append .html
void file_open(int npair, string &infile, FILE **in, FILE **out)
{
*in = fopen(infile.c_str(),"r");
if (*in == NULL) {
string root = infile;
infile = infile + ".txt";
*in = fopen(infile.c_str(),"r");
if (*in == NULL) {
fprintf(stderr,"ERROR: Could not open %s or %s\n",
root.c_str(),infile.c_str());
exit(1);
}
}
if (npair == 0) return;
else if (npair == 1) *out = stdout;
else {
string outfile;
size_t pos = infile.rfind(".txt");
if (pos == infile.length()-4) outfile = infile.substr(0,pos) + ".html";
else outfile = infile + ".html";
*out = fopen(outfile.c_str(),"w");
if (*out == NULL) {
fprintf(stderr,"ERROR: Could not open %s\n",outfile.c_str());
exit(1);
}
}
}
// for tables:
// build <TD> string (DT) based on current column
string td_tag(int currentc) {
// eacolumn gives the alignment printout of a specific column
string eacolumn;
// va gives vertical alignment to a specific column
string va;
// DT is the complete <td> tag, with width and align
string DT;
// dw is the width for tables. It is also the <dt> tag beginning
string dw;
// set up alignment for particular columns
for (int counter=0; counter < ncalign; counter++){
if (ncalign != 0 && acolnum[counter] == currentc){
string align;
if (colalign[counter] == "l") align= "left";
else if (colalign[counter] == "r") align= "right";
else if (colalign[counter] == "c") align= "center";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for caM=X\n",
colalign[counter].c_str());
exit(1);
}
eacolumn= " ALIGN =\"" + align +"\"";
}else eacolumn= "";
}
// set up vertical alignment for particular columns
for (int counter=0; counter < ncvalign; counter++){
if (ncvalign != 0 && vacolnum[counter] == currentc){
string valign;
if (colvalign[counter] == "t") valign= "top";
else if (colvalign[counter] == "m") valign= "middle";
else if (colvalign[counter] == "ba") valign= "baseline";
else if (colvalign[counter] == "bo") valign= "bottom";
else {
fprintf(stderr,
"ERROR: Unrecognized table alignment argument %s for cvaM=X\n",
colvalign[counter].c_str());
exit(1);
}
va = " VALIGN =\"" + valign + "\"";
} else va = " ";
}
// put in special width if specified
// new code
// if dwidth has not been set, dw is blank
// if dwidth has been set, dw has that... unless
if (dwidth=="0") dw = " ";
else dw =" WIDTH=\""+ dwidth + "\"";
for (int counter = 0; counter < ncnum; counter++){
// if it is the right column, dw = cwidth property
if (cnum[counter] == currentc) dw= " WIDTH=\"" + cwidth[counter] + "\"";
}
// DT is set for all of this particular separator : reset next separator
DT = "<TD" + dw + eacolumn + va + ">";
return DT;
}
// for tables:
// find the next separator starting at nend(the end of the last .insert)
// if there is either a delim or newline
// decide which is first
// set n = to that position
// nsep is position of the next separator. changes in here.
long find_n(string &s, int nend, int &nsep)
// nsep is position of the next separator. changes in here.
{
long n;
nsep = s.find(tabledelim,nend);
long n2 = s.find('\n',nend);
long m = s.length() - 1;
if (nsep >= 0 && n2 >= 0) {
if (nsep <= n2) n = nsep;
else n = n2;
} else {
if (nsep >= 0) n = nsep;
else{
if (n2 < m) n = n2;
else n = string::npos;
}
}
return n;
}