Back to index

radiance  4R0+20100331
Defines | Functions | Variables
mfio.c File Reference
#include "meta.h"

Go to the source code of this file.

Defines

#define INTARG(n)   (((unsigned)inbuf[n] << 7) | (unsigned)inbuf[n+1])
#define HI7(i)   ((i >> 7) & 0177)
#define LO7(i)   (i & 0177)

Functions

int readp (PRIMITIVE *p, FILE *fp)
void writep (register PRIMITIVE *p, FILE *fp)
void writeof (FILE *fp)

Variables

static const char RCSid [] = "$Id: mfio.c,v 1.2 2003/11/15 02:13:37 schorsch Exp $"
static PRIMITIVE peof = {PEOF, 0200, {-1, -1, -1, -1}, NULL, NULL}

Define Documentation

#define HI7 (   i)    ((i >> 7) & 0177)

Definition at line 89 of file mfio.c.

#define INTARG (   n)    (((unsigned)inbuf[n] << 7) | (unsigned)inbuf[n+1])

Definition at line 15 of file mfio.c.

#define LO7 (   i)    (i & 0177)

Definition at line 91 of file mfio.c.


Function Documentation

int readp ( PRIMITIVE *  p,
FILE *  fp 
)

Definition at line 19 of file mfio.c.

{
 char  inbuf[MAXARGS];
 register int  c, nargs;

 if (fp == NULL) fp = stdin;

 if ((c = getc(fp)) == EOF) {             /* used to be fatal */
    mcopy((char *)p, (char *)&peof, sizeof(PRIMITIVE));
    return(0);
 }
 if (!(c & 0200))
    error(USER, "readp not started on command");

 p->com = c & 0177;
 if (!iscom(p->com))
    error(USER, "bad command in readp");

 for (nargs = 0; (c = getc(fp)) != EOF && !(c & 0200) &&
               nargs < MAXARGS-1; nargs++)
    inbuf[nargs] = c;

 if (c & 0200)
    ungetc(c, fp);
 else if (nargs >= MAXARGS-1)
    error(USER, "command w/ too many arguments in readp");

 c = 0;

 if (nargs)  {
    p->arg0 = inbuf[c++];
    nargs--;
    }
 else
    p->arg0 = 0200;

 if (isprim(p->com))  {
    if (nargs < 8)
       error(USER, "missing extent in readp");
    p->xy[XMN] = INTARG(c); c += 2;
    p->xy[YMN] = INTARG(c); c += 2;
    p->xy[XMX] = INTARG(c); c += 2;
    p->xy[YMX] = INTARG(c); c += 2;
    nargs -= 8;
    }
 else
    p->xy[XMN] = p->xy[YMN] = p->xy[XMX] = p->xy[YMX] = -1;

 if (nargs)  {
    inbuf[c+nargs] = '\0';
    p->args = savestr(inbuf+c);
    }
 else
    p->args = NULL;

 return(p->com != PEOF);
 }

Here is the call graph for this function:

void writeof ( FILE *  fp)

Definition at line 132 of file mfio.c.

{
 writep(&peof, fp);
}
void writep ( register PRIMITIVE *  p,
FILE *  fp 
)

Definition at line 95 of file mfio.c.

{
 if (fp == NULL) fp = stdout;

 if (!iscom(p->com))
    error(USER, "bad command in writep");

 putc(p->com | 0200, fp);

 if (isprim(p->com))  {
    putc(p->arg0 & 0177, fp);
    putc(HI7(p->xy[XMN]), fp); putc(LO7(p->xy[XMN]), fp);
    putc(HI7(p->xy[YMN]), fp); putc(LO7(p->xy[YMN]), fp);
    putc(HI7(p->xy[XMX]), fp); putc(LO7(p->xy[XMX]), fp);
    putc(HI7(p->xy[YMX]), fp); putc(LO7(p->xy[YMX]), fp);
    }
 else if (!(p->arg0 & 0200))
    putc(p->arg0, fp);

 if (p->args != NULL)
    fputs(p->args, fp);

 if (p->com == PDRAW || p->com == PEOF)
    if (fflush(fp) == -1)
       error(SYSTEM, "error detected writing file in writep");

 }

Here is the call graph for this function:


Variable Documentation

PRIMITIVE peof = {PEOF, 0200, {-1, -1, -1, -1}, NULL, NULL} [static]

Definition at line 11 of file mfio.c.

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

Definition at line 2 of file mfio.c.