int command_exec(char *cmd) { int i; char *arg; const command_t const *current_commands; begin_parse(cmd); current_commands = commands; is_negation = false; while (1) { arg = parse_next_arg(); if (arg == NULL) break; if (!strcmp("no", arg)) { /* This is a negation of the command. */ is_negation = true; continue; } for (i = 0; current_commands[i].id != NULL; i++) { if ((current_commands[i].id != NULL && !strcmp(current_commands[i].id, arg)) || (current_commands[i].alias != NULL && !strcmp(current_commands[i].alias, arg))) { if ((void *)current_commands[i].command != NULL) return (current_commands[i].command()); else current_commands = current_commands[i].subcommands; break; } } } return (-1); }
ATSAPI ats_err_t ATSCALL ats_wft_init(struct ats_wft *wft, const char *file_path) { file_t *file = fopen(file_path, "rb"); if (!file) { return ATS_FILE_ERROR; } ats_err_t err = wft_init(wft); if (err) { fclose(file); return ATS_ALLOC_FAILED; } err = begin_parse(file, wft); if (err) { fclose(file); return err; } fclose(file); return ATS_NO_ERROR; }