diff options
author | delphij <delphij@FreeBSD.org> | 2006-08-20 15:49:51 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2006-08-20 15:49:51 +0000 |
commit | 5297f4bc59da861bbe3beb5ee12839fa05e79882 (patch) | |
tree | 66e8cb2705abe3d167ba3a94a60d37c894690ff2 /contrib/less/lsystem.c | |
parent | 71cad8a96df623ac7d9129aa5e8c983df1030b0c (diff) | |
download | FreeBSD-src-5297f4bc59da861bbe3beb5ee12839fa05e79882.zip FreeBSD-src-5297f4bc59da861bbe3beb5ee12839fa05e79882.tar.gz |
Import less v394
Diffstat (limited to 'contrib/less/lsystem.c')
-rw-r--r-- | contrib/less/lsystem.c | 148 |
1 files changed, 4 insertions, 144 deletions
diff --git a/contrib/less/lsystem.c b/contrib/less/lsystem.c index eb82eec..1489351 100644 --- a/contrib/less/lsystem.c +++ b/contrib/less/lsystem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1984-2002 Mark Nudelman + * Copyright (C) 1984-2005 Mark Nudelman * * You may distribute under the terms of either the GNU General Public * License or the Less License, as specified in the README file. @@ -133,9 +133,9 @@ lsystem(cmd, donemsg) char *esccmd = shell_quote(cmd); if (esccmd != NULL) { - p = (char *) ecalloc(strlen(shell) + - strlen(esccmd) + 5, sizeof(char)); - sprintf(p, "%s %s %s", shell, shell_coption(), esccmd); + int len = strlen(shell) + strlen(esccmd) + 5; + p = (char *) ecalloc(len, sizeof(char)); + SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd); free(esccmd); } } @@ -367,143 +367,3 @@ pipe_data(cmd, spos, epos) } #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 <strings.h> -#include <errno.h> -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++; - strcpy(cmd_path, cp); - if (cp = index(cmd_path, ' ')) - *cp++ = '\0'; - strcpy(cmd, "ex "); - strcat(cmd, cmd_path); - if (cp) - { - strcat(cmd, " "); - strcat(cmd, cp); - } - 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 */ |