NeoMutt  2024-12-12-14-g7b49f7
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_NO_FLAGS   0
 No flags are set.
 
#define STATE_DISPLAY   (1 << 0)
 Output is displayed to the user.
 
#define STATE_VERIFY   (1 << 1)
 Perform signature verification.
 
#define STATE_PENDINGPREFIX   (1 << 2)
 Prefix to write, but character must follow.
 
#define STATE_WEED   (1 << 3)
 Weed headers even when not in display mode.
 
#define STATE_CHARCONV   (1 << 4)
 Do character set conversions.
 
#define STATE_PRINTING   (1 << 5)
 Are we printing? - STATE_DISPLAY "light".
 
#define STATE_REPLYING   (1 << 6)
 Are we replying?
 
#define STATE_FIRSTDONE   (1 << 7)
 The first attachment has been done.
 
#define STATE_DISPLAY_ATTACH   (1 << 8)
 We are displaying an attachment.
 
#define STATE_PAGER   (1 << 9)
 Output will be displayed in the Pager.
 
#define state_set_prefix(state)   ((state)->flags |= STATE_PENDINGPREFIX)
 
#define state_reset_prefix(state)   ((state)->flags &= ~STATE_PENDINGPREFIX)
 
#define state_puts(STATE, STR)   fputs(STR, (STATE)->fp_out)
 
#define state_putc(STATE, STR)   fputc(STR, (STATE)->fp_out)
 

Typedefs

typedef uint16_t StateFlags
 Flags for State->flags, e.g. STATE_DISPLAY.
 

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_NO_FLAGS

#define STATE_NO_FLAGS   0

No flags are set.

Definition at line 32 of file state.h.

◆ STATE_DISPLAY

#define STATE_DISPLAY   (1 << 0)

Output is displayed to the user.

Definition at line 33 of file state.h.

◆ STATE_VERIFY

#define STATE_VERIFY   (1 << 1)

Perform signature verification.

Definition at line 34 of file state.h.

◆ STATE_PENDINGPREFIX

#define STATE_PENDINGPREFIX   (1 << 2)

Prefix to write, but character must follow.

Definition at line 35 of file state.h.

◆ STATE_WEED

#define STATE_WEED   (1 << 3)

Weed headers even when not in display mode.

Definition at line 36 of file state.h.

◆ STATE_CHARCONV

#define STATE_CHARCONV   (1 << 4)

Do character set conversions.

Definition at line 37 of file state.h.

◆ STATE_PRINTING

#define STATE_PRINTING   (1 << 5)

Are we printing? - STATE_DISPLAY "light".

Definition at line 38 of file state.h.

◆ STATE_REPLYING

#define STATE_REPLYING   (1 << 6)

Are we replying?

Definition at line 39 of file state.h.

◆ STATE_FIRSTDONE

#define STATE_FIRSTDONE   (1 << 7)

The first attachment has been done.

Definition at line 40 of file state.h.

◆ STATE_DISPLAY_ATTACH

#define STATE_DISPLAY_ATTACH   (1 << 8)

We are displaying an attachment.

Definition at line 41 of file state.h.

◆ STATE_PAGER

#define STATE_PAGER   (1 << 9)

Output will be displayed in the Pager.

Definition at line 42 of file state.h.

◆ state_set_prefix

#define state_set_prefix (   state)    ((state)->flags |= STATE_PENDINGPREFIX)

Definition at line 56 of file state.h.

◆ state_reset_prefix

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

Definition at line 57 of file state.h.

◆ state_puts

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

Definition at line 58 of file state.h.

◆ state_putc

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

Definition at line 59 of file state.h.

Typedef Documentation

◆ StateFlags

typedef uint16_t StateFlags

Flags for State->flags, e.g. STATE_DISPLAY.

Definition at line 31 of file state.h.

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:59
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_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_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
+ 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 205 of file state.c.

206{
207 if (state->prefix)
208 {
209 while (buflen--)
210 state_prefix_putc(state, *buf++);
211 }
212 else
213 {
214 fwrite(buf, buflen, 1, state->fp_out);
215 }
216}
void state_prefix_putc(struct State *state, char c)
Write a prefixed character to the state.
Definition: state.c:165
const char * prefix
String to add to the beginning of each output line.
Definition: state.h:51
+ 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 165 of file state.c.

166{
167 if (state->flags & STATE_PENDINGPREFIX)
168 {
169 state_reset_prefix(state);
170 if (state->prefix)
171 state_puts(state, state->prefix);
172 }
173
174 state_putc(state, c);
175
176 if (c == '\n')
177 state_set_prefix(state);
178}
#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
+ Here is the caller graph for this function:

◆ state_printf()

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

◆ 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 const wchar_t *p = ws;
150
151 while (p && (*p != L'\0'))
152 {
153 if (state_putwc(state, *p) < 0)
154 return -1;
155 p++;
156 }
157 return 0;
158}
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:456
+ Here is the call graph for this function:
+ Here is the caller graph for this function: