NeoMutt  2024-04-25-97-g7d2481
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
  • Pietro Cerutti

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

45{
46 static char marker[256] = { 0 };
47 if (!marker[0])
48 {
49 snprintf(marker, sizeof(marker), "\033]9;%" PRIu64 "\a", mutt_rand64());
50 }
51 return marker;
52}
uint64_t mutt_rand64(void)
Create a 64-bit random number.
Definition: random.c:123
+ 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 58 of file state.c.

59{
60 static char marker[256] = { 0 };
61 if (!marker[0])
62 {
63 snprintf(marker, sizeof(marker), "\033]8;%lld\a", (long long) mutt_date_now());
64 }
65 return marker;
66}
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
+ 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 72 of file state.c.

73{
74 if (!state || !state->fp_out)
75 return;
76
78 {
80 }
81}
const char * state_attachment_marker(void)
Get a unique (per-run) ANSI string to mark PGP messages in an email.
Definition: state.c:44
#define STATE_PAGER
Output will be displayed in the Pager.
Definition: state.h:42
#define state_puts(STATE, STR)
Definition: state.h:58
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:33
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition: state.h:52
FILE * fp_out
File to write to.
Definition: state.h:50
+ 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 87 of file state.c.

88{
89 if (!state || !state->fp_out)
90 return;
91
93 {
95 }
96}
const char * state_protected_header_marker(void)
Get a unique (per-run) ANSI string to mark protected headers in an email.
Definition: state.c:58
+ 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 103 of file state.c.

104{
105 if (!state || !state->fp_out || !t)
106 return;
107
108 if (*t != '\n')
109 state_mark_attach(state);
110 while (*t)
111 {
112 state_putc(state, *t);
113 if ((*t++ == '\n') && *t)
114 if (*t != '\n')
115 state_mark_attach(state);
116 }
117}
void state_mark_attach(struct State *state)
Write a unique marker around content.
Definition: state.c:72
#define state_putc(STATE, STR)
Definition: state.h:59
+ 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 126 of file state.c.

127{
128 char mb[MB_LEN_MAX] = { 0 };
129 int rc;
130
131 rc = wcrtomb(mb, wc, NULL);
132 if (rc < 0)
133 return rc;
134 if (fputs(mb, state->fp_out) == EOF)
135 return -1;
136 return 0;
137}
+ 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 146 of file state.c.

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

165{
166 if (state->flags & STATE_PENDINGPREFIX)
167 {
168 state_reset_prefix(state);
169 if (state->prefix)
170 state_puts(state, state->prefix);
171 }
172
173 state_putc(state, c);
174
175 if (c == '\n')
176 state_set_prefix(state);
177}
#define state_set_prefix(state)
Definition: state.h:56
#define STATE_PENDINGPREFIX
Prefix to write, but character must follow.
Definition: state.h:35
#define state_reset_prefix(state)
Definition: state.h:57
const char * prefix
String to add to the beginning of each output line.
Definition: state.h:51
+ 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 186 of file state.c.

187{
188 int rc;
189 va_list ap;
190
191 va_start(ap, fmt);
192 rc = vfprintf(state->fp_out, fmt, ap);
193 va_end(ap);
194
195 return rc;
196}
+ 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 204 of file state.c.

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