2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <string> |
|
28 |
|
29 #ifdef HAVE_SYS_TYPES_H |
|
30 #include <sys/types.h> |
|
31 #endif |
|
32 |
2937
|
33 #include "oct-group.h" |
2928
|
34 |
|
35 #include "defun-dld.h" |
|
36 #include "error.h" |
|
37 #include "gripes.h" |
|
38 #include "oct-map.h" |
|
39 #include "ov.h" |
|
40 #include "oct-obj.h" |
|
41 #include "utils.h" |
|
42 |
|
43 // Group file functions. (Why not?) |
|
44 |
|
45 static octave_value |
2937
|
46 mk_gr_map (const octave_group& gr) |
2928
|
47 { |
|
48 octave_value retval; |
|
49 |
|
50 if (gr) |
|
51 { |
|
52 Octave_map m; |
|
53 |
4675
|
54 m.assign ("name", gr.name ()); |
|
55 m.assign ("passwd", gr.passwd ()); |
|
56 m.assign ("gid", static_cast<double> (gr.gid ())); |
|
57 m.assign ("mem", octave_value (gr.mem ())); |
2928
|
58 |
|
59 retval = m; |
|
60 } |
|
61 else |
4233
|
62 retval = 0; |
2928
|
63 |
|
64 return retval; |
|
65 } |
|
66 |
|
67 DEFUN_DLD (getgrent, args, , |
3301
|
68 "-*- texinfo -*-\n\ |
|
69 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrent ()\n\ |
|
70 Return an entry from the group database, opening it if necessary.\n\ |
|
71 Once the end of the data has been reached, @code{getgrent} returns 0.\n\ |
|
72 @end deftypefn") |
2928
|
73 { |
2937
|
74 octave_value_list retval; |
|
75 |
3523
|
76 retval(1) = std::string (); |
4233
|
77 retval(0) = 0; |
2928
|
78 |
|
79 int nargin = args.length (); |
|
80 |
|
81 if (nargin == 0) |
|
82 { |
3523
|
83 std::string msg; |
2937
|
84 |
|
85 retval(0) = mk_gr_map (octave_group::getgrent (msg)); |
|
86 retval(1) = msg; |
2928
|
87 } |
|
88 else |
|
89 print_usage ("getgrent"); |
|
90 |
|
91 return retval; |
|
92 } |
|
93 |
|
94 DEFUN_DLD (getgrgid, args, , |
3301
|
95 "-*- texinfo -*-\n\ |
|
96 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrgid (@var{gid}).\n\ |
|
97 Return the first entry from the group database with the group ID\n\ |
|
98 @var{gid}. If the group ID does not exist in the database,\n\ |
|
99 @code{getgrgid} returns 0.\n\ |
|
100 @end deftypefn") |
2928
|
101 { |
2937
|
102 octave_value_list retval; |
|
103 |
3523
|
104 retval(1) = std::string (); |
4233
|
105 retval(0) = 0; |
2928
|
106 |
|
107 int nargin = args.length (); |
|
108 |
|
109 if (nargin == 1) |
|
110 { |
|
111 double dval = args(0).double_value (); |
|
112 |
|
113 if (! error_state) |
|
114 { |
|
115 if (D_NINT (dval) == dval) |
|
116 { |
|
117 gid_t gid = static_cast<gid_t> (dval); |
|
118 |
3523
|
119 std::string msg; |
2937
|
120 |
|
121 retval(0) = mk_gr_map (octave_group::getgrgid (gid, msg)); |
|
122 retval(1) = msg; |
2928
|
123 } |
|
124 else |
|
125 error ("getgrgid: argument must be an integer"); |
|
126 } |
|
127 } |
|
128 else |
|
129 print_usage ("getgrgid"); |
|
130 |
|
131 return retval; |
|
132 } |
|
133 |
|
134 DEFUN_DLD (getgrnam, args, , |
3301
|
135 "-*- texinfo -*-\n\ |
|
136 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrnam (@var{name})\n\ |
|
137 Return the first entry from the group database with the group name\n\ |
|
138 @var{name}. If the group name does not exist in the database,\n\ |
|
139 @code{getgrname} returns 0.\n\ |
|
140 @end deftypefn") |
2928
|
141 { |
2937
|
142 octave_value_list retval; |
|
143 |
3523
|
144 retval(1) = std::string (); |
4233
|
145 retval(0) = 0; |
2928
|
146 |
|
147 int nargin = args.length (); |
|
148 |
|
149 if (nargin == 1) |
|
150 { |
3523
|
151 std::string s = args(0).string_value (); |
2928
|
152 |
|
153 if (! error_state) |
2937
|
154 { |
3523
|
155 std::string msg; |
2937
|
156 |
|
157 retval(0) = mk_gr_map (octave_group::getgrnam (s.c_str (), msg)); |
|
158 retval(1) = msg; |
|
159 } |
2928
|
160 } |
|
161 else |
|
162 print_usage ("getgrnam"); |
|
163 |
|
164 return retval; |
|
165 } |
|
166 |
|
167 DEFUN_DLD (setgrent, args, , |
3301
|
168 "-*- texinfo -*-\n\ |
|
169 @deftypefn {Loadable Function} {} setgrent ()\n\ |
|
170 Return the internal pointer to the beginning of the group database.\n\ |
|
171 @end deftypefn") |
2928
|
172 { |
2937
|
173 octave_value_list retval; |
|
174 |
3523
|
175 retval(1) = std::string (); |
2937
|
176 retval(0) = -1.0; |
2928
|
177 |
|
178 int nargin = args.length (); |
|
179 |
|
180 if (nargin == 0) |
|
181 { |
3523
|
182 std::string msg; |
2937
|
183 |
|
184 retval(0) = static_cast<double> (octave_group::setgrent (msg)); |
|
185 retval(1) = msg; |
2928
|
186 } |
|
187 else |
|
188 print_usage ("setgrent"); |
|
189 |
|
190 return retval; |
|
191 } |
|
192 |
|
193 DEFUN_DLD (endgrent, args, , |
3301
|
194 "-*- texinfo -*-\n\ |
|
195 @deftypefn {Loadable Function} {} endgrent ()\n\ |
|
196 Close the group database.\n\ |
|
197 @end deftypefn") |
2928
|
198 { |
2937
|
199 octave_value_list retval; |
|
200 |
3523
|
201 retval(1) = std::string (); |
2937
|
202 retval(0) = -1.0; |
2928
|
203 |
|
204 int nargin = args.length (); |
|
205 |
|
206 if (nargin == 0) |
|
207 { |
3523
|
208 std::string msg; |
2937
|
209 |
|
210 retval(0) = static_cast<double> (octave_group::endgrent (msg)); |
|
211 retval(1) = msg; |
2928
|
212 } |
|
213 else |
|
214 print_usage ("endgrent"); |
|
215 |
|
216 return retval; |
|
217 } |
|
218 |
|
219 /* |
|
220 ;;; Local Variables: *** |
|
221 ;;; mode: C++ *** |
|
222 ;;; End: *** |
|
223 */ |