2 * Copyright (C) 2009-2010 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (* Please read generator/README first. *)
26 open Generator_docstrings
27 open Generator_optgroups
28 open Generator_actions
29 open Generator_structs
30 open Generator_prepopts
33 (* Generate a lot of different functions for guestfish. *)
34 let generate_fish_cmds () =
35 generate_header CStyle GPLv2plus;
39 fun (_, _, _, flags, _, _, _) -> not (List.mem NotInFish flags)
41 let all_functions_sorted =
43 fun (_, _, _, flags, _, _, _) -> not (List.mem NotInFish flags)
44 ) all_functions_sorted in
46 let all_functions_and_fish_commands_sorted =
47 List.sort action_compare (all_functions_sorted @ fish_commands) in
49 pr "#include <config.h>\n";
51 pr "/* It is safe to call deprecated functions from this file. */\n";
52 pr "#undef GUESTFS_WARN_DEPRECATED\n";
54 pr "#include <stdio.h>\n";
55 pr "#include <stdlib.h>\n";
56 pr "#include <string.h>\n";
57 pr "#include <inttypes.h>\n";
59 pr "#include \"c-ctype.h\"\n";
60 pr "#include \"full-write.h\"\n";
61 pr "#include \"xstrtol.h\"\n";
63 pr "#include <guestfs.h>\n";
64 pr "#include \"fish.h\"\n";
65 pr "#include \"fish-cmds.h\"\n";
66 pr "#include \"options.h\"\n";
67 pr "#include \"cmds_gperf.h\"\n";
69 pr "/* Valid suffixes allowed for numbers. See Gnulib xstrtol function. */\n";
70 pr "static const char *xstrtol_suffixes = \"0kKMGTPEZY\";\n";
74 fun (name, _, _, _, _, _, _) ->
75 pr "static int run_%s (const char *cmd, size_t argc, char *argv[]);\n"
81 (* List of command_entry structs. *)
83 fun (name, _, _, flags, _, shortdesc, longdesc) ->
84 let name2 = replace_char name '_' '-' in
86 filter_map (function FishAlias n -> Some n | _ -> None) flags in
89 sprintf "\n\nYou can use %s as an alias for this command."
90 (String.concat " or " (List.map (fun s -> "'" ^ s ^ "'") aliases))
94 sprintf "%s - %s\n\n=head1 DESCRIPTION\n\n%s\n\n%s"
95 name2 shortdesc longdesc describe_alias in
97 String.concat "\n" (pod2text ~trim:false ~discard:false "NAME" pod)
100 pr "struct command_entry %s_cmd_entry = {\n" name;
101 pr " .name = \"%s\",\n" name2;
102 pr " .help = \"%s\",\n" (c_quote text);
103 pr " .run = run_%s\n" name;
109 fun (name, (_, args, optargs), _, flags, _, shortdesc, longdesc) ->
110 let name2 = replace_char name '_' '-' in
112 filter_map (function FishAlias n -> Some n | _ -> None) flags in
114 let longdesc = replace_str longdesc "C<guestfs_" "C<" in
119 let args = List.filter (function Key _ -> false | _ -> true) args in
123 (List.map (fun arg -> " " ^ name_of_argt arg) args))
125 (List.map (fun arg -> sprintf " [%s:..]" (name_of_argt arg)) optargs)) in
128 if List.exists (function Key _ -> true | _ -> false) args then
129 "\n\nThis command has one or more key or passphrase parameters.
130 Guestfish will prompt for these separately."
135 if List.mem ProtocolLimitWarning flags then
136 ("\n\n" ^ protocol_limit_warning)
139 (* For DangerWillRobinson commands, we should probably have
140 * guestfish prompt before allowing you to use them (especially
141 * in interactive mode). XXX
145 if List.mem DangerWillRobinson flags then
146 ("\n\n" ^ danger_will_robinson)
151 match deprecation_notice flags with
153 | Some txt -> "\n\n" ^ txt in
156 if aliases <> [] then
157 sprintf "\n\nYou can use %s as an alias for this command."
158 (String.concat " or " (List.map (fun s -> "'" ^ s ^ "'") aliases))
162 sprintf "%s - %s\n\n=head1 SYNOPSIS\n\n %s\n\n=head1 DESCRIPTION\n\n%s%s%s"
163 name2 shortdesc synopsis longdesc warnings describe_alias in
165 String.concat "\n" (pod2text ~trim:false ~discard:false "NAME" pod)
168 pr "struct command_entry %s_cmd_entry = {\n" name;
169 pr " .name = \"%s\",\n" name2;
170 pr " .help = \"%s\",\n" (c_quote text);
171 pr " .run = run_%s\n" name;
176 (* list_commands function, which implements guestfish -h *)
177 pr "void list_commands (void)\n";
179 pr " printf (\" %%-16s %%s\\n\", _(\"Command\"), _(\"Description\"));\n";
180 pr " list_builtin_commands ();\n";
182 fun (name, _, _, flags, _, shortdesc, _) ->
183 let name = replace_char name '_' '-' in
184 pr " printf (\"%%-20s %%s\\n\", \"%s\", _(\"%s\"));\n"
186 ) all_functions_and_fish_commands_sorted;
187 pr " printf (\" %%s\\n\",";
188 pr " _(\"Use -h <cmd> / help <cmd> to show detailed help for a command.\"));\n";
192 (* display_command function, which implements guestfish -h cmd *)
193 pr "int display_command (const char *cmd)\n";
195 pr " const struct command_table *ct;\n";
197 pr " ct = lookup_fish_command (cmd, strlen (cmd));\n";
199 pr " fputs (ct->entry->help, stdout);\n";
203 pr " return display_builtin_command (cmd);\n";
207 let emit_print_list_function typ =
208 pr "static void print_%s_list (struct guestfs_%s_list *%ss)\n"
211 pr " unsigned int i;\n";
213 pr " for (i = 0; i < %ss->len; ++i) {\n" typ;
214 pr " printf (\"[%%d] = {\\n\", i);\n";
215 pr " print_%s_indent (&%ss->val[i], \" \");\n" typ typ;
216 pr " printf (\"}\\n\");\n";
222 (* print_* functions *)
226 List.exists (function (_, (FUUID|FBuffer)) -> true | _ -> false) cols in
228 pr "static void print_%s_indent (struct guestfs_%s *%s, const char *indent)\n" typ typ typ;
231 pr " unsigned int i;\n";
237 pr " printf (\"%%s%s: %%s\\n\", indent, %s->%s);\n" name typ name
239 pr " printf (\"%%s%s: \", indent);\n" name;
240 pr " for (i = 0; i < 32; ++i)\n";
241 pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
242 pr " printf (\"\\n\");\n"
244 pr " printf (\"%%s%s: \", indent);\n" name;
245 pr " for (i = 0; i < %s->%s_len; ++i)\n" typ name;
246 pr " if (c_isprint (%s->%s[i]))\n" typ name;
247 pr " printf (\"%%c\", %s->%s[i]);\n" typ name;
249 pr " printf (\"\\\\x%%02x\", %s->%s[i]);\n" typ name;
250 pr " printf (\"\\n\");\n"
251 | name, (FUInt64|FBytes) ->
252 pr " printf (\"%%s%s: %%\" PRIu64 \"\\n\", indent, %s->%s);\n"
255 pr " printf (\"%%s%s: %%\" PRIi64 \"\\n\", indent, %s->%s);\n"
258 pr " printf (\"%%s%s: %%\" PRIu32 \"\\n\", indent, %s->%s);\n"
261 pr " printf (\"%%s%s: %%\" PRIi32 \"\\n\", indent, %s->%s);\n"
264 pr " printf (\"%%s%s: %%c\\n\", indent, %s->%s);\n"
266 | name, FOptPercent ->
267 pr " if (%s->%s >= 0) printf (\"%%s%s: %%g %%%%\\n\", indent, %s->%s);\n"
268 typ name name typ name;
269 pr " else printf (\"%%s%s: \\n\", indent);\n" name
275 (* Emit a print_TYPE_list function definition only if that function is used. *)
278 | typ, (RStructListOnly | RStructAndList) ->
279 (* generate the function for typ *)
280 emit_print_list_function typ
281 | typ, _ -> () (* empty *)
282 ) (rstructs_used_by all_functions);
284 (* Emit a print_TYPE function definition only if that function is used. *)
287 | typ, (RStructOnly | RStructAndList) ->
288 pr "static void print_%s (struct guestfs_%s *%s)\n" typ typ typ;
290 pr " print_%s_indent (%s, \"\");\n" typ typ;
293 | typ, _ -> () (* empty *)
294 ) (rstructs_used_by all_functions);
296 (* run_<action> actions *)
298 fun (name, (ret, args, optargs as style), _, flags, _, _, _) ->
300 pr "run_%s (const char *cmd, size_t argc, char *argv[])\n" name;
305 | RBool _ -> pr " int r;\n"
306 | RInt64 _ -> pr " int64_t r;\n"
307 | RConstString _ | RConstOptString _ -> pr " const char *r;\n"
308 | RString _ -> pr " char *r;\n"
309 | RStringList _ | RHashtable _ -> pr " char **r;\n"
310 | RStruct (_, typ) -> pr " struct guestfs_%s *r;\n" typ
311 | RStructList (_, typ) -> pr " struct guestfs_%s_list *r;\n" typ
314 pr " size_t size;\n";
320 | OptString n -> pr " const char *%s;\n" n
325 | Key n -> pr " char *%s;\n" n
327 pr " const char *%s;\n" n;
328 pr " size_t %s_size;\n" n
329 | StringList n | DeviceList n -> pr " char **%s;\n" n
330 | Bool n -> pr " int %s;\n" n
331 | Int n -> pr " int %s;\n" n
332 | Int64 n -> pr " int64_t %s;\n" n
333 | Pointer _ -> assert false
336 if optargs <> [] then (
337 pr " struct guestfs_%s_argv optargs_s = { .bitmask = 0 };\n" name;
338 pr " struct guestfs_%s_argv *optargs = &optargs_s;\n" name
341 if args <> [] || optargs <> [] then
342 pr " size_t i = 0;\n";
346 (* Check and convert parameters. *)
347 let argc_minimum, argc_maximum =
349 List.filter (function Key _ -> false | _ -> true) args in
350 let argc_minimum = List.length args_no_keys in
351 let argc_maximum = argc_minimum + List.length optargs in
352 argc_minimum, argc_maximum in
354 if argc_minimum = argc_maximum then (
355 pr " if (argc != %d) {\n" argc_minimum;
356 pr " fprintf (stderr, _(\"%%s should have %%d parameter(s)\\n\"), cmd, %d);\n"
359 pr " if (argc < %d || argc > %d) {\n" argc_minimum argc_maximum;
360 pr " fprintf (stderr, _(\"%%s should have %%d-%%d parameter(s)\\n\"), cmd, %d, %d);\n"
361 argc_minimum argc_maximum;
363 pr " fprintf (stderr, _(\"type 'help %%s' for help on %%s\\n\"), cmd, cmd);\n";
367 let parse_integer expr fn fntyp rtyp range name =
369 pr " strtol_error xerr;\n";
372 pr " xerr = %s (%s, NULL, 0, &r, xstrtol_suffixes);\n" fn expr;
373 pr " if (xerr != LONGINT_OK) {\n";
374 pr " fprintf (stderr,\n";
375 pr " _(\"%%s: %%s: invalid integer parameter (%%s returned %%d)\\n\"),\n";
376 pr " cmd, \"%s\", \"%s\", xerr);\n" name fn;
381 | Some (min, max, comment) ->
382 pr " /* %s */\n" comment;
383 pr " if (r < %s || r > %s) {\n" min max;
384 pr " fprintf (stderr, _(\"%%s: %%s: integer out of range\\n\"), cmd, \"%s\");\n"
388 pr " /* The check above should ensure this assignment does not overflow. */\n";
390 pr " %s = r;\n" name;
398 pr " %s = argv[i++];\n" name
400 | Dev_or_Path name ->
401 pr " %s = win_prefix (argv[i++]); /* process \"win:\" prefix */\n" name;
402 pr " if (%s == NULL) return -1;\n" name
404 pr " %s = STRNEQ (argv[i], \"\") ? argv[i] : NULL;\n" name;
407 pr " %s = argv[i];\n" name;
408 pr " %s_size = strlen (argv[i]);\n" name;
411 pr " %s = file_in (argv[i++]);\n" name;
412 pr " if (%s == NULL) return -1;\n" name
414 pr " %s = file_out (argv[i++]);\n" name;
415 pr " if (%s == NULL) return -1;\n" name
416 | StringList name | DeviceList name ->
417 pr " %s = parse_string_list (argv[i++]);\n" name;
418 pr " if (%s == NULL) return -1;\n" name
420 pr " %s = read_key (\"%s\");\n" name name;
421 pr " if (%s == NULL) return -1;\n" name
423 pr " %s = is_true (argv[i++]) ? 1 : 0;\n" name
426 let min = "(-(2LL<<30))"
427 and max = "((2LL<<30)-1)"
429 "The Int type in the generator is a signed 31 bit int." in
430 Some (min, max, comment) in
431 parse_integer "argv[i++]" "xstrtoll" "long long" "int" range name
433 parse_integer "argv[i++]" "xstrtoll" "long long" "int64_t" None name
434 | Pointer _ -> assert false
437 (* Optional arguments are prefixed with <argname>:<value> and
438 * may be missing, so we need to parse those until the end of
441 if optargs <> [] then (
442 let uc_name = String.uppercase name in
444 pr " for (; i < argc; ++i) {\n";
445 pr " uint64_t this_mask;\n";
446 pr " const char *this_arg;\n";
451 let n = name_of_argt argt in
452 let uc_n = String.uppercase n in
453 let len = String.length n in
454 pr "if (STRPREFIX (argv[i], \"%s:\")) {\n" n;
457 pr " optargs_s.%s = is_true (&argv[i][%d]) ? 1 : 0;\n"
461 let min = "(-(2LL<<30))"
462 and max = "((2LL<<30)-1)"
464 "The Int type in the generator is a signed 31 bit int." in
465 Some (min, max, comment) in
466 let expr = sprintf "&argv[i][%d]" (len+1) in
467 parse_integer expr "xstrtoll" "long long" "int" range
468 (sprintf "optargs_s.%s" n)
470 let expr = sprintf "&argv[i][%d]" (len+1) in
471 parse_integer expr "xstrtoll" "long long" "int64_t" None
472 (sprintf "optargs_s.%s" n)
474 pr " optargs_s.%s = &argv[i][%d];\n" n (len+1);
477 pr " this_mask = GUESTFS_%s_%s_BITMASK;\n" uc_name uc_n;
478 pr " this_arg = \"%s\";\n" n;
484 pr " fprintf (stderr, _(\"%%s: unknown optional argument \\\"%%s\\\"\\n\"),\n";
485 pr " cmd, argv[i]);\n";
489 pr " if (optargs_s.bitmask & this_mask) {\n";
490 pr " fprintf (stderr, _(\"%%s: optional argument \\\"%%s\\\" given twice\\n\"),\n";
491 pr " cmd, this_arg);\n";
494 pr " optargs_s.bitmask |= this_mask;\n";
499 (* Call C API function. *)
501 pr " r = guestfs_%s " name
503 pr " r = guestfs_%s_argv " name;
504 generate_c_call_args ~handle:"g" style;
509 | Device _ | String _
510 | OptString _ | Bool _
513 | Pathname name | Dev_or_Path name | FileOut name
515 pr " free (%s);\n" name
517 pr " free_file_in (%s);\n" name
518 | StringList name | DeviceList name ->
519 pr " free_strings (%s);\n" name
520 | Pointer _ -> assert false
523 (* Any output flags? *)
525 let flags = filter_map (
526 function FishOutput flag -> Some flag | _ -> None
532 failwithf "%s: more than one FishOutput flag is not allowed" name in
534 (* Check return value for errors and display command results. *)
536 | RErr -> pr " return r;\n"
538 pr " if (r == -1) return -1;\n";
539 (match fish_output with
541 pr " printf (\"%%d\\n\", r);\n";
542 | Some FishOutputOctal ->
543 pr " printf (\"%%s%%o\\n\", r != 0 ? \"0\" : \"\", r);\n";
544 | Some FishOutputHexadecimal ->
545 pr " printf (\"%%s%%x\\n\", r != 0 ? \"0x\" : \"\", r);\n");
548 pr " if (r == -1) return -1;\n";
549 (match fish_output with
551 pr " printf (\"%%\" PRIi64 \"\\n\", r);\n";
552 | Some FishOutputOctal ->
553 pr " printf (\"%%s%%\" PRIo64 \"\\n\", r != 0 ? \"0\" : \"\", r);\n";
554 | Some FishOutputHexadecimal ->
555 pr " printf (\"%%s%%\" PRIx64 \"\\n\", r != 0 ? \"0x\" : \"\", r);\n");
558 pr " if (r == -1) return -1;\n";
559 pr " if (r) printf (\"true\\n\"); else printf (\"false\\n\");\n";
562 pr " if (r == NULL) return -1;\n";
563 pr " printf (\"%%s\\n\", r);\n";
565 | RConstOptString _ ->
566 pr " printf (\"%%s\\n\", r ? : \"(null)\");\n";
569 pr " if (r == NULL) return -1;\n";
570 pr " printf (\"%%s\\n\", r);\n";
574 pr " if (r == NULL) return -1;\n";
575 pr " print_strings (r);\n";
576 pr " free_strings (r);\n";
578 | RStruct (_, typ) ->
579 pr " if (r == NULL) return -1;\n";
580 pr " print_%s (r);\n" typ;
581 pr " guestfs_free_%s (r);\n" typ;
583 | RStructList (_, typ) ->
584 pr " if (r == NULL) return -1;\n";
585 pr " print_%s_list (r);\n" typ;
586 pr " guestfs_free_%s_list (r);\n" typ;
589 pr " if (r == NULL) return -1;\n";
590 pr " print_table (r);\n";
591 pr " free_strings (r);\n";
594 pr " if (r == NULL) return -1;\n";
595 pr " if (full_write (1, r, size) != size) {\n";
596 pr " perror (\"write\");\n";
607 (* run_action function *)
609 pr "run_action (const char *cmd, size_t argc, char *argv[])\n";
611 pr " const struct command_table *ct;\n";
613 pr " ct = lookup_fish_command (cmd, strlen (cmd));\n";
615 pr " return ct->entry->run (cmd, argc, argv);\n";
617 pr " fprintf (stderr, _(\"%%s: unknown command\\n\"), cmd);\n";
618 pr " if (command_num == 1)\n";
619 pr " extended_help_message ();\n";
624 and generate_fish_cmds_h () =
625 generate_header CStyle GPLv2plus;
627 pr "#ifndef FISH_CMDS_H\n";
628 pr "#define FISH_CMDS_H\n";
632 fun (shortname, _, _, _, _, _, _) ->
633 pr "extern int run_%s (const char *cmd, size_t argc, char *argv[]);\n"
638 pr "#endif /* FISH_CMDS_H */\n"
640 (* gperf code to do fast lookups of commands. *)
641 and generate_fish_cmds_gperf () =
642 generate_header CStyle GPLv2plus;
644 let all_functions_sorted =
646 fun (_, _, _, flags, _, _, _) -> not (List.mem NotInFish flags)
647 ) all_functions_sorted in
649 let all_functions_and_fish_commands_sorted =
650 List.sort action_compare (all_functions_sorted @ fish_commands) in
654 %%define lookup-function-name lookup_fish_command
666 #include \"cmds_gperf.h\"
671 fun (name, _, _, _, _, _, _) ->
672 pr "extern struct command_entry %s_cmd_entry;\n" name
673 ) all_functions_and_fish_commands_sorted;
678 struct command_table;
684 fun (name, _, _, flags, _, _, _) ->
685 let name2 = replace_char name '_' '-' in
687 filter_map (function FishAlias n -> Some n | _ -> None) flags in
689 (* The basic command. *)
690 pr "%s, &%s_cmd_entry\n" name name;
692 (* Command with dashes instead of underscores. *)
693 if name <> name2 then
694 pr "%s, &%s_cmd_entry\n" name2 name;
696 (* Aliases for the command. *)
699 pr "%s, &%s_cmd_entry\n" alias name;
701 ) all_functions_and_fish_commands_sorted
703 (* Readline completion for guestfish. *)
704 and generate_fish_completion () =
705 generate_header CStyle GPLv2plus;
709 fun (_, _, _, flags, _, _, _) -> not (List.mem NotInFish flags)
719 #ifdef HAVE_LIBREADLINE
720 #include <readline/readline.h>
725 #ifdef HAVE_LIBREADLINE
727 static const char *const commands[] = {
728 BUILTIN_COMMANDS_FOR_COMPLETION,
731 (* Get the commands, including the aliases. They don't need to be
732 * sorted - the generator() function just does a dumb linear search.
736 fun (name, _, _, flags, _, _, _) ->
737 let name2 = replace_char name '_' '-' in
739 filter_map (function FishAlias n -> Some n | _ -> None) flags in
741 ) (all_functions @ fish_commands) in
742 let commands = List.flatten commands in
744 List.iter (pr " \"%s\",\n") commands;
750 generator (const char *text, int state)
752 static size_t index, len;
760 rl_attempted_completion_over = 1;
762 while ((name = commands[index]) != NULL) {
764 if (STRCASEEQLEN (name, text, len))
765 return strdup (name);
771 #endif /* HAVE_LIBREADLINE */
773 #ifdef HAVE_RL_COMPLETION_MATCHES
774 #define RL_COMPLETION_MATCHES rl_completion_matches
776 #ifdef HAVE_COMPLETION_MATCHES
777 #define RL_COMPLETION_MATCHES completion_matches
779 #endif /* else just fail if we don't have either symbol */
782 do_completion (const char *text, int start, int end)
784 char **matches = NULL;
786 #ifdef HAVE_LIBREADLINE
787 rl_completion_append_character = ' ';
790 matches = RL_COMPLETION_MATCHES (text, generator);
791 else if (complete_dest_paths)
792 matches = RL_COMPLETION_MATCHES (text, complete_dest_paths_generator);
799 (* Generate the POD documentation for guestfish. *)
800 and generate_fish_actions_pod () =
801 let all_functions_sorted =
803 fun (_, _, _, flags, _, _, _) ->
804 not (List.mem NotInFish flags || List.mem NotInDocs flags)
805 ) all_functions_sorted in
807 let rex = Str.regexp "C<guestfs_\\([^>]+\\)>" in
810 fun (name, (_, args, optargs), _, flags, _, _, longdesc) ->
812 Str.global_substitute rex (
815 try Str.matched_group 1 s
817 failwithf "error substituting C<guestfs_...> in longdesc of function %s" name in
818 "L</" ^ replace_char sub '_' '-' ^ ">"
820 let name = replace_char name '_' '-' in
822 filter_map (function FishAlias n -> Some n | _ -> None) flags in
826 pr "=head2 %s\n\n" name
831 | Pathname n | Device n | Dev_or_Path n | String n ->
833 | OptString n -> pr " %s" n
834 | StringList n | DeviceList n -> pr " '%s ...'" n
835 | Bool _ -> pr " true|false"
836 | Int n -> pr " %s" n
837 | Int64 n -> pr " %s" n
838 | FileIn n | FileOut n -> pr " (%s|-)" n
839 | BufferIn n -> pr " %s" n
840 | Key _ -> () (* keys are entered at a prompt *)
841 | Pointer _ -> assert false
845 | Bool n | Int n | Int64 n | String n -> pr " [%s:..]" n
850 pr "%s\n\n" longdesc;
852 if List.exists (function FileIn _ | FileOut _ -> true
853 | _ -> false) args then
854 pr "Use C<-> instead of a filename to read/write from stdin/stdout.\n\n";
856 if List.exists (function Key _ -> true | _ -> false) args then
857 pr "This command has one or more key or passphrase parameters.
858 Guestfish will prompt for these separately.\n\n";
860 if optargs <> [] then
861 pr "This command has one or more optional arguments. See L</OPTIONAL ARGUMENTS>.\n\n";
863 if List.mem ProtocolLimitWarning flags then
864 pr "%s\n\n" protocol_limit_warning;
866 if List.mem DangerWillRobinson flags then
867 pr "%s\n\n" danger_will_robinson;
869 match deprecation_notice flags with
871 | Some txt -> pr "%s\n\n" txt
872 ) all_functions_sorted
874 (* Generate documentation for guestfish-only commands. *)
875 and generate_fish_commands_pod () =
877 fun (name, _, _, flags, _, _, longdesc) ->
878 let name = replace_char name '_' '-' in
880 filter_map (function FishAlias n -> Some n | _ -> None) flags in
884 pr "=head2 %s\n\n" name
886 pr "%s\n\n" longdesc;
889 and generate_fish_prep_options_h () =
890 generate_header CStyle GPLv2plus;
892 pr "#ifndef PREPOPTS_H\n";
897 const char *name; /* eg. \"fs\" */
899 size_t nr_params; /* optional parameters */
900 struct prep_param *params;
902 const char *shortdesc; /* short description */
903 const char *longdesc; /* long description */
905 /* functions to implement it */
906 void (*prelaunch) (const char *filename, prep_data *);
907 void (*postlaunch) (const char *filename, prep_data *, const char *device);
911 const char *pname; /* parameter name */
912 const char *pdefault; /* parameter default */
913 const char *pdesc; /* parameter description */
916 extern const struct prep preps[];
919 " (List.length prepopts);
922 fun (name, shortdesc, args, longdesc) ->
924 extern void prep_prelaunch_%s (const char *filename, prep_data *data);
925 extern void prep_postlaunch_%s (const char *filename, prep_data *data, const char *device);
931 pr "#endif /* PREPOPTS_H */\n"
933 and generate_fish_prep_options_c () =
934 generate_header CStyle GPLv2plus;
940 #include \"prepopts.h\"
945 fun (name, shortdesc, args, longdesc) ->
946 pr "static struct prep_param %s_args[] = {\n" name;
948 fun (n, default, desc) ->
949 pr " { \"%s\", \"%s\", \"%s\" },\n" n default desc
955 pr "const struct prep preps[] = {\n";
957 fun (name, shortdesc, args, longdesc) ->
958 pr " { \"%s\", %d, %s_args,
961 prep_prelaunch_%s, prep_postlaunch_%s },
963 name (List.length args) name
964 (c_quote shortdesc) (c_quote longdesc)