NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 "state.h"
#include "date.h"
#include "random.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.
 
const char * state_protected_header_marker (void)
 Get a unique (per-run) ANSI string to mark protected headers in an email.
 
void state_mark_attach (struct State *state)
 Write a unique marker around content.
 
void state_mark_protected_header (struct State *state)
 Write a unique marker around protected headers.
 
void state_attach_puts (struct State *state, const char *t)
 Write a string to the state.
 
static int state_putwc (struct State *state, wchar_t wc)
 Write a wide character to the state.
 
int state_putws (struct State *state, const wchar_t *ws)
 Write a wide string to the state.
 
void state_prefix_putc (struct State *state, char c)
 Write a prefixed character to the state.
 
int state_printf (struct State *state, const char *fmt,...)
 Write a formatted string to the State.
 
void state_prefix_put (struct State *state, const char *buf, size_t buflen)
 Write a prefixed fixed-string to the State.
 

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:134
+ 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_now());
63 }
64 return marker;
65}
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:446
+ 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 state)

Write a unique marker around content.

Parameters
stateState to write to

Definition at line 71 of file state.c.

72{
73 if (!state || !state->fp_out)
74 return;
75
77 {
79 }
80}
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_PAGER
Output will be displayed in the Pager.
Definition: state.h:41
#define state_puts(STATE, STR)
Definition: state.h:57
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:32
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:51
FILE * fp_out
File to write to.
Definition: state.h:49
+ 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 state)

Write a unique marker around protected headers.

Parameters
stateState to write to

Definition at line 86 of file state.c.

87{
88 if (!state || !state->fp_out)
89 return;
90
92 {
94 }
95}
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 state,
const char *  t 
)

Write a string to the state.

Parameters
stateState to write to
tText to write

Definition at line 102 of file state.c.

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

◆ state_putwc()

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

Write a wide character to the state.

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

Definition at line 125 of file state.c.

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

◆ state_putws()

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

Write a wide string to the state.

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

Definition at line 145 of file state.c.

146{
147 const wchar_t *p = ws;
148
149 while (p && (*p != L'\0'))
150 {
151 if (state_putwc(state, *p) < 0)
152 return -1;
153 p++;
154 }
155 return 0;
156}
static int state_putwc(struct State *state, wchar_t wc)
Write a wide character to the state.
Definition: state.c:125
+ 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 state,
char  c 
)

Write a prefixed character to the state.

Parameters
stateState to write to
cCharacter to write

Definition at line 163 of file state.c.

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

◆ state_printf()

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

Write a formatted string to the State.

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

Definition at line 185 of file state.c.

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

◆ state_prefix_put()

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

Write a prefixed fixed-string to the State.

Parameters
stateState to write to
bufString to write
buflenLength of string

Definition at line 203 of file state.c.

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