Mercurial > hg > octave-nkf
changeset 1377:44f5d41ff757
[project @ 1995-09-12 00:07:58 by jwe]
author | jwe |
---|---|
date | Tue, 12 Sep 1995 00:08:47 +0000 |
parents | b5e74064566f |
children | 53a7bdf18077 |
files | configure.in src/file-io.cc |
diffstat | 2 files changed, 95 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.in +++ b/configure.in @@ -20,7 +20,7 @@ ### along with Octave; see the file COPYING. If not, write to the Free ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -AC_REVISION($Revision: 1.130 $) +AC_REVISION($Revision: 1.131 $) AC_PREREQ(2.0) AC_INIT(src/octave.cc) AC_CONFIG_HEADER(config.h) @@ -557,12 +557,13 @@ ### Checks for header files. AC_HEADER_STDC -AC_CHECK_HEADERS(assert.h float.h limits.h memory.h pwd.h stdlib.h) -AC_CHECK_HEADERS(string.h varargs.h unistd.h floatingpoint.h) -AC_CHECK_HEADERS(sys/param.h sys/utsname.h sys/time.h sys/fcntl.h) -AC_CHECK_HEADERS(sys/select.h sys/resource.h) AC_HEADER_DIRENT -AC_TIME_WITH_SYS_TIME +AC_HEADER_TIME +AC_HEADER_SYS_WAIT +AC_CHECK_HEADERS(assert.h float.h floatingpoint.h limits.h memory.h) +AC_CHECK_HEADERS(pwd.h stdlib.h string.h unistd.h varargs.h) +AC_CHECK_HEADERS(sys/fcntl.h sys/param.h sys/resource.h sys/select.h) +AC_CHECK_HEADERS(sys/stat.h sys/time.h sys/utsname.h) ### Use sgtty on Ultrix so that using DEC Migrate to convert a Mips ### binary to an Alpha binary will work. Also on Alpha/OSF to avoid @@ -658,6 +659,9 @@ ### Checks for OS specific cruft. +AC_STRUCT_ST_BLKSIZE +AC_STRUCT_ST_BLOCKS +AC_STRUCT_ST_RDEV AC_STRUCT_TM AC_STRUCT_TIMEZONE AC_FUNC_SETVBUF_REVERSED
--- a/src/file-io.cc +++ b/src/file-io.cc @@ -58,6 +58,7 @@ #include "help.h" #include "input.h" #include "mappers.h" +#include "oct-map.h" #include "octave-hist.h" #include "pager.h" #include "statdefs.h" @@ -67,6 +68,11 @@ #include "utils.h" #include "variables.h" +extern "C" +{ +#include <readline/tilde.h> +} + // keeps a count of args sent to printf or scanf static int fmt_arg_count = 0; @@ -2445,6 +2451,85 @@ return retval; } +static Octave_map +mk_stat_map (struct stat& st) +{ + Octave_map m; + + m["dev"] = (double) st.st_dev; + m["ino"] = (double) st.st_ino; + m["mode"] = (double) st.st_mode; + m["nlink"] = (double) st.st_nlink; + m["uid"] = (double) st.st_uid; + m["gid"] = (double) st.st_gid; +#if defined (HAVE_ST_RDEV) + m["rdev"] = (double) st.st_rdev; +#endif + m["size"] = (double) st.st_size; + m["atime"] = (double) st.st_atime; + m["mtime"] = (double) st.st_mtime; + m["ctime"] = (double) st.st_ctime; +#if defined (HAVE_ST_BLKSIZE) + m["blksize"] = (double) st.st_blksize; +#endif +#if defined (HAVE_ST_BLOCKS) + m["blocks"] = (double) st.st_blocks; +#endif + + return m; +} + +DEFUN ("stat", Fstat, Sstat, 1, 1, + "stat (NAME)\n\ +\n\ + Given the name of a file, return a structure with the following + elements:\n\ +\n\ + dev : id of device containing a directory entry for this file\n\ + ino : file number of the file\n\ + mode : file mode, as an integer\n\ + nlink : number of links\n\ + uid : user id of file's owner\n\ + gid : group id of file's group \n\ + rdev : id of device for block or character special files\n\ + size : size in bytes\n\ + atime : time of last access\n\ + mtime : time of last modification\n\ + ctime : time of last file status change\n\ + blksize : size of blocks in the file\n\ + blocks : number of blocks allocated for file\n\ +\n\ + If the file does not exist, -1 is returned.") +{ + Octave_object retval; + + if (args.length () == 1) + { + const char *name = args(0).string_value (); + + static char *fname = 0; + + if (fname) + free (fname); + + fname = tilde_expand (name); + + if (! error_state) + { + struct stat buf; + + if (stat (fname, &buf) < 0) + retval = -1.0; + else + retval = tree_constant (mk_stat_map (buf)); + } + } + else + print_usage ("stat"); + + return retval; +} + /* ;;; Local Variables: *** ;;; mode: C++ ***