| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflfile.h" Bool file_readn ( FILE *stream, char *string, int line_max)
Works as file read() but with a maximum line-length specified by the caller. The supplied buffer must be at least as large as the specified line_max + 1.
{ 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 |