psss / rpms / libguestfs

Forked from rpms/libguestfs 5 years ago
Clone

Blame 0092-builder-split-INI-C-OCaml-glue-code-in-own-module.patch

4bf3775
From 623c36262943f6f1e3c3df56d5c56e34ed658e48 Mon Sep 17 00:00:00 2001
4bf3775
From: Pino Toscano <ptoscano@redhat.com>
4bf3775
Date: Mon, 24 Feb 2014 15:08:03 +0100
4bf3775
Subject: [PATCH] builder: split INI C <-> OCaml glue code in own module
4bf3775
4bf3775
Move in an own module the code which calls the C
4bf3775
virt_builder_parse_index and does the array -> list conversion of the
4bf3775
result. This way this code can be easily called also in places different
4bf3775
than Index_parser without the need to copy the types mapping, etc.
4bf3775
4bf3775
Just code motion, no actual behaviour changes.
4bf3775
4bf3775
(cherry picked from commit 8ed905c7e6a837887a758417bdfd1822b86a214f)
4bf3775
---
4bf3775
 builder/Makefile.am     |  3 +++
4bf3775
 builder/index_parser.ml | 17 +----------------
4bf3775
 builder/ini_reader.ml   | 38 ++++++++++++++++++++++++++++++++++++++
4bf3775
 builder/ini_reader.mli  | 24 ++++++++++++++++++++++++
4bf3775
 po/POTFILES-ml          |  1 +
4bf3775
 5 files changed, 67 insertions(+), 16 deletions(-)
4bf3775
 create mode 100644 builder/ini_reader.ml
4bf3775
 create mode 100644 builder/ini_reader.mli
4bf3775
4bf3775
diff --git a/builder/Makefile.am b/builder/Makefile.am
4bf3775
index 8c48be5..a72b7ac 100644
4bf3775
--- a/builder/Makefile.am
4bf3775
+++ b/builder/Makefile.am
4bf3775
@@ -46,6 +46,8 @@ SOURCES = \
4bf3775
 	index_parser.mli \
4bf3775
 	index_parser.ml \
4bf3775
 	index-parser-c.c \
4bf3775
+	ini_reader.mli \
4bf3775
+	ini_reader.ml \
4bf3775
 	list_entries.mli \
4bf3775
 	list_entries.ml \
4bf3775
 	paths.ml \
4bf3775
@@ -94,6 +96,7 @@ OBJECTS = \
4bf3775
 	pxzcat.cmx \
4bf3775
 	setlocale-c.o \
4bf3775
 	setlocale.cmx \
4bf3775
+	ini_reader.cmx \
4bf3775
 	paths.cmx \
4bf3775
 	get_kernel.cmx \
4bf3775
 	downloader.cmx \
