[BACK]Return to lsystem.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/lsystem.c between version 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2003/04/13 18:21:21 version 1.1.1.3, 2011/09/16 17:47:06
Line 1 
Line 1 
 /*  /*
  * Copyright (C) 1984-2002  Mark Nudelman   * Copyright (C) 1984-2011  Mark Nudelman
  *   *
  * You may distribute under the terms of either the GNU General Public   * You may distribute under the terms of either the GNU General Public
  * License or the Less License, as specified in the README file.   * License or the Less License, as specified in the README file.
Line 49 
Line 49 
         register char *p;          register char *p;
 #endif  #endif
         IFILE save_ifile;          IFILE save_ifile;
 #if MSDOS_COMPILER  #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C
         char cwd[FILENAME_MAX+1];          char cwd[FILENAME_MAX+1];
 #endif  #endif
   
Line 68 
Line 68 
         }          }
   
 #if MSDOS_COMPILER  #if MSDOS_COMPILER
   #if MSDOS_COMPILER==WIN32C
           if (*cmd == '\0')
                   cmd = getenv("COMSPEC");
   #else
         /*          /*
          * Working directory is global on MSDOS.           * Working directory is global on MSDOS.
          * The child might change the working directory, so we           * The child might change the working directory, so we
Line 77 
Line 81 
          */           */
         getcwd(cwd, FILENAME_MAX);          getcwd(cwd, FILENAME_MAX);
 #endif  #endif
   #endif
   
         /*          /*
          * Close the current input file.           * Close the current input file.
Line 133 
Line 138 
                         char *esccmd = shell_quote(cmd);                          char *esccmd = shell_quote(cmd);
                         if (esccmd != NULL)                          if (esccmd != NULL)
                         {                          {
                                 p = (char *) ecalloc(strlen(shell) +                                  int len = strlen(shell) + strlen(esccmd) + 5;
                                         strlen(esccmd) + 5, sizeof(char));                                  p = (char *) ecalloc(len, sizeof(char));
                                 sprintf(p, "%s %s %s", shell, shell_coption(), esccmd);                                  SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd);
                                 free(esccmd);                                  free(esccmd);
                         }                          }
                 }                  }
Line 192 
Line 197 
         init();          init();
         screen_trashed = 1;          screen_trashed = 1;
   
 #if MSDOS_COMPILER  #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C
         /*          /*
          * Restore the previous directory (possibly           * Restore the previous directory (possibly
          * changed by the child program we just ran).           * changed by the child program we just ran).
Line 367 
Line 372 
 }  }
   
 #endif  #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 */  

Legend:
Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3