mess822x 1.23
mess822x
Loading...
Searching...
No Matches
mess822_fold.c
Go to the documentation of this file.
1#include "mess822.h"
2
3int mess822_fold(stralloc *out,stralloc *in,char *prefix,int linelen)
4{
5 int i;
6 int j;
7 int k;
8 int partial;
9
10 if (!stralloc_copys(out,prefix)) return 0;
11 partial = out->len;
12
13 for (j = i = 0; j <= in->len; ++j)
14 if ((j == in->len) || (in->s[j] == '\n')) {
15 k = i;
16 while ((in->s[k] == ' ') && (in->s[k + 1] == ' ')) ++k;
17 if (i && (partial + j - k > linelen)) {
18 if (!stralloc_cats(out,"\n")) return 0;
19 if (!stralloc_catb(out,in->s + i,j - i)) return 0;
20 partial = j - i;
21 }
22 else {
23 if (!stralloc_catb(out,in->s + k,j - k)) return 0;
24 partial += j - k;
25 }
26 i = j + 1;
27 }
28
29 if (!stralloc_append(out,"\n")) return 0;
30
31 return 1;
32}
stralloc out
Definition: b64decode.c:12
int mess822_fold(stralloc *out, stralloc *in, char *prefix, int linelen)
Definition: mess822_fold.c:3