=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/lsystem.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/less/lsystem.c 2004/12/19 13:27:08 1.6 --- src/usr.bin/less/lsystem.c 2007/04/19 05:56:45 1.7 *************** *** 368,510 **** } #endif - - #ifdef _OSK - /* - * Popen, and Pclose, for OS-9. - * - * Based on code copyright (c) 1988 by Wolfgang Ocker, Puchheim, - * Ulli Dessauer, Germering and - * Reimer Mellin, Muenchen - * (W-Germany) - * - * These functions can be copied and distributed freely for any - * non-commercial purposes. It can only be incorporated into - * commercial software with the written permission of the authors. - * - * TOP-specific code stripped out and adapted for less by M.Gregorie, 1996 - * - * address: Wolfgang Ocker - * Lochhauserstrasse 35a - * D-8039 Puchheim - * West Germany - * - * e-mail: weo@altger.UUCP, ud@altger.UUCP, ram@altger.UUCP - * pyramid!tmpmbx!recco!weo - * pyramid!tmpmbx!nitmar!ud - * pyramid!tmpmbx!ramsys!ram - * - * Martin Gregorie - * 10 Sadlers Mead - * Harlow - * Essex, CM18 6HG - * U.K. - * - * gregorie@logica.com - */ - #include - #include - extern char **environ; - extern char *getenv(); - extern int os9forkc(); - static int pids[_NFILE] = { 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 }; - /* - * p o p e n - */ - FILE *popen(name, mode) - char *name; - char *mode; - { - int fd, fd2, fdsav, pid; - static char *argv[] = {NULL, NULL, NULL }; - static char cmd[200]; - static char cmd_path[200]; - char *cp; - char *shell; - FILE *r; - if ((shell = getenv("SHELL")) == NULL) - return(NULL); - cp = name; - while (*cp == ' ') - cp++; - strlcpy(cmd_path, cp, sizeof(cmd_path)); - if (cp = strchr(cmd_path, ' ')) - *cp++ = '\0'; - strlcpy(cmd, "ex ", sizeof(cmd)); - strlcat(cmd, cmd_path, sizeof(cmd)); - if (cp) - { - strlcat(cmd, " ", sizeof(cmd)); - strlcat(cmd, cp, sizeof(cmd)); - } - argv[0] = shell; - argv[1] = cmd; - /* - mode is "r" (stdout) or "w" (stdin) - */ - switch(mode[0]) - { - case 'w': fd = 0; - break; - case 'r': fd = 1; - break; - default: return(NULL); - } - if (fd == 1) - fflush(stdout); - fdsav = dup(fd); - close(fd); - - creat("/pipe", S_IWRITE+S_IREAD); - pid = os9exec(os9forkc, argv[0], argv, environ, 0, 0, 3); - fd2 = dup(fd); - close(fd); - dup(fdsav); - close(fdsav); - if (pid > 0) - { - pids[fd2] = pid; - r = fdopen(fd2, mode); - } - else - { - close(fd2); - r = NULL; - } - return(r); - } - - /* - * p c l o s e - */ - int pclose(fp) - FILE *fp; - { - unsigned int status; - int pid; - int fd, - i; - fd = fileno(fp); - if (pids[fd] == 0) - return(-1); - fflush(fp); - fclose(fp); - while ((pid = wait(&status)) != -1) - if (pid == pids[fd]) - break; - else - for (i = 0; i < _NFILE; i++) - if (pids[i] == pid) - { - pids[i] = 0; - break; - } - if (pid == -1) - status = -1; - pids[fd] = 0; - return(status); - } - #endif /* _OSK */ --- 368,370 ----