# HG changeset patch # User John W. Eaton # Date 1294921416 18000 # Node ID e4e82740e9cd6f553f728b649bfb53286aaa8379 # Parent 8837a42205d3eb94718bbfb3ed9a4d7fbc3c527c prototype fixes for C language files diff -r 8837a42205d3 -r e4e82740e9cd liboctave/ChangeLog --- a/liboctave/ChangeLog Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/ChangeLog Thu Jan 13 07:23:36 2011 -0500 @@ -1,3 +1,20 @@ +2011-01-13 John W. Eaton + + * filemode.c: Use prototypes for function definitions. Reorder + functions to eliminate need for forward declarations. + * filemode.h: New file. + * file-stat.cc: Include filemode.h instead of using local extern + declarations. + * Makefile.am (INCS): Add filemode.h to the list. + + * lo-cutils.h: New file. + (octave_qsort, octave_strcasecmp, octave_strncasecmp, + octave_w32_library_search, octave_waitpid): Move decls here from + lo-utils.h. + * Makefile.am (INCS): Add lo-cutils.h to the list. + * lo-utils.h: Include cutils.h. + * lo-cutils.c: Include cutils.h. + 2011-01-13 John W. Eaton * SparseCmplxQR.cc diff -r 8837a42205d3 -r e4e82740e9cd liboctave/Makefile.am --- a/liboctave/Makefile.am Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/Makefile.am Thu Jan 13 07:23:36 2011 -0500 @@ -198,10 +198,12 @@ dir-ops.h \ file-ops.h \ file-stat.h \ + filemode.h \ functor.h \ glob-match.h \ idx-vector.h \ lo-array-gripes.h \ + lo-cutils.h \ lo-ieee.h \ lo-macros.h \ lo-mappers.h \ diff -r 8837a42205d3 -r e4e82740e9cd liboctave/file-stat.cc --- a/liboctave/file-stat.cc Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/file-stat.cc Thu Jan 13 07:23:36 2011 -0500 @@ -33,6 +33,7 @@ #include "file-ops.h" #include "file-stat.h" +#include "filemode.h" #include "statdefs.h" // FIXME -- the is_* and mode_as_string functions are only valid @@ -151,8 +152,6 @@ #endif } -extern "C" void mode_string (unsigned short, char *); - std::string base_file_stat::mode_as_string (void) const { diff -r 8837a42205d3 -r e4e82740e9cd liboctave/filemode.c --- a/liboctave/filemode.c Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/filemode.c Thu Jan 13 07:23:36 2011 -0500 @@ -20,8 +20,7 @@ #include #endif -#include -#include +#include "filemode.h" #if !S_IRUSR # if S_IREAD @@ -89,10 +88,115 @@ #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK) #endif -void mode_string (); -static char ftypelet (); -static void rwx (); -static void setst (); +/* Return a character indicating the type of file described by + file mode BITS: + 'd' for directories + 'b' for block special files + 'c' for character special files + 'm' for multiplexor files + 'l' for symbolic links + 's' for sockets + 'p' for fifos + '-' for regular files + '?' for any other file type. */ + +static char +ftypelet (long bits) +{ +#ifdef S_ISBLK + if (S_ISBLK (bits)) + return 'b'; +#endif + if (S_ISCHR (bits)) + return 'c'; + if (S_ISDIR (bits)) + return 'd'; + if (S_ISREG (bits)) + return '-'; +#ifdef S_ISFIFO + if (S_ISFIFO (bits)) + return 'p'; +#endif +#ifdef S_ISLNK + if (S_ISLNK (bits)) + return 'l'; +#endif +#ifdef S_ISSOCK + if (S_ISSOCK (bits)) + return 's'; +#endif +#ifdef S_ISMPC + if (S_ISMPC (bits)) + return 'm'; +#endif +#ifdef S_ISNWK + if (S_ISNWK (bits)) + return 'n'; +#endif + return '?'; +} + +/* Look at read, write, and execute bits in BITS and set + flags in CHARS accordingly. */ + +static void +rwx (unsigned short bits, char *chars) +{ + chars[0] = (bits & S_IRUSR) ? 'r' : '-'; + chars[1] = (bits & S_IWUSR) ? 'w' : '-'; + chars[2] = (bits & S_IXUSR) ? 'x' : '-'; +} + +/* Set the 's' and 't' flags in file attributes string CHARS, + according to the file mode BITS. */ + +static void +setst (unsigned short bits, char *chars) +{ +#ifdef S_ISUID + if (bits & S_ISUID) + { + if (chars[3] != 'x') + /* Set-uid, but not executable by owner. */ + chars[3] = 'S'; + else + chars[3] = 's'; + } +#endif +#ifdef S_ISGID + if (bits & S_ISGID) + { + if (chars[6] != 'x') + /* Set-gid, but not executable by group. */ + chars[6] = 'S'; + else + chars[6] = 's'; + } +#endif +#ifdef S_ISVTX + if (bits & S_ISVTX) + { + if (chars[9] != 'x') + /* Sticky, but not executable by others. */ + chars[9] = 'T'; + else + chars[9] = 't'; + } +#endif +} + +/* Like filemodestring, but only the relevant part of the `struct stat' + is given as an argument. */ + +void +mode_string (unsigned short mode, char *str) +{ + str[0] = ftypelet ((long) mode); + rwx ((mode & 0700) << 0, &str[1]); + rwx ((mode & 0070) << 3, &str[4]); + rwx ((mode & 0007) << 6, &str[7]); + setst (mode, str); +} /* filemodestring - fill in string STR with an ls-style ASCII representation of the st_mode field of file stats block STATP. @@ -131,126 +235,7 @@ 'T' if the file is sticky but not executable. */ void -filemodestring (statp, str) - struct stat *statp; - char *str; +filemodestring (struct stat *statp, char *str) { mode_string (statp->st_mode, str); } - -/* Like filemodestring, but only the relevant part of the `struct stat' - is given as an argument. */ - -void -mode_string (mode, str) - unsigned short mode; - char *str; -{ - str[0] = ftypelet ((long) mode); - rwx ((mode & 0700) << 0, &str[1]); - rwx ((mode & 0070) << 3, &str[4]); - rwx ((mode & 0007) << 6, &str[7]); - setst (mode, str); -} - -/* Return a character indicating the type of file described by - file mode BITS: - 'd' for directories - 'b' for block special files - 'c' for character special files - 'm' for multiplexor files - 'l' for symbolic links - 's' for sockets - 'p' for fifos - '-' for regular files - '?' for any other file type. */ - -static char -ftypelet (bits) - long bits; -{ -#ifdef S_ISBLK - if (S_ISBLK (bits)) - return 'b'; -#endif - if (S_ISCHR (bits)) - return 'c'; - if (S_ISDIR (bits)) - return 'd'; - if (S_ISREG (bits)) - return '-'; -#ifdef S_ISFIFO - if (S_ISFIFO (bits)) - return 'p'; -#endif -#ifdef S_ISLNK - if (S_ISLNK (bits)) - return 'l'; -#endif -#ifdef S_ISSOCK - if (S_ISSOCK (bits)) - return 's'; -#endif -#ifdef S_ISMPC - if (S_ISMPC (bits)) - return 'm'; -#endif -#ifdef S_ISNWK - if (S_ISNWK (bits)) - return 'n'; -#endif - return '?'; -} - -/* Look at read, write, and execute bits in BITS and set - flags in CHARS accordingly. */ - -static void -rwx (bits, chars) - unsigned short bits; - char *chars; -{ - chars[0] = (bits & S_IRUSR) ? 'r' : '-'; - chars[1] = (bits & S_IWUSR) ? 'w' : '-'; - chars[2] = (bits & S_IXUSR) ? 'x' : '-'; -} - -/* Set the 's' and 't' flags in file attributes string CHARS, - according to the file mode BITS. */ - -static void -setst (bits, chars) - unsigned short bits; - char *chars; -{ -#ifdef S_ISUID - if (bits & S_ISUID) - { - if (chars[3] != 'x') - /* Set-uid, but not executable by owner. */ - chars[3] = 'S'; - else - chars[3] = 's'; - } -#endif -#ifdef S_ISGID - if (bits & S_ISGID) - { - if (chars[6] != 'x') - /* Set-gid, but not executable by group. */ - chars[6] = 'S'; - else - chars[6] = 's'; - } -#endif -#ifdef S_ISVTX - if (bits & S_ISVTX) - { - if (chars[9] != 'x') - /* Sticky, but not executable by others. */ - chars[9] = 'T'; - else - chars[9] = 't'; - } -#endif -} diff -r 8837a42205d3 -r e4e82740e9cd liboctave/filemode.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/filemode.h Thu Jan 13 07:23:36 2011 -0500 @@ -0,0 +1,41 @@ +/* + +Copyright (C) 2011 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if !defined (octave_liboctave_filemode_h) +#define octave_liboctave_filemode_h 1 + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void mode_string (unsigned short, char *); + +void filemodestring (struct stat *, char *); + +#ifdef __cplusplus +} +#endif + +#endif diff -r 8837a42205d3 -r e4e82740e9cd liboctave/lo-cutils.c --- a/liboctave/lo-cutils.c Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/lo-cutils.c Thu Jan 13 07:23:36 2011 -0500 @@ -38,6 +38,7 @@ #include #include +#include "lo-cutils.h" #include "syswait.h" OCTAVE_API void diff -r 8837a42205d3 -r e4e82740e9cd liboctave/lo-cutils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/liboctave/lo-cutils.h Thu Jan 13 07:23:36 2011 -0500 @@ -0,0 +1,57 @@ +/* + +Copyright (C) 2011 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if !defined (octave_liboctave_cutils_h) +#define octave_liboctave_cutils_h 1 + +#ifdef HAVE_LOADLIBRARY_API +#define WIN32_LEAN_AND_MEAN +#include +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +OCTAVE_API void +octave_qsort (void *base, size_t n, size_t size, + int (*cmp) (const void *, const void *)); + +OCTAVE_API int +octave_strcasecmp (const char *s1, const char *s2); + +OCTAVE_API int +octave_strncasecmp (const char *s1, const char *s2, size_t n); + +#ifdef HAVE_LOADLIBRARY_API +OCTAVE_API void * +octave_w32_library_search (HINSTANCE handle, const char *name); +#endif + +OCTAVE_API pid_t +octave_waitpid (pid_t pid, int *status, int options); + +#ifdef __cplusplus +} +#endif + +#endif diff -r 8837a42205d3 -r e4e82740e9cd liboctave/lo-utils.h --- a/liboctave/lo-utils.h Thu Jan 13 07:21:46 2011 -0500 +++ b/liboctave/lo-utils.h Thu Jan 13 07:23:36 2011 -0500 @@ -29,8 +29,8 @@ #include #include +#include "lo-cutils.h" #include "oct-cmplx.h" -#include "syswait.h" extern OCTAVE_API bool xis_int_or_inf_or_nan (double x); extern OCTAVE_API bool xis_one_or_zero (double x); @@ -53,16 +53,6 @@ extern OCTAVE_API std::string octave_fgets (std::FILE *, bool& eof); extern OCTAVE_API std::string octave_fgetl (std::FILE *, bool& eof); -extern "C" OCTAVE_API void -octave_qsort (void *base, size_t n, size_t size, - int (*cmp) (const void *, const void *)); - -extern "C" OCTAVE_API int -octave_strcasecmp (const char *s1, const char *s2); - -extern "C" OCTAVE_API int -octave_strncasecmp (const char *s1, const char *s2, size_t n); - template T octave_read_value (std::istream& is) @@ -114,14 +104,4 @@ extern OCTAVE_API void octave_write_float_complex (std::ostream& os, const FloatComplex& cval); -#ifdef HAVE_LOADLIBRARY_API -#define WIN32_LEAN_AND_MEAN -#include -extern "C" OCTAVE_API void * -octave_w32_library_search (HINSTANCE handle, const char *name); #endif - -extern "C" OCTAVE_API pid_t -octave_waitpid (pid_t pid, int *status, int options); - -#endif diff -r 8837a42205d3 -r e4e82740e9cd src/ChangeLog --- a/src/ChangeLog Thu Jan 13 07:21:46 2011 -0500 +++ b/src/ChangeLog Thu Jan 13 07:23:36 2011 -0500 @@ -1,3 +1,12 @@ +2011-01-13 John W. Eaton + + * cutils.h: New file. + (octave_sleep, octave_usleep, octave_raw_vsnprintf): Move decls + here from utils.h. + * Makefile.am (octinclude_HEADERS): Add cutils.h to the list. + * utils.h: Include cutils.h. + * cutils.c: Include cutils.h. + 2011-01-12 David Grundberg * DLD-FUNCTIONS/__magick_read__.cc (__magick_read__) [!HAVE_MAGICK]: diff -r 8837a42205d3 -r e4e82740e9cd src/Makefile.am --- a/src/Makefile.am Thu Jan 13 07:21:46 2011 -0500 +++ b/src/Makefile.am Thu Jan 13 07:23:36 2011 -0500 @@ -223,6 +223,7 @@ builtins.h \ c-file-ptr-stream.h \ comment-list.h \ + cutils.h \ debug.h \ defaults.h \ defun-dld.h \ diff -r 8837a42205d3 -r e4e82740e9cd src/cutils.c --- a/src/cutils.c Thu Jan 13 07:21:46 2011 -0500 +++ b/src/cutils.c Thu Jan 13 07:23:36 2011 -0500 @@ -30,6 +30,8 @@ #include #include +#include "cutils.h" + void octave_sleep (unsigned int seconds) { diff -r 8837a42205d3 -r e4e82740e9cd src/cutils.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cutils.h Thu Jan 13 07:23:36 2011 -0500 @@ -0,0 +1,43 @@ +/* + +Copyright (C) 2011 John W. Eaton + +This file is part of Octave. + +Octave is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 3 of the License, or (at your +option) any later version. + +Octave is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +. + +*/ + +#if !defined (octave_cutils_h) +#define octave_cutils_h 1 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +OCTINTERP_API void octave_sleep (unsigned int seconds); + +OCTINTERP_API void octave_usleep (unsigned int useconds); + +OCTINTERP_API int +octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args); + +#ifdef __cplusplus +} +#endif + +#endif diff -r 8837a42205d3 -r e4e82740e9cd src/utils.h --- a/src/utils.h Thu Jan 13 07:21:46 2011 -0500 +++ b/src/utils.h Thu Jan 13 07:23:36 2011 -0500 @@ -33,6 +33,8 @@ #include "dMatrix.h" #include "lo-utils.h" +#include "cutils.h" + class octave_value; class octave_value_list; class string_vector; @@ -119,13 +121,6 @@ extern OCTINTERP_API void octave_sleep (double seconds); -extern "C" OCTINTERP_API void octave_sleep (unsigned int seconds); - -extern "C" OCTINTERP_API void octave_usleep (unsigned int useconds); - -extern "C" OCTINTERP_API int -octave_raw_vsnprintf (char *buf, size_t n, const char *fmt, va_list args); - extern OCTINTERP_API octave_value_list do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), @@ -136,4 +131,5 @@ octave_value do_simple_cellfun (octave_value_list (*fun) (const octave_value_list&, int), const char *fun_name, const octave_value_list& args); + #endif