NeoMutt  2019-11-11
Teaching an old dog new tricks
DOXYGEN
state.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <limits.h>
31 #include <stdarg.h>
32 #include <wchar.h>
33 #include "mutt/mutt.h"
34 #include "state.h"
35 #include "globals.h"
36 
41 void state_mark_attach(struct State *s)
42 {
43  if (!s || !s->fp_out)
44  return;
45  if ((s->flags & MUTT_DISPLAY) &&
46  (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0)))
47  {
49  }
50 }
51 
57 {
58  if ((s->flags & MUTT_DISPLAY) &&
59  (!C_Pager || (mutt_str_strcmp(C_Pager, "builtin") == 0)))
60  {
62  }
63 }
64 
70 void state_attach_puts(struct State *s, const char *t)
71 {
72  if (!s || !s->fp_out || !t)
73  return;
74 
75  if (*t != '\n')
77  while (*t)
78  {
79  state_putc(s, *t);
80  if ((*t++ == '\n') && *t)
81  if (*t != '\n')
83  }
84 }
85 
93 static int state_putwc(struct State *s, wchar_t wc)
94 {
95  char mb[MB_LEN_MAX] = { 0 };
96  int rc;
97 
98  rc = wcrtomb(mb, wc, NULL);
99  if (rc < 0)
100  return rc;
101  if (fputs(mb, s->fp_out) == EOF)
102  return -1;
103  return 0;
104 }
105 
113 int state_putws(struct State *s, const wchar_t *ws)
114 {
115  const wchar_t *p = ws;
116 
117  while (p && (*p != L'\0'))
118  {
119  if (state_putwc(s, *p) < 0)
120  return -1;
121  p++;
122  }
123  return 0;
124 }
125 
131 void state_prefix_putc(struct State *s, char c)
132 {
133  if (s->flags & MUTT_PENDINGPREFIX)
134  {
136  if (s->prefix)
137  state_puts(s, s->prefix);
138  }
139 
140  state_putc(s, c);
141 
142  if (c == '\n')
143  state_set_prefix(s);
144 }
145 
153 int state_printf(struct State *s, const char *fmt, ...)
154 {
155  int rc;
156  va_list ap;
157 
158  va_start(ap, fmt);
159  rc = vfprintf(s->fp_out, fmt, ap);
160  va_end(ap);
161 
162  return rc;
163 }
164 
171 void state_prefix_put(struct State *s, const char *buf, size_t buflen)
172 {
173  if (s->prefix)
174  {
175  while (buflen--)
176  state_prefix_putc(s, *buf++);
177  }
178  else
179  fwrite(buf, buflen, 1, s->fp_out);
180 }
int state_printf(struct State *s, const char *fmt,...)
Write a formatted string to the State.
Definition: state.c:153
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define state_puts(STATE, STR)
Definition: state.h:55
WHERE char AttachmentMarker[256]
Unique ANSI string to mark PGP messages in an email.
Definition: globals.h:48
#define MUTT_PENDINGPREFIX
Prefix to write, but character must follow.
Definition: state.h:34
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
#define state_reset_prefix(state)
Definition: state.h:54
FILE * fp_out
File to write to.
Definition: state.h:47
Hundreds of global variables to back the user variables.
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
int state_putws(struct State *s, const wchar_t *ws)
Write a wide string to the state.
Definition: state.c:113
void state_mark_protected_header(struct State *s)
Write a unique marker around protected headers.
Definition: state.c:56
void state_mark_attach(struct State *s)
Write a unique marker around content.
Definition: state.c:41
WHERE char ProtectedHeaderMarker[256]
Unique ANSI string to mark protected headers in an email.
Definition: globals.h:49
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
Definition: state.c:70
Keep track when processing files.
#define state_set_prefix(state)
Definition: state.h:53
void state_prefix_put(struct State *s, const char *buf, size_t buflen)
Write a prefixed fixed-string to the State.
Definition: state.c:171
void state_prefix_putc(struct State *s, char c)
Write a prefixed character to the state.
Definition: state.c:131
Keep track when processing files.
Definition: state.h:44
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:134
#define state_putc(STATE, STR)
Definition: state.h:56
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615
static int state_putwc(struct State *s, wchar_t wc)
Write a wide character to the state.
Definition: state.c:93