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

Comparing ray/src/meta/igraph.c (file contents):
Revision 1.1 by greg, Sat Feb 22 02:07:26 2003 UTC vs.
Revision 1.5 by greg, Thu Feb 9 21:54:11 2023 UTC

# Line 10 | Line 10 | static const char      RCSid[] = "$Id$";
10   */
11  
12   #include  <stdio.h>
13
13   #include  <ctype.h>
15
14   #include  <setjmp.h>
15  
16 + #include  "rtprocess.h"
17 + #include  "rterror.h"
18 + #include  "meta.h"
19 + #include  "mgraph.h"
20   #include  "mgvars.h"
21  
22   typedef struct {
# Line 67 | Line 69 | static jmp_buf  env;           /* setjmp buffer */
69  
70   static char  curfile[64] = "temp.plt";  /* current file name */
71  
72 < char  *getfile(), *gets(), *strcpy();
72 > static void mainmenu(void);
73 > static void uwait(void);
74 > static void gcompute(void);
75 > static void setvars(int  nvar, VARIABLE  vars[]);
76 > static void plotout(void);
77 > static void settype(void);
78 > static char  *getfile(void);
79  
80 <
80 > int
81   main(argc, argv)
82   int  argc;
83   char  *argv[];
# Line 90 | Line 98 | char  *argv[];
98          mainmenu();
99  
100          quit(0);
101 +        return 0; /* pro forma return */
102   }
103  
104 <
105 < eputs(msg)                              /* print error message */
97 < char  *msg;
104 > void
105 > eputs(const char *msg)                  /* print error message */
106   {
107          fputs(msg, stderr);
108   }
109  
110 <
111 < quit(code)                              /* recover or quit */
104 < int  code;
110 > void
111 > quit(int code)                          /* recover or quit */
112   {
113          if (code && recover--)
114                  longjmp(env, 1);
# Line 109 | Line 116 | int  code;
116   }
117  
118  
119 < mainmenu()                      /* the main menu loop */
119 > static void
120 > mainmenu(void)                  /* the main menu loop */
121   {
122          char  sbuf[128];
123  
# Line 127 | Line 135 | mainmenu()                     /* the main menu loop */
135                  printf("\t10    Quit\n");
136  
137                  printf("\nChoice: ");
138 <                clearerr(stdin); gets(sbuf);
138 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
139                  if (feof(stdin))
140                          return;
141                  switch (atoi(sbuf)) {
# Line 158 | Line 166 | mainmenu()                     /* the main menu loop */
166                          break;
167                  case 6:                         /* set curve variable */
168                          printf("\nCurve (A-%c): ", MAXCUR-1+'A');
169 <                        clearerr(stdin); gets(sbuf);
169 >                        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
170                          if (islower(sbuf[0]))
171                                  sbuf[0] -= 'a';
172                          else if (isupper(sbuf[0]))
# Line 166 | Line 174 | mainmenu()                     /* the main menu loop */
174                          else
175                                  break;
176                          if (sbuf[0] < MAXCUR)
177 <                                setvars(NCVARS, cparam[sbuf[0]]);
177 >                                setvars(NCVARS, cparam[(int)sbuf[0]]);
178                          break;
179                  case 7:                         /* output plot */
180                          plotout();
181                          break;
182                  case 8:                         /* escape command */
183                          printf("\nCommand: ");
184 <                        clearerr(stdin); gets(sbuf);
184 >                        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
185                          if (sbuf[0]) {
186                                  system(sbuf);
187                                  uwait();
# Line 189 | Line 197 | mainmenu()                     /* the main menu loop */
197   }
198  
199  
200 < char *
201 < getfile()                       /* get file name from user */
200 > static char *
201 > getfile(void)                   /* get file name from user */
202   {
203          char  sbuf[128];
204  
205          printf("\nFile (%s): ", curfile);
206 <        clearerr(stdin); gets(sbuf);
206 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
207          if (sbuf[0] == '-')
208                  return(NULL);
209          if (sbuf[0])
# Line 203 | Line 211 | getfile()                      /* get file name from user */
211          return(curfile);
212   }
213  
214 <
215 < settype()                       /* set plot type */
214 > static void
215 > settype(void)                   /* set plot type */
216   {
217          char  sbuf[128];
218          int  i;
# Line 215 | Line 223 | settype()                      /* set plot type */
223                  printf("\t%d    %s\n", i+1, typ[i].descrip);
224          
225          printf("\nChoice (0): ");
226 <        clearerr(stdin); gets(sbuf);
226 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
227          i = atoi(sbuf) - 1;
228          if (i < 0 || i >= NTYP)
229                  return;
# Line 224 | Line 232 | settype()                      /* set plot type */
232   }
233  
234  
235 < plotout()                       /* output our graph */
235 > static void
236 > plotout(void)                   /* output our graph */
237   {
238 <        extern FILE  *pout, *popen();
238 >        extern FILE  *pout;
239          char  sbuf[128];
240 <        char  *command;
240 >        char  *command = NULL;
241          int  i;
242  
243          printf("\nOUTPUT PLOT\n");
# Line 239 | Line 248 | plotout()                      /* output our graph */
248          printf("\t%d    Other\n", NDEV+2);
249          
250          printf("\nChoice (0): ");
251 <        clearerr(stdin); gets(sbuf);
251 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
252          i = atoi(sbuf) - 1;
253          if (i < 0 || i > NDEV+1)
254                  return;
# Line 255 | Line 264 | plotout()                      /* output our graph */
264                  return;
265          } else if (i == NDEV+1) {
266                  printf("\nDriver command: ");
267 <                clearerr(stdin); gets(sbuf);
267 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
268                  if (!sbuf[0])
269                          return;
270                  command = sbuf;
# Line 276 | Line 285 | plotout()                      /* output our graph */
285   }
286  
287  
288 < setvars(nvar, vars)             /* set variables */
289 < int  nvar;
290 < VARIABLE  vars[];
288 > static void
289 > setvars(                /* set variables */
290 > int  nvar,
291 > VARIABLE  vars[])
292   {
293          char  sbuf[128];
294          int  i, j;
# Line 291 | Line 301 | VARIABLE  vars[];
301                                          vars[i].name : vars[i].descrip);
302  
303                  printf("\nChoice (0): ");
304 <                clearerr(stdin); gets(sbuf);
304 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
305                  i = atoi(sbuf) - 1;
306                  if (i < 0 || i >= nvar)
307                          return;
# Line 308 | Line 318 | VARIABLE  vars[];
318                  else
319                          sprintf(sbuf, "%s=", vars[i].name);
320                  j = strlen(sbuf);
321 <                clearerr(stdin); gets(sbuf+j);
321 >                clearerr(stdin); fgets(sbuf+j, sizeof(sbuf)-j, stdin);
322                  if (sbuf[j]) {
323                          if (vars[i].type == DATA && sbuf[j] == '-')
324                                  sbuf[j] = '\0';
# Line 324 | Line 334 | VARIABLE  vars[];
334   }
335  
336  
337 < gcompute()                      /* do a computation */
337 > static void
338 > gcompute(void)                  /* do a computation */
339   {
340          char  sbuf[64];
341          int  i;
# Line 335 | Line 346 | gcompute()                     /* do a computation */
346                  printf("\t%d    %s\n", i+1, cal[i].descrip);
347          
348          printf("\nChoice (0): ");
349 <        clearerr(stdin); gets(sbuf);
349 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
350          i = atoi(sbuf) - 1;
351          if (i < 0 || i >= NCAL)
352                  return;
# Line 350 | Line 361 | gcompute()                     /* do a computation */
361   }
362  
363  
364 < uwait()                         /* wait for user after command, error */
364 > static void
365 > uwait(void)                             /* wait for user after command, error */
366   {
367          printf("Hit return to continue: ");
368          while (getchar() != '\n')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines