NeoMutt  2018-07-16 +2388-bcedc8
Teaching an old dog new tricks
DOXYGEN
state.c File Reference

Keep track when processing files. More...

#include "config.h"
#include <limits.h>
#include <stdarg.h>
#include <wchar.h>
#include "mutt/mutt.h"
#include "state.h"
#include "globals.h"
+ Include dependency graph for state.c:

Go to the source code of this file.

Functions

void state_mark_attach (struct State *s)
 Write a unique marker around content. More...
 
void state_mark_protected_header (struct State *s)
 Write a unique marker around protected headers. More...
 
void state_attach_puts (const char *t, struct State *s)
 Write a string to the state. More...
 
static int state_putwc (wchar_t wc, struct State *s)
 Write a wide character to the state. More...
 
int state_putws (const wchar_t *ws, struct State *s)
 Write a wide string to the state. More...
 
void state_prefix_putc (char c, struct State *s)
 Write a prefixed character to the state. More...
 
int state_printf (struct State *s, const char *fmt,...)
 Write a formatted string to the State. More...
 
void state_prefix_put (const char *buf, size_t buflen, struct State *s)
 Write a prefixed fixed-string to the State. More...
 

Detailed Description

Keep track when processing files.

Authors
  • Richard Russon

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/.

Definition in file state.c.

Function Documentation

void state_mark_attach ( struct State s)

Write a unique marker around content.

Parameters
sState to write to

Definition at line 41 of file state.c.

42 {
43  if (!s || !s->fp_out)
44  return;
45  if ((s->flags & MUTT_DISPLAY) && (mutt_str_strcmp(C_Pager, "builtin") == 0))
47 }
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
WHERE char AttachmentMarker[256]
Unique ANSI string to mark PGP messages in an email.
Definition: globals.h:45
FILE * fp_out
File to write to.
Definition: state.h:47
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
#define state_puts(str, state)
Definition: state.h:54
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:139
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void state_mark_protected_header ( struct State s)

Write a unique marker around protected headers.

Parameters
sState to write to

Definition at line 53 of file state.c.

54 {
55  if ((s->flags & MUTT_DISPLAY) && (mutt_str_strcmp(C_Pager, "builtin") == 0))
57 }
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
WHERE char ProtectedHeaderMarker[256]
Unique ANSI string to mark protected headers in an email.
Definition: globals.h:46
#define state_puts(str, state)
Definition: state.h:54
WHERE char * C_Pager
Config: External command for viewing messages, or &#39;builtin&#39; to use NeoMutt&#39;s.
Definition: globals.h:139
int mutt_str_strcmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:615

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void state_attach_puts ( const char *  t,
struct State s 
)

Write a string to the state.

Parameters
tText to write
sState to write to

Definition at line 64 of file state.c.

65 {
66  if (!t || !s || !s->fp_out)
67  return;
68 
69  if (*t != '\n')
71  while (*t)
72  {
73  state_putc(*t, s);
74  if ((*t++ == '\n') && *t)
75  if (*t != '\n')
77  }
78 }
FILE * fp_out
File to write to.
Definition: state.h:47
void state_mark_attach(struct State *s)
Write a unique marker around content.
Definition: state.c:41
#define state_putc(str, state)
Definition: state.h:55

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int state_putwc ( wchar_t  wc,
struct State s 
)
static

Write a wide character to the state.

Parameters
wcWide character to write
sState to write to
Return values
0Success
-1Error

Definition at line 87 of file state.c.

88 {
89  char mb[MB_LEN_MAX] = { 0 };
90  int rc;
91 
92  rc = wcrtomb(mb, wc, NULL);
93  if (rc < 0)
94  return rc;
95  if (fputs(mb, s->fp_out) == EOF)
96  return -1;
97  return 0;
98 }
FILE * fp_out
File to write to.
Definition: state.h:47

+ Here is the caller graph for this function:

int state_putws ( const wchar_t *  ws,
struct State s 
)

Write a wide string to the state.

Parameters
wsWide string to write
sState to write to
Return values
0Success
-1Error

Definition at line 107 of file state.c.

108 {
109  const wchar_t *p = ws;
110 
111  while (p && (*p != L'\0'))
112  {
113  if (state_putwc(*p, s) < 0)
114  return -1;
115  p++;
116  }
117  return 0;
118 }
static int state_putwc(wchar_t wc, struct State *s)
Write a wide character to the state.
Definition: state.c:87

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void state_prefix_putc ( char  c,
struct State s 
)

Write a prefixed character to the state.

Parameters
cCharacter to write
sState to write to

Definition at line 125 of file state.c.

126 {
127  if (s->flags & MUTT_PENDINGPREFIX)
128  {
130  if (s->prefix)
131  state_puts(s->prefix, s);
132  }
133 
134  state_putc(c, s);
135 
136  if (c == '\n')
137  state_set_prefix(s);
138 }
#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:53
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
#define state_set_prefix(state)
Definition: state.h:52
#define state_puts(str, state)
Definition: state.h:54
#define state_putc(str, state)
Definition: state.h:55

+ Here is the caller graph for this function:

int state_printf ( struct State s,
const char *  fmt,
  ... 
)

Write a formatted string to the State.

Parameters
sState to write to
fmtprintf format string
...Arguments to formatting string
Return values
numNumber of characters written

Definition at line 147 of file state.c.

148 {
149  int rc;
150  va_list ap;
151 
152  va_start(ap, fmt);
153  rc = vfprintf(s->fp_out, fmt, ap);
154  va_end(ap);
155 
156  return rc;
157 }
FILE * fp_out
File to write to.
Definition: state.h:47

+ Here is the caller graph for this function:

void state_prefix_put ( const char *  buf,
size_t  buflen,
struct State s 
)

Write a prefixed fixed-string to the State.

Parameters
bufString to write
buflenLength of string
sState to write to

Definition at line 165 of file state.c.

166 {
167  if (s->prefix)
168  {
169  while (buflen--)
170  state_prefix_putc(*buf++, s);
171  }
172  else
173  fwrite(buf, buflen, 1, s->fp_out);
174 }
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
FILE * fp_out
File to write to.
Definition: state.h:47
void state_prefix_putc(char c, struct State *s)
Write a prefixed character to the state.
Definition: state.c:125

+ Here is the call graph for this function:

+ Here is the caller graph for this function: