66use std:: cell:: RefCell ;
77
88use uu_pgrep:: process:: { ProcessInformation , Teletype } ;
9+ #[ cfg( unix) ]
10+ use uucore:: entries:: { gid2grp, uid2usr} ;
11+
12+ #[ cfg( not( unix) ) ]
13+ fn uid2usr ( id : u32 ) -> Result < String , std:: io:: Error > {
14+ Ok ( id. to_string ( ) )
15+ }
16+
17+ #[ cfg( not( unix) ) ]
18+ fn gid2grp ( id : u32 ) -> Result < String , std:: io:: Error > {
19+ Ok ( id. to_string ( ) )
20+ }
921
1022pub ( crate ) fn collect_pickers (
1123 code_order : & [ String ] ,
@@ -15,6 +27,17 @@ pub(crate) fn collect_pickers(
1527 for code in code_order {
1628 match code. as_str ( ) {
1729 "pid" | "tgid" => pickers. push ( helper ( pid) ) ,
30+ "ppid" => pickers. push ( helper ( ppid) ) ,
31+ "uid" => pickers. push ( helper ( uid) ) ,
32+ "euid" => pickers. push ( helper ( euid) ) ,
33+ "user" => pickers. push ( helper ( user) ) ,
34+ "euser" => pickers. push ( helper ( euser) ) ,
35+ "pgid" => pickers. push ( helper ( pgid) ) ,
36+ "sid" => pickers. push ( helper ( sid) ) ,
37+ "gid" => pickers. push ( helper ( gid) ) ,
38+ "egid" => pickers. push ( helper ( egid) ) ,
39+ "group" => pickers. push ( helper ( group) ) ,
40+ "egroup" => pickers. push ( helper ( egroup) ) ,
1841 "tname" | "tt" | "tty" => pickers. push ( helper ( tty) ) ,
1942 "time" | "cputime" => pickers. push ( helper ( time) ) ,
2043 "ucmd" => pickers. push ( helper ( ucmd) ) ,
@@ -34,7 +57,55 @@ fn helper(
3457}
3558
3659fn pid ( proc_info : RefCell < ProcessInformation > ) -> String {
37- format ! ( "{}" , proc_info. borrow( ) . pid)
60+ proc_info. borrow ( ) . pid . to_string ( )
61+ }
62+
63+ fn ppid ( proc_info : RefCell < ProcessInformation > ) -> String {
64+ proc_info. borrow_mut ( ) . ppid ( ) . unwrap ( ) . to_string ( )
65+ }
66+
67+ fn uid ( proc_info : RefCell < ProcessInformation > ) -> String {
68+ proc_info. borrow_mut ( ) . uid ( ) . unwrap ( ) . to_string ( )
69+ }
70+
71+ fn euid ( proc_info : RefCell < ProcessInformation > ) -> String {
72+ proc_info. borrow_mut ( ) . euid ( ) . unwrap ( ) . to_string ( )
73+ }
74+
75+ fn user ( proc_info : RefCell < ProcessInformation > ) -> String {
76+ let uid = proc_info. borrow_mut ( ) . uid ( ) . unwrap ( ) ;
77+ uid2usr ( uid) . ok ( ) . unwrap_or_else ( || uid. to_string ( ) )
78+ }
79+
80+ fn euser ( proc_info : RefCell < ProcessInformation > ) -> String {
81+ let euid = proc_info. borrow_mut ( ) . euid ( ) . unwrap ( ) ;
82+ uid2usr ( euid) . ok ( ) . unwrap_or_else ( || euid. to_string ( ) )
83+ }
84+
85+ fn gid ( proc_info : RefCell < ProcessInformation > ) -> String {
86+ proc_info. borrow_mut ( ) . gid ( ) . unwrap ( ) . to_string ( )
87+ }
88+
89+ fn egid ( proc_info : RefCell < ProcessInformation > ) -> String {
90+ proc_info. borrow_mut ( ) . egid ( ) . unwrap ( ) . to_string ( )
91+ }
92+
93+ fn group ( proc_info : RefCell < ProcessInformation > ) -> String {
94+ let gid = proc_info. borrow_mut ( ) . gid ( ) . unwrap ( ) ;
95+ gid2grp ( gid) . ok ( ) . unwrap_or_else ( || gid. to_string ( ) )
96+ }
97+
98+ fn egroup ( proc_info : RefCell < ProcessInformation > ) -> String {
99+ let egid = proc_info. borrow_mut ( ) . egid ( ) . unwrap ( ) ;
100+ gid2grp ( egid) . ok ( ) . unwrap_or_else ( || egid. to_string ( ) )
101+ }
102+
103+ fn pgid ( proc_info : RefCell < ProcessInformation > ) -> String {
104+ proc_info. borrow_mut ( ) . pgid ( ) . unwrap ( ) . to_string ( )
105+ }
106+
107+ fn sid ( proc_info : RefCell < ProcessInformation > ) -> String {
108+ proc_info. borrow_mut ( ) . sid ( ) . unwrap ( ) . to_string ( )
38109}
39110
40111fn tty ( proc_info : RefCell < ProcessInformation > ) -> String {
0 commit comments