1 |
– |
/* Copyright (c) 1996 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* xform.c - program to transform object files. |
6 |
|
* Transformations must preserve aspect ratio. |
34 |
|
|
35 |
|
char *idprefix; /* prefix for object identifiers */ |
36 |
|
|
37 |
< |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
37 |
> |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* default types and actions */ |
38 |
|
|
42 |
– |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
43 |
– |
|
44 |
– |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
45 |
– |
|
39 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
40 |
|
|
41 |
|
int nrept = 1; /* number of array repetitions */ |
42 |
|
|
43 |
|
int stdinused = 0; /* stdin has been used by -f option? */ |
44 |
|
|
52 |
– |
extern char *malloc(), *fgets(), *fgetword(); |
53 |
– |
|
45 |
|
char mainfn[MAXPATH]; /* main file name */ |
46 |
|
FILE *mainfp = NULL; /* main file pointer */ |
47 |
|
|
95 |
|
sprintf(newp, "%s.%s", |
96 |
|
idprefix, argv[a]); |
97 |
|
if (mal_prefix++) |
98 |
< |
free((char *)idprefix); |
98 |
> |
free((void *)idprefix); |
99 |
|
idprefix = newp; |
100 |
|
} |
101 |
|
continue; |
156 |
|
} |
157 |
|
|
158 |
|
if (mal_prefix) |
159 |
< |
free((char *)idprefix); |
159 |
> |
free((void *)idprefix); |
160 |
|
return(0); |
161 |
|
} |
162 |
|
|
165 |
|
char **av; |
166 |
|
int ac, fi; |
167 |
|
{ |
168 |
+ |
int inquote; |
169 |
|
char *newav[256], **avp; |
170 |
|
char argbuf[1024]; |
171 |
|
char newid[128]; |
180 |
|
} |
181 |
|
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
182 |
|
if (stdinused++) { |
183 |
< |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
183 |
> |
fprintf(stderr, |
184 |
> |
"%s: cannot use stdin more than once\n", |
185 |
|
av[0]); |
186 |
|
exit(1); |
187 |
|
} |
189 |
|
n = 100; /* we just don't know! */ |
190 |
|
} else { |
191 |
|
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
192 |
< |
fprintf(stderr, "%s: cannot open argument file \"%s\"\n", |
192 |
> |
fprintf(stderr, |
193 |
> |
"%s: cannot open argument file \"%s\"\n", |
194 |
|
av[0], av[fi+1]); |
195 |
|
exit(1); |
196 |
|
} |
197 |
|
n = 0; /* count number of lines in file */ |
198 |
< |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) |
199 |
< |
n += argbuf[0] != '\n' & argbuf[0] != '#'; |
198 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) |
199 |
> |
n += argbuf[0] && argbuf[0] != '#'; |
200 |
|
if (!n) { |
201 |
|
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
202 |
|
av[0], av[fi+1]); |
206 |
|
rewind(argfp); |
207 |
|
} |
208 |
|
err = 0; k = 0; /* read each arg list and call main */ |
209 |
< |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) { |
210 |
< |
if (argbuf[0] == '\n' | argbuf[0] == '#') |
209 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { |
210 |
> |
if (!argbuf[0] || argbuf[0] == '#') |
211 |
|
continue; |
212 |
|
avp = newav+2; |
213 |
|
avp[0] = av[0]; |
217 |
|
cp = argbuf; /* parse new words */ |
218 |
|
if (*cp == '!') cp++; |
219 |
|
if (!strncmp(cp, "xform ", 6)) cp += 6; |
220 |
+ |
inquote = 0; |
221 |
|
for ( ; ; ) { |
222 |
+ |
skipspaces: |
223 |
|
while (isspace(*cp)) /* nullify spaces */ |
224 |
|
*cp++ = '\0'; |
225 |
+ |
if ((*cp == '"' | *cp == '\'')) |
226 |
+ |
inquote = *cp++; |
227 |
|
if (!*cp) /* all done? */ |
228 |
|
break; |
229 |
+ |
if (cp[0] == '\\' && cp[1]) |
230 |
+ |
if (*++cp == '\n') |
231 |
+ |
goto skipspaces; |
232 |
|
avp[newac++] = cp; /* add argument to list */ |
233 |
< |
while (*++cp && !isspace(*cp)) |
234 |
< |
; |
233 |
> |
if (inquote) { |
234 |
> |
while (*++cp) |
235 |
> |
if (*cp == inquote) { |
236 |
> |
*cp++ = '\0'; |
237 |
> |
break; |
238 |
> |
} |
239 |
> |
} else { |
240 |
> |
while (*++cp && !isspace(*cp)) |
241 |
> |
; |
242 |
> |
} |
243 |
|
} |
244 |
|
for (i = fi+2; i < ac; i++) |
245 |
|
avp[newac++] = av[i]; |
352 |
|
char *fname; |
353 |
|
FILE *fin; |
354 |
|
{ |
346 |
– |
extern FILE *popen(); |
347 |
– |
extern char *fgetline(); |
355 |
|
FILE *pin; |
356 |
|
char buf[512]; |
357 |
|
int i; |
368 |
|
} else { |
369 |
|
printf("\n%s", buf); |
370 |
|
if (xac > 1) { |
371 |
< |
printf(" | %s", xav[0]); |
371 |
> |
printf(" | %s -e", xav[0]); /* expand next time */ |
372 |
|
for (i = 1; i < xac; i++) |
373 |
< |
printf(" %s", xav[i]); |
373 |
> |
if (i >= xfa || strcmp(xav[i], "-c")) |
374 |
> |
printf(" %s", xav[i]); |
375 |
|
} |
376 |
|
putchar('\n'); |
377 |
|
} |
382 |
|
char *fname; |
383 |
|
FILE *fin; |
384 |
|
{ |
377 |
– |
extern char *strcpy(); |
385 |
|
char typ[16], nam[MAXSTR]; |
386 |
|
int fn; |
387 |
|
/* modifier and type */ |
423 |
|
return(-1); |
424 |
|
/* string arguments */ |
425 |
|
printf("%d", fa.nsargs); |
426 |
< |
for (i = 0; i < fa.nsargs; i++) |
427 |
< |
printf(" %s", fa.sarg[i]); |
426 |
> |
for (i = 0; i < fa.nsargs; i++) { |
427 |
> |
fputc(' ', stdout); |
428 |
> |
fputword(fa.sarg[i], stdout); |
429 |
> |
} |
430 |
|
printf("\n"); |
431 |
|
#ifdef IARGS |
432 |
|
/* integer arguments */ |
460 |
|
if (xac > xfa && strcmp(xav[xfa], "-i")) |
461 |
|
resetarr = 2; |
462 |
|
printf("%d", fa.nsargs + resetarr + xac-xfa); |
463 |
< |
for (i = 0; i < fa.nsargs; i++) |
464 |
< |
printf(" %s", fa.sarg[i]); |
463 |
> |
for (i = 0; i < fa.nsargs; i++) { |
464 |
> |
fputc(' ', stdout); |
465 |
> |
fputword(fa.sarg[i], stdout); |
466 |
> |
} |
467 |
|
if (resetarr) |
468 |
|
printf(" -i 1"); |
469 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
488 |
|
} |
489 |
|
|
490 |
|
|
480 |
– |
int |
481 |
– |
otype(ofname) /* get object function number from its name */ |
482 |
– |
register char *ofname; |
483 |
– |
{ |
484 |
– |
register int i; |
485 |
– |
|
486 |
– |
for (i = 0; i < NUMTYPES; i++) |
487 |
– |
if (!strcmp(ofun[i].funame, ofname)) |
488 |
– |
return(i); |
489 |
– |
|
490 |
– |
return(-1); /* not found */ |
491 |
– |
} |
492 |
– |
|
493 |
– |
|
491 |
|
alias(fin) /* transfer alias */ |
492 |
|
FILE *fin; |
493 |
|
{ |
638 |
|
return(-1); |
639 |
|
/* string arguments */ |
640 |
|
printf("%d", fa.nsargs); |
641 |
< |
for (i = 0; i < fa.nsargs; i++) |
642 |
< |
printf(" %s", fa.sarg[i]); |
641 |
> |
for (i = 0; i < fa.nsargs; i++) { |
642 |
> |
fputc(' ', stdout); |
643 |
> |
fputword(fa.sarg[i], stdout); |
644 |
> |
} |
645 |
|
printf("\n0\n%d\n", fa.nfargs); |
646 |
|
/* anchor point */ |
647 |
|
multp3(v, fa.farg, tot.xfm); |
824 |
|
|
825 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
826 |
|
return; /* done already */ |
828 |
– |
/* alias is additional */ |
829 |
– |
ofun[ALIAS].funame = ALIASID; |
830 |
– |
ofun[ALIAS].flags = 0; |
827 |
|
/* functions get new transform */ |
828 |
< |
for (i = 0; i < NUMTYPES; i++) |
828 |
> |
for (i = 0; i < NUMOTYPE; i++) |
829 |
|
if (hasfunc(i)) |
830 |
|
ofun[i].funp = addxform; |
831 |
|
/* special cases */ |
847 |
|
ofun[PAT_CTEXT].funp = |
848 |
|
ofun[PAT_BTEXT].funp = |
849 |
|
ofun[MIX_TEXT].funp = text; |
850 |
< |
ofun[ALIAS].funp = alias; |
850 |
> |
ofun[MOD_ALIAS].funp = alias; |
851 |
|
/* surface inverses */ |
852 |
|
tinvers[OBJ_FACE] = OBJ_FACE; |
853 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
886 |
|
strcpy(mainfn, fname); |
887 |
|
} |
888 |
|
#else |
889 |
< |
openmain(fname) /* open fname for input, changing to its directory */ |
890 |
< |
char *fname; |
889 |
> |
openmain(iname) /* open input, changing directory for file */ |
890 |
> |
char *iname; |
891 |
|
{ |
896 |
– |
extern FILE *tmpfile(); |
897 |
– |
extern char *getlibpath(), *getpath(); |
892 |
|
static char origdir[MAXPATH]; |
893 |
|
static char curfn[MAXPATH]; |
894 |
|
static int diffdir; |
895 |
|
register char *fpath; |
896 |
|
|
897 |
< |
if (fname == NULL) { /* standard input */ |
897 |
> |
if (iname == NULL) { /* standard input */ |
898 |
|
if (mainfp == NULL) { |
899 |
|
register int c; |
900 |
|
strcpy(mainfn, "standard input"); |
911 |
|
} |
912 |
|
while ((c = getc(stdin)) != EOF) |
913 |
|
putc(c, mainfp); |
920 |
– |
fclose(stdin); |
914 |
|
} |
915 |
|
rewind(mainfp); /* rewind copy */ |
916 |
|
return; |
917 |
|
} |
918 |
|
if (mainfp == NULL) { /* first call, initialize */ |
919 |
|
getwd(origdir); |
920 |
< |
} else if (!strcmp(fname, curfn)) { /* just need to rewind? */ |
920 |
> |
} else if (!strcmp(iname, curfn)) { /* just need to rewind? */ |
921 |
|
rewind(mainfp); |
922 |
|
return; |
923 |
|
} else { /* else close old stream */ |
924 |
|
fclose(mainfp); |
925 |
< |
if (diffdir) { |
925 |
> |
mainfp = NULL; |
926 |
> |
if (diffdir) { /* return to our directory */ |
927 |
|
chdir(origdir); |
928 |
|
diffdir = 0; |
929 |
|
} |
930 |
|
} |
931 |
< |
strcpy(curfn, fname); /* remember file name */ |
932 |
< |
/* get full path */ |
933 |
< |
if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) { |
931 |
> |
strcpy(curfn, iname); /* remember input name */ |
932 |
> |
/* get full path for file */ |
933 |
> |
if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) { |
934 |
|
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
935 |
< |
progname, fname); |
935 |
> |
progname, iname); |
936 |
|
exit(1); |
937 |
|
} |
938 |
|
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
960 |
|
diffdir++; |
961 |
|
} |
962 |
|
/* get final path component */ |
963 |
< |
for (fpath = fname+strlen(fname); |
964 |
< |
fpath > fname && !ISDIRSEP(fpath[-1]); fpath--) |
963 |
> |
for (fpath = iname+strlen(iname); |
964 |
> |
fpath > iname && !ISDIRSEP(fpath[-1]); fpath--) |
965 |
|
; |
966 |
|
} |
967 |
< |
/* open the file */ |
967 |
> |
/* finally, open the file */ |
968 |
|
if ((mainfp = fopen(fpath, "r")) == NULL) { |
969 |
|
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
970 |
|
progname, mainfn); |