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" |
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++) |
118 |
|
printf(" %s", xav[a]); |
119 |
|
putchar('\n'); |
120 |
|
/* transform input */ |
121 |
< |
if (xac == argc) |
122 |
< |
xform("standard input", stdin); |
123 |
< |
else |
121 |
> |
if (xac == argc) { |
122 |
> |
openmain(NULL); |
123 |
> |
xform(mainfn, mainfp); |
124 |
> |
} else |
125 |
|
for (a = xac; a < argc; a++) { |
126 |
< |
if ((fp = fopen(argv[a], "r")) == NULL) { |
127 |
< |
fprintf(stderr, "%s: cannot open \"%s\"\n", |
121 |
< |
progname, argv[a]); |
122 |
< |
exit(1); |
123 |
< |
} |
124 |
< |
xform(argv[a], fp); |
125 |
< |
fclose(fp); |
126 |
> |
openmain(argv[a]); |
127 |
> |
xform(mainfn, mainfp); |
128 |
|
} |
129 |
|
|
130 |
|
return(0); |
138 |
|
char *newav[256], **avp; |
139 |
|
char newid[128], repts[32]; |
140 |
|
char *oldid = NULL; |
141 |
< |
int i, err; |
141 |
> |
int n, i, err; |
142 |
|
|
143 |
|
avp = newav+2; |
144 |
|
avp[0] = av[0]; |
158 |
|
avp = newav; |
159 |
|
ac += 2; |
160 |
|
} |
161 |
+ |
nrept *= n = atoi(av[ai+1]); |
162 |
|
err = 0; |
163 |
< |
for (i = 0; i < atoi(av[ai+1]); i++) { |
163 |
> |
for (i = 0; i < n; i++) { |
164 |
|
if (oldid == NULL) |
165 |
|
sprintf(newid, "a%d", i); |
166 |
|
else |
209 |
|
char *fname; |
210 |
|
FILE *fin; |
211 |
|
{ |
212 |
< |
FILE *popen(); |
213 |
< |
char *fgetline(); |
212 |
> |
extern FILE *popen(); |
213 |
> |
extern char *fgetline(); |
214 |
|
FILE *pin; |
215 |
|
char buf[512]; |
216 |
|
int i; |
732 |
|
tinvers[OBJ_TUBE] = OBJ_CYLINDER; |
733 |
|
tinvers[OBJ_INSTANCE] = OBJ_INSTANCE; /* oh, well */ |
734 |
|
} |
735 |
+ |
|
736 |
+ |
|
737 |
+ |
#ifdef OLDXFORM |
738 |
+ |
openmain(fname) |
739 |
+ |
char *fname; |
740 |
+ |
{ |
741 |
+ |
if (fname == NULL) { |
742 |
+ |
strcpy(mainfn, "standard input"); |
743 |
+ |
mainfp = stdin; |
744 |
+ |
return; |
745 |
+ |
} |
746 |
+ |
if (mainfp != NULL) { |
747 |
+ |
if (!strcmp(fname, mainfn)) { |
748 |
+ |
rewind(mainfp); |
749 |
+ |
return; |
750 |
+ |
} |
751 |
+ |
fclose(mainfp); |
752 |
+ |
} |
753 |
+ |
if ((mainfp = fopen(fname, "r")) == NULL) { |
754 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
755 |
+ |
progname, fname); |
756 |
+ |
exit(1); |
757 |
+ |
} |
758 |
+ |
strcpy(mainfn, fname); |
759 |
+ |
} |
760 |
+ |
#else |
761 |
+ |
openmain(fname) /* open fname for input, changing to its directory */ |
762 |
+ |
char *fname; |
763 |
+ |
{ |
764 |
+ |
extern FILE *tmpfile(); |
765 |
+ |
extern char *getlibpath(), *getpath(); |
766 |
+ |
static char origdir[MAXPATH]; |
767 |
+ |
static char curdir[MAXPATH]; |
768 |
+ |
char newdir[MAXPATH], *cp; |
769 |
+ |
|
770 |
+ |
if (fname == NULL) { /* standard input */ |
771 |
+ |
if (mainfp == NULL) { |
772 |
+ |
register int c; |
773 |
+ |
strcpy(mainfn, "standard input"); |
774 |
+ |
if (nrept <= 1) { |
775 |
+ |
mainfp = stdin; |
776 |
+ |
return; /* just read once */ |
777 |
+ |
} |
778 |
+ |
/* else copy */ |
779 |
+ |
if ((mainfp = tmpfile()) == NULL) { |
780 |
+ |
fprintf(stderr, |
781 |
+ |
"%s: cannot create temporary file\n", |
782 |
+ |
progname); |
783 |
+ |
exit(1); |
784 |
+ |
} |
785 |
+ |
while ((c = getc(stdin)) != EOF) |
786 |
+ |
putc(c, mainfp); |
787 |
+ |
fclose(stdin); |
788 |
+ |
} |
789 |
+ |
rewind(mainfp); /* rewind copy */ |
790 |
+ |
return; |
791 |
+ |
} |
792 |
+ |
/* get full path */ |
793 |
+ |
if ((cp = getpath(fname, getlibpath(), R_OK)) == NULL) { |
794 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
795 |
+ |
progname, fname); |
796 |
+ |
exit(1); |
797 |
+ |
} |
798 |
+ |
if (cp[0] == '.' && ISDIRSEP(cp[1])) /* remove leading ./ */ |
799 |
+ |
cp += 2; |
800 |
+ |
if (mainfp == NULL) { /* first call, initialize */ |
801 |
+ |
getwd(origdir); |
802 |
+ |
strcpy(curdir, origdir); |
803 |
+ |
} else if (!strcmp(cp, mainfn)) { /* just need to rewind? */ |
804 |
+ |
rewind(mainfp); |
805 |
+ |
return; |
806 |
+ |
} else /* else close old stream */ |
807 |
+ |
fclose(mainfp); |
808 |
+ |
/* record path name */ |
809 |
+ |
strcpy(mainfn, cp); |
810 |
+ |
if (expand) { /* get directory component */ |
811 |
+ |
if (ISDIRSEP(cp[0])) |
812 |
+ |
strcpy(newdir, cp); |
813 |
+ |
else |
814 |
+ |
sprintf(newdir, "%s%c%s", origdir, DIRSEP, cp); |
815 |
+ |
for (cp = newdir+strlen(newdir); !ISDIRSEP(cp[-1]); cp--) |
816 |
+ |
; |
817 |
+ |
*cp = '\0'; |
818 |
+ |
if (strcmp(newdir, curdir)) { /* change to new directory? */ |
819 |
+ |
if (chdir(newdir) < 0) { |
820 |
+ |
fprintf(stderr, |
821 |
+ |
"%s: cannot change directory to \"%s\"\n", |
822 |
+ |
progname, newdir); |
823 |
+ |
exit(1); |
824 |
+ |
} |
825 |
+ |
strcpy(curdir, newdir); |
826 |
+ |
} |
827 |
+ |
/* get final path component */ |
828 |
+ |
for (cp = fname+strlen(fname); |
829 |
+ |
cp > fname && !ISDIRSEP(cp[-1]); cp--) |
830 |
+ |
; |
831 |
+ |
} |
832 |
+ |
/* open the file */ |
833 |
+ |
if ((mainfp = fopen(cp, "r")) == NULL) { |
834 |
+ |
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
835 |
+ |
progname, mainfn); |
836 |
+ |
exit(1); |
837 |
+ |
} |
838 |
+ |
} |
839 |
+ |
#endif |