translator.h File Reference

Header for source token substituter. More...

#include "pair.h"

Include dependency graph for translator.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Enumerations

enum  etrans {
  TRSUB = 2, TRCONST = 3, TRVECT = 2, TRCONT = 1,
  TRBEGIN = 0, TREND = 1
}
 PCRE constants for iterative parsing. More...

Functions

void translatetoken (char *, char **)
 Translates source token according to {key, value} pairs, prompted of lexbuf.
int translate (char *, pair_t *)
 Translates template's source according to {key, value} pairs.

Variables

pair_tppa
 {key, value} pairs for lexical call-back


Detailed Description

Header for source token substituter.

Definition in file translator.h.


Enumeration Type Documentation

enum etrans
 

PCRE constants for iterative parsing.

Enumeration values:
TRSUB  subexpressions
TRCONST  PCRE vector constant
TRVECT  vector
TRCONT  content subexpression
TRBEGIN  begin index
TREND  end index

Definition at line 9 of file translator.h.

00009             {
00010   TRSUB = 2,                    
00011   TRCONST = 3,                  
00012   TRVECT = 2,                   
00013   TRCONT = 1,                   
00014   TRBEGIN = 0,                  
00015   TREND = 1                     
00016 };


Function Documentation

int translate char *  pcin,
pair_t ppain
 

Translates template's source according to {key, value} pairs.

Parameters:
pcin untranslate [sic] source
ppain {key, value} pairs
Returns:
state eserialerr.

Definition at line 42 of file translator.c.

References lexbuf(), NONE, ppa, serialize(), and translatetoken().

Referenced by parsetag().

00043 {
00044   int iret = EXIT_SUCCESS;
00045   const char *pcmask = "%%__[[:alnum:]]+?__%%";
00046   char NONE(*pcbuf);
00047   ppa = ppain;
00048 
00049   lexbuf(pcin, pcmask, translatetoken, &pcbuf);
00050   /* Buck stops on FILE *. */
00051   serialize(pcbuf, ppa);
00052 
00053   return iret;
00054 }

Here is the call graph for this function:

void translatetoken char *  pc,
char **  ppc
 

Translates source token according to {key, value} pairs, prompted of lexbuf.

Parameters:
pc lexate text
ppc lexand

Definition at line 59 of file translator.c.

References EVAL, pair_t::i, NONE, ppa, pair_t::ppan, STRCPY, STRSUB, TRBEGIN, TRCONST, TRCONT, TREND, TRSUB, and TRVECT.

Referenced by translate().

00060 {
00061   pcre *pre;
00062   int i, ire, iret, aisub[TRSUB * TRCONST];                     /* iret: macro placeholder */
00063   const char *pcmask = "^%%__([[:alnum:]]+?)__%%$";
00064   const char *pcre;
00065   const char *pcerr = "translator.c translatetoken()";
00066   char NONE(*pctoken);
00067   STRCPY(*ppc, "");         /* Guard against uninitialized garbage in case of unaccounted-for keys. */
00068 
00069   pre = pcre_compile(pcmask, PCRE_CASELESS | PCRE_DOTALL, &pcre, &ire, NULL);
00070   EVAL(pcre_exec(pre, NULL, pc, strlen(pc), 0, 0, aisub, TRSUB * TRCONST) < 0, EINVAL);
00071   STRSUB(pctoken, pc + aisub[TRCONT * TRVECT + TRBEGIN], aisub[TRCONT * TRVECT + TREND] - aisub[TRCONT * TRVECT + TRBEGIN]);
00072   for (i = 0; i < ppa->i; i++) {
00073     if (strcmp((ppa->ppan + i)->pckey, pctoken) == 0) {
00074       STRCPY(*ppc, (ppa->ppan + i)->pcvalue);
00075     }
00076   }
00077 
00078   cleanup:
00079     free(pctoken);
00080 }


Variable Documentation

pair_t* ppa
 

{key, value} pairs for lexical call-back

Definition at line 18 of file translator.h.

Referenced by addpair(), freepair(), math(), serialize(), translate(), and translatetoken().


Generated on Tue Dec 7 06:38:25 2004 for CSCI101:ProjectLatex by  doxygen 1.3.9.1