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.2 by schorsch, Mon Oct 27 10:28:59 2003 UTC vs.
Revision 1.4 by schorsch, Sat Nov 15 02:13:37 2003 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 68 | 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 91 | Line 98 | char  *argv[];
98          mainmenu();
99  
100          quit(0);
101 +        return 0; /* pro forma return */
102   }
103  
104 <
104 > extern void
105   eputs(msg)                              /* print error message */
106   char  *msg;
107   {
108          fputs(msg, stderr);
109   }
110  
111 <
111 > extern void
112   quit(code)                              /* recover or quit */
113   int  code;
114   {
# Line 110 | Line 118 | int  code;
118   }
119  
120  
121 < mainmenu()                      /* the main menu loop */
121 > static void
122 > mainmenu(void)                  /* the main menu loop */
123   {
124          char  sbuf[128];
125  
# Line 128 | Line 137 | mainmenu()                     /* the main menu loop */
137                  printf("\t10    Quit\n");
138  
139                  printf("\nChoice: ");
140 <                clearerr(stdin); gets(sbuf);
140 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
141                  if (feof(stdin))
142                          return;
143                  switch (atoi(sbuf)) {
# Line 159 | Line 168 | mainmenu()                     /* the main menu loop */
168                          break;
169                  case 6:                         /* set curve variable */
170                          printf("\nCurve (A-%c): ", MAXCUR-1+'A');
171 <                        clearerr(stdin); gets(sbuf);
171 >                        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
172                          if (islower(sbuf[0]))
173                                  sbuf[0] -= 'a';
174                          else if (isupper(sbuf[0]))
# Line 167 | Line 176 | mainmenu()                     /* the main menu loop */
176                          else
177                                  break;
178                          if (sbuf[0] < MAXCUR)
179 <                                setvars(NCVARS, cparam[sbuf[0]]);
179 >                                setvars(NCVARS, cparam[(int)sbuf[0]]);
180                          break;
181                  case 7:                         /* output plot */
182                          plotout();
183                          break;
184                  case 8:                         /* escape command */
185                          printf("\nCommand: ");
186 <                        clearerr(stdin); gets(sbuf);
186 >                        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
187                          if (sbuf[0]) {
188                                  system(sbuf);
189                                  uwait();
# Line 190 | Line 199 | mainmenu()                     /* the main menu loop */
199   }
200  
201  
202 < char *
203 < getfile()                       /* get file name from user */
202 > static char *
203 > getfile(void)                   /* get file name from user */
204   {
205          char  sbuf[128];
206  
207          printf("\nFile (%s): ", curfile);
208 <        clearerr(stdin); gets(sbuf);
208 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
209          if (sbuf[0] == '-')
210                  return(NULL);
211          if (sbuf[0])
# Line 204 | Line 213 | getfile()                      /* get file name from user */
213          return(curfile);
214   }
215  
216 <
217 < settype()                       /* set plot type */
216 > static void
217 > settype(void)                   /* set plot type */
218   {
219          char  sbuf[128];
220          int  i;
# Line 216 | Line 225 | settype()                      /* set plot type */
225                  printf("\t%d    %s\n", i+1, typ[i].descrip);
226          
227          printf("\nChoice (0): ");
228 <        clearerr(stdin); gets(sbuf);
228 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
229          i = atoi(sbuf) - 1;
230          if (i < 0 || i >= NTYP)
231                  return;
# Line 225 | Line 234 | settype()                      /* set plot type */
234   }
235  
236  
237 < plotout()                       /* output our graph */
237 > static void
238 > plotout(void)                   /* output our graph */
239   {
240          extern FILE  *pout;
241          char  sbuf[128];
242 <        char  *command;
242 >        char  *command = NULL;
243          int  i;
244  
245          printf("\nOUTPUT PLOT\n");
# Line 240 | Line 250 | plotout()                      /* output our graph */
250          printf("\t%d    Other\n", NDEV+2);
251          
252          printf("\nChoice (0): ");
253 <        clearerr(stdin); gets(sbuf);
253 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
254          i = atoi(sbuf) - 1;
255          if (i < 0 || i > NDEV+1)
256                  return;
# Line 256 | Line 266 | plotout()                      /* output our graph */
266                  return;
267          } else if (i == NDEV+1) {
268                  printf("\nDriver command: ");
269 <                clearerr(stdin); gets(sbuf);
269 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
270                  if (!sbuf[0])
271                          return;
272                  command = sbuf;
# Line 277 | Line 287 | plotout()                      /* output our graph */
287   }
288  
289  
290 < setvars(nvar, vars)             /* set variables */
291 < int  nvar;
292 < VARIABLE  vars[];
290 > static void
291 > setvars(                /* set variables */
292 > int  nvar,
293 > VARIABLE  vars[])
294   {
295          char  sbuf[128];
296          int  i, j;
# Line 292 | Line 303 | VARIABLE  vars[];
303                                          vars[i].name : vars[i].descrip);
304  
305                  printf("\nChoice (0): ");
306 <                clearerr(stdin); gets(sbuf);
306 >                clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
307                  i = atoi(sbuf) - 1;
308                  if (i < 0 || i >= nvar)
309                          return;
# Line 309 | Line 320 | VARIABLE  vars[];
320                  else
321                          sprintf(sbuf, "%s=", vars[i].name);
322                  j = strlen(sbuf);
323 <                clearerr(stdin); gets(sbuf+j);
323 >                clearerr(stdin); fgets(sbuf+j, sizeof(sbuf)-j, stdin);
324                  if (sbuf[j]) {
325                          if (vars[i].type == DATA && sbuf[j] == '-')
326                                  sbuf[j] = '\0';
# Line 325 | Line 336 | VARIABLE  vars[];
336   }
337  
338  
339 < gcompute()                      /* do a computation */
339 > static void
340 > gcompute(void)                  /* do a computation */
341   {
342          char  sbuf[64];
343          int  i;
# Line 336 | Line 348 | gcompute()                     /* do a computation */
348                  printf("\t%d    %s\n", i+1, cal[i].descrip);
349          
350          printf("\nChoice (0): ");
351 <        clearerr(stdin); gets(sbuf);
351 >        clearerr(stdin); fgets(sbuf, sizeof(sbuf), stdin);
352          i = atoi(sbuf) - 1;
353          if (i < 0 || i >= NCAL)
354                  return;
# Line 351 | Line 363 | gcompute()                     /* do a computation */
363   }
364  
365  
366 < uwait()                         /* wait for user after command, error */
366 > static void
367 > uwait(void)                             /* wait for user after command, error */
368   {
369          printf("Hit return to continue: ");
370          while (getchar() != '\n')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines