Line Get Functions

There are a pair of functions which get a line of data from a file. There is a base fetch routine which knows nothing about the data other than is a line worth. The other repeatedly reads lines until it reaches one which does not have the standard configuration file comment characters at the start.


fgetline()

    #include <mplib1/fgetline.h>

    int fgetline( FILE *fh, char *line_buf, int line_len );
This function provides a simple way of reading a line from a file into a buffer. Up to line_len-1 characters will be read. The routine strips any trailing newline characters from the buffer.

The function returns 0 on success and -1 on failure.

A typical use would be look like.

    char tbuf[T_BUF_LEN];
    FILE *fh;

    ....

    while(fgetline(fh,tbuf,T_BUF_LEN)==0)
	process_line( tbuf );


fgetline2()

    #include <mplib1/fgetline.h>

    int fgetline2( FILE *fh, char *line_buf, int line_len );
This function provides a simple way of reading a line from a file into a buffer. Up to line_len-1 characters will be read. The routine strips any trailing newline characters from the buffer. It also skips any lines which have '#' as their first non-blank character.

The function returns 0 on success and -1 on failure.

A typical use would be look like.

    char tbuf[T_BUF_LEN];
    FILE *fh;

    ....

    while(fgetline2(fh,tbuf,T_BUF_LEN)==0)
	process_line( tbuf );