summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2010-11-03 19:26:10 +0000
committerRichard W.M. Jones <rjones@redhat.com>2010-11-03 19:26:10 +0000
commitf661db2c393d1b7e4211c55682b7fac82a70e36d (patch)
tree57864b2733a145b93e8f8fff9137a1daf5a707c3 /generator
parent5d6a91844520d07f9477e2ddca4caf8f040ef8a1 (diff)
downloadlibguestfs-f661db2c393d1b7e4211c55682b7fac82a70e36d.tar.gz
libguestfs-f661db2c393d1b7e4211c55682b7fac82a70e36d.tar.xz
libguestfs-f661db2c393d1b7e4211c55682b7fac82a70e36d.zip
generator: Properly lay out and indent multi-line C function decls.
Diffstat (limited to 'generator')
-rw-r--r--generator/generator_c.ml42
-rw-r--r--generator/generator_utils.ml9
-rw-r--r--generator/generator_utils.mli6
3 files changed, 44 insertions, 13 deletions
diff --git a/generator/generator_c.ml b/generator/generator_c.ml
index c1b2e632..ca14d142 100644
--- a/generator/generator_c.ml
+++ b/generator/generator_c.ml
@@ -35,27 +35,41 @@ type optarg_proto = Dots | VA | Argv
(* Generate a C function prototype. *)
let rec generate_prototype ?(extern = true) ?(static = false)
?(semicolon = true)
- ?(single_line = false) ?(newline = false) ?(in_daemon = false)
+ ?(single_line = false) ?(indent = "") ?(newline = false)
+ ?(in_daemon = false)
?(prefix = "") ?(suffix = "")
?handle
?(optarg_proto = Dots)
name (ret, args, optargs) =
+ pr "%s" indent;
if extern then pr "extern ";
if static then pr "static ";
(match ret with
- | RErr -> pr "int "
- | RInt _ -> pr "int "
- | RInt64 _ -> pr "int64_t "
- | RBool _ -> pr "int "
- | RConstString _ | RConstOptString _ -> pr "const char *"
- | RString _ | RBufferOut _ -> pr "char *"
- | RStringList _ | RHashtable _ -> pr "char **"
+ | RErr
+ | RInt _
+ | RBool _ ->
+ pr "int";
+ if single_line then pr " " else pr "\n%s" indent
+ | RInt64 _ ->
+ pr "int64_t";
+ if single_line then pr " " else pr "\n%s" indent
+ | RConstString _ | RConstOptString _ ->
+ pr "const char *";
+ if not single_line then pr "\n%s" indent
+ | RString _ | RBufferOut _ ->
+ pr "char *";
+ if not single_line then pr "\n%s" indent
+ | RStringList _ | RHashtable _ ->
+ pr "char **";
+ if not single_line then pr "\n%s" indent
| RStruct (_, typ) ->
if not in_daemon then pr "struct guestfs_%s *" typ
- else pr "guestfs_int_%s *" typ
+ else pr "guestfs_int_%s *" typ;
+ if not single_line then pr "\n%s" indent
| RStructList (_, typ) ->
if not in_daemon then pr "struct guestfs_%s_list *" typ
- else pr "guestfs_int_%s_list *" typ
+ else pr "guestfs_int_%s_list *" typ;
+ if not single_line then pr "\n%s" indent
);
let is_RBufferOut = match ret with RBufferOut _ -> true | _ -> false in
pr "%s%s%s (" prefix name suffix;
@@ -69,7 +83,10 @@ let rec generate_prototype ?(extern = true) ?(static = false)
);
let next () =
if !comma then (
- if single_line then pr ", " else pr ",\n\t\t"
+ if single_line then pr ", "
+ else
+ pr ",\n%s%s"
+ indent (spaces (String.length prefix + String.length name + 2))
);
comma := true
in
@@ -152,8 +169,7 @@ and generate_actions_pod () =
if not (List.mem NotInDocs flags) then (
let name = "guestfs_" ^ shortname in
pr "=head2 %s\n\n" name;
- pr " ";
- generate_prototype ~extern:false ~handle:"g" name style;
+ generate_prototype ~extern:false ~indent:" " ~handle:"g" name style;
pr "\n\n";
let uc_shortname = String.uppercase shortname in
diff --git a/generator/generator_utils.ml b/generator/generator_utils.ml
index 85112271..425a5794 100644
--- a/generator/generator_utils.ml
+++ b/generator/generator_utils.ml
@@ -305,3 +305,12 @@ let pod2text ~width name longdesc =
(* Compare two actions (for sorting). *)
let action_compare (n1,_,_,_,_,_,_) (n2,_,_,_,_,_,_) = compare n1 n2
+
+let chars c n =
+ let str = String.create n in
+ for i = 0 to n-1 do
+ String.unsafe_set str i c
+ done;
+ str
+
+let spaces n = chars ' ' n
diff --git a/generator/generator_utils.mli b/generator/generator_utils.mli
index f43a276d..bbdab791 100644
--- a/generator/generator_utils.mli
+++ b/generator/generator_utils.mli
@@ -99,3 +99,9 @@ val pod2text : width:int -> string -> string -> string list
val action_compare : Generator_types.action -> Generator_types.action -> int
(** 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. *)
+
+val spaces : int -> string
+(** [spaces n] creates a string of n spaces. *)