-/*)Function char * readlin()
- *
- * char * str poinetr to beginning of the buffer
- * size_t n size of the buffer
- * FILE * infp input file pointer
- *
- * The function readlin() reads a line from a file to the buffer s.
- * The buffer length is n. If the line is truncterd to n -1 caharecters
- * if it is longer the n - 1 characters.
- * Trailing LF or CR/LF are removed from str, if present.
- *
- * local variables:
- * int c character read from the file
- * char *s buffer pointer
- * satic char eof_f EOF flag
- *
- * global variables:
- * none
- *
- * called functions:
- * int getc c-library
- */
-
-char *
-readlin(char *str, size_t n, FILE *infp)
-{
- int c = ' '; /* initialize it to something for the caharacter eating step */
- char *s;
- static char eof_f = 0;
-
- if (eof_f)
- {
- eof_f = 0;
- return NULL;
- }
-
- if (n > 0)
- {
- s = str;
- if (n > 1)
- {
- while (--n && (c = getc(infp)) != '\n' && c != EOF)
- *s++ = c;
- }
-
- /* chop CR */
- if (s > str && *(s - 1) == '\r')
- --s;
-
- /* terminate the line */
- *s = '\0';
-
- /* eat characters until the end of line */
- while (c != '\n' && c != EOF)
- c = getc(infp);
-
- /* if the EOF is not at the beginning of the line, return the line;
- return NULL at the next call of redlin */
- if (c == EOF)
- {
- if (s == str)
- return NULL;
- eof_f = 1;
- }
- }
-
- return str;
-}
-