2 * gw-res.h: Resource management.
4 * Europagate, 1994-1995.
7 * Revision 1.5 1995/05/03 07:36:29 adam
8 * New functions: gw_res_bool and gw_res_int.
10 * Revision 1.4 1995/04/19 12:12:02 adam
11 * Resource system uses only one log debug level.
13 * Revision 1.3 1995/02/23 08:32:12 adam
16 * Revision 1.1.1.1 1995/02/09 17:27:12 adam
17 * Initial version of email gateway under CVS control.
19 * Initial: Dec 7, 94 (Adam Dickmeiss)
24 #define RES_DEBUG GW_LOG_DEBUGN(8)
26 typedef struct Gw_res_info *GwRes; /* Gateway resource handle */
28 GwRes gw_res_init (void);
30 A resource handle is returned by this function describing
34 void gw_res_close (GwRes id);
36 The resources described by 'id' are freed. No further references
40 int gw_res_merge (GwRes id, const char *filename);
42 The resources described by 'id' are merged by the contents of
43 'filename'. If a resource is duplicated (in both resources 'id' and
44 the file) the resource is set to the value specified in 'filename'.
46 This function returns 0 on success; -1 on failure ('filename'
50 const char *gw_res_get (GwRes id, const char *name, const char *def);
52 The resource with name 'name' is checked in the resources represented
53 by 'id'. If the resource is present a pointer to the value (null-
54 terminated string) is returned. If the value is not present the
55 value of 'def' is returned.
58 int gw_res_put (GwRes id, const char *name, const char *value,
61 Change a resource - modify if it exists - add if not already
62 there. The resource will have impact on the file name 'fname'.
63 Use gw_res_commit (see below) to actually write to the
67 int gw_res_commit (GwRes id, const char *fname);
69 Rewrite the resource file 'fname'. If resources are modified/added
70 then these will be written now.
74 int gw_res_trav (GwRes id, const char *fname, void (*tf)(const char *name,
77 Traverse resources associated with file 'fname'. For each resource
78 the handler 'tf' is invoked with name and value.
81 int gw_res_bool (GwRes res, const char *name, int def_val);
83 Return true(1) or false(0) depending on setting for name. If
84 name doesn't exist, def_val is returned
87 int gw_res_int (GwRes res, const char *name, int def_val);
89 Treat value of name as integer. Issue warning (GW_LOG_WARN) if the value
90 cannot be read as integer. If name doesn't exist, def_val is returned
95 A resource name must begin on column 0 on a line. The name is followed
96 by colon. The value of the resource comes after the colon. A value may
97 span over several lines. Subsequent value lines are preceeded by one or
98 more blanks (tab/space). Empty/blank lines are ignored. Lines beginning
99 with # are treated as comments.
104 # Single line resource
106 # Multi line resource
107 FatalMsg: A serious error
109 # Yet another (danish):
110 Warning: Advarsel, taenk
111 dig om - inden du foretager dig noget.
113 The FatalMsg resource has the value "A serious error occured. Aborting.",
114 and the Warning resource has the value
115 "Advarsel, taenk dig om - inden du foretager dig noget." Note
116 that all blanks used to separate subsequent lines are treated as exactly