| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflfile.h" Bool file_read ( FILE *stream, char *string)
Reads a line of text delimited by newline from the stream. The string must be LINE_MAX + 1 long. Places a null byte in place of the newline character. Expands tab characters to every 8th column. Returns TRUE when there is more input waiting; FALSE when the last line of the file has been read. Sets the global variable file_crlf to TRUE if CR was found in the file. This variable is by default FALSE. It is also used by file_write.
{ int ch, /* Character read from file */ cnbr; /* Index into returned string */ ASSERT (stream); ASSERT (string); cnbr = 0; /* Start at the beginning... */ memset (string, ' ', LINE_MAX); /* and prepare entire line */ for (;;) { ch = fgetc (stream); /* Get next character from file */ if (ch == '\t') /* Jump if tab */ cnbr = ((cnbr >> 3) << 3) + 8; else if (ch == '\r') /* Found carriage-return */ file_crlf = TRUE; /* Set flag and ignore CR */ else if ((ch == '\n') /* Have end of line */ || (ch == EOF) /* or end of file */ || (ch == 26)) /* or MS-DOS Ctrl-Z */ { string [cnbr] = '\0'; /* Terminate string */ return (ch == '\n' || cnbr); /* and return TRUE/FALSE */ } else if (cnbr < LINE_MAX) string [cnbr++] = (char) ch; /* Else add char to string */ if (cnbr >= LINE_MAX) /* Return in any case if line is */ { /* too long - the line will be */ string [LINE_MAX] = '\0'; /* cut into pieces */ return (TRUE); } } }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |