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 (!stralloc_0(&line
)) return -1;
83 if (!scan_ulong(line
.s
,&u
)) return 0;
88 int control_readfile(sa
,fn
,flagme
)
97 if (!stralloc_copys(sa
,"")) return -1;
102 if (errno
== error_noent
)
106 if (!stralloc_copy(sa
,&me
)) return -1;
107 if (!stralloc_0(sa
)) return -1;
115 substdio_fdbuf(&ss
,read
,fd
,inbuf
,sizeof(inbuf
));
119 if (getln(&ss
,&line
,&match
,'\n') == -1) break;
120 if (!match
&& !line
.len
) { close(fd
); return 1; }
121 striptrailingwhitespace(&line
);
122 if (!stralloc_0(&line
)) break;
124 if (line
.s
[0] != '#')
125 if (!stralloc_cat(sa
,&line
)) break;
126 if (!match
) { close(fd
); return 1; }