forked from neomutt/neomutt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate.c
114 lines (98 loc) · 2.31 KB
/
state.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* @file
* Keep track when processing files
*
* @authors
* Copyright (C) 2017 Richard Russon <[email protected]>
*
* @copyright
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <limits.h>
#include <stdarg.h>
#include "state.h"
#include "globals.h"
#include "mbyte.h"
void state_mark_attach(struct State *s)
{
if (!s || !s->fpout)
return;
if ((s->flags & MUTT_DISPLAY) && (mutt_strcmp(Pager, "builtin") == 0))
state_puts(AttachmentMarker, s);
}
void state_attach_puts(const char *t, struct State *s)
{
if (!t || !s || !s->fpout)
return;
if (*t != '\n')
state_mark_attach(s);
while (*t)
{
state_putc(*t, s);
if (*t++ == '\n' && *t)
if (*t != '\n')
state_mark_attach(s);
}
}
static int state_putwc(wchar_t wc, struct State *s)
{
char mb[MB_LEN_MAX] = "";
int rc;
if ((rc = wcrtomb(mb, wc, NULL)) < 0)
return rc;
if (fputs(mb, s->fpout) == EOF)
return -1;
return 0;
}
int state_putws(const wchar_t *ws, struct State *s)
{
const wchar_t *p = ws;
while (p && *p != L'\0')
{
if (state_putwc(*p, s) < 0)
return -1;
p++;
}
return 0;
}
void state_prefix_putc(char c, struct State *s)
{
if (s->flags & MUTT_PENDINGPREFIX)
{
state_reset_prefix(s);
if (s->prefix)
state_puts(s->prefix, s);
}
state_putc(c, s);
if (c == '\n')
state_set_prefix(s);
}
int state_printf(struct State *s, const char *fmt, ...)
{
int rv;
va_list ap;
va_start(ap, fmt);
rv = vfprintf(s->fpout, fmt, ap);
va_end(ap);
return rv;
}
void state_prefix_put(const char *d, size_t dlen, struct State *s)
{
if (s->prefix)
while (dlen--)
state_prefix_putc(*d++, s);
else
fwrite(d, dlen, 1, s->fpout);
}