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<LinkList>, }
1095
1096pub 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)]
1109#[derive(Clone)]
1110pub struct gsu_scalar {
1111 pub getfn: fn(pm: ¶m) -> String, pub setfn: fn(pm: &mut param, val: String), pub unsetfn: fn(pm: &mut param, exp: i32), }
1116#[allow(non_camel_case_types)]
1118#[derive(Clone)]
1119pub struct gsu_integer {
1120 pub getfn: fn(pm: ¶m) -> i64,
1122 pub setfn: fn(pm: &mut param, val: i64),
1124 pub unsetfn: fn(pm: &mut param, exp: i32),
1126}
1127#[allow(non_camel_case_types)]
1129#[derive(Clone)]
1130pub struct gsu_float {
1131 pub getfn: fn(pm: ¶m) -> f64,
1133 pub setfn: fn(pm: &mut param, val: f64),
1135 pub unsetfn: fn(pm: &mut param, exp: i32),
1137}
1138#[allow(non_camel_case_types)]
1140#[derive(Clone)]
1141pub struct gsu_array {
1142 pub getfn: fn(pm: ¶m) -> Vec<String>,
1144 pub setfn: fn(pm: &mut param, val: Vec<String>),
1146 pub unsetfn: fn(pm: &mut param, exp: i32),
1148}
1149#[allow(non_camel_case_types)]
1151#[derive(Clone)]
1152pub struct gsu_hash {
1153 pub getfn: fn(pm: ¶m) -> Option<&HashTable>,
1155 pub setfn: fn(pm: &mut param, val: HashTable),
1157 pub unsetfn: fn(pm: &mut param, exp: i32),
1159}
1160
1161#[allow(non_camel_case_types)]
1166#[derive(Clone, Default)]
1167pub struct param {
1168 pub node: hashnode, pub u_data: usize, 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, }
1190
1191#[allow(non_camel_case_types)]
1193pub struct tieddata {
1194 pub arrptr: Option<Vec<String>>, pub joinchar: i32, }
1198
1199#[allow(non_camel_case_types)]
1201pub struct repldata {
1202 pub b: i32, pub e: i32, pub replstr: Option<String>, }
1207pub type Repldata = Box<repldata>; #[allow(non_camel_case_types)]
1212#[derive(Default)]
1213pub struct paramdef {
1214 pub name: String, pub flags: i32, pub var: usize, pub gsu: usize, pub getnfn: Option<GetNodeFunc>, pub scantfn: Option<ScanTabFunc>, pub pm: Option<Param>, }
1223
1224#[allow(non_camel_case_types)]
1226#[derive(Clone)]
1227pub struct nameddir {
1228 pub node: hashnode, pub dir: String, pub diff: i32, }
1233
1234#[allow(non_camel_case_types)]
1236pub struct groupmap {
1237 pub name: String, pub gid: u32, }
1241pub type Groupmap = Box<groupmap>; #[allow(non_camel_case_types)]
1246pub struct groupset {
1247 pub array: Vec<groupmap>, pub num: i32, }
1251pub type Groupset = Box<groupset>; #[allow(non_camel_case_types)]
1256pub struct histent {
1257 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, }
1268
1269#[allow(non_camel_case_types)]
1271#[derive(Debug, Clone)]
1272pub struct emulation_options {
1273 pub emulation: i32, pub n_on_opts: i32, pub n_off_opts: i32, pub on_opts: Vec<OptIndex>, pub off_opts: Vec<OptIndex>, }
1280
1281#[allow(non_camel_case_types)]
1286#[derive(Debug, Clone)]
1287pub struct ttyinfo {
1288 #[cfg(unix)]
1290 pub tio: libc::termios, #[cfg(unix)]
1292 pub winsize: libc::winsize, }
1294
1295#[allow(non_camel_case_types)]
1297pub struct heapstack {
1298 pub next: Option<Heapstack>, pub used: usize, }
1302
1303#[allow(non_camel_case_types)]
1305pub struct heap {
1306 pub next: Option<Heap>, pub size: usize, pub used: usize, pub sp: Option<Heapstack>, }
1312
1313#[allow(non_camel_case_types)]
1315pub struct sortelt {
1316 pub orig: String, pub cmp: String, pub origlen: i32, pub len: i32, }
1322pub type SortElt = Box<sortelt>; #[allow(non_camel_case_types)]
1327pub struct hist_stack {
1328 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, }
1342
1343#[allow(non_camel_case_types)]
1345#[derive(Debug, Clone, Default)]
1346pub struct lexbufstate {
1347 pub ptr: Option<String>, pub siz: i32, pub len: i32, }
1352
1353#[allow(non_camel_case_types)]
1355#[derive(Debug, Clone, Default)]
1356pub struct lex_stack {
1357 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, }
1372
1373#[allow(non_camel_case_types)]
1375pub struct parse_stack {
1376 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, }
1396
1397#[allow(non_camel_case_types)]
1400#[derive(Debug, Clone)]
1401pub struct heredocs {
1402 pub next: Option<Box<heredocs>>, pub typ: i32, pub pc: i32, pub str: Option<String>, }
1408
1409#[allow(non_camel_case_types)]
1411pub struct execstack {
1412 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>, }
1435
1436#[allow(non_camel_case_types)]
1451#[derive(Debug, Clone)]
1452pub struct process {
1453 pub pid: i32, pub text: String, pub status: i32, pub ti: timeinfo, pub bgtime: Option<std::time::Instant>, pub endtime: Option<std::time::Instant>, }
1461
1462#[allow(non_camel_case_types)]
1474#[derive(Debug, Clone, Default)]
1475pub struct job {
1476 pub gleader: i32, pub other: i32, pub stat: i32, pub pwd: Option<String>, pub procs: Vec<process>, pub auxprocs: Vec<process>, pub filelist: Vec<String>, pub stty_in_env: i32, pub ty: Option<Box<ttyinfo>>, pub text: String,
1489}
1490
1491#[allow(non_camel_case_types)]
1493#[derive(Debug, Clone)]
1494pub struct funcdump {
1495 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>, }
1506
1507#[allow(non_camel_case_types)]
1509#[derive(Debug, Clone, Default)]
1510pub struct eprog {
1511 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>, }
1522
1523#[allow(non_camel_case_types)]
1525pub struct estate {
1526 pub prog: Eprog, pub pc: usize, pub strs: Option<String>, pub strs_offset: usize, }
1532
1533#[allow(non_camel_case_types)]
1535pub struct eccstr {
1536 pub left: Option<Eccstr>, pub right: Option<Eccstr>, pub str: Option<String>, pub offs: wordcode, pub aoffs: wordcode, pub nfunc: i32, pub hashval: u32, }
1545
1546pub 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;
1563pub const COND_AND: i32 = 1;
1565pub const COND_OR: i32 = 2;
1567pub const COND_STREQ: i32 = 3;
1569pub const COND_STRDEQ: i32 = 4;
1571pub const COND_STRNEQ: i32 = 5;
1573pub const COND_STRLT: i32 = 6;
1575pub const COND_STRGTR: i32 = 7;
1577pub const COND_NT: i32 = 8;
1579pub const COND_OT: i32 = 9;
1581pub const COND_EF: i32 = 10;
1583pub const COND_EQ: i32 = 11;
1585pub const COND_NE: i32 = 12;
1587pub const COND_LT: i32 = 13;
1589pub const COND_GT: i32 = 14;
1591pub const COND_LE: i32 = 15;
1593pub const COND_GE: i32 = 16;
1595pub const COND_REGEX: i32 = 17;
1597pub const COND_MOD: i32 = 18;
1599pub const COND_MODI: i32 = 19;
1601pub 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)]
1615#[derive(Clone)]
1616pub struct redir {
1617 pub typ: i32,
1620 pub flags: i32,
1622 pub fd1: i32,
1624 pub fd2: i32,
1626 pub name: Option<String>,
1628 pub varid: Option<String>,
1630 pub here_terminator: Option<String>,
1632 pub munged_here_terminator: Option<String>,
1634}
1635pub const MULTIOUNIT: usize = 8; #[allow(non_camel_case_types)]
1639pub struct multio {
1640 pub ct: i32,
1643 pub rflag: i32,
1645 pub pipe: i32,
1647 pub fds: Vec<i32>,
1652}
1653
1654#[allow(non_camel_case_types)]
1659pub struct value {
1660 pub pm: Option<Param>,
1663 pub arr: Vec<String>,
1665 pub scanflags: i32,
1667 pub valflags: i32,
1669 pub start: i32,
1671 pub end: i32,
1673}
1674pub const VALFLAG_INV: i32 = 0x0001; pub const VALFLAG_EMPTY: i32 = 0x0002;
1678pub const VALFLAG_SUBST: i32 = 0x0004;
1680pub const VALFLAG_REFSLICE: i32 = 0x0008;
1682pub const MAX_ARRLEN: i32 = 262144; #[allow(non_camel_case_types)]
1690pub 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;
1701pub const EF_MAP: i32 = 4;
1703pub const EF_RUN: i32 = 8;
1705pub 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]
1719#[allow(non_snake_case)]
1720pub fn wc_code(c: wordcode) -> wordcode {
1721 c & ((1 << WC_CODEBITS) - 1)
1722}
1723#[inline]
1725#[allow(non_snake_case)]
1726pub fn wc_data(c: wordcode) -> wordcode {
1727 c >> WC_CODEBITS
1728}
1729#[inline]
1731#[allow(non_snake_case)]
1732pub fn wc_bdata(d: wordcode) -> wordcode {
1733 d << WC_CODEBITS
1734}
1735#[inline]
1737#[allow(non_snake_case)]
1738pub fn wc_bld(c: wordcode, d: wordcode) -> wordcode {
1739 c | (d << WC_CODEBITS)
1740}
1741pub const WC_END: wordcode = 0;
1743pub const WC_LIST: wordcode = 1;
1745pub const WC_SUBLIST: wordcode = 2;
1747pub const WC_PIPE: wordcode = 3;
1749pub const WC_REDIR: wordcode = 4;
1751pub const WC_ASSIGN: wordcode = 5;
1753pub const WC_SIMPLE: wordcode = 6;
1755pub const WC_TYPESET: wordcode = 7;
1757pub const WC_SUBSH: wordcode = 8;
1759pub const WC_CURSH: wordcode = 9;
1761pub const WC_TIMED: wordcode = 10;
1763pub const WC_FUNCDEF: wordcode = 11;
1765pub const WC_FOR: wordcode = 12;
1767pub const WC_SELECT: wordcode = 13;
1769pub const WC_WHILE: wordcode = 14;
1771pub const WC_REPEAT: wordcode = 15;
1773pub const WC_CASE: wordcode = 16;
1775pub const WC_IF: wordcode = 17;
1777pub const WC_COND: wordcode = 18;
1779pub const WC_ARITH: wordcode = 19;
1781pub const WC_AUTOFN: wordcode = 20;
1783pub const WC_TRY: wordcode = 21;
1785pub const WC_COUNT: wordcode = 22;
1787pub 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;
1795pub const WC_SUBLIST_AND: wordcode = 1;
1797pub const WC_SUBLIST_OR: wordcode = 2;
1799pub const WC_SUBLIST_COPROC: wordcode = 4;
1801pub const WC_SUBLIST_NOT: wordcode = 8;
1803pub const WC_SUBLIST_SIMPLE: wordcode = 16;
1805pub const WC_SUBLIST_FREE: u32 = 5; pub const WC_PIPE_END: wordcode = 0;
1809pub const WC_PIPE_MID: wordcode = 1;
1811pub const WC_ASSIGN_SCALAR: wordcode = 0;
1813pub const WC_ASSIGN_ARRAY: wordcode = 1;
1815pub const WC_ASSIGN_NEW: wordcode = 0;
1817pub const WC_ASSIGN_INC: wordcode = 1;
1819pub const WC_TIMED_EMPTY: wordcode = 0;
1821pub const WC_TIMED_PIPE: wordcode = 1;
1823pub const WC_FOR_PPARAM: wordcode = 0;
1825pub const WC_FOR_LIST: wordcode = 1;
1827pub const WC_FOR_COND: wordcode = 2;
1829pub const WC_SELECT_PPARAM: wordcode = 0;
1831pub const WC_SELECT_LIST: wordcode = 1;
1833pub const WC_WHILE_WHILE: wordcode = 0;
1835pub const WC_WHILE_UNTIL: wordcode = 1;
1837pub const WC_CASE_HEAD: wordcode = 0;
1839pub const WC_CASE_OR: wordcode = 1;
1841pub const WC_CASE_AND: wordcode = 2;
1843pub const WC_CASE_TESTAND: wordcode = 3;
1845pub const WC_CASE_FREE: u32 = 3; pub const WC_IF_HEAD: wordcode = 0;
1849pub const WC_IF_IF: wordcode = 1;
1851pub const WC_IF_ELIF: wordcode = 2;
1853pub const WC_IF_ELSE: wordcode = 3;
1855
1856#[inline]
1863#[allow(non_snake_case)]
1864pub fn WCB_END() -> wordcode {
1865 wc_bld(WC_END, 0)
1866} #[inline]
1869#[allow(non_snake_case)]
1870pub fn WC_LIST_TYPE(c: wordcode) -> wordcode {
1871 wc_data(c)
1872} #[inline]
1875#[allow(non_snake_case)]
1876pub fn WC_LIST_SKIP(c: wordcode) -> wordcode {
1877 wc_data(c) >> WC_LIST_FREE
1878} #[inline]
1881#[allow(non_snake_case)]
1882pub fn WCB_LIST(t: wordcode, o: wordcode) -> wordcode {
1883 wc_bld(WC_LIST, t | (o << WC_LIST_FREE))
1884}
1885#[inline]
1887#[allow(non_snake_case)]
1888pub fn WC_SUBLIST_TYPE(c: wordcode) -> wordcode {
1889 wc_data(c) & 3
1890} #[inline]
1893#[allow(non_snake_case)]
1894pub fn WC_SUBLIST_FLAGS(c: wordcode) -> wordcode {
1895 wc_data(c) & 0x1c
1896} #[inline]
1899#[allow(non_snake_case)]
1900pub fn WC_SUBLIST_SKIP(c: wordcode) -> wordcode {
1901 wc_data(c) >> WC_SUBLIST_FREE
1902}
1903#[inline]
1905#[allow(non_snake_case)]
1906pub fn WCB_SUBLIST(t: wordcode, f: wordcode, o: wordcode) -> wordcode {
1907 wc_bld(WC_SUBLIST, t | f | (o << WC_SUBLIST_FREE))
1908}
1909#[inline]
1911#[allow(non_snake_case)]
1912pub fn WC_PIPE_TYPE(c: wordcode) -> wordcode {
1913 wc_data(c) & 1
1914} #[inline]
1917#[allow(non_snake_case)]
1918pub fn WC_PIPE_LINENO(c: wordcode) -> wordcode {
1919 wc_data(c) >> 1
1920}
1921#[inline]
1923#[allow(non_snake_case)]
1924pub fn WCB_PIPE(t: wordcode, l: wordcode) -> wordcode {
1925 wc_bld(WC_PIPE, t | (l << 1))
1926}
1927#[inline]
1929#[allow(non_snake_case)]
1930pub fn WC_REDIR_TYPE(c: wordcode) -> i32 {
1931 (wc_data(c) & REDIR_TYPE_MASK as u32) as i32
1932}
1933#[inline]
1935#[allow(non_snake_case)]
1936pub fn WC_REDIR_VARID(c: wordcode) -> i32 {
1937 (wc_data(c) & REDIR_VARID_MASK as u32) as i32
1938}
1939#[inline]
1941#[allow(non_snake_case)]
1942pub fn WC_REDIR_FROM_HEREDOC(c: wordcode) -> i32 {
1943 (wc_data(c) & REDIR_FROM_HEREDOC_MASK as u32) as i32
1944}
1945#[inline]
1947#[allow(non_snake_case)]
1948pub fn WCB_REDIR(t: wordcode) -> wordcode {
1949 wc_bld(WC_REDIR, t)
1950}
1951#[inline]
1953#[allow(non_snake_case)]
1954pub fn WC_REDIR_WORDS(c: wordcode) -> i32 {
1955 (if WC_REDIR_VARID(c) != 0 { 4 } else { 3 })
1956 + (if WC_REDIR_FROM_HEREDOC(c) != 0 { 2 } else { 0 })
1957}
1958#[inline]
1960#[allow(non_snake_case)]
1961pub fn WC_ASSIGN_TYPE(c: wordcode) -> wordcode {
1962 wc_data(c) & 1
1963} #[inline]
1966#[allow(non_snake_case)]
1967pub fn WC_ASSIGN_TYPE2(c: wordcode) -> wordcode {
1968 (wc_data(c) & 2) >> 1
1969}
1970#[inline]
1972#[allow(non_snake_case)]
1973pub fn WC_ASSIGN_NUM(c: wordcode) -> wordcode {
1974 wc_data(c) >> 2
1975}
1976#[inline]
1978#[allow(non_snake_case)]
1979pub fn WCB_ASSIGN(t: wordcode, a: wordcode, n: wordcode) -> wordcode {
1980 wc_bld(WC_ASSIGN, t | (a << 1) | (n << 2))
1981}
1982#[inline]
1984#[allow(non_snake_case)]
1985pub fn WC_SIMPLE_ARGC(c: wordcode) -> wordcode {
1986 wc_data(c)
1987} #[inline]
1990#[allow(non_snake_case)]
1991pub fn WCB_SIMPLE(n: wordcode) -> wordcode {
1992 wc_bld(WC_SIMPLE, n)
1993}
1994#[inline]
1996#[allow(non_snake_case)]
1997pub fn WC_TYPESET_ARGC(c: wordcode) -> wordcode {
1998 wc_data(c)
1999} #[inline]
2002#[allow(non_snake_case)]
2003pub fn WCB_TYPESET(n: wordcode) -> wordcode {
2004 wc_bld(WC_TYPESET, n)
2005}
2006#[inline]
2008#[allow(non_snake_case)]
2009pub fn WC_SUBSH_SKIP(c: wordcode) -> wordcode {
2010 wc_data(c)
2011} #[inline]
2014#[allow(non_snake_case)]
2015pub fn WCB_SUBSH(o: wordcode) -> wordcode {
2016 wc_bld(WC_SUBSH, o)
2017}
2018#[inline]
2020#[allow(non_snake_case)]
2021pub fn WC_CURSH_SKIP(c: wordcode) -> wordcode {
2022 wc_data(c)
2023} #[inline]
2026#[allow(non_snake_case)]
2027pub fn WCB_CURSH(o: wordcode) -> wordcode {
2028 wc_bld(WC_CURSH, o)
2029}
2030#[inline]
2032#[allow(non_snake_case)]
2033pub fn WC_TIMED_TYPE(c: wordcode) -> wordcode {
2034 wc_data(c)
2035} #[inline]
2038#[allow(non_snake_case)]
2039pub fn WCB_TIMED(t: wordcode) -> wordcode {
2040 wc_bld(WC_TIMED, t)
2041}
2042#[inline]
2044#[allow(non_snake_case)]
2045pub fn WC_FUNCDEF_SKIP(c: wordcode) -> wordcode {
2046 wc_data(c)
2047} #[inline]
2050#[allow(non_snake_case)]
2051pub fn WCB_FUNCDEF(o: wordcode) -> wordcode {
2052 wc_bld(WC_FUNCDEF, o)
2053}
2054#[inline]
2056#[allow(non_snake_case)]
2057pub fn WC_FOR_TYPE(c: wordcode) -> wordcode {
2058 wc_data(c) & 3
2059} #[inline]
2062#[allow(non_snake_case)]
2063pub fn WC_FOR_SKIP(c: wordcode) -> wordcode {
2064 wc_data(c) >> 2
2065}
2066#[inline]
2068#[allow(non_snake_case)]
2069pub fn WCB_FOR(t: wordcode, o: wordcode) -> wordcode {
2070 wc_bld(WC_FOR, t | (o << 2))
2071}
2072#[inline]
2074#[allow(non_snake_case)]
2075pub fn WC_SELECT_TYPE(c: wordcode) -> wordcode {
2076 wc_data(c) & 1
2077} #[inline]
2080#[allow(non_snake_case)]
2081pub fn WC_SELECT_SKIP(c: wordcode) -> wordcode {
2082 wc_data(c) >> 1
2083}
2084#[inline]
2086#[allow(non_snake_case)]
2087pub fn WCB_SELECT(t: wordcode, o: wordcode) -> wordcode {
2088 wc_bld(WC_SELECT, t | (o << 1))
2089}
2090#[inline]
2092#[allow(non_snake_case)]
2093pub fn WC_WHILE_TYPE(c: wordcode) -> wordcode {
2094 wc_data(c) & 1
2095} #[inline]
2098#[allow(non_snake_case)]
2099pub fn WC_WHILE_SKIP(c: wordcode) -> wordcode {
2100 wc_data(c) >> 1
2101}
2102#[inline]
2104#[allow(non_snake_case)]
2105pub fn WCB_WHILE(t: wordcode, o: wordcode) -> wordcode {
2106 wc_bld(WC_WHILE, t | (o << 1))
2107}
2108#[inline]
2110#[allow(non_snake_case)]
2111pub fn WC_REPEAT_SKIP(c: wordcode) -> wordcode {
2112 wc_data(c)
2113} #[inline]
2116#[allow(non_snake_case)]
2117pub fn WCB_REPEAT(o: wordcode) -> wordcode {
2118 wc_bld(WC_REPEAT, o)
2119}
2120#[inline]
2122#[allow(non_snake_case)]
2123pub fn WC_TRY_SKIP(c: wordcode) -> wordcode {
2124 wc_data(c)
2125} #[inline]
2128#[allow(non_snake_case)]
2129pub fn WCB_TRY(o: wordcode) -> wordcode {
2130 wc_bld(WC_TRY, o)
2131}
2132#[inline]
2134#[allow(non_snake_case)]
2135pub fn WC_CASE_TYPE(c: wordcode) -> wordcode {
2136 wc_data(c) & 7
2137} #[inline]
2140#[allow(non_snake_case)]
2141pub fn WC_CASE_SKIP(c: wordcode) -> wordcode {
2142 wc_data(c) >> WC_CASE_FREE
2143}
2144#[inline]
2146#[allow(non_snake_case)]
2147pub fn WCB_CASE(t: wordcode, o: wordcode) -> wordcode {
2148 wc_bld(WC_CASE, t | (o << WC_CASE_FREE))
2149}
2150#[inline]
2152#[allow(non_snake_case)]
2153pub fn WC_IF_TYPE(c: wordcode) -> wordcode {
2154 wc_data(c) & 3
2155} #[inline]
2158#[allow(non_snake_case)]
2159pub fn WC_IF_SKIP(c: wordcode) -> wordcode {
2160 wc_data(c) >> 2
2161}
2162#[inline]
2164#[allow(non_snake_case)]
2165pub fn WCB_IF(t: wordcode, o: wordcode) -> wordcode {
2166 wc_bld(WC_IF, t | (o << 2))
2167}
2168#[inline]
2170#[allow(non_snake_case)]
2171pub fn WC_COND_TYPE(c: wordcode) -> wordcode {
2172 wc_data(c) & 127
2173} #[inline]
2176#[allow(non_snake_case)]
2177pub fn WC_COND_SKIP(c: wordcode) -> wordcode {
2178 wc_data(c) >> 7
2179}
2180#[inline]
2182#[allow(non_snake_case)]
2183pub fn WCB_COND(t: wordcode, o: wordcode) -> wordcode {
2184 wc_bld(WC_COND, t | (o << 7))
2185}
2186#[inline]
2188#[allow(non_snake_case)]
2189pub fn WCB_ARITH() -> wordcode {
2190 wc_bld(WC_ARITH, 0)
2191} #[inline]
2194#[allow(non_snake_case)]
2195pub fn WCB_AUTOFN() -> wordcode {
2196 wc_bld(WC_AUTOFN, 0)
2197} pub const NULLBINCMD: Option<HandlerFunc> = None; #[inline]
2210#[allow(non_snake_case)]
2211pub fn EMULATION(x: i32) -> bool {
2212 let emul = crate::ported::options::emulation.load(std::sync::atomic::Ordering::Relaxed);
2214 (emul & x) != 0
2215}
2216
2217#[inline]
2221#[allow(non_snake_case)]
2222pub fn SHELL_EMULATION() -> i32 {
2223 let emul = crate::ported::options::emulation.load(std::sync::atomic::Ordering::Relaxed);
2225 emul & ((1 << 5) - 1)
2226}
2227
2228#[inline]
2235#[allow(non_snake_case)]
2236pub fn IN_EVAL_TRAP() -> bool {
2237 crate::ported::signals::intrap.load(Ordering::Relaxed) != 0
2239 && crate::ported::signals::trapisfunc.load(Ordering::Relaxed) == 0
2240 && crate::ported::signals::traplocallevel.load(Ordering::Relaxed)
2241 == crate::ported::params::locallevel.load(Ordering::Relaxed)
2242}
2243
2244#[inline]
2246#[allow(non_snake_case)]
2247pub fn ASG_ARRAYP(asg: &asgment) -> bool {
2248 (asg.flags & ASG_ARRAY) != 0
2249}
2250
2251#[inline]
2253#[allow(non_snake_case)]
2254pub fn ASG_VALUEP(asg: &asgment) -> bool {
2255 ASG_ARRAYP(asg) || asg.scalar.is_some()
2256}
2257
2258#[inline]
2263#[allow(non_snake_case)]
2264pub fn MB_METASTRLEN2END(s: &str, widthp: bool, eptr: usize) -> usize {
2265 let truncated = if eptr <= s.len() { &s[..eptr] } else { s };
2266 MB_METASTRLEN2(truncated, widthp)
2267}
2268
2269pub 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;
2292pub const ALLOWHIST: i32 = ALLOWHIST_DELTA;
2294
2295pub const EXITHOOK: usize = EXITHOOK_OFFSET;
2298pub const BEFORETRAPHOOK: usize = BEFORETRAPHOOK_OFFSET;
2300pub const AFTERTRAPHOOK: usize = AFTERTRAPHOOK_OFFSET;
2302pub const GETCOLORATTR: usize = GETCOLORATTR_OFFSET;
2304
2305#[inline]
2310#[allow(non_snake_case)]
2311pub const fn ZLONG_CONST(x: i64) -> zlong {
2312 x
2313} #[macro_export]
2319macro_rules! STRINGIFY_LITERAL {
2320 ($x:tt) => {
2321 stringify!($x)
2322 };
2323}
2324
2325#[macro_export]
2328macro_rules! STRINGIFY {
2329 ($x:tt) => {
2330 $crate::STRINGIFY_LITERAL!($x)
2331 };
2332}
2333
2334#[macro_export]
2337macro_rules! ERRMSG {
2338 ($msg:expr) => {
2339 concat!(file!(), ":", line!(), ": ", $msg)
2340 };
2341}
2342
2343pub const HEAPID_FMT: &str = "{:x}"; #[macro_export]
2352macro_rules! HEAP_ERROR {
2353 ($heap_id:expr) => {
2354 eprintln!(
2355 "{}:{}: HEAP DEBUG: invalid heap: {:x}.",
2356 file!(),
2357 line!(),
2358 $heap_id
2359 )
2360 };
2361}
2362
2363#[macro_export]
2380macro_rules! DPUTS {
2381 ($x:expr, $y:expr) => {
2383 #[cfg(feature = "zsh-debug")] {
2386 if $x {
2387 crate::ported::utils::dputs(&format!(
2389 "{}:{}: {}",
2391 file!(),
2392 line!(),
2393 $y )); } } }; } #[macro_export]
2412macro_rules! DPUTS1 {
2413 ($x:expr, $y:expr, $z1:expr) => {
2415 #[cfg(feature = "zsh-debug")] {
2418 if $x {
2419 crate::ported::utils::dputs(&format!(
2421 "{}:{}: {}",
2423 file!(),
2424 line!(),
2425 format!($y, $z1) )); } } }; } #[macro_export]
2437macro_rules! DPUTS2 {
2438 ($x:expr, $y:expr, $z1:expr, $z2:expr) => {
2440 #[cfg(feature = "zsh-debug")] {
2443 if $x {
2444 crate::ported::utils::dputs(&format!(
2446 "{}:{}: {}",
2448 file!(),
2449 line!(),
2450 format!($y, $z1, $z2) )); } } }; } #[macro_export]
2462macro_rules! DPUTS3 {
2463 ($x:expr, $y:expr, $z1:expr, $z2:expr, $z3:expr) => {
2465 #[cfg(feature = "zsh-debug")] {
2468 if $x {
2469 crate::ported::utils::dputs(&format!(
2471 "{}:{}: {}",
2473 file!(),
2474 line!(),
2475 format!($y, $z1, $z2, $z3) )); } } }; } pub const SGTTYFLAG_NAME: &str = "tio.c_oflag";
2487
2488pub const SGTTYFLAG: &str = SGTTYFLAG_NAME;
2491
2492#[cfg(target_os = "linux")]
2496pub const SGTABTYPE: u32 = libc::XTABS;
2497#[cfg(not(target_os = "linux"))]
2499pub const SGTABTYPE: u32 = 0;
2500
2501#[inline]
2504#[allow(non_snake_case)]
2505pub fn ZWS(s: &str) -> &str {
2506 s
2507}
2508
2509#[inline]
2521#[allow(non_snake_case)]
2522pub fn BUILTIN(
2523 name: &str,
2524 flags: i32,
2525 handler: Option<HandlerFunc>,
2526 min: i32,
2527 max: i32,
2528 funcid: i32,
2529 optstr: Option<&str>,
2530 defopts: Option<&str>,
2531) -> builtin {
2532 builtin {
2533 node: hashnode {
2534 next: None,
2535 nam: name.to_string(),
2536 flags,
2537 },
2538 handlerfunc: handler,
2539 minargs: min,
2540 maxargs: max,
2541 funcid,
2542 optstr: optstr.map(|s| s.to_string()),
2543 defopts: defopts.map(|s| s.to_string()),
2544 }
2545}
2546
2547#[inline]
2550#[allow(non_snake_case)]
2551pub fn BIN_PREFIX(name: &str, flags: i32) -> builtin {
2552 BUILTIN(
2553 name,
2554 flags | BINF_PREFIX as i32,
2555 NULLBINCMD,
2556 0,
2557 0,
2558 0,
2559 None,
2560 None,
2561 )
2562}
2563
2564#[inline]
2567#[allow(non_snake_case)]
2568pub fn CONDDEF(
2569 name: &str,
2570 flags: i32,
2571 handler: CondHandler,
2572 min: i32,
2573 max: i32,
2574 condid: i32,
2575) -> conddef {
2576 conddef {
2577 next: None,
2578 name: name.to_string(),
2579 flags,
2580 handler: Some(handler),
2581 min,
2582 max,
2583 condid,
2584 module: None,
2585 }
2586}
2587
2588#[inline]
2592#[allow(non_snake_case)]
2593pub fn HOOKDEF(name: &str, func: Option<Hookfn>, flags: i32) -> hookdef {
2594 hookdef {
2595 next: std::ptr::null_mut(),
2596 name: name.to_string(),
2597 def: func,
2598 flags,
2599 funcs: std::ptr::null_mut(),
2600 }
2601}
2602
2603#[inline]
2605#[allow(non_snake_case)]
2606pub fn NUMMATHFUNC(name: &str, func: NumMathFunc, min: i32, max: i32, id: i32) -> mathfunc {
2607 mathfunc {
2608 next: None,
2609 name: name.to_string(),
2610 flags: 0,
2611 nfunc: Some(func),
2612 sfunc: None,
2613 module: None,
2614 minargs: min,
2615 maxargs: max,
2616 funcid: id,
2617 }
2618}
2619
2620#[inline]
2622#[allow(non_snake_case)]
2623pub fn STRMATHFUNC(name: &str, func: StrMathFunc, id: i32) -> mathfunc {
2624 mathfunc {
2625 next: None,
2626 name: name.to_string(),
2627 flags: MFF_STR,
2628 nfunc: None,
2629 sfunc: Some(func),
2630 module: None,
2631 minargs: 0,
2632 maxargs: 0,
2633 funcid: id,
2634 }
2635}
2636
2637#[inline]
2639#[allow(non_snake_case)]
2640pub fn PARAMDEF(name: &str, flags: i32, var: usize, gsu: usize) -> paramdef {
2641 paramdef {
2642 name: name.to_string(),
2643 flags,
2644 var,
2645 gsu,
2646 getnfn: None,
2647 scantfn: None,
2648 pm: None,
2649 }
2650}
2651
2652#[inline]
2654#[allow(non_snake_case)]
2655pub fn INTPARAMDEF(name: &str, var: usize) -> paramdef {
2656 PARAMDEF(name, PM_INTEGER as i32, var, 0)
2657}
2658
2659#[inline]
2661#[allow(non_snake_case)]
2662pub fn STRPARAMDEF(name: &str, var: usize) -> paramdef {
2663 PARAMDEF(name, PM_SCALAR as i32, var, 0)
2664}
2665
2666#[inline]
2668#[allow(non_snake_case)]
2669pub fn ARRPARAMDEF(name: &str, var: usize) -> paramdef {
2670 PARAMDEF(name, PM_ARRAY as i32, var, 0)
2671}
2672
2673#[inline]
2676#[allow(non_snake_case)]
2677pub fn SPECIALPMDEF(
2678 name: &str,
2679 flags: i32,
2680 gsufn: usize,
2681 getfn: Option<GetNodeFunc>,
2682 scanfn: Option<ScanTabFunc>,
2683) -> paramdef {
2684 paramdef {
2685 name: name.to_string(),
2686 flags: flags | (PM_SPECIAL | PM_HIDE | PM_HIDEVAL) as i32,
2687 var: 0,
2688 gsu: gsufn,
2689 getnfn: getfn,
2690 scantfn: scanfn,
2691 pm: None,
2692 }
2693}
2694#[inline]
2696#[allow(non_snake_case)]
2697pub fn WRAPDEF(func: WrapFunc) -> funcwrap {
2698 funcwrap {
2699 next: None,
2700 flags: 0,
2701 handler: Some(func),
2702 module: None,
2703 }
2704}
2705
2706#[allow(non_camel_case_types)]
2711pub struct jobfile {
2712 pub name: Option<String>,
2715 pub fd: i32,
2717 pub is_fd: i32,
2719}
2720pub const STAT_CHANGED: i32 = 0x0001; pub const STAT_STOPPED: i32 = 0x0002;
2724pub const STAT_TIMED: i32 = 0x0004;
2726pub const STAT_DONE: i32 = 0x0008;
2728pub const STAT_LOCKED: i32 = 0x0010;
2730pub const STAT_NOPRINT: i32 = 0x0020;
2732pub const STAT_INUSE: i32 = 0x0040;
2734pub const STAT_SUPERJOB: i32 = 0x0080;
2736pub const STAT_SUBJOB: i32 = 0x0100;
2738pub const STAT_WASSUPER: i32 = 0x0200;
2740pub const STAT_CURSH: i32 = 0x0400;
2742pub const STAT_NOSTTY: i32 = 0x0800;
2744pub const STAT_ATTACH: i32 = 0x1000;
2746pub const STAT_SUBLEADER: i32 = 0x2000;
2748pub const STAT_BUILTIN: i32 = 0x4000;
2750pub const STAT_SUBJOB_ORPHANED: i32 = 0x8000;
2752pub 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)]
2769#[derive(Debug, Clone, Default)]
2770pub struct timeinfo {
2771 pub ut: i64,
2777 pub st: i64,
2779 pub maxrss: i64,
2781 pub majflt: i64,
2783 pub minflt: i64,
2785 pub nswap: i64,
2787 pub ixrss: i64,
2789 pub idrss: i64,
2791 pub isrss: i64,
2793 pub inblock: i64,
2795 pub oublock: i64,
2797 pub nvcsw: i64,
2799 pub nivcsw: i64,
2801 pub msgsnd: i64,
2803 pub msgrcv: i64,
2805 pub nsignals: i64,
2807}
2808
2809impl timeinfo {
2810 pub fn user_dur(&self) -> std::time::Duration {
2812 std::time::Duration::from_micros(self.ut as u64)
2813 }
2814 pub fn sys_dur(&self) -> std::time::Duration {
2816 std::time::Duration::from_micros(self.st as u64)
2817 }
2818
2819 #[cfg(unix)]
2823 pub fn from_rusage(r: &libc::rusage) -> Self {
2824 let ut = r.ru_utime.tv_sec as i64 * 1_000_000 + r.ru_utime.tv_usec as i64;
2825 let st = r.ru_stime.tv_sec as i64 * 1_000_000 + r.ru_stime.tv_usec as i64;
2826 #[cfg(target_os = "macos")]
2827 let maxrss = r.ru_maxrss / 1024;
2828 #[cfg(not(target_os = "macos"))]
2829 let maxrss = r.ru_maxrss as i64;
2830 Self {
2831 ut,
2832 st,
2833 maxrss: maxrss as i64,
2834 majflt: r.ru_majflt as i64,
2835 minflt: r.ru_minflt as i64,
2836 nswap: r.ru_nswap as i64,
2837 ixrss: r.ru_ixrss as i64,
2838 idrss: r.ru_idrss as i64,
2839 isrss: r.ru_isrss as i64,
2840 inblock: r.ru_inblock as i64,
2841 oublock: r.ru_oublock as i64,
2842 nvcsw: r.ru_nvcsw as i64,
2843 nivcsw: r.ru_nivcsw as i64,
2844 msgsnd: r.ru_msgsnd as i64,
2845 msgrcv: r.ru_msgrcv as i64,
2846 nsignals: r.ru_nsignals as i64,
2847 }
2848 }
2849}
2850
2851pub 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;
2874pub const SFC_SIGNAL: i32 = 2;
2876pub const SFC_HOOK: i32 = 3;
2878pub const SFC_WIDGET: i32 = 4;
2880pub const SFC_COMPLETE: i32 = 5;
2882pub const SFC_CWIDGET: i32 = 6;
2884pub const SFC_SUBST: i32 = 7;
2886pub const FS_SOURCE: i32 = 0; pub const FS_FUNC: i32 = 1;
2890pub const FS_EVAL: i32 = 2;
2892pub 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)]
2906#[derive(Clone)]
2907pub struct options {
2908 pub ind: [u8; MAX_OPS],
2910 pub args: Vec<String>,
2912 pub argscount: i32,
2914 pub argsalloc: i32,
2916}
2917pub const PARSEARGS_TOPLEVEL: i32 = 0x1; pub const PARSEARGS_LOGIN: i32 = 0x2; #[inline]
2931#[allow(non_snake_case)]
2932pub fn OPT_MINUS(ops: &options, c: u8) -> bool {
2933 (ops.ind[c as usize] & 1) != 0
2934}
2935
2936#[inline]
2939#[allow(non_snake_case)]
2940pub fn OPT_PLUS(ops: &options, c: u8) -> bool {
2941 (ops.ind[c as usize] & 2) != 0
2942}
2943
2944#[inline]
2947#[allow(non_snake_case)]
2948pub fn OPT_ISSET(ops: &options, c: u8) -> bool {
2949 ops.ind[c as usize] != 0
2950}
2951
2952#[inline]
2955#[allow(non_snake_case)]
2956pub fn OPT_HASARG(ops: &options, c: u8) -> bool {
2957 ops.ind[c as usize] > 3
2958}
2959
2960pub type HandlerFunc = fn(name: &str, args: &[String], ops: &options, funcid: i32) -> i32;
2965pub 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;
3031pub const PAT_FILET: i32 = 0x0002;
3033pub const PAT_ANY: i32 = 0x0004;
3035pub const PAT_NOANCH: i32 = 0x0008;
3037pub const PAT_NOGLD: i32 = 0x0010;
3039pub const PAT_PURES: i32 = 0x0020;
3041pub const PAT_STATIC: i32 = 0x0040;
3043pub const PAT_SCAN: i32 = 0x0080;
3045pub const PAT_ZDUP: i32 = 0x0100;
3047pub const PAT_NOTSTART: i32 = 0x0200;
3049pub const PAT_NOTEND: i32 = 0x0400;
3051pub const PAT_HAS_EXCLUDP: i32 = 0x0800;
3053pub const PAT_LCMATCHUC: i32 = 0x1000;
3055
3056pub const ZPC_SLASH: i32 = 0;
3061pub const ZPC_NULL: i32 = 1;
3063pub const ZPC_BAR: i32 = 2;
3065pub const ZPC_OUTPAR: i32 = 3;
3067pub const ZPC_TILDE: i32 = 4;
3069pub const ZPC_SEG_COUNT: i32 = 5;
3071pub const ZPC_INPAR: i32 = ZPC_SEG_COUNT;
3073pub const ZPC_QUEST: i32 = ZPC_SEG_COUNT + 1;
3075pub const ZPC_STAR: i32 = ZPC_SEG_COUNT + 2;
3077pub const ZPC_INBRACK: i32 = ZPC_SEG_COUNT + 3;
3079pub const ZPC_INANG: i32 = ZPC_SEG_COUNT + 4;
3081pub const ZPC_HAT: i32 = ZPC_SEG_COUNT + 5;
3083pub const ZPC_HASH: i32 = ZPC_SEG_COUNT + 6;
3085pub const ZPC_BNULLKEEP: i32 = ZPC_SEG_COUNT + 7;
3087pub const ZPC_NO_KSH_GLOB: i32 = ZPC_SEG_COUNT + 8;
3089pub const ZPC_KSH_QUEST: i32 = ZPC_NO_KSH_GLOB;
3091pub const ZPC_KSH_STAR: i32 = ZPC_NO_KSH_GLOB + 1;
3093pub const ZPC_KSH_PLUS: i32 = ZPC_NO_KSH_GLOB + 2;
3095pub const ZPC_KSH_BANG: i32 = ZPC_NO_KSH_GLOB + 3;
3097pub const ZPC_KSH_BANG2: i32 = ZPC_NO_KSH_GLOB + 4;
3099pub const ZPC_KSH_AT: i32 = ZPC_NO_KSH_GLOB + 5;
3101pub const ZPC_COUNT: i32 = ZPC_NO_KSH_GLOB + 6;
3103
3104pub const PP_FIRST: i32 = 1;
3109pub const PP_ALPHA: i32 = 1;
3111pub const PP_ALNUM: i32 = 2;
3113pub const PP_ASCII: i32 = 3;
3115pub const PP_BLANK: i32 = 4;
3117pub const PP_CNTRL: i32 = 5;
3119pub const PP_DIGIT: i32 = 6;
3121pub const PP_GRAPH: i32 = 7;
3123pub const PP_LOWER: i32 = 8;
3125pub const PP_PRINT: i32 = 9;
3127pub const PP_PUNCT: i32 = 10;
3129pub const PP_SPACE: i32 = 11;
3131pub const PP_UPPER: i32 = 12;
3133pub const PP_XDIGIT: i32 = 13;
3135pub const PP_IDENT: i32 = 14;
3137pub const PP_IFS: i32 = 15;
3139pub const PP_IFSSPACE: i32 = 16;
3141pub const PP_WORD: i32 = 17;
3143pub const PP_INCOMPLETE: i32 = 18;
3145pub const PP_INVALID: i32 = 19;
3147pub const PP_LAST: i32 = 19;
3149pub const PP_UNKWN: i32 = 20;
3151pub const PP_RANGE: i32 = 21;
3153pub const GF_LCMATCHUC: i32 = 0x0100;
3155pub const GF_IGNCASE: i32 = 0x0200;
3157pub const GF_BACKREF: i32 = 0x0400;
3159pub const GF_MATCHREF: i32 = 0x0800;
3161pub const GF_MULTIBYTE: i32 = 0x1000;
3163pub const ZMB_VALID: i32 = 0;
3165pub const ZMB_INCOMPLETE: i32 = 1;
3167pub const ZMB_INVALID: i32 = 2;
3169
3170pub const PM_SCALAR: u32 = 0;
3175pub const PM_ARRAY: u32 = 1 << 0;
3177pub const PM_INTEGER: u32 = 1 << 1;
3179pub const PM_EFLOAT: u32 = 1 << 2;
3181pub const PM_FFLOAT: u32 = 1 << 3;
3183pub const PM_HASHED: u32 = 1 << 4;
3185pub const PM_LEFT: u32 = 1 << 5;
3187pub const PM_RIGHT_B: u32 = 1 << 6;
3189pub const PM_RIGHT_Z: u32 = 1 << 7;
3191pub const PM_LOWER: u32 = 1 << 8;
3193pub const PM_UPPER: u32 = 1 << 9;
3195pub const PM_UNDEFINED: u32 = 1 << 9;
3197pub const PM_READONLY: u32 = 1 << 10;
3199pub const PM_TAGGED: u32 = 1 << 11;
3201pub const PM_EXPORTED: u32 = 1 << 12;
3203pub const PM_ABSPATH_USED: u32 = 1 << 12;
3205pub const PM_UNIQUE: u32 = 1 << 13;
3207pub const PM_UNALIASED: u32 = 1 << 13;
3209pub const PM_HIDE: u32 = 1 << 14;
3211pub const PM_CUR_FPATH: u32 = 1 << 14;
3213pub const PM_HIDEVAL: u32 = 1 << 15;
3215pub const PM_WARNNESTED: u32 = 1 << 15;
3217pub const PM_TIED: u32 = 1 << 16;
3219pub const PM_TAGGED_LOCAL: u32 = 1 << 16;
3221pub const PM_DONTIMPORT_SUID: u32 = 1 << 17;
3223pub const PM_LOADDIR: u32 = 1 << 17;
3225pub const PM_SINGLE: u32 = 1 << 18;
3227pub const PM_ANONYMOUS: u32 = 1 << 18;
3229pub const PM_LOCAL: u32 = 1 << 19;
3231pub const PM_KSHSTORED: u32 = 1 << 19;
3233pub const PM_SPECIAL: u32 = 1 << 20;
3235pub const PM_ZSHSTORED: u32 = 1 << 20;
3237pub const PM_RO_BY_DESIGN: u32 = 1 << 21;
3239pub const PM_READONLY_SPECIAL: u32 = PM_SPECIAL | PM_READONLY | PM_RO_BY_DESIGN;
3241pub const PM_DONTIMPORT: u32 = 1 << 22;
3243pub const PM_DECLARED: u32 = 1 << 22;
3245pub const PM_RESTRICTED: u32 = 1 << 23;
3247pub const PM_UNSET: u32 = 1 << 24;
3249pub const PM_DEFAULTED: u32 = PM_DECLARED | PM_UNSET;
3251pub const PM_REMOVABLE: u32 = 1 << 25;
3253pub const PM_AUTOLOAD: u32 = 1 << 26;
3255pub const PM_NORESTORE: u32 = 1 << 27;
3257pub const PM_AUTOALL: u32 = 1 << 27;
3259pub const PM_HASHELEM: u32 = 1 << 28;
3261pub const PM_NAMEDDIR: u32 = 1 << 29;
3263pub const PM_NAMEREF: u32 = 1 << 30;
3265#[inline]
3267#[allow(non_snake_case)]
3268pub const fn PM_TYPE(x: u32) -> u32 {
3269 x & (PM_SCALAR | PM_INTEGER | PM_EFLOAT | PM_FFLOAT | PM_ARRAY | PM_HASHED | PM_NAMEREF)
3270}
3271pub const TYPESET_OPTSTR: &str = "aiEFALRZlurtxUhHT"; pub const TYPESET_OPTNUM: &str = "LRZiEF"; pub const SCANPM_WANTVALS: u32 = 1 << 0;
3281pub const SCANPM_WANTKEYS: u32 = 1 << 1;
3283pub const SCANPM_WANTINDEX: u32 = 1 << 2;
3285pub const SCANPM_MATCHKEY: u32 = 1 << 3;
3287pub const SCANPM_MATCHVAL: u32 = 1 << 4;
3289pub const SCANPM_MATCHMANY: u32 = 1 << 5;
3291pub const SCANPM_ASSIGNING: u32 = 1 << 6;
3293pub const SCANPM_KEYMATCH: u32 = 1 << 7;
3295pub const SCANPM_DQUOTED: u32 = 1 << 8;
3297pub const SCANPM_ARRONLY: u32 = 1 << 9;
3299pub const SCANPM_CHECKING: u32 = 1 << 10;
3301pub const SCANPM_NOEXEC: u32 = 1 << 11;
3303pub const SCANPM_NONAMESPC: u32 = 1 << 12;
3305pub const SCANPM_NONAMEREF: u32 = 1 << 13;
3307pub const SCANPM_ISVAR_AT: u32 = 1 << 14;
3309
3310pub const SUB_END: i32 = 0x0001;
3315pub const SUB_LONG: i32 = 0x0002;
3317pub const SUB_SUBSTR: i32 = 0x0004;
3319pub const SUB_MATCH: i32 = 0x0008;
3321pub const SUB_REST: i32 = 0x0010;
3323pub const SUB_BIND: i32 = 0x0020;
3325pub const SUB_EIND: i32 = 0x0040;
3327pub const SUB_LEN: i32 = 0x0080;
3329pub const SUB_ALL: i32 = 0x0100;
3331pub const SUB_GLOBAL: i32 = 0x0200;
3333pub const SUB_DOSUBST: i32 = 0x0400;
3335pub const SUB_RETFAIL: i32 = 0x0800;
3337pub const SUB_START: i32 = 0x1000;
3339pub const SUB_LIST: i32 = 0x2000;
3341pub const SUB_EGLOB: i32 = 0x4000;
3343
3344pub const ZSHTOK_SUBST: i32 = 0x0001;
3349pub const ZSHTOK_SHGLOB: i32 = 0x0002;
3351pub const PREFORK_TYPESET: i32 = 0x01;
3353pub const PREFORK_ASSIGN: i32 = 0x02;
3355pub const PREFORK_SINGLE: i32 = 0x04;
3357pub const PREFORK_SPLIT: i32 = 0x08;
3359pub const PREFORK_SHWORDSPLIT: i32 = 0x10;
3361pub const PREFORK_NOSHWORDSPLIT: i32 = 0x20;
3363pub const PREFORK_SUBEXP: i32 = 0x40;
3365pub const PREFORK_KEY_VALUE: i32 = 0x80;
3367pub const PREFORK_NO_UNTOK: i32 = 0x100;
3369pub const MULTSUB_WS_AT_START: i32 = 1;
3371pub const MULTSUB_WS_AT_END: i32 = 2;
3373pub const MULTSUB_PARAM_NAME: i32 = 4;
3375
3376pub const ASSPM_AUGMENT: i32 = 1 << 0;
3381pub const ASSPM_WARN_CREATE: i32 = 1 << 1;
3383pub const ASSPM_WARN_NESTED: i32 = 1 << 2;
3385pub const ASSPM_WARN: i32 = ASSPM_WARN_CREATE | ASSPM_WARN_NESTED;
3387pub const ASSPM_ENV_IMPORT: i32 = 1 << 3;
3389pub const ASSPM_KEY_VALUE: i32 = 1 << 4;
3391
3392pub 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;
3403pub const PRINT_LIST: i32 = 1 << 2;
3405pub const PRINT_KV_PAIR: i32 = 1 << 3;
3407pub const PRINT_INCLUDEVALUE: i32 = 1 << 4;
3409pub const PRINT_TYPESET: i32 = 1 << 5;
3411pub const PRINT_LINE: i32 = 1 << 6;
3413pub const PRINT_POSIX_EXPORT: i32 = 1 << 7;
3415pub const PRINT_POSIX_READONLY: i32 = 1 << 8;
3417pub const PRINT_WITH_NAMESPACE: i32 = 1 << 9;
3419pub const PRINT_WHENCE_CSH: i32 = 1 << 7; pub const PRINT_WHENCE_VERBOSE: i32 = 1 << 8;
3423pub const PRINT_WHENCE_SIMPLE: i32 = 1 << 9;
3425pub const PRINT_WHENCE_FUNCDEF: i32 = 1 << 10;
3427pub const PRINT_WHENCE_WORD: i32 = 1 << 11;
3429pub const LOOP_OK: i32 = 0; pub const LOOP_EMPTY: i32 = 1;
3433pub const LOOP_ERROR: i32 = 2;
3435pub const SOURCE_OK: i32 = 0; pub const SOURCE_NOT_FOUND: i32 = 1;
3439pub const SOURCE_ERROR: i32 = 2;
3441pub const NOERREXIT_EXIT: i32 = 1; pub const NOERREXIT_RETURN: i32 = 2;
3445pub const NOERREXIT_SIGNAL: i32 = 8;
3447
3448pub const HIST_MAKEUNIQUE: u32 = 0x00000001; pub const HIST_OLD: u32 = 0x00000002;
3455pub const HIST_READ: u32 = 0x00000004;
3457pub const HIST_DUP: u32 = 0x00000008;
3459pub const HIST_FOREIGN: u32 = 0x00000010;
3461pub const HIST_TMPSTORE: u32 = 0x00000020;
3463pub const HIST_NOWRITE: u32 = 0x00000040;
3465pub const GETHIST_UPWARD: i32 = -1;
3467pub const GETHIST_DOWNWARD: i32 = 1;
3469pub const GETHIST_EXACT: i32 = 0;
3471pub const HISTFLAG_DONE: i32 = 1; pub const HISTFLAG_NOEXEC: i32 = 2;
3475pub const HISTFLAG_RECALL: i32 = 4;
3477pub const HISTFLAG_SETTY: i32 = 8;
3479pub const HFILE_APPEND: u32 = 0x0001;
3481pub const HFILE_SKIPOLD: u32 = 0x0002;
3483pub const HFILE_SKIPDUPS: u32 = 0x0004;
3485pub const HFILE_SKIPFOREIGN: u32 = 0x0008;
3487pub const HFILE_FAST: u32 = 0x0010;
3489pub const HFILE_NO_REWRITE: u32 = 0x0020;
3491pub const HFILE_USE_OPTIONS: u32 = 0x8000;
3493pub const LEXFLAGS_ACTIVE: i32 = 0x0001;
3495pub const LEXFLAGS_ZLE: i32 = 0x0002;
3497pub const LEXFLAGS_COMMENTS_KEEP: i32 = 0x0004;
3499pub const LEXFLAGS_COMMENTS_STRIP: i32 = 0x0008;
3501pub const LEXFLAGS_COMMENTS: i32 = LEXFLAGS_COMMENTS_KEEP | LEXFLAGS_COMMENTS_STRIP;
3503pub const LEXFLAGS_NEWLINE: i32 = 0x0010;
3505
3506pub const IN_NOTHING: i32 = 0;
3511pub const IN_CMD: i32 = 1;
3513pub const IN_MATH: i32 = 2;
3515pub const IN_COND: i32 = 3;
3517pub const IN_ENV: i32 = 4;
3519pub const IN_PAR: i32 = 5;
3521
3522pub const EMULATE_CSH: i32 = 1 << 1; pub const EMULATE_KSH: i32 = 1 << 2;
3529pub const EMULATE_SH: i32 = 1 << 3;
3531pub const EMULATE_ZSH: i32 = 1 << 4;
3533pub const EMULATE_FULLY: i32 = 1 << 5;
3535pub const EMULATE_UNUSED: i32 = 1 << 6;
3537
3538pub const OPT_INVALID: i32 = 0;
3543pub const ALIASESOPT: i32 = 1;
3545pub const ALIASFUNCDEF: i32 = 2;
3547pub const ALLEXPORT: i32 = 3;
3549pub const ALWAYSLASTPROMPT: i32 = 4;
3551pub const ALWAYSTOEND: i32 = 5;
3553pub const APPENDHISTORY: i32 = 6;
3555pub const AUTOCD: i32 = 7;
3557pub const AUTOCONTINUE: i32 = 8;
3559pub const AUTOLIST: i32 = 9;
3561pub const AUTOMENU: i32 = 10;
3563pub const AUTONAMEDIRS: i32 = 11;
3565pub const AUTOPARAMKEYS: i32 = 12;
3567pub const AUTOPARAMSLASH: i32 = 13;
3569pub const AUTOPUSHD: i32 = 14;
3571pub const AUTOREMOVESLASH: i32 = 15;
3573pub const AUTORESUME: i32 = 16;
3575pub const BADPATTERN: i32 = 17;
3577pub const BANGHIST: i32 = 18;
3579pub const BAREGLOBQUAL: i32 = 19;
3581pub const BASHAUTOLIST: i32 = 20;
3583pub const BASHREMATCH: i32 = 21;
3585pub const BEEP: i32 = 22;
3587pub const BGNICE: i32 = 23;
3589pub const BRACECCL: i32 = 24;
3591pub const BSDECHO: i32 = 25;
3593pub const CASEGLOB: i32 = 26;
3595pub const CASEMATCH: i32 = 27;
3597pub const CASEPATHS: i32 = 28;
3599pub const CBASES: i32 = 29;
3601pub const CDABLEVARS: i32 = 30;
3603pub const CDSILENT: i32 = 31;
3605pub const CHASEDOTS: i32 = 32;
3607pub const CHASELINKS: i32 = 33;
3609pub const CHECKJOBS: i32 = 34;
3611pub const CHECKRUNNINGJOBS: i32 = 35;
3613pub const CLOBBER: i32 = 36;
3615pub const CLOBBEREMPTY: i32 = 37;
3617pub const APPENDCREATE: i32 = 38;
3619pub const COMBININGCHARS: i32 = 39;
3621pub const COMPLETEALIASES: i32 = 40;
3623pub const COMPLETEINWORD: i32 = 41;
3625pub const CORRECT: i32 = 42;
3627pub const CORRECTALL: i32 = 43;
3629pub const CONTINUEONERROR: i32 = 44;
3631pub const CPRECEDENCES: i32 = 45;
3633pub const CSHJUNKIEHISTORY: i32 = 46;
3635pub const CSHJUNKIELOOPS: i32 = 47;
3637pub const CSHJUNKIEQUOTES: i32 = 48;
3639pub const CSHNULLCMD: i32 = 49;
3641pub const CSHNULLGLOB: i32 = 50;
3643pub const DEBUGBEFORECMD: i32 = 51;
3645pub const EMACSMODE: i32 = 52;
3647pub const EQUALSOPT: i32 = 53; pub const ERREXIT: i32 = 54;
3651pub const ERRRETURN: i32 = 55;
3653pub const EXECOPT: i32 = 56;
3655pub const EXTENDEDGLOB: i32 = 57;
3657pub const EXTENDEDHISTORY: i32 = 58;
3659pub const EVALLINENO: i32 = 59;
3661pub const FLOWCONTROL: i32 = 60;
3663pub const FORCEFLOAT: i32 = 61;
3665pub const FUNCTIONARGZERO: i32 = 62;
3667pub const GLOBOPT: i32 = 63;
3669pub const GLOBALEXPORT: i32 = 64;
3671pub const GLOBALRCS: i32 = 65;
3673pub const GLOBASSIGN: i32 = 66;
3675pub const GLOBCOMPLETE: i32 = 67;
3677pub const GLOBDOTS: i32 = 68;
3679pub const GLOBSTARSHORT: i32 = 69;
3681pub const GLOBSUBST: i32 = 70;
3683pub const HASHCMDS: i32 = 71;
3685pub const HASHDIRS: i32 = 72;
3687pub const HASHEXECUTABLESONLY: i32 = 73;
3689pub const HASHLISTALL: i32 = 74;
3691pub const HISTALLOWCLOBBER: i32 = 75;
3693pub const HISTBEEP: i32 = 76;
3695pub const HISTEXPIREDUPSFIRST: i32 = 77;
3697pub const HISTFCNTLLOCK: i32 = 78;
3699pub const HISTFINDNODUPS: i32 = 79;
3701pub const HISTIGNOREALLDUPS: i32 = 80;
3703pub const HISTIGNOREDUPS: i32 = 81;
3705pub const HISTIGNORESPACE: i32 = 82;
3707pub const HISTLEXWORDS: i32 = 83;
3709pub const HISTNOFUNCTIONS: i32 = 84;
3711pub const HISTNOSTORE: i32 = 85;
3713pub const HISTREDUCEBLANKS: i32 = 86;
3715pub const HISTSAVEBYCOPY: i32 = 87;
3717pub const HISTSAVENODUPS: i32 = 88;
3719pub const HISTSUBSTPATTERN: i32 = 89;
3721pub const HISTVERIFY: i32 = 90;
3723pub const HUP: i32 = 91;
3725pub const IGNOREBRACES: i32 = 92;
3727pub const IGNORECLOSEBRACES: i32 = 93;
3729pub const IGNOREEOF: i32 = 94;
3731pub const INCAPPENDHISTORY: i32 = 95;
3733pub const INCAPPENDHISTORYTIME: i32 = 96;
3735pub const INTERACTIVE: i32 = 97;
3737pub const INTERACTIVECOMMENTS: i32 = 98;
3739pub const KSHARRAYS: i32 = 99;
3741pub const KSHAUTOLOAD: i32 = 100;
3743pub const KSHGLOB: i32 = 101;
3745pub const KSHOPTIONPRINT: i32 = 102;
3747pub const KSHTYPESET: i32 = 103;
3749pub const KSHZEROSUBSCRIPT: i32 = 104;
3751pub const LISTAMBIGUOUS: i32 = 105;
3753pub const LISTBEEP: i32 = 106;
3755pub const LISTPACKED: i32 = 107;
3757pub const LISTROWSFIRST: i32 = 108;
3759pub const LISTTYPES: i32 = 109;
3761pub const LOCALLOOPS: i32 = 110;
3763pub const LOCALOPTIONS: i32 = 111;
3765pub const LOCALPATTERNS: i32 = 112;
3767pub const LOCALTRAPS: i32 = 113;
3769pub const LOGINSHELL: i32 = 114;
3771pub const LONGLISTJOBS: i32 = 115;
3773pub const MAGICEQUALSUBST: i32 = 116;
3775pub const MAILWARNING: i32 = 117;
3777pub const MARKDIRS: i32 = 118;
3779pub const MENUCOMPLETE: i32 = 119;
3781pub const MONITOR: i32 = 120;
3783pub const MULTIBYTE: i32 = 121;
3785pub const MULTIFUNCDEF: i32 = 122;
3787pub const MULTIOS: i32 = 123;
3789pub const NOMATCH: i32 = 124;
3791pub const NOTIFY: i32 = 125;
3793pub const NULLGLOB: i32 = 126;
3795pub const NUMERICGLOBSORT: i32 = 127;
3797pub const OCTALZEROES: i32 = 128;
3799pub const OVERSTRIKE: i32 = 129;
3801pub const PATHDIRS: i32 = 130;
3803pub const PATHSCRIPT: i32 = 131;
3805pub const PIPEFAIL: i32 = 132;
3807pub const POSIXALIASES: i32 = 133;
3809pub const POSIXARGZERO: i32 = 134;
3811pub const POSIXBUILTINS: i32 = 135;
3813pub const POSIXCD: i32 = 136;
3815pub const POSIXIDENTIFIERS: i32 = 137;
3817pub const POSIXJOBS: i32 = 138;
3819pub const POSIXSTRINGS: i32 = 139;
3821pub const POSIXTRAPS: i32 = 140;
3823pub const PRINTEIGHTBIT: i32 = 141;
3825pub const PRINTEXITVALUE: i32 = 142;
3827pub const PRIVILEGED: i32 = 143;
3829pub const PROMPTBANG: i32 = 144;
3831pub const PROMPTCR: i32 = 145;
3833pub const PROMPTPERCENT: i32 = 146;
3835pub const PROMPTSP: i32 = 147;
3837pub const PROMPTSUBST: i32 = 148;
3839pub const PUSHDIGNOREDUPS: i32 = 149;
3841pub const PUSHDMINUS: i32 = 150;
3843pub const PUSHDSILENT: i32 = 151;
3845pub const PUSHDTOHOME: i32 = 152;
3847pub const RCEXPANDPARAM: i32 = 153;
3849pub const RCQUOTES: i32 = 154;
3851pub const RCS: i32 = 155;
3853pub const RECEXACT: i32 = 156;
3855pub const REMATCHPCRE: i32 = 157;
3857pub const RESTRICTED: i32 = 158;
3859pub const RMSTARSILENT: i32 = 159;
3861pub const RMSTARWAIT: i32 = 160;
3863pub const SHAREHISTORY: i32 = 161;
3865pub const SHFILEEXPANSION: i32 = 162;
3867pub const SHGLOB: i32 = 163;
3869pub const SHINSTDIN: i32 = 164;
3871pub const SHNULLCMD: i32 = 165;
3873pub const SHOPTIONLETTERS: i32 = 166;
3875pub const SHORTLOOPS: i32 = 167;
3877pub const SHORTREPEAT: i32 = 168;
3879pub const SHWORDSPLIT: i32 = 169;
3881pub const SINGLECOMMAND: i32 = 170;
3883pub const SINGLELINEZLE: i32 = 171;
3885pub const SOURCETRACE: i32 = 172;
3887pub const SUNKEYBOARDHACK: i32 = 173;
3889pub const TRANSIENTRPROMPT: i32 = 174;
3891pub const TRAPSASYNC: i32 = 175;
3893pub const TYPESETSILENT: i32 = 176;
3895pub const TYPESETTOUNSET: i32 = 177;
3897pub const UNSET: i32 = 178;
3899pub const VERBOSE: i32 = 179;
3901pub const VIMODE: i32 = 180;
3903pub const WARNCREATEGLOBAL: i32 = 181;
3905pub const WARNNESTEDVAR: i32 = 182;
3907pub const XTRACE: i32 = 183;
3909pub const USEZLE: i32 = 184;
3911pub const DVORAK: i32 = 185;
3913pub const OPT_SIZE: i32 = 186;
3915pub type OptIndex = u8; #[inline]
3922pub fn isset(opt: i32) -> bool {
3923 crate::ported::options::opt_state_get(&opt_name(opt)).unwrap_or(false)
3924}
3925
3926#[inline]
3930pub fn unset(opt: i32) -> bool {
3931 !isset(opt)
3932}
3933
3934#[inline]
3937pub fn interact() -> bool {
3938 isset(INTERACTIVE)
3939}
3940
3941#[inline]
3944pub fn jobbing() -> bool {
3945 isset(MONITOR)
3946}
3947
3948#[inline]
3951pub fn islogin() -> bool {
3952 isset(LOGINSHELL)
3953}
3954
3955pub fn opt_name(opt: i32) -> &'static str {
3957 match opt {
3958 x if x == ALIASFUNCDEF => "aliasfuncdef",
3959 x if x == ALLEXPORT => "allexport",
3960 x if x == ALWAYSLASTPROMPT => "alwayslastprompt",
3961 x if x == ALWAYSTOEND => "alwaystoend",
3962 x if x == APPENDHISTORY => "appendhistory",
3963 x if x == AUTOCD => "autocd",
3964 x if x == AUTOCONTINUE => "autocontinue",
3965 x if x == AUTOLIST => "autolist",
3966 x if x == AUTOMENU => "automenu",
3967 x if x == AUTONAMEDIRS => "autonamedirs",
3968 x if x == AUTOPARAMKEYS => "autoparamkeys",
3969 x if x == AUTOPARAMSLASH => "autoparamslash",
3970 x if x == AUTOPUSHD => "autopushd",
3971 x if x == AUTOREMOVESLASH => "autoremoveslash",
3972 x if x == AUTORESUME => "autoresume",
3973 x if x == BADPATTERN => "badpattern",
3974 x if x == BANGHIST => "banghist",
3975 x if x == BAREGLOBQUAL => "bareglobqual",
3976 x if x == BASHAUTOLIST => "bashautolist",
3977 x if x == BASHREMATCH => "bashrematch",
3978 x if x == BEEP => "beep",
3979 x if x == BGNICE => "bgnice",
3980 x if x == BRACECCL => "braceccl",
3981 x if x == BSDECHO => "bsdecho",
3982 x if x == CASEGLOB => "caseglob",
3983 x if x == CASEMATCH => "casematch",
3984 x if x == CASEPATHS => "casepaths",
3985 x if x == CBASES => "cbases",
3986 x if x == CDABLEVARS => "cdablevars",
3987 x if x == CDSILENT => "cdsilent",
3988 x if x == CHASEDOTS => "chasedots",
3989 x if x == CHASELINKS => "chaselinks",
3990 x if x == CHECKJOBS => "checkjobs",
3991 x if x == CHECKRUNNINGJOBS => "checkrunningjobs",
3992 x if x == CLOBBER => "clobber",
3993 x if x == CLOBBEREMPTY => "clobberempty",
3994 x if x == APPENDCREATE => "appendcreate",
3995 x if x == COMBININGCHARS => "combiningchars",
3996 x if x == COMPLETEALIASES => "completealiases",
3997 x if x == COMPLETEINWORD => "completeinword",
3998 x if x == CORRECT => "correct",
3999 x if x == CORRECTALL => "correctall",
4000 x if x == CPRECEDENCES => "cprecedences",
4001 x if x == CSHJUNKIEHISTORY => "cshjunkiehistory",
4002 x if x == CSHJUNKIELOOPS => "cshjunkieloops",
4003 x if x == CSHJUNKIEQUOTES => "cshjunkiequotes",
4004 x if x == CSHNULLCMD => "cshnullcmd",
4005 x if x == CSHNULLGLOB => "cshnullglob",
4006 x if x == CONTINUEONERROR => "continueonerror",
4007 x if x == DEBUGBEFORECMD => "debugbeforecmd",
4008 x if x == EMACSMODE => "emacs",
4009 x if x == EQUALSOPT => "equals",
4010 x if x == ERREXIT => "errexit",
4011 x if x == ERRRETURN => "errreturn",
4012 x if x == EXECOPT => "exec",
4013 x if x == EXTENDEDGLOB => "extendedglob",
4014 x if x == EXTENDEDHISTORY => "extendedhistory",
4015 x if x == EVALLINENO => "evallineno",
4016 x if x == FLOWCONTROL => "flowcontrol",
4017 x if x == FORCEFLOAT => "forcefloat",
4018 x if x == FUNCTIONARGZERO => "functionargzero",
4019 x if x == GLOBOPT => "glob",
4020 x if x == GLOBALEXPORT => "globalexport",
4021 x if x == GLOBALRCS => "globalrcs",
4022 x if x == GLOBASSIGN => "globassign",
4023 x if x == GLOBCOMPLETE => "globcomplete",
4024 x if x == GLOBDOTS => "globdots",
4025 x if x == GLOBSTARSHORT => "globstarshort",
4026 x if x == GLOBSUBST => "globsubst",
4027 x if x == HASHCMDS => "hashcmds",
4028 x if x == HASHDIRS => "hashdirs",
4029 x if x == HASHEXECUTABLESONLY => "hashexecutablesonly",
4030 x if x == HASHLISTALL => "hashlistall",
4031 x if x == HISTALLOWCLOBBER => "histallowclobber",
4032 x if x == HISTBEEP => "histbeep",
4033 x if x == HISTEXPIREDUPSFIRST => "histexpiredupsfirst",
4034 x if x == HISTFCNTLLOCK => "histfcntllock",
4035 x if x == HISTFINDNODUPS => "histfindnodups",
4036 x if x == HISTIGNOREALLDUPS => "histignorealldups",
4037 x if x == HISTIGNOREDUPS => "histignoredups",
4038 x if x == HISTIGNORESPACE => "histignorespace",
4039 x if x == HISTLEXWORDS => "histlexwords",
4040 x if x == HISTNOFUNCTIONS => "histnofunctions",
4041 x if x == HISTNOSTORE => "histnostore",
4042 x if x == HISTREDUCEBLANKS => "histreduceblanks",
4043 x if x == HISTSAVEBYCOPY => "histsavebycopy",
4044 x if x == HISTSAVENODUPS => "histsavenodups",
4045 x if x == HISTSUBSTPATTERN => "histsubstpattern",
4046 x if x == HISTVERIFY => "histverify",
4047 x if x == HUP => "hup",
4048 x if x == IGNOREBRACES => "ignorebraces",
4049 x if x == IGNORECLOSEBRACES => "ignoreclosebraces",
4050 x if x == IGNOREEOF => "ignoreeof",
4051 x if x == INCAPPENDHISTORY => "incappendhistory",
4052 x if x == INCAPPENDHISTORYTIME => "incappendhistorytime",
4053 x if x == INTERACTIVE => "interactive",
4054 x if x == INTERACTIVECOMMENTS => "interactivecomments",
4055 x if x == KSHARRAYS => "ksharrays",
4056 x if x == KSHAUTOLOAD => "kshautoload",
4057 x if x == KSHGLOB => "kshglob",
4058 x if x == KSHOPTIONPRINT => "kshoptionprint",
4059 x if x == KSHTYPESET => "kshtypeset",
4060 x if x == KSHZEROSUBSCRIPT => "kshzerosubscript",
4061 x if x == LISTAMBIGUOUS => "listambiguous",
4062 x if x == LISTBEEP => "listbeep",
4063 x if x == LISTPACKED => "listpacked",
4064 x if x == LISTROWSFIRST => "listrowsfirst",
4065 x if x == LISTTYPES => "listtypes",
4066 x if x == LOCALOPTIONS => "localoptions",
4067 x if x == LOCALLOOPS => "localloops",
4068 x if x == LOCALPATTERNS => "localpatterns",
4069 x if x == LOCALTRAPS => "localtraps",
4070 x if x == LOGINSHELL => "loginshell",
4071 x if x == LONGLISTJOBS => "longlistjobs",
4072 x if x == MAGICEQUALSUBST => "magicequalsubst",
4073 x if x == MAILWARNING => "mailwarning",
4074 x if x == MARKDIRS => "markdirs",
4075 x if x == MENUCOMPLETE => "menucomplete",
4076 x if x == MONITOR => "monitor",
4077 x if x == MULTIBYTE => "multibyte",
4078 x if x == MULTIFUNCDEF => "multifuncdef",
4079 x if x == MULTIOS => "multios",
4080 x if x == NOMATCH => "nomatch",
4081 x if x == NOTIFY => "notify",
4082 x if x == NULLGLOB => "nullglob",
4083 x if x == NUMERICGLOBSORT => "numericglobsort",
4084 x if x == OCTALZEROES => "octalzeroes",
4085 x if x == OVERSTRIKE => "overstrike",
4086 x if x == PATHDIRS => "pathdirs",
4087 x if x == PATHSCRIPT => "pathscript",
4088 x if x == PIPEFAIL => "pipefail",
4089 x if x == POSIXALIASES => "posixaliases",
4090 x if x == POSIXARGZERO => "posixargzero",
4091 x if x == POSIXBUILTINS => "posixbuiltins",
4092 x if x == POSIXCD => "posixcd",
4093 x if x == POSIXIDENTIFIERS => "posixidentifiers",
4094 x if x == POSIXJOBS => "posixjobs",
4095 x if x == POSIXSTRINGS => "posixstrings",
4096 x if x == POSIXTRAPS => "posixtraps",
4097 x if x == PRINTEIGHTBIT => "printeightbit",
4098 x if x == PRINTEXITVALUE => "printexitvalue",
4099 x if x == PRIVILEGED => "privileged",
4100 x if x == PROMPTBANG => "promptbang",
4101 x if x == PROMPTCR => "promptcr",
4102 x if x == PROMPTPERCENT => "promptpercent",
4103 x if x == PROMPTSP => "promptsp",
4104 x if x == PROMPTSUBST => "promptsubst",
4105 x if x == PUSHDIGNOREDUPS => "pushdignoredups",
4106 x if x == PUSHDMINUS => "pushdminus",
4107 x if x == PUSHDSILENT => "pushdsilent",
4108 x if x == PUSHDTOHOME => "pushdtohome",
4109 x if x == RCEXPANDPARAM => "rcexpandparam",
4110 x if x == RCQUOTES => "rcquotes",
4111 x if x == RCS => "rcs",
4112 x if x == RECEXACT => "recexact",
4113 x if x == REMATCHPCRE => "rematchpcre",
4114 x if x == RESTRICTED => "restricted",
4115 x if x == RMSTARSILENT => "rmstarsilent",
4116 x if x == RMSTARWAIT => "rmstarwait",
4117 x if x == SHAREHISTORY => "sharehistory",
4118 x if x == SHFILEEXPANSION => "shfileexpansion",
4119 x if x == SHGLOB => "shglob",
4120 x if x == SHINSTDIN => "shinstdin",
4121 x if x == SHNULLCMD => "shnullcmd",
4122 x if x == SHOPTIONLETTERS => "shoptionletters",
4123 x if x == SHORTLOOPS => "shortloops",
4124 x if x == SHORTREPEAT => "shortrepeat",
4125 x if x == SHWORDSPLIT => "shwordsplit",
4126 x if x == SINGLECOMMAND => "singlecommand",
4127 x if x == SINGLELINEZLE => "singlelinezle",
4128 x if x == SOURCETRACE => "sourcetrace",
4129 x if x == SUNKEYBOARDHACK => "sunkeyboardhack",
4130 x if x == TRANSIENTRPROMPT => "transientrprompt",
4131 x if x == TRAPSASYNC => "trapsasync",
4132 x if x == TYPESETSILENT => "typesetsilent",
4133 x if x == TYPESETTOUNSET => "typesettounset",
4134 x if x == UNSET => "unset",
4135 x if x == VERBOSE => "verbose",
4136 x if x == ALIASESOPT => "aliases",
4137 x if x == WARNCREATEGLOBAL => "warncreateglobal",
4138 x if x == WARNNESTEDVAR => "warnnestedvar",
4139 x if x == XTRACE => "xtrace",
4140 x if x == USEZLE => "zle",
4141 x if x == DVORAK => "dvorak",
4142 x if x == VIMODE => "vi",
4147 _ => "",
4148 }
4149}
4150
4151pub const TERM_BAD: i32 = 0x01;
4156pub const TERM_UNKNOWN: i32 = 0x02;
4158pub const TERM_NOUP: i32 = 0x04;
4160pub const TERM_SHORT: i32 = 0x08;
4162pub const TERM_NARROW: i32 = 0x10;
4164pub const TCCLEARSCREEN: i32 = 0;
4166pub const TCLEFT: i32 = 1;
4168pub const TCMULTLEFT: i32 = 2;
4170pub const TCRIGHT: i32 = 3;
4172pub const TCMULTRIGHT: i32 = 4;
4174pub const TCUP: i32 = 5;
4176pub const TCMULTUP: i32 = 6;
4178pub const TCDOWN: i32 = 7;
4180pub const TCMULTDOWN: i32 = 8;
4182pub const TCDEL: i32 = 9;
4184pub const TCMULTDEL: i32 = 10;
4186pub const TCINS: i32 = 11;
4188pub const TCMULTINS: i32 = 12;
4190pub const TCCLEAREOD: i32 = 13;
4192pub const TCCLEAREOL: i32 = 14;
4194pub const TCINSLINE: i32 = 15;
4196pub const TCDELLINE: i32 = 16;
4198pub const TCNEXTTAB: i32 = 17;
4200pub const TCBOLDFACEBEG: i32 = 18;
4202pub const TCFAINTBEG: i32 = 19;
4204pub const TCSTANDOUTBEG: i32 = 20;
4206pub const TCUNDERLINEBEG: i32 = 21;
4208pub const TCITALICSBEG: i32 = 22;
4210pub const TCALLATTRSOFF: i32 = 23;
4212pub const TCSTANDOUTEND: i32 = 24;
4214pub const TCUNDERLINEEND: i32 = 25;
4216pub const TCITALICSEND: i32 = 26;
4218pub const TCHORIZPOS: i32 = 27;
4220pub const TCUPCURSOR: i32 = 28;
4222pub const TCDOWNCURSOR: i32 = 29;
4224pub const TCLEFTCURSOR: i32 = 30;
4226pub const TCRIGHTCURSOR: i32 = 31;
4228pub const TCSAVECURSOR: i32 = 32;
4230pub const TCRESTRCURSOR: i32 = 33;
4232pub const TCBACKSPACE: i32 = 34;
4234pub const TCFGCOLOUR: i32 = 35;
4236pub const TCBGCOLOUR: i32 = 36;
4238pub const TCCURINV: i32 = 37;
4240pub const TCCURVIS: i32 = 38;
4242pub const TC_COUNT: i32 = 39;
4244
4245pub type zattr = u64; pub const TXTBOLDFACE: zattr = 0x0001;
4252pub const TXTFAINT: zattr = 0x0002;
4254pub const TXTSTANDOUT: zattr = 0x0004;
4256pub const TXTUNDERLINE: zattr = 0x0008;
4258pub const TXTITALIC: zattr = 0x0010;
4260pub const TXTFGCOLOUR: zattr = 0x0020;
4262pub const TXTBGCOLOUR: zattr = 0x0040;
4264pub const TXT_ATTR_ALL: zattr = 0x007F;
4266pub const TXT_MULTIWORD_MASK: zattr = 0x0400;
4268pub const TXT_ERROR: zattr = 0xF00000F000000003;
4270pub const TXT_ATTR_FONT_WEIGHT: zattr = TXTBOLDFACE | TXTFAINT;
4272pub const TXT_ATTR_FG_COL_MASK: zattr = 0x000000FFFFFF0000;
4274pub const TXT_ATTR_FG_COL_SHIFT: u32 = 16;
4276pub const TXT_ATTR_BG_COL_MASK: zattr = 0xFFFFFF0000000000;
4278pub const TXT_ATTR_BG_COL_SHIFT: u32 = 40;
4280pub const TXT_ATTR_FG_24BIT: zattr = 0x4000;
4282pub const TXT_ATTR_BG_24BIT: zattr = 0x8000;
4284pub const TXT_ATTR_FG_MASK: zattr = TXTFGCOLOUR | TXT_ATTR_FG_COL_MASK | TXT_ATTR_FG_24BIT;
4286pub const TXT_ATTR_BG_MASK: zattr = TXTBGCOLOUR | TXT_ATTR_BG_COL_MASK | TXT_ATTR_BG_24BIT;
4288pub const TXT_ATTR_COLOUR_MASK: zattr = TXT_ATTR_FG_MASK | TXT_ATTR_BG_MASK;
4290pub const COL_SEQ_FG: i32 = 0;
4292pub const COL_SEQ_BG: i32 = 1;
4294#[allow(non_camel_case_types)]
4296pub struct color_rgb {
4297 pub red: u32,
4300 pub green: u32,
4302 pub blue: u32,
4304}
4305pub type Color_rgb = Box<color_rgb>;
4307pub const TSC_RAW: i32 = 0x0001; pub const TSC_PROMPT: i32 = 0x0002;
4311
4312pub const CMDSTACKSZ: usize = 256;
4317pub const CS_FOR: i32 = 0;
4319pub const CS_WHILE: i32 = 1;
4321pub const CS_REPEAT: i32 = 2;
4323pub const CS_SELECT: i32 = 3;
4325pub const CS_UNTIL: i32 = 4;
4327pub const CS_IF: i32 = 5;
4329pub const CS_IFTHEN: i32 = 6;
4331pub const CS_ELSE: i32 = 7;
4333pub const CS_ELIF: i32 = 8;
4335pub const CS_MATH: i32 = 9;
4337pub const CS_COND: i32 = 10;
4339pub const CS_CMDOR: i32 = 11;
4341pub const CS_CMDAND: i32 = 12;
4343pub const CS_PIPE: i32 = 13;
4345pub const CS_ERRPIPE: i32 = 14;
4347pub const CS_FOREACH: i32 = 15;
4349pub const CS_CASE: i32 = 16;
4351pub const CS_FUNCDEF: i32 = 17;
4353pub const CS_SUBSH: i32 = 18;
4355pub const CS_CURSH: i32 = 19;
4357pub const CS_ARRAY: i32 = 20;
4359pub const CS_QUOTE: i32 = 21;
4361pub const CS_DQUOTE: i32 = 22;
4363pub const CS_BQUOTE: i32 = 23;
4365pub const CS_CMDSUBST: i32 = 24;
4367pub const CS_MATHSUBST: i32 = 25;
4369pub const CS_ELIFTHEN: i32 = 26;
4371pub const CS_HEREDOC: i32 = 27;
4373pub const CS_HEREDOCD: i32 = 28;
4375pub const CS_BRACE: i32 = 29;
4377pub const CS_BRACEPAR: i32 = 30;
4379pub const CS_ALWAYS: i32 = 31;
4381pub const CS_COUNT: i32 = 32;
4383
4384pub type Heapid = u32; pub const HEAPID_PERMANENT: Heapid = u32::MAX; pub const HDV_PUSH: i32 = 0x01;
4393pub const HDV_POP: i32 = 0x02;
4395pub const HDV_CREATE: i32 = 0x04;
4397pub const HDV_FREE: i32 = 0x08;
4399pub const HDV_NEW: i32 = 0x10;
4401pub const HDV_OLD: i32 = 0x20;
4403pub const HDV_SWITCH: i32 = 0x40;
4405pub const HDV_ALLOC: i32 = 0x80;
4407
4408pub const ZSIG_TRAPPED: i32 = 1 << 0;
4413pub const ZSIG_IGNORED: i32 = 1 << 1;
4415pub const ZSIG_FUNC: i32 = 1 << 2;
4417pub const ZSIG_MASK: i32 = ZSIG_TRAPPED | ZSIG_IGNORED | ZSIG_FUNC;
4419pub const ZSIG_ALIAS: i32 = 1 << 3;
4421pub const ZSIG_SHIFT: i32 = 4;
4423pub const TRAP_STATE_INACTIVE: i32 = 0;
4425pub const TRAP_STATE_PRIMED: i32 = 1;
4427pub const TRAP_STATE_FORCE_RETURN: i32 = 2;
4429pub const ERRFLAG_ERROR: i32 = 1;
4431pub const ERRFLAG_INT: i32 = 2;
4433pub const ERRFLAG_HARD: i32 = 4;
4435
4436pub const SORTIT_ANYOLDHOW: i32 = 0;
4441pub const SORTIT_IGNORING_CASE: i32 = 1;
4443pub const SORTIT_NUMERICALLY: i32 = 2;
4445pub const SORTIT_NUMERICALLY_SIGNED: i32 = 4;
4447pub const SORTIT_BACKWARDS: i32 = 8;
4449pub const SORTIT_IGNORING_BACKSLASHES: i32 = 16;
4451pub const SORTIT_SOMEHOW: i32 = 32;
4453
4454pub const CASMOD_NONE: i32 = 0;
4459pub const CASMOD_UPPER: i32 = 1;
4461pub const CASMOD_LOWER: i32 = 2;
4463pub const CASMOD_CAPS: i32 = 3;
4465pub const GETKEY_OCTAL_ESC: i32 = 1 << 0;
4467pub const GETKEY_EMACS: i32 = 1 << 1;
4469pub const GETKEY_CTRL: i32 = 1 << 2;
4471pub const GETKEY_BACKSLASH_C: i32 = 1 << 3;
4473pub const GETKEY_DOLLAR_QUOTE: i32 = 1 << 4;
4475pub const GETKEY_BACKSLASH_MINUS: i32 = 1 << 5;
4477pub const GETKEY_SINGLE_CHAR: i32 = 1 << 6;
4479pub const GETKEY_UPDATE_OFFSET: i32 = 1 << 7;
4481pub const GETKEY_PRINTF_PERCENT: i32 = 1 << 8;
4483pub const GETKEYS_ECHO: i32 = GETKEY_BACKSLASH_C;
4485pub const GETKEYS_PRINTF_FMT: i32 = GETKEY_OCTAL_ESC | GETKEY_BACKSLASH_C | GETKEY_PRINTF_PERCENT;
4487pub const GETKEYS_PRINTF_ARG: i32 = GETKEY_BACKSLASH_C;
4489pub const GETKEYS_PRINT: i32 = GETKEY_OCTAL_ESC | GETKEY_BACKSLASH_C | GETKEY_EMACS;
4491pub const GETKEYS_BINDKEY: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL;
4493pub const GETKEYS_DOLLARS_QUOTE: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_DOLLAR_QUOTE;
4495pub const GETKEYS_MATH: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL | GETKEY_SINGLE_CHAR;
4497pub const GETKEYS_SEP: i32 = GETKEY_OCTAL_ESC | GETKEY_EMACS;
4499pub const GETKEYS_SUFFIX: i32 =
4500 GETKEY_OCTAL_ESC | GETKEY_EMACS | GETKEY_CTRL | GETKEY_BACKSLASH_MINUS;
4501
4502pub const ZLRF_HISTORY: i32 = 0x01;
4507pub const ZLRF_NOSETTY: i32 = 0x02;
4509pub const ZLRF_IGNOREEOF: i32 = 0x04;
4511pub const ZLCON_LINE_START: i32 = 0;
4513pub const ZLCON_LINE_CONT: i32 = 1;
4515pub const ZLCON_SELECT: i32 = 2;
4517pub const ZLCON_VARED: i32 = 3;
4519pub const ZLE_CMD_GET_LINE: i32 = 0;
4521pub const ZLE_CMD_READ: i32 = 1;
4523pub const ZLE_CMD_ADD_TO_LINE: i32 = 2;
4525pub const ZLE_CMD_TRASH: i32 = 3;
4527pub const ZLE_CMD_RESET_PROMPT: i32 = 4;
4529pub const ZLE_CMD_REFRESH: i32 = 5;
4531pub const ZLE_CMD_SET_KEYMAP: i32 = 6;
4533pub const ZLE_CMD_GET_KEY: i32 = 7;
4535pub const ZLE_CMD_SET_HIST_LINE: i32 = 8;
4537pub const ZLE_CMD_PREEXEC: i32 = 9;
4539pub const ZLE_CMD_POSTEXEC: i32 = 10;
4541pub const ZLE_CMD_CHPWD: i32 = 11;
4543
4544pub const ZEXIT_NORMAL: i32 = 0;
4549pub const ZEXIT_SIGNAL: i32 = 1;
4551pub const ZEXIT_DEFERRED: i32 = 2;
4553pub const NICEFLAG_HEAP: i32 = 1;
4555pub const NICEFLAG_QUOTE: i32 = 2;
4557pub const NICEFLAG_NODUP: i32 = 4;
4559
4560pub 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]
4576#[allow(non_snake_case)]
4577pub fn MB_METACHARINIT() {} #[inline]
4584#[allow(non_snake_case)]
4585pub fn MB_METACHARLEN(s: &[u8]) -> usize {
4586 if s.is_empty() {
4588 0
4589 } else if s[0] == Meta {
4590 2
4591 } else {
4592 1
4593 }
4594}
4595
4596#[inline]
4600#[allow(non_snake_case)]
4601pub fn MB_METACHARLENCONV(s: &[u8]) -> (usize, Option<char>) {
4602 if s.is_empty() {
4604 return (0, None);
4605 }
4606 if s[0] == Meta && s.len() >= 2 {
4607 let unmeta = s[1] ^ 0x20;
4608 (2, Some(unmeta as char))
4609 } else {
4610 (1, Some(s[0] as char))
4611 }
4612}
4613
4614#[inline]
4617#[allow(non_snake_case)]
4618pub fn MB_METASTRLEN(s: &str) -> usize {
4619 let mut n = 0;
4621 let mut i = 0;
4622 let bytes = s.as_bytes();
4623 while i < bytes.len() {
4624 if bytes[i] == Meta && i + 1 < bytes.len() {
4625 i += 2;
4626 } else {
4627 i += 1;
4628 }
4629 n += 1;
4630 }
4631 n
4632}
4633
4634#[inline]
4638#[allow(non_snake_case)]
4639pub fn MB_METASTRWIDTH(s: &str) -> usize {
4640 MB_METASTRLEN(s)
4642}
4643
4644#[inline]
4648#[allow(non_snake_case)]
4649pub fn MB_METASTRLEN2(s: &str, widthp: bool) -> usize {
4650 if widthp {
4652 MB_METASTRWIDTH(s)
4653 } else {
4654 MB_METASTRLEN(s)
4655 }
4656}
4657
4658#[inline]
4661#[allow(non_snake_case)]
4662pub fn MB_CHARINIT() {} #[inline]
4667#[allow(non_snake_case)]
4668pub fn MB_CHARLEN(s: &[u8], len: usize) -> usize {
4669 if len == 0 || s.is_empty() {
4671 0
4672 } else {
4673 1
4674 }
4675}
4676
4677#[inline]
4681#[allow(non_snake_case)]
4682pub fn MB_CHARLENCONV(s: &[u8], len: usize) -> (usize, Option<char>) {
4683 if len == 0 || s.is_empty() {
4685 (0, None)
4686 } else {
4687 (1, Some(s[0] as char))
4688 }
4689}
4690
4691#[inline]
4704#[allow(non_snake_case)]
4705pub fn WCWIDTH(wc: char) -> i32 {
4706 unicode_width::UnicodeWidthChar::width(wc)
4708 .map(|w| w as i32)
4709 .unwrap_or_else(|| if wc.is_control() { 0 } else { 1 })
4710}
4711
4712#[inline]
4715#[allow(non_snake_case)]
4716pub fn WCWIDTH_WINT(wc: char) -> i32 {
4717 WCWIDTH(wc)
4719}
4720
4721#[inline]
4724#[allow(non_snake_case)]
4725pub fn IS_COMBINING(wc: char) -> bool {
4726 wc as u32 != 0 && WCWIDTH(wc) == 0
4728}
4729
4730#[inline]
4734#[allow(non_snake_case)]
4735pub fn IS_BASECHAR(wc: char) -> bool {
4736 !wc.is_whitespace() && !wc.is_control() && WCWIDTH(wc) > 0
4738}
4739
4740#[inline]
4744#[allow(non_snake_case)]
4745pub const fn ZWC(c: char) -> char {
4746 c
4747} #[inline]
4760#[allow(non_snake_case)]
4761pub fn OPT_ARG<'a>(ops: &'a options, c: u8) -> Option<&'a str> {
4762 let idx = (ops.ind[c as usize] >> 2) as usize;
4763 if idx == 0 {
4764 return None;
4765 }
4766 ops.args.get(idx - 1).map(|s| s.as_str())
4767}
4768
4769#[inline]
4772#[allow(non_snake_case)]
4773pub fn OPT_ARG_SAFE<'a>(ops: &'a options, c: u8) -> Option<&'a str> {
4774 if OPT_HASARG(ops, c) {
4775 OPT_ARG(ops, c)
4776 } else {
4777 None
4778 }
4779}
4780
4781#[allow(dead_code)]
4783const _MARKER_KEEP: AtomicI32 = AtomicI32::new(0);
4784
4785#[cfg(test)]
4786mod tests {
4787 use super::*;
4788
4789 #[test]
4790 fn zlong_zulong_sizes() {
4791 let _g = crate::test_util::global_state_lock();
4792 assert_eq!(std::mem::size_of::<zlong>(), 8);
4793 assert_eq!(std::mem::size_of::<zulong>(), 8);
4794 }
4795
4796 #[test]
4797 fn meta_byte_value() {
4798 let _g = crate::test_util::global_state_lock();
4799 assert_eq!(Meta as u32, 0x83);
4800 }
4801
4802 #[test]
4803 fn parser_tokens_correct() {
4804 let _g = crate::test_util::global_state_lock();
4805 assert_eq!(Pound as u32, 0x84);
4806 assert_eq!(Bang as u32, 0x9c);
4807 assert_eq!(Snull as u32, 0x9d);
4808 assert_eq!(Dnull as u32, 0x9e);
4809 assert_eq!(Bnull as u32, 0x9f);
4810 assert_eq!(Bnullkeep as u32, 0xa0);
4811 assert_eq!(Nularg as u32, 0xa1);
4812 assert_eq!(Marker as u32, 0xa2);
4813 }
4814
4815 #[test]
4816 fn pm_type_isolates_type_bits() {
4817 let _g = crate::test_util::global_state_lock();
4818 assert_eq!(PM_TYPE(PM_INTEGER | PM_EXPORTED), PM_INTEGER);
4819 assert_eq!(PM_TYPE(PM_ARRAY | PM_READONLY), PM_ARRAY);
4820 }
4821
4822 #[test]
4823 fn opt_isset_basic() {
4824 let _g = crate::test_util::global_state_lock();
4825 let mut ops = options {
4826 ind: [0u8; MAX_OPS],
4827 args: Vec::new(),
4828 argscount: 0,
4829 argsalloc: 0,
4830 };
4831 ops.ind[b'l' as usize] = 1; assert!(OPT_ISSET(&ops, b'l'));
4833 assert!(OPT_MINUS(&ops, b'l'));
4834 assert!(!OPT_PLUS(&ops, b'l'));
4835 assert!(!OPT_ISSET(&ops, b'r'));
4836 }
4837
4838 #[test]
4839 fn binf_constants_correct() {
4840 let _g = crate::test_util::global_state_lock();
4841 assert_eq!(BINF_PREFIX, 1 << 5);
4842 assert_eq!(BINF_ASSIGN, 1 << 19);
4843 }
4844
4845 #[test]
4846 fn cond_constants_correct() {
4847 let _g = crate::test_util::global_state_lock();
4848 assert_eq!(COND_NOT, 0);
4849 assert_eq!(COND_MODI, 19);
4850 }
4851
4852 #[test]
4853 fn fdt_constants_correct() {
4854 let _g = crate::test_util::global_state_lock();
4855 assert_eq!(FDT_UNUSED, 0);
4856 assert_eq!(FDT_PROC_SUBST, 7);
4857 assert_eq!(FDT_TYPE_MASK, 15);
4858 }
4859
4860 #[test]
4861 fn redir_iswrite_classification() {
4862 let _g = crate::test_util::global_state_lock();
4863 assert!(IS_WRITE_FILE(REDIR_WRITE));
4864 assert!(IS_WRITE_FILE(REDIR_READWRITE));
4865 assert!(!IS_WRITE_FILE(REDIR_READ));
4866 assert!(IS_ERROR_REDIR(REDIR_ERRWRITE));
4867 assert!(IS_ERROR_REDIR(REDIR_ERRAPPNOW));
4868 assert!(!IS_ERROR_REDIR(REDIR_WRITE));
4869 }
4870
4871 #[test]
4872 fn wc_macros_round_trip() {
4873 let _g = crate::test_util::global_state_lock();
4874 let w = wc_bld(WC_LIST, 42);
4875 assert_eq!(wc_code(w), WC_LIST);
4876 assert_eq!(wc_data(w), 42);
4877 }
4878
4879 #[test]
4880 fn mb_metastrlen_counts_meta_pairs() {
4881 let _g = crate::test_util::global_state_lock();
4882 assert_eq!(MB_METASTRLEN("abc"), 3);
4883 assert_eq!(MB_METASTRLEN("hello"), 5);
4887 assert_eq!(MB_METASTRLEN(""), 0);
4888 }
4889
4890 #[test]
4891 fn mb_charlen_basic() {
4892 let _g = crate::test_util::global_state_lock();
4893 assert_eq!(MB_CHARLEN(b"abc", 3), 1);
4894 assert_eq!(MB_CHARLEN(b"", 0), 0);
4895 }
4896
4897 #[test]
4898 fn wcwidth_basic() {
4899 let _g = crate::test_util::global_state_lock();
4900 assert_eq!(WCWIDTH('a'), 1);
4901 assert_eq!(WCWIDTH('\u{0007}'), 0); assert_eq!(WCWIDTH('\u{4E2D}'), 2); }
4904
4905 #[test]
4906 fn is_combining_zero_width() {
4907 let _g = crate::test_util::global_state_lock();
4908 assert!(!IS_COMBINING('a')); assert!(!IS_COMBINING('\u{0000}')); assert!(IS_COMBINING('\u{0007}'));
4917 }
4918
4919 #[test]
4920 fn pat_flags_correct() {
4921 let _g = crate::test_util::global_state_lock();
4922 assert_eq!(PAT_FILE, 0x0001);
4923 assert_eq!(PAT_LCMATCHUC, 0x1000);
4924 }
4925
4926 #[test]
4927 fn sub_flags_correct() {
4928 let _g = crate::test_util::global_state_lock();
4929 assert_eq!(SUB_END, 0x0001);
4930 assert_eq!(SUB_EGLOB, 0x4000);
4931 }
4932
4933 #[test]
4934 fn pp_constants_ordered() {
4935 let _g = crate::test_util::global_state_lock();
4936 assert_eq!(PP_FIRST, PP_ALPHA);
4937 assert!(PP_LAST >= PP_ALPHA);
4938 assert!(PP_RANGE > PP_LAST);
4939 }
4940
4941 #[test]
4942 fn typeset_optstr_constants() {
4943 let _g = crate::test_util::global_state_lock();
4944 assert_eq!(TYPESET_OPTSTR, "aiEFALRZlurtxUhHT");
4945 assert_eq!(TYPESET_OPTNUM, "LRZiEF");
4946 }
4947
4948 #[test]
4949 fn job_stat_flags_distinct() {
4950 let _g = crate::test_util::global_state_lock();
4951 let all = STAT_CHANGED
4952 | STAT_STOPPED
4953 | STAT_TIMED
4954 | STAT_DONE
4955 | STAT_LOCKED
4956 | STAT_NOPRINT
4957 | STAT_INUSE
4958 | STAT_SUPERJOB
4959 | STAT_SUBJOB
4960 | STAT_WASSUPER
4961 | STAT_CURSH
4962 | STAT_NOSTTY
4963 | STAT_ATTACH
4964 | STAT_SUBLEADER
4965 | STAT_BUILTIN
4966 | STAT_SUBJOB_ORPHANED
4967 | STAT_DISOWN;
4968 assert_eq!(all.count_ones(), 17);
4969 }
4970
4971 #[test]
4972 fn opt_size_at_186() {
4973 let _g = crate::test_util::global_state_lock();
4974 assert_eq!(OPT_SIZE, 186);
4975 }
4976
4977 #[test]
4978 fn cs_count_is_32() {
4979 let _g = crate::test_util::global_state_lock();
4980 assert_eq!(CS_COUNT, 32);
4981 }
4982
4983 #[test]
4984 fn zwc_passes_through() {
4985 let _g = crate::test_util::global_state_lock();
4986 assert_eq!(ZWC('a'), 'a');
4987 }
4988
4989 #[test]
4994 fn is_dash_recognises_both_ascii_and_lexed_token() {
4995 let _g = crate::test_util::global_state_lock();
4996 assert!(IS_DASH('-'), "ASCII '-' is dash");
4997 assert!(IS_DASH('\u{9b}'), "lexed Dash token is dash");
4998 assert!(!IS_DASH('+'), "non-dash chars must NOT match");
4999 assert!(!IS_DASH(' '), "space is not dash");
5000 }
5001
5002 #[test]
5006 fn opt_isset_reads_ind_array_directly() {
5007 let _g = crate::test_util::global_state_lock();
5008 let mut ops = options {
5009 ind: [0u8; MAX_OPS],
5010 args: Vec::new(),
5011 argscount: 0,
5012 argsalloc: 0,
5013 };
5014 assert!(!OPT_ISSET(&ops, b'x'));
5015 ops.ind[b'x' as usize] = 1;
5016 assert!(
5017 OPT_ISSET(&ops, b'x'),
5018 "after setting ind, OPT_ISSET must be true"
5019 );
5020 ops.ind[b'x' as usize] = 0;
5021 assert!(
5022 !OPT_ISSET(&ops, b'x'),
5023 "clearing ind must make OPT_ISSET false"
5024 );
5025 }
5026
5027 #[test]
5033 fn pm_type_strips_modifier_flags() {
5034 let _g = crate::test_util::global_state_lock();
5035 let with_mods = PM_INTEGER | PM_READONLY | PM_EXPORTED;
5036 assert_eq!(PM_TYPE(with_mods), PM_INTEGER);
5037 let just_array = PM_TYPE(PM_ARRAY | PM_LEFT | PM_TIED);
5038 assert_eq!(just_array, PM_ARRAY);
5039 }
5040
5041 #[test]
5046 fn pm_flags_match_c_zsh_h_canonical_values() {
5047 let _g = crate::test_util::global_state_lock();
5048 assert_eq!(PM_SCALAR, 0, "c:1878");
5049 assert_eq!(PM_ARRAY, 1 << 0, "c:1879");
5050 assert_eq!(PM_INTEGER, 1 << 1, "c:1880");
5051 assert_eq!(PM_EFLOAT, 1 << 2, "c:1881");
5052 assert_eq!(PM_FFLOAT, 1 << 3, "c:1882");
5053 assert_eq!(PM_HASHED, 1 << 4, "c:1883");
5054 assert_eq!(PM_LEFT, 1 << 5, "c:1888");
5055 assert_eq!(PM_RIGHT_B, 1 << 6, "c:1889");
5056 assert_eq!(PM_RIGHT_Z, 1 << 7, "c:1890");
5057 assert_eq!(PM_LOWER, 1 << 8, "c:1891");
5058 assert_eq!(PM_UPPER, 1 << 9, "c:1895");
5059 assert_eq!(PM_UNDEFINED, 1 << 9, "c:1896 (aliases PM_UPPER for funcs)");
5060 assert_eq!(PM_READONLY, 1 << 10, "c:1898");
5061 assert_eq!(PM_TAGGED, 1 << 11, "c:1899");
5062 assert_eq!(PM_EXPORTED, 1 << 12, "c:1900");
5063 assert_eq!(
5064 PM_ABSPATH_USED,
5065 1 << 12,
5066 "c:1901 (aliases EXPORTED for funcs)"
5067 );
5068 assert_eq!(PM_UNIQUE, 1 << 13, "c:1905");
5069 assert_eq!(PM_HIDE, 1 << 14, "c:1908");
5070 assert_eq!(PM_HIDEVAL, 1 << 15, "c:1910");
5071 assert_eq!(PM_TIED, 1 << 16, "c:1912");
5072 assert_eq!(PM_SPECIAL, 1 << 20, "c:1922");
5073 assert_eq!(PM_RO_BY_DESIGN, 1 << 21, "c:1924");
5074 assert_eq!(PM_LOCAL, 1 << 19, "c:1920");
5075 assert_eq!(PM_UNSET, 1 << 24, "c:1930");
5076 assert_eq!(PM_NAMEREF, 1 << 30, "c:1944");
5077 }
5078
5079 #[test]
5083 fn scanpm_flags_match_c_zsh_h_canonical_values() {
5084 let _g = crate::test_util::global_state_lock();
5085 assert_eq!(SCANPM_WANTVALS, 1 << 0, "c:1953");
5086 assert_eq!(SCANPM_WANTKEYS, 1 << 1, "c:1954");
5087 assert_eq!(SCANPM_WANTINDEX, 1 << 2, "c:1955");
5088 assert_eq!(SCANPM_MATCHKEY, 1 << 3, "c:1956");
5089 assert_eq!(SCANPM_MATCHVAL, 1 << 4, "c:1957");
5090 assert_eq!(SCANPM_MATCHMANY, 1 << 5, "c:1958");
5091 assert_eq!(SCANPM_ASSIGNING, 1 << 6, "c:1959");
5092 assert_eq!(SCANPM_KEYMATCH, 1 << 7, "c:1960");
5093 assert_eq!(SCANPM_DQUOTED, 1 << 8, "c:1961");
5094 assert_eq!(SCANPM_ARRONLY, 1 << 9, "c:1965");
5095 }
5096
5097 #[test]
5103 fn token_byte_values_match_c_zsh_h() {
5104 let _g = crate::test_util::global_state_lock();
5105 assert_eq!(Meta, 0x83, "c:144");
5106 assert_eq!(Pound, '\u{84}', "c:159");
5107 assert_eq!(Stringg, '\u{85}', "c:160");
5108 assert_eq!(Hat, '\u{86}', "c:161");
5109 assert_eq!(Star, '\u{87}', "c:162");
5110 assert_eq!(Inpar, '\u{88}', "c:163");
5111 assert_eq!(Inparmath, '\u{89}', "c:164");
5112 assert_eq!(Outpar, '\u{8a}', "c:165");
5113 assert_eq!(Outparmath, '\u{8b}', "c:166");
5114 assert_eq!(Qstring, '\u{8c}', "c:167");
5115 assert_eq!(Equals, '\u{8d}', "c:168");
5116 assert_eq!(Bar, '\u{8e}', "c:169");
5117 assert_eq!(Inbrace, '\u{8f}', "c:170");
5118 assert_eq!(Outbrace, '\u{90}', "c:171");
5119 assert_eq!(Inbrack, '\u{91}', "c:172");
5120 assert_eq!(Outbrack, '\u{92}', "c:173");
5121 assert_eq!(Tick, '\u{93}', "c:174");
5122 assert_eq!(Inang, '\u{94}', "c:175");
5123 assert_eq!(Outang, '\u{95}', "c:176");
5124 assert_eq!(OutangProc, '\u{96}', "c:177");
5125 assert_eq!(Quest, '\u{97}', "c:178");
5126 assert_eq!(Tilde, '\u{98}', "c:179");
5127 assert_eq!(Qtick, '\u{99}', "c:180");
5128 assert_eq!(Comma, '\u{9a}', "c:181");
5129 assert_eq!(Dash, '\u{9b}', "c:182");
5130 assert_eq!(Bang, '\u{9c}', "c:183");
5131 assert_eq!(LAST_NORMAL_TOK, Bang, "c:188 == Bang");
5132 assert_eq!(Snull, '\u{9d}', "c:193");
5133 assert_eq!(Dnull, '\u{9e}', "c:194");
5134 assert_eq!(Bnull, '\u{9f}', "c:195");
5135 assert_eq!(Bnullkeep, '\u{a0}', "c:200");
5136 assert_eq!(Nularg, '\u{a1}', "c:206");
5137 assert_eq!(Marker, '\u{a2}', "c:224");
5138 }
5139
5140 #[test]
5145 fn specchars_patchars_match_c_zsh_h() {
5146 let _g = crate::test_util::global_state_lock();
5147 assert_eq!(
5149 SPECCHARS, "#$^*()=|{}[]`<>?~;&\n\t \\\'\"",
5150 "c:228 — SPECCHARS literal must match C verbatim"
5151 );
5152 assert_eq!(
5153 SPECCHARS.chars().count(),
5154 25,
5155 "c:228 — SPECCHARS has 25 chars"
5156 );
5157 assert_eq!(
5159 PATCHARS, "#^*()|[]<>?~\\",
5160 "c:232 — PATCHARS literal must match C verbatim"
5161 );
5162 assert_eq!(
5163 PATCHARS.chars().count(),
5164 13,
5165 "c:232 — PATCHARS has 13 chars"
5166 );
5167 }
5168
5169 #[test]
5171 fn default_ifs_strings_match_c_zsh_h() {
5172 let _g = crate::test_util::global_state_lock();
5173 assert_eq!(
5175 DEFAULT_IFS, " \t\n\u{83} ",
5176 "c:149 — DEFAULT_IFS = space + tab + newline + Meta + space"
5177 );
5178 assert_eq!(
5179 DEFAULT_IFS.chars().count(),
5180 5,
5181 "c:149 — DEFAULT_IFS is 5 chars"
5182 );
5183 assert_eq!(
5185 DEFAULT_IFS_SH, " \t\n",
5186 "c:153 — DEFAULT_IFS_SH = POSIX 3-char set"
5187 );
5188 }
5189
5190 #[test]
5195 fn pm_type_mask_excludes_modifier_flags() {
5196 let _g = crate::test_util::global_state_lock();
5197 let type_mask = PM_ARRAY | PM_INTEGER | PM_EFLOAT | PM_FFLOAT | PM_HASHED;
5198 for modifier in &[
5200 PM_LEFT,
5201 PM_RIGHT_B,
5202 PM_RIGHT_Z,
5203 PM_LOWER,
5204 PM_UPPER,
5205 PM_READONLY,
5206 PM_EXPORTED,
5207 PM_LOCAL,
5208 PM_UNSET,
5209 ] {
5210 assert_eq!(
5211 modifier & type_mask,
5212 0,
5213 "modifier flag 0x{:x} must NOT overlap type mask 0x{:x}",
5214 modifier,
5215 type_mask
5216 );
5217 }
5218 }
5219
5220 #[test]
5225 fn is_write_file_sweep_all_redir_types() {
5226 let _g = crate::test_util::global_state_lock();
5227 for x in REDIR_WRITE..=REDIR_READWRITE {
5229 assert!(
5230 IS_WRITE_FILE(x),
5231 "redir-type {} ({}) must be IS_WRITE_FILE",
5232 x,
5233 x
5234 );
5235 }
5236 for x in [
5238 REDIR_READ,
5239 REDIR_HEREDOC,
5240 REDIR_HEREDOCDASH,
5241 REDIR_HERESTR,
5242 REDIR_MERGEIN,
5243 REDIR_MERGEOUT,
5244 REDIR_CLOSE,
5245 REDIR_INPIPE,
5246 REDIR_OUTPIPE,
5247 ] {
5248 assert!(
5249 !IS_WRITE_FILE(x),
5250 "redir-type {} must NOT be IS_WRITE_FILE",
5251 x
5252 );
5253 }
5254 }
5255
5256 #[test]
5261 fn is_append_redir_pins_bit_1() {
5262 let _g = crate::test_util::global_state_lock();
5263 assert!(IS_APPEND_REDIR(REDIR_APP), "REDIR_APP=2 is append");
5265 assert!(IS_APPEND_REDIR(REDIR_APPNOW), "REDIR_APPNOW=3 is append");
5266 assert!(IS_APPEND_REDIR(REDIR_ERRAPP), "REDIR_ERRAPP=6 is append");
5267 assert!(
5268 IS_APPEND_REDIR(REDIR_ERRAPPNOW),
5269 "REDIR_ERRAPPNOW=7 is append"
5270 );
5271 assert!(!IS_APPEND_REDIR(REDIR_WRITE), "REDIR_WRITE=0 is not append");
5273 assert!(
5274 !IS_APPEND_REDIR(REDIR_WRITENOW),
5275 "REDIR_WRITENOW=1 is not append"
5276 );
5277 assert!(
5278 !IS_APPEND_REDIR(REDIR_ERRWRITE),
5279 "REDIR_ERRWRITE=4 is not append"
5280 );
5281 assert!(
5282 !IS_APPEND_REDIR(REDIR_ERRWRITENOW),
5283 "REDIR_ERRWRITENOW=5 is not append"
5284 );
5285 assert!(
5287 !IS_APPEND_REDIR(REDIR_READ),
5288 "REDIR_READ=9 is not write-file"
5289 );
5290 }
5291
5292 #[test]
5297 fn is_clobber_redir_pins_bit_0() {
5298 let _g = crate::test_util::global_state_lock();
5299 assert!(
5301 IS_CLOBBER_REDIR(REDIR_WRITENOW),
5302 "REDIR_WRITENOW=1 is clobber"
5303 );
5304 assert!(IS_CLOBBER_REDIR(REDIR_APPNOW), "REDIR_APPNOW=3 is clobber");
5305 assert!(
5306 IS_CLOBBER_REDIR(REDIR_ERRWRITENOW),
5307 "REDIR_ERRWRITENOW=5 is clobber"
5308 );
5309 assert!(
5310 IS_CLOBBER_REDIR(REDIR_ERRAPPNOW),
5311 "REDIR_ERRAPPNOW=7 is clobber"
5312 );
5313 assert!(!IS_CLOBBER_REDIR(REDIR_WRITE));
5315 assert!(!IS_CLOBBER_REDIR(REDIR_APP));
5316 assert!(!IS_CLOBBER_REDIR(REDIR_ERRWRITE));
5317 assert!(!IS_CLOBBER_REDIR(REDIR_ERRAPP));
5318 }
5319
5320 #[test]
5324 fn is_error_redir_inclusive_range() {
5325 let _g = crate::test_util::global_state_lock();
5326 for x in REDIR_ERRWRITE..=REDIR_ERRAPPNOW {
5328 assert!(IS_ERROR_REDIR(x), "redir-type {} must be IS_ERROR_REDIR", x);
5329 }
5330 for x in [
5332 REDIR_WRITE,
5333 REDIR_WRITENOW,
5334 REDIR_APP,
5335 REDIR_APPNOW,
5336 REDIR_READWRITE,
5337 REDIR_READ,
5338 REDIR_HEREDOC,
5339 REDIR_INPIPE,
5340 ] {
5341 assert!(
5342 !IS_ERROR_REDIR(x),
5343 "redir-type {} must NOT be IS_ERROR_REDIR",
5344 x
5345 );
5346 }
5347 }
5348
5349 #[test]
5354 fn is_readfd_range_plus_inpipe() {
5355 let _g = crate::test_util::global_state_lock();
5356 for x in REDIR_READWRITE..=REDIR_MERGEIN {
5358 assert!(IS_READFD(x), "redir-type {} must be IS_READFD", x);
5359 }
5360 assert!(
5361 IS_READFD(REDIR_INPIPE),
5362 "REDIR_INPIPE=16 must be IS_READFD (special-case OR arm)"
5363 );
5364 assert!(!IS_READFD(REDIR_WRITE));
5366 assert!(!IS_READFD(REDIR_MERGEOUT));
5367 assert!(!IS_READFD(REDIR_CLOSE));
5368 assert!(!IS_READFD(REDIR_OUTPIPE));
5369 }
5370
5371 #[test]
5376 fn redir_constants_have_exact_canonical_values() {
5377 let _g = crate::test_util::global_state_lock();
5378 assert_eq!(REDIR_WRITE, 0);
5379 assert_eq!(REDIR_WRITENOW, 1);
5380 assert_eq!(REDIR_APP, 2);
5381 assert_eq!(REDIR_APPNOW, 3);
5382 assert_eq!(REDIR_ERRWRITE, 4);
5383 assert_eq!(REDIR_ERRWRITENOW, 5);
5384 assert_eq!(REDIR_ERRAPP, 6);
5385 assert_eq!(REDIR_ERRAPPNOW, 7);
5386 assert_eq!(REDIR_READWRITE, 8);
5387 assert_eq!(REDIR_READ, 9);
5388 assert_eq!(REDIR_HEREDOC, 10);
5389 assert_eq!(REDIR_HEREDOCDASH, 11);
5390 assert_eq!(REDIR_HERESTR, 12);
5391 assert_eq!(REDIR_MERGEIN, 13);
5392 assert_eq!(REDIR_MERGEOUT, 14);
5393 assert_eq!(REDIR_CLOSE, 15);
5394 assert_eq!(REDIR_INPIPE, 16);
5395 assert_eq!(REDIR_OUTPIPE, 17);
5396 }
5397
5398 #[test]
5404 fn redir_masks_have_no_overlap() {
5405 let _g = crate::test_util::global_state_lock();
5406 assert_eq!(REDIR_TYPE_MASK, 0x1f);
5407 assert_eq!(REDIR_VARID_MASK, 0x20);
5408 assert_eq!(REDIR_FROM_HEREDOC_MASK, 0x40);
5409 assert_eq!(REDIR_TYPE_MASK & REDIR_VARID_MASK, 0);
5411 assert_eq!(REDIR_TYPE_MASK & REDIR_FROM_HEREDOC_MASK, 0);
5412 assert_eq!(REDIR_VARID_MASK & REDIR_FROM_HEREDOC_MASK, 0);
5413 assert_eq!(
5415 REDIR_OUTPIPE & REDIR_TYPE_MASK,
5416 REDIR_OUTPIPE,
5417 "type-mask must include every REDIR_* up to OUTPIPE=17"
5418 );
5419 }
5420
5421 #[test]
5425 fn zshh_corpus_wcwidth_ascii_is_one() {
5426 assert_eq!(WCWIDTH('a'), 1);
5427 assert_eq!(WCWIDTH('Z'), 1);
5428 assert_eq!(WCWIDTH('0'), 1);
5429 assert_eq!(WCWIDTH(' '), 1);
5430 }
5431
5432 #[test]
5434 fn zshh_corpus_wcwidth_cjk_is_two() {
5435 assert_eq!(WCWIDTH('中'), 2);
5437 assert_eq!(WCWIDTH('日'), 2);
5439 }
5440
5441 #[test]
5444 fn zshh_corpus_wcwidth_combining_is_zero() {
5445 assert_eq!(WCWIDTH('\u{0301}'), 0, "combining acute accent has width 0");
5446 }
5447
5448 #[test]
5450 fn zshh_corpus_is_combining_true_for_accents() {
5451 assert!(IS_COMBINING('\u{0301}'), "U+0301 COMBINING ACUTE");
5452 assert!(IS_COMBINING('\u{0300}'), "U+0300 COMBINING GRAVE");
5453 }
5454
5455 #[test]
5457 fn zshh_corpus_is_combining_false_for_ascii() {
5458 assert!(!IS_COMBINING('a'));
5459 assert!(!IS_COMBINING('Z'));
5460 assert!(!IS_COMBINING('0'));
5461 }
5462
5463 #[test]
5465 fn zshh_corpus_is_basechar_true_for_letters() {
5466 assert!(IS_BASECHAR('a'));
5467 assert!(IS_BASECHAR('A'));
5468 assert!(IS_BASECHAR('z'));
5469 assert!(IS_BASECHAR('日'));
5470 }
5471
5472 #[test]
5474 fn zshh_corpus_is_basechar_false_for_combining() {
5475 assert!(
5476 !IS_BASECHAR('\u{0301}'),
5477 "combining accent is not a base char"
5478 );
5479 }
5480
5481 #[test]
5483 fn zshh_corpus_pound_marker_in_imeta_range() {
5484 let p = Pound as u32;
5485 assert!(
5486 p >= 0x83 && p <= 0xa2,
5487 "Pound = {:#x} must be in imeta range 0x83..=0xa2",
5488 p
5489 );
5490 }
5491
5492 #[test]
5498 fn minimum_picks_smaller_int() {
5499 assert_eq!(minimum(3, 5), 3);
5500 assert_eq!(minimum(5, 3), 3);
5501 }
5502
5503 #[test]
5505 fn minimum_equal_values_returns_value() {
5506 assert_eq!(minimum(7, 7), 7);
5507 }
5508
5509 #[test]
5511 fn minimum_negative_picks_negative() {
5512 assert_eq!(minimum(-5, 5), -5);
5513 }
5514
5515 #[test]
5518 fn QT_IS_SINGLE_recognises_QT_SINGLE() {
5519 assert!(QT_IS_SINGLE(QT_SINGLE));
5520 }
5521
5522 #[test]
5524 fn QT_IS_SINGLE_QT_NONE_returns_false() {
5525 assert!(!QT_IS_SINGLE(QT_NONE));
5526 }
5527
5528 #[test]
5531 fn IS_WRITE_FILE_recognises_write_token() {
5532 assert!(IS_WRITE_FILE(REDIR_WRITE));
5533 }
5534
5535 #[test]
5537 fn IS_APPEND_REDIR_recognises_app_token() {
5538 assert!(IS_APPEND_REDIR(REDIR_APP));
5539 }
5540
5541 #[test]
5543 fn IS_ERROR_REDIR_recognises_errwrite_token() {
5544 assert!(IS_ERROR_REDIR(REDIR_ERRWRITE));
5545 }
5546
5547 #[test]
5549 fn IS_READFD_recognises_read_token() {
5550 assert!(IS_READFD(REDIR_READ));
5551 }
5552
5553 #[test]
5559 fn WCB_END_returns_wc_end_opcode() {
5560 let end = WCB_END();
5561 assert_eq!(wc_code(end), WC_END, "WCB_END encodes WC_END opcode");
5562 assert_eq!(wc_data(end), 0, "WCB_END encodes zero data");
5563 }
5564
5565 #[test]
5567 fn wc_bld_code_round_trip() {
5568 for opcode in [WC_END, WC_LIST, WC_SUBLIST, WC_PIPE] {
5569 let w = wc_bld(opcode, 42);
5570 assert_eq!(wc_code(w), opcode, "wc_code round-trips opcode {}", opcode);
5571 }
5572 }
5573
5574 #[test]
5576 fn wc_bld_data_round_trip() {
5577 for data in [0u32, 1, 42, 0xFFFF, 0x00FFFFFF] {
5578 let w = wc_bld(WC_LIST, data);
5579 assert_eq!(wc_data(w), data, "wc_data round-trips data {}", data);
5580 }
5581 }
5582
5583 #[test]
5585 fn WC_LIST_TYPE_reads_data_field() {
5586 let w = WCB_LIST(7, 0);
5587 assert_eq!(WC_LIST_TYPE(w), 7, "list type round-trips");
5588 }
5589
5590 #[test]
5592 fn WC_LIST_SKIP_round_trip() {
5593 let w = WCB_LIST(0, 100);
5594 assert_eq!(WC_LIST_SKIP(w), 100, "list skip round-trips");
5595 }
5596
5597 #[test]
5599 fn WC_SUBLIST_TYPE_masks_low_2_bits() {
5600 let w = WCB_SUBLIST(2, 0, 0); assert_eq!(WC_SUBLIST_TYPE(w), 2);
5602 }
5603
5604 #[test]
5606 fn WC_SUBLIST_FLAGS_masks_bits_2_through_4() {
5607 let w = WCB_SUBLIST(0, 0x04, 0); assert_eq!(WC_SUBLIST_FLAGS(w), 0x04);
5609 }
5610
5611 #[test]
5613 fn WC_PIPE_TYPE_masks_low_bit() {
5614 let w = WCB_PIPE(1, 100);
5615 assert_eq!(WC_PIPE_TYPE(w), 1);
5616 let w0 = WCB_PIPE(0, 100);
5617 assert_eq!(WC_PIPE_TYPE(w0), 0);
5618 }
5619
5620 #[test]
5622 fn WC_PIPE_LINENO_shifts_down_by_one() {
5623 let w = WCB_PIPE(0, 42);
5624 assert_eq!(WC_PIPE_LINENO(w), 42, "lineno round-trips through >> 1");
5625 }
5626
5627 #[test]
5629 fn IS_DASH_only_recognizes_hyphen() {
5630 assert!(IS_DASH('-'));
5631 assert!(!IS_DASH('+'));
5632 assert!(!IS_DASH(' '));
5633 assert!(!IS_DASH('a'));
5634 assert!(!IS_DASH('\0'));
5635 }
5636
5637 #[test]
5639 fn minimum_returns_smaller_value() {
5640 assert_eq!(minimum(3, 7), 3);
5641 assert_eq!(minimum(7, 3), 3);
5642 assert_eq!(
5643 minimum(5, 5),
5644 5,
5645 "equal → either (returns first per PartialOrd)"
5646 );
5647 assert_eq!(minimum(-10, 10), -10);
5648 }
5649
5650 #[test]
5652 fn minimum_works_with_floats() {
5653 assert_eq!(minimum(1.5_f64, 2.5_f64), 1.5);
5654 assert_eq!(minimum(-1.0_f64, 0.0_f64), -1.0);
5655 }
5656
5657 #[test]
5659 fn QT_IS_SINGLE_recognizes_single_quote() {
5660 assert!(QT_IS_SINGLE(crate::ported::zsh_h::QT_SINGLE));
5663 assert!(!QT_IS_SINGLE(0));
5664 assert!(!QT_IS_SINGLE(-1));
5665 }
5666
5667 #[test]
5673 fn WCB_SIMPLE_round_trips_argc() {
5674 for n in [0u32, 1, 42, 1000, 0xFFFF] {
5675 let w = WCB_SIMPLE(n);
5676 assert_eq!(WC_SIMPLE_ARGC(w), n, "argc {} must round-trip", n);
5677 }
5678 }
5679
5680 #[test]
5682 fn WCB_TYPESET_round_trips_argc() {
5683 for n in [0u32, 5, 100, 1000] {
5684 let w = WCB_TYPESET(n);
5685 assert_eq!(WC_TYPESET_ARGC(w), n);
5686 }
5687 }
5688
5689 #[test]
5691 fn WCB_SUBSH_round_trips_skip() {
5692 for o in [0u32, 1, 100, 0x10000] {
5693 let w = WCB_SUBSH(o);
5694 assert_eq!(WC_SUBSH_SKIP(w), o);
5695 }
5696 }
5697
5698 #[test]
5700 fn WCB_CURSH_round_trips_skip() {
5701 for o in [0u32, 1, 50, 500] {
5702 let w = WCB_CURSH(o);
5703 assert_eq!(WC_CURSH_SKIP(w), o);
5704 }
5705 }
5706
5707 #[test]
5709 fn WCB_TIMED_round_trips_type() {
5710 for t in [0u32, 1, 2] {
5711 let w = WCB_TIMED(t);
5712 assert_eq!(WC_TIMED_TYPE(w), t);
5713 }
5714 }
5715
5716 #[test]
5718 fn WCB_FUNCDEF_round_trips_skip() {
5719 for o in [0u32, 10, 100] {
5720 let w = WCB_FUNCDEF(o);
5721 assert_eq!(WC_FUNCDEF_SKIP(w), o);
5722 }
5723 }
5724
5725 #[test]
5728 fn WCB_FOR_packs_type_low_skip_high() {
5729 for t in [0u32, 1, 2, 3] {
5731 for o in [0u32, 10, 100] {
5732 let w = WCB_FOR(t, o);
5733 assert_eq!(WC_FOR_TYPE(w), t, "type round-trip for ({}, {})", t, o);
5734 assert_eq!(WC_FOR_SKIP(w), o, "skip round-trip for ({}, {})", t, o);
5735 }
5736 }
5737 }
5738
5739 #[test]
5741 fn WC_SELECT_TYPE_masks_low_bit() {
5742 let w = wc_bld(WC_SELECT, 3);
5744 assert_eq!(WC_SELECT_TYPE(w), 1);
5745 let w0 = wc_bld(WC_SELECT, 4);
5746 assert_eq!(WC_SELECT_TYPE(w0), 0, "0b100 & 1 = 0");
5747 }
5748
5749 #[test]
5751 fn WC_SELECT_SKIP_shifts_right_one() {
5752 let w = wc_bld(WC_SELECT, 42);
5753 assert_eq!(WC_SELECT_SKIP(w), 42 >> 1);
5754 }
5755
5756 #[test]
5758 fn WC_FOR_TYPE_only_uses_low_2_bits() {
5759 let w = wc_bld(WC_FOR, 0b1011);
5761 assert_eq!(WC_FOR_TYPE(w), 3);
5762 }
5763
5764 #[test]
5771 fn pm_scalar_is_zero() {
5772 assert_eq!(PM_SCALAR, 0, "PM_SCALAR is the default (no bits)");
5773 }
5774
5775 #[test]
5777 fn pm_type_flags_canonical_bit_positions() {
5778 assert_eq!(PM_ARRAY, 1 << 0, "c:3176");
5779 assert_eq!(PM_INTEGER, 1 << 1, "c:3178");
5780 assert_eq!(PM_EFLOAT, 1 << 2, "c:3180");
5781 assert_eq!(PM_FFLOAT, 1 << 3, "c:3182");
5782 assert_eq!(PM_HASHED, 1 << 4, "c:3184");
5783 }
5784
5785 #[test]
5787 fn pm_padding_case_flags_canonical_bit_positions() {
5788 assert_eq!(PM_LEFT, 1 << 5, "c:3186");
5789 assert_eq!(PM_RIGHT_B, 1 << 6, "c:3188");
5790 assert_eq!(PM_RIGHT_Z, 1 << 7, "c:3190");
5791 assert_eq!(PM_LOWER, 1 << 8, "c:3192");
5792 assert_eq!(PM_UPPER, 1 << 9, "c:3194");
5793 }
5794
5795 #[test]
5799 fn pm_undefined_aliases_pm_upper() {
5800 assert_eq!(
5801 PM_UNDEFINED, PM_UPPER,
5802 "c:3196 INTENTIONAL alias: undefined fns reuse UPPER bit"
5803 );
5804 }
5805
5806 #[test]
5809 fn pm_abspath_used_aliases_pm_exported() {
5810 assert_eq!(
5811 PM_ABSPATH_USED, PM_EXPORTED,
5812 "c:3204 INTENTIONAL alias: bit reuse for path-tracking"
5813 );
5814 }
5815
5816 #[test]
5818 fn pm_readonly_is_bit_10() {
5819 assert_eq!(PM_READONLY, 1 << 10);
5820 }
5821
5822 #[test]
5824 fn pm_flags_are_u32_type() {
5825 let _: u32 = PM_SCALAR;
5826 let _: u32 = PM_ARRAY;
5827 let _: u32 = PM_INTEGER;
5828 let _: u32 = PM_READONLY;
5829 }
5830
5831 #[test]
5834 fn pm_distinct_type_flags_pairwise_disjoint() {
5835 let codes = [
5836 PM_ARRAY, PM_INTEGER, PM_EFLOAT, PM_FFLOAT, PM_HASHED, PM_LEFT, PM_RIGHT_B, PM_RIGHT_Z,
5837 PM_LOWER, PM_UPPER,
5838 ];
5839 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
5840 assert_eq!(
5841 unique.len(),
5842 codes.len(),
5843 "distinct PM type/padding flags must be pairwise disjoint"
5844 );
5845 }
5846
5847 #[test]
5849 fn pm_distinct_type_flags_all_single_bits() {
5850 for &v in &[
5851 PM_ARRAY,
5852 PM_INTEGER,
5853 PM_EFLOAT,
5854 PM_FFLOAT,
5855 PM_HASHED,
5856 PM_LEFT,
5857 PM_RIGHT_B,
5858 PM_RIGHT_Z,
5859 PM_LOWER,
5860 PM_UPPER,
5861 PM_READONLY,
5862 PM_TAGGED,
5863 PM_EXPORTED,
5864 PM_UNIQUE,
5865 ] {
5866 assert!(
5867 v.is_power_of_two(),
5868 "PM_* flag {:#x} must be a single bit",
5869 v
5870 );
5871 }
5872 }
5873
5874 #[test]
5876 fn pm_scalar_zero_is_default_state() {
5877 assert_eq!(
5878 PM_SCALAR & (PM_ARRAY | PM_INTEGER | PM_HASHED),
5879 0,
5880 "PM_SCALAR=0 by design: clear-all-bits state"
5881 );
5882 }
5883
5884 #[test]
5892 fn print_canonical_bit_positions() {
5893 assert_eq!(PRINT_NAMEONLY, 1 << 0, "c:3400");
5894 assert_eq!(PRINT_TYPE, 1 << 1, "c:3402");
5895 assert_eq!(PRINT_LIST, 1 << 2, "c:3404");
5896 assert_eq!(PRINT_KV_PAIR, 1 << 3, "c:3406");
5897 assert_eq!(PRINT_INCLUDEVALUE, 1 << 4, "c:3408");
5898 assert_eq!(PRINT_TYPESET, 1 << 5, "c:3410");
5899 assert_eq!(PRINT_LINE, 1 << 6, "c:3412");
5900 assert_eq!(PRINT_POSIX_EXPORT, 1 << 7, "c:3414");
5901 assert_eq!(PRINT_POSIX_READONLY, 1 << 8, "c:3416");
5902 assert_eq!(PRINT_WITH_NAMESPACE, 1 << 9, "c:3418");
5903 }
5904
5905 #[test]
5909 fn print_whence_csh_aliases_print_posix_export() {
5910 assert_eq!(
5911 PRINT_WHENCE_CSH, PRINT_POSIX_EXPORT,
5912 "c:3420 INTENTIONAL alias: whence vs typeset disambiguated by builtin"
5913 );
5914 }
5915
5916 #[test]
5918 fn print_whence_verbose_aliases_print_posix_readonly() {
5919 assert_eq!(
5920 PRINT_WHENCE_VERBOSE, PRINT_POSIX_READONLY,
5921 "c:3422 INTENTIONAL alias"
5922 );
5923 }
5924
5925 #[test]
5927 fn print_whence_simple_aliases_print_with_namespace() {
5928 assert_eq!(
5929 PRINT_WHENCE_SIMPLE, PRINT_WITH_NAMESPACE,
5930 "c:3424 INTENTIONAL alias"
5931 );
5932 }
5933
5934 #[test]
5936 fn print_flags_are_i32_type() {
5937 let _: i32 = PRINT_NAMEONLY;
5938 let _: i32 = PRINT_TYPE;
5939 let _: i32 = PRINT_WHENCE_CSH;
5940 }
5941
5942 #[test]
5945 fn hist_canonical_bit_positions() {
5946 assert_eq!(HIST_MAKEUNIQUE, 0x01, "c:3452");
5947 assert_eq!(HIST_OLD, 0x02, "c:3454");
5948 assert_eq!(HIST_READ, 0x04, "c:3456");
5949 assert_eq!(HIST_DUP, 0x08, "c:3458");
5950 assert_eq!(HIST_FOREIGN, 0x10, "c:3460");
5951 assert_eq!(HIST_TMPSTORE, 0x20, "c:3462");
5952 assert_eq!(HIST_NOWRITE, 0x40, "c:3464");
5953 }
5954
5955 #[test]
5957 fn hist_flags_are_u32_type() {
5958 let _: u32 = HIST_MAKEUNIQUE;
5959 let _: u32 = HIST_OLD;
5960 let _: u32 = HIST_NOWRITE;
5961 }
5962
5963 #[test]
5965 fn hist_flags_all_single_bits() {
5966 for &v in &[
5967 HIST_MAKEUNIQUE,
5968 HIST_OLD,
5969 HIST_READ,
5970 HIST_DUP,
5971 HIST_FOREIGN,
5972 HIST_TMPSTORE,
5973 HIST_NOWRITE,
5974 ] {
5975 assert!(v.is_power_of_two(), "HIST_* {:#x} must be a single bit", v);
5976 }
5977 }
5978
5979 #[test]
5981 fn hist_flags_pairwise_distinct() {
5982 let codes = [
5983 HIST_MAKEUNIQUE,
5984 HIST_OLD,
5985 HIST_READ,
5986 HIST_DUP,
5987 HIST_FOREIGN,
5988 HIST_TMPSTORE,
5989 HIST_NOWRITE,
5990 ];
5991 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
5992 assert_eq!(
5993 unique.len(),
5994 codes.len(),
5995 "HIST_* must be pairwise distinct"
5996 );
5997 }
5998
5999 #[test]
6001 fn print_non_aliased_pairwise_distinct() {
6002 let codes = [
6003 PRINT_NAMEONLY,
6004 PRINT_TYPE,
6005 PRINT_LIST,
6006 PRINT_KV_PAIR,
6007 PRINT_INCLUDEVALUE,
6008 PRINT_TYPESET,
6009 PRINT_LINE,
6010 ];
6011 let unique: std::collections::HashSet<_> = codes.iter().copied().collect();
6012 assert_eq!(
6013 unique.len(),
6014 codes.len(),
6015 "non-aliased PRINT_* must be pairwise distinct"
6016 );
6017 }
6018}