#-h- argssym 23 asc 12-oct-80 17:21:32 define(ESCAPE,ATSIGN) #-h- args.r 2734 asc 12-oct-80 17:21:33 #-h- args.q 1990 asc 12-oct-80 17:05:22 include argssym subroutine main character name(FILENAMESIZE), arg(MAXLINE), args(ARGBUFSIZE), image(FILENAMESIZE), pid(PIDSIZE) integer k, i, n, type, verbos, count integer getarg, getlin, length, loccom, spawn string sh "sh" string local "local" verbos = NO for (i=1; getarg(i, arg, MAXLINE) != EOF; i=i+1) if (arg(1) != MINUS) break else if (arg(2) == LETV | arg(2) == BIGV) verbos = YES else { call putlin(arg, ERROUT) call remark(" : ignoring invalid argument.") } if (getarg(i, name, FILENAMESIZE) == EOF) call error("usage: args [-v] tool [arguments].") k = 1 count = 1 for ( ; getarg(i, arg, MAXLINE) != EOF; i=i+1) { call packit(count, arg, args, k, ARGBUFSIZE) count = count + 1 } for (n=getlin(arg, STDIN); n != EOF; n=getlin(arg, STDIN)) if (n > 1) { arg(n) = EOS call packit(count, arg, args, k, ARGBUFSIZE) count = count + 1 } args(k) = EOS # terminate string # # build search path # :~home:~usr:~bin # arg(1) = EOS # current directory first i = 2 call mailid(image, arg(i)) # home directory i = i + length(arg(i)) + 1 call getdir(USRDIRECTORY, LOCAL, arg(i)) # usr directory i = i + length(arg(i)) + 1 call getdir(BINDIRECTORY, LOCAL, arg(i)) # bin directory i = i + length(arg(i)) + 1 arg(i) = NEWLINE # end of path arg(i+1) = EOS # # now find the process and spawn it # type = loccom(name, arg, image) if (type == ERR) call scopy(local, 1, image, 1) else if (type == ASCII) if (loccom(sh, arg, image) != BINARY) call error("Cannot locate shell image file.") else { i = 1 call stcopy(sh, 1, arg, i) call chcopy(BLANK, arg, i) call scopy(args, 1, arg, i) for (i=1; arg(i) != EOS; i=i+1) if (i < ARGBUFSIZE) args(i) = arg(i) else break args(i) = EOS } if (verbos == YES) call remark(args) if (spawn(image, args, pid, WAIT) == ERR) { call remark(args) call remark("** Error spawning this command from args. **") } return end #-h- packit.q 447 asc 22-aug-80 08:26:10 subroutine packit(n, in, out, outptr, size) integer n, outptr, size, j, len integer length, index character in(ARB), out(ARB) string redir "<>?" if (n > 1) if (outptr < size) call chcopy(BLANK, out, outptr) else call sizerr(out, outptr) j = 1 if (in(1) == ESCAPE) if (index(redir, in(2)) > 0) j = 2 len = length(in(j)) if (outptr+len >= size) call sizerr(out, outptr) call stcopy(in, j, out, outptr) return end #-h- sizerr.q 150 asc 22-aug-80 08:26:10 subroutine sizerr(buf, n) integer n character buf(ARB) buf(n) = EOS call remark(buf) call error("** Command line too long. **") return end