int command_doline(buffer_t* out, command_t* commands, const char* line) { uint8_t argc; char** argv = NULL; int error; command_t* command; if (NULL == commands || NULL == line) return EFAULT; argc = command_split(line, &argv); if (NULL == argv) return errno; if (!argc || NULL == (command = command_find(commands, argv[0]))) { command_sfree(&argv); command_report_error(out, commands, ENOCMD); return ENOCMD; } error = command_do(out, command, argc, argv); command_sfree(&argv); return error; }
int mymain(void) { int argc = 0; char * argv[10]; int i = 0; led_init(); uart_init(); nand_init(); nand_read_id(buf); putchar_hex(buf[0]); putchar_hex(buf[1]); putchar_hex(buf[2]); putchar_hex(buf[3]); putchar_hex(buf[4]); printf("\n\n" __DATE__ " " __TIME__ "\n"); printf("welcome to my boot v1.0 \n\n"); //printf("test: %c,%s,%d,%x\n", 'A', "abcdef", 11, 0x23); while (1) { printf("LUMIT $ "); gets(buf); printf("your input: <%s>\n", buf); argc = shell_parse(buf, argv); for (i = 0; i < argc; i++) printf("%d: <%s>\n", i, argv[i]); command_do(argc, argv); } }
static int rmmod_do_module(struct kmod_module *mod, bool do_dependencies) { const char *modname = kmod_module_get_name(mod); struct kmod_list *pre = NULL, *post = NULL; const char *cmd = NULL; int err; if (!ignore_commands) { err = kmod_module_get_softdeps(mod, &pre, &post); if (err < 0) { WRN("could not get softdeps of '%s': %s\n", modname, strerror(-err)); return err; } cmd = kmod_module_get_remove_commands(mod); } if (cmd == NULL && !ignore_loaded) { int state = kmod_module_get_initstate(mod); if (state < 0) { LOG ("Module %s not found.\n", modname); err = -ENOENT; goto error; } else if (state == KMOD_MODULE_BUILTIN) { LOG("Module %s is builtin.\n", modname); err = -ENOENT; goto error; } else if (state != KMOD_MODULE_LIVE) { if (first_time) { LOG("Module %s is not in kernel.\n", modname); err = -ENOENT; goto error; } else { err = 0; goto error; } } } rmmod_do_deps_list(post, false); if (do_dependencies && remove_dependencies) { struct kmod_list *deps = kmod_module_get_dependencies(mod); err = rmmod_do_deps_list(deps, true); if (err < 0) goto error; } if (!ignore_loaded) { int usage = kmod_module_get_refcnt(mod); if (usage > 0) { if (!quiet_inuse) LOG("Module %s is in use.\n", modname); err = -EBUSY; goto error; } } if (cmd == NULL) err = rmmod_do_remove_module(mod); else err = command_do(mod, "remove", cmd, NULL); if (err < 0) goto error; rmmod_do_deps_list(pre, false); error: kmod_module_unref_list(pre); kmod_module_unref_list(post); return err; }