Mercurial > octave-nkf
annotate src/DLD-FUNCTIONS/getpwent.cc @ 10154:40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 20 Jan 2010 17:33:41 -0500 |
parents | 7c02ec148a3c |
children | d0ce5e973937 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1996, 1997, 1999, 2000, 2002, 2003, 2005, 2006, 2007, 2008 |
7017 | 4 John W. Eaton |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
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 | |
2933 | 34 #include "oct-passwd.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 // Password file functions. (Why not?) | |
45 | |
46 static octave_value | |
2933 | 47 mk_pw_map (const octave_passwd& pw) |
2928 | 48 { |
49 octave_value retval; | |
50 | |
51 if (pw) | |
52 { | |
53 Octave_map m; | |
54 | |
4675 | 55 m.assign ("name", pw.name ()); |
56 m.assign ("passwd", pw.passwd ()); | |
57 m.assign ("uid", static_cast<double> (pw.uid ())); | |
58 m.assign ("gid", static_cast<double> (pw.gid ())); | |
59 m.assign ("gecos", pw.gecos ()); | |
60 m.assign ("dir", pw.dir ()); | |
61 m.assign ("shell", pw.shell ()); | |
2928 | 62 |
63 retval = m; | |
64 } | |
65 else | |
4233 | 66 retval = 0; |
2928 | 67 |
68 return retval; | |
69 } | |
70 | |
71 DEFUN_DLD (getpwent, args, , | |
3301 | 72 "-*- texinfo -*-\n\ |
7650 | 73 @deftypefn {Loadable Function} {@var{pw_struct} =} getpwent ()\n\ |
3301 | 74 Return a structure containing an entry from the password database,\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
75 opening it if necessary. Once the end of the data has been reached,\n\ |
3301 | 76 @code{getpwent} returns 0.\n\ |
77 @end deftypefn") | |
2928 | 78 { |
2937 | 79 octave_value_list retval; |
80 | |
3523 | 81 retval(1) = std::string (); |
4233 | 82 retval(0) = 0; |
2928 | 83 |
84 int nargin = args.length (); | |
85 | |
86 if (nargin == 0) | |
2937 | 87 { |
3523 | 88 std::string msg; |
2937 | 89 |
90 retval(0) = mk_pw_map (octave_passwd::getpwent (msg)); | |
91 retval(1) = msg; | |
92 } | |
2928 | 93 else |
5823 | 94 print_usage (); |
2928 | 95 |
96 return retval; | |
97 } | |
98 | |
99 DEFUN_DLD (getpwuid, args, , | |
3301 | 100 "-*- texinfo -*-\n\ |
7650 | 101 @deftypefn {Loadable Function} {@var{pw_struct} =} getpwuid (@var{uid}).\n\ |
3301 | 102 Return a structure containing the first entry from the password database\n\ |
103 with the user ID @var{uid}. If the user ID does not exist in the\n\ | |
104 database, @code{getpwuid} returns 0.\n\ | |
105 @end deftypefn") | |
2928 | 106 { |
2937 | 107 octave_value_list retval; |
108 | |
3523 | 109 retval(1) = std::string (); |
4233 | 110 retval(0) = 0; |
2928 | 111 |
112 int nargin = args.length (); | |
113 | |
114 if (nargin == 1) | |
115 { | |
116 double dval = args(0).double_value (); | |
117 | |
118 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
119 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
120 if (D_NINT (dval) == dval) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
121 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
122 uid_t uid = static_cast<uid_t> (dval); |
2928 | 123 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
124 std::string msg; |
2937 | 125 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
126 retval(0) = mk_pw_map (octave_passwd::getpwuid (uid, msg)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
127 retval(1) = msg; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
128 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
129 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
130 error ("getpwuid: argument must be an integer"); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
131 } |
2928 | 132 } |
133 else | |
5823 | 134 print_usage (); |
2928 | 135 |
136 return retval; | |
137 } | |
138 | |
139 DEFUN_DLD (getpwnam, args, , | |
3301 | 140 "-*- texinfo -*-\n\ |
7650 | 141 @deftypefn {Loadable Function} {@var{pw_struct} =} getpwnam (@var{name})\n\ |
3301 | 142 Return a structure containing the first entry from the password database\n\ |
143 with the user name @var{name}. If the user name does not exist in the\n\ | |
144 database, @code{getpwname} returns 0.\n\ | |
145 @end deftypefn") | |
2928 | 146 { |
2937 | 147 octave_value_list retval; |
148 | |
3523 | 149 retval(1) = std::string (); |
2937 | 150 retval(0) = 0.0; |
2928 | 151 |
152 int nargin = args.length (); | |
153 | |
154 if (nargin == 1) | |
155 { | |
3523 | 156 std::string s = args(0).string_value (); |
2928 | 157 |
158 if (! error_state) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
159 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
160 std::string msg; |
2937 | 161 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
162 retval(0) = mk_pw_map (octave_passwd::getpwnam (s, msg)); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
163 retval(1) = msg; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9064
diff
changeset
|
164 } |
2928 | 165 } |
166 else | |
5823 | 167 print_usage (); |
2928 | 168 |
169 return retval; | |
170 } | |
171 | |
172 DEFUN_DLD (setpwent, args, , | |
3301 | 173 "-*- texinfo -*-\n\ |
174 @deftypefn {Loadable Function} {} setpwent ()\n\ | |
175 Return the internal pointer to the beginning of the password database.\n\ | |
176 @end deftypefn") | |
2928 | 177 { |
2937 | 178 octave_value_list retval; |
179 | |
3523 | 180 retval(1) = std::string (); |
2937 | 181 retval(0) = -1.0; |
2928 | 182 |
183 int nargin = args.length (); | |
184 | |
185 if (nargin == 0) | |
2937 | 186 { |
3523 | 187 std::string msg; |
2937 | 188 |
189 retval(0) = static_cast<double> (octave_passwd::setpwent (msg)); | |
190 retval(1) = msg; | |
191 } | |
2928 | 192 else |
5823 | 193 print_usage (); |
2928 | 194 |
195 return retval; | |
196 } | |
197 | |
198 DEFUN_DLD (endpwent, args, , | |
3301 | 199 "-*- texinfo -*-\n\ |
200 @deftypefn {Loadable Function} {} endpwent ()\n\ | |
201 Close the password database.\n\ | |
202 @end deftypefn") | |
2928 | 203 { |
2937 | 204 octave_value_list retval; |
205 | |
3523 | 206 retval(1) = std::string (); |
2937 | 207 retval(0) = -1.0; |
2928 | 208 |
209 int nargin = args.length (); | |
210 | |
211 if (nargin == 0) | |
2937 | 212 { |
3523 | 213 std::string msg; |
2937 | 214 |
215 retval(0) = static_cast<double> (octave_passwd::endpwent (msg)); | |
216 retval(1) = msg; | |
217 } | |
2928 | 218 else |
5823 | 219 print_usage (); |
2928 | 220 |
221 return retval; | |
222 } | |
223 | |
224 /* | |
225 ;;; Local Variables: *** | |
226 ;;; mode: C++ *** | |
227 ;;; End: *** | |
228 */ |