|
|
@ -5,17 +5,24 @@
|
|
|
|
char *read_line(FILE *file) {
|
|
|
|
char *read_line(FILE *file) {
|
|
|
|
size_t length = 0, size = 128;
|
|
|
|
size_t length = 0, size = 128;
|
|
|
|
char *string = malloc(size);
|
|
|
|
char *string = malloc(size);
|
|
|
|
|
|
|
|
char lastChar = '\0';
|
|
|
|
if (!string) {
|
|
|
|
if (!string) {
|
|
|
|
return NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
while (1) {
|
|
|
|
int c = getc(file);
|
|
|
|
int c = getc(file);
|
|
|
|
|
|
|
|
if (c == '\n' && lastChar == '\\'){
|
|
|
|
|
|
|
|
--length; // Ignore last character.
|
|
|
|
|
|
|
|
lastChar = '\0';
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (c == EOF || c == '\n' || c == '\0') {
|
|
|
|
if (c == EOF || c == '\n' || c == '\0') {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (c == '\r') {
|
|
|
|
if (c == '\r') {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lastChar = c;
|
|
|
|
if (length == size) {
|
|
|
|
if (length == size) {
|
|
|
|
char *new_string = realloc(string, size *= 2);
|
|
|
|
char *new_string = realloc(string, size *= 2);
|
|
|
|
if (!new_string) {
|
|
|
|
if (!new_string) {
|
|
|
|