|
0
|
1 |
#include "stralloc.h"
|
|
|
2 |
#include "readwrite.h"
|
|
|
3 |
#include "substdio.h"
|
|
|
4 |
#include "qsutil.h"
|
|
|
5 |
|
|
|
6 |
static stralloc foo = {0};
|
|
|
7 |
|
|
|
8 |
static char errbuf[1];
|
|
|
9 |
static struct substdio sserr = SUBSTDIO_FDBUF(write,0,errbuf,1);
|
|
|
10 |
|
|
|
11 |
void logsa(sa) stralloc *sa; {
|
|
|
12 |
substdio_putflush(&sserr,sa->s,sa->len); }
|
|
|
13 |
void log1(s1) char *s1; {
|
|
|
14 |
substdio_putsflush(&sserr,s1); }
|
|
|
15 |
void log2(s1,s2) char *s1; char *s2; {
|
|
|
16 |
substdio_putsflush(&sserr,s1);
|
|
|
17 |
substdio_putsflush(&sserr,s2); }
|
|
|
18 |
void log3(s1,s2,s3) char *s1; char *s2; char *s3; {
|
|
|
19 |
substdio_putsflush(&sserr,s1);
|
|
|
20 |
substdio_putsflush(&sserr,s2);
|
|
|
21 |
substdio_putsflush(&sserr,s3); }
|
|
|
22 |
void nomem() { log1("alert: out of memory, sleeping...\n"); sleep(10); }
|
|
|
23 |
|
|
|
24 |
void pausedir(dir) char *dir;
|
|
|
25 |
{ log3("alert: unable to opendir ",dir,", sleeping...\n"); sleep(10); }
|
|
|
26 |
|
|
|
27 |
static int issafe(ch) char ch;
|
|
|
28 |
{
|
|
|
29 |
if (ch == '%') return 0; /* general principle: allman's code is crap */
|
|
|
30 |
if (ch < 33) return 0;
|
|
|
31 |
if (ch > 126) return 0;
|
|
|
32 |
return 1;
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
void logsafe(s) char *s;
|
|
|
36 |
{
|
|
|
37 |
int i;
|
|
|
38 |
while (!stralloc_copys(&foo,s)) nomem();
|
|
|
39 |
for (i = 0;i < foo.len;++i)
|
|
|
40 |
if (foo.s[i] == '\n')
|
|
|
41 |
foo.s[i] = '/';
|
|
|
42 |
else
|
|
|
43 |
if (!issafe(foo.s[i]))
|
|
|
44 |
foo.s[i] = '_';
|
|
|
45 |
logsa(&foo);
|
|
|
46 |
}
|