2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
4 Desc: The functions to read lines from a file
11 static char *line
= NULL
; /* The current read file */
12 static char *filename
= NULL
; /* The name of the opened file */
13 static FILE *file
= NULL
; /* The opened file */
14 static unsigned int slen
= 0; /* The allocation length pointed to be line */
15 static unsigned int lineno
= 0; /* The line number, will be increased by one everytime a line is read */
17 int fileopen(const char *fname
)
27 file
= fopen(fname
, "r");
29 filename
= strdup(fname
);
49 if (file
==NULL
|| feof(file
))
57 if (fgets(line
, slen
, file
))
59 size_t len
= strlen(line
);
60 haseol
= line
[len
-1]=='\n';
61 if (haseol
) line
[len
-1]='\0';
63 while (!(haseol
|| feof(file
)))
66 line
= (char *)realloc(line
, slen
);
67 if (fgets(line
+len
, slen
, file
))
70 haseol
= line
[len
-1]=='\n';
71 if (haseol
) line
[len
-1]='\0';
73 else if (ferror(file
))
88 void filewarning(const char *format
, ...)
92 fprintf(stderr
, "%s:%d:warning ", filename
, lineno
);
95 vfprintf(stderr
, format
, ap
);
99 void exitfileerror(int code
, const char *format
, ...)
103 fprintf(stderr
, "%s:%d:error ", filename
, lineno
);
105 va_start(ap
, format
);
106 vfprintf(stderr
, format
, ap
);