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.3 by greg, Tue May 18 09:26:05 1993 UTC vs.
Revision 2.11 by greg, Thu Jun 12 22:12:20 2014 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 #ifndef  MEMHOG
19 #define  bmalloc        malloc
20 #endif
15  
16 < extern char  *bmalloc(), *savestr(), *fgetword();
17 < #ifndef atof
18 < extern double  atof();
19 < #endif
20 < extern int  atoi();
27 < extern long  atol();
28 <
29 <
30 < readfargs(fa, fp)               /* read function arguments from stream */
31 < register FUNARGS  *fa;
32 < FILE  *fp;
16 > int
17 > readfargs(                      /* read function arguments from stream */
18 >        FUNARGS  *fa,
19 >        FILE  *fp
20 > )
21   {
22   #define getstr(s)       (fgetword(s,sizeof(s),fp)!=NULL)
23   #define getint(s)       (getstr(s) && isint(s))
24   #define getflt(s)       (getstr(s) && isflt(s))
25          char  sbuf[MAXSTR];
26 <        register int  n, i;
26 >        int  n, i;
27  
28          if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
29                  return(0);
30 <        if (fa->nsargs = n) {
31 <                fa->sarg = (char **)bmalloc(n*sizeof(char *));
30 >        if ( (fa->nsargs = n) ) {
31 >                fa->sarg = (char **)malloc(n*sizeof(char *));
32                  if (fa->sarg == NULL)
33                          return(-1);
34                  for (i = 0; i < fa->nsargs; i++) {
# Line 54 | Line 42 | FILE  *fp;
42                  return(0);
43   #ifdef  IARGS
44          if (fa->niargs = n) {
45 <                fa->iarg = (long *)bmalloc(n*sizeof(long));
45 >                fa->iarg = (long *)malloc(n*sizeof(long));
46                  if (fa->iarg == NULL)
47                          return(-1);
48                  for (i = 0; i < n; i++) {
# Line 70 | Line 58 | FILE  *fp;
58   #endif
59          if (!getint(sbuf) || (n = atoi(sbuf)) < 0)
60                  return(0);
61 <        if (fa->nfargs = n) {
62 <                fa->farg = (FLOAT *)bmalloc(n*sizeof(FLOAT));
61 >        if ( (fa->nfargs = n) ) {
62 >                fa->farg = (RREAL *)malloc(n*sizeof(RREAL));
63                  if (fa->farg == NULL)
64                          return(-1);
65                  for (i = 0; i < n; i++) {
# Line 88 | Line 76 | FILE  *fp;
76   }
77  
78  
79 < #ifndef  MEMHOG
80 < freefargs(fa)                   /* free object arguments */
81 < register FUNARGS  *fa;
79 > void
80 > freefargs(                              /* free object arguments */
81 >        FUNARGS  *fa
82 > )
83   {
84 <        register int  i;
84 >        int  i;
85  
86          if (fa->nsargs) {
87                  for (i = 0; i < fa->nsargs; i++)
88                          freestr(fa->sarg[i]);
89 <                free((char *)fa->sarg);
89 >                free((void *)fa->sarg);
90 >                fa->sarg = NULL;
91 >                fa->nsargs = 0;
92          }
93   #ifdef  IARGS
94 <        if (fa->niargs)
95 <                free((char *)fa->iarg);
94 >        if (fa->niargs) {
95 >                free((void *)fa->iarg);
96 >                fa->iarg = NULL;
97 >                fa->niargs = 0;
98 >        }
99   #endif
100 <        if (fa->nfargs)
101 <                free((char *)fa->farg);
100 >        if (fa->nfargs) {
101 >                free((void *)fa->farg);
102 >                fa->farg = NULL;
103 >                fa->nfargs = 0;
104 >        }
105   }
109 #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines