ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/Development/ray/src/gen/genprism.c
(Generate patch)

Comparing ray/src/gen/genprism.c (file contents):
Revision 2.11 by schorsch, Mon Jul 21 22:30:18 2003 UTC vs.
Revision 2.15 by greg, Thu Aug 14 19:32:00 2025 UTC

# Line 9 | Line 9 | static const char      RCSid[] = "$Id$";
9   *              orientation.
10   */
11  
12 < #include  <stdio.h>
13 < #include  <string.h>
14 < #include <stdlib.h>
12 > #include  "rtio.h"
13 > #include  "paths.h"
14   #include  <math.h>
15   #include  <ctype.h>
16  
# Line 36 | Line 35 | int  do_ends = 1;              /* include end caps */
35   int  iscomplete = 0;            /* polygon is already completed */
36   double  crad = 0.0;             /* radius for corners (sign from lvdir) */
37  
39 static double  compute_rounding(void);
38  
39 <
40 < static void
43 < readverts(fname)                /* read vertices from a file */
44 < char  *fname;
39 > void
40 > readverts(char *fname)          /* read vertices from a file */
41   {
42          FILE  *fp;
43  
44 <        if (fname == NULL)
44 >        if (fname == NULL) {
45                  fp = stdin;
46 <        else if ((fp = fopen(fname, "r")) == NULL) {
46 >                fname = "<stdin>";
47 >        } else if ((fp = fopen(fname, "r")) == NULL) {
48                  fprintf(stderr, "%s: cannot open\n", fname);
49                  exit(1);
50          }
51          while (fscanf(fp, "%lf %lf", &vert[nverts][0], &vert[nverts][1]) == 2)
52 <                nverts++;
52 >                if (++nverts >= MAXVERT)
53 >                        break;
54 >
55 >        if (!feof(fp)) {
56 >                if (nverts < MAXVERT) {
57 >                        fprintf(stderr, "%s: warning - non-numerical data\n", fname);
58 >                } else {
59 >                        fprintf(stderr, "%s: too many vertices\n", fname);
60 >                        exit(1);
61 >                }
62 >        }
63          fclose(fp);
64   }
65  
66  
67 < static void
68 < side(n0, n1)                    /* print single side */
62 < register int  n0, n1;
67 > void
68 > side(int n0, int n1)                    /* print single side */
69   {
70          printf("\n%s polygon %s.%d\n", pmtype, pname, n0+1);
71          printf("0\n0\n12\n");
# Line 74 | Line 80 | register int  n0, n1;
80   }
81  
82  
83 < static void
84 < rside(n0, n1)                   /* print side with rounded edge */
79 < register int  n0, n1;
83 > void
84 > rside(int n0, int n1)                   /* print side with rounded edge */
85   {
86          double  s, c, t[3];
87  
# Line 125 | Line 130 | register int  n0, n1;
130   }
131  
132  
133 < static double
133 > double
134   compute_rounding()              /* compute vectors for rounding operations */
135   {
136 <        register int  i;
137 <        register double *v0, *v1;
136 >        int  i;
137 >        double  *v0, *v1;
138          double  l, asum;
139  
140          v0 = vert[nverts-1];
# Line 169 | Line 174 | compute_rounding()             /* compute vectors for rounding op
174   }
175  
176  
177 < static void
177 > void
178   printends()                     /* print ends of prism */
179   {
180 <        register int  i;
180 >        int  i;
181                                                  /* bottom face */
182          printf("\n%s polygon %s.b\n", pmtype, pname);
183          printf("0\n0\n%d\n", nverts*3);
# Line 188 | Line 193 | printends()                    /* print ends of prism */
193   }
194  
195  
196 < static void
197 < printrends()                    /* print ends of prism with rounding */
196 > void
197 > printrends()            /* print ends of prism with rounding */
198   {
199 <        register int  i;
199 >        int  i;
200          double  c0[3], c1[3], cl[3];
201                                                  /* bottom face */
202          printf("\n%s polygon %s.b\n", pmtype, pname);
# Line 268 | Line 273 | printrends()                   /* print ends of prism with rounding */
273   }
274  
275  
276 < static void
277 < printsides(round)               /* print prism sides */
273 < int  round;
276 > void
277 > printsides(int round)           /* print prism sides */
278   {
279 <        register int  i;
279 >        int  i;
280  
281          for (i = 0; i < nverts-1; i++)
282                  if (round)
# Line 288 | Line 292 | int  round;
292   }
293  
294  
295 < static void
296 < printhead(ac, av)               /* print command header */
293 < register int  ac;
294 < register char  **av;
295 > int
296 > main(int argc, char **argv)
297   {
296        putchar('#');
297        while (ac--) {
298                putchar(' ');
299                fputs(*av++, stdout);
300        }
301        putchar('\n');
302 }
303
304
305 main(argc, argv)
306 int  argc;
307 char  **argv;
308 {
298          int  an;
299          
300          if (argc < 4)
# Line 321 | Line 310 | char  **argv;
310                  nverts = atoi(argv[3]);
311                  if (argc-3 < 2*nverts)
312                          goto userr;
313 +                if (nverts > MAXVERT) {
314 +                        fprintf(stderr, "%s: too many vertices\n", argv[0]);
315 +                        return(1);
316 +                }
317                  for (an = 0; an < nverts; an++) {
318                          vert[an][0] = atof(argv[2*an+4]);
319                          vert[an][1] = atof(argv[2*an+5]);
# Line 332 | Line 325 | char  **argv;
325          }
326          if (nverts < 3) {
327                  fprintf(stderr, "%s: not enough vertices\n", argv[0]);
328 <                exit(1);
328 >                return(1);
329          }
330  
331          for ( ; an < argc; an++) {
# Line 351 | Line 344 | char  **argv;
344                                  fprintf(stderr,
345                                          "%s: illegal extrusion vector\n",
346                                                  argv[0]);
347 <                                exit(1);
347 >                                return(1);
348                          }
349                          llen = sqrt(lvect[0]*lvect[0] + lvect[1]*lvect[1] +
350                                          lvect[2]*lvect[2]);
# Line 373 | Line 366 | char  **argv;
366                  if (crad > lvdir*lvect[2]) {
367                          fprintf(stderr, "%s: rounding greater than height\n",
368                                          argv[0]);
369 <                        exit(1);
369 >                        return(1);
370                  }
371                  crad *= lvdir;          /* simplifies formulas */
372                  compute_rounding();
373 <                printhead(argc, argv);
373 >                fputs("# ", stdout);
374 >                printargs(argc, argv, stdout);
375                  if (do_ends)
376                          printrends();
377                  printsides(1);
378          } else {
379 <                printhead(argc, argv);
379 >                fputs("# ", stdout);
380 >                printargs(argc, argv, stdout);
381                  if (do_ends)
382                          printends();
383                  printsides(0);
384          }
385 <        exit(0);
385 >        return(0);
386   userr:
387          fprintf(stderr, "Usage: %s material name ", argv[0]);
388          fprintf(stderr, "{ - | vfile | N v1 v2 .. vN } ");
389          fprintf(stderr, "[-l lvect][-r radius][-c][-e]\n");
390 <        exit(1);
390 >        return(1);
391   }
392  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines