t_listp *cut_the_path(char *str) { int i; int j; char *tmp; t_listp *path; i = 0; path = init_list(); while (str && str[i]) { j = 0; tmp = NULL; if (!(tmp = malloc(sizeof(char) * count_char_before(str, i)))) my_rprintf("Bad Malloc for the path.\n"); while (str[i] != '\0' && str[i] != ':') tmp[j++] = str[i++]; tmp[j] = 0; if (ins_elem(path, tmp, 1) == -1) my_rprintf("Bad insertion in list for the path.\n"); i++; free(tmp); } ins_elem(path, NULL, path->size); return (path); }
void create_list_ls(t_elem *elem, t_pos *list) { static int i; if ((ins_elem(list, elem, 1)) == -1) { my_printf("Erreur insertion element\n"); exit(3); } return ; }
t_listp *init_env(char **tab) { int i; t_listp *env; i = 0; env = init_list(); if (ins_elem(env, tab[i++], 1) == -1) { my_rprintf("Error to take the envirronement"); return (NULL); } while (tab[i]) { if (ins_elem(env, tab[i++], env->size) == -1) { my_rprintf("Error to take the envirronement"); return (NULL); } } ins_elem(env, tab[i], env->size); return (env); }
int inigrf(char * fnome, struct grafo ** g) { int i, j, k, n; struct grafo *gaux; FILE *fp; /* iniciando */ fp = fopen(fnome, "r"); /* abrindo o arquivo que contem o grafo de fluxo de controle */ if (fp == NULL) { char mensagem[255]; sprintf(mensagem, "Error: could not open file with data of the control flow graph (%s)\n", fnome); error(mensagem); } fscanf(fp, "%d", &n); /* obtive numero de nos */ gaux = (struct grafo *) malloc((n + 1) * sizeof(struct grafo)); /* aloquei memoria para o nos do grafo */ if (gaux == NULL) { error("Error: could not alloc memory to store the control flow graph"); } /* iniciando com todos os apontadores de listas de sucessores */ for (i = 0; i <= n; ++i) { gaux[i].list_suc = NULL; } /* construindo o grafo na memoria */ k=1; while (fscanf(fp, "%d", &i) != EOF && k <= n) { (gaux + i)->num = i; (gaux +i )->list_suc = NULL; if (i > n || i <= 0) { error("Error: CFG is not correctly specified in the file"); } for (fscanf(fp, "%d", &j); j != 0; fscanf(fp,"%d",&j)) { ins_elem(&((gaux+i)->list_suc),j); } k++; } if (fscanf(fp, "%d", &i) != EOF) { error("Error: there are more nodes than expected to be read"); } fclose(fp); *g = gaux; return n; }