11 static char inbuf
[64];
12 static stralloc line
= {0};
13 static stralloc me
= {0};
16 static void striptrailingwhitespace(sa
)
20 switch(sa
->s
[sa
->len
- 1])
22 case '\n': case ' ': case '\t':
33 r
= control_readline(&me
,"control/me");
38 int control_rldef(sa
,fn
,flagme
,def
)
45 r
= control_readline(sa
,fn
);
47 if (flagme
) if (meok
) return stralloc_copy(sa
,&me
) ?
1 : -1;
48 if (def
) return stralloc_copys(sa
,def
) ?
1 : -1;
52 int control_readline(sa
,fn
)
61 if (fd
== -1) { if (errno
== error_noent
) return 0; return -1; }
63 substdio_fdbuf(&ss
,read
,fd
,inbuf
,sizeof(inbuf
));
65 if (getln(&ss
,sa
,&match
,'\n') == -1) { close(fd
); return -1; }
67 striptrailingwhitespace(sa
);
72 int control_readint(i
,fn
)
77 switch(control_readline(&line
,fn
))
82 if (scan_nbblong(line
.s
,line
.len
,10,0,&u
) == 0) return 0;
87 int control_readfile(sa
,fn
,flagme
)
96 if (!stralloc_copys(sa
,"")) return -1;
101 if (errno
== error_noent
)
105 if (!stralloc_copy(sa
,&me
)) return -1;
106 if (!stralloc_0(sa
)) return -1;
114 substdio_fdbuf(&ss
,read
,fd
,inbuf
,sizeof(inbuf
));
118 if (getln(&ss
,&line
,&match
,'\n') == -1) break;
119 if (!match
&& !line
.len
) { close(fd
); return 1; }
120 striptrailingwhitespace(&line
);
121 if (!stralloc_0(&line
)) break;
123 if (line
.s
[0] != '#')
124 if (!stralloc_cat(sa
,&line
)) break;
125 if (!match
) { close(fd
); return 1; }