diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/Buffer.h | 10 | ||||
-rw-r--r-- | include/Color.h | 10 | ||||
-rw-r--r-- | include/Exceptions.h | 22 | ||||
-rw-r--r-- | include/General.h | 5 | ||||
-rw-r--r-- | include/Handle.h | 37 | ||||
-rw-r--r-- | include/Image.h | 20 | ||||
-rw-r--r-- | include/Input.h | 21 | ||||
-rw-r--r-- | include/Output.h | 28 | ||||
-rw-r--r-- | include/String.h | 9 | ||||
-rw-r--r-- | include/generic.h | 128 | ||||
-rw-r--r-- | include/gettext.h | 72 |
11 files changed, 311 insertions, 51 deletions
diff --git a/include/Buffer.h b/include/Buffer.h index 79d0e02..dc4d768 100644 --- a/include/Buffer.h +++ b/include/Buffer.h @@ -17,12 +17,12 @@ class Buffer : public Handle { virtual ~Buffer(); virtual ssize_t write(const void *buf, size_t count) throw(GeneralException); virtual ssize_t read(void *buf, size_t count) throw (GeneralException); - virtual bool CanRead(); - virtual bool CanWrite(); - virtual String GetName(); + virtual bool CanRead() const; + virtual bool CanWrite() const; + virtual String GetName() const; virtual Buffer operator=(const Buffer &); - virtual bool CanWatch(); - virtual ssize_t GetSize(); + virtual bool CanWatch() const; + virtual ssize_t GetSize() const; char operator[](size_t) const; char & operator[](size_t); diff --git a/include/Color.h b/include/Color.h new file mode 100644 index 0000000..293c55c --- /dev/null +++ b/include/Color.h @@ -0,0 +1,10 @@ +#ifndef __COLOR_H__ +#define __COLOR_H__ + +struct Color { + Color(unsigned char aR, unsigned char aG, unsigned char aB, unsigned char aA = 255) : + R(aR), G(aG), B(aB), A(aA) { } + unsigned char R, G, B, A; +}; + +#endif diff --git a/include/Exceptions.h b/include/Exceptions.h index ef697e7..74ad938 100644 --- a/include/Exceptions.h +++ b/include/Exceptions.h @@ -21,8 +21,10 @@ class Base { void operator delete(void * p); static void free(void *& p); static void free(char *& p); + static void free(unsigned char *& p); static int pipe(int * p, int flag = 0); static pid_t fork(); + static void exit(int); }; class String; @@ -32,7 +34,7 @@ class GeneralException : public Base { GeneralException(String); GeneralException(const GeneralException &); ~GeneralException(); - char * GetMsg(); + const char * GetMsg() const; protected: GeneralException(); @@ -44,9 +46,11 @@ char * xstrdup(const char *); void * xmalloc(size_t) throw (GeneralException); void xfree(void *&); void xfree(char *&); +void xfree(unsigned char *&); void * xrealloc(void *, size_t); int xpipe(int *, int = 0) throw (GeneralException); pid_t xfork() throw (GeneralException); +void xexit(int) throw (GeneralException); INLINE char * Base::strdup(const char * s) { return xstrdup(s); @@ -84,6 +88,10 @@ INLINE void Base::free(char *& p) { xfree(p); } +INLINE void Base::free(unsigned char *& p) { + xfree(p); +} + INLINE int Base::pipe(int * p, int flag) { return xpipe(p, flag); } @@ -92,6 +100,10 @@ INLINE pid_t Base::fork() { return xfork(); } +INLINE void Base::exit(int status) { + xexit(status); +} + class MemoryException : public GeneralException { public: MemoryException(ssize_t); @@ -129,6 +141,14 @@ class TaskSwitch : public GeneralException { TaskSwitch(); }; +class Exit : public GeneralException { + public: + Exit(int); + int GetCode(); + private: + int code; +}; + #include <String.h> #else diff --git a/include/General.h b/include/General.h index 6f423ed..2b645c9 100644 --- a/include/General.h +++ b/include/General.h @@ -4,4 +4,9 @@ #define MAX(__a,__b) ((__a)<(__b)?(__b):(__a)) #define MIN(__a,__b) ((__a)>(__b)?(__b):(__a)) +#define BITCOUNT(x) (((BX_(x)+(BX_(x)>>4)) & 0x0F0F0F0F) % 255) +#define BX_(x) ((x) - (((x)>>1)&0x77777777) \ + - (((x)>>2)&0x33333333) \ + - (((x)>>3)&0x11111111)) + #endif diff --git a/include/Handle.h b/include/Handle.h index 6e26e9c..9744b7e 100644 --- a/include/Handle.h +++ b/include/Handle.h @@ -2,48 +2,61 @@ #define __HANDLE_H__ #ifdef __cplusplus +#include <sys/types.h> +#include <time.h> + +#ifdef HAVE_ZLIB #include <zlib.h> +#endif #include <unistd.h> #include <iostream> #include <String.h> #include <Exceptions.h> -#include <sys/types.h> -#include <time.h> - class Handle : public Base { public: Handle(const Handle &); virtual ~Handle(); virtual ssize_t read(void *buf, size_t count) throw (GeneralException); virtual ssize_t write(const void *buf, size_t count) throw (GeneralException); - bool IsClosed(void); - bool IsNonBlock(void); + bool IsClosed(void) const; + bool IsNonBlock(void) const; void SetNonBlock(void); - virtual bool CanRead(); - virtual bool CanWrite(); - virtual String GetName(); - virtual ssize_t GetSize(); - virtual time_t GetModif(); + virtual bool CanRead() const; + virtual bool CanWrite() const; + virtual bool CanSeek() const; + virtual off_t seek(off_t, int = SEEK_SET) throw (GeneralException); + virtual off_t tell() const; + virtual String GetName() const; + virtual ssize_t GetSize() const; + virtual time_t GetModif() const; void close() throw (GeneralException); int GetHandle(); - virtual bool CanWatch(); + virtual bool CanWatch() const; virtual void Dup(const Handle &); - virtual void SetZ(int) throw (GeneralException); +#ifdef HAVE_ZLIB + virtual void SetZ(int = 9) throw (GeneralException); +#endif protected: Handle(int h); + int GetHandle() const; + off_t itell; private: ssize_t uwrite(const void *, size_t) throw (GeneralException); ssize_t uread(void *, size_t); int h; bool closed, nonblock; +#ifdef HAVE_ZLIB gzFile zfile; int z; +#endif }; Handle & operator<<(Handle &, const String &); Handle & operator>>(Handle &, String &); +void copy(Handle *, Handle *, ssize_t = -1); + #else #error This only works with a C++ compiler #endif diff --git a/include/Image.h b/include/Image.h index 8fd719c..87a8ddd 100644 --- a/include/Image.h +++ b/include/Image.h @@ -3,27 +3,23 @@ #ifdef __cplusplus #include <Buffer.h> +#include <generic.h> +#include <Color.h> enum { - FORMAT_TGA_BASIC, -} format_t; - -struct Color { - Color(unsigned char aR, unsigned char aG, unsigned char aB, unsigned char aA = 255) : - R(aR), G(aG), B(aB), A(aA) { } - unsigned char R, G, B, A; + FORMAT_TGA_BASIC }; class Image : public Buffer { public: Image(unsigned int, unsigned int); virtual ~Image(); - Color GetPixel(unsigned int, unsigned int); + Color GetPixel(unsigned int, unsigned int) const; void SetPixel(unsigned int, unsigned int, Color); bool Prepare(unsigned int = FORMAT_TGA_BASIC); void Fill(Color = Color(0, 0, 0)); - virtual String GetName(); - virtual bool CanWrite(); + virtual String GetName() const; + virtual bool CanWrite() const; private: typedef unsigned char Byte; @@ -42,13 +38,13 @@ class Image : public Buffer { Word IS_Height; Byte IS_Depth; Byte IS_Descriptor; - } __attribute__((packed)); + } PACKED; struct TGAFooter { DWord ExtOffset; DWord DevOffset; char Sig[18]; - } __attribute__((packed)); + } PACKED; unsigned int x, y; bool r; diff --git a/include/Input.h b/include/Input.h index 7091258..cb1428f 100644 --- a/include/Input.h +++ b/include/Input.h @@ -9,14 +9,16 @@ class Input : public Handle { public: - Input(String = "") throw (GeneralException); + Input(const String & = "") throw (GeneralException); Input(const Input &); virtual ~Input() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual String GetName(); - virtual ssize_t GetSize(); - virtual time_t GetModif(); + 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; + virtual ssize_t GetSize() const; + virtual time_t GetModif() const; protected: String n; @@ -24,13 +26,12 @@ class Input : public Handle { time_t date_modif; }; -class Stdin_t : public Handle { +class Stdin_t : public Input { public: Stdin_t(); virtual ~Stdin_t() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual String GetName(); + virtual bool CanSeek() const; + virtual String GetName() const; }; extern Stdin_t Stdin; diff --git a/include/Output.h b/include/Output.h index 32d4e66..eb7b8a6 100644 --- a/include/Output.h +++ b/include/Output.h @@ -2,38 +2,44 @@ #define __OUTPUT_H__ #ifdef __cplusplus +#include <sys/types.h> +#include <time.h> #include <String.h> #include <Handle.h> class Output : public Handle { public: - Output(String = "", int trunc = 1) throw (GeneralException); + Output(String = "", int create = 1, int trunc = 1) throw (GeneralException); Output(const Output &); virtual ~Output() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual String GetName(); + 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; protected: String n; + off_t size; + time_t date_modif; }; -class Stdout_t : public Handle { +class Stdout_t : public Output { public: Stdout_t(); virtual ~Stdout_t() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual String GetName(); + virtual bool CanSeek() const; + virtual String GetName() const; }; class Stderr_t : public Handle { public: Stderr_t(); virtual ~Stderr_t() {} - virtual bool CanWrite(); - virtual bool CanRead(); - virtual String GetName(); + virtual bool CanWrite() const; + virtual bool CanRead() const; + virtual bool CanSeek() const; + virtual String GetName() const; }; extern Stdout_t Stdout; diff --git a/include/String.h b/include/String.h index f8db2c7..27a7f2c 100644 --- a/include/String.h +++ b/include/String.h @@ -10,11 +10,16 @@ class String : public Base { public: String(const String &); String(const char * = ""); +#if 0 + String(const char * = "", ...); +#endif String(char); String(int); String(unsigned int); +#ifdef USE_LONG_LONG String(long long); String(unsigned long long); +#endif String(double); ~String(); const char * set(const char *, ...); @@ -48,6 +53,8 @@ class String : public Base { bool operator<(const String &) const; bool operator>(const String &) const; char operator[](size_t i) const; + String & toupper(); + String & tolower(); private: String(int hs, const char *); @@ -59,6 +66,8 @@ class String : public Base { std::ostream & operator<<(std::ostream &, const String &); std::istream & operator>>(std::istream &, String &); +String operator+(const char *, const String &); + #else #error This only works with a C++ compiler #endif diff --git a/include/generic.h b/include/generic.h new file mode 100644 index 0000000..62a9942 --- /dev/null +++ b/include/generic.h @@ -0,0 +1,128 @@ +/* + * PSX-Tools Bundle Pack + * Copyright (C) 2002 Nicolas "Pixel" Noble + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __GENERIC_H__ +#define __GENERIC_H__ +#ifdef __cplusplus +#include "String.h" +#endif + +#define M_BARE -1 +#define M_ERROR 0 +#define M_STATUS 1 +#define M_WARNING 2 +#define M_INFO 3 + +#ifndef bcopy +#define bcopy(x,y,z) memcpy((y),(x),(z)) +#endif + +#ifndef MAX +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +#ifndef MAX +#define MAX(a,b) ((a)<(b)?(b):(a) +#endif + +#ifndef SDL_VERSIONNUM +typedef unsigned long int Uint32; +#endif + +#ifndef int32 +typedef signed long int int32; +#endif + +#ifndef Uint16 +typedef unsigned short int Uint16; +#endif + +#ifndef int16 +typedef signed short int int16; +#endif + +#ifndef Uint8 +typedef unsigned char Uint8; +#endif + +#ifndef int8 +typedef signed char int8; +#endif + +#ifndef Byte +typedef Uint8 Byte; +#endif + +#ifndef Word +typedef Uint16 Word; +#endif + +#ifndef DWord +typedef Uint32 DWord; +#endif + +#if defined __linux__ || defined __CYGWIN32__ +#define PACKED __attribute__((packed)) +#else +#define PACKED +#endif + +extern char verbosity; +char ** split(char * s, char t); + +#ifdef __cplusplus +void printm(int level, String fmt, ...); + +#ifndef MAX +template<class T> +inline T MAX(T a, T b) { + return a < b ? b : a; +} +#endif + +#ifndef MIN +template<class T> +inline T MIN(T a, T b) { + return a > b ? b : a; +} +#endif + +#else +#ifndef MAX +#define MAX(__a,__b) ((__a)<(__b)?(__b):(__a)) +#endif + +#ifndef MIN +#define MIN(__a,__b) ((__a)>(__b)?(__b):(__a)) +#endif + +#endif + +#include <sys/types.h> +#include <sys/stat.h> + +#if defined __linux__ || defined __CYGWIN32__ +#define MKDIR(name) mkdir(name, 0777) +#elif defined __WIN32__ +#define MKDIR mkdir +#else +#error Unknow compiler/platform +#endif + +#endif diff --git a/include/gettext.h b/include/gettext.h new file mode 100644 index 0000000..ab2d962 --- /dev/null +++ b/include/gettext.h @@ -0,0 +1,72 @@ +/* Convenience header for conditional use of GNU <libintl.h>. + Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU Library General Public License as published + by the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, + USA. */ + +#ifndef _LIBGETTEXT_H +#define _LIBGETTEXT_H 1 + +/* NLS can be disabled through the configure --disable-nls option. */ +#if ENABLE_NLS + +/* Get declarations of GNU message catalog functions. */ +# include <libintl.h> + +#else + +/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which + chokes if dcgettext is defined as a macro. So include it now, to make + later inclusions of <locale.h> a NOP. We don't include <libintl.h> + as well because people using "gettext.h" will not include <libintl.h>, + and also including <libintl.h> would fail on SunOS 4, whereas <locale.h> + is OK. */ +#if defined(__sun) +# include <locale.h> +#endif + +/* Disabled NLS. + The casts to 'const char *' serve the purpose of producing warnings + for invalid uses of the value returned from these functions. + On pre-ANSI systems without 'const', the config.h file is supposed to + contain "#define const". */ +# define gettext(Msgid) ((const char *) (Msgid)) +# define dgettext(Domainname, Msgid) ((const char *) (Msgid)) +# define dcgettext(Domainname, Msgid, Category) ((const char *) (Msgid)) +# define ngettext(Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define dngettext(Domainname, Msgid1, Msgid2, N) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \ + ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2)) +# define textdomain(Domainname) ((const char *) (Domainname)) +# define bindtextdomain(Domainname, Dirname) ((const char *) (Dirname)) +# define bind_textdomain_codeset(Domainname, Codeset) ((const char *) (Codeset)) + +#endif + +/* A pseudo function call that serves as a marker for the automated + extraction of messages, but does not call gettext(). The run-time + translation is done at a different place in the code. + The argument, String, should be a literal string. Concatenated strings + and other string expressions won't work. + The macro's expansion is not parenthesized, so that it is suitable as + initializer for static 'char[]' or 'const char[]' variables. */ +#define gettext_noop(String) String + +#define _(Text) gettext (Text) +#define N_(Text) Text + +#endif /* _LIBGETTEXT_H */ |