groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 02/02: Improve native Windows port.


From: Werner LEMBERG
Subject: [groff] 02/02: Improve native Windows port.
Date: Thu, 20 Nov 2014 18:46:16 +0000

wl pushed a commit to branch master
in repository groff.

commit 6360d7c66deea677de7260e1efacfce3daa55d85
Author: Eli Zaretskii <address@hidden>
Date:   Thu Nov 20 19:45:17 2014 +0100

    Improve native Windows port.
    
    This patch fixes two issues.
    
      . Handle backslashes in `.lf' arguments for MSDOS and Windows.
      . Fix file name quoting for the groff pipeline.
    
    * src/preproc/soelim/soelim.cpp (do_file):
    * src/preproc/refer/refer.cpp (do_file):
    * src/preproc/preconv/preconv.cpp (do_file):
    * src/preproc/pic/main.cpp (do_file):
    * src/preproc/eqn/main.cpp (do_file): Call `normalize_for_lf' to
    convert backslashes in the file name being processed to forward
    slashes.
    
    * src/include/lib.h (normalize_for_lf): Add prototype.
    
    * src/preproc/eqn/eqn.h:
    * src/preproc/pic/pic.h:
    * src/preproc/refer/refer.h:
    * src/preproc/tbl/table.h: Include stringclass.h before lib.h.
    
    * src/libs/libgroff/lf.cpp (normalize_for_lf): New function.
    
    * src/roff/groff/groff.cpp: Include stringclass.h before lib.h.
    (append_arg_to_string) [_WIN32 && !__CYGWIN__]: Use only "..." for
    quoting in native Windows builds.
---
 ChangeLog                       |   30 ++++++++++++++++++++++++++++++
 src/include/lib.h               |    1 +
 src/libs/libgroff/lf.cpp        |   17 ++++++++++++++++-
 src/preproc/eqn/eqn.h           |    1 +
 src/preproc/eqn/main.cpp        |    8 +++++---
 src/preproc/pic/main.cpp        |    7 +++++--
 src/preproc/pic/pic.h           |    2 +-
 src/preproc/preconv/preconv.cpp |   10 +++++++---
 src/preproc/refer/refer.cpp     |    7 +++++--
 src/preproc/refer/refer.h       |    2 +-
 src/preproc/soelim/soelim.cpp   |    3 ++-
 src/preproc/tbl/main.cpp        |    5 ++++-
 src/preproc/tbl/table.cpp       |    5 ++++-
 src/preproc/tbl/table.h         |    2 +-
 src/roff/groff/groff.cpp        |   15 ++++++++++++++-
 15 files changed, 97 insertions(+), 18 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1b1ce36..36c0645 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,33 @@
+2014-11-10  Eli Zaretskii  <address@hidden>
+
+       Improve native Windows port.
+
+       This patch fixes two issues.
+
+         . Handle backslashes in `.lf' arguments for MSDOS and Windows.
+         . Fix file name quoting for the groff pipeline.
+
+       * src/preproc/soelim/soelim.cpp (do_file):
+       * src/preproc/refer/refer.cpp (do_file):
+       * src/preproc/preconv/preconv.cpp (do_file):
+       * src/preproc/pic/main.cpp (do_file):
+       * src/preproc/eqn/main.cpp (do_file): Call `normalize_for_lf' to
+       convert backslashes in the file name being processed to forward
+       slashes.
+
+       * src/include/lib.h (normalize_for_lf): Add prototype.
+
+       * src/preproc/eqn/eqn.h:
+       * src/preproc/pic/pic.h:
+       * src/preproc/refer/refer.h:
+       * src/preproc/tbl/table.h: Include stringclass.h before lib.h.
+
+       * src/libs/libgroff/lf.cpp (normalize_for_lf): New function.
+
+       * src/roff/groff/groff.cpp: Include stringclass.h before lib.h.
+       (append_arg_to_string) [_WIN32 && !__CYGWIN__]: Use only "..." for
+       quoting in native Windows builds.
+
 2014-11-18  Deri James  <address@hidden>
 
        My commit '3fe78135c9fe666dadffde2a822b0535d8db6feb' introduced
diff --git a/src/include/lib.h b/src/include/lib.h
index a0b79fa..005369e 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -99,6 +99,7 @@ size_t file_name_max(const char *fname);
 size_t path_name_max();
 
 int interpret_lf_args(const char *p);
+void normalize_for_lf (string &fn);
 
 extern char invalid_char_table[];
 
diff --git a/src/libs/libgroff/lf.cpp b/src/libs/libgroff/lf.cpp
index b35683b..5d094b5 100644
--- a/src/libs/libgroff/lf.cpp
+++ b/src/libs/libgroff/lf.cpp
@@ -19,9 +19,9 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include <ctype.h>
 
