[Pkg-ocaml-maint-commits] r3155 - /trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff

enrico at users.alioth.debian.org enrico at users.alioth.debian.org
Sun Sep 17 11:18:59 UTC 2006


Author: enrico
Date: Sun Sep 17 11:18:59 2006
New Revision: 3155

URL: http://svn.debian.org/wsvn/pkg-ocaml-maint/?sc=1&rev=3155
Log:
Implemented a smarter way of finding grammars

Modified:
    trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff

Modified: trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff
URL: http://svn.debian.org/wsvn/pkg-ocaml-maint/trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff?rev=3155&op=diff
==============================================================================
--- trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff (original)
+++ trunk/packages/polygen/trunk/debian/patches/02-search-for-grammars.diff Sun Sep 17 11:18:59 2006
@@ -1,36 +1,86 @@
---- src/main.ml	2004-06-25 11:58:00.000000000 +0200
-+++ src/main.ml	2004-11-23 19:44:14.000000000 +0100
-@@ -119,6 +119,29 @@
+diff -Naur polygen-1.0.6.ds1/src/main.ml polygen-1.0.6.ds1.patched/src/main.ml
+--- polygen-1.0.6.ds1/src/main.ml	2005-11-21 21:33:38.000000000 +0100
++++ polygen-1.0.6.ds1.patched/src/main.ml	2006-09-17 13:12:15.238668750 +0200
+@@ -119,6 +119,78 @@
          msg "preprocessing grammar...";
          Pre.pre decls0
  
++(* based on is_dir function from HELM *)
++let is_dir fname =
++  try
++    (Unix.stat fname).Unix.st_kind = Unix.S_DIR
++  with
++    Unix.Unix_error _ -> false
++
++(* based on find function from HELM *)
++let rec find path source = 
++  try
++    if Sys.file_exists(path^"/"^source) then
++      path^"/"^source
++    else if Sys.file_exists(path^"/"^source^".grm") then
++      path^"/"^source^".grm"
++    else
++      let handle = Unix.opendir path in
++      try 
++        let res = ref "" in 
++        try
++          while true do 
++            match Unix.readdir handle with
++            | "." | ".." -> ()
++            | s when is_dir (path^"/"^s) -> (
++                res := find (path^"/"^s) source ;
++                if !res <> "" then
++                  raise Exit
++              )
++            | s -> ()
++          done ; ""
++        with Exit -> !res
++      with End_of_file -> (Unix.closedir handle ; "")
++  with Unix.Unix_error _ -> ""
++
 +let find_grammar source =
-+    if (Sys.file_exists(source)) then
++(* TODO:
++ *  1) Check current directory
++ *  2) check $LANG. If it exists, let A be everything before _ or end of line,
++ *     and try in /usr/share/polygen/A
++ *  3) Then try a recursive search under /usr/share/polygen
++ *
++ *  LANG="_"
++ *)
++   let lang =
++     try
++       let lang = Sys.getenv "LANG" in
++       try
++         Some (String.sub lang 0 (String.index lang '_'))
++       with Not_found -> Some lang
++     with Not_found -> None
++   in
++    if (Sys.file_exists(source)) then (
++      prerr_endline "SAMEDIR none" ;
 +    	source
-+    else if (Sys.file_exists(source^".grm")) then
++    ) else if (Sys.file_exists(source^".grm")) then (
++      prerr_endline "SAMEDIRgrm none" ;
 +    	source^".grm"
-+    else if (Sys.file_exists("/usr/share/polygen/"^source)) then
-+        "/usr/share/polygen/"^source
-+    else if (Sys.file_exists("/usr/share/polygen/"^source^".grm")) then
-+        "/usr/share/polygen/"^source^".grm"
-+    else if (Sys.file_exists("/usr/share/polygen/eng/"^source)) then
-+        "/usr/share/polygen/eng/"^source
-+    else if (Sys.file_exists("/usr/share/polygen/eng/"^source^".grm")) then
-+        "/usr/share/polygen/eng/"^source^".grm"
-+    else if (Sys.file_exists("/usr/share/polygen/fra/"^source)) then
-+        "/usr/share/polygen/fra/"^source
-+    else if (Sys.file_exists("/usr/share/polygen/fra/"^source^".grm")) then
-+        "/usr/share/polygen/fra/"^source^".grm"
-+    else if (Sys.file_exists("/usr/share/polygen/ita/"^source)) then
-+        "/usr/share/polygen/ita/"^source
-+    else if (Sys.file_exists("/usr/share/polygen/ita/"^source^".grm")) then
-+        "/usr/share/polygen/ita/"^source^".grm"
-+    else
-+    	source
++    ) else match lang with
++    | Some s when Sys.file_exists ("/usr/share/polygen/"^s^"/"^source) -> (
++        prerr_endline ("LANG1 "^s) ;
++        "/usr/share/polygen/"^s^"/"^source
++      )
++    | Some s when Sys.file_exists ("/usr/share/polygen/"^s^"/"^source^".grm") -> (
++        prerr_endline ("LANG2 "^s) ;
++        "/usr/share/polygen/"^s^"/"^source^".grm"
++      )
++    | _ -> (
++        prerr_endline "LANG none" ;
++        (* Then try a recursive search under /usr/share/polygen *)
++        let f = find "/usr/share/polygen" source in 
++          if f <> "" then f
++          else source
++      )
  
  (* main *)
  
-@@ -132,6 +155,9 @@
+@@ -132,6 +204,9 @@
              fprintf !dest "%s\n" (Absyn1.pretty_decls "" (get_decls1 source))
  
        | Generate ->
@@ -40,3 +90,4 @@
        		(* load complied or source grammar *)
              let decls =
              	try
+ 




More information about the Pkg-ocaml-maint-commits mailing list