Bump to 608
[platform/upstream/less.git] / lsystem.c
old mode 100755 (executable)
new mode 100644 (file)
index 674e5a2..d817369
--- a/lsystem.c
+++ b/lsystem.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1984-2012  Mark Nudelman
+ * Copyright (C) 1984-2022  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.
 
 #if MSDOS_COMPILER
 #include <dos.h>
+#if MSDOS_COMPILER==WIN32C && defined(MINGW)
+#include <direct.h>
+#define setdisk(n) _chdrive((n)+1)
+#else
 #ifdef _MSC_VER
 #include <direct.h>
 #define setdisk(n) _chdrive((n)+1)
@@ -26,6 +30,7 @@
 #include <dir.h>
 #endif
 #endif
+#endif
 
 extern int screen_trashed;
 extern IFILE curr_ifile;
@@ -42,10 +47,10 @@ lsystem(cmd, donemsg)
        char *cmd;
        char *donemsg;
 {
-       register int inp;
+       int inp;
 #if HAVE_SHELL
-       register char *shell;
-       register char *p;
+       char *shell;
+       char *p;
 #endif
        IFILE save_ifile;
 #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C
@@ -92,7 +97,7 @@ lsystem(cmd, donemsg)
         * De-initialize the terminal and take out of raw mode.
         */
        deinit();
-       flush();        /* Make sure the deinit chars get out */
+       flush();         /* Make sure the deinit chars get out */
        raw_mode(0);
 #if MSDOS_COMPILER==WIN32C
        close_getchr();
@@ -111,11 +116,8 @@ lsystem(cmd, donemsg)
         */
        inp = dup(0);
        close(0);
-#if OS2
-       /* The __open() system call translates "/dev/tty" to "con". */
-       if (__open("/dev/tty", OPEN_READ) < 0)
-#else
-       if (open("/dev/tty", OPEN_READ) < 0)
+#if !MSDOS_COMPILER
+       if (open_tty() < 0)
 #endif
                dup(inp);
 #endif
@@ -137,7 +139,7 @@ lsystem(cmd, donemsg)
                        char *esccmd = shell_quote(cmd);
                        if (esccmd != NULL)
                        {
-                               int len = strlen(shell) + strlen(esccmd) + 5;
+                               int len = (int) (strlen(shell) + strlen(esccmd) + 5);
                                p = (char *) ecalloc(len, sizeof(char));
                                SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd);
                                free(esccmd);
@@ -164,7 +166,7 @@ lsystem(cmd, donemsg)
         * also makes trouble with some DPMI servers).
         */
        __djgpp_exception_toggle();
-       system(cmd);
+       system(cmd);
        __djgpp_exception_toggle();
 #else
        system(cmd);
@@ -269,14 +271,14 @@ pipe_mark(c, cmd)
                tpos = ch_zero();
        bpos = position(BOTTOM);
 
-       if (c == '.') 
-               return (pipe_data(cmd, tpos, bpos));
-       else if (mpos <= tpos)
-               return (pipe_data(cmd, mpos, bpos));
-       else if (bpos == NULL_POSITION)
-               return (pipe_data(cmd, tpos, bpos));
-       else
-               return (pipe_data(cmd, tpos, mpos));
+       if (c == '.') 
+               return (pipe_data(cmd, tpos, bpos));
+       else if (mpos <= tpos)
+               return (pipe_data(cmd, mpos, bpos));
+       else if (bpos == NULL_POSITION)
+               return (pipe_data(cmd, tpos, bpos));
+       else
+               return (pipe_data(cmd, tpos, mpos));
 }
 
 /*
@@ -289,9 +291,8 @@ pipe_data(cmd, spos, epos)
        POSITION spos;
        POSITION epos;
 {
-       register FILE *f;
-       register int c;
-       extern FILE *popen();
+       FILE *f;
+       int c;
 
        /*
         * This is structured much like lsystem().
@@ -342,14 +343,14 @@ pipe_data(cmd, spos, epos)
        /*
         * Finish up the last line.
         */
-       while (c != '\n' && c != EOI ) 
-       {
-               c = ch_forw_get();
-               if (c == EOI)
-                       break;
-               if (putc(c, f) == EOF)
-                       break;
-       }
+       while (c != '\n' && c != EOI ) 
+       {
+               c = ch_forw_get();
+               if (c == EOI)
+                       break;
+               if (putc(c, f) == EOF)
+                       break;
+       }
 
        pclose(f);