leafnode  1.12.0
About: Leafnode is a store & forward NNTP proxy for small (dialup) sites.
  Fossies Dox: leafnode-1.12.0.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

getfoldedline.c
Go to the documentation of this file.
1/* (C) 2002 - 2005 Matthias Andree. See COPYING for license conditions */
2
3#include "leafnode.h"
4#include "critmem.h"
5
6#ifdef WITH_DMALLOC
7#include <dmalloc.h>
8#endif
9
10#include <string.h>
11
12/*@null@*/ /*@only@*/ char *
13getfoldedline(FILE * f, char *(*reader)(FILE *))
14{
15 /* what characters are considered whitespace that marks the beginning of
16 continuation lines.
17 WARNING: NEVER EVER list \n here! */
18 static const char white[] = " \t";
19 char *l1, *l2;
20 int c;
21 size_t len, oldlen;
22
23 l1 = reader(f);
24 if (!l1)
25 return NULL;
26 l2 = (char *)critmalloc((len = strlen(l1)) + 1, "getfoldedline");
27 strcpy(l2, l1); /* RATS: ignore */
28
29 /* only try to read continuation if the line is not empty
30 * and not a lone dot */
31 if (*l2 && strcmp(l2, ".")) {
32 for (;;) {
33 c = fgetc(f);
34 if (c != EOF) {
35 ungetc(c, f);
36 if (strchr(white, c)) {
37 /* join */
38 l1 = reader(f);
39 if (l1) {
40 oldlen = len;
41 len += strlen(l1) + 1;
42 l2 = (char *)critrealloc(l2, len + 2,
43 "getfoldedline");
44 l2[oldlen++] = '\n';
45 strcpy(l2 + oldlen, l1); /* RATS: ignore */
46 }
47 } else {
48 break;
49 }
50 } else {
51 break;
52 }
53 }
54 }
55 return l2;
56}
57
58#ifdef TEST
59int debug = 0;
60
61int
62main()
63{
64 char *f;
65 while ((f = getfoldedline(stdin, getaline))) {
66 puts(f);
67 free(f);
68 }
69 return 0;
70}
71#endif
int main(void)
Definition: amiroot.c:12
int debug
Definition: applyfilter.c:30
char * critrealloc(char *a, size_t size, const char *message)
Definition: critmem.c:79
char * critmalloc(size_t size, const char *message)
Definition: critmem.c:61
char * getaline(FILE *f)
Definition: getaline.c:84
char * getfoldedline(FILE *f, char *(*reader)(FILE *))
Definition: getfoldedline.c:13
#define len
Definition: mastring.c:31