Mercurial > hg > octave-nkf
annotate liboctave/oct-passwd.cc @ 14783:0d35ab1cf10c gui
Set text elide mode and replaced \n by \\n, so long strings do not bloat the workspace view.
* symbol-information.h: Replacing \n with \\n.
* workspace-view.cc: Set text elide mode and deactivated word wrapping.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Thu, 21 Jun 2012 12:18:39 +0200 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
2934 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2934 | 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 | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2934 | 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 | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2934 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
2937 | 27 #include <sys/types.h> |
28 | |
2934 | 29 #ifdef HAVE_PWD_H |
30 #include <pwd.h> | |
31 #endif | |
32 | |
33 #include "lo-error.h" | |
34 #include "oct-passwd.h" | |
35 | |
2937 | 36 #define NOT_SUPPORTED(nm) \ |
4062 | 37 nm ": not supported on this system" |
2937 | 38 |
3504 | 39 std::string |
2934 | 40 octave_passwd::name (void) const |
41 { | |
42 if (! ok ()) | |
43 gripe_invalid (); | |
44 | |
45 return pw_name; | |
46 } | |
47 | |
3504 | 48 std::string |
2934 | 49 octave_passwd::passwd (void) const |
50 { | |
51 if (! ok ()) | |
52 gripe_invalid (); | |
53 | |
54 return pw_passwd; | |
55 } | |
56 | |
57 uid_t | |
58 octave_passwd::uid (void) const | |
59 { | |
60 if (! ok ()) | |
61 gripe_invalid (); | |
62 | |
63 return pw_uid; | |
64 } | |
65 | |
66 gid_t | |
67 octave_passwd::gid (void) const | |
68 { | |
69 if (! ok ()) | |
70 gripe_invalid (); | |
71 | |
72 return pw_gid; | |
73 } | |
74 | |
3504 | 75 std::string |
2934 | 76 octave_passwd::gecos (void) const |
77 { | |
78 if (! ok ()) | |
79 gripe_invalid (); | |
80 | |
81 return pw_gecos; | |
82 } | |
83 | |
3504 | 84 std::string |
2934 | 85 octave_passwd::dir (void) const |
86 { | |
87 if (! ok ()) | |
88 gripe_invalid (); | |
89 | |
90 return pw_dir; | |
91 } | |
92 | |
3504 | 93 std::string |
2934 | 94 octave_passwd::shell (void) const |
95 { | |
96 if (! ok ()) | |
97 gripe_invalid (); | |
98 | |
99 return pw_shell; | |
100 } | |
101 | |
102 octave_passwd | |
103 octave_passwd::getpwent (void) | |
104 { | |
3504 | 105 std::string msg; |
2937 | 106 return getpwent (msg); |
107 } | |
108 | |
109 octave_passwd | |
3504 | 110 octave_passwd::getpwent (std::string& msg) |
2937 | 111 { |
112 #if defined HAVE_GETPWENT | |
3504 | 113 msg = std::string (); |
2937 | 114 return octave_passwd (::getpwent (), msg); |
2934 | 115 #else |
2937 | 116 msg = NOT_SUPPORTED ("getpwent"); |
2934 | 117 return octave_passwd (); |
118 #endif | |
119 } | |
120 | |
121 octave_passwd | |
122 octave_passwd::getpwuid (uid_t uid) | |
123 { | |
3504 | 124 std::string msg; |
2937 | 125 return getpwuid (uid, msg); |
126 } | |
127 | |
128 octave_passwd | |
3504 | 129 octave_passwd::getpwuid (uid_t uid, std::string& msg) |
2937 | 130 { |
131 #if defined (HAVE_GETPWUID) | |
3504 | 132 msg = std::string (); |
2937 | 133 return octave_passwd (::getpwuid (uid), msg); |
2934 | 134 #else |
2937 | 135 msg = NOT_SUPPORTED ("getpwuid"); |
2934 | 136 return octave_passwd (); |
137 #endif | |
138 } | |
139 | |
140 octave_passwd | |
3504 | 141 octave_passwd::getpwnam (const std::string& nm) |
2934 | 142 { |
3504 | 143 std::string msg; |
2937 | 144 return getpwnam (nm, msg); |
145 } | |
146 | |
147 octave_passwd | |
3504 | 148 octave_passwd::getpwnam (const std::string& nm, std::string& msg) |
2937 | 149 { |
150 #if defined (HAVE_GETPWNAM) | |
3504 | 151 msg = std::string (); |
2937 | 152 return octave_passwd (::getpwnam (nm.c_str ()), msg); |
2934 | 153 #else |
2937 | 154 msg = NOT_SUPPORTED ("getpwnam"); |
2934 | 155 return octave_passwd (); |
156 #endif | |
157 } | |
158 | |
2937 | 159 int |
2934 | 160 octave_passwd::setpwent (void) |
161 { | |
3504 | 162 std::string msg; |
2937 | 163 return setpwent (msg); |
164 } | |
165 | |
166 int | |
3504 | 167 octave_passwd::setpwent (std::string& msg) |
2937 | 168 { |
169 #if defined (HAVE_SETPWENT) | |
3504 | 170 msg = std::string (); |
2934 | 171 ::setpwent (); |
2937 | 172 return 0; |
2934 | 173 #else |
2937 | 174 msg = NOT_SUPPORTED ("setpwent"); |
175 return -1; | |
2934 | 176 #endif |
177 } | |
178 | |
2937 | 179 int |
2934 | 180 octave_passwd::endpwent (void) |
181 { | |
3504 | 182 std::string msg; |
2937 | 183 return endpwent (msg); |
184 } | |
185 | |
186 int | |
3504 | 187 octave_passwd::endpwent (std::string& msg) |
2937 | 188 { |
189 #if defined (HAVE_ENDPWENT) | |
3504 | 190 msg = std::string (); |
2934 | 191 ::endpwent (); |
2937 | 192 return 0; |
2934 | 193 #else |
2937 | 194 msg = NOT_SUPPORTED ("endpwent"); |
195 return -1; | |
2934 | 196 #endif |
197 } | |
198 | |
3504 | 199 octave_passwd::octave_passwd (void *p, std::string& msg) |
2934 | 200 : pw_name (), pw_passwd (), pw_uid (0), pw_gid (0), pw_gecos (), |
201 pw_dir (), pw_shell (), valid (false) | |
202 { | |
2937 | 203 #if defined (HAVE_PWD_H) |
3504 | 204 msg = std::string (); |
2937 | 205 |
2934 | 206 if (p) |
207 { | |
208 struct passwd *pw = static_cast<struct passwd *> (p); | |
209 | |
210 pw_name = pw->pw_name; | |
211 pw_passwd = pw->pw_passwd; | |
212 pw_uid = pw->pw_uid; | |
213 pw_gid = pw->pw_gid; | |
214 pw_gecos = pw->pw_gecos; | |
215 pw_dir = pw->pw_dir; | |
216 pw_shell = pw->pw_shell; | |
217 | |
218 valid = true; | |
219 } | |
2937 | 220 #else |
221 msg = NOT_SUPPORTED ("password functions"); | |
2934 | 222 #endif |
223 } | |
224 | |
225 void | |
226 octave_passwd::gripe_invalid (void) const | |
227 { | |
228 (*current_liboctave_error_handler) ("invalid password object"); | |
229 } |