template.h File Reference

Header for template's abstract data type. More...

#include <errno.h>
#include <regex.h>

Include dependency graph for template.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.

Data Structures

struct  templatenode_t
 Associates a class with its source and adherent hash. More...
struct  template_t
 template root and vector More...

Defines

#define TE_NULL   '\0'

Enumerations

enum  etemplate {
  TE_REGDEF = 0, TE_REGOK = 0, TE_WORDDEF = 0, TE_WORDOK = 0,
  TE_MATCH = 2, TE_INDEX = 1, TE_ERR = EINVAL
}

Functions

int template (template_t *)
 Populates a template_t with classes and sources according to the inc folder's files.
void templatefree (template_t *)
 Destructs template.
char * pcdigest (char *, template_t *)
 Also, mir ja gar nicht bekannt; 'raus.


Detailed Description

Header for template's abstract data type.

Definition in file template.h.


Define Documentation

#define TE_NULL   '\0'
 

null character

Definition at line 10 of file template.h.

Referenced by template().


Enumeration Type Documentation

enum etemplate
 

regular expression constants

Enumeration values:
TE_REGDEF  regex flags
TE_REGOK  regex match
TE_WORDDEF  wordexp flags
TE_WORDOK  wordexp match
TE_MATCH  matching subexpression
TE_INDEX  matching index
TE_ERR  default errno

Definition at line 13 of file template.h.

00013                {
00014   TE_REGDEF = 0,                
00015   TE_REGOK = 0,                 
00016   TE_WORDDEF = 0,               
00017   TE_WORDOK = 0,                
00018   TE_MATCH = 2,                 
00019   TE_INDEX = 1,                 
00020   TE_ERR = EINVAL               
00021 };


Function Documentation

char* pcdigest char *  pctemplate,
template_t pte
 

Also, mir ja gar nicht bekannt; 'raus.

Parameters:
pctemplate digestand
pte digestand's receptacle
Returns:
digestate

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 }

int template template_t pt  ) 
 

Populates a template_t with classes and sources according to the inc folder's files.

Parameters:
pt populand template
Returns:
EXIT_SUCCESS, EXIT_FAILURE.

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:

void templatefree template_t pt  ) 
 

Destructs template.

Parameters:
pt destructand

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 }


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