+#include "stringclass.h"
 #include "lib.h"
 #include "cset.h"
-#include "stringclass.h"
 
 extern void change_filename(const char *);
 extern void change_lineno(int);
@@ -60,3 +60,18 @@ int interpret_lf_args(const char *p)
   change_lineno(ln);
   return 1;
 }
+
+#if defined(__MSDOS__) || (defined(_WIN32) && !defined(__CYGWIN__))
+void normalize_for_lf (string &fn)
+{
+  int fnlen = fn.length();
+  for (int i = 0; i < fnlen; i++) {
+    if (fn[i] == '\\')
+      fn[i] = '/';
+  }
+}
+#else
+void normalize_for_lf (string &)
+{
+}
+#endif
diff --git a/src/preproc/eqn/eqn.h b/src/preproc/eqn/eqn.h
index ed2d420..5904575 100644
--- a/src/preproc/eqn/eqn.h
+++ b/src/preproc/eqn/eqn.h
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <assert.h>
diff --git a/src/preproc/eqn/main.cpp b/src/preproc/eqn/main.cpp
index 57347f1..0b6f0e2 100644
--- a/src/preproc/eqn/main.cpp
+++ b/src/preproc/eqn/main.cpp
@@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public 
License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
 #include "eqn.h"
-#include "stringclass.h"
 #include "device.h"
 #include "searchpath.h"
 #include "macropath.h"
@@ -66,9 +65,12 @@ void do_file(FILE *fp, const char *filename)
 {
   string linebuf;
   string str;
+  string fn(filename);
+  fn += '\0';
+  normalize_for_lf(fn);
+  current_filename = fn.contents();
   if (output_format == troff)
-    printf(".lf 1 %s\n", filename);
-  current_filename = filename;
+    printf(".lf 1 %s\n", current_filename);
   current_lineno = 0;
   while (read_line(fp, &linebuf)) {
     if (linebuf.length() >= 4
diff --git a/src/preproc/pic/main.cpp b/src/preproc/pic/main.cpp
index 19065a6..1902840 100644
--- a/src/preproc/pic/main.cpp
+++ b/src/preproc/pic/main.cpp
@@ -309,8 +309,11 @@ void do_file(const char *filename)
       fatal("can't open `%1': %2", filename, strerror(errno));
     }
   }
-  out->set_location(filename, 1);
-  current_filename = filename;
+  string fn(filename);
+  fn += '\0';
+  normalize_for_lf(fn);
+  current_filename = fn.contents();
+  out->set_location(current_filename, 1);
   current_lineno = 1;
   enum { START, MIDDLE, HAD_DOT, HAD_P, HAD_PS, HAD_l, HAD_lf } state = START;
   for (;;) {
diff --git a/src/preproc/pic/pic.h b/src/preproc/pic/pic.h
index 6e8cf0f..7da9169 100644
--- a/src/preproc/pic/pic.h
+++ b/src/preproc/pic/pic.h
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <math.h>
@@ -49,7 +50,6 @@ extern "C" {
 
 #include "assert.h"
 #include "cset.h"
-#include "stringclass.h"
 #include "errarg.h"
 #include "error.h"
 #include "position.h"
diff --git a/src/preproc/preconv/preconv.cpp b/src/preproc/preconv/preconv.cpp
index e965fca..b3fdba0 100644
--- a/src/preproc/preconv/preconv.cpp
+++ b/src/preproc/preconv/preconv.cpp
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <assert.h>
@@ -26,7 +27,6 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 #include "error.h"
 #include "localcharset.h"
 #include "nonposix.h"
-#include "stringclass.h"
 
 #include <locale.h>
 
@@ -1065,8 +1065,12 @@ do_file(const char *filename)
   }
   if (debug_flag)
     fprintf(stderr, "  encoding used: `%s'\n", encoding);
-  if (!raw_flag)
-    printf(".lf 1 %s\n", filename);
+  if (!raw_flag) {
+    string fn(filename);
+    fn += '\0';
+    normalize_for_lf(fn);
+    printf(".lf 1 %s\n", fn.contents());
+  }
   int success = 1;
   // Call converter (converters write to stdout).
   if (!strcasecmp(encoding, "ISO-8859-1"))
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index ec0a4e3..4560475 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -432,8 +432,11 @@ static void do_file(const char *filename)
       return;
     }
   }
