1 /* dyncmd.c - support dynamic command */
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2009 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
23 #include <grub/misc.h>
24 #include <grub/command.h>
25 #include <grub/normal.h>
28 grub_dyncmd_dispatcher (struct grub_command
*cmd
,
29 int argc
, char **args
)
31 char *modname
= cmd
->data
;
35 mod
= grub_dl_load (modname
);
43 name
= (char *) cmd
->name
;
44 grub_unregister_command (cmd
);
46 cmd
= grub_command_find (name
);
48 ret
= (cmd
->func
) (cmd
, argc
, args
);
60 /* Read the file command.lst for auto-loading. */
62 read_command_list (void)
65 static int first_time
= 1;
67 /* Make sure that this function does not get executed twice. */
72 prefix
= grub_env_get ("prefix");
77 filename
= grub_malloc (grub_strlen (prefix
) + sizeof ("/command.lst"));
82 grub_sprintf (filename
, "%s/command.lst", prefix
);
83 file
= grub_file_open (filename
);
87 for (;; grub_free(buf
))
89 char *p
, *name
, *modname
;
93 buf
= grub_file_getline (file
);
105 if (! grub_isgraph (name
[0]))
108 p
= grub_strchr (name
, ':');
116 if (! grub_isgraph (*p
))
122 name
= grub_strdup (name
);
126 modname
= grub_strdup (p
);
133 cmd
= grub_register_command_prio (name
,
134 grub_dyncmd_dispatcher
,
135 0, "not loaded", prio
);
142 cmd
->flags
|= GRUB_COMMAND_FLAG_DYNCMD
;
145 /* Update the active flag. */
146 grub_command_find (name
);
149 grub_file_close (file
);
152 grub_free (filename
);
157 grub_errno
= GRUB_ERR_NONE
;