void get_obj_params(t_obj *obj, char *s, short *nb_obj) { if (s[0] == '<' && s[1] != '/') obj->type = get_type(s); get_prs_params(obj, s); obj->id_grp = get_data_short("ID_GRP = ", s, obj->id_grp); obj->ra = get_data_short("RA = ", s, obj->ra); obj->rb = get_data_float("RB = ", s, obj->rb); obj->sp = get_data_short("SP = ", s, obj->sp); obj->br = get_data_float("BR = ", s, obj->br); obj->kd = get_data_float("Kd = ", s, obj->kd); obj->ks = get_data_float("Ks = ", s, obj->ks); obj->kr = get_data_float("Kr = ", s, obj->kr); obj->damier = get_data_short("DAMIER = ", s, obj->damier); if (my_strncmp("COLOR = ", s, 8) == 0) obj->color = (int)my_getnbr_base(&s[8], "0123456789ABCDEF"); else if (my_strncmp("COLOR_IN = ", s, 11) == 0) obj->color_in = (int)my_getnbr_base(&s[11], "0123456789ABCDEF"); else if (my_strncmp("COLOR_SP = ", s, 11) == 0) obj->color_sp = (int)my_getnbr_base(&s[11], "0123456789ABCDEF"); else if (my_strncmp("TEXTURE = ", s, 10) == 0) obj->tex.file = my_strncpy(&s[10], 0, my_strlen(&s[9])); else if (my_strncmp("</", s, 2) == 0) obj->id = (*nb_obj)++; }
int is_relative_dir(char *bin) { if (!my_strncmp(bin, "~/", 2) || !my_strncmp(bin, "/", 1) || !my_strncmp(bin, "./", 2) || access(bin, F_OK) == 0) return (1); return (0); }
int ls(){ DIR* rep = NULL; rep = opendir("."); if (rep == NULL){ return(1); perror("Erreur rep"); } while ((file = readdir(rep))){ if (my_strncmp(file->d_name,".",1) != 0 && my_strncmp(file->d_name,"..",1) != 0){ my_putstr(file->d_name); my_putstr(" "); } } my_putstr(" "); my_putstr("\n"); if (file == NULL){ return(1); perror("erreur fichier"); } if (closedir(rep) == -1) return(-1); return 0; }
t_pars *my_path_remp(t_struct *struc, char **env, t_pars *pars, int i) { if (struc->instruction != NULL) if (!(pars->path = malloc(sizeof(char) * (my_strlen(struc->instruction) + 10)))) return (NULL); if (my_strncmp(struc->instruction, "./", 2) == 0) return (my_relativ_path(struc, pars)); while (env[i]) { if (my_global_path(struc) == 0) { pars = my_global_remp(pars, struc); break; } if (my_strncmp(env[i], "PATH=", 5) == 0) return (my_path_access(pars, env, i)); else { free(pars->path); pars->path = NULL; } i++; } return (pars); }
int main(void) { char * A = "Hello!"; char * B = "Hello from Chicago"; char * C = " Excellent. Perfect."; char result[1024] = "Hi "; printf("Test 1: "); printf("%s\n", my_strcat(result, A)); printf("Test 2: "); printf("%s\n", my_strncpy(result, B, 2)); printf("Test 3: "); printf("%s\n", my_strncpy(result, B, 100)); printf("Test 4: "); printf("%s\n", my_strncat(result, C, 10)); printf("Test 5: "); printf("%d\n", my_strncmp(A, B, 5)); printf("Test 6: "); printf("%d\n", my_strncmp(A, B, 10)); return 0; }
static int my_check_line(header_t *header, char **str) { char *tmp; int i; if ((tmp = my_sup_comment(*str)) == NULL) return (1); free(*str); i = 0; while (tmp[i] == ' ' || tmp[i] == '\t') i++; if (my_strncmp(tmp + i, COMMENT_CMD_STRING, my_strlen(COMMENT_CMD_STRING)) == 0) my_cpy_comment(header, tmp + i); else if (my_strncmp(tmp + i, NAME_CMD_STRING, my_strlen(NAME_CMD_STRING)) == 0) my_cpy_name(header, tmp + i); if ((*str = my_epur_str(tmp)) == NULL) return (1); free(tmp); if (**str == '\0') return (1); else if (**str == '.') return (1); return (0); }
int main() { char before1[] = "________"; char after1[] = "--------"; printf("strncopy 3\n"); printf("\t before:\t %s\n", before1); printf("\t after: \t %s\n", after1); my_strncopy(before1, after1, 3); printf("\t\t*poof*\n"); printf("\t before:\t %s\n\n", before1); char before2[] = "________"; char after2[] = "--------"; printf("strncat 3\n"); printf("\t before:\t %s\n", before2); printf("\t after: \t %s\n", after2); my_strncat(before2, after2, 3); printf("\t\t*poof*\n"); printf("\t before:\t %s\n\n", before2); char first[] = "star wars"; char second[] = "star trek"; printf("Do the first %i letters of '%s' match '%s'?\n", 4, first, second); int end = my_strncmp(first, second, 4); end == 0 ? printf("\tyes\n\n") : printf("\tno\n\n"); printf("Do the first %i letters of '%s' match '%s'?\n", 6, first, second); end = my_strncmp(first, second, 6); end == 0 ? printf("\t yes\n\n") : printf("\t no\n\n"); }
int check_msg_leave(t_socket *sock, char *all, fd_set *readfds) { int i; int len; i = -1; while (++i < MAX_CLIENTS) if (FD_ISSET(sock->cli_sock[i], readfds)) { len = read(sock->cli_sock[i], all, MAX_MSG - 1); all[len] = '\0'; if (len == 0) close_sock(sock, i); else { if (my_strncmp(all, "/start ", 7) == 0 && my_strncmp(sock->pseudo[0], &all[7], my_strlen(sock->pseudo[0])) == 0) socket_send_seed_all(sock, sock->seed); else socket_send_msg_all(sock, all); } } return (0); }
int str_compare(char **tab, int index) { if (my_strncmp(tab[index], "int", 3) == 0) return (1); if (my_strncmp(tab[index], "char", 4) == 0) return (1); if (my_strncmp(tab[index], "float", 5) == 0) return (1); if (my_strncmp(tab[index], "double", 6) == 0) return (1); if (my_strncmp(tab[index], "const", 5) == 0) return (1); if (my_strncmp(tab[index], "void", 4) == 0) return (1); if (my_strncmp(tab[index], "static", 6) == 0) return (1); if (my_strncmp(tab[index], "unsigned", 8) == 0) return (1); if (my_strncmp(tab[index], "short", 5) == 0) return (1); if (my_strncmp(tab[index], "long", 4) == 0) return (1); if (str_compare_struct(tab, index) == 1) return (1); return (0); }
int str_compare_struct(char **tab, int index) { if (my_strncmp(tab[index], "typedef struct", 14) == 0) return (1); if (my_strncmp(tab[index], "struct", 6) == 0) return (1); return (0); }
int my_global_path(t_struct *struc) { if (my_strncmp(struc->instruction, "/bin/", 5) == 0) return (0); if (my_strncmp(struc->instruction, "/usr/bin/", 9) == 0) return (0); if (my_strncmp(struc->instruction, "/usr/sbin/", 10) == 0) return (0); if (my_strncmp(struc->instruction, "/sbin/", 6) == 0) return (0); return (1); }
int check_load(t_shell *shell, t_prg *prg) { int res; if ((my_strlen(prg->args[0]) == 4) && !(my_strncmp(prg->args[0], "load", 4))) { res = exec_load(shell, prg->args); return 1; } if ((my_strlen(prg->args[0]) == 6) && !(my_strncmp(prg->args[0], "unload", 6))) return exec_unload(shell, prg->args); return -1; }
char get_type(char *str) { if (!my_strncmp(&str[1], "SPHERE", 6)) return (0); else if (!my_strncmp(&str[1], "CYLINDER", 8)) return (1); else if (!my_strncmp(&str[1], "CONE", 4)) return (2); else if (!my_strncmp(&str[1], "PLAN", 4)) return (3); else return (-1); }
int isopt(char *str, t_parser *parser) { int i; i = 0; while (parser->opt[i]) { if (my_strncmp(parser->opt[i], str, my_strlen(parser->opt[i])) == 0 && my_strncmp(str, "||", 2) != 0) return (1); i++; } return (0); }
void remove_comment_and_name(char *file) { int i; i = -1; while (file[++i]) { if (!my_strncmp(&file[i], NAME_CMD_STRING, my_strlen(NAME_CMD_STRING))) while (file[i] != '\n' && file[i]) shift_string(file, i); if (!my_strncmp(&file[i], COMMENT_CMD_STRING, my_strlen(COMMENT_CMD_STRING))) while (file[i] != '\n' && file[i]) shift_string(file, i); } }
int check_builtins(t_cmd *cmds, char **env) { int cur_case; char **builtins; int found; int (*fptr[6])(t_cmd *, char ***); found = -1; cur_case = -1; if ((builtins = my_split(get_builtins(), ';')) == NULL) return (-1); fill_func_ptr(fptr); if (cmds->name != NULL) { while (builtins[++cur_case]) if (my_strncmp(builtins[cur_case], cmds->name, get_longest_string(builtins[cur_case], cmds->name)) == 0) { fptr[cur_case](cmds, &env); found = 1; } free_tab(builtins); } return (found); }
int my_strcmp(const char* s1, const char* s2) { // TODO // begin ikouna_l return my_strncmp(s1,s2,-1); return 0; }
void check_first(char **argv, char **envp, pid_t pid, t_shell *shell) { int i; i = 0; if (shell->buffer[0] == 'l' && shell->buffer[1] == 's' && shell->buffer[3] == ' ' && shell->buffer[4] == '\0') { execve(path_dir("/bin/", "ls"), argv, NULL); exit(1); } if (my_strncmp(shell->buffer, "cd", 2) == 0) { i = chdir(shell->reader[1]); exit(1); } else if (my_strcmp(shell->buffer, "exit") == 0) { kill(pid, 1); exit(1); } else if (my_strcmp(shell->buffer, "env") == 0) show_env(envp); else if (my_strcmp(shell->buffer, "clear") == 0) clear_window(); }
void aff_stoi(int i, char *str, int n) { int j; char temp[200]; while (str[i]) { j = 0; if (my_strncmp(&str[i], "speciesReference stoichiometry=", 31) == 0) { i = i + 32; while (str[i] != '\"') { temp[j] =str[i]; j++; i++; } temp[j] = '\0'; if (n > 0) printf("+ "); printf("%i ", atoi(temp)); break; } i--; } }
//int my_strcmp(char *p,char *q) int my_strncmp(char *p,char *q,int n) { /* for(;*p;p++,q++) {if(*p!=*q) break; } if(*p==*q) return 0; else if(*p>*q) return 1; else return -1; */ //if (*p && *p==*q) if(--n &&*p==*q) return(my_strncmp(p+1,q+1,n)); else if(*p==*q) return 0; else if(*p>*q) return 1; else return -1; }
int my_getenv(char *name, char **env) { int i; char *search; int name_len; name_len = my_strlen(name) + 2; search = (char*)malloc(sizeof(char) * name_len); if (search != NULL) { my_strcpy(search, name); my_strcat(search, "="); i = 0; while (env[i] != NULL) { if (my_strncmp(env[i], search, name_len) == 0) { free(search); return (i); } i = i + 1; } free(search); } return (-1); }
static char *my_cd_back(char *path, char **env) { char *tmp; char *home; char *pwd; char *oldpwd; tmp = NULL; oldpwd = my_getenv(env, "OLDPWD"); if (my_strcmp(path, "-") == 0) { tmp = my_strdup(oldpwd); my_putpath(env, my_realpath(tmp), 1); } else if (my_strcmp(path, "--") == 0) { pwd = my_getenv(env, "PWD"); home = my_getenv(env, "HOME"); if (my_strncmp(pwd, home, my_strlen(home)) == 0) tmp = my_strdup(home); else tmp = my_strdup("/"); } return (tmp); }
int my_cd(t_datas *datas, char **cmd) { int res; char *path; char *pwd; res = 0; if (my_cd_usage(cmd) < 0) return (-1); path = my_cd_realpath(cmd[1], datas->env); if (path == NULL && my_strncmp(cmd[1], "~", 1) == 0) return (my_error(cmd[0], "no such file or directory", cmd[1])); if (path == NULL) return (my_error(cmd[0], "memory allocation failed.", NULL)); res = my_cd_check(path); if (res == 0) { pwd = my_getenv(datas->env, "PWD"); res = my_sys_setenv(datas, "cd", "OLDPWD", pwd); } if (res == 0) res = my_sys_setenv(datas, "cd", "PWD", path); free((char *)path); return (res); }
int toto() { char toto[] = "Coucou Ca Va ?"; char test[20]; char dest[7]; printf("sa marche ? toto fait %d char\n", my_strlen("toto")); my_memcpy(dest, toto, 14); dest[14] = 0; printf("dest = [%s]\n", dest); printf("strchr = [%s]\n", my_strchr(toto, 'a')); printf("strcmp toto, dest = %d\n", my_strcmp(toto + 1, dest)); dest[3] = 'a'; printf("strncmp toto, dest = %d\n", my_strncmp(toto, dest, 3)); my_bzero(toto, 5); printf("bzero = [%s]\n", toto + 5); printf("strcasecmp = %d\n", strcasecmp("SALUT", "123456")); my_write(1, "test\n", 5); printf("rindex my toto with the char 'a' : [%s]\n", my_rindex("caca coco coucou", 'i')); test[14] = 0; printf("apres le memset = [%s]\n", my_memset(test, 'A', 14)); strcpy(dest, "Coucou"); printf("memmove result = [%s]\n", memmove(dest, dest + 1, 20)); printf("dest = [%s]\n", dest); }
char *find_last(t_history *list, char *comp) { end(&list); while (my_strncmp(list->cmd, comp + 1, my_strlen(comp) - 1)) list = list->prev; return (list->cmd); }
void my_unsetenv(char *str, t_details *details) { char *unset_name; int len_name; int i; if ((unset_name = malloc(my_strlen(str) + 1)) == NULL) return; i = 8; while (str[++i] != '\0') unset_name[i - 9] = str[i]; unset_name[i - 9] = '\0'; len_name = my_strlen(unset_name); i = 0; while ((details->env[i] != NULL) && (my_strncmp(unset_name, details->env[i], len_name) != 0)) i++; if (details->env[i] != NULL) { free(details->env[i]); if ((details->env[i] = malloc(1)) == NULL) return; details->env[i][0] = '\0'; } }
void unset_env_key(const char *key, t_shell *shell) { t_env *prev; t_env *cur; int length; prev = NULL; cur = shell->env; length = my_strlen(key); while (cur) { if (!my_strncmp(key, cur->var, length) && cur->var[length] && cur->var[length] == '=') { if (cur->var != NULL) free(cur->var); if (prev != NULL) prev->next = cur->next; else shell->env = cur->next; free(cur); return; } prev = cur; cur = cur->next; } }
char *check_comment(char *str) { int fd; int quotes; char *comment; char *tmp; fd = xopen(str, O_RDONLY); comment = NULL; while ((tmp = get_next_line(fd))) { if (my_strncmp(tmp, COMMENT_CMD_STRING, 8) == 0) { quotes = count_dot(tmp, 0, '"'); if (quotes < 2) print_bad_comment(); else return (recup_comment(tmp)); } } close(fd); if (comment == NULL) print_header_error(); return (NULL); }
int handle_keyboard(t_tetris *s) { static char **keys; char buff[10]; int len; int i; len = 0; i = -1; if ((keys = malloc(sizeof(char *) * 6)) == NULL) exit_tetris("Error with malloc\n", -1); keys[0] = s->keys->keyleft; keys[1] = s->keys->keyright; keys[2] = s->keys->keydrop; keys[3] = s->keys->keyturn; keys[4] = s->keys->keypause; keys[5] = s->keys->keyquit; mode(0, 1); len = read(0, buff, 10); buff[len] = '\0'; mode(1, 1); if (len > 0) while (redirection[++i] && !(my_strncmp(buff, keys[i], 0))); free(keys); return (i >= 0 && i != 6) ? redirection[i](s) : (0); }
int my_setenv(char ***env, char *variable, char *value) { char **tmp_var; int i; i = 0; tmp_var = *env; if (variable == NULL || value == NULL) return (my_putstr_error("usage: setenv VARIABLE VALUE\n")); if (variable == NULL || my_strlen(variable) == 0 || my_strchr(variable, '=') != NULL) return (my_putstr_error("error : variable NULL or '=' in name\n")); if ((variable = add_egale(variable)) == NULL) return (-1); while (tmp_var && tmp_var[i] && my_strncmp(variable, tmp_var[i], my_strlen(variable)) != 0) i = i + 1; if (tmp_var == NULL || tmp_var[i] == NULL) { if ((push_env(env, variable, value)) == -1) return (-1); } else if ((mod_env(&tmp_var[i], value)) == -1) return (-1); return (0); }