4bf3775
diff --git a/builder/index_parser.ml b/builder/index_parser.ml
4bf3775
index de4d72e..9fd9cda 100644
4bf3775
--- a/builder/index_parser.ml
4bf3775
+++ b/builder/index_parser.ml
4bf3775
@@ -102,15 +102,6 @@ let print_entry chan (name, { printable_name = printable_name;
4bf3775
   ) notes;
4bf3775
   if hidden then fp "hidden=true\n"
4bf3775
 
4bf3775
-(* Types returned by the C index parser. *)
4bf3775
-type sections = section array
4bf3775
-and section = string * fields           (* [name] + fields *)
4bf3775
-and fields = field array
4bf3775
-and field = string * string option * string    (* key + subkey + value *)
4bf3775
-
4bf3775
-(* Calls yyparse in the C code. *)
4bf3775
-external parse_index : string -> sections = "virt_builder_parse_index"
4bf3775
-
4bf3775
 let get_index ~prog ~debug ~downloader ~sigchecker source =
4bf3775
   let corrupt_file () =
4bf3775
     eprintf (f_"\nThe index file downloaded from '%s' is corrupt.\nYou need to ask the supplier of this file to fix it and upload a fixed version.\n")
4bf3775
@@ -128,16 +119,10 @@ let get_index ~prog ~debug ~downloader ~sigchecker source =
4bf3775
     Sigchecker.verify sigchecker tmpfile;
4bf3775
 
4bf3775
     (* Try parsing the file. *)
4bf3775
-    let sections = parse_index tmpfile in
4bf3775
+    let sections = Ini_reader.read_ini tmpfile in
4bf3775
     if delete_tmpfile then
4bf3775
       (try Unix.unlink tmpfile with _ -> ());
4bf3775
 
4bf3775
-    let sections = Array.to_list sections in
4bf3775
-    let sections = List.map (
4bf3775
-      fun (n, fields) ->
4bf3775
-        n, Array.to_list fields
4bf3775
-    ) sections in
4bf3775
-
4bf3775
     (* Check for repeated os-version names. *)
4bf3775
     let nseen = Hashtbl.create 13 in
4bf3775
     List.iter (
4bf3775
diff --git a/builder/ini_reader.ml b/builder/ini_reader.ml
4bf3775
new file mode 100644
4bf3775
index 0000000..fbd4d2f
4bf3775
--- /dev/null
4bf3775
+++ b/builder/ini_reader.ml
4bf3775
@@ -0,0 +1,38 @@
4bf3775
+(* virt-builder
4bf3775
+ * Copyright (C) 2013-2014 Red Hat Inc.
4bf3775
+ *
4bf3775
+ * This program is free software; you can redistribute it and/or modify
4bf3775
+ * it under the terms of the GNU General Public License as published by
4bf3775
+ * the Free Software Foundation; either version 2 of the License, or
4bf3775
+ * (at your option) any later version.
4bf3775
+ *
4bf3775
+ * This program is distributed in the hope that it will be useful,
4bf3775
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4bf3775
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4bf3775
+ * GNU General Public License for more details.
4bf3775
+ *
4bf3775
+ * You should have received a copy of the GNU General Public License along
4bf3775
+ * with this program; if not, write to the Free Software Foundation, Inc.,
4bf3775
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4bf3775
+ *)
4bf3775
+
4bf3775
+type sections = section list
4bf3775
+and section = string * fields                (* [name] + fields *)
4bf3775
+and fields = field list
4bf3775
+and field = string * string option * string  (* key + subkey + value *)
4bf3775
+
4bf3775
+(* Types returned by the C index parser. *)
4bf3775
+type c_sections = c_section array
4bf3775
+and c_section = string * c_fields             (* [name] + fields *)
4bf3775
+and c_fields = field array
4bf3775
+
4bf3775
+(* Calls yyparse in the C code. *)
4bf3775
+external parse_index : string -> c_sections = "virt_builder_parse_index"
4bf3775
+
4bf3775
+let read_ini file =
4bf3775
+  let sections = parse_index file in
4bf3775
+  let sections = Array.to_list sections in
4bf3775
+  List.map (
4bf3775
+    fun (n, fields) ->
4bf3775
+      n, Array.to_list fields
4bf3775
+  ) sections
4bf3775
diff --git a/builder/ini_reader.mli b/builder/ini_reader.mli
4bf3775
new file mode 100644
4bf3775
index 0000000..992a1cb
4bf3775
--- /dev/null
4bf3775
+++ b/builder/ini_reader.mli
4bf3775
@@ -0,0 +1,24 @@
4bf3775
+(* virt-builder
4bf3775
+ * Copyright (C) 2013-2014 Red Hat Inc.
4bf3775
+ *
4bf3775
+ * This program is free software; you can redistribute it and/or modify
4bf3775
+ * it under the terms of the GNU General Public License as published by
4bf3775
+ * the Free Software Foundation; either version 2 of the License, or
4bf3775
+ * (at your option) any later version.
4bf3775
+ *
4bf3775
+ * This program is distributed in the hope that it will be useful,
4bf3775
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
4bf3775
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4bf3775
+ * GNU General Public License for more details.
4bf3775
+ *
4bf3775
+ * You should have received a copy of the GNU General Public License along
4bf3775
+ * with this program; if not, write to the Free Software Foundation, Inc.,
4bf3775
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4bf3775
+ *)
4bf3775
+
4bf3775
+type sections = section list
4bf3775
+and section = string * fields                (* [name] + fields *)
4bf3775
+and fields = field list
4bf3775
+and field = string * string option * string  (* key + subkey + value *)
4bf3775
+
4bf3775
+val read_ini : string -> sections
4bf3775
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
4bf3775
index ea357e4..94230f8 100644
4bf3775
--- a/po/POTFILES-ml
4bf3775
+++ b/po/POTFILES-ml
4bf3775
@@ -3,6 +3,7 @@ builder/cmdline.ml
4bf3775
 builder/downloader.ml
4bf3775
 builder/get_kernel.ml
4bf3775
 builder/index_parser.ml
4bf3775
+builder/ini_reader.ml
4bf3775
 builder/list_entries.ml
4bf3775
 builder/paths.ml
4bf3775
 builder/pxzcat.ml
4bf3775
-- 
4bf3775
1.8.5.3
4bf3775