From: Richard W.M. Jones Date: Fri, 26 Nov 2010 21:51:11 +0000 (+0000) Subject: fish: Don't use external pod2text program. X-Git-Tag: 1.7.16~1 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=272b754093ef824486993540a893d39be8e7e9f0;p=libguestfs.git fish: Don't use external pod2text program. This removes the dependency from guestfish to the external pod2text program (and hence the final dependency on perl for guestfish). This is done by storing the formatted pod2text output in guestfish as the help text. --- diff --git a/fish/cmds_gperf.h b/fish/cmds_gperf.h index 92bd607..74db69d 100644 --- a/fish/cmds_gperf.h +++ b/fish/cmds_gperf.h @@ -23,10 +23,8 @@ * guestfish can execute. */ struct command_entry { - /* These fields are passed to pod2text to implement the online help. */ - const char *name; - const char *shortdesc; - const char *podbody; + const char *name; /* Short name. */ + const char *help; /* Online help. */ /* The run_* function. */ int (*run) (const char *cmd, size_t argc, char *argv[]); diff --git a/fish/fish.c b/fish/fish.c index c1dbfb4..50340a3 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -531,24 +531,6 @@ set_up_terminal (void) have_terminfo = 1; } -void -pod2text (const char *name, const char *shortdesc, const char *str) -{ - FILE *fp; - - fp = popen ("pod2text", "w"); - if (fp == NULL) { - /* pod2text failed, maybe not found, so let's just print the - * source instead, since that's better than doing nothing. - */ - printf ("%s - %s\n\n%s\n", name, shortdesc, str); - return; - } - fprintf (fp, "=head1 NAME\n\n%s - %s\n\n", name, shortdesc); - fputs (str, fp); - pclose (fp); -} - static void prepare_drives (struct drv *drv) { diff --git a/fish/fish.h b/fish/fish.h index 3597805..f4b6c9c 100644 --- a/fish/fish.h +++ b/fish/fish.h @@ -64,7 +64,6 @@ extern int progress_bars; extern int remote_control_csh; extern const char *libvirt_uri; extern int issue_command (const char *cmd, char *argv[], const char *pipe); -extern void pod2text (const char *name, const char *shortdesc, const char *body); extern void list_builtin_commands (void); extern int display_builtin_command (const char *cmd); extern void free_strings (char **argv); diff --git a/generator/generator_fish.ml b/generator/generator_fish.ml index 0c81dfc..516c5b1 100644 --- a/generator/generator_fish.ml +++ b/generator/generator_fish.ml @@ -76,11 +76,7 @@ let generate_fish_cmds () = (* List of command_entry structs. *) List.iter ( fun (name, _, _, flags, _, shortdesc, longdesc) -> - pr "struct command_entry %s_cmd_entry = {\n" name; - let name2 = replace_char name '_' '-' in - pr " .name = \"%s\",\n" name2; - let aliases = filter_map (function FishAlias n -> Some n | _ -> None) flags in let describe_alias = @@ -89,10 +85,16 @@ let generate_fish_cmds () = (String.concat " or " (List.map (fun s -> "'" ^ s ^ "'") aliases)) else "" in - pr " .shortdesc = \"%s\",\n" shortdesc; - pr " .podbody = %S,\n" - ("=head1 DESCRIPTION\n\n" ^ longdesc ^ describe_alias); + let pod = + sprintf "%s - %s\n\n=head1 DESCRIPTION\n\n%s\n\n%s" + name2 shortdesc longdesc describe_alias in + let text = + String.concat "\n" (pod2text ~trim:false ~discard:false "NAME" pod) + ^ "\n" in + pr "struct command_entry %s_cmd_entry = {\n" name; + pr " .name = \"%s\",\n" name2; + pr " .help = \"%s\",\n" (c_quote text); pr " .run = run_%s\n" name; pr "};\n"; pr "\n"; @@ -100,11 +102,7 @@ let generate_fish_cmds () = List.iter ( fun (name, (_, args, optargs), _, flags, _, shortdesc, longdesc) -> - pr "struct command_entry %s_cmd_entry = {\n" name; - let name2 = replace_char name '_' '-' in - pr " .name = \"%s\",\n" name2; - let aliases = filter_map (function FishAlias n -> Some n | _ -> None) flags in @@ -155,12 +153,16 @@ Guestfish will prompt for these separately." (String.concat " or " (List.map (fun s -> "'" ^ s ^ "'") aliases)) else "" in - pr " .shortdesc = \"%s\",\n" shortdesc; - pr " .podbody = %S,\n" - ("=head1 SYNOPSIS\n\n " ^ synopsis ^ "\n\n" ^ - "=head1 DESCRIPTION\n\n" ^ - longdesc ^ warnings ^ describe_alias); + let pod = + sprintf "%s - %s\n\n=head1 SYNOPSIS\n\n %s\n\n=head1 DESCRIPTION\n\n%s%s%s" + name2 shortdesc synopsis longdesc warnings describe_alias in + let text = + String.concat "\n" (pod2text ~trim:false ~discard:false "NAME" pod) + ^ "\n" in + pr "struct command_entry %s_cmd_entry = {\n" name; + pr " .name = \"%s\",\n" name2; + pr " .help = \"%s\",\n" (c_quote text); pr " .run = run_%s\n" name; pr "};\n"; pr "\n"; @@ -189,7 +191,7 @@ Guestfish will prompt for these separately." pr "\n"; pr " ct = lookup_fish_command (cmd, strlen (cmd));\n"; pr " if (ct) {\n"; - pr " pod2text (ct->entry->name, ct->entry->shortdesc, ct->entry->podbody);\n"; + pr " fputs (ct->entry->help, stdout);\n"; pr " return 0;\n"; pr " }\n"; pr " else\n";