summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-11-26 21:49:58 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-11-26 21:49:58 +0000
commitb4c853f7d493af1d71f352832fed29eb7e377e8f (patch)
treebbc61a9b49b95c378cbda19170e4fb3e0d068eb0 /generator
parent60b3c8e81124a881cd93ed66c167cac37e87c36b (diff)
downloadlibguestfs-b4c853f7d493af1d71f352832fed29eb7e377e8f.tar.gz
libguestfs-b4c853f7d493af1d71f352832fed29eb7e377e8f.tar.xz
libguestfs-b4c853f7d493af1d71f352832fed29eb7e377e8f.zip
generator: More options for internal pod2text generator.
Allow extra width, and trimming options. This necessitates a change in the memoized format. To avoid causing crashes if a new generator loads the old format, also change the filename of the memo file.
Diffstat (limited to 'generator')
-rw-r--r--generator/generator_utils.ml21
-rw-r--r--generator/generator_utils.mli21
2 files changed, 29 insertions, 13 deletions
diff --git a/generator/generator_utils.ml b/generator/generator_utils.ml
index 6dc11bfd..27b543d4 100644
--- a/generator/generator_utils.ml
+++ b/generator/generator_utils.ml
@@ -244,15 +244,17 @@ let seq_of_test = function
| TestLastFail s -> s
let c_quote str =
+ let str = replace_str str "\\" "\\\\" in
let str = replace_str str "\r" "\\r" in
let str = replace_str str "\n" "\\n" in
let str = replace_str str "\t" "\\t" in
let str = replace_str str "\000" "\\0" in
+ let str = replace_str str "\"" "\\\"" in
str
(* Used to memoize the result of pod2text. *)
-let pod2text_memo_filename = "generator/.pod2text.data"
-let pod2text_memo : ((int * string * string), string list) Hashtbl.t =
+let pod2text_memo_filename = "generator/.pod2text.data.version.2"
+let pod2text_memo : ((int option * bool * bool * string * string), string list) Hashtbl.t =
try
let chan = open_in pod2text_memo_filename in
let v = input_value chan in
@@ -271,22 +273,27 @@ let pod2text_memo_updated () =
* Because this is very slow (the slowest part of autogeneration),
* we memoize the results.
*)
-let pod2text ~width name longdesc =
- let key = width, name, longdesc in
+let pod2text ?width ?(trim = true) ?(discard = true) name longdesc =
+ let key = width, trim, discard, name, longdesc in
try Hashtbl.find pod2text_memo key
with Not_found ->
let filename, chan = Filename.open_temp_file "gen" ".tmp" in
fprintf chan "=head1 %s\n\n%s\n" name longdesc;
close_out chan;
- let cmd = sprintf "pod2text -w %d %s" width (Filename.quote filename) in
+ let cmd =
+ match width with
+ | Some width ->
+ sprintf "pod2text -w %d %s" width (Filename.quote filename)
+ | None ->
+ sprintf "pod2text %s" (Filename.quote filename) in
let chan = open_process_in cmd in
let lines = ref [] in
let rec loop i =
let line = input_line chan in
- if i = 1 then (* discard the first line of output *)
+ if i = 1 && discard then (* discard the first line of output *)
loop (i+1)
else (
- let line = triml line in
+ let line = if trim then triml line else line in
lines := line :: !lines;
loop (i+1)
) in
diff --git a/generator/generator_utils.mli b/generator/generator_utils.mli
index bbdab791..5104a162 100644
--- a/generator/generator_utils.mli
+++ b/generator/generator_utils.mli
@@ -91,14 +91,23 @@ val seq_of_test : Generator_types.test -> Generator_types.seq
val c_quote : string -> string
(** Perform quoting on a string so it is safe to include in a C source file. *)
-val pod2text : width:int -> string -> string -> string list
-(** [pod2text ~width name longdesc] converts the POD in [longdesc] to
- plain ASCII lines of text. This is the slowest part of
- autogeneration, so the results are memoized into a temporary
- file. *)
+val pod2text : ?width:int -> ?trim:bool -> ?discard:bool -> string -> string -> string list
+ (** [pod2text ?width ?trim ?discard name longdesc] converts the POD in
+ [longdesc] to plain ASCII lines of text.
+
+ [width] is the width in characters. If not specified, then
+ use the pod2text default.
+
+ [trim] means trim the left margin (useful when including the
+ output inside comments, as in Java generator).
+
+ [discard] means discard the first heading.
+
+ This is the slowest part of autogeneration, so the results are
+ memoized into a temporary file. *)
val action_compare : Generator_types.action -> Generator_types.action -> int
-(** Compare the names of two actions, for sorting. *)
+ (** Compare the names of two actions, for sorting. *)
val chars : char -> int -> string
(** [chars c n] creates a string containing character c repeated n times. *)