NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
private.h File Reference

Shared constants/structs that are private to libpattern. More...

#include "config.h"
#include <stdbool.h>
#include "mutt/lib.h"
#include "lib.h"
+ Include dependency graph for private.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PatternFlags
 Mapping between user character and internal constant. More...
 
struct  RangeRegex
 Regular expression representing a range. More...
 

Macros

#define RANGE_NUM_RX   "([[:digit:]]+|0x[[:xdigit:]]+)[MmKk]?"
 
#define RANGE_REL_SLOT_RX   "[[:blank:]]*([.^$]|-?" RANGE_NUM_RX ")?[[:blank:]]*"
 
#define RANGE_REL_RX   "^" RANGE_REL_SLOT_RX "," RANGE_REL_SLOT_RX
 
#define RANGE_ABS_SLOT_RX   "[[:blank:]]*([.^$]|" RANGE_NUM_RX ")?[[:blank:]]*"
 
#define RANGE_ABS_RX   "^" RANGE_ABS_SLOT_RX "-" RANGE_ABS_SLOT_RX
 
#define RANGE_LT_RX   "^()[[:blank:]]*(<[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_GT_RX   "^()[[:blank:]]*(>[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_BARE_RX   "^[[:blank:]]*([.^$]|" RANGE_NUM_RX ")[[:blank:]]*"
 
#define RANGE_RX_GROUPS   5
 
#define RANGE_DOT   '.'
 
#define RANGE_CIRCUM   '^'
 
#define RANGE_DOLLAR   '$'
 
#define RANGE_LT   '<'
 
#define RANGE_GT   '>'
 
#define EMSG(e)   (((e)->msgno) + 1)
 
#define MUTT_MAXRANGE   -1
 

Enumerations

enum  PatternEat {
  EAT_NONE, EAT_REGEX, EAT_DATE, EAT_RANGE,
  EAT_MESSAGE_RANGE, EAT_QUERY
}
 Function to process pattern arguments. More...
 
enum  RangeType {
  RANGE_K_REL, RANGE_K_ABS, RANGE_K_LT, RANGE_K_GT,
  RANGE_K_BARE, RANGE_K_INVALID
}
 Type of range. More...
 
enum  RangeSide { RANGE_S_LEFT, RANGE_S_RIGHT }
 Which side of the range. More...
 

Functions

const struct PatternFlagslookup_op (int op)
 Lookup the Pattern Flags for an op. More...
 
const struct PatternFlagslookup_tag (char tag)
 Lookup a pattern modifier. More...
 
bool eval_date_minmax (struct Pattern *pat, const char *s, struct Buffer *err)
 Evaluate a date-range pattern against 'now'. More...
 

Variables

struct RangeRegex range_regexes []
 Set of Regexes for various range types. More...
 
const struct PatternFlags Flags []
 Lookup table for all patterns. More...
 

Detailed Description

Shared constants/structs that are private to libpattern.

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

Macro Definition Documentation

◆ RANGE_NUM_RX

#define RANGE_NUM_RX   "([[:digit:]]+|0x[[:xdigit:]]+)[MmKk]?"

Definition at line 86 of file private.h.

◆ RANGE_REL_SLOT_RX

#define RANGE_REL_SLOT_RX   "[[:blank:]]*([.^$]|-?" RANGE_NUM_RX ")?[[:blank:]]*"

Definition at line 87 of file private.h.

◆ RANGE_REL_RX

#define RANGE_REL_RX   "^" RANGE_REL_SLOT_RX "," RANGE_REL_SLOT_RX

Definition at line 88 of file private.h.

◆ RANGE_ABS_SLOT_RX

#define RANGE_ABS_SLOT_RX   "[[:blank:]]*([.^$]|" RANGE_NUM_RX ")?[[:blank:]]*"

Definition at line 91 of file private.h.

◆ RANGE_ABS_RX

#define RANGE_ABS_RX   "^" RANGE_ABS_SLOT_RX "-" RANGE_ABS_SLOT_RX

Definition at line 92 of file private.h.

◆ RANGE_LT_RX

#define RANGE_LT_RX   "^()[[:blank:]]*(<[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 95 of file private.h.

◆ RANGE_GT_RX

#define RANGE_GT_RX   "^()[[:blank:]]*(>[[:blank:]]*" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 96 of file private.h.

◆ RANGE_BARE_RX

#define RANGE_BARE_RX   "^[[:blank:]]*([.^$]|" RANGE_NUM_RX ")[[:blank:]]*"

Definition at line 99 of file private.h.

◆ RANGE_RX_GROUPS

#define RANGE_RX_GROUPS   5

Definition at line 100 of file private.h.

◆ RANGE_DOT

#define RANGE_DOT   '.'

Definition at line 102 of file private.h.

◆ RANGE_CIRCUM

#define RANGE_CIRCUM   '^'

Definition at line 103 of file private.h.

◆ RANGE_DOLLAR

#define RANGE_DOLLAR   '$'

Definition at line 104 of file private.h.

◆ RANGE_LT

#define RANGE_LT   '<'

Definition at line 105 of file private.h.

◆ RANGE_GT

#define RANGE_GT   '>'

Definition at line 106 of file private.h.

◆ EMSG

#define EMSG (   e)    (((e)->msgno) + 1)

Definition at line 117 of file private.h.

◆ MUTT_MAXRANGE

#define MUTT_MAXRANGE   -1

Definition at line 119 of file private.h.

Enumeration Type Documentation

◆ PatternEat

enum PatternEat

Function to process pattern arguments.

Values for PatternFlags.eat_arg

Enumerator
EAT_NONE 

No arguments required.

EAT_REGEX 

Process a regex.

EAT_DATE 

Process a date (range)

EAT_RANGE 

Process a number (range)

EAT_MESSAGE_RANGE 

Process a message number (range)

EAT_QUERY 

Process a query string.

Definition at line 36 of file private.h.

37 {
38  EAT_NONE,
39  EAT_REGEX,
40  EAT_DATE,
41  EAT_RANGE,
43  EAT_QUERY,
44 };
Process a number (range)
Definition: private.h:41
Process a regex.
Definition: private.h:39
No arguments required.
Definition: private.h:38
Process a message number (range)
Definition: private.h:42
Process a date (range)
Definition: private.h:40
Process a query string.
Definition: private.h:43

◆ RangeType

enum RangeType

Type of range.

Enumerator
RANGE_K_REL 

Relative range.

RANGE_K_ABS 

Absolute range.

RANGE_K_LT 

Less-than range.

RANGE_K_GT 

Greater-than range.

RANGE_K_BARE 

Single symbol.

RANGE_K_INVALID 

Range is invalid.

Definition at line 74 of file private.h.

75 {
76  RANGE_K_REL,
77  RANGE_K_ABS,
78  RANGE_K_LT,
79  RANGE_K_GT,
80  RANGE_K_BARE,
81  /* add new ones HERE */
83 };
Relative range.
Definition: private.h:76
Less-than range.
Definition: private.h:78
Single symbol.
Definition: private.h:80
Range is invalid.
Definition: private.h:82
Greater-than range.
Definition: private.h:79
Absolute range.
Definition: private.h:77

◆ RangeSide

enum RangeSide

Which side of the range.

Enumerator
RANGE_S_LEFT 

Left side of range.

RANGE_S_RIGHT 

Right side of range.

Definition at line 111 of file private.h.

112 {
113  RANGE_S_LEFT,
114  RANGE_S_RIGHT,
115 };
Right side of range.
Definition: private.h:114
Left side of range.
Definition: private.h:113

Function Documentation

◆ lookup_op()

const struct PatternFlags* lookup_op ( int  op)

Lookup the Pattern Flags for an op.

Parameters
opOperation, e.g. MUTT_PAT_SENDER
Return values
ptrPatternFlags

Definition at line 210 of file flags.c.

211 {
212  for (int i = 0; Flags[i].tag; i++)
213  if (Flags[i].op == op)
214  return (&Flags[i]);
215  return NULL;
216 }
const struct PatternFlags Flags[]
Lookup table for all patterns.
Definition: flags.c:41
int tag
Character used to represent this operation, e.g. &#39;A&#39; for &#39;~A&#39;.
Definition: private.h:51
+ Here is the caller graph for this function:

◆ lookup_tag()

const struct PatternFlags* lookup_tag ( char  tag)

Lookup a pattern modifier.

Parameters
tagLetter, e.g. 'b' for pattern '~b'
Return values
ptrPattern data

Definition at line 197 of file flags.c.

198 {
199  for (int i = 0; Flags[i].tag; i++)
200  if (Flags[i].tag == tag)
201  return &Flags[i];
202  return NULL;
203 }
const struct PatternFlags Flags[]
Lookup table for all patterns.
Definition: flags.c:41
int tag
Character used to represent this operation, e.g. &#39;A&#39; for &#39;~A&#39;.
Definition: private.h:51
+ Here is the caller graph for this function:

◆ eval_date_minmax()

bool eval_date_minmax ( struct Pattern pat,
const char *  s,
struct Buffer err 
)

Evaluate a date-range pattern against 'now'.

Parameters
patPattern to modify
sPattern string to use
errBuffer for error messages
Return values
truePattern valid and updated
falsePattern invalid

Definition at line 499 of file compile.c.

500 {
501  /* the '0' time is Jan 1, 1970 UTC, so in order to prevent a negative time
502  * when doing timezone conversion, we use Jan 2, 1970 UTC as the base here */
503  struct tm min = { 0 };
504  min.tm_mday = 2;
505  min.tm_year = 70;
506 
507  /* Arbitrary year in the future. Don't set this too high or
508  * mutt_date_make_time() returns something larger than will fit in a time_t
509  * on some systems */
510  struct tm max = { 0 };
511  max.tm_year = 130;
512  max.tm_mon = 11;
513  max.tm_mday = 31;
514  max.tm_hour = 23;
515  max.tm_min = 59;
516  max.tm_sec = 59;
517 
518  if (strchr("<>=", s[0]))
519  {
520  /* offset from current time
521  * <3d less than three days ago
522  * >3d more than three days ago
523  * =3d exactly three days ago */
524  struct tm *tm = NULL;
525  bool exact = false;
526 
527  if (s[0] == '<')
528  {
530  tm = &min;
531  }
532  else
533  {
535  tm = &max;
536 
537  if (s[0] == '=')
538  exact = true;
539  }
540 
541  /* Reset the HMS unless we are relative matching using one of those
542  * offsets. */
543  char *offset_type = NULL;
544  strtol(s + 1, &offset_type, 0);
545  if (!(*offset_type && strchr("HMS", *offset_type)))
546  {
547  tm->tm_hour = 23;
548  tm->tm_min = 59;
549  tm->tm_sec = 59;
550  }
551 
552  /* force negative offset */
553  get_offset(tm, s + 1, -1);
554 
555  if (exact)
556  {
557  /* start at the beginning of the day in question */
558  memcpy(&min, &max, sizeof(max));
559  min.tm_hour = 0;
560  min.tm_sec = 0;
561  min.tm_min = 0;
562  }
563  }
564  else
565  {
566  const char *pc = s;
567 
568  bool have_min = false;
569  bool until_now = false;
570  if (isdigit((unsigned char) *pc))
571  {
572  /* minimum date specified */
573  pc = get_date(pc, &min, err);
574  if (!pc)
575  {
576  return false;
577  }
578  have_min = true;
579  SKIPWS(pc);
580  if (*pc == '-')
581  {
582  const char *pt = pc + 1;
583  SKIPWS(pt);
584  until_now = (*pt == '\0');
585  }
586  }
587 
588  if (!until_now)
589  { /* max date or relative range/window */
590 
591  struct tm base_min;
592 
593  if (!have_min)
594  { /* save base minimum and set current date, e.g. for "-3d+1d" */
595  memcpy(&base_min, &min, sizeof(base_min));
597  min.tm_hour = 0;
598  min.tm_sec = 0;
599  min.tm_min = 0;
600  }
601 
602  /* preset max date for relative offsets,
603  * if nothing follows we search for messages on a specific day */
604  max.tm_year = min.tm_year;
605  max.tm_mon = min.tm_mon;
606  max.tm_mday = min.tm_mday;
607 
608  if (!parse_date_range(pc, &min, &max, have_min, &base_min, err))
609  { /* bail out on any parsing error */
610  return false;
611  }
612  }
613  }
614 
615  /* Since we allow two dates to be specified we'll have to adjust that. */
616  adjust_date_range(&min, &max);
617 
618  pat->min = mutt_date_make_time(&min, true);
619  pat->max = mutt_date_make_time(&max, true);
620 
621  return true;
622 }
static const char * parse_date_range(const char *pc, struct tm *min, struct tm *max, bool have_min, struct tm *base_min, struct Buffer *err)
Parse a date range.
Definition: compile.c:375
struct tm mutt_date_localtime(time_t t)
Converts calendar time to a broken-down time structure expressed in user timezone.
Definition: date.c:654
static const char * get_date(const char *s, struct tm *t, struct Buffer *err)
Parse a (partial) date in dd/mm/yyyy format.
Definition: compile.c:289
#define MUTT_DATE_NOW
Constant representing the &#39;current time&#39;, see: mutt_date_gmtime(), mutt_date_localtime() ...
Definition: date.h:39
#define SKIPWS(ch)
Definition: string2.h:46
static void adjust_date_range(struct tm *min, struct tm *max)
Put a date range in the correct order.
Definition: compile.c:461
int min
Minimum for range checks.
Definition: lib.h:80
int max
Maximum for range checks.
Definition: lib.h:81
static const char * get_offset(struct tm *tm, const char *s, int sign)
Calculate a symbolic offset.
Definition: compile.c:235
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:229
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ range_regexes

struct RangeRegex range_regexes[]

Set of Regexes for various range types.

This array, will also contain the compiled regexes.

Definition at line 66 of file pattern.c.

◆ Flags

const struct PatternFlags Flags[]

Lookup table for all patterns.

Definition at line 41 of file flags.c.