4
* Interface for non-destructively reading/writing files containing
5
* only shell variable declarations and full-line comments.
7
* Includes explicit inheritance mechanism intended for use with
8
* Red Hat Linux ifcfg-* files. There is no protection against
9
* inheritance loops; they will generally cause stack overflows.
10
* Furthermore, they are only intended for one level of inheritance;
11
* the value setting algorithm assumes this.
13
* Copyright 1999 Red Hat, Inc.
15
* This is free software; you can redistribute it and/or modify it
16
* under the terms of the GNU General Public License as published by
17
* the Free Software Foundation; either version 2 of the License, or
18
* (at your option) any later version.
20
* This program is distributed in the hope that it will be useful, but
21
* WITHOUT ANY WARRANTY; without even the implied warranty of
22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23
* General Public License for more details.
25
* You should have received a copy of the GNU General Public License
26
* along with this program; if not, write to the Free Software
27
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37
#endif /* __cplusplus */
39
typedef struct _shvarFile shvarFile;
41
char *fileName; /* read-only */
42
int fd; /* read-only */
43
char *arena; /* ignore */
44
GList *lineList; /* read-only */
45
GList *freeList; /* ignore */
46
GList *current; /* set implicitly or explicitly,
47
points to element of lineList */
48
shvarFile *parent; /* set explicitly */
49
int modified; /* ignore */
53
/* Create the file <name>, return shvarFile on success, NULL on failure */
55
svCreateFile(const char *name);
57
/* Open the file <name>, return shvarFile on success, NULL on failure */
59
svNewFile(const char *name);
61
/* Get the value associated with the key, and leave the current pointer
62
* pointing at the line containing the value. The char* returned MUST
63
* be freed by the caller.
66
svGetValue(shvarFile *s, const char *key);
68
/* return 1 if <key> resolves to any truth value (e.g. "yes", "y", "true")
69
* return 0 if <key> resolves to any non-truth value (e.g. "no", "n", "false")
70
* return <def> otherwise
73
svTrueValue(shvarFile *s, const char *key, int def);
75
/* Set the variable <key> equal to the value <value>.
76
* If <key> does not exist, and the <current> pointer is set, append
77
* the key=value pair after that line. Otherwise, prepend the pair
78
* to the top of the file.
81
svSetValue(shvarFile *s, const char *key, const char *value);
84
/* Write the current contents iff modified. Returns -1 on error
85
* and 0 on success. Do not write if no values have been modified.
86
* The mode argument is only used if creating the file, not if
87
* re-writing an existing file, and is passed unchanged to the
91
svWriteFile(shvarFile *s, int mode);
93
/* Close the file descriptor (if open) and delete the shvarFile.
94
* Returns -1 on error and 0 on success.
97
svCloseFile(shvarFile *s);
101
#endif /* __cplusplus */
103
#endif /* ! _SHVAR_H */