ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
getconf.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "byte.h"
3#include "logmsg.h"
4#include "getconf.h"
5#include "idx.h"
6#include "errtxt.h"
7#include "readclose.h"
8
9#define WHO "getconf"
10
16
17void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
18
19static stralloc data = {0};
20
21int getconf(stralloc *sa,const char *fn,int flagrequired,const char *dir)
22{
23 int i;
24 int j;
25 int k;
26
27 if (!stralloc_copys(&data,"")) die_nomem();
28
29 switch (openreadclose(fn,&data,128)) {
30 case -1: logmsg(WHO,111,FATAL,B("unable to read :",dir,"/",fn));
31 case 0: if (!flagrequired) return 0;
32 logmsg(WHO,100,FATAL,B(dir,"/",fn," does not exist"));
33 }
34
35 if (!stralloc_append(&data,"\n")) die_nomem();
36 if (!stralloc_copys(sa,"")) die_nomem();
37
38 i = 0;
39 for (j = 0; j < data.len; ++j)
40 if (data.s[j] == '\n') {
41 k = j;
42 while ((k > i) && ((data.s[k-1] == ' ') || (data.s[k-1] == '\t')))
43 --k;
44 if ((k > i) && (data.s[i] != '#')) {
45 if (!stralloc_catb(sa,data.s + i,k - i)) die_nomem();
46 if (!stralloc_0(sa)) die_nomem();
47 }
48 i = j + 1;
49 }
50 return 1;
51}
52
53int getconf_line(stralloc *sa,const char *fn,int flagrequired,const char *dir)
54{
55 if (!getconf(sa,fn,flagrequired,dir)) return 0;
56 sa->len = byte_chr(sa->s,sa->len,0);
57 return 1;
58}
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
void die_nomem()
Definition getconf.c:17
int getconf(stralloc *sa, const char *fn, int flagrequired, const char *dir)
Definition getconf.c:21
int getconf_line(stralloc *sa, const char *fn, int flagrequired, const char *dir)
Definition getconf.c:53
#define WHO
Definition author.c:1
stralloc fn
char * dir
#define data
Definition makehash.c:45
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32