Home | History | Annotate | Line # | Download | only in util
      1 /*	$NetBSD: mac_expand.h,v 1.6 2026/05/09 18:49:22 christos Exp $	*/
      2 
      3 #ifndef _MAC_EXPAND_H_INCLUDED_
      4 #define _MAC_EXPAND_H_INCLUDED_
      5 
      6 /*++
      7 /* NAME
      8 /*	mac_expand 3h
      9 /* SUMMARY
     10 /*	expand macro references in string
     11 /* SYNOPSIS
     12 /*	#include <mac_expand.h>
     13 /* DESCRIPTION
     14 /* .nf
     15 
     16  /*
     17   * Utility library.
     18   */
     19 #include <vstring.h>
     20 #include <mac_parse.h>
     21 
     22  /*
     23   * Features.
     24   */
     25 #define MAC_EXP_FLAG_NONE	(0)
     26 #define MAC_EXP_FLAG_RECURSE	(1<<0)
     27 #define MAC_EXP_FLAG_APPEND	(1<<1)
     28 #define MAC_EXP_FLAG_SCAN	(1<<2)
     29 #define MAC_EXP_FLAG_PRINTABLE  (1<<3)
     30 
     31  /*
     32   * Token codes, public so tha they are available to mac_expand_add_relop()
     33   */
     34 #define MAC_EXP_OP_TOK_NONE	0	/* Sentinel */
     35 #define MAC_EXP_OP_TOK_EQ	1	/* == */
     36 #define MAC_EXP_OP_TOK_NE	2	/* != */
     37 #define MAC_EXP_OP_TOK_LT	3	/* < */
     38 #define MAC_EXP_OP_TOK_LE	4	/* <= */
     39 #define MAC_EXP_OP_TOK_GE	5	/* >= */
     40 #define MAC_EXP_OP_TOK_GT	6	/* > */
     41 
     42  /*
     43   * Relational operator results. An enum to discourage assuming that 0 is
     44   * false, !0 is true.
     45   */
     46 typedef enum MAC_EXP_OP_RES {
     47     MAC_EXP_OP_RES_TRUE,
     48     MAC_EXP_OP_RES_FALSE,
     49     MAC_EXP_OP_RES_ERROR,
     50 }       MAC_EXP_OP_RES;
     51 
     52 
     53 extern MAC_EXP_OP_RES mac_exp_op_res_bool[2];
     54 
     55  /*
     56   * Real lookup or just a test?
     57   */
     58 #define MAC_EXP_MODE_TEST	(0)
     59 #define MAC_EXP_MODE_USE	(1)
     60 
     61 typedef const char *(*MAC_EXP_LOOKUP_FN) (const char *, int, void *);
     62 typedef bool(*MAC_EXP_DONT_PARSE_FN) (const char *, void *);
     63 typedef MAC_EXP_OP_RES(*MAC_EXPAND_RELOP_FN) (const char *, int, const char *);
     64 typedef int (*MAC_EXPAND_NAMED_FN) (VSTRING *, const char *);
     65 
     66 extern int mac_expand7(VSTRING *, const char *, int, const char *, MAC_EXP_LOOKUP_FN, MAC_EXP_DONT_PARSE_FN, void *);
     67 extern void mac_expand_add_relop(int *, const char *, MAC_EXPAND_RELOP_FN);
     68 extern void mac_expand_add_named_fn(const char *, MAC_EXPAND_NAMED_FN);
     69 
     70 #define mac_expand(res, pat, flags, filter, lookup, ctx) \
     71     mac_expand7((res), (pat), (flags), (filter), (lookup), \
     72 	(MAC_EXP_DONT_PARSE_FN) 0, (ctx))
     73 
     74 /* LICENSE
     75 /* .ad
     76 /* .fi
     77 /*	The Secure Mailer license must be distributed with this software.
     78 /* AUTHOR(S)
     79 /*	Wietse Venema
     80 /*	IBM T.J. Watson Research
     81 /*	P.O. Box 704
     82 /*	Yorktown Heights, NY 10598, USA
     83 /*
     84 /*	Wietse Venema
     85 /*	Google, Inc.
     86 /*	111 8th Avenue
     87 /*	New York, NY 10011, USA
     88 /*
     89 /*	Wietse Venema
     90 /*	porcupine.org
     91 /*--*/
     92 
     93 #endif
     94