2 * Copyright (C) 1994, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1994-08-18 08:23:26 adam
8 * Res.c now use handles. xmalloc defines xstrdup.
10 * Revision 1.1 1994/08/17 15:34:23 adam
11 * Initial version of resource manager.
18 const char *alex_path (const char *name)
20 static char path[256];
23 if (!(alex_prefix = getenv ("ALEXPREFIX")))
26 if (*alex_prefix && alex_prefix[strlen(alex_prefix)-1] == '/')
27 sprintf (path, "%s%s", alex_prefix, name);
29 sprintf (path, "%s/%s", alex_prefix, name);
33 static void reread (Res r)
35 struct res_entry *resp;
38 int val_size, val_max = 1024;
45 val_buf = xmalloc (val_max);
47 strcpy (path, alex_path(r->name));
49 fr = fopen (path, "r");
52 log (LOG_FATAL, "cannot open %s", path);
57 line = fgets (fr_buf, 1023, fr);
64 while (fr_buf[no] && fr_buf[no] != '\n')
69 resp = r->last = r->first = xmalloc (sizeof(*resp));
72 resp = xmalloc (sizeof(*resp));
77 resp->name = xmalloc (no+1);
79 strcpy (resp->name, fr_buf);
86 if (fr_buf[no] == 0 || fr_buf[no] == '\n' )
91 if (fr_buf[no] == ':')
99 resp = r->last = r->first = xmalloc (sizeof(*resp));
102 resp = xmalloc (sizeof(*resp));
103 r->last->next = resp;
107 resp->name = xmalloc (no);
108 strcpy (resp->name, fr_buf);
110 while (fr_buf[no] == ' ')
115 if (fr_buf[no] == '\0' || fr_buf[no] == '\n')
117 val_buf[val_size++] = '\0';
118 resp->value = xmalloc (val_size);
119 strcpy (resp->value, val_buf);
122 else if (fr_buf[no] == '\\' && fr_buf[no+1] == '\n')
124 line = fgets (fr_buf, 1023, fr);
127 resp->value = xmalloc (val_size);
128 strcpy (resp->value, val_buf);
134 val_buf[val_size] = fr_buf[no++];
142 Res res_open (const char *name)
144 Res r = xmalloc (sizeof(*r));
146 r->name = xstrdup (name);
150 void res_close (Res r)
152 /* more to xfree... */
156 const char *res_get (Res r, const char *name)
163 const char *res_put (Res r, const char *name, const char *value)
170 int res_write (Res r)