libite
Classes | Functions
lfile.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
Include dependency graph for lfile.c:

Functions

lfile_tlfopen (const char *file, const char *sep)
 Open file and return parsing context. More...
 
void lfclose (lfile_t *lf)
 Close a parser context. More...
 
char * lftok (lfile_t *lf)
 Get next token in file. More...
 
char * lfgetkey (lfile_t *lf, const char *key)
 Find key in file. More...
 
int lfgetint (lfile_t *lf, const char *key)
 Same as lfgetkey() but returns an integer. More...
 
int fgetint (const char *file, const char *sep, const char *key)
 Find the integer value for key in a file. More...
 

Detailed Description

Author
Joachim Wiberg
Date
2015-2021

Function Documentation

◆ fgetint()

int fgetint ( const char *  file,
const char *  sep,
const char *  key 
)

Find the integer value for key in a file.

Parameters
fileFile to search for key
sepSeparator for tokens in file
keyKey to look for in file

This is a convenience wrapper for lfopen(), lfgetint(), and lfclose().

Returns
The positive integer value for key, or -1 if not found.

◆ lfclose()

void lfclose ( lfile_t lf)

Close a parser context.

Parameters
lfPointer to lfile_t parser context from lfopen()

◆ lfgetint()

int lfgetint ( lfile_t lf,
const char *  key 
)

Same as lfgetkey() but returns an integer.

Parameters
lfPointer to lfile_t parser context from lfopen()
keyKey to look for

This function is the same as lfgetkey() but returns the positive integer value for the matching key, if found.

Returns
The positive integer value for key, or -1 if not found.

◆ lfgetkey()

char* lfgetkey ( lfile_t lf,
const char *  key 
)

Find key in file.

Parameters
lfPointer to lfile_t parser context from lfopen()
keyKey to look for

Locate key from the current position in the file parser context returned from lfopen(). Please note, the search for key does not start from the beginning of the file, it searches from the current position. To restart search from the beginning use rewind() on the lf->fp.

Returns
The value to key, or NULL if not found.

◆ lfopen()

lfile_t* lfopen ( const char *  file,
const char *  sep 
)

Open file and return parsing context.

Parameters
fileFile to parse
sepSeparator(s) to use in lftok()
Returns
Pointer to an lfile_t parser context, or NULL on error.

◆ lftok()

char* lftok ( lfile_t lf)

Get next token in file.

Parameters
lfPointer to lfile_t parser context from lfopen()
Returns
Next token, read from file previously opened with lfopen(), or NULL if EOF.