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