Move the simple OCaml JSON writer to mllib, so that can be enhanced and
used also outside v2v.
---
mllib/JSON.ml | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
mllib/JSON.mli | 26 ++++++++++++++++++++++++++
mllib/Makefile.am | 5 ++++-
po/POTFILES-ml | 2 +-
v2v/JSON.ml | 53 -----------------------------------------------------
v2v/JSON.mli | 26 --------------------------
v2v/Makefile.am | 3 +--
7 files changed, 85 insertions(+), 83 deletions(-)
create mode 100644 mllib/JSON.ml
create mode 100644 mllib/JSON.mli
delete mode 100644 v2v/JSON.ml
delete mode 100644 v2v/JSON.mli
diff --git a/mllib/JSON.ml b/mllib/JSON.ml
new file mode 100644
index 0000000..5e3a879
--- /dev/null
+++ b/mllib/JSON.ml
@@ -0,0 +1,53 @@
+(* virt-v2v
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(* Poor man's JSON generator. *)
+
+open Printf
+
+open Common_utils
+
+type field = string * json_t
+and json_t = String of string | Int of int
+and doc = field list
+
+(* JSON quoting. *)
+let json_quote str =
+ let str = replace_str str "\\" "\\\\" in
+ let str = replace_str str "\"" "\\\"" in
+ let str = replace_str str "'" "\\'" in
+ let str = replace_str str "\008" "\\b" in
+ let str = replace_str str "\012" "\\f" in
+ let str = replace_str str "\n" "\\n" in
+ let str = replace_str str "\r" "\\r" in
+ let str = replace_str str "\t" "\\t" in
+ let str = replace_str str "\011" "\\v" in
+ str
+
+let string_of_doc fields =
+ "{ " ^
+ String.concat ", " (
+ List.map (
+ function
+ | (n, String v) ->
+ sprintf "\"%s\" : \"%s\"" n (json_quote v)
+ | (n, Int v) ->
+ sprintf "\"%s\" : %d" n v
+ ) fields
+ )
+ ^ " }"
diff --git a/mllib/JSON.mli b/mllib/JSON.mli
new file mode 100644
index 0000000..1e3a1b3
--- /dev/null
+++ b/mllib/JSON.mli
@@ -0,0 +1,26 @@
+(* virt-v2v
+ * Copyright (C) 2009-2014 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Poor man's JSON generator. *)
+
+type field = string * json_t
+and json_t = String of string | Int of int
+and doc = field list
+
+val string_of_doc : doc -> string
+ (** Serialize {!doc} object as a string. *)
diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index ac953ac..653b8aa 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -32,6 +32,8 @@ SOURCES = \
fsync-c.c \
fsync.mli \
fsync.ml \
+ JSON.mli \
+ JSON.ml \
mkdtemp.mli \
mkdtemp.ml \
mkdtemp-c.c \
@@ -65,7 +67,8 @@ ocaml_modules = config \
uRI \
mkdtemp \
planner \
- regedit
+ regedit \
+ JSON
OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index df39e7b..d919b6f 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -25,6 +25,7 @@ customize/perl_edit.ml
customize/random_seed.ml
customize/timezone.ml
customize/urandom.ml
+mllib/JSON.ml
mllib/common_gettext.ml
mllib/common_utils.ml
mllib/common_utils_tests.ml
@@ -83,7 +84,6 @@ sysprep/sysprep_operation_user_account.ml
sysprep/sysprep_operation_utmp.ml
sysprep/sysprep_operation_yum_uuid.ml
v2v/DOM.ml
-v2v/JSON.ml
v2v/OVF.ml
v2v/cmdline.ml
v2v/convert_linux.ml
diff --git a/v2v/JSON.ml b/v2v/JSON.ml
deleted file mode 100644
index 5e3a879..0000000
--- a/v2v/JSON.ml
+++ /dev/null
@@ -1,53 +0,0 @@
-(* virt-v2v
- * Copyright (C) 2009-2014 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-(* Poor man's JSON generator. *)
-
-open Printf
-
-open Common_utils
-
-type field = string * json_t
-and json_t = String of string | Int of int
-and doc = field list
-
-(* JSON quoting. *)
-let json_quote str =
- let str = replace_str str "\\" "\\\\" in
- let str = replace_str str "\"" "\\\"" in
- let str = replace_str str "'" "\\'" in
- let str = replace_str str "\008" "\\b" in
- let str = replace_str str "\012" "\\f" in
- let str = replace_str str "\n" "\\n" in
- let str = replace_str str "\r" "\\r" in
- let str = replace_str str "\t" "\\t" in
- let str = replace_str str "\011" "\\v" in
- str
-
-let string_of_doc fields =
- "{ " ^
- String.concat ", " (
- List.map (
- function
- | (n, String v) ->
- sprintf "\"%s\" : \"%s\"" n (json_quote v)
- | (n, Int v) ->
- sprintf "\"%s\" : %d" n v
- ) fields
- )
- ^ " }"
diff --git a/v2v/JSON.mli b/v2v/JSON.mli
deleted file mode 100644
index 1e3a1b3..0000000
--- a/v2v/JSON.mli
+++ /dev/null
@@ -1,26 +0,0 @@
-(* virt-v2v
- * Copyright (C) 2009-2014 Red Hat Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *)
-
-(** Poor man's JSON generator. *)
-
-type field = string * json_t
-and json_t = String of string | Int of int
-and doc = field list
-
-val string_of_doc : doc -> string
- (** Serialize {!doc} object as a string. *)
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
index 8bf8f07..dafe27e 100644
--- a/v2v/Makefile.am
+++ b/v2v/Makefile.am
@@ -37,7 +37,6 @@ SOURCES_MLI = \
input_libvirt.mli \
input_libvirtxml.mli \
input_ova.mli \
- JSON.mli \
kvmuid.mli \
linux.mli \
modules_list.mli \
@@ -62,7 +61,6 @@ SOURCES_ML = \
xml.ml \
domainxml.ml \
DOM.ml \
- JSON.ml \
kvmuid.ml \
vCenter.ml \
xen.ml \
@@ -122,6 +120,7 @@ BOBJECTS = \
$(top_builddir)/mllib/progress.cmo \
$(top_builddir)/mllib/config.cmo \
$(top_builddir)/mllib/mkdtemp.cmo \
+ $(top_builddir)/mllib/JSON.cmo \
$(top_builddir)/customize/urandom.cmo \
$(top_builddir)/customize/random_seed.cmo \
$(top_builddir)/customize/hostname.cmo \
--
1.9.3