int runcmd(WJElement *doc, WJElement *current, char *cmd, char *args) { WJECLIcmd *command; int i; for (i = 0; (command = &WJECLIcmds[i]) && command->name; i++) { if (!stricmp(cmd, command->name)) { break; } } if (!*current) { *current = *doc; } if (command && command->name) { return(command->cb(doc, current, args)); } else if (!stricmp(cmd, "help")) { usage(NULL); return(0); } else { fprintf(stderr, "Unknown command: %s\n", cmd); return(3); } }
int runcmd(WJElement *doc, WJElement *current, char *line) { WJECLIcmd *command; char *cmd = line; char *args = NULL; int i; // cmd = nextField(line, &args); /* Look for a command using the letter, which does NOT require a space */ for (i = 0; (command = &WJECLIcmds[i]) && command->name; i++) { if (command->letter != '\0' && *cmd == command->letter) { args = skipspace(++cmd); break; } } /* Look for a full command */ if (!command || !command->name) { cmd = nextField(line, &args); for (i = 0; (command = &WJECLIcmds[i]) && command->name; i++) { if (!stricmp(cmd, command->name)) { break; } } } if (!*current) { *current = *doc; } if (command && command->name) { return(command->cb(doc, current, args)); } else { fprintf(stderr, "Unknown command: %s\n", cmd); return(3); } }