fish: Don't use external pod2text program.
authorRichard W.M. Jones <rjones@redhat.com>
Fri, 26 Nov 2010 21:51:11 +0000 (21:51 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Fri, 26 Nov 2010 21:51:11 +0000 (21:51 +0000)
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.

fish/cmds_gperf.h
fish/fish.c
fish/fish.h
generator/generator_fish.ml

index 92bd607..74db69d 100644 (file)
  * guestfish can execute.
  */
 struct command_entry {
  * 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[]);
 
   /* The run_* function. */
   int (*run) (const char *cmd, size_t argc, char *argv[]);
index c1dbfb4..50340a3 100644 (file)
@@ -531,24 +531,6 @@ set_up_terminal (void)
   have_terminfo = 1;
 }
 
   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)
 {
 static void
 prepare_drives (struct drv *drv)
 {
index 3597805..f4b6c9c 100644 (file)
@@ -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 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);
 extern void list_builtin_commands (void);
 extern int display_builtin_command (const char *cmd);
 extern void free_strings (char **argv);
index 0c81dfc..516c5b1 100644 (file)
@@ -76,11 +76,7 @@ let generate_fish_cmds () =
   (* List of command_entry structs. *)
   List.iter (
     fun (name, _, _, flags, _, shortdesc, longdesc) ->
   (* 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
       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 =
       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
 
             (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";
       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) ->
 
   List.iter (
     fun (name, (_, args, optargs), _, flags, _, shortdesc, longdesc) ->
-      pr "struct command_entry %s_cmd_entry = {\n" name;
-
       let name2 = replace_char name '_' '-' in
       let name2 = replace_char name '_' '-' in
-      pr "  .name = \"%s\",\n" name2;
-
       let aliases =
         filter_map (function FishAlias n -> Some n | _ -> None) flags in
 
       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
 
             (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";
       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 "\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";
   pr "    return 0;\n";
   pr "  }\n";
   pr "  else\n";