2 parted - a frontend to libparted
3 Copyright (C) 1999-2000, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <parted/debug.h>
30 command_create (const StrList* names,
31 int (*method) (PedDevice** dev),
32 const StrList* summary,
34 const int non_interactive)
38 cmd = xmalloc (sizeof (Command));
41 cmd->non_interactive = 1;
43 cmd->non_interactive = 0;
45 cmd->names = (StrList*) names;
47 cmd->summary = (StrList*) summary;
48 cmd->help = (StrList*) help;
54 command_destroy (Command* cmd)
56 str_list_destroy (cmd->names);
57 str_list_destroy (cmd->summary);
58 str_list_destroy (cmd->help);
63 command_register (Command** list, Command* cmd)
67 for (i = 0; list [i]; i++);
70 list [i + 1] = (Command*) NULL;
74 command_get (Command** list, char* name)
77 int partial_match = -1;
83 for (i=0; list [i]; i++) {
84 switch (str_list_match_any (list [i]->names, name)) {
90 if (partial_match == -1) {
100 if (partial_match == -1)
103 return list [partial_match];
107 command_get_names (Command** list)
110 StrList* result = NULL;
112 for (walk = list; *walk; walk++)
113 result = str_list_join (result,
114 str_list_duplicate ((*walk)->names));
119 command_print_summary (Command* cmd)
122 str_list_print_wrap (cmd->summary, screen_width(), 2, 8);
127 command_print_help (Command* cmd)
129 command_print_summary (cmd);
131 fputs ("\n\t", stdout);
132 str_list_print_wrap (cmd->help, screen_width(), 8, 8);
137 command_run (Command* cmd, PedDevice** dev)
139 return cmd->method (dev);