int set_dump(char **argv, int *i, int *dump) { ++(*i); if (argv[(*i)] == NULL) { my_putstr2("no argument after \"-dump\"\n"); return (ERROR); } if (!isnum(argv[(*i)])) { my_putstr2("argument after \"-dump\" must be an unsigned number !\n"); return (ERROR); } (*dump) = my_atoi(argv[(*i)]); ++(*i); return (SUCCESS); }
int set_prog_adress(char **argv, int *i, int *a) { ++(*i); if (argv[(*i)] == NULL) { my_putstr2("no argument after \"-a\"\n"); return (ERROR); } if (!isnum(argv[(*i)])) { my_putstr2("argument after \"-a\" must be an unsigned number !\n"); return (ERROR); } (*a) = (my_atoi(argv[(*i)]) % MEM_SIZE); ++(*i); return (SUCCESS); }
int set_prog_path(char **argv, int *i, char **adress) { if (argv[(*i)] == NULL) { my_putstr2("no path specified after -a / -n\n"); return (ERROR); } (*adress) = my_strdup(argv[(*i)]); ++(*i); return (SUCCESS); }
int is_dir(char *path) { int fd; if (path == NULL) return (0); if ((fd = open(path, O_RDONLY | O_DIRECTORY)) < 0) return (0); close(fd); my_putstr2("Error : input is a folder\n"); return (1); }
void underline(char *str) { char *usstr; char *uestr; char t[4096]; char *area; area = t; usstr = xtgetstr("us", &area); if (tputs(usstr, 1, my_outc) == ERR) exit(-1); my_putstr2(str); uestr = xtgetstr("ue", &area); if (tputs(uestr, 1, my_outc) == ERR) exit(-1); }
void video_inv(char *str) { char *sostr; char *sestr; char t[4096]; char *area; area = t; sostr = xtgetstr("so", &area); if (tputs(sostr, 1, my_outc) == ERR) exit(-1); my_putstr2(str); sestr = xtgetstr("se", &area); if (tputs(sestr, 1, my_outc) == ERR) exit(-1); }
void my_cd(t_lnv *list, char *path) { static t_lnv *env; if (list != NULL) env = list; else if (list == NULL && env != NULL) { if (!is_cdpathdir(path) && my_strcmp("-", path)) { set_lastreturnvalue(NULL, 1); my_putstr2("Error : the path given is not a directory\n"); return; } my_cd2(env, path, NULL, NULL); } set_lastreturnvalue(NULL, 1); }
int check_magic(char buf[], int rd) { int i; int m; int n; i = 0; m = 0; n = 256 * 256 * 256; while (i < rd) { m += buf[i] * n; n /= 256; i++; } if (m == MAGIC) return (1); my_putstr2("Bad magic number\n"); return (0); }
int write_champ(t_chp *champ, char *mem) { int warning; int j; warning = 0; j = 0; while (j < champ->header.prog_size) { if (!warning && mem[circ((champ->pc + j))] != 0) { my_putstr2("warning : one of the programs is overwriting another. " "If this is an issue, make sure to set a proper adress " "or to load less or smaller programs !\n"); ++warning; } mem[circ((champ->pc + j))] = champ->raw[j]; j++; } return (SUCCESS); }