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 haseol
= line
[strlen(line
)-1]=='\n';
60 if (haseol
) line
[strlen(line
)-1]='\0';
62 while (!(haseol
|| feof(file
)))
65 line
= (char *)realloc(line
, slen
);
66 fgets(line
+strlen(line
), slen
, file
);
67 haseol
= line
[strlen(line
)-1]=='\n';
68 if (haseol
) line
[strlen(line
)-1]='\0';
78 void filewarning(const char *format
, ...)
82 fprintf(stderr
, "%s:%d:warning ", filename
, lineno
);
85 vfprintf(stderr
, format
, ap
);
89 void exitfileerror(int code
, const char *format
, ...)
93 fprintf(stderr
, "%s:%d:error ", filename
, lineno
);
96 vfprintf(stderr
, format
, ap
);