Mercurial > hg > octave-lojdl
changeset 11512:e4e82740e9cd
prototype fixes for C language files
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 13 Jan 2011 07:23:36 -0500 |
parents | 8837a42205d3 |
children | a2289858dcb2 |
files | liboctave/ChangeLog liboctave/Makefile.am liboctave/file-stat.cc liboctave/filemode.c liboctave/filemode.h liboctave/lo-cutils.c liboctave/lo-cutils.h liboctave/lo-utils.h src/ChangeLog src/Makefile.am src/cutils.c src/cutils.h src/utils.h |
diffstat | 13 files changed, 289 insertions(+), 156 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,20 @@ +2011-01-13 John W. Eaton <jwe@octave.org> + + * 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 <jwe@octave.org> * SparseCmplxQR.cc
--- a/liboctave/Makefile.am +++ b/liboctave/Makefile.am @@ -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 \
--- a/liboctave/file-stat.cc +++ b/liboctave/file-stat.cc @@ -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 {
--- a/liboctave/filemode.c +++ b/liboctave/filemode.c @@ -20,8 +20,7 @@ #include <config.h> #endif -#include <sys/types.h> -#include <sys/stat.h> +#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 -}
new file mode 100644 --- /dev/null +++ b/liboctave/filemode.h @@ -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 +<http://www.gnu.org/licenses/>. + +*/ + +#if !defined (octave_liboctave_filemode_h) +#define octave_liboctave_filemode_h 1 + +#include <sys/types.h> +#include <sys/stat.h> + +#ifdef __cplusplus +extern "C" { +#endif + +void mode_string (unsigned short, char *); + +void filemodestring (struct stat *, char *); + +#ifdef __cplusplus +} +#endif + +#endif
--- a/liboctave/lo-cutils.c +++ b/liboctave/lo-cutils.c @@ -38,6 +38,7 @@ #include <string.h> #include <time.h> +#include "lo-cutils.h" #include "syswait.h" OCTAVE_API void
new file mode 100644 --- /dev/null +++ b/liboctave/lo-cutils.h @@ -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 +<http://www.gnu.org/licenses/>. + +*/ + +#if !defined (octave_liboctave_cutils_h) +#define octave_liboctave_cutils_h 1 + +#ifdef HAVE_LOADLIBRARY_API +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#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
--- a/liboctave/lo-utils.h +++ b/liboctave/lo-utils.h @@ -29,8 +29,8 @@ #include <iostream> #include <string> +#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 <typename T> 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 <windows.h> -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
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2011-01-13 John W. Eaton <jwe@octave.org> + + * 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 <individ@acc.umu.se> * DLD-FUNCTIONS/__magick_read__.cc (__magick_read__) [!HAVE_MAGICK]:
--- a/src/Makefile.am +++ b/src/Makefile.am @@ -223,6 +223,7 @@ builtins.h \ c-file-ptr-stream.h \ comment-list.h \ + cutils.h \ debug.h \ defaults.h \ defun-dld.h \
--- a/src/cutils.c +++ b/src/cutils.c @@ -30,6 +30,8 @@ #include <sys/types.h> #include <unistd.h> +#include "cutils.h" + void octave_sleep (unsigned int seconds) {
new file mode 100644 --- /dev/null +++ b/src/cutils.h @@ -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 +<http://www.gnu.org/licenses/>. + +*/ + +#if !defined (octave_cutils_h) +#define octave_cutils_h 1 + +#include <stdarg.h> + +#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
--- a/src/utils.h +++ b/src/utils.h @@ -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