1use std::sync::atomic::{AtomicI32, Ordering};
24
25#[inline]
31#[allow(non_snake_case)]
32pub fn minimum<T: PartialOrd>(a: T, b: T) -> T {
33 if a < b {
35 a
36 } else {
37 b
38 }
39}
40
41#[allow(non_camel_case_types)]
44pub type zlong = i64; #[allow(non_camel_case_types)]
48pub type zulong = u64; pub const ZLONG_MAX: zlong = i64::MAX; #[allow(non_camel_case_types)]
71#[derive(Debug, Clone, Copy)] pub struct mnumber {
73 pub l: i64, pub d: f64, pub type_: u32, }
78pub const MN_INTEGER: u32 = 1; pub const MN_FLOAT: u32 = 2; pub const MN_UNSET: u32 = 4; pub type MathFunc = Box<mathfunc>; pub type NumMathFunc = fn(name: &str, argc: i32, argv: &[mnumber], id: i32) -> mnumber;
90
91pub type StrMathFunc = fn(name: &str, arg: &str, id: i32) -> mnumber;
93
94#[allow(non_camel_case_types)]
96pub struct mathfunc {
97 pub next: Option<Box<mathfunc>>, pub name: String, pub flags: i32, pub nfunc: Option<NumMathFunc>, pub sfunc: Option<StrMathFunc>, pub module: Option<String>, pub minargs: i32, pub maxargs: i32, pub funcid: i32, }
108pub const MFF_STR: i32 = 1; pub const MFF_ADDED: i32 = 2; pub const MFF_USERFUNC: i32 = 4; pub const MFF_AUTOALL: i32 = 8; pub const Meta: u8 = 0x83; pub const DEFAULT_IFS: &str = " \t\n\u{83} "; pub const DEFAULT_IFS_SH: &str = " \t\n"; #[allow(non_upper_case_globals)]
144pub const Pound: char = '\u{84}'; pub const Stringg: char = '\u{85}'; #[allow(non_upper_case_globals)]
147pub const Hat: char = '\u{86}'; #[allow(non_upper_case_globals)]
149pub const Star: char = '\u{87}'; #[allow(non_upper_case_globals)]
151pub const Inpar: char = '\u{88}'; #[allow(non_upper_case_globals)]
153pub const Inparmath: char = '\u{89}'; #[allow(non_upper_case_globals)]
155pub const Outpar: char = '\u{8a}'; #[allow(non_upper_case_globals)]
157pub const Outparmath: char = '\u{8b}'; #[allow(non_upper_case_globals)]
159pub const Qstring: char = '\u{8c}'; #[allow(non_upper_case_globals)]
161pub const Equals: char = '\u{8d}'; #[allow(non_upper_case_globals)]
163pub const Bar: char = '\u{8e}'; #[allow(non_upper_case_globals)]
165pub const Inbrace: char = '\u{8f}'; #[allow(non_upper_case_globals)]
167pub const Outbrace: char = '\u{90}'; #[allow(non_upper_case_globals)]
169pub const Inbrack: char = '\u{91}'; #[allow(non_upper_case_globals)]
171pub const Outbrack: char = '\u{92}'; #[allow(non_upper_case_globals)]
173pub const Tick: char = '\u{93}'; #[allow(non_upper_case_globals)]
175pub const Inang: char = '\u{94}'; #[allow(non_upper_case_globals)]
177pub const Outang: char = '\u{95}'; #[allow(non_upper_case_globals)]
179pub const OutangProc: char = '\u{96}'; #[allow(non_upper_case_globals)]
181pub const Quest: char = '\u{97}'; #[allow(non_upper_case_globals)]
183pub const Tilde: char = '\u{98}'; #[allow(non_upper_case_globals)]
185pub const Qtick: char = '\u{99}'; #[allow(non_upper_case_globals)]
187pub const Comma: char = '\u{9a}'; #[allow(non_upper_case_globals)]
189pub const Dash: char = '\u{9b}'; #[allow(non_upper_case_globals)]
191pub const Bang: char = '\u{9c}'; pub const LAST_NORMAL_TOK: char = Bang; #[allow(non_upper_case_globals)]
196pub const Snull: char = '\u{9d}'; #[allow(non_upper_case_globals)]
198pub const Dnull: char = '\u{9e}'; #[allow(non_upper_case_globals)]
200pub const Bnull: char = '\u{9f}'; #[allow(non_upper_case_globals)]
202pub const Bnullkeep: char = '\u{a0}'; #[allow(non_upper_case_globals)]
204pub const Nularg: char = '\u{a1}'; #[allow(non_upper_case_globals)]
206pub const Marker: char = '\u{a2}'; pub const SPECCHARS: &str = "#$^*()=|{}[]`<>?~;&\n\t \\\'\""; pub const PATCHARS: &str = "#^*()|[]<>?~\\"; #[inline]
214#[allow(non_snake_case)]
215pub fn IS_DASH(x: char) -> bool {
216 x == '-' || x == Dash
217} pub const QT_NONE: i32 = 0; pub const QT_BACKSLASH: i32 = 1; pub const QT_SINGLE: i32 = 2; pub const QT_DOUBLE: i32 = 3; pub const QT_DOLLARS: i32 = 4; pub const QT_BACKTICK: i32 = 5; pub const QT_SINGLE_OPTIONAL: i32 = 6; pub const QT_BACKSLASH_PATTERN: i32 = 7; pub const QT_BACKSLASH_SHOWNULL: i32 = 8; pub const QT_QUOTEDZPUTS: i32 = 9; #[inline]
245#[allow(non_snake_case)]
246pub fn QT_IS_SINGLE(x: i32) -> bool {
247 x == QT_SINGLE || x == QT_SINGLE_OPTIONAL
248}
249
250#[allow(non_camel_case_types)]
255pub type lextok = i32;
256pub const NULLTOK: lextok = 0; pub const SEPER: lextok = 1;
260pub const NEWLIN: lextok = 2;
262pub const SEMI: lextok = 3;
264pub const DSEMI: lextok = 4;
266pub const AMPER: lextok = 5;
268pub const INPAR_TOK: lextok = 6; pub const OUTPAR_TOK: lextok = 7;
272pub const DBAR: lextok = 8;
274pub const DAMPER: lextok = 9;
276pub const OUTANG_TOK: lextok = 10; pub const OUTANGBANG: lextok = 11;
280pub const DOUTANG: lextok = 12;
282pub const DOUTANGBANG: lextok = 13;
284pub const INANG_TOK: lextok = 14;
286pub const INOUTANG: lextok = 15;
288pub const DINANG: lextok = 16;
290pub const DINANGDASH: lextok = 17;
292pub const INANGAMP: lextok = 18;
294pub const OUTANGAMP: lextok = 19;
296pub const AMPOUTANG: lextok = 20;
298pub const OUTANGAMPBANG: lextok = 21;
300pub const DOUTANGAMP: lextok = 22;
302pub const DOUTANGAMPBANG: lextok = 23;
304pub const TRINANG: lextok = 24;
306pub const BAR_TOK: lextok = 25;
308pub const BARAMP: lextok = 26;
310pub const INOUTPAR: lextok = 27;
312pub const DINPAR: lextok = 28;
314pub const DOUTPAR: lextok = 29;
316pub const AMPERBANG: lextok = 30;
318pub const SEMIAMP: lextok = 31;
320pub const SEMIBAR: lextok = 32;
322pub const DOUTBRACK: lextok = 33;
324pub const STRING_LEX: lextok = 34;
326pub const ENVSTRING: lextok = 35;
328pub const ENVARRAY: lextok = 36;
330pub const ENDINPUT: lextok = 37;
332pub const LEXERR: lextok = 38;
334pub const BANG_TOK: lextok = 39; pub const DINBRACK: lextok = 40;
338pub const INBRACE_TOK: lextok = 41;
340pub const OUTBRACE_TOK: lextok = 42;
342pub const CASE: lextok = 43;
344pub const COPROC: lextok = 44;
346pub const DOLOOP: lextok = 45;
348pub const DONE: lextok = 46;
350pub const ELIF: lextok = 47;
352pub const ELSE: lextok = 48;
354pub const ZEND: lextok = 49;
356pub const ESAC: lextok = 50;
358pub const FI: lextok = 51;
360pub const FOR: lextok = 52;
362pub const FOREACH: lextok = 53;
364pub const FUNC: lextok = 54;
366pub const IF: lextok = 55;
368pub const NOCORRECT: lextok = 56;
370pub const REPEAT: lextok = 57;
372pub const SELECT: lextok = 58;
374pub const THEN: lextok = 59;
376pub const TIME: lextok = 60;
378pub const UNTIL: lextok = 61;
380pub const WHILE: lextok = 62;
382pub const TYPESET: lextok = 63; pub const REDIR_WRITE: i32 = 0;
390pub const REDIR_WRITENOW: i32 = 1;
392pub const REDIR_APP: i32 = 2;
394pub const REDIR_APPNOW: i32 = 3;
396pub const REDIR_ERRWRITE: i32 = 4;
398pub const REDIR_ERRWRITENOW: i32 = 5;
400pub const REDIR_ERRAPP: i32 = 6;
402pub const REDIR_ERRAPPNOW: i32 = 7;
404pub const REDIR_READWRITE: i32 = 8;
406pub const REDIR_READ: i32 = 9;
408pub const REDIR_HEREDOC: i32 = 10;
410pub const REDIR_HEREDOCDASH: i32 = 11;
412pub const REDIR_HERESTR: i32 = 12;
414pub const REDIR_MERGEIN: i32 = 13;
416pub const REDIR_MERGEOUT: i32 = 14;
418pub const REDIR_CLOSE: i32 = 15;
420pub const REDIR_INPIPE: i32 = 16;
422pub const REDIR_OUTPIPE: i32 = 17;
424pub const REDIR_TYPE_MASK: i32 = 0x1f; pub const REDIR_VARID_MASK: i32 = 0x20; pub const REDIR_FROM_HEREDOC_MASK: i32 = 0x40; #[inline]
432#[allow(non_snake_case)]
433pub fn IS_WRITE_FILE(x: i32) -> bool {
434 x >= REDIR_WRITE && x <= REDIR_READWRITE
435}
436#[inline]
438#[allow(non_snake_case)]
439pub fn IS_APPEND_REDIR(x: i32) -> bool {
440 IS_WRITE_FILE(x) && (x & 2) != 0
441}
442#[inline]
444#[allow(non_snake_case)]
445pub fn IS_CLOBBER_REDIR(x: i32) -> bool {
446 IS_WRITE_FILE(x) && (x & 1) != 0
447}
448#[inline]
450#[allow(non_snake_case)]
451pub fn IS_ERROR_REDIR(x: i32) -> bool {
452 x >= REDIR_ERRWRITE && x <= REDIR_ERRAPPNOW
453}
454#[inline]
456#[allow(non_snake_case)]
457pub fn IS_READFD(x: i32) -> bool {
458 (x >= REDIR_READWRITE && x <= REDIR_MERGEIN) || x == REDIR_INPIPE
459}
460#[inline]
462#[allow(non_snake_case)]
463pub fn IS_REDIROP(x: lextok) -> bool {
464 x >= OUTANG_TOK && x <= TRINANG
465}
466
467pub const FDT_UNUSED: i32 = 0; pub const FDT_INTERNAL: i32 = 1; pub const FDT_EXTERNAL: i32 = 2; pub const FDT_MODULE: i32 = 3; pub const FDT_XTRACE: i32 = 4; pub const FDT_FLOCK: i32 = 5; pub const FDT_FLOCK_EXEC: i32 = 6; pub const FDT_PROC_SUBST: i32 = 7; pub const FDT_TYPE_MASK: i32 = 15; pub const FDT_SAVED_MASK: i32 = 16; pub const INP_FREE: i32 = 1 << 0; pub const INP_ALIAS: i32 = 1 << 1; pub const INP_HIST: i32 = 1 << 2; pub const INP_CONT: i32 = 1 << 3; pub const INP_ALCONT: i32 = 1 << 4; pub const INP_HISTCONT: i32 = 1 << 5; pub const INP_LINENO: i32 = 1 << 6; pub const INP_APPEND: i32 = 1 << 7; pub const INP_RAW_KEEP: i32 = 1 << 8; pub const META_REALLOC: i32 = 0; pub const META_USEHEAP: i32 = 1;
520pub const META_STATIC: i32 = 2;
522pub const META_DUP: i32 = 3;
524pub const META_ALLOC: i32 = 4;
526pub const META_NOALLOC: i32 = 5;
528pub const META_HEAPDUP: i32 = 6;
530pub const META_HREALLOC: i32 = 7;
532
533pub const ZCONTEXT_HIST: i32 = 1 << 0; pub const ZCONTEXT_LEX: i32 = 1 << 1; pub const ZCONTEXT_PARSE: i32 = 1 << 2; #[derive(Default)]
544#[allow(non_camel_case_types)]
545pub struct entersubsh_ret {
546 pub gleader: i32, pub list_pipe_job: i32, }
550
551#[allow(non_camel_case_types)]
556pub struct linknode {
557 pub next: Option<Box<linknode>>,
560 pub prev: Option<Box<linknode>>,
562 pub dat: usize,
564}
565#[allow(non_camel_case_types)]
567pub struct linklist {
568 pub first: Option<Box<linknode>>,
571 pub last: Option<Box<linknode>>,
573 pub flags: i32,
575}
576pub type LinkNode = Box<linknode>; pub type LinkList = Box<linklist>; pub type Alias = Box<alias>; pub type Asgment = Box<asgment>; pub type Builtin = Box<builtin>; pub type Cmdnam = Box<cmdnam>; pub type Complist = Box<crate::ported::glob::complist>; pub type Conddef = Box<conddef>; pub type Dirsav = Box<dirsav>; pub type Emulation_options = Box<emulation_options>; pub type Execcmd_params = Box<execcmd_params>; pub type Features = Box<features>; pub type Feature_enables = Box<feature_enables>; pub type Funcstack = Box<funcstack>; pub type FuncWrap = Box<funcwrap>; pub type HashNode = Box<hashnode>; pub type HashTable = Box<hashtable>; pub type Heap = Box<heap>; pub type Heapstack = Box<heapstack>; pub type Histent = Box<histent>; pub type Hookdef = Box<hookdef>; pub type Imatchdata = Box<imatchdata>; pub type Job = Box<job>; pub type Jobfile = Box<jobfile>; pub type Linkedmod = Box<linkedmod>; pub type Module = Box<module>; pub type Nameddir = Box<nameddir>; pub type Options = Box<options>; pub type Optname = Box<optname>; pub type Param = Box<param>; pub type Paramdef = Box<paramdef>; pub type Patstralloc = Box<patstralloc>; pub type Patprog = Box<patprog>; pub type Prepromptfn = Box<prepromptfn>; pub type Process = Box<process>; pub type Redir = Box<redir>; pub type Reswd = Box<reswd>; pub type Shfunc = Box<shfunc>; pub type Timedfn = Box<timedfn>; pub type Value = Box<value>; pub type voidvoidfnptr_t = fn(); #[allow(non_camel_case_types)]
675pub struct prepromptfn {
676 pub func: voidvoidfnptr_t,
679}
680
681#[allow(non_camel_case_types)]
683pub struct timedfn {
684 pub func: voidvoidfnptr_t,
687 pub when: i64, }
689
690pub type CondHandler = fn(args: &[String], id: i32) -> i32;
692
693#[allow(non_camel_case_types)]
695pub struct conddef {
696 pub next: Option<Conddef>, pub name: String, pub flags: i32, pub handler: Option<CondHandler>, pub min: i32, pub max: i32, pub condid: i32, pub module: Option<String>, }
706
707#[allow(non_camel_case_types)]
709pub struct dirsav {
710 pub dirfd: i32, pub level: i32, pub dirname: Option<String>, pub dev: u64, pub ino: u64, }
717
718#[allow(non_camel_case_types)]
720#[derive(Debug, Clone, Default)]
721pub struct hashnode {
722 pub next: Option<HashNode>, pub nam: String, pub flags: i32, }
727
728pub type VFunc = fn(usize) -> usize; pub type FreeFunc = fn(usize); pub type HashFunc = fn(name: &str) -> u32; pub type TableFunc = fn(table: &mut hashtable); pub type AddNodeFunc = fn(table: &mut hashtable, name: String, val: usize);
739pub type GetNodeFunc = fn(table: &hashtable, name: &str) -> Option<HashNode>;
741pub type RemoveNodeFunc = fn(table: &mut hashtable, name: &str) -> Option<HashNode>;
743pub type FreeNodeFunc = fn(node: HashNode);
745pub type CompareFunc = fn(a: &str, b: &str) -> i32;
747pub type ScanFunc = fn(node: &HashNode, flags: i32);
749pub type ScanTabFunc = fn(table: &hashtable, func: ScanFunc, flags: i32);
751pub type PrintTableStats = fn(table: &hashtable);
753
754#[allow(non_camel_case_types)]
756#[derive(Clone)]
757pub struct hashtable {
758 pub hsize: i32, pub ct: i32, pub nodes: Vec<Option<HashNode>>, pub tmpdata: usize, pub hash: Option<HashFunc>, pub emptytable: Option<TableFunc>, pub filltable: Option<TableFunc>, pub cmpnodes: Option<CompareFunc>, pub addnode: Option<AddNodeFunc>, pub getnode: Option<GetNodeFunc>, pub getnode2: Option<GetNodeFunc>, pub removenode: Option<RemoveNodeFunc>, pub disablenode: Option<ScanFunc>, pub enablenode: Option<ScanFunc>, pub freenode: Option<FreeNodeFunc>, pub printnode: Option<ScanFunc>, pub scantab: Option<ScanTabFunc>, }
777
778#[allow(non_camel_case_types)]
780pub struct optname {
781 pub node: hashnode, pub optno: i32, }
785
786#[allow(non_camel_case_types)]
788#[derive(Debug, Clone)]
789pub struct reswd {
790 pub node: hashnode, pub token: i32, }
794
795#[allow(non_camel_case_types)]
797#[derive(Debug, Clone)]
798pub struct alias {
799 pub node: hashnode, pub text: String, pub inuse: i32, }
804
805#[allow(non_camel_case_types)]
815pub struct asgment {
816 pub node: linknode, pub name: String, pub flags: i32, pub scalar: Option<String>, pub array: Option<crate::ported::linklist::LinkList<String>>, }
823
824#[allow(non_camel_case_types)]
828#[derive(Debug, Clone)]
829pub struct cmdnam {
830 pub node: hashnode, pub name: Option<Vec<String>>, pub cmd: Option<String>, }
835
836#[allow(non_camel_case_types)]
838#[derive(Debug, Clone)]
839pub struct shfunc {
840 pub node: hashnode, pub filename: Option<String>, pub lineno: i64, pub funcdef: Option<Eprog>, pub redir: Option<Eprog>, pub sticky: Option<Emulation_options>, pub body: Option<String>,
856}
857
858#[allow(non_camel_case_types)]
860#[derive(Clone, Default)]
861pub struct funcstack {
862 pub prev: Option<Funcstack>, pub name: String, pub filename: Option<String>, pub caller: Option<String>, pub flineno: i64, pub lineno: i64, pub tp: i32, }
871
872pub type WrapFunc = fn(prog: Eprog, w: FuncWrap, name: &str) -> i32;
874
875#[allow(non_camel_case_types)]
877pub struct funcwrap {
878 pub next: Option<FuncWrap>, pub flags: i32, pub handler: Option<WrapFunc>, pub module: Option<Module>, }
884
885#[allow(non_camel_case_types)]
887pub struct builtin {
888 pub node: hashnode, pub handlerfunc: Option<HandlerFunc>, pub minargs: i32, pub maxargs: i32, pub funcid: i32, pub optstr: Option<String>, pub defopts: Option<String>, }
897
898#[allow(non_camel_case_types)]
906#[derive(Default)]
907pub struct execcmd_params {
908 pub args: Option<Vec<String>>, pub redir: Option<Vec<redir>>, pub beg: usize, pub varspc: Option<usize>, pub assignspc: Option<usize>, pub typ: i32, pub postassigns: i32, pub htok: i32, }
918
919#[allow(non_camel_case_types)]
927#[derive(Debug)]
928pub struct module {
929 pub node: hashnode, pub handle: Option<usize>, pub linked: Option<Linkedmod>, pub alias: Option<String>, pub autoloads: Option<crate::ported::linklist::LinkList<String>>, pub deps: Option<crate::ported::linklist::LinkList<String>>, pub wrapper: i32, }
938
939impl module {
940 pub fn new(name: &str) -> Self {
944 Self {
945 node: hashnode {
946 next: None,
947 nam: name.to_string(),
948 flags: MOD_LINKED,
949 },
950 handle: None,
951 linked: None,
952 alias: None,
953 autoloads: None,
954 deps: None,
955 wrapper: 0,
956 }
957 }
958
959 pub fn is_loaded(&self) -> bool {
963 (self.node.flags & MOD_LINKED) != 0 && (self.node.flags & MOD_UNLOAD) == 0
964 }
965}
966
967pub type Module_generic_func = fn() -> i32;
969pub type Module_void_func = fn(m: &module) -> i32;
971pub type Module_features_func = fn(m: &module, features: &mut Vec<String>) -> i32;
973pub type Module_enables_func = fn(m: &module, enables: &mut Vec<i32>) -> i32;
975
976#[allow(non_camel_case_types)]
978#[derive(Debug)]
979pub struct linkedmod {
980 pub name: String, pub setup: Option<Module_void_func>, pub features: Option<Module_features_func>, pub enables: Option<Module_enables_func>, pub boot: Option<Module_void_func>, pub cleanup: Option<Module_void_func>, pub finish: Option<Module_void_func>, }
989
990#[allow(non_camel_case_types)]
992pub struct features {
993 pub bn_list: Option<Builtin>, pub bn_size: i32, pub cd_list: Option<Conddef>, pub cd_size: i32, pub mf_list: Option<MathFunc>, pub mf_size: i32, pub pd_list: Option<Paramdef>, pub pd_size: i32, pub n_abstract: i32, }
1004
1005#[allow(non_camel_case_types)]
1007pub struct feature_enables {
1008 pub str: String, pub pat: Option<Patprog>, }
1012
1013pub type Hookfn = fn(h: *mut hookdef, d: *mut std::ffi::c_void) -> i32;
1016
1017#[allow(non_camel_case_types)]
1025pub struct hookdef {
1026 pub next: *mut hookdef, pub name: String, pub def: Option<Hookfn>, pub flags: i32, pub funcs: *mut linklist, }
1033unsafe impl Send for hookdef {}
1038unsafe impl Sync for hookdef {}
1039
1040#[derive(Debug, Clone)]
1048#[allow(non_camel_case_types)]
1049pub struct patprog {
1050 pub startoff: i64, pub size: i64, pub mustoff: i64, pub patmlen: i64, pub globflags: i32, pub globend: i32, pub flags: i32, pub patnpar: i32, pub patstartch: u8, }
1061
1062#[allow(non_camel_case_types)]
1064pub struct patstralloc {
1065 pub unmetalen: i32, pub unmetalenp: i32, pub alloced: Option<String>, pub progstrunmeta: Option<String>, pub progstrunmetalen: i32, }
1072
1073#[allow(non_camel_case_types)]
1075pub struct zpc_disables_save {
1076 pub next: Option<Box<zpc_disables_save>>, pub disables: u32, }
1080pub type Zpc_disables_save = Box<zpc_disables_save>; #[allow(non_camel_case_types)]
1085pub struct imatchdata {
1086 pub mstr: Option<String>, pub mlen: i32, pub ustr: Option<String>, pub ulen: i32, pub flags: i32, pub replstr: Option<String>, pub repllist: Option<Vec<repldata>>, }
1100
1101pub type GsuScalar = Box<gsu_scalar>; pub type GsuInteger = Box<gsu_integer>; pub type GsuFloat = Box<gsu_float>; pub type GsuArray = Box<gsu_array>; pub type GsuHash = Box<gsu_hash>; #[allow(non_camel_case_types)]
1114#[derive(Clone)]
1115pub struct gsu_scalar {
1116 pub getfn: fn(pm: ¶m) -> String, pub setfn: fn(pm: &mut param, val: String), pub unsetfn: fn(pm: &mut param, exp: i32), }
1121#[allow(non_camel_case_types)]
1123#[derive(Clone)]
1124pub struct gsu_integer {
1125 pub getfn: fn(pm: ¶m) -> i64,
1127 pub setfn: fn(pm: &mut param, val: i64),
1129 pub unsetfn: fn(pm: &mut param, exp: i32),
1131}
1132#[allow(non_camel_case_types)]
1134#[derive(Clone)]
1135pub struct gsu_float {
1136 pub getfn: fn(pm: ¶m) -> f64,
1138 pub setfn: fn(pm: &mut param, val: f64),
1140 pub unsetfn: fn(pm: &mut param, exp: i32),
1142}
1143#[allow(non_camel_case_types)]
1145#[derive(Clone)]
1146pub struct gsu_array {
1147 pub getfn: fn(pm: ¶m) -> Vec<String>,
1149 pub setfn: fn(pm: &mut param, val: Vec<String>),
1151 pub unsetfn: fn(pm: &mut param, exp: i32),
1153}
1154#[allow(non_camel_case_types)]
1156#[derive(Clone)]
1157pub struct gsu_hash {
1158 pub getfn: fn(pm: ¶m) -> Option<&HashTable>,
1160 pub setfn: fn(pm: &mut param, val: HashTable),
1162 pub unsetfn: fn(pm: &mut param, exp: i32),
1164}
1165
1166#[allow(non_camel_case_types)]
1171#[derive(Clone, Default)]
1172pub struct param {
1173 pub node: hashnode, pub u_data: usize, pub u_tied: Option<Box<tieddata>>,
1181 pub u_arr: Option<Vec<String>>, pub u_str: Option<String>, pub u_val: i64, pub u_dval: f64, pub u_hash: Option<HashTable>, pub gsu_s: Option<GsuScalar>, pub gsu_i: Option<GsuInteger>, pub gsu_f: Option<GsuFloat>, pub gsu_a: Option<GsuArray>, pub gsu_h: Option<GsuHash>, pub base: i32, pub width: i32, pub env: Option<String>, pub ename: Option<String>, pub old: Option<Param>, pub level: i32, }
1199
1200#[allow(non_camel_case_types)]
1202#[derive(Clone)]
1203pub struct tieddata {
1204 pub arrptr: Option<Vec<String>>, pub joinchar: i32, }
1208
1209#[allow(non_camel_case_types)]
1211pub struct repldata {
1212 pub b: i32, pub e: i32, pub replstr: Option<String>, }
1217pub type Repldata = Box<repldata>; #[allow(non_camel_case_types)]
1222#[derive(Default)]
1223pub struct paramdef {
1224 pub name: String, pub flags: i32, pub var: usize, pub gsu: usize, pub getnfn: Option<GetNodeFunc>, pub scantfn: Option<ScanTabFunc>, pub pm: Option<Param>, }
1233
1234#[allow(non_camel_case_types)]
1236#[derive(Clone)]
1237pub struct nameddir {
1238 pub node: hashnode, pub dir: String, pub diff: i32, }
1243
1244#[allow(non_camel_case_types)]
1246pub struct groupmap {
1247 pub name: String, pub gid: u32, }
1251pub type Groupmap = Box<groupmap>; #[allow(non_camel_case_types)]
1256pub struct groupset {
1257 pub array: Vec<groupmap>, pub num: i32, }
1261pub type Groupset = Box<groupset>; #[allow(non_camel_case_types)]
1266pub struct histent {
1267 pub node: hashnode, pub up: Option<Histent>, pub down: Option<Histent>, pub zle_text: Option<String>, pub stim: i64, pub ftim: i64, pub words: Vec<i16>, pub nwords: i32, pub histnum: i64, }
1278
1279#[allow(non_camel_case_types)]
1281#[derive(Debug, Clone)]
1282pub struct emulation_options {
1283 pub emulation: i32, pub n_on_opts: i32, pub n_off_opts: i32, pub on_opts: Vec<OptIndex>, pub off_opts: Vec<OptIndex>, }
1290
1291#[allow(non_camel_case_types)]
1296#[derive(Debug, Clone)]
1297pub struct ttyinfo {
1298 #[cfg(unix)]
1300 pub tio: libc::termios, #[cfg(unix)]
1302 pub winsize: libc::winsize, }
1304
1305#[allow(non_camel_case_types)]
1307pub struct heapstack {
1308 pub next: Option<Heapstack>, pub used: usize, }
1312
1313#[allow(non_camel_case_types)]
1315pub struct heap {
1316 pub next: Option<Heap>, pub size: usize, pub used: usize, pub sp: Option<Heapstack>, }
1322
1323#[allow(non_camel_case_types)]
1325pub struct sortelt {
1326 pub orig: String, pub cmp: String, pub origlen: i32, pub len: i32, }
1332pub type SortElt = Box<sortelt>; #[allow(non_camel_case_types)]
1337pub struct hist_stack {
1338 pub histactive: i32, pub histdone: i32, pub stophist: i32, pub hlinesz: i32, pub defev: i64, pub hline: Option<String>, pub hptr: Option<String>, pub chwords: Vec<i16>, pub chwordlen: i32, pub chwordpos: i32, pub csp: i32, pub hist_keep_comment: i32, }
1352
1353#[allow(non_camel_case_types)]
1355#[derive(Debug, Clone, Default)]
1356pub struct lexbufstate {
1357 pub ptr: Option<String>, pub siz: i32, pub len: i32, }
1362
1363#[allow(non_camel_case_types)]
1365#[derive(Debug, Clone, Default)]
1366pub struct lex_stack {
1367 pub dbparens: i32, pub isfirstln: i32, pub isfirstch: i32, pub lexflags: i32, pub tok: lextok, pub tokstr: Option<String>, pub zshlextext: Option<String>, pub lexbuf: lexbufstate, pub lex_add_raw: i32, pub tokstr_raw: Option<String>, pub lexbuf_raw: lexbufstate, pub lexstop: i32, pub toklineno: i64, }
1382
1383#[allow(non_camel_case_types)]
1385pub struct parse_stack {
1386 pub hdocs: Option<Box<heredocs>>, pub incmdpos: i32, pub aliasspaceflag: i32, pub incond: i32, pub inredir: i32, pub incasepat: i32, pub isnewlin: i32, pub infor: i32, pub inrepeat_: i32, pub intypeset: i32, pub eclen: i32, pub ecused: i32, pub ecnpats: i32, pub ecbuf: Wordcode, pub ecstrs: Option<Eccstr>, pub ecsoffs: i32, pub ecssub: i32, pub ecnfunc: i32, }
1406
1407#[allow(non_camel_case_types)]
1410#[derive(Debug, Clone)]
1411pub struct heredocs {
1412 pub next: Option<Box<heredocs>>, pub typ: i32, pub pc: i32, pub str: Option<String>, }
1418
1419#[allow(non_camel_case_types)]
1421pub struct execstack {
1422 pub next: Option<Box<execstack>>, pub list_pipe_pid: i32, pub nowait: i32, pub pline_level: i32, pub list_pipe_child: i32, pub list_pipe_job: i32, pub list_pipe_text: [u8; JOBTEXTSIZE], pub lastval: i32, pub noeval: i32, pub badcshglob: i32, pub cmdoutpid: i32, pub cmdoutval: i32, pub use_cmdoutval: i32, pub procsubstpid: i32, pub trap_return: i32, pub trap_state: i32, pub trapisfunc: i32, pub traplocallevel: i32, pub noerrs: i32, pub this_noerrexit: i32, pub underscore: Option<String>, }
1445
1446#[allow(non_camel_case_types)]
1461#[derive(Debug, Clone)]
1462pub struct process {
1463 pub pid: i32, pub text: String, pub status: i32, pub ti: timeinfo, pub bgtime: Option<std::time::Instant>, pub endtime: Option<std::time::Instant>, }
1471
1472#[allow(non_camel_case_types)]
1484#[derive(Debug, Clone, Default)]
1485pub struct job {
1486 pub gleader: i32, pub other: i32, pub stat: i32, pub pwd: Option<String>, pub procs: Vec<process>, pub auxprocs: Vec<process>, pub filelist: Vec<jobfile>, pub stty_in_env: i32, pub ty: Option<Box<ttyinfo>>, pub text: String,
1499}
1500
1501#[allow(non_camel_case_types)]
1503#[derive(Debug, Clone)]
1504pub struct funcdump {
1505 pub next: Option<FuncDump>, pub dev: u64, pub ino: u64, pub fd: i32, pub map: Wordcode, pub addr: Wordcode, pub len: i32, pub count: i32, pub filename: Option<String>, }
1516
1517#[allow(non_camel_case_types)]
1519#[derive(Debug, Clone, Default)]
1520pub struct eprog {
1521 pub flags: i32, pub len: i32, pub npats: i32, pub nref: i32, pub pats: Vec<Patprog>, pub prog: Wordcode, pub strs: Option<String>, pub shf: Option<Shfunc>, pub dump: Option<FuncDump>, }
1532
1533#[allow(non_camel_case_types)]
1535pub struct estate {
1536 pub prog: Eprog, pub pc: usize, pub strs: Option<String>, pub strs_offset: usize, }
1542
1543#[allow(non_camel_case_types)]
1545pub struct eccstr {
1546 pub left: Option<Eccstr>, pub right: Option<Eccstr>, pub str: Option<String>, pub offs: wordcode, pub aoffs: wordcode, pub nfunc: i32, pub hashval: u32, }
1555
1556pub const Z_TIMED: i32 = 1 << 0; pub const Z_SYNC: i32 = 1 << 1; pub const Z_ASYNC: i32 = 1 << 2; pub const Z_DISOWN: i32 = 1 << 3; pub const COND_NOT: i32 = 0;
1573pub const COND_AND: i32 = 1;
1575pub const COND_OR: i32 = 2;
1577pub const COND_STREQ: i32 = 3;
1579pub const COND_STRDEQ: i32 = 4;
1581pub const COND_STRNEQ: i32 = 5;
1583pub const COND_STRLT: i32 = 6;
1585pub const COND_STRGTR: i32 = 7;
1587pub const COND_NT: i32 = 8;
1589pub const COND_OT: i32 = 9;
1591pub const COND_EF: i32 = 10;
1593pub const COND_EQ: i32 = 11;
1595pub const COND_NE: i32 = 12;
1597pub const COND_LT: i32 = 13;
1599pub const COND_GT: i32 = 14;
1601pub const COND_LE: i32 = 15;
1603pub const COND_GE: i32 = 16;
1605pub const COND_REGEX: i32 = 17;
1607pub const COND_MOD: i32 = 18;
1609pub const COND_MODI: i32 = 19;
1611pub const CONDF_INFIX: i32 = 1; pub const CONDF_ADDED: i32 = 2; pub const CONDF_AUTOALL: i32 = 4; pub const REDIRF_FROM_HEREDOC: i32 = 1; #[allow(non_camel_case_types)]
1625#[derive(Clone)]
1626pub struct redir {
1627 pub typ: i32,
1630 pub flags: i32,
1632 pub fd1: i32,
1634 pub fd2: i32,
1636 pub name: Option<String>,
1638 pub varid: Option<String>,
1640 pub here_terminator: Option<String>,
1642 pub munged_here_terminator: Option<String>,
1644}
1645pub const MULTIOUNIT: usize = 8; #[allow(non_camel_case_types)]
1649pub struct multio {
1650 pub ct: i32,
1653 pub rflag: i32,
1655 pub pipe: i32,
1657 pub fds: Vec<i32>,
1662}
1663
1664#[allow(non_camel_case_types)]
1669pub struct value {
1670 pub pm: Option<Param>,
1673 pub arr: Vec<String>,
1675 pub scanflags: i32,
1677 pub valflags: i32,
1679 pub start: i32,
1681 pub end: i32,
1683}
1684pub const VALFLAG_INV: i32 = 0x0001; pub const VALFLAG_EMPTY: i32 = 0x0002;
1688pub const VALFLAG_SUBST: i32 = 0x0004;
1690pub const VALFLAG_REFSLICE: i32 = 0x0008;
1692pub const MAX_ARRLEN: i32 = 262144; #[allow(non_camel_case_types)]
1700pub type wordcode = u32; pub type Wordcode = Vec<wordcode>; pub type FuncDump = Box<funcdump>; pub type Eprog = Box<eprog>; pub const EF_REAL: i32 = 1; pub const EF_HEAP: i32 = 2;
1711pub const EF_MAP: i32 = 4;
1713pub const EF_RUN: i32 = 8;
1715pub type Estate = Box<estate>; pub type Eccstr = Box<eccstr>; pub const EC_NODUP: i32 = 0; pub const EC_DUP: i32 = 1; pub const EC_DUPTOK: i32 = 2; pub const WC_CODEBITS: u32 = 5; #[inline]
1729#[allow(non_snake_case)]
1730pub fn wc_code(c: wordcode) -> wordcode {
1731 c & ((1 << WC_CODEBITS) - 1)
1732}
1733#[inline]
1735#[allow(non_snake_case)]
1736pub fn wc_data(c: wordcode) -> wordcode {
1737 c >> WC_CODEBITS
1738}
1739#[inline]
1741#[allow(non_snake_case)]
1742pub fn wc_bdata(d: wordcode) -> wordcode {
1743 d << WC_CODEBITS
1744}
1745#[inline]
1747#[allow(non_snake_case)]
1748pub fn wc_bld(c: wordcode, d: wordcode) -> wordcode {
1749 c | (d << WC_CODEBITS)
1750}
1751pub const WC_END: wordcode = 0;
1753pub const WC_LIST: wordcode = 1;
1755pub const WC_SUBLIST: wordcode = 2;
1757pub const WC_PIPE: wordcode = 3;
1759pub const WC_REDIR: wordcode = 4;
1761pub const WC_ASSIGN: wordcode = 5;
1763pub const WC_SIMPLE: wordcode = 6;
1765pub const WC_TYPESET: wordcode = 7;
1767pub const WC_SUBSH: wordcode = 8;
1769pub const WC_CURSH: wordcode = 9;
1771pub const WC_TIMED: wordcode = 10;
1773pub const WC_FUNCDEF: wordcode = 11;
1775pub const WC_FOR: wordcode = 12;
1777pub const WC_SELECT: wordcode = 13;
1779pub const WC_WHILE: wordcode = 14;
1781pub const WC_REPEAT: wordcode = 15;
1783pub const WC_CASE: wordcode = 16;
1785pub const WC_IF: wordcode = 17;
1787pub const WC_COND: wordcode = 18;
1789pub const WC_ARITH: wordcode = 19;
1791pub const WC_AUTOFN: wordcode = 20;
1793pub const WC_TRY: wordcode = 21;
1795pub const WC_COUNT: wordcode = 22;
1797pub const Z_END: i32 = 1 << 4; pub const Z_SIMPLE: i32 = 1 << 5; pub const WC_LIST_FREE: u32 = 6; pub const WC_SUBLIST_END: wordcode = 0;
1805pub const WC_SUBLIST_AND: wordcode = 1;
1807pub const WC_SUBLIST_OR: wordcode = 2;
1809pub const WC_SUBLIST_COPROC: wordcode = 4;
1811pub const WC_SUBLIST_NOT: wordcode = 8;
1813pub const WC_SUBLIST_SIMPLE: wordcode = 16;
1815pub const WC_SUBLIST_FREE: u32 = 5; pub const WC_PIPE_END: wordcode = 0;
1819pub const WC_PIPE_MID: wordcode = 1;
1821pub const WC_ASSIGN_SCALAR: wordcode = 0;
1823pub const WC_ASSIGN_ARRAY: wordcode = 1;
1825pub const WC_ASSIGN_NEW: wordcode = 0;
1827pub const WC_ASSIGN_INC: wordcode = 1;
1829pub const WC_TIMED_EMPTY: wordcode = 0;
1831pub const WC_TIMED_PIPE: wordcode = 1;
1833pub const WC_FOR_PPARAM: wordcode = 0;
1835pub const WC_FOR_LIST: wordcode = 1;
1837pub const WC_FOR_COND: wordcode = 2;
1839pub const WC_SELECT_PPARAM: wordcode = 0;
1841pub const WC_SELECT_LIST: wordcode = 1;
1843pub const WC_WHILE_WHILE: wordcode = 0;
1845pub const WC_WHILE_UNTIL: wordcode = 1;
1847pub const WC_CASE_HEAD: wordcode = 0;
1849pub const WC_CASE_OR: wordcode = 1;
1851pub const WC_CASE_AND: wordcode = 2;
1853pub const WC_CASE_TESTAND: wordcode = 3;
1855pub const WC_CASE_FREE: u32 = 3; pub const WC_IF_HEAD: wordcode = 0;
1859pub const WC_IF_IF: wordcode = 1;
1861pub const WC_IF_ELIF: wordcode = 2;
1863pub const WC_IF_ELSE: wordcode = 3;
1865
1866#[inline]
1873#[allow(non_snake_case)]
1874pub fn WCB_END() -> wordcode {
1875 wc_bld(WC_END, 0)
1876} #[inline]
1879#[allow(non_snake_case)]
1880pub fn WC_LIST_TYPE(c: wordcode) -> wordcode {
1881 wc_data(c)
1882} #[inline]
1885#[allow(non_snake_case)]
1886pub fn WC_LIST_SKIP(c: wordcode) -> wordcode {
1887 wc_data(c) >> WC_LIST_FREE
1888} #[inline]
1891#[allow(non_snake_case)]
1892pub fn WCB_LIST(t: wordcode, o: wordcode) -> wordcode {
1893 wc_bld(WC_LIST, t | (o << WC_LIST_FREE))
1894}
1895#[inline]
1897#[allow(non_snake_case)]
1898pub fn WC_SUBLIST_TYPE(c: wordcode) -> wordcode {
1899 wc_data(c) & 3
1900} #[inline]
1903#[allow(non_snake_case)]
1904pub fn WC_SUBLIST_FLAGS(c: wordcode) -> wordcode {
1905 wc_data(c) & 0x1c
1906} #[inline]
1909#[allow(non_snake_case)]
1910pub fn WC_SUBLIST_SKIP(c: wordcode) -> wordcode {
1911 wc_data(c) >> WC_SUBLIST_FREE
1912}
1913#[inline]
1915#[allow(non_snake_case)]
1916pub fn WCB_SUBLIST(t: wordcode, f: wordcode, o: wordcode) -> wordcode {
1917 wc_bld(WC_SUBLIST, t | f | (o << WC_SUBLIST_FREE))
1918}
1919#[inline]
1921#[allow(non_snake_case)]
1922pub fn WC_PIPE_TYPE(c: wordcode) -> wordcode {
1923 wc_data(c) & 1
1924} #[inline]
1927#[allow(non_snake_case)]
1928pub fn WC_PIPE_LINENO(c: wordcode) -> wordcode {
1929 wc_data(c) >> 1
1930}
1931#[inline]
1933#[allow(non_snake_case)]
1934pub fn WCB_PIPE(t: wordcode, l: wordcode) -> wordcode {
1935 wc_bld(WC_PIPE, t | (l << 1))
1936}
1937#[inline]
1939#[allow(non_snake_case)]
1940pub fn WC_REDIR_TYPE(c: wordcode) -> i32 {
1941 (wc_data(c) & REDIR_TYPE_MASK as u32) as i32
1942}
1943#[inline]
1945#[allow(non_snake_case)]
1946pub fn WC_REDIR_VARID(c: wordcode) -> i32 {
1947 (wc_data(c) & REDIR_VARID_MASK as u32) as i32
1948}
1949#[inline]
1951#[allow(non_snake_case)]
1952pub fn WC_REDIR_FROM_HEREDOC(c: wordcode) -> i32 {
1953 (wc_data(c) & REDIR_FROM_HEREDOC_MASK as u32) as i32
1954}
1955#[inline]
1957#[allow(non_snake_case)]
1958pub fn WCB_REDIR(t: wordcode) -> wordcode {
1959 wc_bld(WC_REDIR, t)
1960}
1961#[inline]
1963#[allow(non_snake_case)]
1964pub fn WC_REDIR_WORDS(c: wordcode) -> i32 {
1965 (if WC_REDIR_VARID(c) != 0 { 4 } else { 3 })
1966 + (if WC_REDIR_FROM_HEREDOC(c) != 0 { 2 } else { 0 })
1967}
1968#[inline]
1970#[allow(non_snake_case)]
1971pub fn WC_ASSIGN_TYPE(c: wordcode) -> wordcode {
1972 wc_data(c) & 1
1973} #[inline]
1976#[allow(non_snake_case)]
1977pub fn WC_ASSIGN_TYPE2(c: wordcode) -> wordcode {
1978 (wc_data(c) & 2) >> 1
1979}
1980#[inline]
1982#[allow(non_snake_case)]
1983pub fn WC_ASSIGN_NUM(c: wordcode) -> wordcode {
1984 wc_data(c) >> 2
1985}
1986#[inline]
1988#[allow(non_snake_case)]
1989pub fn WCB_ASSIGN(t: wordcode, a: wordcode, n: wordcode) -> wordcode {
1990 wc_bld(WC_ASSIGN, t | (a << 1) | (n << 2))
1991}
1992#[inline]
1994#[allow(non_snake_case)]
1995pub fn WC_SIMPLE_ARGC(c: wordcode) -> wordcode {
1996 wc_data(c)
1997} #[inline]
2000#[allow(non_snake_case)]
2001pub fn WCB_SIMPLE(n: wordcode) -> wordcode {
2002 wc_bld(WC_SIMPLE, n)
2003}
2004#[inline]
2006#[allow(non_snake_case)]
2007pub fn WC_TYPESET_ARGC(c: wordcode) -> wordcode {
2008 wc_data(c)
2009} #[inline]
2012#[allow(non_snake_case)]
2013pub fn WCB_TYPESET(n: wordcode) -> wordcode {
2014 wc_bld(WC_TYPESET, n)
2015}
2016#[inline]
2018#[allow(non_snake_case)]
2019pub fn WC_SUBSH_SKIP(c: wordcode) -> wordcode {
2020 wc_data(c)
2021} #[inline]
2024#[allow(non_snake_case)]
2025pub fn WCB_SUBSH(o: wordcode) -> wordcode {
2026 wc_bld(WC_SUBSH, o)
2027}
2028#[inline]
2030#[allow(non_snake_case)]
2031pub fn WC_CURSH_SKIP(c: wordcode) -> wordcode {
2032 wc_data(c)
2033} #[inline]
2036#[allow(non_snake_case)]
2037pub fn WCB_CURSH(o: wordcode) -> wordcode {
2038 wc_bld(WC_CURSH, o)
2039}
2040#[inline]
2042#[allow(non_snake_case)]
2043pub fn WC_TIMED_TYPE(c: wordcode) -> wordcode {
2044 wc_data(c)
2045} #[inline]
2048#[allow(non_snake_case)]
2049pub fn WCB_TIMED(t: wordcode) -> wordcode {
2050 wc_bld(WC_TIMED, t)
2051}
2052#[inline]
2054#[allow(non_snake_case)]
2055pub fn WC_FUNCDEF_SKIP(c: wordcode) -> wordcode {
2056 wc_data(c)
2057} #[inline]
2060#[allow(non_snake_case)]
2061pub fn WCB_FUNCDEF(o: wordcode) -> wordcode {
2062 wc_bld(WC_FUNCDEF, o)
2063}
2064#[inline]
2066#[allow(non_snake_case)]
2067pub fn WC_FOR_TYPE(c: wordcode) -> wordcode {
2068 wc_data(c) & 3
2069} #[inline]
2072#[allow(non_snake_case)]
2073pub fn WC_FOR_SKIP(c: wordcode) -> wordcode {
2074 wc_data(c) >> 2
2075}
2076#[inline]
2078#[allow(non_snake_case)]
2079pub fn WCB_FOR(t: wordcode, o: wordcode) -> wordcode {
2080 wc_bld(WC_FOR, t | (o << 2))
2081}
2082#[inline]
2084#[allow(non_snake_case)]
2085pub fn WC_SELECT_TYPE(c: wordcode) -> wordcode {
2086 wc_data(c) & 1
2087} #[inline]
2090#[allow(non_snake_case)]
2091pub fn WC_SELECT_SKIP(c: wordcode) -> wordcode {
2092 wc_data(c) >> 1
2093}
2094#[inline]
2096#[allow(non_snake_case)]
2097pub fn WCB_SELECT(t: wordcode, o: wordcode) -> wordcode {
2098 wc_bld(WC_SELECT, t | (o << 1))
2099}
2100#[inline]
2102#[allow(non_snake_case)]
2103pub fn WC_WHILE_TYPE(c: wordcode) -> wordcode {
2104 wc_data(c) & 1
2105} #[inline]
2108#[allow(non_snake_case)]
2109pub fn WC_WHILE_SKIP(c: wordcode) -> wordcode {
2110 wc_data(c) >> 1
2111}
2112#[inline]
2114#[allow(non_snake_case)]
2115pub fn WCB_WHILE(t: wordcode, o: wordcode) -> wordcode {
2116 wc_bld(WC_WHILE, t | (o << 1))
2117}
2118#[inline]
2120#[allow(non_snake_case)]
2121pub fn WC_REPEAT_SKIP(c: wordcode) -> wordcode {
2122 wc_data(c)
2123} #[inline]
2126#[allow(non_snake_case)]
2127pub fn WCB_REPEAT(o: wordcode) -> wordcode {
2128 wc_bld(WC_REPEAT, o)
2129}
2130#[inline]
2132#[allow(non_snake_case)]
2133pub fn WC_TRY_SKIP(c: wordcode) -> wordcode {
2134 wc_data(c)
2135} #[inline]
2138#[allow(non_snake_case)]
2139pub fn WCB_TRY(o: wordcode) -> wordcode {
2140 wc_bld(WC_TRY, o)
2141}
2142#[inline]
2144#[allow(non_snake_case)]
2145pub fn WC_CASE_TYPE(c: wordcode) -> wordcode {
2146 wc_data(c) & 7
2147} #[inline]
2150#[allow(non_snake_case)]
2151pub fn WC_CASE_SKIP(c: wordcode) -> wordcode {
2152 wc_data(c) >> WC_CASE_FREE
2153}
2154#[inline]
2156#[allow(non_snake_case)]
2157pub fn WCB_CASE(t: wordcode, o: wordcode) -> wordcode {
2158 wc_bld(WC_CASE, t | (o << WC_CASE_FREE))
2159}
2160#[inline]
2162#[allow(non_snake_case)]
2163pub fn WC_IF_TYPE(c: wordcode) -> wordcode {
2164 wc_data(c) & 3
2165} #[inline]
2168#[allow(non_snake_case)]
2169pub fn WC_IF_SKIP(c: wordcode) -> wordcode {
2170 wc_data(c) >> 2
2171}
2172#[inline]
2174#[allow(non_snake_case)]
2175pub fn WCB_IF(t: wordcode, o: wordcode) -> wordcode {
2176 wc_bld(WC_IF, t | (o << 2))
2177}
2178#[inline]
2180#[allow(non_snake_case)]
2181pub fn WC_COND_TYPE(c: wordcode) -> wordcode {
2182 wc_data(c) & 127
2183} #[inline]
2186#[allow(non_snake_case)]
2187pub fn WC_COND_SKIP(c: wordcode) -> wordcode {
2188 wc_data(c) >> 7
2189}
2190#[inline]
2192#[allow(non_snake_case)]
2193pub fn WCB_COND(t: wordcode, o: wordcode) -> wordcode {
2194 wc_bld(WC_COND, t | (o << 7))
2195}
2196#[inline]
2198#[allow(non_snake_case)]
2199pub fn WCB_ARITH() -> wordcode {
2200 wc_bld(WC_ARITH, 0)
2201} #[inline]
2204#[allow(non_snake_case)]
2205pub fn WCB_AUTOFN() -> wordcode {
2206 wc_bld(WC_AUTOFN, 0)
2207} pub const NULLBINCMD: Option<HandlerFunc> = None; #[inline]
2220#[allow(non_snake_case)]
2221pub fn EMULATION(x: i32) -> bool {
2222 let emul = crate::ported::options::emulation.load(std::sync::atomic::Ordering::Relaxed);
2224 (emul & x) != 0
2225}
2226
2227#[inline]
2231#[allow(non_snake_case)]
2232pub fn SHELL_EMULATION() -> i32 {
2233 let emul = crate::ported::options::emulation.load(std::sync::atomic::Ordering::Relaxed);
2235 emul & ((1 << 5) - 1)
2236}
2237
2238#[inline]
2245#[allow(non_snake_case)]
2246pub fn IN_EVAL_TRAP() -> bool {
2247 crate::ported::signals::intrap.load(Ordering::Relaxed) != 0
2249 && crate::ported::signals::trapisfunc.load(Ordering::Relaxed) == 0
2250 && crate::ported::signals::traplocallevel.load(Ordering::Relaxed)
2251 == crate::ported::params::locallevel.load(Ordering::Relaxed)
2252}
2253
2254#[inline]
2256#[allow(non_snake_case)]
2257pub fn ASG_ARRAYP(asg: &asgment) -> bool {
2258 (asg.flags & ASG_ARRAY) != 0
2259}
2260
2261#[inline]
2263#[allow(non_snake_case)]
2264pub fn ASG_VALUEP(asg: &asgment) -> bool {
2265 ASG_ARRAYP(asg) || asg.scalar.is_some()
2266}
2267
2268#[inline]
2273#[allow(non_snake_case)]
2274pub fn MB_METASTRLEN2END(s: &str, widthp: bool, eptr: usize) -> usize {
2275 let truncated = if eptr <= s.len() { &s[..eptr] } else { s };
2276 MB_METASTRLEN2(truncated, widthp)
2277}
2278
2279pub const EXITHOOK_OFFSET: usize = 0; pub const BEFORETRAPHOOK_OFFSET: usize = 1; pub const AFTERTRAPHOOK_OFFSET: usize = 2; pub const GETCOLORATTR_OFFSET: usize = 3; pub const STOPHIST_DELTA: i32 = 4; pub const ALLOWHIST_DELTA: i32 = -4; pub const STOPHIST: i32 = STOPHIST_DELTA;
2302pub const ALLOWHIST: i32 = ALLOWHIST_DELTA;
2304
2305pub const EXITHOOK: usize = EXITHOOK_OFFSET;
2308pub const BEFORETRAPHOOK: usize = BEFORETRAPHOOK_OFFSET;
2310pub const AFTERTRAPHOOK: usize = AFTERTRAPHOOK_OFFSET;
2312pub const GETCOLORATTR: usize = GETCOLORATTR_OFFSET;
2314
2315#[inline]
2320#[allow(non_snake_case)]
2321pub const fn ZLONG_CONST(x: i64) -> zlong {
2322 x
2323} #[macro_export]
2329macro_rules! STRINGIFY_LITERAL {
2330 ($x:tt) => {
2331 stringify!($x)
2332 };
2333}
2334
2335#[macro_export]
2338macro_rules! STRINGIFY {
2339 ($x:tt) => {
2340 $crate::STRINGIFY_LITERAL!($x)
2341 };
2342}
2343
2344#[macro_export]
2347macro_rules! ERRMSG {
2348 ($msg:expr) => {
2349 concat!(file!(), ":", line!(), ": ", $msg)
2350 };
2351}
2352
2353pub const HEAPID_FMT: &str = "{:x}"; #[macro_export]
2362macro_rules! HEAP_ERROR {
2363 ($heap_id:expr) => {
2364 eprintln!(
2365 "{}:{}: HEAP DEBUG: invalid heap: {:x}.",
2366 file!(),
2367 line!(),
2368 $heap_id
2369 )
2370 };
2371}
2372
2373#[macro_export]
2390macro_rules! DPUTS {
2391 ($x:expr, $y:expr) => {
2393 #[cfg(feature = "zsh-debug")] {
2396 if $x {
2397 crate::ported::utils::dputs(&format!(
2399 "{}:{}: {}",
2401 file!(),
2402 line!(),
2403 $y )); } } }; } #[macro_export]
2422macro_rules! DPUTS1 {
2423 ($x:expr, $y:expr, $z1:expr) => {
2425 #[cfg(feature = "zsh-debug")] {
2428 if $x {
2429 crate::ported::utils::dputs(&format!(
2431 "{}:{}: {}",
2433 file!(),
2434 line!(),
2435 format!($y, $z1) )); } } }; } #[macro_export]
2447macro_rules! DPUTS2 {
2448 ($x:expr, $y:expr, $z1:expr, $z2:expr) => {
2450 #[cfg(feature = "zsh-debug")] {
2453 if $x {
2454 crate::ported::utils::dputs(&format!(
2456 "{}:{}: {}",
2458 file!(),
2459 line!(),
2460 format!($y, $z1, $z2) )); } } }; } #[macro_export]
2472macro_rules! DPUTS3 {
2473 ($x:expr, $y:expr, $z1:expr, $z2:expr, $z3:expr) => {
2475 #[cfg(feature = "zsh-debug")] {
2478 if $x {
2479 crate::ported::utils::dputs(&format!(
2481 "{}:{}: {}",
2483 file!(),
2484 line!(),
2485 format!($y, $z1, $z2, $z3) )); } } }; } pub const SGTTYFLAG_NAME: &str = "tio.c_oflag";
2497
2498pub const SGTTYFLAG: &str = SGTTYFLAG_NAME;
2501
2502#[cfg(target_os = "linux")]
2506pub const SGTABTYPE: u32 = libc::XTABS;
2507#[cfg(not(target_os = "linux"))]
2509pub const SGTABTYPE: u32 = 0;
2510
2511#[inline]
2514#[allow(non_snake_case)]
2515pub fn ZWS(s: &str) -> &str {
2516 s
2517}
2518
2519#[inline]
2531#[allow(non_snake_case)]
2532pub fn BUILTIN(
2533 name: &str,
2534 flags: i32,
2535 handler: Option<HandlerFunc>,
2536 min: i32,
2537 max: i32,
2538 funcid: i32,
2539 optstr: Option<&str>,
2540 defopts: Option<&str>,
2541) -> builtin {
2542 builtin {
2543 node: hashnode {
2544 next: None,
2545 nam: name.to_string(),
2546 flags,
2547 },
2548 handlerfunc: handler,
2549 minargs: min,
2550 maxargs: max,
2551 funcid,
2552 optstr: optstr.map(|s| s.to_string()),
2553 defopts: defopts.map(|s| s.to_string()),
2554 }
2555}
2556
2557#[inline]
2560#[allow(non_snake_case)]
2561pub fn BIN_PREFIX(name: &str, flags: i32) -> builtin {
2562 BUILTIN(
2563 name,
2564 flags | BINF_PREFIX as i32,
2565 NULLBINCMD,
2566 0,
2567 0,
2568 0,
2569 None,
2570 None,
2571 )
2572}
2573
2574#[inline]
2577#[allow(non_snake_case)]
2578pub fn CONDDEF(
2579 name: &str,
2580 flags: i32,
2581 handler: CondHandler,
2582 min: i32,
2583 max: i32,
2584 condid: i32,
2585) -> conddef {
2586 conddef {
2587 next: None,
2588 name: name.to_string(),
2589 flags,
2590 handler: Some(handler),
2591 min,
2592 max,
2593 condid,
2594 module: None,
2595 }
2596}
2597
2598#[inline]
2602#[allow(non_snake_case)]
2603pub fn HOOKDEF(name: &str, func: Option<Hookfn>, flags: i32) -> hookdef {
2604 hookdef {
2605 next: std::ptr::null_mut(),
2606 name: name.to_string(),
2607 def: func,
2608 flags,
2609 funcs: std::ptr::null_mut(),
2610 }
2611}
2612
2613#[inline]
2615#[allow(non_snake_case)]
2616pub fn NUMMATHFUNC(name: &str, func: NumMathFunc, min: i32, max: i32, id: i32) -> mathfunc {
2617 mathfunc {
2618 next: None,
2619 name: name.to_string(),
2620 flags: 0,
2621 nfunc: Some(func),
2622 sfunc: None,
2623 module: None,
2624 minargs: min,
2625 maxargs: max,
2626 funcid: id,
2627 }
2628}
2629
2630#[inline]
2632#[allow(non_snake_case)]
2633pub fn STRMATHFUNC(name: &str, func: StrMathFunc, id: i32) -> mathfunc {
2634 mathfunc {
2635 next: None,
2636 name: name.to_string(),
2637 flags: MFF_STR,
2638 nfunc: None,
2639 sfunc: Some(func),
2640 module: None,
2641 minargs: 0,
2642 maxargs: 0,
2643 funcid: id,
2644 }
2645}
2646
2647#[inline]
2649#[allow(non_snake_case)]
2650pub fn PARAMDEF(name: &str, flags: i32, var: usize, gsu: usize) -> paramdef {
2651 paramdef {
2652 name: name.to_string(),
2653 flags,
2654 var,
2655 gsu,
2656 getnfn: None,
2657 scantfn: None,
2658 pm: None,
2659 }
2660}
2661
2662#[inline]
2664#[allow(non_snake_case)]
2665pub fn INTPARAMDEF(name: &str, var: usize) -> paramdef {
2666 PARAMDEF(name, PM_INTEGER as i32, var, 0)
2667}
2668
2669#[inline]
2671#[allow(non_snake_case)]
2672pub fn STRPARAMDEF(name: &str, var: usize) -> paramdef {
2673 PARAMDEF(name, PM_SCALAR as i32, var, 0)
2674}
2675
2676#[inline]
2678#[allow(non_snake_case)]
2679pub fn ARRPARAMDEF(name: &str, var: usize) -> paramdef {
2680 PARAMDEF(name, PM_ARRAY as i32, var, 0)
2681}
2682
2683#[inline]
2686#[allow(non_snake_case)]
2687pub fn SPECIALPMDEF(
2688 name: &str,
2689 flags: i32,
2690 gsufn: usize,
2691 getfn: Option<GetNodeFunc>,
2692 scanfn: Option<ScanTabFunc>,
2693) -> paramdef {
2694 paramdef {
2695 name: name.to_string(),
2696 flags: flags | (PM_SPECIAL | PM_HIDE | PM_HIDEVAL) as i32,
2697 var: 0,
2698 gsu: gsufn,
2699 getnfn: getfn,
2700 scantfn: scanfn,
2701 pm: None,
2702 }
2703}
2704#[inline]
2706#[allow(non_snake_case)]
2707pub fn WRAPDEF(func: WrapFunc) -> funcwrap {
2708 funcwrap {
2709 next: None,
2710 flags: 0,
2711 handler: Some(func),
2712 module: None,
2713 }
2714}
2715
2716#[allow(non_camel_case_types)]
2726#[derive(Debug, Clone)]
2727pub struct jobfile {
2728 pub name: Option<String>,
2731 pub fd: i32,
2733 pub is_fd: i32,
2735}
2736pub const STAT_CHANGED: i32 = 0x0001; pub const STAT_STOPPED: i32 = 0x0002;
2740pub const STAT_TIMED: i32 = 0x0004;
2742pub const STAT_DONE: i32 = 0x0008;
2744pub const STAT_LOCKED: i32 = 0x0010;
2746pub const STAT_NOPRINT: i32 = 0x0020;
2748pub const STAT_INUSE: i32 = 0x0040;
2750pub const STAT_SUPERJOB: i32 = 0x0080;
2752pub const STAT_SUBJOB: i32 = 0x0100;
2754pub const STAT_WASSUPER: i32 = 0x0200;
2756pub const STAT_CURSH: i32 = 0x0400;
2758pub const STAT_NOSTTY: i32 = 0x0800;
2760pub const STAT_ATTACH: i32 = 0x1000;
2762pub const STAT_SUBLEADER: i32 = 0x2000;
2764pub const STAT_BUILTIN: i32 = 0x4000;
2766pub const STAT_SUBJOB_ORPHANED: i32 = 0x8000;
2768pub const STAT_DISOWN: i32 = 0x10000; pub const SP_RUNNING: i32 = -1; pub const JOBTEXTSIZE: usize = 80; pub const MAXJOBS_ALLOC: usize = 50; pub const MAX_PIPESTATS: usize = 256; #[allow(non_camel_case_types)]
2785#[derive(Debug, Clone, Default)]
2786pub struct timeinfo {
2787 pub ut: i64,
2793 pub st: i64,
2795 pub maxrss: i64,
2797 pub majflt: i64,
2799 pub minflt: i64,
2801 pub nswap: i64,
2803 pub ixrss: i64,
2805 pub idrss: i64,
2807 pub isrss: i64,
2809 pub inblock: i64,
2811 pub oublock: i64,
2813 pub nvcsw: i64,
2815 pub nivcsw: i64,
2817 pub msgsnd: i64,
2819 pub msgrcv: i64,
2821 pub nsignals: i64,
2823}
2824
2825impl timeinfo {
2826 pub fn user_dur(&self) -> std::time::Duration {
2828 std::time::Duration::from_micros(self.ut as u64)
2829 }
2830 pub fn sys_dur(&self) -> std::time::Duration {
2832 std::time::Duration::from_micros(self.st as u64)
2833 }
2834
2835 #[cfg(unix)]
2839 pub fn from_rusage(r: &libc::rusage) -> Self {
2840 let ut = r.ru_utime.tv_sec as i64 * 1_000_000 + r.ru_utime.tv_usec as i64;
2841 let st = r.ru_stime.tv_sec as i64 * 1_000_000 + r.ru_stime.tv_usec as i64;
2842 #[cfg(target_os = "macos")]
2843 let maxrss = r.ru_maxrss / 1024;
2844 #[cfg(not(target_os = "macos"))]
2845 let maxrss = r.ru_maxrss as i64;
2846 Self {
2847 ut,
2848 st,
2849 maxrss: maxrss as i64,
2850 majflt: r.ru_majflt as i64,
2851 minflt: r.ru_minflt as i64,
2852 nswap: r.ru_nswap as i64,
2853 ixrss: r.ru_ixrss as i64,
2854 idrss: r.ru_idrss as i64,
2855 isrss: r.ru_isrss as i64,
2856 inblock: r.ru_inblock as i64,
2857 oublock: r.ru_oublock as i64,
2858 nvcsw: r.ru_nvcsw as i64,
2859 nivcsw: r.ru_nivcsw as i64,
2860 msgsnd: r.ru_msgsnd as i64,
2861 msgrcv: r.ru_msgrcv as i64,
2862 nsignals: r.ru_nsignals as i64,
2863 }
2864 }
2865}
2866
2867pub const DISABLED: i32 = 1 << 0; pub const HASHED: i32 = 1 << 1; pub const ALIAS_GLOBAL: i32 = 1 << 1; pub const ALIAS_SUFFIX: i32 = 1 << 2; pub const ASG_ARRAY: i32 = 1; pub const ASG_KEY_VALUE: i32 = 2; pub const SFC_NONE: i32 = 0; pub const SFC_DIRECT: i32 = 1;
2890pub const SFC_SIGNAL: i32 = 2;
2892pub const SFC_HOOK: i32 = 3;
2894pub const SFC_WIDGET: i32 = 4;
2896pub const SFC_COMPLETE: i32 = 5;
2898pub const SFC_CWIDGET: i32 = 6;
2900pub const SFC_SUBST: i32 = 7;
2902pub const FS_SOURCE: i32 = 0; pub const FS_FUNC: i32 = 1;
2906pub const FS_EVAL: i32 = 2;
2908pub const WRAPF_ADDED: i32 = 1; pub const HOOK_SUFFIX: &str = "_functions"; pub const HOOK_SUFFIX_LEN: usize = 11; pub const MAX_OPS: usize = 128; #[allow(non_camel_case_types)]
2922#[derive(Clone)]
2923pub struct options {
2924 pub ind: [u8; MAX_OPS],
2926 pub args: Vec<String>,
2928 pub argscount: i32,
2930 pub argsalloc: i32,
2932}
2933pub const PARSEARGS_TOPLEVEL: i32 = 0x1; pub const PARSEARGS_LOGIN: i32 = 0x2; #[inline]
2947#[allow(non_snake_case)]
2948pub fn OPT_MINUS(ops: &options, c: u8) -> bool {
2949 (ops.ind[c as usize] & 1) != 0
2950}
2951
2952#[inline]
2955#[allow(non_snake_case)]
2956pub fn OPT_PLUS(ops: &options, c: u8) -> bool {
2957 (ops.ind[c as usize] & 2) != 0
2958}
2959
2960#[inline]
2963#[allow(non_snake_case)]
2964pub fn OPT_ISSET(ops: &options, c: u8) -> bool {
2965 ops.ind[c as usize] != 0
2966}
2967
2968#[inline]
2971#[allow(non_snake_case)]
2972pub fn OPT_HASARG(ops: &options, c: u8) -> bool {
2973 ops.ind[c as usize] > 3
2974}
2975
2976pub type HandlerFunc = fn(name: &str, args: &[String], ops: &options, funcid: i32) -> i32;
2981pub const BINF_PLUSOPTS: u32 = 1 << 1; pub const BINF_PRINTOPTS: u32 = 1 << 2; pub const BINF_ADDED: u32 = 1 << 3; pub const BINF_MAGICEQUALS: u32 = 1 << 4; pub const BINF_PREFIX: u32 = 1 << 5; pub const BINF_DASH: u32 = 1 << 6; pub const BINF_BUILTIN: u32 = 1 << 7; pub const BINF_COMMAND: u32 = 1 << 8; pub const BINF_EXEC: u32 = 1 << 9; pub const BINF_NOGLOB: u32 = 1 << 10; pub const BINF_PSPECIAL: u32 = 1 << 11; pub const BINF_SKIPINVALID: u32 = 1 << 12; pub const BINF_KEEPNUM: u32 = 1 << 13; pub const BINF_SKIPDASH: u32 = 1 << 14; pub const BINF_DASHDASHVALID: u32 = 1 << 15; pub const BINF_CLEARENV: u32 = 1 << 16; pub const BINF_AUTOALL: u32 = 1 << 17; pub const BINF_HANDLES_OPTS: u32 = 1 << 18; pub const BINF_ASSIGN: u32 = 1 << 19; pub const MOD_BUSY: i32 = 1 << 0; pub const MOD_UNLOAD: i32 = 1 << 1; pub const MOD_SETUP: i32 = 1 << 2; pub const MOD_LINKED: i32 = 1 << 3; pub const MOD_INIT_S: i32 = 1 << 4; pub const MOD_INIT_B: i32 = 1 << 5; pub const MOD_ALIAS: i32 = 1 << 6; pub const HOOKF_ALL: i32 = 1; pub const PAT_HEAPDUP: i32 = 0x0000; pub const PAT_FILE: i32 = 0x0001;
3047pub const PAT_FILET: i32 = 0x0002;
3049pub const PAT_ANY: i32 = 0x0004;
3051pub const PAT_NOANCH: i32 = 0x0008;
3053pub const PAT_NOGLD: i32 = 0x0010;
3055pub const PAT_PURES: i32 = 0x0020;
3057pub const PAT_STATIC: i32 = 0x0040;
3059pub const PAT_SCAN: i32 = 0x0080;
3061pub const PAT_ZDUP: i32 = 0x0100;
3063pub const PAT_NOTSTART: i32 = 0x0200;
3065pub const PAT_NOTEND: i32 = 0x0400;
3067pub const PAT_HAS_EXCLUDP: i32 = 0x0800;
3069pub const PAT_LCMATCHUC: i32 = 0x1000;
3071
3072pub const ZPC_SLASH: i32 = 0;
3077pub const ZPC_NULL: i32 = 1;
3079pub const ZPC_BAR: i32 = 2;
3081pub const ZPC_OUTPAR: i32 = 3;
3083pub const ZPC_TILDE: i32 = 4;
3085pub const ZPC_SEG_COUNT: i32 = 5;
3087pub const ZPC_INPAR: i32 = ZPC_SEG_COUNT;
3089pub const ZPC_QUEST: i32 = ZPC_SEG_COUNT + 1;
3091pub const ZPC_STAR: i32 = ZPC_SEG_COUNT + 2;
3093pub const ZPC_INBRACK: i32 = ZPC_SEG_COUNT + 3;
3095pub const ZPC_INANG: i32 = ZPC_SEG_COUNT + 4;
3097pub const ZPC_HAT: i32 = ZPC_SEG_COUNT + 5;
3099pub const ZPC_HASH: i32 = ZPC_SEG_COUNT + 6;
3101pub const ZPC_BNULLKEEP: i32 = ZPC_SEG_COUNT + 7;
3103pub const ZPC_NO_KSH_GLOB: i32 = ZPC_SEG_COUNT + 8;
3105pub const ZPC_KSH_QUEST: i32 = ZPC_NO_KSH_GLOB;
3107pub const ZPC_KSH_STAR: i32 = ZPC_NO_KSH_GLOB + 1;
3109pub const ZPC_KSH_PLUS: i32 = ZPC_NO_KSH_GLOB + 2;
3111pub const ZPC_KSH_BANG: i32 = ZPC_NO_KSH_GLOB + 3;
3113pub const ZPC_KSH_BANG2: i32 = ZPC_NO_KSH_GLOB + 4;
3115pub const ZPC_KSH_AT: i32 = ZPC_NO_KSH_GLOB + 5;
3117pub const ZPC_COUNT: i32 = ZPC_NO_KSH_GLOB + 6;
3119
3120pub const PP_FIRST: i32 = 1;
3125pub const PP_ALPHA: i32 = 1;
3127pub const PP_ALNUM: i32 = 2;
3129pub const PP_ASCII: i32 = 3;
3131pub const PP_BLANK: i32 = 4;
3133pub const PP_CNTRL: i32 = 5;
3135pub const PP_DIGIT: i32 = 6;
3137pub const PP_GRAPH: i32 = 7;
3139pub const PP_LOWER: i32 = 8;
3141pub const PP_PRINT: i32 = 9;
3143pub const PP_PUNCT: i32 = 10;
3145pub const PP_SPACE: i32 = 11;
3147pub const PP_UPPER: i32 = 12;
3149pub const PP_XDIGIT: i32 = 13;
3151pub const PP_IDENT: i32 = 14;
3153pub const PP_IFS: i32 = 15;
3155pub const PP_IFSSPACE: i32 = 16;
3157pub const PP_WORD: i32 = 17;
3159pub const PP_INCOMPLETE: i32 = 18;
3161pub const PP_INVALID: i32 = 19;
3163pub const PP_LAST: i32 = 19;
3165pub const PP_UNKWN: i32 = 20;
3167pub const PP_RANGE: i32 = 21;
3169pub const GF_LCMATCHUC: i32 = 0x0100;
3171pub const GF_IGNCASE: i32 = 0x0200;
3173pub const GF_BACKREF: i32 = 0x0400;
3175pub const GF_MATCHREF: i32 = 0x0800;
3177pub const GF_MULTIBYTE: i32 = 0x1000;
3179pub const ZMB_VALID: i32 = 0;
3181pub const ZMB_INCOMPLETE: i32 = 1;
3183pub const ZMB_INVALID: i32 = 2;
3185
3186pub const PM_SCALAR: u32 = 0;
3191pub const PM_ARRAY: u32 = 1 << 0;
3193pub const PM_INTEGER: u32 = 1 << 1;
3195pub const PM_EFLOAT: u32 = 1 << 2;
3197pub const PM_FFLOAT: u32 = 1 << 3;
3199pub const PM_HASHED: u32 = 1 << 4;
3201pub const PM_LEFT: u32 = 1 << 5;
3203pub const PM_RIGHT_B: u32 = 1 << 6;
3205pub const PM_RIGHT_Z: u32 = 1 << 7;
3207pub const PM_LOWER: u32 = 1 << 8;
3209pub const PM_UPPER: u32 = 1 << 9;
3211pub const PM_UNDEFINED: u32 = 1 << 9;
3213pub const PM_READONLY: u32 = 1 << 10;
3215pub const PM_TAGGED: u32 = 1 << 11;
3217pub const PM_EXPORTED: u32 = 1 << 12;
3219pub const PM_ABSPATH_USED: u32 = 1 << 12;
3221pub const PM_UNIQUE: u32 = 1 << 13;
3223pub const PM_UNALIASED: u32 = 1 << 13;
3225pub const PM_HIDE: u32 = 1 << 14;
3227pub const PM_CUR_FPATH: u32 = 1 << 14;
3229pub const PM_HIDEVAL: u32 = 1 << 15;
3231pub const PM_WARNNESTED: u32 = 1 << 15;
3233pub const PM_TIED: u32 = 1 << 16;
3235pub const PM_TAGGED_LOCAL: u32 = 1 << 16;
3237pub const PM_DONTIMPORT_SUID: u32 = 1 << 17;
3239pub const PM_LOADDIR: u32 = 1 << 17;
3241pub const PM_SINGLE: u32 = 1 << 18;
3243pub const PM_ANONYMOUS: u32 = 1 << 18;
3245pub const PM_LOCAL: u32 = 1 << 19;
3247pub const PM_KSHSTORED: u32 = 1 << 19;
3249pub const PM_SPECIAL: u32 = 1 << 20;
3251pub const PM_ZSHSTORED: u32 = 1 << 20;
3253pub const PM_RO_BY_DESIGN: u32 = 1 << 21;
3255pub const PM_READONLY_SPECIAL: u32 = PM_SPECIAL | PM_READONLY | PM_RO_BY_DESIGN;
3257pub const PM_DONTIMPORT: u32 = 1 << 22;
3259pub const PM_DECLARED: u32 = 1 << 22;
3261pub const PM_RESTRICTED: u32 = 1 << 23;
3263pub const PM_UNSET: u32 = 1 << 24;
3265pub const PM_DEFAULTED: u32 = PM_DECLARED | PM_UNSET;
3267pub const PM_REMOVABLE: u32 = 1 << 25;
3269pub const PM_AUTOLOAD: u32 = 1 << 26;
3271pub const PM_NORESTORE: u32 = 1 << 27;
3273pub const PM_AUTOALL: u32 = 1 << 27;
3275pub const PM_HASHELEM: u32 = 1 << 28;
3277pub const PM_NAMEDDIR: u32 = 1 << 29;
3279pub const PM_NAMEREF: u32 = 1 << 30;
3281#[inline]
3283#[allow(non_snake_case)]
3284pub const fn PM_TYPE(x: u32) -> u32 {
3285 x & (PM_SCALAR | PM_INTEGER | PM_EFLOAT | PM_FFLOAT | PM_ARRAY | PM_HASHED | PM_NAMEREF)
3286}
3287pub const TYPESET_OPTSTR: &str = "aiEFALRZlurtxUhHT"; pub const TYPESET_OPTNUM: &str = "LRZiEF"; pub const SCANPM_WANTVALS: u32 = 1 << 0;
3297pub const SCANPM_WANTKEYS: u32 = 1 << 1;
3299pub const SCANPM_WANTINDEX: u32 = 1 << 2;
3301pub const SCANPM_MATCHKEY: u32 = 1 << 3;
3303pub const SCANPM_MATCHVAL: u32 = 1 << 4;
3305pub const SCANPM_MATCHMANY: u32 = 1 << 5;
3307pub const SCANPM_ASSIGNING: u32 = 1 << 6;
3309pub const SCANPM_KEYMATCH: u32 = 1 << 7;
3311pub const SCANPM_DQUOTED: u32 = 1 << 8;
3313pub const SCANPM_ARRONLY: u32 = 1 << 9;
3315pub const SCANPM_CHECKING: u32 = 1 << 10;
3317pub const SCANPM_NOEXEC: u32 = 1 << 11;
3319pub const SCANPM_NONAMESPC: u32 = 1 << 12;
3321pub const SCANPM_NONAMEREF: u32 = 1 << 13;
3323pub const SCANPM_ISVAR_AT: u32 = 1 << 14;
3325
3326pub const SUB_END: i32 = 0x0001;
3331pub const SUB_LONG: i32 = 0x0002;
3333pub const SUB_SUBSTR: i32 = 0x0004;
3335pub const SUB_MATCH: i32 = 0x0008;
3337pub const SUB_REST: i32 = 0x0010;
3339pub const SUB_BIND: i32 = 0x0020;
3341pub const SUB_EIND: i32 = 0x0040;
3343pub const SUB_LEN: i32 = 0x0080;
3345pub const SUB_ALL: i32 = 0x0100;
3347pub const SUB_GLOBAL: i32 = 0x0200;
3349pub const SUB_DOSUBST: i32 = 0x0400;
3351pub const SUB_RETFAIL: i32 = 0x0800;
3353pub const SUB_START: i32 = 0x1000;
3355pub const SUB_LIST: i32 = 0x2000;
3357pub const SUB_EGLOB: i32 = 0x4000;
3359
3360pub const ZSHTOK_SUBST: i32 = 0x0001;
3365pub const ZSHTOK_SHGLOB: i32 = 0x0002;
3367pub const PREFORK_TYPESET: i32 = 0x01;
3369pub const PREFORK_ASSIGN: i32 = 0x02;
3371pub const PREFORK_SINGLE: i32 = 0x04;
3373pub const PREFORK_SPLIT: i32 = 0x08;
3375pub const PREFORK_SHWORDSPLIT: i32 = 0x10;
3377pub const PREFORK_NOSHWORDSPLIT: i32 = 0x20;
3379pub const PREFORK_SUBEXP: i32 = 0x40;
3381pub const PREFORK_KEY_VALUE: i32 = 0x80;
3383pub const PREFORK_NO_UNTOK: i32 = 0x100;
3385pub const MULTSUB_WS_AT_START: i32 = 1;
3387pub const MULTSUB_WS_AT_END: i32 = 2;
3389pub const MULTSUB_PARAM_NAME: i32 = 4;
3391
3392pub const ASSPM_AUGMENT: i32 = 1 << 0;
3397pub const ASSPM_WARN_CREATE: i32 = 1 << 1;
3399pub const ASSPM_WARN_NESTED: i32 = 1 << 2;
3401pub const ASSPM_WARN: i32 = ASSPM_WARN_CREATE | ASSPM_WARN_NESTED;
3403pub const ASSPM_ENV_IMPORT: i32 = 1 << 3;
3405pub const ASSPM_KEY_VALUE: i32 = 1 << 4;
3407
3408pub const ND_USERNAME: i32 = 1 << 1; pub const ND_NOABBREV: i32 = 1 << 2; pub const PRINT_NAMEONLY: i32 = 1 << 0; pub const PRINT_TYPE: i32 = 1 << 1;
3419pub const PRINT_LIST: i32 = 1 << 2;
3421pub const PRINT_KV_PAIR: i32 = 1 << 3;
3423pub const PRINT_INCLUDEVALUE: i32 = 1 << 4;
3425pub const PRINT_TYPESET: i32 = 1 << 5;
3427pub const PRINT_LINE: i32 = 1 << 6;
3429pub const PRINT_POSIX_EXPORT: i32 = 1 << 7;
3431pub const PRINT_POSIX_READONLY: i32 = 1 << 8;
3433pub const PRINT_WITH_NAMESPACE: i32 = 1 << 9;
3435pub const PRINT_WHENCE_CSH: i32 = 1 << 7; pub const PRINT_WHENCE_VERBOSE: i32 = 1 << 8;
3439pub const PRINT_WHENCE_SIMPLE: i32 = 1 << 9;
3441pub const PRINT_WHENCE_FUNCDEF: i32 = 1 << 10;
3443pub const PRINT_WHENCE_WORD: i32 = 1 << 11;
3445pub const LOOP_OK: i32 = 0; pub const LOOP_EMPTY: i32 = 1;
3449pub const LOOP_ERROR: i32 = 2;
3451pub const SOURCE_OK: i32 = 0; pub const SOURCE_NOT_FOUND: i32 = 1;
3455pub const SOURCE_ERROR: i32 = 2;
3457pub const NOERREXIT_EXIT: i32 = 1; pub const NOERREXIT_RETURN: i32 = 2;
3461pub const NOERREXIT_SIGNAL: i32 = 8;
3463
3464pub const HIST_MAKEUNIQUE: u32 = 0x00000001; pub const HIST_OLD: u32 = 0x00000002;
3471pub const HIST_READ: u32 = 0x00000004;
3473pub const HIST_DUP: u32 = 0x00000008;
3475pub const HIST_FOREIGN: u32 = 0x00000010;
3477pub const HIST_TMPSTORE: u32 = 0x00000020;
3479pub const HIST_NOWRITE: u32 = 0x00000040;
3481pub const GETHIST_UPWARD: i32 = -1;
3483pub const GETHIST_DOWNWARD: i32 = 1;
3485pub const GETHIST_EXACT: i32 = 0;
3487pub const HISTFLAG_DONE: i32 = 1; pub const HISTFLAG_NOEXEC: i32 = 2;
3491pub const HISTFLAG_RECALL: i32 = 4;
3493pub const HISTFLAG_SETTY: i32 = 8;
3495pub const HFILE_APPEND: u32 = 0x0001;
3497pub const HFILE_SKIPOLD: u32 = 0x0002;
3499pub const HFILE_SKIPDUPS: u32 = 0x0004;
3501pub const HFILE_SKIPFOREIGN: u32 = 0x0008;
3503pub const HFILE_FAST: u32 = 0x0010;
3505pub const HFILE_NO_REWRITE: u32 = 0x0020;
3507pub const HFILE_USE_OPTIONS: u32 = 0x8000;
3509pub const LEXFLAGS_ACTIVE: i32 = 0x0001;
3511pub const LEXFLAGS_ZLE: i32 = 0x0002;
3513pub const LEXFLAGS_COMMENTS_KEEP: i32 = 0x0004;
3515pub const LEXFLAGS_COMMENTS_STRIP: i32 = 0x0008;
3517pub const LEXFLAGS_COMMENTS: i32 = LEXFLAGS_COMMENTS_KEEP | LEXFLAGS_COMMENTS_STRIP;
3519pub const LEXFLAGS_NEWLINE: i32 = 0x0010;
3521
3522pub const IN_NOTHING: i32 = 0;
3527pub const IN_CMD: i32 = 1;
3529pub const IN_MATH: i32 = 2;
3531pub const IN_COND: i32 = 3;
3533pub const IN_ENV: i32 = 4;
3535pub const IN_PAR: i32 = 5;
3537
3538pub const EMULATE_CSH: i32 = 1 << 1; pub const EMULATE_KSH: i32 = 1 << 2;
3545pub const EMULATE_SH: i32 = 1 << 3;
3547pub const EMULATE_ZSH: i32 = 1 << 4;
3549pub const EMULATE_FULLY: i32 = 1 << 5;
3551pub const EMULATE_UNUSED: i32 = 1 << 6;
3553
3554pub const OPT_INVALID: i32 = 0;
3559pub const ALIASESOPT: i32 = 1;
3561pub const ALIASFUNCDEF: i32 = 2;
3563pub const ALLEXPORT: i32 = 3;
3565pub const ALWAYSLASTPROMPT: i32 = 4;
3567pub const ALWAYSTOEND: i32 = 5;
3569pub const APPENDHISTORY: i32 = 6;
3571pub const AUTOCD: i32 = 7;
3573pub const AUTOCONTINUE: i32 = 8;
3575pub const AUTOLIST: i32 = 9;
3577pub const AUTOMENU: i32 = 10;
3579pub const AUTONAMEDIRS: i32 = 11;
3581pub const AUTOPARAMKEYS: i32 = 12;
3583pub const AUTOPARAMSLASH: i32 = 13;
3585pub const AUTOPUSHD: i32 = 14;
3587pub const AUTOREMOVESLASH: i32 = 15;
3589pub const AUTORESUME: i32 = 16;
3591pub const BADPATTERN: i32 = 17;
3593pub const BANGHIST: i32 = 18;
3595pub const BAREGLOBQUAL: i32 = 19;
3597pub const BASHAUTOLIST: i32 = 20;
3599pub const BASHREMATCH: i32 = 21;
3601pub const BEEP: i32 = 22;
3603pub const BGNICE: i32 = 23;
3605pub const BRACECCL: i32 = 24;
3607pub const BSDECHO: i32 = 25;
3609pub const CASEGLOB: i32 = 26;
3611pub const CASEMATCH: i32 = 27;
3613pub const CASEPATHS: i32 = 28;
3615pub const CBASES: i32 = 29;
3617pub const CDABLEVARS: i32 = 30;
3619pub const CDSILENT: i32 = 31;
3621pub const CHASEDOTS: i32 = 32;
3623pub const CHASELINKS: i32 = 33;
3625pub const CHECKJOBS: i32 = 34;
3627pub const CHECKRUNNINGJOBS: i32 = 35;
3629pub const CLOBBER: i32 = 36;
3631pub const CLOBBEREMPTY: i32 = 37;
3633pub const APPENDCREATE: i32 = 38;
3635pub const COMBININGCHARS: i32 = 39;
3637pub const COMPLETEALIASES: i32 = 40;
3639pub const COMPLETEINWORD: i32 = 41;
3641pub const CORRECT: i32 = 42;
3643pub const CORRECTALL: i32 = 43;
3645pub const CONTINUEONERROR: i32 = 44;
3647pub const CPRECEDENCES: i32 = 45;
3649pub const CSHJUNKIEHISTORY: i32 = 46;
3651pub const CSHJUNKIELOOPS: i32 = 47;
3653pub const CSHJUNKIEQUOTES: i32 = 48;
3655pub const CSHNULLCMD: i32 = 49;
3657pub const CSHNULLGLOB: i32 = 50;
3659pub const DEBUGBEFORECMD: i32 = 51;
3661pub const EMACSMODE: i32 = 52;
3663pub const EQUALSOPT: i32 = 53; pub const ERREXIT: i32 = 54;
3667pub const ERRRETURN: i32 = 55;
3669pub const EXECOPT: i32 = 56;
3671pub const EXTENDEDGLOB: i32 = 57;
3673pub const EXTENDEDHISTORY: i32 = 58;
3675pub const EVALLINENO: i32 = 59;
3677pub const FLOWCONTROL: i32 = 60;
3679pub const FORCEFLOAT: i32 = 61;
3681pub const FUNCTIONARGZERO: i32 = 62;
3683pub const GLOBOPT: i32 = 63;
3685pub const GLOBALEXPORT: i32 = 64;
3687pub const GLOBALRCS: i32 = 65;
3689pub const GLOBASSIGN: i32 = 66;
3691pub const GLOBCOMPLETE: i32 = 67;
3693pub const GLOBDOTS: i32 = 68;
3695pub const GLOBSTARSHORT: i32 = 69;
3697pub const GLOBSUBST: i32 = 70;
3699pub const HASHCMDS: i32 = 71;
3701pub const HASHDIRS: i32 = 72;
3703pub const HASHEXECUTABLESONLY: i32 = 73;
3705pub const HASHLISTALL: i32 = 74;
3707pub const HISTALLOWCLOBBER: i32 = 75;
3709pub const HISTBEEP: i32 = 76;
3711pub const HISTEXPIREDUPSFIRST: i32 = 77;
3713pub const HISTFCNTLLOCK: i32 = 78;
3715pub const HISTFINDNODUPS: i32 = 79;
3717pub const HISTIGNOREALLDUPS: i32 = 80;
3719pub const HISTIGNOREDUPS: i32 = 81;
3721pub const HISTIGNORESPACE: i32 = 82;
3723pub const HISTLEXWORDS: i32 = 83;
3725pub const HISTNOFUNCTIONS: i32 = 84;
3727pub const HISTNOSTORE: i32 = 85;
3729pub const HISTREDUCEBLANKS: i32 = 86;
3731pub const HISTSAVEBYCOPY: i32 = 87;
3733pub const HISTSAVENODUPS: i32 = 88;
3735pub const HISTSUBSTPATTERN: i32 = 89;
3737pub const HISTVERIFY: i32 = 90;
3739pub const HUP: i32 = 91;
3741pub const IGNOREBRACES: i32 = 92;
3743pub const IGNORECLOSEBRACES: i32 = 93;
3745pub const IGNOREEOF: i32 = 94;
3747pub const INCAPPENDHISTORY: i32 = 95;
3749pub const INCAPPENDHISTORYTIME: i32 = 96;
3751pub const INTERACTIVE: i32 = 97;
3753pub const INTERACTIVECOMMENTS: i32 = 98;
3755pub const KSHARRAYS: i32 = 99;
3757pub const KSHAUTOLOAD: i32 = 100;
3759pub const KSHGLOB: i32 = 101;
3761pub const KSHOPTIONPRINT: i32 = 102;
3763pub const KSHTYPESET: i32 = 103;
3765pub const KSHZEROSUBSCRIPT: i32 = 104;
3767pub const LISTAMBIGUOUS: i32 = 105;
3769pub const LISTBEEP: i32 = 106;
3771pub const LISTPACKED: i32 = 107;
3773pub const LISTROWSFIRST: i32 = 108;
3775pub const LISTTYPES: i32 = 109;
3777pub const LOCALLOOPS: i32 = 110;
3779pub const LOCALOPTIONS: i32 = 111;
3781pub const LOCALPATTERNS: i32 = 112;
3783pub const LOCALTRAPS: i32 = 113;
3785pub const LOGINSHELL: i32 = 114;
3787pub const LONGLISTJOBS: i32 = 115;
3789pub const MAGICEQUALSUBST: i32 = 116;
3791pub const MAILWARNING: i32 = 117;
3793pub const MARKDIRS: i32 = 118;
3795pub const MENUCOMPLETE: i32 = 119;
3797pub const MONITOR: i32 = 120;
3799pub const MULTIBYTE: i32 = 121;
3801pub const MULTIFUNCDEF: i32 = 122;
3803pub const MULTIOS: i32 = 123;
3805pub const NOMATCH: i32 = 124;
3807pub const NOTIFY: i32 = 125;
3809pub const NULLGLOB: i32 = 126;
3811pub const NUMERICGLOBSORT: i32 = 127;
3813pub const OCTALZEROES: i32 = 128;
3815pub const OVERSTRIKE: i32 = 129;
3817pub const PATHDIRS: i32 = 130;
3819pub const PATHSCRIPT: i32 = 131;
3821pub const PIPEFAIL: i32 = 132;
3823pub const POSIXALIASES: i32 = 133;
3825pub const POSIXARGZERO: i32 = 134;
3827pub const POSIXBUILTINS: i32 = 135;
3829pub const POSIXCD: i32 = 136;
3831pub const POSIXIDENTIFIERS: i32 = 137;
3833pub const POSIXJOBS: i32 = 138;
3835pub const POSIXSTRINGS: i32 = 139;
3837pub const POSIXTRAPS: i32 = 140;
3839pub const PRINTEIGHTBIT: i32 = 141;
3841pub const PRINTEXITVALUE: i32 = 142;
3843pub const PRIVILEGED: i32 = 143;
3845pub const PROMPTBANG: i32 = 144;
3847pub const PROMPTCR: i32 = 145;
3849pub const PROMPTPERCENT: i32 = 146;
3851pub const PROMPTSP: i32 = 147;
3853pub const PROMPTSUBST: i32 = 148;
3855pub const PUSHDIGNOREDUPS: i32 = 149;
3857pub const PUSHDMINUS: i32 = 150;
3859pub const PUSHDSILENT: i32 = 151;
3861pub const PUSHDTOHOME: i32 = 152;
3863pub const RCEXPANDPARAM: i32 = 153;
3865pub const RCQUOTES: i32 = 154;
3867pub const RCS: i32 = 155;
3869pub const RECEXACT: i32 = 156;
3871pub const REMATCHPCRE: i32 = 157;
3873pub const RESTRICTED: i32 = 158;
3875pub const RMSTARSILENT: i32 = 159;
3877pub const RMSTARWAIT: i32 = 160;
3879pub const SHAREHISTORY: i32 = 161;
3881pub const SHFILEEXPANSION: i32 = 162;
3883pub const SHGLOB: i32 = 163;
3885pub const SHINSTDIN: i32 = 164;
3887pub const SHNULLCMD: i32 = 165;
3889pub const SHOPTIONLETTERS: i32 = 166;
3891pub const SHORTLOOPS: i32 = 167;
3893pub const SHORTREPEAT: i32 = 168;
3895pub const SHWORDSPLIT: i32 = 169;
3897pub const SINGLECOMMAND: i32 = 170;
3899pub const SINGLELINEZLE: i32 = 171;
3901pub const SOURCETRACE: i32 = 172;
3903pub const SUNKEYBOARDHACK: i32 = 173;
3905pub const TRANSIENTRPROMPT: i32 = 174;
3907pub const TRAPSASYNC: i32 = 175;
3909pub const TYPESETSILENT: i32 = 176;
3911pub const TYPESETTOUNSET: i32 = 177;
3913pub const UNSET: i32 = 178;
3915pub const VERBOSE: i32 = 179;
3917pub const VIMODE: i32 = 180;
3919pub const WARNCREATEGLOBAL: i32 = 181;
3921pub const WARNNESTEDVAR: i32 = 182;
3923pub const XTRACE: i32 = 183;
3925pub const USEZLE: i32 = 184;
3927pub const DVORAK: i32 = 185;
3929pub const OPT_SIZE: i32 = 186;
3931pub type OptIndex = u8; #[inline]
3938pub fn isset(opt: i32) -> bool {
3939 crate::opts_cache::is_set(opt)
3943}
3944
3945#[inline]
3949pub fn unset(opt: i32) -> bool {
3950 !isset(opt)
3951}
3952
3953#[inline]
3956pub fn interact() -> bool {
3957 isset(INTERACTIVE)
3958}
3959
3960#[inline]
3963pub fn jobbing() -> bool {
3964 isset(MONITOR)
3965}
3966
3967#[inline]
3970pub fn islogin() -> bool {
3971 isset(LOGINSHELL)
3972}
3973
3974pub fn opt_name(opt: i32) -> &'static str {
3985 static OPT_NAMES: std::sync::OnceLock<Vec<&'static str>> = std::sync::OnceLock::new();
3986 let table = OPT_NAMES.get_or_init(|| {
3987 let build = |opt: i32| -> &'static str {
3988 match opt {
3989 x if x == ALIASFUNCDEF => "aliasfuncdef",
3990 x if x == ALLEXPORT => "allexport",
3991 x if x == ALWAYSLASTPROMPT => "alwayslastprompt",
3992 x if x == ALWAYSTOEND => "alwaystoend",
3993 x if x == APPENDHISTORY => "appendhistory",
3994 x if x == AUTOCD => "autocd",
3995 x if x == AUTOCONTINUE => "autocontinue",
3996 x if x == AUTOLIST => "autolist",
3997 x if x == AUTOMENU => "automenu",
3998 x if x == AUTONAMEDIRS => "autonamedirs",
3999 x if x == AUTOPARAMKEYS => "autoparamkeys",
4000 x if x == AUTOPARAMSLASH => "autoparamslash",
4001 x if x == AUTOPUSHD => "autopushd",
4002 x if x == AUTOREMOVESLASH => "autoremoveslash",
4003 x if x == AUTORESUME => "autoresume",
4004 x if x == BADPATTERN => "badpattern",
4005 x if x == BANGHIST => "banghist",
4006 x if x == BAREGLOBQUAL => "bareglobqual",
4007 x if x == BASHAUTOLIST => "bashautolist",
4008 x if x == BASHREMATCH => "bashrematch",
4009 x if x == BEEP => "beep",
4010 x if x == BGNICE => "bgnice",
4011 x if x == BRACECCL => "braceccl",
4012 x if x == BSDECHO => "bsdecho",
4013 x if x == CASEGLOB => "caseglob",
4014 x if x == CASEMATCH => "casematch",
4015 x if x == CASEPATHS => "casepaths",
4016 x if x == CBASES => "cbases",
4017 x if x == CDABLEVARS => "cdablevars",
4018 x if x == CDSILENT => "cdsilent",
4019 x if x == CHASEDOTS => "chasedots",
4020 x if x == CHASELINKS => "chaselinks",
4021 x if x == CHECKJOBS => "checkjobs",
4022 x if x == CHECKRUNNINGJOBS => "checkrunningjobs",
4023 x if x == CLOBBER => "clobber",
4024 x if x == CLOBBEREMPTY => "clobberempty",
4025 x if x == APPENDCREATE => "appendcreate",
4026 x if x == COMBININGCHARS => "combiningchars",
4027 x if x == COMPLETEALIASES => "completealiases",
4028 x if x == COMPLETEINWORD => "completeinword",
4029 x if x == CORRECT => "correct",
4030 x if x == CORRECTALL => "correctall",
4031 x if x == CPRECEDENCES => "cprecedences",
4032 x if x == CSHJUNKIEHISTORY => "cshjunkiehistory",
4033 x if x == CSHJUNKIELOOPS => "cshjunkieloops",
4034 x if x == CSHJUNKIEQUOTES => "cshjunkiequotes",
4035 x if x == CSHNULLCMD => "cshnullcmd",
4036 x if x == CSHNULLGLOB => "cshnullglob",
4037 x if x == CONTINUEONERROR => "continueonerror",
4038 x if x == DEBUGBEFORECMD => "debugbeforecmd",
4039 x if x == EMACSMODE => "emacs",
4040 x if x == EQUALSOPT => "equals",
4041 x if x == ERREXIT => "errexit",
4042 x if x == ERRRETURN => "errreturn",
4043 x if x == EXECOPT => "exec",
4044 x if x == EXTENDEDGLOB => "extendedglob",
4045 x if x == EXTENDEDHISTORY => "extendedhistory",
4046 x if x == EVALLINENO => "evallineno",
4047 x if x == FLOWCONTROL => "flowcontrol",
4048 x if x == FORCEFLOAT => "forcefloat",
4049 x if x == FUNCTIONARGZERO => "functionargzero",
4050 x if x == GLOBOPT => "glob",
4051 x if x == GLOBALEXPORT => "globalexport",
4052 x if x == GLOBALRCS => "globalrcs",
4053 x if x == GLOBASSIGN => "globassign",
4054 x if x == GLOBCOMPLETE => "globcomplete",
4055 x if x == GLOBDOTS => "globdots",
4056 x if x == GLOBSTARSHORT => "globstarshort",
4057 x if x == GLOBSUBST => "globsubst",
4058 x if x == HASHCMDS => "hashcmds",
4059 x if x == HASHDIRS => "hashdirs",
4060 x if x == HASHEXECUTABLESONLY => "hashexecutablesonly",
4061 x if x == HASHLISTALL => "hashlistall",
4062 x if x == HISTALLOWCLOBBER => "histallowclobber",
4063 x if x == HISTBEEP => "histbeep",
4064 x if x == HISTEXPIREDUPSFIRST => "histexpiredupsfirst",
4065 x if x == HISTFCNTLLOCK => "histfcntllock",
4066 x if x == HISTFINDNODUPS => "histfindnodups",
4067 x if x == HISTIGNOREALLDUPS => "histignorealldups",
4068 x if x == HISTIGNOREDUPS => "histignoredups",
4069 x if x == HISTIGNORESPACE => "histignorespace",
4070 x if x == HISTLEXWORDS => "histlexwords",
4071 x if x == HISTNOFUNCTIONS => "histnofunctions",
4072 x if x == HISTNOSTORE => "histnostore",
4073 x if x == HISTREDUCEBLANKS => "histreduceblanks",
4074 x if x == HISTSAVEBYCOPY => "histsavebycopy",
4075 x if x == HISTSAVENODUPS => "histsavenodups",
4076 x if x == HISTSUBSTPATTERN => "histsubstpattern",
4077 x if x == HISTVERIFY => "histverify",
4078 x if x == HUP => "hup",
4079 x if x == IGNOREBRACES => "ignorebraces",
4080 x if x == IGNORECLOSEBRACES => "ignoreclosebraces",
4081 x if x == IGNOREEOF => "ignoreeof",
4082 x if x == INCAPPENDHISTORY => "incappendhistory",
4083 x if x == INCAPPENDHISTORYTIME => "incappendhistorytime",
4084 x if x == INTERACTIVE => "interactive",
4085 x if x == INTERACTIVECOMMENTS => "interactivecomments",
4086 x if x == KSHARRAYS => "ksharrays",
4087 x if x == KSHAUTOLOAD => "kshautoload",
4088 x if x == KSHGLOB => "kshglob",
4089 x if x == KSHOPTIONPRINT => "kshoptionprint",
4090 x if x == KSHTYPESET => "kshtypeset",
4091 x if x == KSHZEROSUBSCRIPT => "kshzerosubscript",
4092 x if x == LISTAMBIGUOUS => "listambiguous",
4093 x if x == LISTBEEP => "listbeep",
4094 x if x == LISTPACKED => "listpacked",
4095 x if x == LISTROWSFIRST => "listrowsfirst",
4096 x if x == LISTTYPES => "listtypes",
4097 x if x == LOCALOPTIONS => "localoptions",
4098 x if x == LOCALLOOPS => "localloops",
4099 x if x == LOCALPATTERNS => "localpatterns",
4100 x if x == LOCALTRAPS => "localtraps",
4101 x if x == LOGINSHELL => "loginshell",
4102 x if x == LONGLISTJOBS => "longlistjobs",
4103 x if x == MAGICEQUALSUBST => "magicequalsubst",
4104 x if x == MAILWARNING => "mailwarning",
4105 x if x == MARKDIRS => "markdirs",
4106 x if x == MENUCOMPLETE => "menucomplete",
4107 x if x == MONITOR => "monitor",
4108 x if x == MULTIBYTE => "multibyte",
4109 x if x == MULTIFUNCDEF => "multifuncdef",
4110 x if x == MULTIOS => "multios",
4111 x if x == NOMATCH => "nomatch",
4112 x if x == NOTIFY => "notify",
4113 x if x == NULLGLOB => "nullglob",
4114 x if x == NUMERICGLOBSORT => "numericglobsort",
4115 x if x == OCTALZEROES => "octalzeroes",
4116 x if x == OVERSTRIKE => "overstrike",
4117 x if x == PATHDIRS => "pathdirs",
4118 x if x == PATHSCRIPT => "pathscript",
4119 x if x == PIPEFAIL => "pipefail",
4120 x if x == POSIXALIASES => "posixaliases",
4121 x if x == POSIXARGZERO => "posixargzero",
4122 x if x == POSIXBUILTINS => "posixbuiltins",
4123 x if x == POSIXCD => "posixcd",
4124 x if x == POSIXIDENTIFIERS => "posixidentifiers",
4125 x if x == POSIXJOBS => "posixjobs",
4126 x if x == POSIXSTRINGS => "posixstrings",
4127 x if x == POSIXTRAPS => "posixtraps",
4128 x if x == PRINTEIGHTBIT => "printeightbit",
4129 x if x == PRINTEXITVALUE => "printexitvalue",
4130 x if x == PRIVILEGED => "privileged",
4131 x if x == PROMPTBANG => "promptbang",
4132 x if x == PROMPTCR => "promptcr",
4133 x if x == PROMPTPERCENT => "promptpercent",
4134 x if x == PROMPTSP => "promptsp",
4135 x if x == PROMPTSUBST => "promptsubst",
4136 x if x == PUSHDIGNOREDUPS => "pushdignoredups",
4137 x if x == PUSHDMINUS => "pushdminus",
4138 x if x == PUSHDSILENT => "pushdsilent",
4139 x if x == PUSHDTOHOME => "pushdtohome",
4140 x if x == RCEXPANDPARAM => "rcexpandparam",
4141 x if x == RCQUOTES => "rcquotes",
4142 x if x == RCS => "rcs",
4143 x if x == RECEXACT => "recexact",
4144 x if x == REMATCHPCRE => "rematchpcre",
4145 x if x == RESTRICTED => "restricted",
4146 x if x == RMSTARSILENT => "rmstarsilent",
4147 x if x == RMSTARWAIT => "rmstarwait",
4148 x if x == SHAREHISTORY => "sharehistory",
4149 x if x == SHFILEEXPANSION => "shfileexpansion",
4150 x if x == SHGLOB => "shglob",
4151 x if x == SHINSTDIN => "shinstdin",
4152 x if x == SHNULLCMD => "shnullcmd",
4153 x if x == SHOPTIONLETTERS => "shoptionletters",
4154 x if x == SHORTLOOPS => "shortloops",
4155 x if x == SHORTREPEAT => "shortrepeat",
4156 x if x == SHWORDSPLIT => "shwordsplit",
4157 x if x == SINGLECOMMAND => "singlecommand",
4158 x if x == SINGLELINEZLE => "singlelinezle",
4159 x if x == SOURCETRACE => "sourcetrace",
4160 x if x == SUNKEYBOARDHACK => "sunkeyboardhack",
4161 x if x == TRANSIENTRPROMPT => "transientrprompt",
4162 x if x == TRAPSASYNC => "trapsasync",
4163 x if x == TYPESETSILENT => "typesetsilent",
4164 x if x == TYPESETTOUNSET => "typesettounset",
4165 x if x == UNSET => "unset",
4166 x if x == VERBOSE => "verbose",
4167 x if x == ALIASESOPT => "aliases",
4168 x if x == WARNCREATEGLOBAL => "warncreateglobal",
4169 x if x == WARNNESTEDVAR => "warnnestedvar",
4170 x if x == XTRACE => "xtrace",
4171 x if x == USEZLE => "zle",
4172 x if x == DVORAK => "dvorak",
4173 x if x == VIMODE => "vi",
4178 _ => "",
4179 }
4180 };
4181 (0..OPT_SIZE).map(build).collect()
4182 });
4183 table.get(opt as usize).copied().unwrap_or("")
4184}
4185
4186pub const TERM_BAD: i32 = 0x01;
4191pub const TERM_UNKNOWN: i32 = 0x02;
4193pub const TERM_NOUP: i32 = 0x04;
4195pub const TERM_SHORT: i32 = 0x08;
4197pub const TERM_NARROW: i32 = 0x10;
4199pub const TCCLEARSCREEN: i32 = 0;
4201pub const TCLEFT: i32 = 1;
4203pub const TCMULTLEFT: i32 = 2;
4205pub const TCRIGHT: i32 = 3;
4207pub const TCMULTRIGHT: i32 = 4;
4209pub const TCUP: i32 = 5;
4211pub const TCMULTUP: i32 = 6;
4213pub const TCDOWN: i32 = 7;
4215pub const TCMULTDOWN: i32 = 8;
4217pub const TCDEL: i32 = 9;
4219pub const TCMULTDEL: i32 = 10;
4221pub const TCINS: i32 = 11;
4223pub const TCMULTINS: i32 = 12;
4225pub const TCCLEAREOD: i32 = 13;
4227pub const TCCLEAREOL: i32 = 14;
4229pub const TCINSLINE: i32 = 15;
4231pub const TCDELLINE: i32 = 16;
4233pub const TCNEXTTAB: i32 = 17;
4235pub const TCBOLDFACEBEG: i32 = 18;
4237pub const TCFAINTBEG: i32 = 19;
4239pub const TCSTANDOUTBEG: i32 = 20;
4241pub const TCUNDERLINEBEG: i32 = 21;
4243pub const TCITALICSBEG: i32 = 22;
4245pub const TCALLATTRSOFF: i32 = 23;
4247pub const TCSTANDOUTEND: i32 = 24;
4249pub const TCUNDERLINEEND: i32 = 25;
4251pub const TCITALICSEND: i32 = 26;
4253pub const TCHORIZPOS: i32 = 27;
4255pub const TCUPCURSOR: i32 = 28;
4257pub const TCDOWNCURSOR: i32 = 29;
4259pub const TCLEFTCURSOR: i32 = 30;
4261pub const TCRIGHTCURSOR: i32 = 31;
4263pub const TCSAVECURSOR: i32 = 32;
4265pub const TCRESTRCURSOR: i32 = 33;
4267pub const TCBACKSPACE: i32 = 34;
4269pub const TCFGCOLOUR: i32 = 35;
4271pub const TCBGCOLOUR: i32 = 36;
4273pub const TCCURINV: i32 = 37;
4275pub const TCCURVIS: i32 = 38;
4277pub const TC_COUNT: i32 = 39;
4279
4280pub type zattr = u64; pub const TXTBOLDFACE: zattr = 0x0001;
4287pub const TXTFAINT: zattr = 0x0002;
4289pub const TXTSTANDOUT: zattr = 0x0004;
4291pub const TXTUNDERLINE: zattr = 0x0008;
4293pub const TXTITALIC: zattr = 0x0010;
4295pub const TXTFGCOLOUR: zattr = 0x0020;
4297pub const TXTBGCOLOUR: zattr = 0x0040;
4299pub const TXT_ATTR_ALL: zattr = 0x007F;
4301pub const TXT_MULTIWORD_MASK: zattr = 0x0400;
4303pub const TXT_ERROR: zattr = 0xF00000F000000003;
4305pub const TXT_ATTR_FONT_WEIGHT: zattr = TXTBOLDFACE | TXTFAINT;
4307pub const TXT_ATTR_FG_COL_MASK: zattr = 0x000000FFFFFF0000;
4309pub const TXT_ATTR_FG_COL_SHIFT: u32 = 16;
4311pub const TXT_ATTR_BG_COL_MASK: zattr = 0xFFFFFF0000000000;
4313pub const TXT_ATTR_BG_COL_SHIFT: u32 = 40;
4315pub const TXT_ATTR_FG_24BIT: zattr = 0x4000;
4317pub const TXT_ATTR_BG_24BIT: zattr = 0x8000;
4319pub const TXT_ATTR_FG_MASK: zattr = TXTFGCOLOUR | TXT_ATTR_FG_COL_MASK | TXT_ATTR_FG_24BIT;
4321pub const TXT_ATTR_BG_MASK: zattr = TXTBGCOLOUR | TXT_ATTR_BG_COL_MASK | TXT_ATTR_BG_24BIT;
4323pub const TXT_ATTR_COLOUR_MASK: zattr = TXT_ATTR_FG_MASK | TXT_ATTR_BG_MASK;
4325pub const COL_SEQ_FG: i32 = 0;
4327pub const COL_SEQ_BG: i32 = 1;
4329#[allow(non_camel_case_types)]
4331pub struct color_rgb {
4332 pub red: u32,
4335 pub green: u32,
4337 pub blue: u32,
4339}
4340pub type Color_rgb = Box<color_rgb>;
4342pub const TSC_RAW: i32 = 0x0001; pub const TSC_PROMPT: i32 = 0x0002;
4346pub const TSC_DIRTY: i32 = 0x0004;
4353
4354pub const CMDSTACKSZ: usize = 256;
4359pub const CS_FOR: i32 = 0;
4361pub const CS_WHILE: i32 = 1;
4363pub const CS_REPEAT: i32 = 2;
4365pub const CS_SELECT: i32 = 3;
4367pub const CS_UNTIL: i32 = 4;
4369pub const CS_IF: i32 = 5;
4371pub const CS_IFTHEN: i32 = 6;
4373pub const CS_ELSE: i32 = 7;
4375pub const CS_ELIF: i32 = 8;
4377pub const CS_MATH: i32 = 9;
4379pub const CS_COND: i32 = 10;
4381pub const CS_CMDOR: i32 = 11;
4383pub const CS_CMDAND: i32 = 12;
4385pub const CS_PIPE: i32 = 13;
4387pub const CS_ERRPIPE: i32 = 14;
4389pub const CS_FOREACH: i32 = 15;
4391pub const CS_CASE: i32 = 16;
4393pub const CS_FUNCDEF: i32 = 17;
4395pub const CS_SUBSH: i32 = 18;
4397pub const CS_CURSH: i32 = 19;
4399pub const CS_ARRAY: i32 = 20;
4401pub const CS_QUOTE: i32 = 21;
4403pub const CS_DQUOTE: i32 = 22;
4405pub const CS_BQUOTE: i32 = 23;
4407pub const CS_CMDSUBST: i32 = 24;
4409pub const CS_MATHSUBST: i32 = 25;
4411pub const CS_ELIFTHEN: i32 = 26;
4413pub const CS_HEREDOC: i32 = 27;
4415pub const CS_HEREDOCD: i32 = 28;
4417pub const CS_BRACE: i32 = 29;
4419pub const CS_BRACEPAR: i32 = 30;
4421pub const CS_ALWAYS: i32 = 31;
4423pub const CS_COUNT: i32 = 32;
4425
4426pub type Heapid = u32; pub const HEAPID_PERMANENT: Heapid = u32::MAX; pub const HDV_PUSH: i32 = 0x01;
4435pub const HDV_POP: i32 = 0x02;
4437pub const HDV_CREATE: i32 = 0x04;
4439pub const HDV_FREE: i32 = 0x08;
4441pub const HDV_NEW: i32 = 0x10;
4443pub const HDV_OLD: i32 = 0x20;
4445pub const HDV_SWITCH: i32 = 0x40;
4447pub const HDV_ALLOC: i32 = 0x80;
4449
4450pub const ZSIG_TRAPPED: i32 = 1 << 0;
4455pub const ZSIG_IGNORED: i32 = 1 << 1;
4457pub const ZSIG_FUNC: i32 = 1 << 2;
4459pub const ZSIG_MASK: i32 = ZSIG_TRAPPED | ZSIG_IGNORED | ZSIG_FUNC;
4461pub const ZSIG_ALIAS: i32 = 1 << 3;
4463pub const ZSIG_SHIFT: i32 = 4;
4465pub const TRAP_STATE_INACTIVE: i32 = 0;
4467pub const TRAP_STATE_PRIMED: i32 = 1;
4469pub const TRAP_STATE_FORCE_RETURN: i32 = 2;
4471pub const ERRFLAG_ERROR: i32 = 1;
4473pub const ERRFLAG_INT: i32 = 2;
4475pub const ERRFLAG_HARD: i32 = 4;
4477
4478pub const SORTIT_ANYOLDHOW: i32 = 0;
4483pub const SORTIT_IGNORING_CASE: i32 = 1;
4485pub const SORTIT_NUMERICALLY: i32 = 2;
4487pub const SORTIT_NUMERICALLY_SIGNED: i32 = 4;
4489pub const SORTIT_BACKWARDS: i32 = 8;
4491pub const SORTIT_IGNORING_BACKSLASHES: i32 = 16;
4493pub const SORTIT_SOMEHOW: i32 = 32;
4495
4496pub const CASMOD_NONE: i32 = 0;
4501pub const CASMOD_UPPER: i32 = 1;
4503pub const CASMOD_LOWER: i32 = 2;
4505pub const CASMOD_CAPS: i32 = 3;
4507pub const GETKEY_OCTAL_ESC: i32 = 1 << 0;
4509pub const GETKEY_EMACS: i32 = 1 << 1;
4511pub const GETKEY_CTRL: i32 = 1 << 2;
4513pub const GETKEY_BACKSLASH_C: i32 = 1 << 3;
4515pub const GETKEY_DOLLAR_QUOTE: i32 = 1 << 4;
4517pub const GETKEY_BACKSLASH_MINUS: i32 = 1 << 5;
4519pub const GETKEY_SINGLE_CHAR: i32 = 1 << 6;
4521pub const GETKEY_UPDATE_OFFSET: i32 = 1 << 7;
4523pub const GETKEY_PRINTF_PERCENT: i32 = 1 << 8;
4525pub const GETKEYS_ECHO: i32 = GETKEY_BACKSLASH_C;
4527pub const GETKEYS_PRINTF_FMT: i32 = GETKEY_OCTAL_ESC | GETKEY_BACKSLASH_C | GETKEY_PRINTF_PERCENT;
4529pub const GETKEYS_PRINTF_ARG: i32 = GETKEY_BACKSLASH_C;
4531pub const GETKEYS_PRINT: i32 = GETKEY_OCTAL_ESC | GETKEY_BACKSLASH_C | GETKEY_EMACS;
4533pub const GETKEYS_BINDKEY: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL;
4535pub const GETKEYS_DOLLARS_QUOTE: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_DOLLAR_QUOTE;
4537pub const GETKEYS_MATH: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL | GETKEY_SINGLE_CHAR;
4539pub const GETKEYS_SEP: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS;
4541pub const GETKEYS_SUFFIX: i32 =
4542 GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL | GETKEY_BACKSLASH_MINUS;
4543
4544pub const ZLRF_HISTORY: i32 = 0x01;
4549pub const ZLRF_NOSETTY: i32 = 0x02;
4551pub const ZLRF_IGNOREEOF: i32 = 0x04;
4553pub const ZLCON_LINE_START: i32 = 0;
4555pub const ZLCON_LINE_CONT: i32 = 1;
4557pub const ZLCON_SELECT: i32 = 2;
4559pub const ZLCON_VARED: i32 = 3;
4561pub const ZLE_CMD_GET_LINE: i32 = 0;
4563pub const ZLE_CMD_READ: i32 = 1;
4565pub const ZLE_CMD_ADD_TO_LINE: i32 = 2;
4567pub const ZLE_CMD_TRASH: i32 = 3;
4569pub const ZLE_CMD_RESET_PROMPT: i32 = 4;
4571pub const ZLE_CMD_REFRESH: i32 = 5;
4573pub const ZLE_CMD_SET_KEYMAP: i32 = 6;
4575pub const ZLE_CMD_GET_KEY: i32 = 7;
4577pub const ZLE_CMD_SET_HIST_LINE: i32 = 8;
4579pub const ZLE_CMD_PREEXEC: i32 = 9;
4581pub const ZLE_CMD_POSTEXEC: i32 = 10;
4583pub const ZLE_CMD_CHPWD: i32 = 11;
4585
4586pub const ZEXIT_NORMAL: i32 = 0;
4591pub const ZEXIT_SIGNAL: i32 = 1;
4593pub const ZEXIT_DEFERRED: i32 = 2;
4595pub const NICEFLAG_HEAP: i32 = 1;
4597pub const NICEFLAG_QUOTE: i32 = 2;
4599pub const NICEFLAG_NODUP: i32 = 4;
4601
4602pub type convchar_t = u32; pub const MB_INCOMPLETE: usize = usize::MAX - 1; pub const MB_INVALID: usize = usize::MAX; pub const MB_CUR_MAX: usize = 6; #[inline]
4618#[allow(non_snake_case)]
4619pub fn MB_METACHARINIT() {} #[inline]
4626#[allow(non_snake_case)]
4627pub fn MB_METACHARLEN(s: &[u8]) -> usize {
4628 if s.is_empty() {
4630 0
4631 } else if s[0] == Meta {
4632 2
4633 } else {
4634 1
4635 }
4636}
4637
4638#[inline]
4642#[allow(non_snake_case)]
4643pub fn MB_METACHARLENCONV(s: &[u8]) -> (usize, Option<char>) {
4644 if s.is_empty() {
4646 return (0, None);
4647 }
4648 if s[0] == Meta && s.len() >= 2 {
4649 let unmeta = s[1] ^ 0x20;
4650 (2, Some(unmeta as char))
4651 } else {
4652 (1, Some(s[0] as char))
4653 }
4654}
4655
4656#[inline]
4659#[allow(non_snake_case)]
4660pub fn MB_METASTRLEN(s: &str) -> usize {
4661 let mut n = 0;
4663 let mut i = 0;
4664 let bytes = s.as_bytes();
4665 while i < bytes.len() {
4666 if bytes[i] == Meta && i + 1 < bytes.len() {
4667 i += 2;
4668 } else {
4669 i += 1;
4670 }
4671 n += 1;
4672 }
4673 n
4674}
4675
4676#[inline]
4680#[allow(non_snake_case)]
4681pub fn MB_METASTRWIDTH(s: &str) -> usize {
4682 MB_METASTRLEN(s)
4684}
4685
4686#[inline]
4690#[allow(non_snake_case)]
4691pub fn MB_METASTRLEN2(s: &str, widthp: bool) -> usize {
4692 if widthp {
4694 MB_METASTRWIDTH(s)
4695 } else {
4696 MB_METASTRLEN(s)
4697 }
4698}
4699
4700#[inline]
4703#[allow(non_snake_case)]
4704pub fn MB_CHARINIT() {} #[inline]
4709#[allow(non_snake_case)]
4710pub fn MB_CHARLEN(s: &[u8], len: usize) -> usize {
4711 if len == 0 || s.is_empty() {
4713 0
4714 } else {
4715 1
4716 }
4717}
4718
4719#[inline]
4723#[allow(non_snake_case)]
4724pub fn MB_CHARLENCONV(s: &[u8], len: usize) -> (usize, Option<char>) {
4725 if len == 0 || s.is_empty() {
4727 (0, None)
4728 } else {
4729 (1, Some(s[0] as char))
4730 }
4731}
4732
4733#[inline]
4746#[allow(non_snake_case)]
4747pub fn WCWIDTH(wc: char) -> i32 {
4748 unicode_width::UnicodeWidthChar::width(wc)
4750 .map(|w| w as i32)
4751 .unwrap_or_else(|| if wc.is_control() { 0 } else { 1 })
4752}
4753
4754#[inline]
4757#[allow(non_snake_case)]
4758pub fn WCWIDTH_WINT(wc: char) -> i32 {
4759 WCWIDTH(wc)
4761}
4762
4763#[inline]
4766#[allow(non_snake_case)]
4767pub fn IS_COMBINING(wc: char) -> bool {
4768 wc as u32 != 0 && WCWIDTH(wc) == 0
4770}
4771
4772#[inline]
4776#[allow(non_snake_case)]
4777pub fn IS_BASECHAR(wc: char) -> bool {
4778 !wc.is_whitespace() && !wc.is_control() && WCWIDTH(wc) > 0
4780}
4781
4782#[inline]
4786#[allow(non_snake_case)]
4787pub const fn ZWC(c: char) -> char {
4788 c
4789} #[inline]
4802#[allow(non_snake_case)]
4803pub fn OPT_ARG<'a>(ops: &'a options, c: u8) -> Option<&'a str> {
4804 let idx = (ops.ind[c as usize] >> 2) as usize;
4805 if idx == 0 {
4806 return None;
4807 }
4808 ops.args.get(idx - 1).map(|s| s.as_str())
4809}
4810
4811#[inline]
4814#[allow(non_snake_case)]
4815pub fn OPT_ARG_SAFE<'a>(ops: &'a options, c: u8) -> Option<&'a str> {
4816 if OPT_HASARG(ops, c) {
4817 OPT_ARG(ops, c)
4818 } else {
4819 None
4820 }
4821}
4822
4823#[allow(dead_code)]
4825const _MARKER_KEEP: AtomicI32 = AtomicI32::new(0);
4826
4827#[cfg(test)]
4828mod tests {
4829 use super::*;
4830
4831 #[test]
4832 fn zlong_zulong_sizes() {
4833 let _g = crate::test_util::global_state_lock();
4834 assert_eq!(std::mem::size_of::<zlong>(), 8);
4835 assert_eq!(std::mem::size_of::<zulong>(), 8);
4836 }
4837
4838 #[test]
4839 fn meta_byte_value() {
4840 let _g = crate::test_util::global_state_lock();
4841 assert_eq!(Meta as u32, 0x83);
4842 }
4843
4844 #[test]
4845 fn parser_tokens_correct() {
4846 let _g = crate::test_util::global_state_lock();
4847 assert_eq!(Pound as u32, 0x84);
4848 assert_eq!(Bang as u32, 0x9c);
4849 assert_eq!(Snull as u32, 0x9d);
4850 assert_eq!(Dnull as u32, 0x9e);
4851 assert_eq!(Bnull as u32, 0x9f);
4852 assert_eq!(Bnullkeep as u32, 0xa0);
4853 assert_eq!(Nularg as u32, 0xa1);
4854 assert_eq!(Marker as u32, 0xa2);
4855 }
4856
4857 #[test]
4858 fn pm_type_isolates_type_bits() {
4859 let _g = crate::test_util::global_state_lock();
4860 assert_eq!(PM_TYPE(PM_INTEGER | PM_EXPORTED), PM_INTEGER);
4861 assert_eq!(PM_TYPE(PM_ARRAY | PM_READONLY), PM_ARRAY);
4862 }
4863
4864 #[test]
4865 fn opt_isset_basic() {
4866 let _g = crate::test_util::global_state_lock();
4867 let mut ops = options {
4868 ind: [0u8; MAX_OPS],
4869 args: Vec::new(),
4870 argscount: 0,
4871 argsalloc: 0,
4872 };
4873 ops.ind[b'l' as usize] = 1; assert!(OPT_ISSET(&ops, b'l'));
4875 assert!(OPT_MINUS(&ops, b'l'));
4876 assert!(!OPT_PLUS(&ops, b'l'));
4877 assert!(!OPT_ISSET(&ops, b'r'));
4878 }
4879
4880 #[test]
4881 fn binf_constants_correct() {
4882 let _g = crate::test_util::global_state_lock();
4883 assert_eq!(BINF_PREFIX, 1 << 5);
4884 assert_eq!(BINF_ASSIGN, 1 << 19);
4885 }
4886
4887 #[test]
4888 fn cond_constants_correct() {
4889 let _g = crate::test_util::global_state_lock();
4890 assert_eq!(COND_NOT, 0);
4891 assert_eq!(COND_MODI, 19);
4892 }
4893
4894 #[test]
4895 fn fdt_constants_correct() {
4896 let _g = crate::test_util::global_state_lock();
4897 assert_eq!(FDT_UNUSED, 0);
4898 assert_eq!(FDT_PROC_SUBST, 7);
4899 assert_eq!(FDT_TYPE_MASK, 15);
4900 }
4901
4902 #[test]
4903 fn redir_iswrite_classification() {
4904 let _g = crate::test_util::global_state_lock();
4905 assert!(IS_WRITE_FILE(REDIR_WRITE));
4906 assert!(IS_WRITE_FILE(REDIR_READWRITE));
4907 assert!(!IS_WRITE_FILE(REDIR_READ));
4908 assert!(IS_ERROR_REDIR(REDIR_ERRWRITE));
4909 assert!(IS_ERROR_REDIR(REDIR_ERRAPPNOW));
4910 assert!(!IS_ERROR_REDIR(REDIR_WRITE));
4911 }
4912
4913 #[test]
4914 fn wc_macros_round_trip() {
4915 let _g = crate::test_util::global_state_lock();
4916 let w = wc_bld(WC_LIST, 42);
4917 assert_eq!(wc_code(w), WC_LIST);
4918 assert_eq!(wc_data(w), 42);
4919 }
4920
4921 #[test]
4922 fn mb_metastrlen_counts_meta_pairs() {
4923 let _g = crate::test_util::global_state_lock();
4924 assert_eq!(MB_METASTRLEN("abc"), 3);
4925 assert_eq!(MB_METASTRLEN("hello"), 5);
4929 assert_eq!(MB_METASTRLEN(""), 0);
4930 }
4931
4932 #[test]
4933 fn mb_charlen_basic() {
4934 let _g = crate::test_util::global_state_lock();
4935 assert_eq!(MB_CHARLEN(b"abc", 3), 1);
4936 assert_eq!(MB_CHARLEN(b"", 0), 0);
4937 }
4938
4939 #[test]
4940 fn wcwidth_basic() {
4941 let _g = crate::test_util::global_state_lock();
4942 assert_eq!(WCWIDTH('a'), 1);
4943 assert_eq!(WCWIDTH('\u{0007}'), 0); assert_eq!(WCWIDTH('\u{4E2D}'), 2); }
4946
4947 #[test]
4948 fn is_combining_zero_width() {
4949 let _g = crate::test_util::global_state_lock();
4950 assert!(!IS_COMBINING('a')); assert!(!IS_COMBINING('\u{0000}')); assert!(IS_COMBINING('\u{0007}'));
4959 }
4960
4961 #[test]
4962 fn pat_flags_correct() {
4963 let _g = crate::test_util::global_state_lock();
4964 assert_eq!(PAT_FILE, 0x0001);
4965 assert_eq!(PAT_LCMATCHUC, 0x1000);
4966 }
4967
4968 #[test]
4969 fn sub_flags_correct() {
4970 let _g = crate::test_util::global_state_lock();
4971 assert_eq!(SUB_END, 0x0001);
4972 assert_eq!(SUB_EGLOB, 0x4000);
4973 }
4974
4975 #[test]
4976 fn pp_constants_ordered() {
4977 let _g = crate::test_util::global_state_lock();
4978 assert_eq!(PP_FIRST, PP_ALPHA);
4979 assert!(PP_LAST >= PP_ALPHA);
4980 assert!(PP_RANGE > PP_LAST);
4981 }
4982
4983 #[test]
4984 fn typeset_optstr_constants() {
4985 let _g = crate::test_util::global_state_lock();
4986 assert_eq!(TYPESET_OPTSTR, "aiEFALRZlurtxUhHT");
4987 assert_eq!(TYPESET_OPTNUM, "LRZiEF");
4988 }
4989
4990 #[test]
4991 fn job_stat_flags_distinct() {
4992 let _g = crate::test_util::global_state_lock();
4993 let all = STAT_CHANGED
4994 | STAT_STOPPED
4995 | STAT_TIMED
4996 | STAT_DONE
4997 | STAT_LOCKED
4998 | STAT_NOPRINT
4999 | STAT_INUSE
5000 | STAT_SUPERJOB
5001 | STAT_SUBJOB
5002 | STAT_WASSUPER
5003 | STAT_CURSH
5004 | STAT_NOSTTY
5005 | STAT_ATTACH
5006 | STAT_SUBLEADER
5007 | STAT_BUILTIN
5008 | STAT_SUBJOB_ORPHANED
5009 | STAT_DISOWN;
5010 assert_eq!(all.count_ones(), 17);
5011 }
5012
5013 #[test]
5014 fn opt_size_at_186() {
5015 let _g = crate::test_util::global_state_lock();
5016 assert_eq!(OPT_SIZE, 186);
5017 }
5018
5019 #[test]
5020 fn cs_count_is_32() {
5021 let _g = crate::test_util::global_state_lock();
5022 assert_eq!(CS_COUNT, 32);
5023 }
5024
5025 #[test]
5026 fn zwc_passes_through() {
5027 let _g = crate::test_util::global_state_lock();
5028 assert_eq!(ZWC('a'), 'a');
5029 }
5030
5031 #[test]
5036 fn is_dash_recognises_both_ascii_and_lexed_token() {
5037 let _g = crate::test_util::global_state_lock();
5038 assert!(IS_DASH('-'), "ASCII '-' is dash");
5039 assert!(IS_DASH('\u{9b}'), "lexed Dash token is dash");
5040 assert!(!IS_DASH('+'), "non-dash chars must NOT match");
5041 assert!(!IS_DASH(' '), "space is not dash");
5042 }
5043
5044 #[test]
5048 fn opt_isset_reads_ind_array_directly() {
5049 let _g = crate::test_util::global_state_lock();
5050 let mut ops = options {
5051 ind: [0u8; MAX_OPS],
5052 args: Vec::new(),
5053 argscount: 0,
5054 argsalloc: 0,
5055 };
5056 assert!(!OPT_ISSET(&ops, b'x'));
5057 ops.ind[b'x' as usize] = 1;
5058 assert!(
5059 OPT_ISSET(&ops, b'x'),
5060 "after setting ind, OPT_ISSET must be true"
5061 );
5062 ops.ind[b'x' as usize] = 0;
5063 assert!(
5064 !OPT_ISSET(&ops, b'x'),
5065 "clearing ind must make OPT_ISSET false"
5066 );
5067 }
5068
5069 #[test]
5075 fn pm_type_strips_modifier_flags() {
5076 let _g = crate::test_util::global_state_lock();
5077 let with_mods = PM_INTEGER | PM_READONLY | PM_EXPORTED;
5078 assert_eq!(PM_TYPE(with_mods), PM_INTEGER);
5079 let just_array = PM_TYPE(PM_ARRAY | PM_LEFT | PM_TIED);
5080 assert_eq!(just_array, PM_ARRAY);
5081 }
5082
5083 #[test]
5088 fn pm_flags_match_c_zsh_h_canonical_values() {
5089 let _g = crate::test_util::global_state_lock();
5090 assert_eq!(PM_SCALAR, 0, "c:1878");
5091 assert_eq!(PM_ARRAY, 1 << 0, "c:1879");
5092 assert_eq!(PM_INTEGER, 1 << 1, "c:1880");
5093 assert_eq!(PM_EFLOAT, 1 << 2, "c:1881");
5094 assert_eq!(PM_FFLOAT, 1 << 3, "c:1882");
5095 assert_eq!(PM_HASHED, 1 << 4, "c:1883");
5096 assert_eq!(PM_LEFT, 1 << 5, "c:1888");
5097 assert_eq!(PM_RIGHT_B, 1 << 6, "c:1889");
5098 assert_eq!(PM_RIGHT_Z, 1 << 7, "c:1890");
5099 assert_eq!(PM_LOWER, 1 << 8, "c:1891");
5100 assert_eq!(PM_UPPER, 1 << 9, "c:1895");
5101 assert_eq!(PM_UNDEFINED, 1 << 9, "c:1896 (aliases PM_UPPER for funcs)");
5102 assert_eq!(PM_READONLY, 1 << 10, "c:1898");
5103 assert_eq!(PM_TAGGED, 1 << 11, "c:1899");
5104 assert_eq!(PM_EXPORTED, 1 << 12, "c:1900");
5105 assert_eq!(
5106 PM_ABSPATH_USED,
5107 1 << 12,
5108 "c:1901 (aliases EXPORTED for funcs)"
5109 );
5110 assert_eq!(PM_UNIQUE, 1 << 13, "c:1905");
5111 assert_eq!(PM_HIDE, 1 << 14, "c:1908");
5112 assert_eq!(PM_HIDEVAL, 1 << 15, "c:1910");
5113 assert_eq!(PM_TIED, 1 << 16, "c:1912");
5114 assert_eq!(PM_SPECIAL, 1 << 20, "c:1922");
5115 assert_eq!(PM_RO_BY_DESIGN, 1 << 21, "c:1924");
5116 assert_eq!(PM_LOCAL, 1 << 19, "c:1920");
5117 assert_eq!(PM_UNSET, 1 << 24, "c:1930");
5118 assert_eq!(PM_NAMEREF, 1 << 30, "c:1944");
5119 }
5120
5121 #[test]
5125 fn scanpm_flags_match_c_zsh_h_canonical_values() {
5126 let _g = crate::test_util::global_state_lock();
5127 assert_eq!(SCANPM_WANTVALS, 1 << 0, "c:1953");
5128 assert_eq!(SCANPM_WANTKEYS, 1 << 1, "c:1954");
5129 assert_eq!(SCANPM_WANTINDEX, 1 << 2, "c:1955");
5130 assert_eq!(SCANPM_MATCHKEY, 1 << 3, "c:1956");
5131 assert_eq!(SCANPM_MATCHVAL, 1 << 4, "c:1957");
5132 assert_eq!(SCANPM_MATCHMANY, 1 << 5, "c:1958");
5133 assert_eq!(SCANPM_ASSIGNING, 1 << 6, "c:1959");
5134 assert_eq!(SCANPM_KEYMATCH, 1 << 7, "c:1960");
5135 assert_eq!(SCANPM_DQUOTED, 1 << 8, "c:1961");
5136 assert_eq!(SCANPM_ARRONLY, 1 << 9, "c:1965");
5137 }
5138
5139 #[test]
5145 fn token_byte_values_match_c_zsh_h() {
5146 let _g = crate::test_util::global_state_lock();
5147 assert_eq!(Meta, 0x83, "c:144");
5148 assert_eq!(Pound, '\u{84}', "c:159");
5149 assert_eq!(Stringg, '\u{85}', "c:160");
5150 assert_eq!(Hat, '\u{86}', "c:161");
5151 assert_eq!(Star, '\u{87}', "c:162");
5152 assert_eq!(Inpar, '\u{88}', "c:163");
5153 assert_eq!(Inparmath, '\u{89}', "c:164");
5154 assert_eq!(Outpar, '\u{8a}', "c:165");
5155 assert_eq!(Outparmath, '\u{8b}', "c:166");
5156 assert_eq!(Qstring, '\u{8c}', "c:167");
5157 assert_eq!(Equals, '\u{8d}', "c:168");
5158 assert_eq!(Bar, '\u{8e}', "c:169");
5159 assert_eq!(Inbrace, '\u{8f}', "c:170");
5160 assert_eq!(Outbrace, '\u{90}', "c:171");
5161 assert_eq!(Inbrack, '\u{91}', "c:172");
5162 assert_eq!(Outbrack, '\u{92}', "c:173");
5163 assert_eq!(Tick, '\u{93}', "c:174");
5164 assert_eq!(Inang, '\u{94}', "c:175");
5165 assert_eq!(Outang, '\u{95}', "c:176");
5166 assert_eq!(OutangProc, '\u{96}', "c:177");
5167 assert_eq!(Quest, '\u{97}', "c:178");
5168 assert_eq!(Tilde, '\u{98}', "c:179");
5169 assert_eq!(Qtick, '\u{99}', "c:180");
5170 assert_eq!(Comma, '\u{9a}', "c:181");
5171 assert_eq!(Dash, '\u{9b}', "c:182");
5172 assert_eq!(Bang, '\u{9c}', "c:183");
5173 assert_eq!(LAST_NORMAL_TOK, Bang, "c:188 == Bang");
5174 assert_eq!(Snull, '\u{9d}', "c:193");
5175 assert_eq!(Dnull, '\u{9e}', "c:194");
5176 assert_eq!(Bnull, '\u{9f}', "c:195");
5177 assert_eq!(Bnullkeep, '\u{a0}', "c:200");
5178 assert_eq!(Nularg, '\u{a1}', "c:206");
5179 assert_eq!(Marker, '\u{a2}', "c:224");
5180 }
5181
5182 #[test]
5187 fn specchars_patchars_match_c_zsh_h() {
5188 let _g = crate::test_util::global_state_lock();
5189 assert_eq!(
5191 SPECCHARS, "#$^*()=|{}[]`<>?~;&\n\t \\\'\"",
5192 "c:228 — SPECCHARS literal must match C verbatim"
5193 );
5194 assert_eq!(
5195 SPECCHARS.chars().count(),
5196 25,
5197 "c:228 — SPECCHARS has 25 chars"
5198 );
5199 assert_eq!(
5201 PATCHARS, "#^*()|[]<>?~\\",
5202 "c:232 — PATCHARS literal must match C verbatim"
5203 );
5204 assert_eq!(
5205 PATCHARS.chars().count(),
5206 13,
5207 "c:232 — PATCHARS has 13 chars"
5208 );
5209 }
5210
5211 #[test]
5213 fn default_ifs_strings_match_c_zsh_h() {
5214 let _g = crate::test_util::global_state_lock();
5215 assert_eq!(
5217 DEFAULT_IFS, " \t\n\u{83} ",
5218 "c:149 — DEFAULT_IFS = space + tab + newline + Meta + space"
5219 );
5220 assert_eq!(
5221 DEFAULT_IFS.chars().count(),
5222 5,
5223 "c:149 — DEFAULT_IFS is 5 chars"
5224 );
5225 assert_eq!(
5227 DEFAULT_IFS_SH, " \t\n",
5228 "c:153 — DEFAULT_IFS_SH = POSIX 3-char set"
5229 );
5230 }
5231
5232 #[test]
5237 fn pm_type_mask_excludes_modifier_flags() {
5238 let _g = crate::test_util::global_state_lock();
5239 let type_mask = PM_ARRAY | PM_INTEGER | PM_EFLOAT | PM_FFLOAT | PM_HASHED;
5240 for modifier in &[
5242 PM_LEFT,
5243 PM_RIGHT_B,
5244 PM_RIGHT_Z,
5245 PM_LOWER,
5246 PM_UPPER,
5247 PM_READONLY,
5248 PM_EXPORTED,
5249 PM_LOCAL,
5250 PM_UNSET,
5251 ] {
5252 assert_eq!(
5253 modifier & type_mask,
5254 0,
5255 "modifier flag 0x{:x} must NOT overlap type mask 0x{:x}",
5256 modifier,
5257 type_mask
5258 );
5259 }
5260 }
5261
5262 #[test]
5267 fn is_write_file_sweep_all_redir_types() {
5268 let _g = crate::test_util::global_state_lock();
5269 for x in REDIR_WRITE..=REDIR_READWRITE {
5271 assert!(
5272 IS_WRITE_FILE(x),
5273 "redir-type {} ({}) must be IS_WRITE_FILE",
5274 x,
5275 x
5276 );
5277 }
5278 for x in [
5280 REDIR_READ,
5281 REDIR_HEREDOC,
5282 REDIR_HEREDOCDASH,
5283 REDIR_HERESTR,
5284 REDIR_MERGEIN,
5285 REDIR_MERGEOUT,
5286 REDIR_CLOSE,
5287 REDIR_INPIPE,
5288 REDIR_OUTPIPE,
5289 ] {
5290 assert!(
5291 !IS_WRITE_FILE(x),
5292 "redir-type {} must NOT be IS_WRITE_FILE",
5293 x
5294 );
5295 }
5296 }
5297
5298 #[test]
5303 fn is_append_redir_pins_bit_1() {
5304 let _g = crate::test_util::global_state_lock();
5305 assert!(IS_APPEND_REDIR(REDIR_APP), "REDIR_APP=2 is append");
5307 assert!(IS_APPEND_REDIR(REDIR_APPNOW), "REDIR_APPNOW=3 is append");
5308 assert!(IS_APPEND_REDIR(REDIR_ERRAPP), "REDIR_ERRAPP=6 is append");
5309 assert!(
5310 IS_APPEND_REDIR(REDIR_ERRAPPNOW),
5311 "REDIR_ERRAPPNOW=7 is append"
5312 );
5313 assert!(!IS_APPEND_REDIR(REDIR_WRITE), "REDIR_WRITE=0 is not append");
5315 assert!(
5316 !IS_APPEND_REDIR(REDIR_WRITENOW),
5317 "REDIR_WRITENOW=1 is not append"
5318 );
5319 assert!(
5320 !IS_APPEND_REDIR(REDIR_ERRWRITE),
5321 "REDIR_ERRWRITE=4 is not append"
5322 );
5323 assert!(
5324 !IS_APPEND_REDIR(REDIR_ERRWRITENOW),
5325 "REDIR_ERRWRITENOW=5 is not append"
5326 );
5327 assert!(
5329 !IS_APPEND_REDIR(REDIR_READ),
5330 "REDIR_READ=9 is not write-file"
5331 );
5332 }
5333
5334 #[test]
5339 fn is_clobber_redir_pins_bit_0() {
5340 let _g = crate::test_util::global_state_lock();
5341 assert!(
5343 IS_CLOBBER_REDIR(REDIR_WRITENOW),
5344 "REDIR_WRITENOW=1 is clobber"
5345 );
5346 assert!(IS_CLOBBER_REDIR(REDIR_APPNOW), "REDIR_APPNOW=3 is clobber");
5347 assert!(
5348 IS_CLOBBER_REDIR(REDIR_ERRWRITENOW),
5349 "REDIR_ERRWRITENOW=5 is clobber"
5350 );
5351 assert!(
5352 IS_CLOBBER_REDIR(REDIR_ERRAPPNOW),
5353 "REDIR_ERRAPPNOW=7 is clobber"
5354 );
5355 assert!(!IS_CLOBBER_REDIR(REDIR_WRITE));
5357 assert!(!IS_CLOBBER_REDIR(REDIR_APP));
5358 assert!(!IS_CLOBBER_REDIR(REDIR_ERRWRITE));
5359 assert!(!IS_CLOBBER_REDIR(REDIR_ERRAPP));
5360 }
5361
5362 #[test]
5366 fn is_error_redir_inclusive_range() {
5367 let _g = crate::test_util::global_state_lock();
5368 for x in REDIR_ERRWRITE..=REDIR_ERRAPPNOW {
5370 assert!(IS_ERROR_REDIR(x), "redir-type {} must be IS_ERROR_REDIR", x);
5371 }
5372 for x in [
5374 REDIR_WRITE,
5375 REDIR_WRITENOW,
5376 REDIR_APP,
5377 REDIR_APPNOW,
5378 REDIR_READWRITE,
5379 REDIR_READ,
5380 REDIR_HEREDOC,
5381 REDIR_INPIPE,
5382 ] {
5383 assert!(
5384 !IS_ERROR_REDIR(x),
5385 "redir-type {} must NOT be IS_ERROR_REDIR",
5386 x
5387 );
5388 }
5389 }
5390
5391 #[test]
5396 fn is_readfd_range_plus_inpipe() {
5397 let _g = crate::test_util::global_state_lock();
5398 for x in REDIR_READWRITE..=REDIR_MERGEIN {
5400 assert!(IS_READFD(x), "redir-type {} must be IS_READFD", x);
5401 }
5402 assert!(
5403 IS_READFD(REDIR_INPIPE),
5404 "REDIR_INPIPE=16 must be IS_READFD (special-case OR arm)"
5405 );
5406 assert!(!IS_READFD(REDIR_WRITE));
5408 assert!(!IS_READFD(REDIR_MERGEOUT));
5409 assert!(!IS_READFD(REDIR_CLOSE));
5410 assert!(!IS_READFD(REDIR_OUTPIPE));
5411 }
5412
5413 #[test]
5418 fn redir_constants_have_exact_canonical_values() {
5419 let _g = crate::test_util::global_state_lock();
5420 assert_eq!(REDIR_WRITE, 0);
5421 assert_eq!(REDIR_WRITENOW, 1);
5422 assert_eq!(REDIR_APP, 2);
5423 assert_eq!(REDIR_APPNOW, 3);
5424 assert_eq!(REDIR_ERRWRITE, 4);
5425 assert_eq!(REDIR_ERRWRITENOW, 5);
5426 assert_eq!(REDIR_ERRAPP, 6);
5427 assert_eq!(REDIR_ERRAPPNOW, 7);
5428 assert_eq!(REDIR_READWRITE, 8);
5429 assert_eq!(REDIR_READ, 9);
5430 assert_eq!(REDIR_HEREDOC, 10);
5431 assert_eq!(REDIR_HEREDOCDASH, 11);
5432 assert_eq!(REDIR_HERESTR, 12);
5433 assert_eq!(REDIR_MERGEIN, 13);
5434 assert_eq!(REDIR_MERGEOUT, 14);
5435 assert_eq!(REDIR_CLOSE, 15);
5436 assert_eq!(REDIR_INPIPE, 16);
5437 assert_eq!(REDIR_OUTPIPE, 17);
5438 }
5439
5440 #[test]
5446 fn redir_masks_have_no_overlap() {
5447 let _g = crate::test_util::global_state_lock();
5448 assert_eq!(REDIR_TYPE_MASK, 0x1f);
5449 assert_eq!(REDIR_VARID_MASK, 0x20);
5450 assert_eq!(REDIR_FROM_HEREDOC_MASK, 0x40);
5451 assert_eq!(REDIR_TYPE_MASK & REDIR_VARID_MASK, 0);
5453 assert_eq!(REDIR_TYPE_MASK & REDIR_FROM_HEREDOC_MASK, 0);
5454 assert_eq!(REDIR_VARID_MASK & REDIR_FROM_HEREDOC_MASK, 0);
5455 assert_eq!(
5457 REDIR_OUTPIPE & REDIR_TYPE_MASK,
5458 REDIR_OUTPIPE,
5459 "type-mask must include every REDIR_* up to OUTPIPE=17"
5460 );
5461 }
5462
5463 #[test]
5467 fn zshh_corpus_wcwidth_ascii_is_one() {
5468 assert_eq!(WCWIDTH('a'), 1);
5469 assert_eq!(WCWIDTH('Z'), 1);
5470 assert_eq!(WCWIDTH('0'), 1);
5471 assert_eq!(WCWIDTH(' '), 1);
5472 }
5473
5474 #[test]
5476 fn zshh_corpus_wcwidth_cjk_is_two() {
5477 assert_eq!(WCWIDTH('中'), 2);
5479 assert_eq!(WCWIDTH('日'), 2);
5481 }
5482
5483 #[test]
5486 fn zshh_corpus_wcwidth_combining_is_zero() {
5487 assert_eq!(WCWIDTH('\u{0301}'), 0, "combining acute accent has width 0");
5488 }
5489
5490 #[test]
5492 fn zshh_corpus_is_combining_true_for_accents() {
5493 assert!(IS_COMBINING('\u{0301}'), "U+0301 COMBINING ACUTE");
5494 assert!(IS_COMBINING('\u{0300}'), "U+0300 COMBINING GRAVE");
5495 }
5496
5497 #[test]
5499 fn zshh_corpus_is_combining_false_for_ascii() {
5500 assert!(!IS_COMBINING('a'));
5501 assert!(!IS_COMBINING('Z'));
5502 assert!(!IS_COMBINING('0'));
5503 }
5504
5505 #[test]
5507 fn zshh_corpus_is_basechar_true_for_letters() {
5508 assert!(IS_BASECHAR('a'));
5509 assert!(IS_BASECHAR('A'));
5510 assert!(IS_BASECHAR('z'));
5511 assert!(IS_BASECHAR('日'));
5512 }
5513
5514 #[test]
5516 fn zshh_corpus_is_basechar_false_for_combining() {
5517 assert!(
5518 !IS_BASECHAR('\u{0301}'),
5519 "combining accent is not a base char"
5520 );
5521 }
5522
5523 #[test]
5525 fn zshh_corpus_pound_marker_in_imeta_range() {
5526 let p = Pound as u32;
5527 assert!(
5528 p >= 0x83 && p <= 0xa2,
5529 "Pound = {:#x} must be in imeta range 0x83..=0xa2",
5530 p
5531 );
5532 }
5533
5534 #[test]
5540 fn minimum_picks_smaller_int() {
5541 assert_eq!(minimum(3, 5), 3);
5542 assert_eq!(minimum(5, 3), 3);
5543 }
5544
5545 #[test]
5547 fn minimum_equal_values_returns_value() {
5548 assert_eq!(minimum(7, 7), 7);
5549 }
5550
5551 #[test]
5553 fn minimum_negative_picks_negative() {
5554 assert_eq!(minimum(-5, 5), -5);
5555 }
5556
5557 #[test]
5560 fn QT_IS_SINGLE_recognises_QT_SINGLE() {
5561 assert!(QT_IS_SINGLE(QT_SINGLE));
5562 }
5563
5564 #[test]
5566 fn QT_IS_SINGLE_QT_NONE_returns_false() {
5567 assert!(!QT_IS_SINGLE(QT_NONE));
5568 }
5569
5570 #[test]
5573 fn IS_WRITE_FILE_recognises_write_token() {
5574 assert!(IS_WRITE_FILE(REDIR_WRITE));
5575 }
5576
5577 #[test]
5579 fn IS_APPEND_REDIR_recognises_app_token() {
5580 assert!(IS_APPEND_REDIR(REDIR_APP));
5581 }
5582
5583 #[test]
5585 fn IS_ERROR_REDIR_recognises_errwrite_token() {
5586 assert!(IS_ERROR_REDIR(REDIR_ERRWRITE));
5587 }
5588
5589 #[test]
5591 fn IS_READFD_recognises_read_token() {
5592 assert!(IS_READFD(REDIR_READ));
5593 }
5594
5595 #[test]
5601 fn WCB_END_returns_wc_end_opcode() {
5602 let end = WCB_END();
5603 assert_eq!(wc_code(end), WC_END, "WCB_END encodes WC_END opcode");
5604 assert_eq!(wc_data(end), 0, "WCB_END encodes zero data");
5605 }
5606
5607 #[test]
5609 fn wc_bld_code_round_trip() {
5610 for opcode in [WC_END, WC_LIST, WC_SUBLIST, WC_PIPE] {
5611 let w = wc_bld(opcode, 42);
5612 assert_eq!(wc_code(w), opcode, "wc_code round-trips opcode {}", opcode);
5613 }
5614 }
5615
5616 #[test]
5618 fn wc_bld_data_round_trip() {
5619 for data in [0u32, 1, 42, 0xFFFF, 0x00FFFFFF] {
5620 let w = wc_bld(WC_LIST, data);
5621 assert_eq!(wc_data(w), data, "wc_data round-trips data {}", data);
5622 }
5623 }
5624
5625 #[test]
5627 fn WC_LIST_TYPE_reads_data_field() {
5628 let w = WCB_LIST(7, 0);
5629 assert_eq!(WC_LIST_TYPE(w), 7, "list type round-trips");
5630 }
5631
5632 #[test]
5634 fn WC_LIST_SKIP_round_trip() {
5635 let w = WCB_LIST(0, 100);
5636 assert_eq!(WC_LIST_SKIP(w), 100, "list skip round-trips");
5637 }
5638
5639 #[test]
5641 fn WC_SUBLIST_TYPE_masks_low_2_bits() {
5642 let w = WCB_SUBLIST(2, 0, 0); assert_eq!(WC_SUBLIST_TYPE(w), 2);
5644 }
5645
5646 #[test]
5648 fn WC_SUBLIST_FLAGS_masks_bits_2_through_4() {
5649 let w = WCB_SUBLIST(0, 0x04, 0); assert_eq!(WC_SUBLIST_FLAGS(w), 0x04);
5651 }
5652
5653 #[test]
5655 fn WC_PIPE_TYPE_masks_low_bit() {
5656 let w = WCB_PIPE(1, 100);
5657 assert_eq!(WC_PIPE_TYPE(w), 1);
5658 let w0 = WCB_PIPE(0, 100);
5659 assert_eq!(WC_PIPE_TYPE(w0), 0);
5660 }
5661
5662 #[test]
5664 fn WC_PIPE_LINENO_shifts_down_by_one() {
5665 let w = WCB_PIPE(0, 42);
5666 assert_eq!(WC_PIPE_LINENO(w), 42, "lineno round-trips through >> 1");
5667 }
5668
5669 #[test]
5671 fn IS_DASH_only_recognizes_hyphen() {
5672 assert!(IS_DASH('-'));
5673 assert!(!IS_DASH('+'));
5674 assert!(!IS_DASH(' '));
5675 assert!(!IS_DASH('a'));
5676 assert!(!IS_DASH('\0'));
5677 }
5678
5679 #[test]
5681 fn minimum_returns_smaller_value() {
5682 assert_eq!(minimum(3, 7), 3);
5683 assert_eq!(minimum(7, 3), 3);
5684 assert_eq!(
5685 minimum(5, 5),
5686 5,
5687 "equal → either (returns first per PartialOrd)"
5688 );
5689 assert_eq!(minimum(-10, 10), -10);
5690 }
5691
5692 #[test]
5694 fn minimum_works_with_floats() {
5695 assert_eq!(minimum(1.5_f64, 2.5_f64), 1.5);
5696 assert_eq!(minimum(-1.0_f64, 0.0_f64), -1.0);
5697 }
5698
5699 #[test]
5701 fn QT_IS_SINGLE_recognizes_single_quote() {
5702 assert!(QT_IS_SINGLE(crate::ported::zsh_h::QT_SINGLE));
5705 assert!(!QT_IS_SINGLE(0));
5706 assert!(!QT_IS_SINGLE(-1));
5707 }
5708
5709 #[test]
5715 fn WCB_SIMPLE_round_trips_argc() {
5716 for n in [0u32, 1, 42, 1000, 0xFFFF] {
5717 let w = WCB_SIMPLE(n);
5718 assert_eq!(WC_SIMPLE_ARGC(w), n, "argc {} must round-trip", n);
5719 }
5720 }
5721
5722 #[test]
5724 fn WCB_TYPESET_round_trips_argc() {
5725 for n in [0u32, 5, 100, 1000] {
5726 let w = WCB_TYPESET(n);
5727 assert_eq!(WC_TYPESET_ARGC(w), n);
5728 }
5729 }
5730
5731 #[test]
5733 fn WCB_SUBSH_round_trips_skip() {
5734 for o in [0u32, 1, 100, 0x10000] {
5735 let w = WCB_SUBSH(o);
5736 assert_eq!(WC_SUBSH_SKIP(w), o);
5737 }
5738 }
5739
5740 #[test]
5742 fn WCB_CURSH_round_trips_skip() {
5743 for o in [0u32, 1, 50, 500] {
5744 let w = WCB_CURSH(o);
5745 assert_eq!(WC_CURSH_SKIP(w), o);
5746 }
5747 }
5748
5749 #[test]
5751 fn WCB_TIMED_round_trips_type() {
5752 for t in [0u32, 1, 2] {
5753 let w = WCB_TIMED(t);
5754 assert_eq!(WC_TIMED_TYPE(w), t);
5755 }
5756 }
5757
5758 #[test]
5760 fn WCB_FUNCDEF_round_trips_skip() {
5761 for o in [0u32, 10, 100] {
5762 let w = WCB_FUNCDEF(o);
5763 assert_eq!(WC_FUNCDEF_SKIP(w), o);
5764 }
5765 }
5766
5767 #[test]
5770 fn WCB_FOR_packs_type_low_skip_high() {
5771 for t in [0u32, 1, 2, 3] {
5773 for o in [0u32, 10, 100] {
5774 let w = WCB_FOR(t, o);
5775 assert_eq!(WC_FOR_TYPE(w), t, "type round-trip for ({}, {})", t, o);
5776 assert_eq!(WC_FOR_SKIP(w), o, "skip round-trip for ({}, {})", t, o);
5777 }
5778 }
5779 }
5780
5781 #[test]
5783 fn WC_SELECT_TYPE_masks_low_bit() {
5784 let w = wc_bld(WC_SELECT, 3);
5786 assert_eq!(WC_SELECT_TYPE(w), 1);
5787 let w0 = wc_bld(WC_SELECT, 4);
5788 assert_eq!(WC_SELECT_TYPE(w0), 0, "0b100 & 1 = 0");
5789 }
5790
5791 #[test]
5793 fn WC_SELECT_SKIP_shifts_right_one() {
5794 let w = wc_bld(WC_SELECT, 42);
5795 assert_eq!(WC_SELECT_SKIP(w), 42 >> 1);
5796 }
5797
5798 #[test]
5800 fn WC_FOR_TYPE_only_uses_low_2_bits() {
5801 let w = wc_bld(WC_FOR, 0b1011);
5803 assert_eq!(WC_FOR_TYPE(w), 3);
5804 }
5805
5806 #[test]
5813 fn pm_scalar_is_zero() {
5814 assert_eq!(PM_SCALAR, 0, "PM_SCALAR is the default (no bits)");
5815 }
5816
5817 #[test]
5819 fn pm_type_flags_canonical_bit_positions() {
5820 assert_eq!(PM_ARRAY, 1 << 0, "c:3176");
5821 assert_eq!(PM_INTEGER, 1 << 1, "c:3178");
5822 assert_eq!(PM_EFLOAT, 1 << 2, "c:3180");
5823 assert_eq!(PM_FFLOAT, 1 << 3, "c:3182");
5824 assert_eq!(PM_HASHED, 1 << 4, "c:3184");
5825 }
5826
5827 #[test]
5829 fn pm_padding_case_flags_canonical_bit_positions() {
5830 assert_eq!(PM_LEFT, 1 << 5, "c:3186");
5831 assert_eq!(PM_RIGHT_B, 1 << 6, "c:3188");
5832 assert_eq!(PM_RIGHT_Z, 1 << 7, "c:3190");
5833 assert_eq!(PM_LOWER, 1 << 8, "c:3192");
5834 assert_eq!(PM_UPPER, 1 << 9, "c:3194");
5835 }
5836
5837 #[test]
5841 fn pm_undefined_aliases_pm_upper() {
5842 assert_eq!(
5843 PM_UNDEFINED, PM_UPPER,
5844 "c:3196 INTENTIONAL alias: undefined fns reuse UPPER bit"
5845 );
5846 }
5847
5848 #[test]
5851 fn pm_abspath_used_aliases_pm_exported() {
5852 assert_eq!(
5853 PM_ABSPATH_USED, PM_EXPORTED,
5854 "c:3204 INTENTIONAL alias: bit reuse for path-tracking"
5855 );
5856 }
5857
5858 #[test]
5860 fn pm_readonly_is_bit_10() {
5861 assert_eq!(PM_READONLY, 1 << 10);
5862 }
5863
5864 #[test]
5866 fn pm_flags_are_u32_type() {
5867 let _: u32 = PM_SCALAR;
5868 let _: u32 = PM_ARRAY;
5869 let _: u32 = PM_INTEGER;
5870 let _: u32 = PM_READONLY;
5871 }
5872
5873 #[test]
5876 fn pm_distinct_type_flags_pairwise_disjoint() {
5877 let codes = [
5878 PM_ARRAY, PM_INTEGER, PM_EFLOAT, PM_FFLOAT, PM_HASHED, PM_LEFT, PM_RIGHT_B, PM_RIGHT_Z,
5879 PM_LOWER, PM_UPPER,
5880 ];
5881 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
5882 assert_eq!(
5883 unique.len(),
5884 codes.len(),
5885 "distinct PM type/padding flags must be pairwise disjoint"
5886 );
5887 }
5888
5889 #[test]
5891 fn pm_distinct_type_flags_all_single_bits() {
5892 for &v in &[
5893 PM_ARRAY,
5894 PM_INTEGER,
5895 PM_EFLOAT,
5896 PM_FFLOAT,
5897 PM_HASHED,
5898 PM_LEFT,
5899 PM_RIGHT_B,
5900 PM_RIGHT_Z,
5901 PM_LOWER,
5902 PM_UPPER,
5903 PM_READONLY,
5904 PM_TAGGED,
5905 PM_EXPORTED,
5906 PM_UNIQUE,
5907 ] {
5908 assert!(
5909 v.is_power_of_two(),
5910 "PM_* flag {:#x} must be a single bit",
5911 v
5912 );
5913 }
5914 }
5915
5916 #[test]
5918 fn pm_scalar_zero_is_default_state() {
5919 assert_eq!(
5920 PM_SCALAR & (PM_ARRAY | PM_INTEGER | PM_HASHED),
5921 0,
5922 "PM_SCALAR=0 by design: clear-all-bits state"
5923 );
5924 }
5925
5926 #[test]
5934 fn print_canonical_bit_positions() {
5935 assert_eq!(PRINT_NAMEONLY, 1 << 0, "c:3400");
5936 assert_eq!(PRINT_TYPE, 1 << 1, "c:3402");
5937 assert_eq!(PRINT_LIST, 1 << 2, "c:3404");
5938 assert_eq!(PRINT_KV_PAIR, 1 << 3, "c:3406");
5939 assert_eq!(PRINT_INCLUDEVALUE, 1 << 4, "c:3408");
5940 assert_eq!(PRINT_TYPESET, 1 << 5, "c:3410");
5941 assert_eq!(PRINT_LINE, 1 << 6, "c:3412");
5942 assert_eq!(PRINT_POSIX_EXPORT, 1 << 7, "c:3414");
5943 assert_eq!(PRINT_POSIX_READONLY, 1 << 8, "c:3416");
5944 assert_eq!(PRINT_WITH_NAMESPACE, 1 << 9, "c:3418");
5945 }
5946
5947 #[test]
5951 fn print_whence_csh_aliases_print_posix_export() {
5952 assert_eq!(
5953 PRINT_WHENCE_CSH, PRINT_POSIX_EXPORT,
5954 "c:3420 INTENTIONAL alias: whence vs typeset disambiguated by builtin"
5955 );
5956 }
5957
5958 #[test]
5960 fn print_whence_verbose_aliases_print_posix_readonly() {
5961 assert_eq!(
5962 PRINT_WHENCE_VERBOSE, PRINT_POSIX_READONLY,
5963 "c:3422 INTENTIONAL alias"
5964 );
5965 }
5966
5967 #[test]
5969 fn print_whence_simple_aliases_print_with_namespace() {
5970 assert_eq!(
5971 PRINT_WHENCE_SIMPLE, PRINT_WITH_NAMESPACE,
5972 "c:3424 INTENTIONAL alias"
5973 );
5974 }
5975
5976 #[test]
5978 fn print_flags_are_i32_type() {
5979 let _: i32 = PRINT_NAMEONLY;
5980 let _: i32 = PRINT_TYPE;
5981 let _: i32 = PRINT_WHENCE_CSH;
5982 }
5983
5984 #[test]
5987 fn hist_canonical_bit_positions() {
5988 assert_eq!(HIST_MAKEUNIQUE, 0x01, "c:3452");
5989 assert_eq!(HIST_OLD, 0x02, "c:3454");
5990 assert_eq!(HIST_READ, 0x04, "c:3456");
5991 assert_eq!(HIST_DUP, 0x08, "c:3458");
5992 assert_eq!(HIST_FOREIGN, 0x10, "c:3460");
5993 assert_eq!(HIST_TMPSTORE, 0x20, "c:3462");
5994 assert_eq!(HIST_NOWRITE, 0x40, "c:3464");
5995 }
5996
5997 #[test]
5999 fn hist_flags_are_u32_type() {
6000 let _: u32 = HIST_MAKEUNIQUE;
6001 let _: u32 = HIST_OLD;
6002 let _: u32 = HIST_NOWRITE;
6003 }
6004
6005 #[test]
6007 fn hist_flags_all_single_bits() {
6008 for &v in &[
6009 HIST_MAKEUNIQUE,
6010 HIST_OLD,
6011 HIST_READ,
6012 HIST_DUP,
6013 HIST_FOREIGN,
6014 HIST_TMPSTORE,
6015 HIST_NOWRITE,
6016 ] {
6017 assert!(v.is_power_of_two(), "HIST_* {:#x} must be a single bit", v);
6018 }
6019 }
6020
6021 #[test]
6023 fn hist_flags_pairwise_distinct() {
6024 let codes = [
6025 HIST_MAKEUNIQUE,
6026 HIST_OLD,
6027 HIST_READ,
6028 HIST_DUP,
6029 HIST_FOREIGN,
6030 HIST_TMPSTORE,
6031 HIST_NOWRITE,
6032 ];
6033 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
6034 assert_eq!(
6035 unique.len(),
6036 codes.len(),
6037 "HIST_* must be pairwise distinct"
6038 );
6039 }
6040
6041 #[test]
6043 fn print_non_aliased_pairwise_distinct() {
6044 let codes = [
6045 PRINT_NAMEONLY,
6046 PRINT_TYPE,
6047 PRINT_LIST,
6048 PRINT_KV_PAIR,
6049 PRINT_INCLUDEVALUE,
6050 PRINT_TYPESET,
6051 PRINT_LINE,
6052 ];
6053 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
6054 assert_eq!(
6055 unique.len(),
6056 codes.len(),
6057 "non-aliased PRINT_* must be pairwise distinct"
6058 );
6059 }
6060}