ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/readfargs.c
(Generate patch)

Comparing ray/src/common/readfargs.c (file contents):
Revision 2.2 by greg, Thu Dec 19 14:45:52 1991 UTC vs.
Revision 2.10 by schorsch, Sun Jul 27 22:12:01 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1991 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Allocate, read and free object arguments
6   */
7  
8 < #include <stdio.h>
8 > #include "copyright.h"
9  
10 < #include "fvect.h"
10 > #include "standard.h"
11  
12   #include "object.h"
13  
14  
18 extern char  *savestr(), *malloc(), *fgetword();
19 #ifndef atof
20 extern double  atof();
21 #endif
22 extern int  atoi();
23 extern long  atol();
15  
16 < #ifdef  MEMHOG
26 < extern char  *bmalloc();
27 < #else
28 < #define  bmalloc        malloc
29 < #endif
30 <
31 <
16 > int
17   readfargs(fa, fp)               /* read function arguments from stream */
18   register FUNARGS  *fa;
19   FILE  *fp;
20   {
21 < #define getstr()        (fgetword(sbuf,MAXSTR,fp)!=NULL)
22 < #define getint()        (getstr() && isint(sbuf))
23 < #define getflt()        (getstr() && isflt(sbuf))
21 > #define getstr(s)       (fgetword(s,sizeof(s),fp)!=NULL)
22 > #define getint(s)       (getstr(s) && isint(s))
23 > #define getflt(s)       (getstr(s) && isflt(s))
24          char  sbuf[MAXSTR];
25          register int  n, i;
26  
27 <        if (!getint() || (n = atoi(sbuf)) < 0)
27 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
28                  return(0);
29 <        if (fa->nsargs = n) {
30 <                fa->sarg = (char **)bmalloc(n*sizeof(char *));
29 >        if ( (fa->nsargs = n) ) {
30 >                fa->sarg = (char **)malloc(n*sizeof(char *));
31                  if (fa->sarg == NULL)
32                          return(-1);
33                  for (i = 0; i < fa->nsargs; i++) {
34 <                        if (!getstr())
34 >                        if (!getstr(sbuf))
35                                  return(0);
36                          fa->sarg[i] = savestr(sbuf);
37                  }
38          } else
39                  fa->sarg = NULL;
40 <        if (!getint() || (n = atoi(sbuf)) < 0)
40 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
41                  return(0);
42   #ifdef  IARGS
43          if (fa->niargs = n) {
44 <                fa->iarg = (long *)bmalloc(n*sizeof(long));
44 >                fa->iarg = (long *)malloc(n*sizeof(long));
45                  if (fa->iarg == NULL)
46                          return(-1);
47                  for (i = 0; i < n; i++) {
48 <                        if (!getint())
48 >                        if (!getint(sbuf))
49                                  return(0);
50                          fa->iarg[i] = atol(sbuf);
51                  }
# Line 70 | Line 55 | FILE  *fp;
55          if (n != 0)
56                  return(0);
57   #endif
58 <        if (!getint() || (n = atoi(sbuf)) < 0)
58 >        if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
59                  return(0);
60 <        if (fa->nfargs = n) {
61 <                fa->farg = (FLOAT *)bmalloc(n*sizeof(FLOAT));
60 >        if ( (fa->nfargs = n) ) {
61 >                fa->farg = (RREAL *)malloc(n*sizeof(RREAL));
62                  if (fa->farg == NULL)
63                          return(-1);
64                  for (i = 0; i < n; i++) {
65 <                        if (!getflt())
65 >                        if (!getflt(sbuf))
66                                  return(0);
67                          fa->farg[i] = atof(sbuf);
68                  }
# Line 90 | Line 75 | FILE  *fp;
75   }
76  
77  
78 < #ifndef  MEMHOG
78 > void
79   freefargs(fa)                   /* free object arguments */
80   register FUNARGS  *fa;
81   {
# Line 99 | Line 84 | register FUNARGS  *fa;
84          if (fa->nsargs) {
85                  for (i = 0; i < fa->nsargs; i++)
86                          freestr(fa->sarg[i]);
87 <                free((char *)fa->sarg);
87 >                free((void *)fa->sarg);
88 >                fa->sarg = NULL;
89 >                fa->nsargs = 0;
90          }
91   #ifdef  IARGS
92 <        if (fa->niargs)
93 <                free((char *)fa->iarg);
92 >        if (fa->niargs) {
93 >                free((void *)fa->iarg);
94 >                fa->iarg = NULL;
95 >                fa->niargs = 0;
96 >        }
97   #endif
98 <        if (fa->nfargs)
99 <                free((char *)fa->farg);
98 >        if (fa->nfargs) {
99 >                free((void *)fa->farg);
100 >                fa->farg = NULL;
101 >                fa->nfargs = 0;
102 >        }
103   }
111 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines