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. |
9 |
|
* 11/6/86 Finally added error checking! |
10 |
|
*/ |
11 |
|
|
15 |
– |
#include "standard.h" |
16 |
– |
|
17 |
– |
#include "paths.h" |
18 |
– |
|
12 |
|
#include <ctype.h> |
13 |
|
|
14 |
+ |
#include "standard.h" |
15 |
+ |
#include "platform.h" |
16 |
+ |
#include "paths.h" |
17 |
|
#include "object.h" |
22 |
– |
|
18 |
|
#include "otypes.h" |
19 |
|
|
20 |
|
int xac; /* global xform argument count */ |
32 |
|
|
33 |
|
char *idprefix; /* prefix for object identifiers */ |
34 |
|
|
35 |
< |
#define ALIAS NUMOTYPE /* put alias at end of array */ |
35 |
> |
FUN ofun[NUMOTYPE] = INIT_OTYPE; /* default types and actions */ |
36 |
|
|
42 |
– |
#define NUMTYPES (NUMOTYPE+1) /* total number of object types */ |
43 |
– |
|
44 |
– |
FUN ofun[NUMTYPES] = INIT_OTYPE; /* default types and actions */ |
45 |
– |
|
37 |
|
short tinvers[NUMOTYPE]; /* inverse types for surfaces */ |
38 |
|
|
39 |
|
int nrept = 1; /* number of array repetitions */ |
40 |
|
|
41 |
|
int stdinused = 0; /* stdin has been used by -f option? */ |
42 |
|
|
43 |
< |
extern char *malloc(), *fgets(), *fgetword(); |
53 |
< |
|
54 |
< |
char mainfn[MAXPATH]; /* main file name */ |
43 |
> |
char mainfn[PATH_MAX]; /* main file name */ |
44 |
|
FILE *mainfp = NULL; /* main file pointer */ |
45 |
|
|
46 |
|
#define progname (xav[0]) |
93 |
|
sprintf(newp, "%s.%s", |
94 |
|
idprefix, argv[a]); |
95 |
|
if (mal_prefix++) |
96 |
< |
free((char *)idprefix); |
96 |
> |
free((void *)idprefix); |
97 |
|
idprefix = newp; |
98 |
|
} |
99 |
|
continue; |
154 |
|
} |
155 |
|
|
156 |
|
if (mal_prefix) |
157 |
< |
free((char *)idprefix); |
157 |
> |
free((void *)idprefix); |
158 |
|
return(0); |
159 |
|
} |
160 |
|
|
163 |
|
char **av; |
164 |
|
int ac, fi; |
165 |
|
{ |
166 |
+ |
int inquote; |
167 |
|
char *newav[256], **avp; |
168 |
|
char argbuf[1024]; |
169 |
|
char newid[128]; |
178 |
|
} |
179 |
|
if (av[fi+1][0] == '-' && av[fi+1][1] == '\0') { |
180 |
|
if (stdinused++) { |
181 |
< |
fprintf(stderr, "%s: cannot use stdin more than once\n", |
181 |
> |
fprintf(stderr, |
182 |
> |
"%s: cannot use stdin more than once\n", |
183 |
|
av[0]); |
184 |
|
exit(1); |
185 |
|
} |
187 |
|
n = 100; /* we just don't know! */ |
188 |
|
} else { |
189 |
|
if ((argfp = fopen(av[fi+1], "r")) == NULL) { |
190 |
< |
fprintf(stderr, "%s: cannot open argument file \"%s\"\n", |
190 |
> |
fprintf(stderr, |
191 |
> |
"%s: cannot open argument file \"%s\"\n", |
192 |
|
av[0], av[fi+1]); |
193 |
|
exit(1); |
194 |
|
} |
195 |
|
n = 0; /* count number of lines in file */ |
196 |
< |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) |
197 |
< |
n += argbuf[0] != '\n' & argbuf[0] != '#'; |
196 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) |
197 |
> |
n += argbuf[0] && argbuf[0] != '#'; |
198 |
|
if (!n) { |
199 |
|
fprintf(stderr, "%s: empty argument file \"%s\"\n", |
200 |
|
av[0], av[fi+1]); |
204 |
|
rewind(argfp); |
205 |
|
} |
206 |
|
err = 0; k = 0; /* read each arg list and call main */ |
207 |
< |
while (fgets(argbuf,sizeof(argbuf),argfp) != NULL) { |
208 |
< |
if (argbuf[0] == '\n' | argbuf[0] == '#') |
207 |
> |
while (fgetline(argbuf,sizeof(argbuf),argfp) != NULL) { |
208 |
> |
if (!argbuf[0] || argbuf[0] == '#') |
209 |
|
continue; |
210 |
|
avp = newav+2; |
211 |
|
avp[0] = av[0]; |
215 |
|
cp = argbuf; /* parse new words */ |
216 |
|
if (*cp == '!') cp++; |
217 |
|
if (!strncmp(cp, "xform ", 6)) cp += 6; |
218 |
+ |
inquote = 0; |
219 |
|
for ( ; ; ) { |
220 |
+ |
skipspaces: |
221 |
|
while (isspace(*cp)) /* nullify spaces */ |
222 |
|
*cp++ = '\0'; |
223 |
+ |
if ((*cp == '"' | *cp == '\'')) |
224 |
+ |
inquote = *cp++; |
225 |
|
if (!*cp) /* all done? */ |
226 |
|
break; |
227 |
+ |
if (cp[0] == '\\' && cp[1]) |
228 |
+ |
if (*++cp == '\n') |
229 |
+ |
goto skipspaces; |
230 |
|
avp[newac++] = cp; /* add argument to list */ |
231 |
< |
while (*++cp && !isspace(*cp)) |
232 |
< |
; |
231 |
> |
if (inquote) { |
232 |
> |
while (*++cp) |
233 |
> |
if (*cp == inquote) { |
234 |
> |
*cp++ = '\0'; |
235 |
> |
break; |
236 |
> |
} |
237 |
> |
} else { |
238 |
> |
while (*++cp && !isspace(*cp)) |
239 |
> |
; |
240 |
> |
} |
241 |
|
} |
242 |
|
for (i = fi+2; i < ac; i++) |
243 |
|
avp[newac++] = av[i]; |
350 |
|
char *fname; |
351 |
|
FILE *fin; |
352 |
|
{ |
346 |
– |
extern FILE *popen(); |
347 |
– |
extern char *fgetline(); |
353 |
|
FILE *pin; |
354 |
|
char buf[512]; |
355 |
|
int i; |
380 |
|
char *fname; |
381 |
|
FILE *fin; |
382 |
|
{ |
378 |
– |
extern char *strcpy(); |
383 |
|
char typ[16], nam[MAXSTR]; |
384 |
|
int fn; |
385 |
|
/* modifier and type */ |
421 |
|
return(-1); |
422 |
|
/* string arguments */ |
423 |
|
printf("%d", fa.nsargs); |
424 |
< |
for (i = 0; i < fa.nsargs; i++) |
425 |
< |
printf(" %s", fa.sarg[i]); |
424 |
> |
for (i = 0; i < fa.nsargs; i++) { |
425 |
> |
fputc(' ', stdout); |
426 |
> |
fputword(fa.sarg[i], stdout); |
427 |
> |
} |
428 |
|
printf("\n"); |
429 |
|
#ifdef IARGS |
430 |
|
/* integer arguments */ |
458 |
|
if (xac > xfa && strcmp(xav[xfa], "-i")) |
459 |
|
resetarr = 2; |
460 |
|
printf("%d", fa.nsargs + resetarr + xac-xfa); |
461 |
< |
for (i = 0; i < fa.nsargs; i++) |
462 |
< |
printf(" %s", fa.sarg[i]); |
461 |
> |
for (i = 0; i < fa.nsargs; i++) { |
462 |
> |
fputc(' ', stdout); |
463 |
> |
fputword(fa.sarg[i], stdout); |
464 |
> |
} |
465 |
|
if (resetarr) |
466 |
|
printf(" -i 1"); |
467 |
|
for (i = xfa; i < xac; i++) /* add xf arguments */ |
486 |
|
} |
487 |
|
|
488 |
|
|
481 |
– |
int |
482 |
– |
otype(ofname) /* get object function number from its name */ |
483 |
– |
register char *ofname; |
484 |
– |
{ |
485 |
– |
register int i; |
486 |
– |
|
487 |
– |
for (i = 0; i < NUMTYPES; i++) |
488 |
– |
if (!strcmp(ofun[i].funame, ofname)) |
489 |
– |
return(i); |
490 |
– |
|
491 |
– |
return(-1); /* not found */ |
492 |
– |
} |
493 |
– |
|
494 |
– |
|
489 |
|
alias(fin) /* transfer alias */ |
490 |
|
FILE *fin; |
491 |
|
{ |
636 |
|
return(-1); |
637 |
|
/* string arguments */ |
638 |
|
printf("%d", fa.nsargs); |
639 |
< |
for (i = 0; i < fa.nsargs; i++) |
640 |
< |
printf(" %s", fa.sarg[i]); |
639 |
> |
for (i = 0; i < fa.nsargs; i++) { |
640 |
> |
fputc(' ', stdout); |
641 |
> |
fputword(fa.sarg[i], stdout); |
642 |
> |
} |
643 |
|
printf("\n0\n%d\n", fa.nfargs); |
644 |
|
/* anchor point */ |
645 |
|
multp3(v, fa.farg, tot.xfm); |
822 |
|
|
823 |
|
if (ofun[OBJ_SOURCE].funp == o_source) |
824 |
|
return; /* done already */ |
829 |
– |
/* alias is additional */ |
830 |
– |
ofun[ALIAS].funame = ALIASID; |
831 |
– |
ofun[ALIAS].flags = 0; |
825 |
|
/* functions get new transform */ |
826 |
< |
for (i = 0; i < NUMTYPES; i++) |
826 |
> |
for (i = 0; i < NUMOTYPE; i++) |
827 |
|
if (hasfunc(i)) |
828 |
|
ofun[i].funp = addxform; |
829 |
|
/* special cases */ |
845 |
|
ofun[PAT_CTEXT].funp = |
846 |
|
ofun[PAT_BTEXT].funp = |
847 |
|
ofun[MIX_TEXT].funp = text; |
848 |
< |
ofun[ALIAS].funp = alias; |
848 |
> |
ofun[MOD_ALIAS].funp = alias; |
849 |
|
/* surface inverses */ |
850 |
|
tinvers[OBJ_FACE] = OBJ_FACE; |
851 |
|
tinvers[OBJ_SOURCE] = OBJ_SOURCE; |
884 |
|
strcpy(mainfn, fname); |
885 |
|
} |
886 |
|
#else |
887 |
< |
openmain(fname) /* open fname for input, changing to its directory */ |
888 |
< |
char *fname; |
887 |
> |
openmain(iname) /* open input, changing directory for file */ |
888 |
> |
char *iname; |
889 |
|
{ |
890 |
< |
extern FILE *tmpfile(); |
891 |
< |
extern char *getlibpath(), *getpath(); |
899 |
< |
static char origdir[MAXPATH]; |
900 |
< |
static char curfn[MAXPATH]; |
890 |
> |
static char origdir[PATH_MAX]; |
891 |
> |
static char curfn[PATH_MAX]; |
892 |
|
static int diffdir; |
893 |
|
register char *fpath; |
894 |
|
|
895 |
< |
if (fname == NULL) { /* standard input */ |
895 |
> |
if (iname == NULL) { /* standard input */ |
896 |
|
if (mainfp == NULL) { |
897 |
|
register int c; |
898 |
|
strcpy(mainfn, "standard input"); |
909 |
|
} |
910 |
|
while ((c = getc(stdin)) != EOF) |
911 |
|
putc(c, mainfp); |
921 |
– |
fclose(stdin); |
912 |
|
} |
913 |
|
rewind(mainfp); /* rewind copy */ |
914 |
|
return; |
915 |
|
} |
916 |
|
if (mainfp == NULL) { /* first call, initialize */ |
917 |
< |
getwd(origdir); |
918 |
< |
} else if (!strcmp(fname, curfn)) { /* just need to rewind? */ |
917 |
> |
getcwd(origdir, sizeof(origdir)); |
918 |
> |
} else if (!strcmp(iname, curfn)) { /* just need to rewind? */ |
919 |
|
rewind(mainfp); |
920 |
|
return; |
921 |
|
} else { /* else close old stream */ |
922 |
|
fclose(mainfp); |
923 |
< |
if (diffdir) { |
923 |
> |
mainfp = NULL; |
924 |
> |
if (diffdir) { /* return to our directory */ |
925 |
|
chdir(origdir); |
926 |
|
diffdir = 0; |
927 |
|
} |
928 |
|
} |
929 |
< |
strcpy(curfn, fname); /* remember file name */ |
930 |
< |
/* get full path */ |
931 |
< |
if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) { |
929 |
> |
strcpy(curfn, iname); /* remember input name */ |
930 |
> |
/* get full path for file */ |
931 |
> |
if ((fpath = getpath(iname, getrlibpath(), R_OK)) == NULL) { |
932 |
|
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
933 |
< |
progname, fname); |
933 |
> |
progname, iname); |
934 |
|
exit(1); |
935 |
|
} |
936 |
|
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
958 |
|
diffdir++; |
959 |
|
} |
960 |
|
/* get final path component */ |
961 |
< |
for (fpath = fname+strlen(fname); |
962 |
< |
fpath > fname && !ISDIRSEP(fpath[-1]); fpath--) |
961 |
> |
for (fpath = iname+strlen(iname); |
962 |
> |
fpath > iname && !ISDIRSEP(fpath[-1]); fpath--) |
963 |
|
; |
964 |
|
} |
965 |
< |
/* open the file */ |
965 |
> |
/* finally, open the file */ |
966 |
|
if ((mainfp = fopen(fpath, "r")) == NULL) { |
967 |
|
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
968 |
|
progname, mainfn); |