libite 2.6.1
lfile.c File Reference
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>

Go to the source code of this file.

Functions

lfile_t * lfopen (const char *file, const char *sep)
 
void lfclose (lfile_t *lf)
 
char * lftok (lfile_t *lf)
 
char * lfgetkey (lfile_t *lf, const char *key)
 
int lfgetint (lfile_t *lf, const char *key)
 
int fgetint (const char *file, const char *sep, const char *key)
 

Detailed Description

Author
Joachim Wiberg
Date
2015-2021

Definition in file lfile.c.

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.

Definition at line 177 of file lfile.c.

◆ lfclose()

void lfclose ( lfile_t * lf)

Close a parser context.

Parameters
lfPointer to lfile_t parser context from lfopen()

Definition at line 75 of file lfile.c.

◆ 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.

Definition at line 156 of file lfile.c.

◆ 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.

Definition at line 131 of file lfile.c.

◆ 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.

Definition at line 46 of file lfile.c.

◆ 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.

Definition at line 92 of file lfile.c.