File: configfile.h

package info (click to toggle)
lcdproc 0.5.7-7
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 5,056 kB
  • ctags: 6,533
  • sloc: ansic: 58,028; sh: 1,963; perl: 681; makefile: 484
file content (107 lines) | stat: -rw-r--r-- 3,670 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/** \file configfile.h
 * Declare routines to read INI-file like files.
 */

/* This file is part of LCDd, the lcdproc server.
 *
 * This file is released under the GNU General Public License. Refer to the
 * COPYING file distributed with this package.
 *
 * Copyright (c) 2001, Joris Robijn
 *           (c) 2006,2007 Peter Marschall
 *
 */

#ifndef CONFIGFILE_H
#define CONFIGFILE_H

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

/* Opens the specified file and reads everything into memory.
 * Returns 0  when config file was successfully parsed
 * Returns <0 on errors
 */
int config_read_file(const char *filename);

#if defined(LCDPROC_CONFIG_READ_STRING)
/* Reads everything in the string into memory.
 * Returns 0  when config file was successfully parsed
 * Returns <0 on errors
 */
int config_read_string(const char *sectionname, const char *str);
#endif

/* Tries to interpret a value in the config file as a boolean.
 * 0, false, off, no, n = false
 * 1, true, on, yes, y = true
 * If the key is not found or cannot be interpreted, the given default value is
 * returned.
 * The skip value can be used to iterate over multiple values with the same
 * key. Should be 0 to get the first one, 1 for the second etc. and -1 for the
 * last.
 */
short config_get_bool(const char *sectionname, const char *keyname,
		int skip, short default_value);

/* Tries to interpret a value in the config file as a boolean.
 * 0, false, off, no, n = 0
 * 1, true, on, yes, y = 1
 * 2, or the given 3rd name = 2
 * If the key is not found or cannot be interpreted, the given default value is
 * returned.
 * The skip value can be used to iterate over multiple values with the same
 * key. Should be 0 to get the first one, 1 for the second etc. and -1 for the
 * last.
 */
short config_get_tristate(const char *sectionname, const char *keyname,
		int skip, const char *name3rd, short default_value);

/* Tries to interpret a value in the config file as an integer.*/
long int config_get_int(const char *sectionname, const char *keyname,
		int skip, long int default_value);

/* Tries to interpret a value in the config file as a float.*/
double config_get_float(const char *sectionname, const char *keyname,
		int skip, double default_value);

/* Returns a pointer to the string associated with the specified key.
 * The strings returned are always NUL-terminated.
 * The string should never be modified, and used only short-term.
 * In successive calls this function can * re-use the data space !
 *
 * You can do some things with the returned string:
 * 1. Scan or parse it:
 *    s = config_get_string(...);
 *    sscanf( s, "%dx%d", &w, &h );  // scan format like: 20x4
 *    ...and check the w and h values...
 * 2. Copy it to a preallocated buffer like device[256]:
 *    s = config_get_string(...);
 *    strncpy( device, s, sizeof(device));
 *    device[sizeof(device)-1] = 0;
 * 3. Copy it to a newly allocated space in char *device:
 *    s = config_get_string(...);
 *    device = malloc(strlen(s)+1);
 *    if( device == NULL ) return -5; // or whatever < 0
 *    strcpy( device, s );
 */
const char *config_get_string(const char *sectionname, const char *keyname,
		int skip, const char *default_value);

/* Checks if a specified section exists.
 * Returns whether it exists.
 */
int config_has_section(const char *sectionname);

/* Checks if a specified key within the specified section exists.
 * Returns the number of times the key exists.
 */
int config_has_key(const char *sectionname, const char *keyname);

/* Clears all data stored by the config_read_* functions.
 * Should be called if the config should be reread.
 */
void config_clear(void);

#endif