sysprep: Make a common Utils.compare_command_line_args function.

This isn't quite code motion, since the new function also ignores case
(which previously we didn't ignore).
This commit is contained in:
Richard W.M. Jones
2012-04-11 16:20:23 +01:00
parent a3d6629a0b
commit 16b2ffa97e
3 changed files with 10 additions and 4 deletions

View File

@@ -138,10 +138,8 @@ let dump_pod_options () =
| Arg.Rest _ -> assert false (* XXX not implemented *)
) args in
let args = List.sort (
fun (a, _) (b, _) ->
compare (skip_dashes a) (skip_dashes b)
) args in
let args =
List.sort (fun (a, _) (b, _) -> compare_command_line_args a b) args in
List.iter (
fun (arg_name, (op_name, heading, pod)) ->

View File

@@ -81,3 +81,6 @@ let skip_dashes str =
let i = loop 0 in
if i = 0 then str
else String.sub str i (n-i)
let compare_command_line_args a b =
compare (String.lowercase (skip_dashes a)) (String.lowercase (skip_dashes b))

View File

@@ -44,3 +44,8 @@ val skip_dashes : string -> string
If the string contains only dash characters, this raises
[Invalid_argument "skip_dashes"]. *)
val compare_command_line_args : string -> string -> int
(** Compare two command line arguments (eg. ["-a"] and ["--V"]),
ignoring leading dashes and case. Note this assumes the
strings are 7 bit ASCII. *)