1 |
< |
/* Copyright (c) 1995 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
14 |
|
|
15 |
|
#include "standard.h" |
16 |
|
|
17 |
+ |
#include "paths.h" |
18 |
+ |
|
19 |
|
#include <ctype.h> |
20 |
|
|
21 |
|
#include "object.h" |
31 |
|
|
32 |
|
int invert = 0; /* boolean true to invert surfaces */ |
33 |
|
|
34 |
< |
int expand = 0; /* boolean true to expand commands */ |
34 |
> |
int expand = 1; /* boolean true to expand commands */ |
35 |
|
|
36 |
|
char *newmod = NULL; /* new modifier for surfaces */ |
37 |
|
|
45 |
|
|
46 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
47 |
|
|
48 |
+ |
int nrept = 1; /* number of array repetitions */ |
49 |
+ |
|
50 |
|
extern char *malloc(), *fgetword(); |
51 |
|
|
52 |
+ |
char mainfn[MAXPATH]; /* main file name */ |
53 |
+ |
FILE *mainfp = NULL; /* main file pointer */ |
54 |
+ |
|
55 |
|
#define progname (xav[0]) |
56 |
|
|
57 |
|
|
59 |
|
int argc; |
60 |
|
char *argv[]; |
61 |
|
{ |
62 |
< |
FILE *fopen(); |
56 |
< |
FILE *fp; |
62 |
> |
char *fname; |
63 |
|
int a; |
64 |
|
/* check for array */ |
65 |
|
for (a = 1; a < argc; a++) |
81 |
|
break; |
82 |
|
idprefix = argv[++a]; |
83 |
|
continue; |
84 |
+ |
case 'c': |
85 |
+ |
if (argv[a][2]) |
86 |
+ |
break; |
87 |
+ |
expand = 0; |
88 |
+ |
continue; |
89 |
|
case 'e': |
90 |
|
if (argv[a][2]) |
91 |
|
break; |
123 |
|
printf(" %s", xav[a]); |
124 |
|
putchar('\n'); |
125 |
|
/* transform input */ |
126 |
< |
if (xac == argc) |
127 |
< |
xform("standard input", stdin); |
128 |
< |
else |
126 |
> |
if (xac == argc) { |
127 |
> |
openmain(NULL); |
128 |
> |
xform(mainfn, mainfp); |
129 |
> |
} else |
130 |
|
for (a = xac; a < argc; a++) { |
131 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
132 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
131 |
> |
openmain(argv[a]); |
132 |
> |
xform(mainfn, mainfp); |
133 |
|
} |
134 |
|
|
135 |
|
return(0); |
143 |
|
char *newav[256], **avp; |
144 |
|
char newid[128], repts[32]; |
145 |
|
char *oldid = NULL; |
146 |
< |
int i, err; |
146 |
> |
int n, i, err; |
147 |
|
|
148 |
|
avp = newav+2; |
149 |
|
avp[0] = av[0]; |
163 |
|
avp = newav; |
164 |
|
ac += 2; |
165 |
|
} |
166 |
+ |
nrept *= n = atoi(av[ai+1]); |
167 |
|
err = 0; |
168 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
168 |
> |
for (i = 0; i < n; i++) { |
169 |
|
if (oldid == NULL) |
170 |
|
sprintf(newid, "a%d", i); |
171 |
|
else |
214 |
|
char *fname; |
215 |
|
FILE *fin; |
216 |
|
{ |
217 |
< |
FILE *popen(); |
218 |
< |
char *fgetline(); |
217 |
> |
extern FILE *popen(); |
218 |
> |
extern char *fgetline(); |
219 |
|
FILE *pin; |
220 |
|
char buf[512]; |
221 |
|
int i; |
232 |
|
} else { |
233 |
|
printf("\n%s", buf); |
234 |
|
if (xac > 1) { |
235 |
< |
printf(" | %s -e", xav[0]); |
235 |
> |
printf(" | %s", xav[0]); |
236 |
|
for (i = 1; i < xac; i++) |
237 |
|
printf(" %s", xav[i]); |
238 |
|
} |
420 |
|
|
421 |
|
if (readfargs(&fa, fin) != 1) |
422 |
|
return(-1); |
423 |
< |
if (fa.nfargs > 5) |
423 |
> |
if (fa.nfargs > 7) |
424 |
|
return(-1); |
425 |
|
printf("%d", fa.nsargs); |
426 |
|
if (idprefix == NULL) |
446 |
|
if (fa.nfargs > 2) |
447 |
|
printf(" %12.6g %12.6g %12.6g", fa.farg[0]/tot.sca, |
448 |
|
fa.farg[1]/tot.sca, fa.farg[2]/tot.sca); |
449 |
< |
if (fa.nfargs > 3) |
450 |
< |
printf(" %12.6g", fa.farg[3]); |
443 |
< |
if (fa.nfargs > 4) |
444 |
< |
printf(" %12.6g", fa.farg[4]); |
449 |
> |
for (i = 3; i < fa.nfargs; i++) |
450 |
> |
printf(" %12.6g", fa.farg[i]); |
451 |
|
printf("\n"); |
452 |
|
freefargs(&fa); |
453 |
|
return(0); |
735 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
736 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
737 |
|
} |
738 |
+ |
|
739 |
+ |
|
740 |
+ |
#ifdef OLDXFORM |
741 |
+ |
openmain(fname) |
742 |
+ |
char *fname; |
743 |
+ |
{ |
744 |
+ |
if (fname == NULL) { |
745 |
+ |
strcpy(mainfn, "standard input"); |
746 |
+ |
mainfp = stdin; |
747 |
+ |
return; |
748 |
+ |
} |
749 |
+ |
if (mainfp != NULL) { |
750 |
+ |
if (!strcmp(fname, mainfn)) { |
751 |
+ |
rewind(mainfp); |
752 |
+ |
return; |
753 |
+ |
} |
754 |
+ |
fclose(mainfp); |
755 |
+ |
} |
756 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
757 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
758 |
+ |
progname, fname); |
759 |
+ |
exit(1); |
760 |
+ |
} |
761 |
+ |
strcpy(mainfn, fname); |
762 |
+ |
} |
763 |
+ |
#else |
764 |
+ |
openmain(fname) /* open fname for input, changing to its directory */ |
765 |
+ |
char *fname; |
766 |
+ |
{ |
767 |
+ |
extern FILE *tmpfile(); |
768 |
+ |
extern char *getlibpath(), *getpath(); |
769 |
+ |
static char origdir[MAXPATH]; |
770 |
+ |
static char curfn[MAXPATH]; |
771 |
+ |
static int diffdir; |
772 |
+ |
register char *fpath; |
773 |
+ |
|
774 |
+ |
if (fname == NULL) { /* standard input */ |
775 |
+ |
if (mainfp == NULL) { |
776 |
+ |
register int c; |
777 |
+ |
strcpy(mainfn, "standard input"); |
778 |
+ |
if (nrept <= 1) { |
779 |
+ |
mainfp = stdin; |
780 |
+ |
return; /* just read once */ |
781 |
+ |
} |
782 |
+ |
/* else copy */ |
783 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
784 |
+ |
fprintf(stderr, |
785 |
+ |
"%s: cannot create temporary file\n", |
786 |
+ |
progname); |
787 |
+ |
exit(1); |
788 |
+ |
} |
789 |
+ |
while ((c = getc(stdin)) != EOF) |
790 |
+ |
putc(c, mainfp); |
791 |
+ |
fclose(stdin); |
792 |
+ |
} |
793 |
+ |
rewind(mainfp); /* rewind copy */ |
794 |
+ |
return; |
795 |
+ |
} |
796 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
797 |
+ |
getwd(origdir); |
798 |
+ |
} else if (!strcmp(fname, curfn)) { /* just need to rewind? */ |
799 |
+ |
rewind(mainfp); |
800 |
+ |
return; |
801 |
+ |
} else { /* else close old stream */ |
802 |
+ |
fclose(mainfp); |
803 |
+ |
if (diffdir) { |
804 |
+ |
chdir(origdir); |
805 |
+ |
diffdir = 0; |
806 |
+ |
} |
807 |
+ |
} |
808 |
+ |
strcpy(curfn, fname); /* remember file name */ |
809 |
+ |
/* get full path */ |
810 |
+ |
if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) { |
811 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
812 |
+ |
progname, fname); |
813 |
+ |
exit(1); |
814 |
+ |
} |
815 |
+ |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
816 |
+ |
fpath += 2; |
817 |
+ |
/* record path name */ |
818 |
+ |
strcpy(mainfn, fpath); |
819 |
+ |
if (expand) { /* change to local directory */ |
820 |
+ |
register char *cp = fpath + strlen(fpath); /* get dir. */ |
821 |
+ |
while (cp > fpath) { |
822 |
+ |
cp--; |
823 |
+ |
if (ISDIRSEP(*cp)) { |
824 |
+ |
if (cp == fpath) |
825 |
+ |
cp++; /* root special case */ |
826 |
+ |
break; |
827 |
+ |
} |
828 |
+ |
} |
829 |
+ |
*cp = '\0'; |
830 |
+ |
if (fpath[0]) { /* change to new directory? */ |
831 |
+ |
if (chdir(fpath) < 0) { |
832 |
+ |
fprintf(stderr, |
833 |
+ |
"%s: cannot change directory to \"%s\"\n", |
834 |
+ |
progname, fpath); |
835 |
+ |
exit(1); |
836 |
+ |
} |
837 |
+ |
diffdir++; |
838 |
+ |
} |
839 |
+ |
/* get final path component */ |
840 |
+ |
for (fpath = fname+strlen(fname); |
841 |
+ |
fpath > fname && !ISDIRSEP(fpath[-1]); fpath--) |
842 |
+ |
; |
843 |
+ |
} |
844 |
+ |
/* open the file */ |
845 |
+ |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
846 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
847 |
+ |
progname, mainfn); |
848 |
+ |
exit(1); |
849 |
+ |
} |
850 |
+ |
} |
851 |
+ |
#endif |