Back to index

radiance  4R0+20100331
Classes | Defines | Typedefs | Functions
trans.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  QLIST
struct  ID
struct  IDLIST
struct  IDMATCH
struct  rule

Defines

#define MAXSTR   128 /* maximum input string length */
#define VOIDID   "void" /* null modifier */
#define doneid(idp)   if ((idp)->name != NULL) freestr((idp)->name)
#define FL(qn)   (1L<<(qn))
#define rulsiz(nq)   (sizeof(RULEHD)+(nq)*sizeof(IDMATCH))
#define idm(rp)   ((IDMATCH *)((rp)+1))

Typedefs

typedef struct rule RULEHD

Functions

char * savestr (char *str)
RULEHDgetmapping (char *file, QLIST *qlp)
int fgetid (ID *idp, char *dls, FILE *fp)
int findid (IDLIST *idl, ID *idp, int insert)
int matchid (ID *it, IDMATCH *im)
void write_quals (QLIST *qlp, IDLIST idl[], FILE *fp)

Class Documentation

struct QLIST

Definition at line 19 of file trans.h.

Class Members
int nquals
char ** qual
struct ID

Definition at line 24 of file trans.h.

Class Members
char * name
int number
struct IDLIST

Definition at line 29 of file trans.h.

Collaboration diagram for IDLIST:
Class Members
ID * id
int nids
struct IDMATCH

Definition at line 34 of file trans.h.

Class Members
int max
int min
char * nam
struct rule

Definition at line 39 of file trans.h.

Collaboration diagram for rule:
Class Members
char * mnam
struct rule * next
long qflg

Define Documentation

#define doneid (   idp)    if ((idp)->name != NULL) freestr((idp)->name)

Definition at line 46 of file trans.h.

#define FL (   qn)    (1L<<(qn))

Definition at line 47 of file trans.h.

#define idm (   rp)    ((IDMATCH *)((rp)+1))

Definition at line 49 of file trans.h.

#define MAXSTR   128 /* maximum input string length */

Definition at line 14 of file trans.h.

#define rulsiz (   nq)    (sizeof(RULEHD)+(nq)*sizeof(IDMATCH))

Definition at line 48 of file trans.h.

#define VOIDID   "void" /* null modifier */

Definition at line 16 of file trans.h.


Typedef Documentation

typedef struct rule RULEHD

Function Documentation

int fgetid ( ID idp,
char *  dls,
FILE *  fp 
)
int findid ( IDLIST idl,
ID idp,
int  insert 
)
RULEHD* getmapping ( char *  file,
QLIST qlp 
)

Definition at line 188 of file trans.c.

{
       char   *err;
       register int  c;
       RULEHD *mp = NULL;
       int    nrules = 0;
       register RULEHD      *rp;
       register int  qt;
       char   buf[MAXSTR];
       FILE   *fp;
       
       if ((fp = fopen(file, "r")) == NULL) {
              eputs(file);
              eputs(": cannot open\n");
              quit(1);
       }
                                                 /* get each rule */
       while (fscanf(fp, " %[^     ;\n]", buf) == 1) {
              if (buf[0] == '#') {               /* comment */
                     while ((c = getc(fp)) != EOF && c != '\n')
                            ;
                     continue;
              }
              rp = (RULEHD *)calloc(1, rulsiz(qlp->nquals));
              if (rp == NULL)
                     goto memerr;
              rp->mnam = savestr(buf);
              for ( ; ; ) {                      /* get conditions */
                     while ((c = getc(fp)) != '(')
                            if (c == ';' || c == EOF)
                                   goto endloop;
                     if (fscanf(fp, " %s ", buf) != 1) {
                            err = "missing variable";
                            goto fmterr;
                     }
                     if ((qt = qtype(buf, qlp)) == -1) {
                            err = "unknown variable";
                            goto fmterr;
                     }
                     if (rp->qflg & FL(qt)) {
                            err = "variable repeated";
                            goto fmterr;
                     }
                     rp->qflg |= FL(qt);
                     c = getc(fp);
                     switch (c) {
                     case '"':                   /* id name */
                            if (fscanf(fp, "%[^\"]\" )", buf) != 1) {
                                   err = "bad string value";
                                   goto fmterr;
                            }
                            idm(rp)[qt].nam = savestr(buf);
                            break;
                     case '[':                   /* id range */
                            if (fscanf(fp, "%d : %d ] )", &idm(rp)[qt].min,
                                          &idm(rp)[qt].max) != 2) {
                                   err = "bad range value";
                                   goto fmterr;
                            }
                            if (idm(rp)[qt].min > idm(rp)[qt].max) {
                                   err = "reverse range value";
                                   goto fmterr;
                            }
                            break;
                     default:                    /* id number? */
                            if ((c < '0' || c > '9') && c != '-') {
                                   err = "unrecognizable value";
                                   goto fmterr;
                            }
                            ungetc(c, fp);
                            if (fscanf(fp, "%d )", &idm(rp)[qt].min) != 1) {
                                   err = "bad number id";
                                   goto fmterr;
                            }
                            idm(rp)[qt].max = idm(rp)[qt].min;
                            break;
                     }
              }
       endloop:
              rp->next = mp;
              mp = rp;
              nrules++;
       }
       fclose(fp);
       return(mp);
fmterr:
       sprintf(buf, "%s: %s for rule %d\n", file, err, nrules+1);
       eputs(buf);
       quit(1);
memerr:
       eputs("Out of memory in getmapping\n");
       quit(1);
       return NULL; /* pro forma return */
}

Here is the call graph for this function:

Here is the caller graph for this function:

int matchid ( ID it,
IDMATCH im 
)
char* savestr ( char *  str)

Definition at line 51 of file savestr.c.

{
       register int  hval;
       register S_HEAD  *sp;

       if (str == NULL)
              return(NULL);
       hval = hash(str);
       for (sp = stab[hval]; sp != NULL; sp = sp->next)
              if (!strcmp(str, string(sp))) {
                     sp->nl++;
                     return(string(sp));
              }
       if ((sp = salloc(str)) == NULL) {
              eputs("Out of memory in savestr\n");
              quit(1);
       }
       strcpy(string(sp), str);
       sp->nl = 1;
       sp->next = stab[hval];
       stab[hval] = sp;
       return(string(sp));
}

Here is the call graph for this function:

void write_quals ( QLIST qlp,
IDLIST  idl[],
FILE *  fp 
)

Definition at line 141 of file trans.c.

{
       int    i;
       
       for (i = 0; i < qlp->nquals; i++)
              if (idl[i].nids > 0) {
                     fprintf(fp, "qualifier %s begin\n", qlp->qual[i]);
                     fputidlist(&idl[i], fp);
                     fprintf(fp, "end\n");
              }
}

Here is the call graph for this function:

Here is the caller graph for this function: