#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pcre.h>
#include "pair.h"
#include "lexer.h"
#include "serializer.h"
#include "translator.h"
Include dependency graph for translator.c:

Go to the source code of this file.
Defines | |
| #define | EVAL(expr, err) if (expr) { errno = err; perror(pcerr); iret = EXIT_FAILURE; goto cleanup; } |
| Evaluates given expression and sets adherent internal failure state; goes to cleanup. | |
| #define | ALLOC(str, vector) EVAL((str = (char *) realloc(str, vector + sizeof('\0'))) == NULL, ENOMEM) |
Sends string to realloc (initialized with NONE ); calls adherent error in case thereof. | |
| #define | STRCAT(stra, strb) ALLOC(stra, strlen(stra) + strlen(strb)); strcat(stra, strb) |
| Concatenates two strings; allocating and setting error states. | |
| #define | STRSUB(stra, strb, offset) ALLOC(stra, offset); sprintf(stra, "%.*s", offset, strb) |
Copies a given string, strb, starting at offset to a new string, stra. | |
| #define | STRCPY(to, from) ALLOC(to, strlen(from)) strcpy(to, from); |
Copy from to to, setting error states. | |
| #define | NONE(a) a = (char *) malloc(0) |
| Prepares string for work, Vollendung. | |
Functions | |
| int | translate (char *pcin, pair_t *ppain) |
| Translates template's source according to {key, value} pairs. | |
| void | translatetoken (char *pc, char **ppc) |
Translates source token according to {key, value} pairs, prompted of lexbuf. | |
Definition in file translator.c.
|
|
Sends string to
Definition at line 20 of file translator.c. |
|
|
Evaluates given expression and sets adherent internal failure state; goes to cleanup.
Definition at line 16 of file translator.c. |
|
|
Prepares string for work, Vollendung.
Definition at line 36 of file translator.c. |
|
|
Concatenates two strings; allocating and setting error states.
Definition at line 24 of file translator.c. |
|
|
Copy
Definition at line 33 of file translator.c. Referenced by translatetoken(). |
|
|
Copies a given string,
Definition at line 29 of file translator.c. |
|
||||||||||||
|
Translates template's source according to {key, value} pairs.
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:

|
||||||||||||
|
Translates source token according to {key, value} pairs, prompted of
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 }
|
1.3.9.1