changeset 2933:b53d9b2acd88

[project @ 1997-05-05 22:50:28 by jwe]
author jwe
date Mon, 05 May 1997 22:52:47 +0000
parents 0f33c19e5f10
children dddc1b5c324e
files src/ChangeLog src/DLD-FUNCTIONS/getpwent.cc src/ov-str-mat.cc
diffstat 3 files changed, 17 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,7 @@
 Mon May  5 00:54:03 1997  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
+	* DLD-FUNCTIONS/getpwent.cc: Use new octave_passwd class.
+
 	* ov-str-mat.cc (octave_char_matrix_str::print_name_tag): Print
 	empty strings on one line.
 
--- a/src/DLD-FUNCTIONS/getpwent.cc
+++ b/src/DLD-FUNCTIONS/getpwent.cc
@@ -30,9 +30,7 @@
 #include <sys/types.h>
 #endif
 
-#ifdef HAVE_PWD_H
-#include <pwd.h>
-#endif
+#include "oct-passwd.h"
 
 #include "defun-dld.h"
 #include "error.h"
@@ -46,7 +44,7 @@
 // Password file functions.  (Why not?)
 
 static octave_value
-mk_pw_map (struct passwd *pw)
+mk_pw_map (const octave_passwd& pw)
 {
   octave_value retval;
 
@@ -54,13 +52,13 @@
     {
       Octave_map m;
 
-      m ["name"] = pw->pw_name;
-      m ["passwd"] = pw->pw_passwd;
-      m ["uid"] = static_cast<double> (pw->pw_uid);
-      m ["gid"] = static_cast<double> (pw->pw_gid);
-      m ["gecos"] = pw->pw_gecos;
-      m ["dir"] = pw->pw_dir;
-      m ["shell"] = pw->pw_shell;
+      m ["name"] = pw.name ();
+      m ["passwd"] = pw.passwd ();
+      m ["uid"] = static_cast<double> (pw.uid ());
+      m ["gid"] = static_cast<double> (pw.gid ());
+      m ["gecos"] = pw.gecos ();
+      m ["dir"] = pw.dir ();
+      m ["shell"] = pw.shell ();
 
       retval = m;
     }
@@ -80,13 +78,7 @@
   int nargin = args.length ();
 
   if (nargin == 0)
-    {
-#ifdef HAVE_GETPWENT
-      retval = mk_pw_map (getpwent ());
-#else
-      gripe_not_supported ("getpwent");
-#endif
-    }
+    retval = mk_pw_map (octave_passwd::getpwent ());
   else
     print_usage ("getpwent");
 
@@ -104,7 +96,6 @@
 
   if (nargin == 1)
     {
-#ifdef HAVE_GETPWUID
       double dval = args(0).double_value ();
 
       if (! error_state)
@@ -113,14 +104,11 @@
 	    {
 	      uid_t uid = static_cast<uid_t> (dval);
 
-	      retval = mk_pw_map (getpwuid (uid));
+	      retval = mk_pw_map (octave_passwd::getpwuid (uid));
 	    }
 	  else
 	    error ("getpwuid: argument must be an integer");
 	}
-#else
-      gripe_not_supported ("getpwuid");
-#endif
     }
   else
     print_usage ("getpwuid");
@@ -139,14 +127,10 @@
 
   if (nargin == 1)
     {
-#ifdef HAVE_GETPWNAM
       string s = args(0).string_value ();
 
       if (! error_state)
-	retval = mk_pw_map (getpwnam (s.c_str ()));
-#else
-      gripe_not_supported ("getpwnam");
-#endif
+	retval = mk_pw_map (octave_passwd::getpwnam (s.c_str ()));
     }
   else
     print_usage ("getpwnam");
@@ -164,13 +148,7 @@
   int nargin = args.length ();
 
   if (nargin == 0)
-    {
-#ifdef HAVE_SETPWENT
-      setpwent ();
-#else
-      gripe_not_supported ("setpwent");
-#endif
-    }
+    octave_passwd::setpwent ();
   else
     print_usage ("setpwent");
 
@@ -187,13 +165,7 @@
   int nargin = args.length ();
 
   if (nargin == 0)
-    {
-#ifdef HAVE_ENDPWENT
-      endpwent ();
-#else
-      gripe_not_supported ("endpwent");
-#endif
-    }
+    octave_passwd::endpwent ();
   else
     print_usage ("endpwent");
 
--- a/src/ov-str-mat.cc
+++ b/src/ov-str-mat.cc
@@ -239,7 +239,7 @@
 
   indent (os);
 
-  if (rows () == 1)
+  if (rows () <= 1)
     os << name << " = ";
   else
     {