Exemplo n.º 1
0
void
DoTranslate(
    Element_t	*e,
    char	*transfile,
    FILE	*fp
)
{
    Trans_t	*t, *tn;

    if (!transfile) {
	fprintf(stderr,
		"Translation spec file not specified. Skipping translation.\n");
	return;
    }
    ReadTransSpec(transfile);

    /* Find transpec for each node. */
    DescendTree(e, PrepTranspecs, 0, 0, 0);

    /* Stuff to do at start of processing */
    if ((t = FindTransByName("_Start"))) {
	if (t->starttext) ProcesOutputSpec(t->starttext, 0, fp, 1);
	if (t->startcode) CallInterpreter(t->startcode, 0);
	if (t->replace)   ProcesOutputSpec(t->replace, 0, fp, 1);
	if (t->message)   ProcesOutputSpec(t->message, 0, stderr, 0);
	if (t->endcode)   CallInterpreter(t->endcode, 0);
	if (t->endtext)   ProcesOutputSpec(t->endtext, 0, fp, 1);
    }

    /* Translate topmost/first element.  This is recursive. */
    TransElement(e, fp, NULL);

    /* Stuff to do at end of processing */
    if ((t = FindTransByName("_End"))) {
	if (t->starttext) ProcesOutputSpec(t->starttext, 0, fp, 1);
	if (t->startcode) CallInterpreter(t->startcode, 0);
	if (t->replace)   ProcesOutputSpec(t->replace, 0, fp, 1);
	if (t->message)   ProcesOutputSpec(t->message, 0, stderr, 0);
	if (t->endcode)   CallInterpreter(t->endcode, 0);
	if (t->endtext)   ProcesOutputSpec(t->endtext, 0, fp, 1);
    }

    /* Warn about unprocessed elements in this doc tree, if verbose mode. */
    if (verbose)
	DescendTree(e, WasProcessed, 0, 0, 0);

    /* Clean up. This is not yet complete, which is no big deal (since the
     * program is normally done at this point anyway.  */
    for (t=TrSpecs; t; ) {
	tn = t->next;
	/* free the contents of t here ... */
	(void)free((void* )t);
	t = tn;
    }
    TrSpecs = 0;
}
Exemplo n.º 2
0
/*  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,
    FILE	*fp
)
{
    Descent_t	DS;		/* state passed to recursive routine */

    memset(&DS, 0, sizeof(Descent_t));
    DS.elem = e;
    DS.fp   = fp;

    /* see if we should start at the top of instance tree */
    if (StrEq(av[1], "top")) {
	av++;
	ac--;
	e = DocTree;
    }
    if (ac < 4) {
	fprintf(stderr, "Bad '_find' specification - missing args.\n");
	return;
    }
    /* Find elem whose GI is av[2] */
    if (StrEq(av[1], "gi")) {
	DS.gi     = av[2];
	strcpy(DS.action, av[3]);
	DescendTree(e, tr_find_gi, 0, 0, &DS);
    }
    /* Find elem whose GI is av[2] and whose parent GI is av[3] */
    else if (StrEq(av[1], "gi-parent")) {
	DS.gi     = av[2];
	DS.gi2    = av[3];
	strcpy(DS.action, av[4]);
	DescendTree(e, tr_find_gipar, 0, 0, &DS);
    }
    /* Find elem whose parent GI is av[2] */
    else if (StrEq(av[0], "parent")) {
	DS.gi     = av[2];
	strcpy(DS.action, av[3]);
	DescendTree(e, tr_find_parent, 0, 0, &DS);
    }
    /* Find elem whose attribute av[2] has value av[3] */
    else if (StrEq(av[0], "attr")) {
	DS.gi     = av[2];
	DS.gi2    = av[3];
	strcpy(DS.action, av[4]);
	DescendTree(e, tr_find_attr, 0, 0, &DS);
    }
}