mldonkey-users
[Top][All Lists]
Advanced

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

[Mldonkey-users] [PATCH 3/7] Do not leave empty files if code generation


From: ygrek
Subject: [Mldonkey-users] [PATCH 3/7] Do not leave empty files if code generation fails
Date: Mon, 18 Jun 2012 00:20:38 +0300

Make tools output directly to file, not via shell redirection

Conflicts:

        config/Makefile.in
---
 config/Makefile.in |    9 ++++-----
 tools/ocamlpp.ml4  |   28 +++++++++++++++-------------
 2 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/config/Makefile.in b/config/Makefile.in
index 208c55d..4f0488f 100644
--- a/config/Makefile.in
+++ b/config/Makefile.in
@@ -1447,7 +1447,7 @@ $(LIB)/md4_comp.o: $(LIB)/md4_$(MD4COMP).o
 
 zogml:
        (for i in $(GUI_CODE)/gui*_base.zog ; do \
-               $(CAMLP4) pa_o.cmo pa_zog.cma pr_o.cmo -impl $$i > 
$(GUI_CODE)/`basename $$i zog`ml ;\
+               $(CAMLP4) pa_o.cmo pa_zog.cma pr_o.cmo -impl $$i -o 
$(GUI_CODE)/`basename $$i zog`ml ;\
        done)
 
 #######################################################################
@@ -1862,17 +1862,16 @@ rpm: sourcedist
        @$(OCAMLYACC) $<
 
 .zog.ml:
-       @$(CAMLP4) pa_o.cmo ./pa_zog.cma pr_o.cmo -impl $< > $@
+       @$(CAMLP4) pa_o.cmo ./pa_zog.cma pr_o.cmo -impl $< -o $@
 
 .ml4.ml:
-       @echo '# 1 "$<"' > $@
-       @$(CAMLP4) pa_o.cmo pa_op.cmo pr_o.cmo -impl $< >> $@
+       @$(CAMLP4) pa_o.cmo pa_op.cmo pr_o.cmo -impl $< -o $@
 
 .mlc4.ml:
        @$(CAMLP4OF) -I +camlp4 -impl $< -o $@
 
 .mlt.ml:
-       @$(OCAMLPP) -pp $< > $@
+       @$(OCAMLPP) -o $@ -pp $<
 
 .c.o :
        $(OCAMLC) -verbose -ccopt "-I $(OCAML_SRC)/byterun -o $*.o" -ccopt 
"$(CFLAGS)" $(LIBS_flags) -c $<
diff --git a/tools/ocamlpp.ml4 b/tools/ocamlpp.ml4
index 38570f5..8e91ef7 100644
--- a/tools/ocamlpp.ml4
+++ b/tools/ocamlpp.ml4
@@ -1,5 +1,7 @@
 open Str
-    
+
+let outch = ref stdout
+
 (*
 let gen dest_filename =
   
@@ -156,8 +158,8 @@ let rec preprocess filename env =
   let ic = open_in filename in
   
   let line_warning line =
-    Printf.fprintf stdout "(*\n\n WARNING: this file is automatically 
generated from: \n\t%s\n\n*)\n\n" filename;
-    Printf.fprintf stdout "# %d \"%s\"\n" (line+1) filename;  
+    Printf.fprintf !outch "(*\n\n WARNING: this file is automatically 
generated from: \n\t%s\n\n*)\n\n" filename;
+    Printf.fprintf !outch "# %d \"%s\"\n" (line+1) filename;  
   in
   
   let rec iter_line i env =
@@ -178,7 +180,7 @@ let rec preprocess filename env =
                   line_warning (i+1);
                   env
               | Line (line, filename) ->
-                  Printf.fprintf stdout "# %d \"%s\"\n" line filename;
+                  Printf.fprintf !outch "# %d \"%s\"\n" line filename;
                   env
               | Regexps regexps2 ->
                   line_warning (i+1);
@@ -192,8 +194,8 @@ let rec preprocess filename env =
                 exit 2
           end;
         end else begin
-          output_string stdout line;
-          output_char stdout '\n';
+          output_string !outch line;
+          output_char !outch '\n';
           env
         end
     in
@@ -217,7 +219,7 @@ let pp filename = preprocess filename new_env
 
 let add_depend  filedep filename depends =
   if not (List.mem filename !depends) then begin
-      Printf.fprintf stdout "%s: %s\n" filedep filename;
+      Printf.fprintf !outch "%s: %s\n" filedep filename;
       depends := filename :: !depends
     end
   
@@ -278,13 +280,13 @@ let depend filename =
         Printf.fprintf stderr "Don't know what to do with %s\n" filename;
         exit 2
       end
-      
-let _ =
+
+let () =
   Arg.parse 
     [
 (*    "-gen", Arg.String gen, " <filename> : generate filename"; *)
     "-pp", Arg.String pp, " <filename> : preprocess filename";
-  ] depend ""
-    
-  
-  
\ No newline at end of file
+    "-o", Arg.String (fun s -> outch := open_out s), " <filename> : output 
filename (influences subsequent options)";
+  ] depend "";
+  close_out !outch
+
-- 
1.7.10




reply via email to

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