int main(void) { char *ptr; char *name; char **arg; while (1) { write(1, "$>", 2); get_next_line(0, &ptr); if (ft_strcmp(ptr, "exit") == 0) return (0); arg = ft_get_args(&ptr, &name); if (!ft_check_builtin(arg)) { if (!ft_run_cmd(name, arg)) { ft_putstr_fd(name, 2); ft_putendl_fd(": command not found", 2); } } free(name); ft_free(arg); } return (0); }
void ft_instructions_sti(t_dvm *vm, t_instructions inst, t_proc *proc) { int registre; int add; int address; if (ft_check_value_args(proc->args, &inst, vm, proc)) { registre = proc->args[0].value; if (ft_get_args(proc)) { log_inst(proc->player, proc->id, "STI"); if (proc->args[1].type == IND_CODE) proc->args[1].type %= IDX_MOD; add = (proc->args[1].value + proc->args[2].value); address = add % IDX_MOD + proc->pc % MEM_SIZE; ft_log_sti(vm, proc, registre); address = ft_convert_pc(address); address *= 2; ft_put_registre(vm->arene, proc->args[0].value, address % SIZE_CHAR_ARENE); ft_put_color_size(vm->color, vm->code_color[ABS(proc->player)], address / 2, 4); } } if ((proc->pc = (proc->pc_turfu / 2)) >= MEM_SIZE) proc->pc %= MEM_SIZE; }
int do_syscall(int child, int *status) { int syscall = ptrace(PTRACE_PEEKUSER, child, sizeof(long)*ORIG_EAX); unsigned int nb_arg = 0; t_proto proto; t_regs regs; regs.ebx = 0; regs.ecx = 0; regs.edx = 0; regs.esi = 0; regs.edi = 0; regs.ebp = 0; regs.ebx2 = NULL; regs.ecx2 = NULL; regs.edx2 = NULL; regs.esi2 = NULL; regs.edi2 = NULL; regs.ebp2 = NULL; proto.a = -1; proto.b = -1; proto.c = -1; proto.d = -1; proto.e = -1; proto.f = -1; proto.ret = -1; if ( (unsigned int) syscall < (sizeof(magic_syscall) / sizeof(magic_syscall[0])) && (magic_syscall[syscall]).name) nb_arg = magic_syscall[syscall].nb_arg; e_trap trap = wait_for_trap(child, status); if (trap == EXIT) { // dprintf(1, "Syscall to EXIT"); dprintf(1, "Unknown exit\n"); exit(0); } else if (trap == SYSCALL) { // dprintf(1, "Syscall to SYSCALL"); ft_parse_proto(magic_syscall[syscall].proto, &proto); ft_get_args(®s, nb_arg, child, &proto); if ( (unsigned int) syscall < (sizeof(magic_syscall) / sizeof(magic_syscall[0])) && (magic_syscall[syscall]).name) put_syscall_name(magic_syscall[syscall].name); else dprintf(2, "NULL "); dprintf(2, " = "); int retval = ptrace(PTRACE_PEEKUSER, child, sizeof(long)*EAX); if (proto.ret == 1) dprintf(2, "%11ld\t", retval); else dprintf(2, "%11p\t", (unsigned int) retval); ft_aff_args(®s, nb_arg, &proto); } else if (trap == SIGNAL) { // dprintf(1, "Syscall to SIGNAL"); return (do_signal(child, status)); } return (0); }
int main(int ac, char **av) { t_args *args; int ret; t_item *items; args = NULL; ret = 0; items = NULL; args = ft_get_args(ac, av); items = get_start(args->items); if (args->options->R == 0) args->options->l ? long_display(items, args) : short_display(items, args); ret = args->ret; clean_program(&args); return (ret); }
int main(int ac, char **av) { t_list *lst; t_list *tmp; if (ac > 1) { lst = ft_get_args(ac, av, tab, 's'); tmp = lst; while(tmp) { printf("{\n type=%d\n opt=%s\n fd=%d\n err=%d\n str=%s\n val=%d\n}\n\n", ((t_parg *)(tmp->content))->type, ((t_parg *)(tmp->content))->opt, ((t_parg *)(tmp->content))->fd,((t_parg *)(tmp->content))->err, ((t_parg *)(tmp->content))->str, ((t_parg *)(tmp->content))->val); tmp = tmp->next; } } return (0); }
int main(int ac, char **av) { t_args *args; t_item *cursor; args = ft_get_args(ac, av); cursor = get_start(args->items); if (cursor->child) { cursor = cursor->child; while (cursor) { printf("%s\n", cursor->name); cursor = cursor->next; } } clean_program(&args); return (0); }
void ft_instructions_lld(t_dvm *vm, t_instructions inst, t_proc *proc) { int registre; if (ft_check_value_args(proc->args, &inst, vm, proc)) { registre = proc->args[1].value; if (ft_get_args(proc)) { if (proc->args[0].type == IND_CODE) proc->args[0].value = ft_get_indirect(proc->args[0].value, vm, proc); ft_log_lld(vm, proc, registre); if ((*(proc->ireg + --registre) = proc->args[0].value)) proc->carry = 0; else proc->carry = 1; } } if ((proc->pc = (proc->pc_turfu / 2)) >= MEM_SIZE) proc->pc %= MEM_SIZE; }