NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
state.c File Reference

Keep track when processing files. More...

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

Go to the source code of this file.

Functions

const char * state_attachment_marker (void)
 Get a unique (per-run) ANSI string to mark PGP messages in an email. More...
 
const char * state_protected_header_marker (void)
 Get a unique (per-run) ANSI string to mark protected headers in an email. More...
 
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 (struct State *s, const char *t)
 Write a string to the state. More...
 
static int state_putwc (struct State *s, wchar_t wc)
 Write a wide character to the state. More...
 
int state_putws (struct State *s, const wchar_t *ws)
 Write a wide string to the state. More...
 
void state_prefix_putc (struct State *s, char c)
 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 (struct State *s, const char *buf, size_t buflen)
 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

◆ state_attachment_marker()

const char* state_attachment_marker ( void  )

Get a unique (per-run) ANSI string to mark PGP messages in an email.

Return values
ptrMarker

Definition at line 43 of file state.c.

44 {
45  static char marker[256] = { 0 };
46  if (!marker[0])
47  {
48  snprintf(marker, sizeof(marker), "\033]9;%" PRIu64 "\a", mutt_rand64());
49  }
50  return marker;
51 }
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_protected_header_marker()

const char* state_protected_header_marker ( void  )

Get a unique (per-run) ANSI string to mark protected headers in an email.

Return values
ptrMarker

Definition at line 57 of file state.c.

58 {
59  static char marker[256] = { 0 };
60  if (!marker[0])
61  {
62  snprintf(marker, sizeof(marker), "\033]8;%lld\a", (long long) mutt_date_epoch());
63  }
64  return marker;
65 }
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:427
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_mark_attach()

void state_mark_attach ( struct State s)

Write a unique marker around content.

Parameters
sState to write to

Definition at line 71 of file state.c.

72 {
73  if (!s || !s->fp_out)
74  return;
75  const char *const c_pager = cs_subset_string(NeoMutt->sub, "pager");
76  if ((s->flags & MUTT_DISPLAY) && (!c_pager || mutt_str_equal(c_pager, "builtin")))
77  {
79  }
80 }
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
const char * state_attachment_marker(void)
Get a unique (per-run) ANSI string to mark PGP messages in an email.
Definition: state.c:43
#define state_puts(STATE, STR)
Definition: state.h:56
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:784
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:50
FILE * fp_out
File to write to.
Definition: state.h:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_mark_protected_header()

void state_mark_protected_header ( struct State s)

Write a unique marker around protected headers.

Parameters
sState to write to

Definition at line 86 of file state.c.

87 {
88  const char *const c_pager = cs_subset_string(NeoMutt->sub, "pager");
89  if ((s->flags & MUTT_DISPLAY) && (!c_pager || mutt_str_equal(c_pager, "builtin")))
90  {
92  }
93 }
const char * state_protected_header_marker(void)
Get a unique (per-run) ANSI string to mark protected headers in an email.
Definition: state.c:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_attach_puts()

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

Write a string to the state.

Parameters
sState to write to
tText to write

Definition at line 100 of file state.c.

101 {
102  if (!s || !s->fp_out || !t)
103  return;
104 
105  if (*t != '\n')
107  while (*t)
108  {
109  state_putc(s, *t);
110  if ((*t++ == '\n') && *t)
111  if (*t != '\n')
113  }
114 }
void state_mark_attach(struct State *s)
Write a unique marker around content.
Definition: state.c:71
#define state_putc(STATE, STR)
Definition: state.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_putwc()

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

Write a wide character to the state.

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

Definition at line 123 of file state.c.

124 {
125  char mb[MB_LEN_MAX] = { 0 };
126  int rc;
127 
128  rc = wcrtomb(mb, wc, NULL);
129  if (rc < 0)
130  return rc;
131  if (fputs(mb, s->fp_out) == EOF)
132  return -1;
133  return 0;
134 }
+ Here is the caller graph for this function:

◆ state_putws()

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

Write a wide string to the state.

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

Definition at line 143 of file state.c.

144 {
145  const wchar_t *p = ws;
146 
147  while (p && (*p != L'\0'))
148  {
149  if (state_putwc(s, *p) < 0)
150  return -1;
151  p++;
152  }
153  return 0;
154 }
static int state_putwc(struct State *s, wchar_t wc)
Write a wide character to the state.
Definition: state.c:123
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ state_prefix_putc()

void state_prefix_putc ( struct State s,
char  c 
)

Write a prefixed character to the state.

Parameters
sState to write to
cCharacter to write

Definition at line 161 of file state.c.

162 {
163  if (s->flags & MUTT_PENDINGPREFIX)
164  {
166  if (s->prefix)
167  state_puts(s, s->prefix);
168  }
169 
170  state_putc(s, c);
171 
172  if (c == '\n')
173  state_set_prefix(s);
174 }
#define state_set_prefix(state)
Definition: state.h:54
#define MUTT_PENDINGPREFIX
Prefix to write, but character must follow.
Definition: state.h:34
#define state_reset_prefix(state)
Definition: state.h:55
char * prefix
String to add to the beginning of each output line.
Definition: state.h:49
+ Here is the caller graph for this function:

◆ state_printf()

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 183 of file state.c.

184 {
185  int rc;
186  va_list ap;
187 
188  va_start(ap, fmt);
189  rc = vfprintf(s->fp_out, fmt, ap);
190  va_end(ap);
191 
192  return rc;
193 }
+ Here is the caller graph for this function:

◆ state_prefix_put()

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

Write a prefixed fixed-string to the State.

Parameters
sState to write to
bufString to write
buflenLength of string

Definition at line 201 of file state.c.

202 {
203  if (s->prefix)
204  {
205  while (buflen--)
206  state_prefix_putc(s, *buf++);
207  }
208  else
209  fwrite(buf, buflen, 1, s->fp_out);
210 }
void state_prefix_putc(struct State *s, char c)
Write a prefixed character to the state.
Definition: state.c:161
+ Here is the call graph for this function:
+ Here is the caller graph for this function: