Back to index

radiance  4R0+20100331
Classes | Defines | Functions | Variables
segment.c File Reference
#include <string.h>
#include "rtio.h"
#include "meta.h"

Go to the source code of this file.

Classes

struct  declaration

Defines

#define NODEC   0 /* null declaration (must be 0) */
#define MAXDEC   2048 /* maximum number of declarations */
#define NHASH   101 /* hash size (prime) */

Functions

static int hash (register char *s)
static int lookup (register char *name)
int inseg (void)
void openseg (char *name)
void segprim (register PRIMITIVE *p)
void closeseg (void)
void segment (PRIMITIVE *p, void(*funcp)(PRIMITIVE *p))
int xlate (short extrema, PRIMITIVE *p, register PRIMITIVE *px)

Variables

static const char RCSid [] = "$Id: segment.c,v 1.2 2003/11/15 02:13:37 schorsch Exp $"
static struct declaration dectabl [MAXDEC]
static int hashtabl [NHASH]
static int dectop = 0
static int curdec = NODEC

Class Documentation

struct declaration

Definition at line 23 of file segment.c.

Class Members
int context
int nexthash
char * sname
PLIST sprims

Define Documentation

#define MAXDEC   2048 /* maximum number of declarations */

Definition at line 18 of file segment.c.

#define NHASH   101 /* hash size (prime) */

Definition at line 20 of file segment.c.

#define NODEC   0 /* null declaration (must be 0) */

Definition at line 16 of file segment.c.


Function Documentation

void closeseg ( void  )

Definition at line 153 of file segment.c.

{
    register int  i;
    
    if (!inseg())
        error(SYSTEM, "illegal call to closeseg");
        
                            /* undefine internal declarations */
    for (i = dectop; i > curdec; i--) {
       hashtabl[hash(dectabl[i].sname)] = dectabl[i].nexthash;
       freestr(dectabl[i].sname);
       plfree(&dectabl[i].sprims);
    }
    dectop = curdec;
                            /* define this declaration */
    i = hash(dectabl[curdec].sname);
    dectabl[curdec].nexthash = hashtabl[i];
    hashtabl[i] = curdec;
                            /* return context */
    curdec = dectabl[curdec].context;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int hash ( register char *  s) [static]

Definition at line 43 of file segment.c.

{
    register int     hval = 0;

    while (*s)
       hval += *s++;

    return(hval % NHASH);
}

Here is the caller graph for this function:

int inseg ( void  )

Definition at line 81 of file segment.c.

{

    return(curdec != NODEC);
}

Here is the caller graph for this function:

static int lookup ( register char *  name) [static]

Definition at line 61 of file segment.c.

{
    register int     curd;

    if (name == NULL)
       error(USER, "illegal null segment name in lookup");

    for (curd = hashtabl[hash(name)]; curd != NODEC; curd = dectabl[curd].nexthash)
       if (strcmp(name, dectabl[curd].sname) == 0)
           break;

    return(curd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void openseg ( char *  name)

Definition at line 91 of file segment.c.

{
    register int  olddec;

    if ((olddec = lookup(name)) != NODEC &&
              dectabl[olddec].context == curdec) /* redefined segment */
        plfree(&dectabl[olddec].sprims);

    if (++dectop >= MAXDEC)
       error(SYSTEM, "too many segments in openseg");

    dectabl[dectop].sname = savestr(name);
                            /* save previous context */
    dectabl[dectop].context = curdec;
    curdec = dectop;
    
}

Here is the call graph for this function:

Here is the caller graph for this function:

void segment ( PRIMITIVE *  p,
void(*)(PRIMITIVE *p)  funcp 
)

Definition at line 179 of file segment.c.

{
    int              decln;
    PRIMITIVE curp;
    register PRIMITIVE      *sp;

    if ((decln = lookup(p->args)) == NODEC)  {
       sprintf(errmsg, "reference to undefined segment \"%s\" in segment",
                                          p->args);
       error(USER, errmsg);
    }

    for (sp = dectabl[decln].sprims.ptop; sp != NULL; sp = sp->pnext)

       if (isglob(sp->com))

           (*funcp)(sp);

       else {

           switch (curp.com = sp->com) {

              case PSEG:
              case PVSTR:
              case PTFILL:
              case PPFILL:
                  curp.arg0 = (sp->arg0 & 0100) |
                            (((sp->arg0 & 060) + p->arg0) & 060);
                  break;

              case PLSEG:
                  if (p->arg0 & 020)
                     curp.arg0 = (~sp->arg0 & 0100) | (sp->arg0 & 060);
                  else
                     curp.arg0 = sp->arg0 & 0160;
                  break;

              default:
                  curp.arg0 = sp->arg0 & 0160;
                  break;
           }
           if (p->arg0 & 014)
              curp.arg0 |= p->arg0 & 014;
           else
              curp.arg0 |= sp->arg0 & 014;
           if (p->arg0 & 03)
              curp.arg0 |= p->arg0 & 03;
           else
              curp.arg0 |= sp->arg0 & 03;

           curp.xy[XMN] = xlate(XMN, sp, p);
           curp.xy[YMN] = xlate(YMN, sp, p);
           curp.xy[XMX] = xlate(XMX, sp, p);
           curp.xy[YMX] = xlate(YMX, sp, p);
           curp.args = sp->args;

            (*funcp)(&curp);
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

void segprim ( register PRIMITIVE *  p)

Definition at line 116 of file segment.c.

{
    register PRIMITIVE  *newp;

    if (!inseg())
        error(SYSTEM, "illegal call to segprim");

    switch (p->com) {

       case POPEN:
           openseg(p->args);
           break;
           
       case PSEG:
           segment(p, segprim);
           break;

       case PCLOSE:
           closeseg();
           break;

       default:
           if ((newp = palloc()) == NULL)
              error(SYSTEM, "memory limit exceeded in segprim");
           mcopy((char *)newp, (char *)p, sizeof(PRIMITIVE));
           newp->args = savestr(p->args);
           add(newp, &dectabl[curdec].sprims);
           break;
    }

}

Here is the call graph for this function:

int xlate ( short  extrema,
PRIMITIVE *  p,
register PRIMITIVE *  px 
)

Definition at line 249 of file segment.c.

{
    short     oldex;
    int              val;

    if (((oldex = (extrema + 4 - ((px->arg0 >> 4) & 03))%4) ^ extrema) & 02)
       val = (XYSIZE-1) - p->xy[oldex];
    else
       val = p->xy[oldex];
    
    if (extrema & 01)
       return(CONV(val, px->xy[YMX] - px->xy[YMN]) + px->xy[YMN]);
    else
       return(CONV(val, px->xy[XMX] - px->xy[XMN]) + px->xy[XMN]);
}

Variable Documentation

int curdec = NODEC [static]

Definition at line 34 of file segment.c.

struct declaration dectabl[MAXDEC] [static]
int dectop = 0 [static]

Definition at line 32 of file segment.c.

int hashtabl[NHASH] [static]

Definition at line 30 of file segment.c.

const char RCSid[] = "$Id: segment.c,v 1.2 2003/11/15 02:13:37 schorsch Exp $" [static]

Definition at line 2 of file segment.c.