| pgetline, pgetlinex, pgetlinec - read a line from a file, optionally removing comments |
#include <pstring.h> char *pgetline (pool, FILE *fp, char *line); char *pgetlinex (pool, FILE *fp, char *line, const char *comment_set, int flags); #define pgetlinec(p,fp,line) pgetlinex ((p), (fp), (line), #",0)" |
| pgetline reads a single line from a file and returns it. It allocates enough space to read lines of arbitrary' and '0) are length. Line ending characters (' automatically removed from the end of the line. |
| The pool argument is a pool for allocating the line. The fp argument is the C FILE pointer. The line argument is a pointer to a string allocated in pool which will be reallocated and filled with the contents of the line. You may pass line as NULL to get a newly allocated buffer. |
| Use pgetline in one of the following two ways: |
| line = pgetline (pool, fp, line); |
| or |
| line = pgetline (pool, fp, NULL); |
| pgetlinex is a more advanced function which reads a line from a file, optionally removing comments, concatenating together lines which have been split with a backslash, and ignoring blank lines. pgetlinex (and the related macro pgetlinec) are very useful for reading lines of input from a configuration file. |
| The pool argument is a pool for allocating the line. The fp argument is the C FILE pointer. The line argument is a buffer allocated in pool which will be reallocated and filled with the result. comment_set is the set of possible comment characters -- eg. "#!" to allow either # or ! to be used to introduce comments. flags is zero or more of the following flags OR-ed together: |
| PGETL_NO_CONCAT: Don't concatenate lines which have been split with trailing backslash characters. |
| PGETL_INLINE_COMMENTS: Treat everything following a comment character as a comment. The default is to only allow comments which appear on a line on their own. |
| pgetlinec is a helper macro which calls pgetlinex with comment_set == "#" and flags == 0. |
| Richard Jones <rich@annexia.org> |
| GNU LGPL (see http://www.gnu.org/) |
| c2lib-1.2.13 |
| pmatch(3). |