NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
state.h File Reference

Keep track when processing files. More...

#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for state.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  State
 Keep track when processing files. More...
 

Macros

#define state_set_prefix(state)
 
#define state_reset_prefix(state)
 
#define state_puts(STATE, STR)
 
#define state_putc(STATE, STR)
 

Typedefs

typedef uint16_t StateFlags
 

Enumerations

enum  StateFlag {
  STATE_NONE = 0 , STATE_DISPLAY = 1U << 0 , STATE_VERIFY = 1U << 1 , STATE_PENDINGPREFIX = 1U << 2 ,
  STATE_WEED = 1U << 3 , STATE_CHARCONV = 1U << 4 , STATE_PRINTING = 1U << 5 , STATE_REPLYING = 1U << 6 ,
  STATE_FIRSTDONE = 1U << 7 , STATE_DISPLAY_ATTACH = 1U << 8 , STATE_PAGER = 1U << 9
}
 Flags for State->flags. More...
 

Functions

void state_attach_puts (struct State *state, const char *t)
 Write a string to the state.
 
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_prefix_put (struct State *state, const char *buf, size_t buflen)
 Write a prefixed fixed-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,...) __attribute__((__format__(__printf__
 
int int state_putws (struct State *state, const wchar_t *ws)
 Write a wide string to the state.
 
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.
 

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

Macro Definition Documentation

◆ state_set_prefix

#define state_set_prefix ( state)
Value:
((state)->flags |= STATE_PENDINGPREFIX)
@ STATE_PENDINGPREFIX
Prefix to write, but character must follow.
Definition state.h:39

Definition at line 62 of file state.h.

◆ state_reset_prefix

#define state_reset_prefix ( state)
Value:
((state)->flags &= ~STATE_PENDINGPREFIX)

Definition at line 63 of file state.h.

◆ state_puts

#define state_puts ( STATE,
STR )
Value:
fputs(STR, (STATE)->fp_out)

Definition at line 64 of file state.h.

◆ state_putc

#define state_putc ( STATE,
STR )
Value:
fputc(STR, (STATE)->fp_out)

Definition at line 65 of file state.h.

Typedef Documentation

◆ StateFlags

typedef uint16_t StateFlags

Definition at line 48 of file state.h.

Enumeration Type Documentation

◆ StateFlag

enum StateFlag

Flags for State->flags.

Enumerator
STATE_NONE 

No flags are set.

STATE_DISPLAY 

Output is displayed to the user.

STATE_VERIFY 

Perform signature verification.

STATE_PENDINGPREFIX 

Prefix to write, but character must follow.

STATE_WEED 

Weed headers even when not in display mode.

STATE_CHARCONV 

Do character set conversions.

STATE_PRINTING 

Are we printing? - STATE_DISPLAY "light".

STATE_REPLYING 

Are we replying?

STATE_FIRSTDONE 

The first attachment has been done.

STATE_DISPLAY_ATTACH 

We are displaying an attachment.

STATE_PAGER 

Output will be displayed in the Pager.

Definition at line 34 of file state.h.

35{
36 STATE_NONE = 0,
37 STATE_DISPLAY = 1U << 0,
38 STATE_VERIFY = 1U << 1,
39 STATE_PENDINGPREFIX = 1U << 2,
40 STATE_WEED = 1U << 3,
41 STATE_CHARCONV = 1U << 4,
42 STATE_PRINTING = 1U << 5,
43 STATE_REPLYING = 1U << 6,
44 STATE_FIRSTDONE = 1U << 7,
45 STATE_DISPLAY_ATTACH = 1U << 8,
46 STATE_PAGER = 1U << 9,
47};
@ STATE_CHARCONV
Do character set conversions.
Definition state.h:41
@ STATE_FIRSTDONE
The first attachment has been done.
Definition state.h:44
@ STATE_PRINTING
Are we printing? - STATE_DISPLAY "light".
Definition state.h:42
@ STATE_REPLYING
Are we replying?
Definition state.h:43
@ STATE_PAGER
Output will be displayed in the Pager.
Definition state.h:46
@ STATE_NONE
No flags are set.
Definition state.h:36
@ STATE_VERIFY
Perform signature verification.
Definition state.h:38
@ STATE_WEED
Weed headers even when not in display mode.
Definition state.h:40
@ STATE_DISPLAY_ATTACH
We are displaying an attachment.
Definition state.h:45
@ STATE_DISPLAY
Output is displayed to the user.
Definition state.h:37

Function Documentation

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

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

74{
75 if (!state || !state->fp_out)
76 return;
77
79 {
81 }
82}
const char * state_attachment_marker(void)
Get a unique (per-run) ANSI string to mark PGP messages in an email.
Definition state.c:45
#define state_puts(STATE, STR)
Definition state.h:64
StateFlags flags
Flags, e.g. STATE_DISPLAY.
Definition state.h:58
+ 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 88 of file state.c.

89{
90 if (!state || !state->fp_out)
91 return;
92
94 {
96 }
97}
const char * state_protected_header_marker(void)
Get a unique (per-run) ANSI string to mark protected headers in an email.
Definition state.c:59
+ Here is the call graph for this function:
+ 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 211 of file state.c.

212{
213 if (!state || !state->fp_out || !buf)
214 return;
215
216 if (state->prefix)
217 {
218 while (buflen--)
219 state_prefix_putc(state, *buf++);
220 }
221 else
222 {
223 fwrite(buf, buflen, 1, state->fp_out);
224 }
225}
void state_prefix_putc(struct State *state, char c)
Write a prefixed character to the state.
Definition state.c:168
const char * prefix
String to add to the beginning of each output line.
Definition state.h:57
+ 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 168 of file state.c.

169{
170 if (state->flags & STATE_PENDINGPREFIX)
171 {
172 state_reset_prefix(state);
173 if (state->prefix)
174 state_puts(state, state->prefix);
175 }
176
177 state_putc(state, c);
178
179 if (c == '\n')
180 state_set_prefix(state);
181}
#define state_set_prefix(state)
Definition state.h:62
#define state_reset_prefix(state)
Definition state.h:63
+ Here is the caller graph for this function:

◆ state_printf()

int state_printf ( struct State * state,
const char * fmt,
... )
+ Here is the call graph for this function:

◆ state_putws()

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

148{
149 if (!state || !state->fp_out)
150 return -1;
151
152 const wchar_t *p = ws;
153
154 while (p && (*p != L'\0'))
155 {
156 if (state_putwc(state, *p) < 0)
157 return -1;
158 p++;
159 }
160 return 0;
161}
static int state_putwc(struct State *state, wchar_t wc)
Write a wide character to the state.
Definition state.c:127
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

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

46{
47 static char marker[256] = { 0 };
48 if (!marker[0])
49 {
50 snprintf(marker, sizeof(marker), "\033]9;%" PRIu64 "\a", mutt_rand64());
51 }
52 return marker;
53}
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 59 of file state.c.

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