tranvar.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.
*/
/* ________________________________________________________________________
*
* instant - a program to manipulate SGML instances.
*
* This module is for handling "special variables". These act a lot like
* procedure calls
* ________________________________________________________________________
*/
#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 <tptregexp.h>
#include "general.h"
#include "translate.h"
static char **idrefs; /* list of IDREF att names to follow */
static char *each_A = 0; /* last seen _eachatt */
static char *each_C = 0; /* last seen _eachcon */
/* forward references */
void GetIDREFnames();
/* ______________________________________________________________________ */
/* Handle "special" variable - read file, run command, do action, etc.
* Arguments:
* Name of special variable to expand.
* Pointer to element under consideration.
* FILE pointer to where to write output.
* Flag saying whether to track the character position we're on
* (passed to OutputString).
*/
void
char *name,
Element_t *e,
int track_pos
)
{
char **tok;
/* Run a command.
* Format: _! command args ... */
if (*name == '!') {
name++;
}
else {
}
return;
}
/* See if caller wants one of the tokens from _eachatt or _eachcon.
* If so, output it and return. (Yes, I admit that this is a hack.)
*/
return;
}
return;
}
ntok = 0;
/* Include another file.
* Format: _include filename */
if (ntok > 1 ) {
return;
}
}
return;
}
/* Print location (nearest title, line no, path).
* Format: _location */
PrintLocation(e, fp);
}
/* Print path to this element.
* Format: _path */
(void)FindElementPath(e, buf);
}
/* Print name of this element (gi).
* Format: _gi [M|L|U] */
if (ntok >= 2) {
}
}
}
/* Print filename of this element's associated external entity.
* Format: _filename */
if ( ntok >= 2 ) {
PrintLocation(e, stderr);
return;
}
} else {
if (!e->entity) {
PrintLocation(e, stderr);
return;
}
fprintf(stderr, "Expected filename (element %s) - no ->entity->fname (internal error? bug?):\n", e->gi);
PrintLocation(e, stderr);
return;
}
}
}
/* Value of parent's attribute, by attr name.
* Format: _pattr attname */
if (!ep) {
return;
}
}
}
/* Use an action, given transpec's SID.
* Format: _action action */
}
/* Number of child elements of this element.
* Format: _nchild */
if (ntok > 1) {
for (n=0,i=0; i<e->necont; i++)
}
else n = e->necont;
}
/* number of 1st child's child elements (grandchildren from first child).
* Format: _n1gchild */
if (e->necont) {
}
}
/* Chase this element's pointers until we hit the named GI.
* Do the action if it matches.
* Format: _chasetogi gi action */
if (ntok < 3) {
return;
}
}
/* Follow link to element pointed to, then do action.
* Format: _followlink [attname] action. */
char **s;
if (ntok > 2) {
return;
}
}
return;
}
for (s=idrefs; *s; s++) {
/* is this IDREF attr set? */
if ((atval = FindAttValByName(e, *s))) {
ntok = 0;
/* we'll follow the first one... */
return;
}
tok[0]);
}
}
PrintLocation(e, stderr);
return;
}
/* Starting at this element, decend tree (in-order), finding GI.
* Do the action if it matches.
* Format: _find args ... */
}
/* Starting at this element's parent, decend tree (in-order), finding GI.
* Do the action if it matches.
* Format: _pfind args ... */
}
/* Content is supposed to be a list of IDREFs. Follow each, doing action.
* If 2 actions are specified, use 1st for the 1st ID, 2nd for the rest.
* Format: _namelist action [action2] */
int id;
for (i=0; i<e->ndcont; i++) {
n = 0;
if (fold_case)
}
}
}
}
/* For each word in the element's content, do action.
* Format: _eachcon action [action] */
int id;
for (i=0; i<e->ndcont; i++) {
n = 0;
}
}
}
/* For each word in the given attribute's value, do action.
* Format: _eachatt attname action [action] */
int id;
n = 0;
}
}
}
/* Do action on this element if element has [relationship] with gi.
* Format: _relation relationship gi action [action] */
if (ntok >= 4) {
/* action not done, see if alt action specified */
if (ntok >= 5)
}
}
}
/* Do action on followed element if element has [relationship] with gi.
* Format: _followrel relationship gi action */
if (ntok >= 4)
}
/* Find element with matching ID and do action. If action not specified,
* choose the right one appropriate for its context.
* Format: _id id [action] */
else {
}
}
}
/* Set variable to value.
* Format: _set name value */
}
/* Do action if variable is set, optionally to value.
* If not set, do nothing.
* Format: _isset varname [value] action
* Format: _issete varname [value] action -- expands value */
else
if (ntok > 3) {
} else
}
}
}
* Format: _insertnode S|E action */
}
/* Do an CALS DTD table spec for TeX or troff. Looks through attributes
* and determines what to output. "check" means to check consistency,
* and print error messages.
* This is (hopefully) the only hard-coded part of instant.
*
* This was originally written for the OSF DTDs and recoded by FLD for
* CALS tables (since no one will ever use the OSF tables). Although
* TeX was addressed first, it seems that a fresh approach was required,
* and so, tbl is the first to be really *fixed*. Once tbl is stable,
* and there is a need for TeX again, that part will be recoded.
*
* *Obsolete* form (viz, for TeX):
* Format: _calstable [clear|check|tex]
* [cellstart|cellend|rowstart|rowend|top|bottom]
*
* New, good form:
*
* Format: _calstable [tbl]
* [tablestart|tableend|tablegroup|tablefoot|rowstart|
* rowend|entrystart|entryend]
*/
}
/* Do action if element's attr is set, optionally to value.
* If not set, do nothing.
* Format: _attval att [value] action */
}
}
/* Same thing, but look at parent */
if (ntok == 3) {
}
}
}
/* Print each attribute and value for the current element, hopefully
* in a legal sgml form: <elem-name att1="value1" att2="value2:> .
* Format: _allatts */
for (i=0; i<e->natts; i++) {
}
}
/* Print the element's input filename, and optionally, the line number.
* Format: _infile [line] */
if (e->infile) {
}
else {
}
return;
}
}
/* Get value of an environement variable */
}
}
/* Something unknown */
else {
}
return;
}
/* ______________________________________________________________________ */
/* return the value for the special variables _A (last processed _eachatt)
* and _C (last processed _eachcon)
*/
char *
Get_A_C_value(char * name)
{
if ( each_A ) {
return each_A;
} else {
}
} else
if ( each_C ) {
return each_C;
} else {
}
} else {
name);
}
return "";
}
/* ______________________________________________________________________ */
/* Chase IDs until we find an element whose GI matches. We also check
* child element names, not just the names of elements directly pointed
* at (by IDREF attributes).
*/
void
{
char *cp;
if (!idrefs) {
/* did user or transpec set the variable */
else
idrefs = def_idrefs;
}
}
/* ______________________________________________________________________ */
/* Chase ID references - follow IDREF(s) attributes until we find
* a GI named 'gi', then perform given action on that GI.
* Arguments:
* Pointer to element under consideration.
* Name of GI we're looking for.
* Spec ID of action to take.
* FILE pointer to where to write output.
*/
void
Element_t *e,
char *gi,
char * action,
)
{
/* First, see if we got what we came for with this element */
return;
}
/* loop for each attribute of type IDREF(s) */
for (s=idrefs; *s; s++) {
/* is this IDREF attr set? */
if ((atval = FindAttValByName(e, *s))) {
ntok = 0;
for (i=0; i<ntok; i++) {
/* get element pointed to */
if ((e = FindElemByID(tok[i]))) {
/* OK, we found a matching GI name */
/* process using named action */
return;
}
else {
/* this elem itself did not match, try its children */
return;
}
}
/* try this elem's IDREF attributes */
return;
}
}
else {
}
}
}
}
/* if the pointers didn't lead to the GI, give error */
if (!s)
}
/* ______________________________________________________________________ */
/* state to pass to recursive routines - so we don't have to use
* global variables. */
typedef struct {
char *gi;
char *gi2;
char action[10];
} Descent_t;
static void
Element_t *e,
)
{
}
static void
Element_t *e,
)
{
}
static void
Element_t *e,
)
{
char *atval;
}
static void
Element_t *e,
)
{
}
}
/* ______________________________________________________________________ */
/* Descend tree, finding elements that match criteria, then perform
* given action.
* Arguments:
* Pointer to element under consideration.
* Number of tokens in special variable.
* Vector of tokens in special variable (eg, "find" "gi" "TITLE")
* FILE pointer to where to write output.
*/
void
Find(
Element_t *e,
int ac,
char **av,
)
{
/* see if we should start at the top of instance tree */
av++;
ac--;
e = DocTree;
}
if (ac < 4) {
return;
}
/* Find elem whose GI is av[2] */
}
/* Find elem whose GI is av[2] and whose parent GI is av[3] */
}
/* Find elem whose parent GI is av[2] */
}
/* Find elem whose attribute av[2] has value av[3] */
}
}
/* ______________________________________________________________________ */