Ejemplo n.º 1
0
void
syntax(			/* report syntax error and quit */
    char  *err
)
{
    int  i;

    if (infile != NULL || lineno != 0) {
	if (infile != NULL) eputs(infile);
	if (lineno != 0) {
	    eputs(infile != NULL ? ", line " : "line ");
	    eputs(long2ascii((long)lineno));
	}
	eputs(":\n");
    }
    eputs(linbuf);
    if (linbuf[strlen(linbuf)-1] != '\n')
	eputs("\n");
    for (i = 0; i < linepos-1; i++)
	eputs(linbuf[i] == '\t' ? "\t" : " ");
    eputs("^ ");
    eputs(err);
    eputs("\n");
    quit(1);
}
Ejemplo n.º 2
0
static void
execute(           /* process a file */
char  *file
)
{
	int  conditional = vardefined("cond");
	long  nrecs = 0;
	long  nout = 0;
	FILE  *fp;
	
	if (file == NULL)
		fp = stdin;
	else if ((fp = fopen(file, "r")) == NULL) {
		eputs(file);
		eputs(": cannot open\n");
		quit(1);
	}
	if (inpfmt != NULL)
		initinp(fp);
	
	while (getinputrec(fp)) {
		varset("recno", '=', (double)++nrecs);
		varset("outno", '=', (double)(nout+1));
		colflg = 0;
		eclock++;
		if (!conditional || varvalue("cond") > 0.0) {
			putout();
			++nout;
		}
	}
	fclose(fp);
}
Ejemplo n.º 3
0
static double			/* evaluate a variable */
dvalue(char  *name, EPNODE	*d)
{
    EPNODE  *ep1, *ep2;
    
    if (d == NULL || d->v.kid->type != SYM) {
	eputs(name);
	eputs(": undefined variable\n");
	quit(1);
    }
    ep1 = d->v.kid->sibling;			/* get expression */
    if (ep1->type == NUM)
	return(ep1->v.num);			/* return if number */
    ep2 = ep1->sibling;				/* check time */
    if (eclock >= MAXCLOCK)
	eclock = 1;				/* wrap clock counter */
    if (ep2->v.tick < MAXCLOCK &&
		(ep2->v.tick == 0) | (ep2->v.tick != eclock)) {
	ep2->v.tick = d->type == ':' ? MAXCLOCK : eclock;
	ep2 = ep2->sibling;
	ep2->v.num = evalue(ep1);		/* needs new value */
    } else
	ep2 = ep2->sibling;			/* else reuse old value */

    return(ep2->v.num);
}
Ejemplo n.º 4
0
Archivo: utils.c Proyecto: atikinn/EOS
int 
strtoull_wrap(const char *num, unsigned long long *res, int base) { 
    char fbuf[256];

    if (num == NULL) {
        sprintf(fbuf, "Parse error: %s\r\n", "passed NULL pointer");
        eputs(STDOUT, fbuf);
        return -3;
    }

    int rv = SUCCESS;

    char *end = NULL;
    *res = strtoull(num, &end, base);

    if (errno) {    /* value out of range: under or over flow */
        sprintf(fbuf, "Parse error: %s\r\n", strerror(errno));
        eputs(STDOUT, fbuf);
        errno = 0;
        rv = -1;
    }

    if (*end) {
        sprintf(fbuf, "Parse error: non-parsing part: %s\r\n", end);
        eputs(STDOUT, fbuf);
        rv = -2;
    }

    return rv;                                         
}  
Ejemplo n.º 5
0
static void
reply_error(			/* what should we do here? */
	char	*routine
)
{
	eputs(routine);
	eputs(": driver reply error\n");
	quit(1);
}
Ejemplo n.º 6
0
extern struct driver *
comm_init(			/* set up and execute driver */
	char	*dname,
	char	*id
)
{
	char	*dvcname;
	int	p1[2], p2[2];
	char	pin[16], pout[16];
						/* find driver program */
	if ((dvcname = getpath(dname, DEVPATH, X_OK)) == NULL) {
		eputs(dname);
		eputs(": not found\n");
		return(NULL);
	}
#ifdef RHAS_FORK_EXEC
						/* open communication pipes */
	if (pipe(p1) == -1 || pipe(p2) == -1)
		goto syserr;
	if ((devchild = fork()) == 0) {	/* fork driver process */
		close(p1[1]);
		close(p2[0]);
		sprintf(pin, "%d", p1[0]);
		sprintf(pout, "%d", p2[1]);
		execl(dvcname, dname, pin, pout, id, NULL);
		perror(dvcname);
		_exit(127);
	}
	if (devchild == -1)
		goto syserr;
	close(p1[0]);
	close(p2[1]);
	/*
	 * Close write stream on exec to avoid multiprocessing deadlock.
	 * No use in read stream without it, so set flag there as well.
	 */
	fcntl(p1[1], F_SETFD, FD_CLOEXEC);
	fcntl(p2[0], F_SETFD, FD_CLOEXEC);
	if ((devout = fdopen(p1[1], "w")) == NULL)
		goto syserr;
	if ((devin = fdopen(p2[0], "r")) == NULL)
		goto syserr;
	return(final_connect());		/* verify initialization */
syserr:
	perror(dname);
	return(NULL);

#else	/* ! RHAS_FORK_EXEC */

	eputs(dname);
	eputs(": no fork/exec\n");
	return(NULL);

#endif	/* ! RHAS_FORK_EXEC */
}
Ejemplo n.º 7
0
void OOC_BuildPhotonMap (struct PhotonMap *pmap, unsigned numProc)
{
   FILE        *leafFile;
   char        leafFname [1024];
   FVECT       d, octOrg;
   int         i;
   RREAL       octSize = 0;
   
   /* Determine octree size and origin from pmap extent and init octree */
   VCOPY(octOrg, pmap -> minPos);
   VSUB(d, pmap -> maxPos, pmap -> minPos);
   for (i = 0; i < 3; i++)
      if (octSize < d [i])
         octSize = d [i];
         
   if (octSize < FTINY)
      error(INTERNAL, "zero octree size in OOC_BuildPhotonMap");
            
   /* Derive leaf filename from photon map and open file */
   strncpy(leafFname, pmap -> fileName, sizeof(leafFname));
   strncat(leafFname, PMAP_OOC_LEAFSUFFIX, 
           sizeof(leafFname) - strlen(leafFname) - 1);   
   if (!(leafFile = fopen(leafFname, "w+b")))
      error(SYSTEM, "failed to open leaf file in OOC_BuildPhotonMap");

#ifdef DEBUG_OOC
   eputs("Sorting photons by Morton code...\n");
#endif
   
   /* Sort photons in heapfile by Morton code and write to leaf file */
   if (OOC_Sort(pmap -> heap, leafFile, PMAP_OOC_NUMBLK, PMAP_OOC_BLKSIZE,
                numProc, sizeof(Photon), octOrg, octSize, OOC_PhotonKey))
      error(INTERNAL, "failed out-of-core photon sort in OOC_BuildPhotonMap");

   /* Init and build octree */   
   OOC_Init(&pmap -> store, sizeof(Photon), octOrg, octSize, OOC_PhotonKey, 
            leafFile);
            
#ifdef DEBUG_OOC
   eputs("Checking leaf file consistency...\n");
   OOC_CheckKeys(leafFile, &pmap -> store);
   
   eputs("Building out-of-core octree...\n");
#endif   
            
   if (!OOC_Build(&pmap -> store, PMAP_OOC_LEAFMAX, PMAP_OOC_MAXDEPTH))
      error(INTERNAL, "failed out-of-core octree build in OOC_BuildPhotonMap");
      
#ifdef DEBUG_OOC
   eputs("Checking out-of-core octree consistency...\n");
   if (OOC_Check(&pmap -> store, OOC_ROOT(&pmap -> store), 
                 octOrg, octSize, 0))
      error(INTERNAL, "inconsistent out-of-core octree; Time4Harakiri");
#endif
}
Ejemplo n.º 8
0
static void
putrec(void)                                /* output a record */
{
	char  fmt[32];
	register int  n;
	register struct field  *f;
	int  adlast, adnext;
	
	adlast = 0;
	for (f = outfmt; f != NULL; f = f->next) {
		adnext =        blnkeq &&
				f->next != NULL &&
				!( (f->next->type&F_TYP) == T_LIT &&
					f->next->f.sl[0] == ' ' );
		switch (f->type & F_TYP) {
		case T_LIT:
			fputs(f->f.sl, stdout);
			adlast = f->f.sl[(f->type&F_WID)-1] != ' ';
			break;
		case T_STR:
			if (f->f.sv->val == NULL) {
				eputs(f->f.sv->name);
				eputs(": undefined string\n");
				quit(1);
			}
			n = (int)(f->type & F_WID) - strlen(f->f.sv->val);
			if (adlast)
				fputs(f->f.sv->val, stdout);
			if (!(adlast && adnext))
				while (n-- > 0)
					putchar(' ');
			if (!adlast)
				fputs(f->f.sv->val, stdout);
			adlast = 1;
			break;
		case T_NUM:
			n = f->type & F_WID;
			if (adlast && adnext)
				strcpy(fmt, "%g");
			else if (adlast)
				sprintf(fmt, "%%-%dg", n);
			else
				sprintf(fmt, "%%%dg", n);
			printf(fmt, evalue(f->f.ne));
			adlast = 1;
			break;
		}
	}
}
Ejemplo n.º 9
0
double
chanvalue(            /* return value for column n */
int  n
)
{
	int  i;
	register char  *cp;

	if (noinput || inpfmt != NULL) {
		eputs("no column input\n");
		quit(1);
	}
	if (n < 1) {
		eputs("illegal channel number\n");
		quit(1);
	}
	if (nbicols) {
		if (n > nbicols)
			return(0.0);
		if (tolower(itype) == 'd') {
			cp = inpbuf + (n-1)*sizeof(double);
			return(*(double *)cp);
		}
		cp = inpbuf + (n-1)*sizeof(float);
		return(*(float *)cp);
	}
	if (n <= MAXCOL && colflg & 1L<<(n-1))
		return(colval[n-1]);

	cp = inpbuf;
	for (i = 1; i < n; i++)
		if (blnkeq && isspace(sepchar)) {
			while (isspace(*cp))
				cp++;
			while (*cp && !isspace(*cp))
				cp++;
		} else
			while (*cp && *cp++ != sepchar)
				;

	while (isspace(*cp))            /* some atof()'s don't like tabs */
		cp++;

	if (n <= MAXCOL) {
		colflg |= 1L<<(n-1);
		return(colval[n-1] = atof(cp));
	} else
		return(atof(cp));
}
Ejemplo n.º 10
0
static double
l_expos(			/* return picture exposure */
	char	*nam
)
{
	int	fn, n;
	double	d;

	d = argument(1);
	if (d <= -0.5 || d >= nfiles+0.5) {
		errno = EDOM;
		return(0.0);
	}
	if (d < 0.5)
		return((double)nfiles);
	fn = d - 0.5;
	if (nam == vbrtexp)
		return((*ourbright)(input[fn].expos));
	n = 3;
	while (n--)
		if (nam == vcolexp[n])
			return(colval(input[fn].expos,n));
	eputs("Bad call to l_expos()!\n");
	quit(1);
	return 1; /* pro forma return */
}
Ejemplo n.º 11
0
void einit_process_ipc_event_handler (struct einit_event *ev) {
 if (ev && ev->argv && ev->argv[0] && strmatch (ev->argv[0], "list")) {
  if (ev->argv[1] && strmatch (ev->argv[1], "processes") && ev->argv[2]) {
   uintptr_t tnum = atoi (ev->argv[3]);
   struct pc_conditional pcc = {
    .match = ev->argv[2],
    .para = (ev->argv[3] ?
      ((strmatch (ev->argv[2], "cwd") || strmatch (ev->argv[2], "cwd-below") || strmatch (ev->argv[2], "files-below")) ?
      (void *)ev->argv[3] : (void *)tnum) : NULL),
    .match_options = einit_pmo_additive },
    *pcl[2] = { &pcc, NULL };
   pid_t *process_list = NULL, i;

   process_list = pcollect ( pcl );

   if (process_list) {
    for (i = 0; process_list[i]; i++) {
     if (ev->ipc_options & einit_ipc_output_xml) {
      eprintf (ev->output, " <process pid=\"%i\" />\n", process_list[i]);
     } else {
      eprintf (ev->output, "process [pid=%i]\n", process_list[i]);
     }
    }
    free (process_list);
   } else {
    eputs ("einit-process: ipc-event-handler: your query has matched no processes\n", ev->output);
   }

   ev->implemented ++;
  }
Ejemplo n.º 12
0
char *
savqstr(char *s)			/* save a private string */
{
	static char  *curp = NULL;		/* allocated memory pointer */
	static unsigned  nrem = 0;		/* bytes remaining in block */
	static unsigned  nextalloc = MINBLOCK;	/* next block size */
	char  *cp;
	unsigned  n;

	for (cp = s; *cp++; )			/* compute strlen()+1 */
		;
	if ((n = cp-s) > nrem) {		/* do we need more core? */
		bfree(curp, nrem);			/* free remnant */
		while (n > nextalloc)
			nextalloc <<= 1;
		if ((curp = bmalloc(nrem=nextalloc)) == NULL) {
			eputs("out of memory in savqstr");
			quit(1);
		}
		if ((nextalloc <<= 1) > MAXBLOCK)	/* double block size */
			nextalloc = MAXBLOCK;
	}
	for (cp = curp; *cp++ = *s++; )		/* inline strcpy() */
		;
	s = curp;				/* update allocation info. */
	curp = cp;
	nrem -= n;
	return(s);				/* return new location */
}
Ejemplo n.º 13
0
Archivo: utils.c Proyecto: atikinn/EOS
/*
 * malloc wrapper which checks for errors and fails immideately
 *
 * n - size to allocate
 *
 * returns void
 */
void 
*emalloc(size_t n) {
    void *rv;
    if ((rv = svc_malloc(n)) == NULL)
        eputs(STDOUT, "out of memory");
    return rv;
}
Ejemplo n.º 14
0
void
wputs(				/* warning message */
	char  *s
)
{
	if (!nowarn)
		eputs(s);
}
Ejemplo n.º 15
0
static double
ebotch(
    EPNODE	*ep
)
{
    eputs("Bad expression!\n");
    quit(1);
	return 0.0; /* pro forma return */
}
Ejemplo n.º 16
0
static double
l_colin(			/* return color value for picture */
	register char	*nam
)
{
	int	fn;
	register int	n, xoff, yoff;
	double	d;

	d = argument(1);
	if (d <= -0.5 || d >= nfiles+0.5) {
		errno = EDOM;
		return(0.0);
	}
	if (d < 0.5)
		return((double)nfiles);
	fn = d - 0.5;
	xoff = yoff = 0;
	n = nargum();
	if (n >= 2) {
		d = argument(2);
		if (d < 0.0) {
			xoff = d-.5;
			if (xscan+xoff < 0)
				xoff = -xscan;
		} else {
			xoff = d+.5;
			if (xscan+xoff >= xmax)
				xoff = xmax-1-xscan;
		}
	}
	if (n >= 3) {
		d = argument(3);
		if (d < 0.0) {
			yoff = d-.5;
			if (yoff+MIDSCN < 0)
				yoff = -MIDSCN;
			if (yscan+yoff < 0)
				yoff = -yscan;
		} else {
			yoff = d+.5;
			if (yoff+MIDSCN >= WINSIZ)
				yoff = WINSIZ-1-MIDSCN;
			if (yscan+yoff >= ymax)
				yoff = ymax-1-yscan;
		}
	}
	if (nam == vbrtin)
		return((*ourbright)(input[fn].scan[MIDSCN+yoff][xscan+xoff]));
	n = 3;
	while (n--)
	    if (nam == vcolin[n])
		return(colval(input[fn].scan[MIDSCN+yoff][xscan+xoff],n));
	eputs("Bad call to l_colin()!\n");
	quit(1);
	return 1; /* pro forma return */
}
Ejemplo n.º 17
0
int fputs(int fd, const char *s)
{
	if (fd == 1)
		return puts(s);
	else if (fd == 2)
		return eputs(s);
	else
		return write(fd, s, strlen(s));
}
Ejemplo n.º 18
0
void
wputs(				/* warning output function */
	char	*s
)
{
	int  lasterrno = errno;
	eputs(s);
	errno = lasterrno;
}
Ejemplo n.º 19
0
static void
onsig(				/* fatal signal */
	int  signo
)
{
	static int  gotsig = 0;

	if (gotsig++)			/* two signals and we're gone! */
		_exit(signo);

#ifdef SIGALRM
	alarm(15);			/* allow 15 seconds to clean up */
	signal(SIGALRM, SIG_DFL);	/* make certain we do die */
#endif
	eputs("signal - ");
	eputs(sigerr[signo]);
	eputs("\n");
	quit(3);
}
Ejemplo n.º 20
0
void
fcompile(			/* get definitions from a file */
	char  *fname
)
{
    FILE  *fp;

    if (fname == NULL)
	fp = stdin;
    else if ((fp = fopen(fname, "r")) == NULL) {
	eputs(fname);
	eputs(": cannot open\n");
	quit(1);
    }
    initfile(fp, fname, 0);
    while (nextc != EOF)
	getstatement();
    if (fname != NULL)
	fclose(fp);
}
Ejemplo n.º 21
0
int devices_init (void)
{
#ifndef CONFIG_ARM     /* already relocated for current ARM implementation */
	ulong relocation_offset = gd->reloc_off;
	int i;

	/* relocate device name pointers */
	for (i = 0; i < (sizeof (stdio_names) / sizeof (char *)); ++i) {
		stdio_names[i] = (char *) (((ulong) stdio_names[i]) +
						relocation_offset);
	}
#endif

	/* Initialize the list */
	devlist = ListCreate (sizeof (device_t));

	if (devlist == NULL) {
		eputs ("Cannot initialize the list of devices!\n");
		return -1;
	}
#if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
	i2c_init (CFG_I2C_SPEED, CFG_I2C_SLAVE);
#endif
#if defined(CONFIG_DRV_BOARD_INIT)
    drv_board_init();
#endif
#ifdef CONFIG_LCD
	drv_lcd_init ();
#endif
#if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
	drv_video_init ();
#endif
#ifdef CONFIG_KEYBOARD
	drv_keyboard_init ();
#endif
#ifdef CONFIG_LOGBUFFER
	drv_logbuff_init ();
#endif
	drv_system_init ();
#ifdef CONFIG_SERIAL_MULTI
	serial_devices_init ();
#endif
#ifdef CONFIG_USB_TTY
	drv_usbtty_init ();
#endif
#ifdef CONFIG_NETCONSOLE
	drv_nc_init ();
#endif

	return (0);
}
Ejemplo n.º 22
0
/* do_choom()
**   if opt_e: abort on fail
**   no chdir(), no effect to cwd
*/
static
void
do_choom(void)
{
  int          fd;

  /* comment:
  ** normally we would first create/write a tmpfile
  ** then atomically rename() tmpfile into procfile
  ** but open(...,O_CREAT,...) of a new tmpfile on /proc fails (EEXIST)
  ** leaving no choice but to write into the procfile directly
  */

  if((fd = open(pathbuf, O_WRONLY | O_TRUNC, 0)) == -1){
      if(opt_e){
          fatal_syserr("failure on open() for path: ", pathbuf);
      }
      /* else: */
      if(opt_v){
          syserr_warn("ignoring failure on open() for path: ", pathbuf);
      }
      return;
  }
  fd_cloexec(fd);

  if(write_all(fd, setbuf, cstr_len(setbuf)) == -1){
      if(opt_e){
          fatal_syserr("failure on write() to path: ", pathbuf);
      }
      /* else: */
      if(opt_v){
          syserr_warn("ignoring failure on write() to path: ", pathbuf);
      }
      return;
  }

  /* comment:
  ** fsync() on /proc fails (EINVAL)
  ** so we simply ignore any following errors
  */
  fsync(fd);
  close(fd);

  /* success: */
  if(opt_v){
      eputs(progname, ": successfully configured ", pathbuf);
  } 

  return;
}
Ejemplo n.º 23
0
static void
advance(void)			/* read in data for next scanline */
{
	int	ytarget;
	register COLOR	*st;
	register int	i, j;

	for (ytarget = (ypos+.5)*ymax/yres; yscan > ytarget; yscan--)
		for (i = 0; i < nfiles; i++) {
			st = input[i].scan[WINSIZ-1];
			for (j = WINSIZ-1; j > 0; j--)	/* rotate window */
				input[i].scan[j] = input[i].scan[j-1];
			input[i].scan[0] = st;
			if (yscan <= MIDSCN)		/* hit bottom? */
				continue;
			if (freadscan(st, xmax, input[i].fp) < 0) {  /* read */
				eputs(input[i].name);
				eputs(": read error\n");
				quit(1);
			}
			for (j = 0; j < xmax; j++)	/* adjust color */
				multcolor(st[j], input[i].coef);
		}
}
Ejemplo n.º 24
0
extern void *	/* return pointer to n uninitialized bytes */
emalloc(size_t  n)
{
	register void  *cp;
	
	if (n == 0)
		return(NULL);

	if ((cp = malloc(n)) != NULL)
		return(cp);

	eputs("Out of memory in emalloc\n");
	quit(1);
	return NULL; /* pro forma return */
}
Ejemplo n.º 25
0
void printHex(unsigned int Number)
{
  // Output the number over the serial port as
  // as hexadecimal string.
  char TxString[9];
  int Index=8;
  TxString[Index]=0; // terminate the string
  Index--;
  while(Index >=0)
  {
    TxString[Index]=HexDigit(Number & 0x0f);
    Number = Number >> 4;
    Index--;
  }
  eputs(TxString);
}
Ejemplo n.º 26
0
int
main(int argc, char *argv[])
{
  nextopt_t  nopt = nextopt_INIT(argc, argv, "hV");
  char       opt;
  int        i;

  progname = nextopt_progname(&nopt);
  while((opt = nextopt(&nopt))){
      char optc[2] = {nopt.opt_got, '\0'};
      switch(opt){
      case 'V': version(); die(0); break;
      case 'h': usage(); die(0); break;
      case '?':
          if(nopt.opt_got != '?'){
              eputs(progname, ": usage error: invalid option: -", optc);
          }
          /* fallthrough: */
      default :
          die_usage(); break; 
      }
  }

  argc -= nopt.arg_ndx;
  argv += nopt.arg_ndx;

  for(i = 0; resources[i] != NULL; ++i){
      const char  *resource = resources[i];
      int  r = rlimit_lookup(resource);
      char  nfmt[NFMT_SIZE];
      struct rlimit  rlim;
      if(r == -1){
          ioq_vputs(ioq1, resource, "\t[not provided on this platform]\n");
          continue;
      }
      getrlimit(r, &rlim);
      ioq_vputs(ioq1, resource, "\t", rlimit_mesg(r), ": "); 
      if(rlim.rlim_cur == RLIM_INFINITY){
          ioq_vputs(ioq1, "unlimited\n");
      } else {
          ioq_vputs(ioq1, nfmt_uint32(nfmt, rlim.rlim_cur), "\n");
      }
  }
  ioq_flush(ioq1);

  return 0;
}
Ejemplo n.º 27
0
char *
savqstr(char *s)			/* save a private string */
{
	char  *cp;
	char  *newp;

	for (cp = s; *cp++; )			/* compute strlen()+1 */
		;
	newp = (char *)malloc(cp-s);
	if (newp == NULL) {
		eputs("out of memory in savqstr");
		quit(1);
	}
	for (cp = newp; (*cp++ = *s++); )		/* inline strcpy() */
		;
	return(newp);				/* return new location */
}
Ejemplo n.º 28
0
extern void *			/* return pointer to initialized memory */
ecalloc(register size_t ne, size_t es)
{
	register char  *cp;
	
	ne *= es;
	if (ne == 0)
		return(NULL);

	if ((cp = malloc(ne)) == NULL) {
		eputs("Out of memory in ecalloc\n");
		quit(1);
	}
	cp += ne;
	while (ne--)
		*--cp = 0;
	return(cp);
}
Ejemplo n.º 29
0
static double
l_ray(		/* return ray origin or direction */
	register char	*nam
)
{
	static unsigned long	ltick[MAXINP];
	static FVECT	lorg[MAXINP], ldir[MAXINP];
	static double	ldist[MAXINP];
	RREAL	loc[2];
	double	d;
	int	fn;
	register int	i;

	d = argument(1);
	if (d <= -0.5 || d >= nfiles+0.5) {
		errno = EDOM;
		return(0.0);
	}
	if (d < 0.5)
		return((double)nfiles);
	fn = d - 0.5;
	if (ltick[fn] != eclock) {		/* need to compute? */
		lorg[fn][0] = lorg[fn][1] = lorg[fn][2] = 0.0;
		ldir[fn][0] = ldir[fn][1] = ldir[fn][2] = 0.0;
		ldist[fn] = -1.0;
		if (input[fn].vw.type == 0)
			errno = EDOM;
		else {
			pix2loc(loc, &input[fn].rs, xscan, ymax-1-yscan);
			ldist[fn] = viewray(lorg[fn], ldir[fn],
					&input[fn].vw, loc[0], loc[1]);
		}
		ltick[fn] = eclock;
	}
	if (nam == vray[i=6])
		return(ldist[fn]);
	while (i--)
		if (nam == vray[i])
			return(i < 3 ? lorg[fn][i] : ldir[fn][i-3]);
	eputs("Bad call to l_ray()!\n");
	quit(1);
	return 1; /* pro forma return */
}
Ejemplo n.º 30
0
extern void *			/* reallocate cp to size n */
erealloc(register void  *cp, size_t  n)
{
	if (n == 0) {
		if (cp != NULL)
			free(cp);
		return(NULL);
	}

	if (cp == NULL)
		cp = malloc(n);
	else 
		cp = realloc(cp, n);

	if (cp != NULL)
		return(cp);

	eputs("Out of memory in erealloc\n");
	quit(1);
	return NULL; /* pro forma return */
}