Back to index

radiance  4R0+20100331
Functions | Variables
portio.c File Reference
#include "copyright.h"
#include "rtio.h"
#include <math.h>

Go to the source code of this file.

Functions

void putstr (char *s, FILE *fp)
void putint (long i, int siz, FILE *fp)
void putflt (double f, FILE *fp)
char * getstr (char *s, FILE *fp)
long getint (int siz, FILE *fp)
double getflt (FILE *fp)

Variables

static const char RCSid [] = "$Id: portio.c,v 2.14 2006/12/23 17:27:45 greg Exp $"

Function Documentation

double getflt ( FILE *  fp)

Definition at line 106 of file portio.c.

{
       long   l;
       double d;

       l = getint(4, fp);
       if (l == 0) {
              getc(fp);            /* exactly zero -- ignore exponent */
              return(0.0);
       }
       d = (l + (l > 0 ? .5 : -.5)) * (1./0x7fffffff);
       return(ldexp(d, (int)getint(1, fp)));
}
long getint ( int  siz,
FILE *  fp 
)

Definition at line 85 of file portio.c.

{
       register int  c;
       register long  r;

       if ((c = getc(fp)) == EOF)
              return(EOF);
       r = 0x80&c ? -1<<8|c : c;          /* sign extend */
       while (--siz > 0) {
              if ((c = getc(fp)) == EOF)
                     return(EOF);
              r <<= 8;
              r |= c;
       }
       return(r);
}
char* getstr ( char *  s,
FILE *  fp 
)

Definition at line 68 of file portio.c.

{
       register char  *cp;
       register int  c;

       cp = s;
       while ((c = getc(fp)) != EOF)
              if ((*cp++ = c) == '\0')
                     return(s);
              
       return(NULL);
}
void putflt ( double  f,
FILE *  fp 
)

Definition at line 47 of file portio.c.

{
       long  m;
       int  e;

       m = frexp(f, &e) * 0x7fffffff;
       if (e > 127) {                     /* overflow */
              m = m > 0 ? (long)0x7fffffff : -(long)0x7fffffff;
              e = 127;
       } else if (e < -128) {             /* underflow */
              m = 0;
              e = 0;
       }
       putint(m, 4, fp);
       putint((long)e, 1, fp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void putint ( long  i,
int  siz,
FILE *  fp 
)

Definition at line 36 of file portio.c.

{
       while (siz--)
              putc((int)(i>>(siz<<3) & 0xff), fp);
}

Here is the caller graph for this function:

void putstr ( char *  s,
FILE *  fp 
)

Definition at line 25 of file portio.c.

{
       do
              putc(*s, fp);
       while (*s++);
}

Here is the caller graph for this function:


Variable Documentation

const char RCSid[] = "$Id: portio.c,v 2.14 2006/12/23 17:27:45 greg Exp $" [static]

Definition at line 2 of file portio.c.