diff options
-rw-r--r-- | include/Buffer.h | 4 | ||||
-rw-r--r-- | include/Input.h | 6 | ||||
-rw-r--r-- | include/Output.h | 6 | ||||
-rw-r--r-- | lib/Buffer.cc | 14 | ||||
-rw-r--r-- | lib/Input.cc | 11 | ||||
-rw-r--r-- | lib/LuaHandle.cc | 32 | ||||
-rw-r--r-- | lib/Output.cc | 11 |
7 files changed, 74 insertions, 10 deletions
diff --git a/include/Buffer.h b/include/Buffer.h index 47c5c5a..0256853 100644 --- a/include/Buffer.h +++ b/include/Buffer.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Buffer.h,v 1.23 2007-09-17 08:33:25 pixel Exp $ */ +/* $Id: Buffer.h,v 1.24 2008-01-21 17:55:43 pixel Exp $ */ #ifndef __BUFFER_H__ #define __BUFFER_H__ @@ -53,12 +53,14 @@ class Buffer : public Handle { off_t wtell() const; void reset(); const Byte * GetBuffer() const; + static int GetNbBuffer(); private: Byte * buffer, zero; size_t realsiz, bufsiz, ptr, wptr; bool seekable; bool got_eof; + static int nb_buffer; }; #endif diff --git a/include/Input.h b/include/Input.h index 2219273..eb4b2a9 100644 --- a/include/Input.h +++ b/include/Input.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Input.h,v 1.22 2007-05-30 11:57:08 pixel Exp $ */ +/* $Id: Input.h,v 1.23 2008-01-21 17:55:43 pixel Exp $ */ #ifndef __INPUT_H__ #define __INPUT_H__ @@ -36,7 +36,7 @@ class Input : public Handle { public: Input(const String & = "") throw (GeneralException); Input(const Input &); - virtual ~Input() {} + virtual ~Input() { nb_input--; } virtual bool CanWrite() const; virtual bool CanRead() const; virtual bool CanSeek() const; @@ -45,6 +45,7 @@ class Input : public Handle { virtual ssize_t GetSize() const; virtual time_t GetModif() const; virtual void SetZ(int = 9) throw (GeneralException); + static int GetNbInput(); struct openresults_t { String name; @@ -62,6 +63,7 @@ class Input : public Handle { private: int wrapopen(const String &, openresults_t *); + static int nb_input; }; class Stdin_t : public Input { diff --git a/include/Output.h b/include/Output.h index b520277..64209b8 100644 --- a/include/Output.h +++ b/include/Output.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Output.h,v 1.15 2007-05-30 11:57:08 pixel Exp $ */ +/* $Id: Output.h,v 1.16 2008-01-21 17:55:43 pixel Exp $ */ #ifndef __OUTPUT_H__ #define __OUTPUT_H__ @@ -31,12 +31,13 @@ class Output : public Handle { public: Output(String = "", int create = 1, int trunc = 1) throw (GeneralException); Output(const Output &); - virtual ~Output() {} + virtual ~Output() { nb_output--; } virtual bool CanWrite() const; virtual bool CanRead() const; virtual bool CanSeek() const; virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); virtual String GetName() const; + static int GetNbOutput(); protected: String n; @@ -45,6 +46,7 @@ class Output : public Handle { private: int wrapopen(const String &, int, int); + static int nb_output; }; class Stdout_t : public Output { diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 7def194..74e8cda 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Buffer.cc,v 1.29 2007-09-17 08:33:25 pixel Exp $ */ +/* $Id: Buffer.cc,v 1.30 2008-01-21 17:55:43 pixel Exp $ */ #include <string.h> #ifdef HAVE_CONFIG_H @@ -26,15 +26,25 @@ #include "Buffer.h" #include "generic.h" -Buffer::Buffer(bool _seekable) : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0), wptr(0), seekable(_seekable), got_eof(false) { } +int Buffer::nb_buffer = 0; + +int Buffer::GetNbBuffer() { + return nb_buffer; +} + +Buffer::Buffer(bool _seekable) : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0), wptr(0), seekable(_seekable), got_eof(false) { + nb_buffer++; +} Buffer::~Buffer() { free(buffer); + nb_buffer--; } Buffer::Buffer(const Buffer & b) : Handle(-1), buffer(0), zero(b.zero), realsiz(b.realsiz), bufsiz(b.bufsiz), ptr(b.ptr), wptr(b.wptr), seekable(b.seekable), got_eof(b.got_eof) { buffer = (Byte *) malloc(bufsiz); memcpy(buffer, b.buffer, bufsiz); + nb_buffer++; } ssize_t Buffer::write(const void *buf, size_t count) throw (GeneralException) { diff --git a/lib/Input.cc b/lib/Input.cc index eab56e1..23bb55e 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Input.cc,v 1.53 2007-05-30 11:57:10 pixel Exp $ */ +/* $Id: Input.cc,v 1.54 2008-01-21 17:55:43 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -86,6 +86,12 @@ those 4 bytes. static Input::openresults_t gresults; +int Input::nb_input = 0; + +int Input::GetNbInput() { + return nb_input; +} + Input::Input(const String & no) throw (GeneralException) : Handle(no.strlen() ? wrapopen(no, &gresults) : dup(0)), n(no) { @@ -101,6 +107,8 @@ Input::Input(const String & no) throw (GeneralException) : throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno)); } + nb_input++; + results = gresults; UNLOCK @@ -140,6 +148,7 @@ Input::Input(const String & no) throw (GeneralException) : } Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { + nb_input++; } bool Input::CanWrite() const { diff --git a/lib/LuaHandle.cc b/lib/LuaHandle.cc index a1e5ccb..7ff7143 100644 --- a/lib/LuaHandle.cc +++ b/lib/LuaHandle.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHandle.cc,v 1.23 2008-01-21 17:19:07 pixel Exp $ */ +/* $Id: LuaHandle.cc,v 1.24 2008-01-21 17:55:43 pixel Exp $ */ #include "LuaHandle.h" @@ -64,6 +64,9 @@ class sLuaHandle : public Base { static int btell(lua_State * L); static int exists(lua_State * L); static int get_nb_handles(lua_State * L); + static int get_nb_input(lua_State * L); + static int get_nb_output(lua_State * L); + static int get_nb_buffer(lua_State * L); private: static int read(lua_State * L, int); static int write(lua_State * L, int); @@ -489,6 +492,30 @@ int sLuaHandle::get_nb_handles(lua_State * __L) { return 1; } +int sLuaHandle::get_nb_input(lua_State * __L) { + Lua * L = Lua::find(__L); + + L->push((lua_Number) Input::GetNbInput()); + + return 1; +} + +int sLuaHandle::get_nb_output(lua_State * __L) { + Lua * L = Lua::find(__L); + + L->push((lua_Number) Output::GetNbOutput()); + + return 1; +} + +int sLuaHandle::get_nb_buffer(lua_State * __L) { + Lua * L = Lua::find(__L); + + L->push((lua_Number) Buffer::GetNbBuffer()); + + return 1; +} + int sLuaHandle::seek(lua_State * __L) { Lua * L = Lua::find(__L); int n = L->gettop(); @@ -702,4 +729,7 @@ void LuaHandle::pushconstruct(Lua * L) { L->settable(LUA_GLOBALSINDEX); L->declarefunc("get_nb_handles", sLuaHandle::get_nb_handles); + L->declarefunc("get_nb_input", sLuaHandle::get_nb_input); + L->declarefunc("get_nb_output", sLuaHandle::get_nb_output); + L->declarefunc("get_nb_buffer", sLuaHandle::get_nb_buffer); } diff --git a/lib/Output.cc b/lib/Output.cc index d1a00c5..82649e8 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: Output.cc,v 1.26 2007-05-30 11:57:10 pixel Exp $ */ +/* $Id: Output.cc,v 1.27 2008-01-21 17:55:43 pixel Exp $ */ #include <stdio.h> #include <string.h> @@ -41,12 +41,20 @@ #define S_ISREG(x) 1 #endif +int Output::nb_output = 0; + +int Output::GetNbOutput() { + return nb_output; +} + Output::Output(String no, int create, int trunc) throw (GeneralException) : Handle(no.strlen() ? wrapopen(no.to_charp(), create, trunc) : dup(1)), n(no) { if (GetHandle() < 0) { throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno)); } + + nb_output++; size = lseek(GetHandle(), 0, SEEK_END); if (trunc) @@ -101,6 +109,7 @@ int Output::wrapopen(const String & n, int create, int trunc) { } Output::Output(const Output & o) : Handle(o), n(o.n) { + nb_output++; } bool Output::CanWrite() const { |