main.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright 1993 Open Software Foundation, Inc., Cambridge, Massachusetts.
* All rights reserved.
*/
/*
#pragma ident "%Z%%M% %I% %E% SMI"
* Copyright (c) 1994
* Open Software Foundation, Inc.
*
* Permission is hereby granted to use, copy, modify and freely distribute
* the software in this file and its documentation for any purpose without
* fee, provided that the above copyright notice appears in all copies and
* that both the copyright notice and this permission notice appear in
* supporting documentation. Further, provided that the name of Open
* Software Foundation, Inc. ("OSF") not be used in advertising or
* publicity pertaining to distribution of the software without prior
* written permission from OSF. OSF makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*/
/*
* Copyright (c) 1996 X Consortium
* Copyright (c) 1995, 1996 Dalrymple Consulting
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* X CONSORTIUM OR DALRYMPLE CONSULTING BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* Except as contained in this notice, the names of the X Consortium and
* Dalrymple Consulting shall not be used in advertising or otherwise to
* promote the sale, use or other dealings in this Software without prior
* written authorization.
*/
/* ________________________________________________________________________
*
* Program to read an SGML document instance, creating any of several things:
*
* "translated" output for formatting applications (given a trans. spec)
* validation report (given a appropriate trans spec)
* tree of the document's structure
* statistics about the element usage
* summary of the elements used
* context of each element used
* IDs of each element
*
* A C structure is created for each element, which includes:
* name, attributes, parent, children, content
* The tree is descended, and the desired actions performed.
*
* Takes input from James Clark's "sgmls" program (v. 1.1).
* ________________________________________________________________________
*/
#ifndef lint
static char *RCSid =
#endif
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <memory.h>
#include <errno.h>
#include <time.h>
#define STORAGE
#include "general.h"
static int do_DATAhack = 0;
static char *this_prog;
static char *start_id;
static char *last_file;
static int last_lineno;
extern int BOFTTextThresh;
/* forward references */
static void HandleArgs(int, char *[]);
static void Initialize1();
static void Initialize2();
static void ReadInstance(char *);
static void DoHelpMessage();
extern void Browse();
/* external reference to version number */
extern char _HeadVeRsIoN_[];
/* ______________________________________________________________________ */
/* Program entry point. Look at args, read instance, dispatch to the
* correct routines to do the work, and finish.
*/
int
main(
int ac,
char *av[]
)
{
Initialize1(av[0]);
Initialize2();
if (interactive) {
Browse(); /* this will handle interactive commands */
}
else {
/* Perform tasks based on command line flags... */
if (tranfile) {
Element_t *e;
/* If user wants to start at a particular ID, point to that
* element. Else, point to the top of the tree. */
if (start_id) {
if (!(e=FindElemByID(start_id))) {
start_id);
exit(1);
}
}
else e = DocTree;
/* If we're doing validation, make output file pointer null.
* This means that we generate no output, except error messages. */
}
if (do_idlist) PrintIDList();
}
return 0;
}
/* ______________________________________________________________________ */
/* Initialization stuff done before dealing with args.
* Arguments:
* Name of program (string).
*/
static void
char *myname
)
{
extern int gethostname(char *, int); /* not in a system .h file... */
/* set some global variables */
warnings = 1;
fold_case = 1;
/* setup global variable mapping */
/* set some pre-defined variables */
}
/* Initialization stuff done after dealing with args. */
static void
{
/* If user wants to send output to a file, open the file, and set
* the file pointer. Else we send output to standard out. */
if (out_file) {
exit(1);
}
}
}
/* ______________________________________________________________________ */
/* Set a variable. If it is one of the "known" variables, set the
* variable in the C code (this program).
* Arguments:
*/
static void
char *var
)
{
int n;
/* Turn '=' into a space, to isolate the name. Then set variable. */
/* we have "var=value" */
*cp = ' ';
n = 2;
/* see if variable name matches one of our internal ones */
}
else {
var);
}
}
/* ______________________________________________________________________ */
/* Bounce through arguments, setting variables and flags.
* Arguments:
* Argc and Argv, as passed to main().
*/
static void
int ac,
char *av[]
)
{
int c, errflag=0;
extern char *optarg;
extern int optind;
switch (c) {
case 'W': warnings = 0; break;
}
if (errflag) {
exit(1);
}
}
/* input (ESIS) file name */
/* If doing interactive/browsing, we can't take ESIS from stdin. */
if (interactive && !in_file) {
"You must specify ESIS file on cmd line for browser mode.\n");
exit(1);
}
}
/* ______________________________________________________________________ */
*/
static char *help_msg[] = {
"",
" -t file Print translated output using translation spec in <file>",
" -s file <file> contains a list of SDATA entity mappings",
" -c file <file> contains a list of character mappings",
" -v Validate using translation spec specified with -t",
" -i id Consider only subtree starting at element with ID <id>",
" -b Interactive browser",
" -S Print statistics (how often elements occur, etc.)",
" -u Print element usage summary (# of children, depth, etc.)",
" -x Print context of each element",
" -h Print document hierarchy as a tree",
" -o file Write output to <file>. Default is standard output.",
" -l dir Set library directory to <dir>. (or env. variable TPT_LIB)",
" -I List all IDs used in the instance",
" -W Do not print warning messages",
" -H Print this help message",
" -Dvar=val Set variable 'var' to value 'val'",
" file Take input from named file. If not specified, assume stdin.",
" File should be output from the 'sgmls' program (ESIS).",
};
static void
{
char **s = help_msg;
while (*s) puts(*s++);
}
/* ______________________________________________________________________ */
/* Remember an external entity for future reference.
* Arguments:
* Pointer to entity structure to remember.
*/
static void
)
{
if (!Entities) {
}
else {
}
}
/* Find an entity, given its entity name.
* Arguments:
* Name of entity to retrieve.
*/
Entity_t *
char *ename
)
{
Entity_t *n;
return 0;
}
/* Accumulate lines up to the open tag. Attributes, line number,
* entity info, notation info, etc., all come before the open tag.
*/
static Element_t *
)
{
int c;
int i, na;
Mapping_t a[100];
Element_t *e;
char **tok;
static int Index=0;
/* Also, keep a linked list of elements, so we can easily scan through */
last_e = e;
/* in case these are not set for this element in the ESIS */
e->lineno = last_lineno;
na = 0;
while (1) {
switch (c) {
case EOF: /* End of input */
exit(1);
break;
case CMD_OPEN: /* (gi */
if (na > 0) {
na = 0;
}
/* Check if this elem has a notation attr. If yes, and there
is no notation specified, recall the previous one. (feature
of sgmls - it does not repeat notation stuff if we the same
is used twice in a row) */
}
return e;
break;
case CMD_ATT: /* Aname val */
i = 3;
{
na++;
}
else {
}
break;
case CMD_LINE: /* Llineno */
/* These lines come in 2 forms: "L123" and "L123 file.sgml".
* Filename is given only at 1st occurance. Remember it.
*/
cp++;
}
break;
case CMD_DATA: /* -data */
/*return e;*/
exit(1);
break;
case CMD_D_ATT: /* Dename name val */
case CMD_NOTATION: /* Nnname */
case CMD_PI: /* ?pi */
/* This should be reworked soon, as it
forces all PI's before the first GI
to be ignored. -CSS */
break;
case CMD_EXT_ENT: /* Eename typ nname */
i = 3;
break;
case CMD_INT_ENT: /* Iename typ text */
break;
case CMD_SYSID: /* ssysid */
break;
case CMD_PUBID: /* ppubid */
break;
case CMD_FILENAME: /* ffilename */
break;
case CMD_CLOSE: /* )gi */
case CMD_SUBDOC: /* Sename */
case CMD_SUBDOC_S: /* {ename */
case CMD_SUBDOC_E: /* }ename */
case CMD_EXT_REF: /* &name */
case CMD_APPINFO: /* #text */
case CMD_CONFORM: /* C */
default:
exit(1);
break;
}
}
if ( e && e->gi )
else
/* return e;*/
exit(1);
}
/* Read ESIS lines.
*/
static Element_t *
int depth
)
{
char *buf;
Element_t *e;
/* Read input stream - the output of "sgmls", called "ESIS". */
e = AccumElemInfo(fp);
ncont = 0;
while (1) {
contsize += GROWCONTSIZE;
}
switch (c) {
case EOF: /* End of input */
break;
case CMD_DATA: /* -data */
}
ncont++;
break;
case CMD_PI: /* ?pi */
ncont++;
break;
case CMD_CLOSE: /* )gi */
if (ncont) {
}
return e;
break;
case CMD_OPEN: /* (gi */
/*fprintf(stderr, "+++++ OPEN +++\n");*/
/* break;*/
case CMD_ATT: /* Aname val */
case CMD_D_ATT: /* Dename name val */
case CMD_NOTATION: /* Nnname */
case CMD_EXT_ENT: /* Eename typ nname */
case CMD_INT_ENT: /* Iename typ text */
case CMD_SYSID: /* ssysid */
case CMD_PUBID: /* ppubid */
case CMD_FILENAME: /* ffilename */
ncont++;
break;
case CMD_LINE: /* Llineno */
break; /* ignore these here */
case CMD_SUBDOC: /* Sename */
case CMD_SUBDOC_S: /* {ename */
case CMD_SUBDOC_E: /* }ename */
case CMD_EXT_REF: /* &name */
case CMD_APPINFO: /* #text */
case CMD_CONFORM: /* C */
default:
exit(1);
break;
}
}
if( e && e->gi)
else
return NULL;
}
/* ______________________________________________________________________ */
/* Read input stream, creating a tree in memory of the elements and data.
* Arguments:
* Filename where instance's ESIS is.
*/
static void
char *filename
)
{
int i, n;
Element_t *e;
char *idatt;
if (filename) { /* if we specified input file. else stdin */
exit(1);
}
}
/* Traverse tree, filling in econt and figuring out which child
* (ie. what birth order) each element is. */
/* count element children */
for (i=0,n=0; i<e->ncont; i++) if (IsContElem(e,i)) n++;
for (i=0; i<e->ncont; i++)
/* count data children */
for (i=0,n=0; i<e->ncont; i++) if (IsContData(e,i)) n++;
for (i=0; i<e->ncont; i++)
/* where in child order order */
for (i=0; i<e->necont; i++)
/* Does this element have an ID? */
for (i=0; i<e->natts; i++) {
/* remember ID value for quick reference */
break;
}
}
}
return;
}
/* ______________________________________________________________________ */