#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <wordexp.h>
#include <regex.h>
#include "in.h"
#include "template.h"
Include dependency graph for template.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; } |
| Evaulates expressand, setting error state and cleaning up. | |
Functions | |
| int | template (template_t *pt) |
Populates a template_t with classes and sources according to the inc folder's files. | |
| void | templatefree (template_t *pt) |
| Destructs template. | |
| char * | pcdigest (char *pctemplate, template_t *pte) |
| Also, mir ja gar nicht bekannt; 'raus. | |
Definition in file template.c.
|
|
Evaulates expressand, setting error state and cleaning up.
Definition at line 16 of file template.c. |
|
||||||||||||
|
Also, mir ja gar nicht bekannt; 'raus.
Definition at line 84 of file template.c. References template_t::i, and template_t::pten. Referenced by math(), and serialize(). 00085 {
00086 int i;
00087 const int imatch = 0;
00088 for (i = 0; i < pte->i; i++) {
00089 if (strcmp(pctemplate, (pte->pten + i)->pctemplate) == imatch) {
00090 return (pte->pten + i)->pctemplate; /* perma-mem */
00091 }
00092 }
00093 return NULL;
00094 }
|
|
|
Populates a
Definition at line 21 of file template.c. References EVAL, in(), templatenode_t::pcclass, templatenode_t::pcdigest, templatenode_t::pctemplate, TE_ERR, TE_INDEX, TE_MATCH, TE_NULL, TE_REGDEF, TE_REGOK, TE_WORDDEF, and TE_WORDOK. 00022 {
00023 int i, ilen, iret = EXIT_SUCCESS;
00024 templatenode_t *pten;
00025 wordexp_t we;
00026 regex_t re;
00027 regmatch_t arm[TE_MATCH];
00028 char **ppc;
00029 FILE *pf = NULL;
00030 const char *pcglob = "inc/*";
00031 const char *pcerr = "template.c template()";
00032 const char *pcmask = "^.*/([^.]+)\\.?.*$";
00033
00034 EVAL(wordexp(pcglob, &we, TE_WORDDEF) != TE_WORDOK, TE_ERR);
00035 pt->i = we.we_wordc;
00036 EVAL((pt->pten = (templatenode_t *) malloc(pt->i * sizeof(templatenode_t))) == NULL, ENOMEM);
00037 EVAL(regcomp(&re, pcmask, REG_EXTENDED) != TE_REGOK, TE_ERR);
00038
00039 for (i = 0, ppc = we.we_wordv, pten = pt->pten; i < we.we_wordc; i++, ppc++, pten++) {
00040 if (regexec(&re, *ppc, TE_MATCH, arm, TE_REGDEF) == TE_REGOK) {
00041 ilen = arm[TE_INDEX].rm_eo - arm[TE_INDEX].rm_so;
00042
00043 EVAL((pten->pcclass = (char *) malloc(ilen + sizeof(TE_NULL))) == NULL, ENOMEM);
00044 strncpy(pten->pcclass, *ppc + arm[TE_INDEX].rm_so, ilen);
00045 *(pten->pcclass + ilen) = TE_NULL;
00046
00047 EVAL((pten->pctemplate = (char *) malloc(strlen(*ppc) + sizeof(TE_NULL))) == NULL, ENOMEM);
00048 strcpy(pten->pctemplate, *ppc);
00049
00050 EVAL((pf = fopen(*ppc, "r")) == NULL, EIO);
00051 EVAL(in(pf, &(pten->pcdigest)) == EXIT_FAILURE, ENOMEM);
00052 } else {
00053 EVAL(1, EINVAL);
00054 pt->i--;
00055 }
00056 }
00057
00058 cleanup:
00059 wordfree(&we);
00060 regfree(&re);
00061 fclose(pf);
00062 return iret;
00063 }
|
Here is the call graph for this function:

|
|
Destructs template.
Definition at line 67 of file template.c. References template_t::i, templatenode_t::pcclass, templatenode_t::pcdigest, templatenode_t::pctemplate, and template_t::pten. Referenced by parse(). 00068 {
00069 int i;
00070 templatenode_t *pten;
00071 for (i = 0, pten = pt->pten; i < pt->i; i++, pten++) {
00072 free(pten->pcclass);
00073 free(pten->pctemplate);
00074 free(pten->pcdigest);
00075 }
00076 free(pt->pten);
00077 pt->i = 0;
00078 }
|
1.3.9.1