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 |
|
|
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; |
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 |
|
} |
769 |
|
extern FILE *tmpfile(); |
770 |
|
extern char *getlibpath(), *getpath(); |
771 |
|
static char origdir[MAXPATH]; |
772 |
< |
static char curdir[MAXPATH]; |
773 |
< |
char newdir[MAXPATH], *cp; |
772 |
> |
static char curfn[MAXPATH]; |
773 |
> |
static int diffdir; |
774 |
> |
register char *fpath; |
775 |
|
|
776 |
|
if (fname == NULL) { /* standard input */ |
777 |
|
if (mainfp == NULL) { |
795 |
|
rewind(mainfp); /* rewind copy */ |
796 |
|
return; |
797 |
|
} |
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; |
798 |
|
if (mainfp == NULL) { /* first call, initialize */ |
799 |
|
getwd(origdir); |
800 |
< |
strcpy(curdir, origdir); |
803 |
< |
} else if (!strcmp(cp, mainfn)) { /* just need to rewind? */ |
800 |
> |
} else if (!strcmp(fname, curfn)) { /* just need to rewind? */ |
801 |
|
rewind(mainfp); |
802 |
|
return; |
803 |
< |
} else /* else close old stream */ |
803 |
> |
} else { /* else close old stream */ |
804 |
|
fclose(mainfp); |
805 |
+ |
if (diffdir) { |
806 |
+ |
chdir(origdir); |
807 |
+ |
diffdir = 0; |
808 |
+ |
} |
809 |
+ |
} |
810 |
+ |
strcpy(curfn, fname); /* remember file name */ |
811 |
+ |
/* get full path */ |
812 |
+ |
if ((fpath = getpath(fname, getlibpath(), R_OK)) == NULL) { |
813 |
+ |
fprintf(stderr, "%s: cannot find file \"%s\"\n", |
814 |
+ |
progname, fname); |
815 |
+ |
exit(1); |
816 |
+ |
} |
817 |
+ |
if (fpath[0] == '.' && ISDIRSEP(fpath[1])) /* remove leading ./ */ |
818 |
+ |
fpath += 2; |
819 |
|
/* record path name */ |
820 |
< |
strcpy(mainfn, cp); |
821 |
< |
if (expand) { /* get directory component */ |
822 |
< |
if (ISDIRSEP(cp[0])) |
823 |
< |
strcpy(newdir, cp); |
824 |
< |
else |
825 |
< |
sprintf(newdir, "%s%c%s", origdir, DIRSEP, cp); |
826 |
< |
for (cp = newdir+strlen(newdir); !ISDIRSEP(cp[-1]); cp--) |
827 |
< |
; |
820 |
> |
strcpy(mainfn, fpath); |
821 |
> |
if (expand) { /* change to local directory */ |
822 |
> |
register char *cp = fpath + strlen(fpath); /* get dir. */ |
823 |
> |
while (cp > fpath) { |
824 |
> |
cp--; |
825 |
> |
if (ISDIRSEP(*cp)) { |
826 |
> |
if (cp == fpath) |
827 |
> |
cp++; /* root special case */ |
828 |
> |
break; |
829 |
> |
} |
830 |
> |
} |
831 |
|
*cp = '\0'; |
832 |
< |
if (strcmp(newdir, curdir)) { /* change to new directory? */ |
833 |
< |
if (chdir(newdir) < 0) { |
832 |
> |
if (fpath[0]) { /* change to new directory? */ |
833 |
> |
if (chdir(fpath) < 0) { |
834 |
|
fprintf(stderr, |
835 |
|
"%s: cannot change directory to \"%s\"\n", |
836 |
< |
progname, newdir); |
836 |
> |
progname, fpath); |
837 |
|
exit(1); |
838 |
|
} |
839 |
< |
strcpy(curdir, newdir); |
839 |
> |
diffdir++; |
840 |
|
} |
841 |
|
/* get final path component */ |
842 |
< |
for (cp = fname+strlen(fname); |
843 |
< |
cp > fname && !ISDIRSEP(cp[-1]); cp--) |
842 |
> |
for (fpath = fname+strlen(fname); |
843 |
> |
fpath > fname && !ISDIRSEP(fpath[-1]); fpath--) |
844 |
|
; |
845 |
|
} |
846 |
|
/* open the file */ |
847 |
< |
if ((mainfp = fopen(cp, "r")) == NULL) { |
847 |
> |
if ((mainfp = fopen(fpath, "r")) == NULL) { |
848 |
|
fprintf(stderr, "%s: cannot open file \"%s\"\n", |
849 |
|
progname, mainfn); |
850 |
|
exit(1); |