-  current_filename = filename;
-  fprintf(outfp, ".lf 1 %s\n", filename);
+  string fn(filename);
+  fn += '\0';
+  normalize_for_lf(fn);
+  current_filename = fn.contents();
+  fprintf(outfp, ".lf 1 %s\n", current_filename);
   string line;
   current_lineno = 0;
   for (;;) {
diff --git a/src/preproc/refer/refer.h b/src/preproc/refer/refer.h
index 38474e9..9b97617 100644
--- a/src/preproc/refer/refer.h
+++ b/src/preproc/refer/refer.h
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <stdlib.h>
@@ -25,7 +26,6 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include "errarg.h"
 #include "error.h"
-#include "stringclass.h"
 #include "cset.h"
 #include "cmap.h"
 
diff --git a/src/preproc/soelim/soelim.cpp b/src/preproc/soelim/soelim.cpp
index 3e27fde..a294a90 100644
--- a/src/preproc/soelim/soelim.cpp
+++ b/src/preproc/soelim/soelim.cpp
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <ctype.h>
@@ -25,7 +26,6 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 #include <errno.h>
 #include "errarg.h"
 #include "error.h"
-#include "stringclass.h"
 #include "nonposix.h"
 #include "searchpath.h"
 
@@ -161,6 +161,7 @@ int do_file(const char *filename)
     error("can't open `%1': %2", whole_filename.contents(), strerror(err));
     return 0;
   }
+  normalize_for_lf(whole_filename);
   current_filename = whole_filename.contents();
   current_lineno = 1;
   set_location();
diff --git a/src/preproc/tbl/main.cpp b/src/preproc/tbl/main.cpp
index 55cf0e2..b1d28be 100644
--- a/src/preproc/tbl/main.cpp
+++ b/src/preproc/tbl/main.cpp
@@ -1615,7 +1615,10 @@ int main(int argc, char **argv)
          fatal("can't open `%1': %2", argv[i], strerror(errno));
        else {
          current_lineno = 1;
-         current_filename = argv[i];
+         string fn(argv[i]);
+         fn += '\0';
+         normalize_for_lf(fn);
+         current_filename = fn.contents();
          printf(".lf 1 %s\n", current_filename);
          process_input_file(fp);
        }
diff --git a/src/preproc/tbl/table.cpp b/src/preproc/tbl/table.cpp
index f43fe7d..436149b 100644
--- a/src/preproc/tbl/table.cpp
+++ b/src/preproc/tbl/table.cpp
@@ -2966,7 +2966,10 @@ void set_troff_location(const char *fn, int ln)
       && strcmp(fn, last_filename) == 0)
     printfs(".lf %1\n", as_string(ln));
   else {
-    printfs(".lf %1 %2\n", as_string(ln), fn);
+    string filename(fn);
+    filename += '\0';
+    normalize_for_lf(filename);
+    printfs(".lf %1 %2\n", as_string(ln), filename.contents());
     last_filename = fn;
     location_force_filename = 0;
   }
diff --git a/src/preproc/tbl/table.h b/src/preproc/tbl/table.h
index 5892867..ca2f9a8 100644
--- a/src/preproc/tbl/table.h
+++ b/src/preproc/tbl/table.h
@@ -17,6 +17,7 @@ for more details.
 You should have received a copy of the GNU General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>. */
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <stdlib.h>
@@ -26,7 +27,6 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 
 #include "cset.h"
 #include "cmap.h"
-#include "stringclass.h"
 #include "errarg.h"
 #include "error.h"
 
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index 9c613b1..2eff984 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -19,6 +19,7 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 
 // A front end for groff.
 
+#include "stringclass.h"
 #include "lib.h"
 
 #include <stdlib.h>
@@ -28,7 +29,6 @@ along with this program. If not, see 
<http://www.gnu.org/licenses/>. */
 #include "assert.h"
 #include "errarg.h"
 #include "error.h"
-#include "stringclass.h"
 #include "cset.h"
 #include "font.h"
 #include "device.h"
@@ -701,7 +701,13 @@ void append_arg_to_string(const char *arg, string &str)
 {
   str += ' ';
   int needs_quoting = 0;
+  // Native Windows programs don't support '..' style of quoting, so
+  // always behave as if ARG included the single quote character.
+#if defined(_WIN32) && !defined(__CYGWIN__)
+  int contains_single_quote = 1;
+#else
   int contains_single_quote = 0;
+#endif
   const char*p;
   for (p = arg; *p != '\0'; p++)
     switch (*p) {
@@ -731,10 +737,17 @@ void append_arg_to_string(const char *arg, string &str)
     str += '"';
     for (p = arg; *p != '\0'; p++)
       switch (*p) {
+#if !(defined(_WIN32) && !defined(__CYGWIN__))
       case '"':
       case '\\':
       case '$':
        str += '\\';
+#else
+      case '"':
+      case '\\':
+       if (*p == '"' || (*p == '\\' && p[1] == '"'))
+         str += '\\';
+#endif
        // fall through
       default:
        str += *p;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]