Alien-Judy
view release on metacpan or search on metacpan
src/judy-1.0.5/tool/jhton.c view on Meta::CPAN
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// _________________
// @(#) $Revision: 4.22 $ $Source: /cvsroot/judy/tool/jhton.c,v $
//
// JUDY HTML MANUAL ENTRY TO NROFF TRANSLATOR.
//
// USAGE: <program> filename.htm[l]
// Writes nroff -man output to stdout.
// Suggestion: Pipe output through rmnl to delete extraneous newlines that
// this program cannot easily avoid.
//
// Compile with -DDEBUG for assertions and other checks.
// If so, run with DUMP set in the env to dump the docnodes tree.
//
// CONCEPT: This program was written out of necessity for the 11.11 OEUR
// release of Judy. Ideally our manual entries would be written in an abstract
// XML format with an XSLT-based means to translate them to any other format,
// such as HTML or nroff. In lieu of that, this program knows how to translate
// a limited subset of HTML, as used in our manual entries, to equivalent
// nroff, as described below preceding EmitNroffHeader().
//
// The translation is still complex enough to merit writing a parser that first
// builds a tree representation of the structured (HTML) document. I would use
// yacc and lex if I knew them...
//
// This program is written for simplicity, cleanliness, and robustness, and not
// necessarily for speed.
//
// FLEXIBILITY: It should be possible to teach this program new HTML tags; see
// data structures below. The program might also be useful for other HTML
// manual entries, so long as they follow the simple conventions used in the
// Judy entries; see the comments before EmitNroffHeader(). You can also
// discover the format by trial and error -- this program issues verbose error
// messages.
//
// CONVENTIONS:
//
// - Global variables start with "g_" except option_*.
// - Global constants start with "gc_".
//
// - Pointer variable names start with one "P" per level of indirection.
//
// - Exception: (char *) and (char[]) types, that is, strings, do not
// necessarily start with "P". A generic char pointer is named "Pch".
// Variables of type (char **) start with a single P.
//
// - Exception: the well known name "char ** argv".
//
// - Pointers to first elements of serial linked lists of structures have names
// ending in "Phead".
//
// - Line lengths are less than 80 columns. Message parameters to Error()
// begin on the same line for easy finding.
//
// - Error messages might exceed one line when emitted, but no effort is made
// to wrap them nicely.
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h> // for varargs.
#include <string.h> // for str*().
#include <errno.h>
#include <ctype.h> // for isspace(), etc.
#include <time.h>
#include <assert.h>
#define ISSPACE(Char) isspace((int) (Char)) // for convenience with lint.
#define ISDIGIT(Char) isdigit((int) (Char))
#define ISUPPER(Char) isupper((int) (Char))
#define PUTS(String) (void) fputs(String, stdout) // for convenience.
#define PUTC(Char) (void) putc((int) (Char), stdout)
#ifndef DEBUG
#define NDEBUG // turn off assertions by default.
#endif
// Shorthand notation to avoid #ifdefs for single-line conditional statement:
//
// Warning: This cannot be used around compiler directives, such as
// "#include", nor in the case where Code contains a comma other than nested
// within parentheses or quotes.
#ifndef DEBUG
#define DBGCODE(Code) // null.
#else
#define DBGCODE(Code) Code
#endif
// ****************************************************************************
// MISCELLANEOUS GLOBAL VALUES:
#define FUNCTION // null; easy to find functions.
#define FALSE 0
#define TRUE 1
#define CHNULL ('\0')
#define PCNULL ((char *) NULL)
typedef int bool_t; // for clarity with Boolean values.
char * gc_usage[] = {
"usage: %s filename.htm[l]",
"",
"Reads restricted (Judy-specific) HTML from filename.htm[l] and emits",
"equivalent nroff -man to stdout.",
PCNULL,
};
char * gc_myname; // how program was invoked.
#define OKEXIT 0
#define NOEXIT 0 // values for Error().
( run in 0.428 second using v1.01-cache-2.11-cpan-13bb782fe5a )