avancement dans le replica.c
This commit is contained in:
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
REPLICA = replica
|
REPLICA = replica
|
||||||
|
|
||||||
REPLICA: replica.o
|
REPLICA: replica.o
|
||||||
cc -o replica replica.o
|
cc -o replica -g3 replica.o
|
||||||
|
|
||||||
replica.o: replica.c
|
replica.o: replica.c
|
||||||
cc -c replica.c
|
cc -c -g3 replica.c
|
||||||
|
|||||||
Binary file not shown.
+49
-3
@@ -2,6 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
static char *escape_str(const char *str)
|
static char *escape_str(const char *str)
|
||||||
{
|
{
|
||||||
@@ -53,8 +54,51 @@ static char *escape_double_quote(const char *str)
|
|||||||
return out;
|
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)
|
int main(int argc, char **argv)
|
||||||
@@ -70,10 +114,12 @@ int main(int argc, char **argv)
|
|||||||
while (1){
|
while (1){
|
||||||
if (getline(&line, &rded, in) == -1)
|
if (getline(&line, &rded, in) == -1)
|
||||||
break;
|
break;
|
||||||
printf("%s", line);
|
//printf("%s", line);
|
||||||
free(line);
|
free(line);
|
||||||
line = NULL;
|
line = NULL;
|
||||||
}
|
}
|
||||||
|
int end_line_count = search_end(in);
|
||||||
|
insert_into_section(in, argv[1], "INSERTED", end_line_count);
|
||||||
free(line);
|
free(line);
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user