int builtin_history(t_cmd *cmd, t_system *sys) { t_history *tmp; if (cmd->args[1] == NULL) { tmp = sys->history; while (tmp->next != NULL) { my_printf("%s\n", tmp->cmd); tmp = tmp->next; } } else if (utl_strcmp(cmd->args[1], "-c") == 0) { while (sys->history != NULL) { tmp = sys->history; sys->history = sys->history->next; free(tmp->cmd); } } else if (utl_strcmp(cmd->args[1], "-d") == 0) remove_item(cmd, sys); return (0); }
t_tds_var *tds_get_next_var(t_tds_var *var, char *name) { while (var != NULL) { if (utl_strcmp(var->name, name) == 0) return (var); var = var->next; } return (var); }
t_tds_block *tds_get_next_block(t_tds_block *block, char *name) { while (block != NULL) { if (utl_strcmp(block->name, name) == 0) return (block); block = block->next; } return (block); }
t_arghandler get_arghandler_str(char *str) { int it; it = 0; while (g_arghandler[it].func != NULL) { if (utl_strcmp(g_arghandler[it].id_s, str) == 0) return (g_arghandler[it]); it++; } return (g_arghandler[it]); }
void args_modifier(t_cmd *cmd, char *name, t_system *sys, int k) { char **wtab; char *env_val; int check; check = 0; env_val = get_value(name, sys->env); if (utl_strcmp(env_val, name) == 0) { env_val = strdup("\0"); check = 1; } wtab = my_str_to_wtab(env_val, " \t\n"); if (wtab == NULL) return; if (check == 0) cmd->args = add_files_to_args(cmd->args, wtab, k); }
int cli_reg(int argc, char* argv[]) { int ret = -1; int found = 0; const cmd_decl_t* cmd_tbl = cmd_reg_tbl; if (argc > 0) { for (int i=0; cmd_tbl[i].cmd; i++) { if (!utl_strcmp(cmd_tbl[i].cmd, argv[0])) { found = 1; ret = (*cmd_tbl[i].cli_func)(argc-1, argv+1); break; } } } if (!found || ret == -1) { print_cmd_table(cmd_tbl); } return(ret); }