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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2928
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <string> |
|
29 |
|
30 #ifdef HAVE_SYS_TYPES_H |
|
31 #include <sys/types.h> |
|
32 #endif |
|
33 |
2937
|
34 #include "oct-group.h" |
2928
|
35 |
|
36 #include "defun-dld.h" |
|
37 #include "error.h" |
|
38 #include "gripes.h" |
|
39 #include "oct-map.h" |
|
40 #include "ov.h" |
|
41 #include "oct-obj.h" |
|
42 #include "utils.h" |
|
43 |
|
44 // Group file functions. (Why not?) |
|
45 |
|
46 static octave_value |
2937
|
47 mk_gr_map (const octave_group& gr) |
2928
|
48 { |
|
49 octave_value retval; |
|
50 |
|
51 if (gr) |
|
52 { |
|
53 Octave_map m; |
|
54 |
4675
|
55 m.assign ("name", gr.name ()); |
|
56 m.assign ("passwd", gr.passwd ()); |
|
57 m.assign ("gid", static_cast<double> (gr.gid ())); |
|
58 m.assign ("mem", octave_value (gr.mem ())); |
2928
|
59 |
|
60 retval = m; |
|
61 } |
|
62 else |
4233
|
63 retval = 0; |
2928
|
64 |
|
65 return retval; |
|
66 } |
|
67 |
|
68 DEFUN_DLD (getgrent, args, , |
3301
|
69 "-*- texinfo -*-\n\ |
|
70 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrent ()\n\ |
|
71 Return an entry from the group database, opening it if necessary.\n\ |
|
72 Once the end of the data has been reached, @code{getgrent} returns 0.\n\ |
|
73 @end deftypefn") |
2928
|
74 { |
2937
|
75 octave_value_list retval; |
|
76 |
3523
|
77 retval(1) = std::string (); |
4233
|
78 retval(0) = 0; |
2928
|
79 |
|
80 int nargin = args.length (); |
|
81 |
|
82 if (nargin == 0) |
|
83 { |
3523
|
84 std::string msg; |
2937
|
85 |
|
86 retval(0) = mk_gr_map (octave_group::getgrent (msg)); |
|
87 retval(1) = msg; |
2928
|
88 } |
|
89 else |
|
90 print_usage ("getgrent"); |
|
91 |
|
92 return retval; |
|
93 } |
|
94 |
|
95 DEFUN_DLD (getgrgid, args, , |
3301
|
96 "-*- texinfo -*-\n\ |
|
97 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrgid (@var{gid}).\n\ |
|
98 Return the first entry from the group database with the group ID\n\ |
|
99 @var{gid}. If the group ID does not exist in the database,\n\ |
|
100 @code{getgrgid} returns 0.\n\ |
|
101 @end deftypefn") |
2928
|
102 { |
2937
|
103 octave_value_list retval; |
|
104 |
3523
|
105 retval(1) = std::string (); |
4233
|
106 retval(0) = 0; |
2928
|
107 |
|
108 int nargin = args.length (); |
|
109 |
|
110 if (nargin == 1) |
|
111 { |
|
112 double dval = args(0).double_value (); |
|
113 |
|
114 if (! error_state) |
|
115 { |
|
116 if (D_NINT (dval) == dval) |
|
117 { |
|
118 gid_t gid = static_cast<gid_t> (dval); |
|
119 |
3523
|
120 std::string msg; |
2937
|
121 |
|
122 retval(0) = mk_gr_map (octave_group::getgrgid (gid, msg)); |
|
123 retval(1) = msg; |
2928
|
124 } |
|
125 else |
|
126 error ("getgrgid: argument must be an integer"); |
|
127 } |
|
128 } |
|
129 else |
|
130 print_usage ("getgrgid"); |
|
131 |
|
132 return retval; |
|
133 } |
|
134 |
|
135 DEFUN_DLD (getgrnam, args, , |
3301
|
136 "-*- texinfo -*-\n\ |
|
137 @deftypefn {Loadable Function} {@var{grp_struct} =} getgrnam (@var{name})\n\ |
|
138 Return the first entry from the group database with the group name\n\ |
|
139 @var{name}. If the group name does not exist in the database,\n\ |
|
140 @code{getgrname} returns 0.\n\ |
|
141 @end deftypefn") |
2928
|
142 { |
2937
|
143 octave_value_list retval; |
|
144 |
3523
|
145 retval(1) = std::string (); |
4233
|
146 retval(0) = 0; |
2928
|
147 |
|
148 int nargin = args.length (); |
|
149 |
|
150 if (nargin == 1) |
|
151 { |
3523
|
152 std::string s = args(0).string_value (); |
2928
|
153 |
|
154 if (! error_state) |
2937
|
155 { |
3523
|
156 std::string msg; |
2937
|
157 |
|
158 retval(0) = mk_gr_map (octave_group::getgrnam (s.c_str (), msg)); |
|
159 retval(1) = msg; |
|
160 } |
2928
|
161 } |
|
162 else |
|
163 print_usage ("getgrnam"); |
|
164 |
|
165 return retval; |
|
166 } |
|
167 |
|
168 DEFUN_DLD (setgrent, args, , |
3301
|
169 "-*- texinfo -*-\n\ |
|
170 @deftypefn {Loadable Function} {} setgrent ()\n\ |
|
171 Return the internal pointer to the beginning of the group database.\n\ |
|
172 @end deftypefn") |
2928
|
173 { |
2937
|
174 octave_value_list retval; |
|
175 |
3523
|
176 retval(1) = std::string (); |
2937
|
177 retval(0) = -1.0; |
2928
|
178 |
|
179 int nargin = args.length (); |
|
180 |
|
181 if (nargin == 0) |
|
182 { |
3523
|
183 std::string msg; |
2937
|
184 |
|
185 retval(0) = static_cast<double> (octave_group::setgrent (msg)); |
|
186 retval(1) = msg; |
2928
|
187 } |
|
188 else |
|
189 print_usage ("setgrent"); |
|
190 |
|
191 return retval; |
|
192 } |
|
193 |
|
194 DEFUN_DLD (endgrent, args, , |
3301
|
195 "-*- texinfo -*-\n\ |
|
196 @deftypefn {Loadable Function} {} endgrent ()\n\ |
|
197 Close the group database.\n\ |
|
198 @end deftypefn") |
2928
|
199 { |
2937
|
200 octave_value_list retval; |
|
201 |
3523
|
202 retval(1) = std::string (); |
2937
|
203 retval(0) = -1.0; |
2928
|
204 |
|
205 int nargin = args.length (); |
|
206 |
|
207 if (nargin == 0) |
|
208 { |
3523
|
209 std::string msg; |
2937
|
210 |
|
211 retval(0) = static_cast<double> (octave_group::endgrent (msg)); |
|
212 retval(1) = msg; |
2928
|
213 } |
|
214 else |
|
215 print_usage ("endgrent"); |
|
216 |
|
217 return retval; |
|
218 } |
|
219 |
|
220 /* |
|
221 ;;; Local Variables: *** |
|
222 ;;; mode: C++ *** |
|
223 ;;; End: *** |
|
224 */ |