diff --git a/REPLICA/Makefile b/REPLICA/Makefile index 488ffbf..ad71ebc 100644 --- a/REPLICA/Makefile +++ b/REPLICA/Makefile @@ -1,7 +1,7 @@ REPLICA = replica REPLICA: replica.o - cc -o replica replica.o + cc -o replica -g3 replica.o replica.o: replica.c - cc -c replica.c + cc -c -g3 replica.c diff --git a/REPLICA/replica b/REPLICA/replica index cc869f0..c192c3c 100755 Binary files a/REPLICA/replica and b/REPLICA/replica differ diff --git a/REPLICA/replica.c b/REPLICA/replica.c index a281f30..eb84ce2 100644 --- a/REPLICA/replica.c +++ b/REPLICA/replica.c @@ -2,6 +2,7 @@ #include #include #include +#include static char *escape_str(const char *str) { @@ -53,8 +54,51 @@ static char *escape_double_quote(const char *str) return out; } -static int insert_into_section(FILE* file, const char* toInsert, int nbLine){ - +static int search_end(FILE* file){ + fseek(file, 0, SEEK_SET); + char* line = NULL; + size_t rded = 0; + char* found = NULL; + int line_count = 0; + while (getline(&line, &rded, file) != -1) { + printf("%s", line); + found = strstr(line, "//END"); + if (found != NULL) + { + printf("MOTIF TROUVE: ligne %d\n", line_count); + free(line); + return line_count; + } + free(line); + line = NULL; + line_count++; + } + free(line); + return -1; +} + +static int insert_into_section(FILE* file, const char* name_out, const char* toInsert, int nbLine){ + if (strlen(name_out) > 48) + return -1; + int end = search_end(file); + char name_concat[50] = {0}; + for (int i = 0; name_out[i] != 0; i++){ + name_concat[i] = name_out[i]; + if (name_out[i + 1] == 0){ + name_concat[i + 1] = '.'; + name_concat[i + 2] = 'i'; + } + } + printf("%s: name_concat for the moment: %s\n", __FUNCTION__, name_out); + FILE* out = fopen(name_out, "w"); + if (end != -1){ + printf("%s: end recupere\n", __FUNCTION__); + } + else{ + printf("%s: end non trouve\n", __FUNCTION__); + } + fclose(out); + return 0; } int main(int argc, char **argv) @@ -70,10 +114,12 @@ int main(int argc, char **argv) while (1){ if (getline(&line, &rded, in) == -1) break; - printf("%s", line); + //printf("%s", line); free(line); line = NULL; } + int end_line_count = search_end(in); + insert_into_section(in, argv[1], "INSERTED", end_line_count); free(line); fclose(in); return 0;