| 1 | /*$Id: */ |
| 2 | /*$Name: ezmlm-idx-040 $*/ |
| 3 | |
| 4 | #include "stralloc.h" |
| 5 | #include "strerr.h" |
| 6 | #include "case.h" |
| 7 | #include "byte.h" |
| 8 | #include "mime.h" |
| 9 | #include "errtxt.h" |
| 10 | |
| 11 | void concatHDR(indata,n,outdata,fatal) |
| 12 | char *indata; |
| 13 | unsigned int n; |
| 14 | stralloc *outdata; |
| 15 | char *fatal; |
| 16 | /* takes a concatenated string of line and continuation line, trims leading */ |
| 17 | /* and trailing LWSP and collapses line breaks and surrounding LWSP to ' '. */ |
| 18 | /* indata has to end in \n or \0 or this routine will write beyond indata! */ |
| 19 | /* if indata ends with \0, this will be changed to \n. */ |
| 20 | |
| 21 | { |
| 22 | register char *cp,*cpout; |
| 23 | char *cplast; |
| 24 | if (!stralloc_copys(outdata,"")) die_nomem(fatal); |
| 25 | if (!stralloc_ready(outdata,n)) die_nomem(fatal); |
| 26 | cpout = outdata->s; |
| 27 | if (n == 0) return; |
| 28 | cplast = indata + n - 1; |
| 29 | cp = cplast; |
| 30 | while (*cplast == '\0' || *cplast == '\n') --cplast; |
| 31 | if (cp == cplast) die_nomem(fatal); /* just in case */ |
| 32 | *(++cplast) = '\n'; /* have terminal '\n' */ |
| 33 | cp = indata; |
| 34 | while (cp <= cplast) { |
| 35 | while (*cp == ' ' || *cp == '\t') ++cp; /* LWSP before */ |
| 36 | while (*cp != '\n') *(cpout++) = *(cp++); /* text */ |
| 37 | ++cp; /* skip \n */ |
| 38 | --cpout; /* last char */ |
| 39 | while (*cpout == ' ' || *cpout == '\t') --cpout; /* LWSP after */ |
| 40 | *(++cpout) = ' '; /* replace with single ' ' */ |
| 41 | ++cpout; /* point to free byte */ |
| 42 | } |
| 43 | outdata->len = cpout - outdata->s; |
| 44 | } |
| 45 | |