diff options
-rw-r--r-- | generic/Buffer.cpp | 106 | ||||
-rw-r--r-- | generic/Exceptions.cpp | 163 | ||||
-rw-r--r-- | generic/Handle.cpp | 331 | ||||
-rw-r--r-- | generic/Image.cpp | 86 | ||||
-rw-r--r-- | generic/Input.cpp | 91 | ||||
-rw-r--r-- | generic/Main.cpp | 45 | ||||
-rwxr-xr-x | generic/Makefile | 18 | ||||
-rw-r--r-- | generic/Output.cpp | 101 | ||||
-rw-r--r-- | generic/String.cpp | 414 | ||||
-rw-r--r-- | generic/checkargs.c | 85 | ||||
-rw-r--r-- | generic/datecalc.c | 80 | ||||
-rw-r--r-- | generic/fileutils.cpp | 74 | ||||
-rw-r--r-- | generic/generic.cpp | 58 | ||||
-rw-r--r-- | includes/Buffer.h | 37 | ||||
-rw-r--r-- | includes/Color.h | 10 | ||||
-rw-r--r-- | includes/Exceptions.h | 157 | ||||
-rw-r--r-- | includes/General.h | 12 | ||||
-rw-r--r-- | includes/Handle.h | 63 | ||||
-rw-r--r-- | includes/Image.h | 57 | ||||
-rw-r--r-- | includes/Input.h | 42 | ||||
-rw-r--r-- | includes/Main.h | 24 | ||||
-rw-r--r-- | includes/Output.h | 51 | ||||
-rw-r--r-- | includes/String.h | 74 | ||||
-rw-r--r-- | includes/engine.h | 16 | ||||
-rw-r--r-- | includes/generic.h | 128 | ||||
-rw-r--r-- | includes/glbase.h | 24 | ||||
-rw-r--r-- | includes/glfont.h | 25 | ||||
-rw-r--r-- | includes/gltexture.h | 26 |
28 files changed, 0 insertions, 2398 deletions
diff --git a/generic/Buffer.cpp b/generic/Buffer.cpp deleted file mode 100644 index 36c56a9..0000000 --- a/generic/Buffer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include <string.h> -#include "Buffer.h" -#include "generic.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -Buffer::Buffer() : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0) { } - -Buffer::~Buffer() { - free(buffer); -} - -Buffer::Buffer(const Buffer & b) : Handle(-1), buffer(0), zero(b.zero), realsiz(b.realsiz), bufsiz(b.bufsiz), ptr(b.ptr) { - buffer = (char *) malloc(bufsiz); - memcpy(buffer, b.buffer, bufsiz); -} - -ssize_t Buffer::write(const void *buf, size_t count) throw (GeneralException) { - if (!count) { - return 0; - } - if (count + realsiz > bufsiz) { - int numblocks = (count + realsiz) / realloc_threshold; - int remains = (count + realsiz) % realloc_threshold; - buffer = (char *) realloc(buffer, bufsiz = ((numblocks + (remains ? 1 : 0)) * realloc_threshold)); - } - memcpy(buffer + realsiz, buf, count); - realsiz += count; - - return count; -} - -ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) { - count = MIN(count, realsiz - ptr); - - if (!count) { - return 0; - } - - memcpy(buf, buffer + ptr, count); - ptr += count; - - if (ptr >= realloc_threshold) { - int numblocks = (bufsiz / realloc_threshold) - (ptr / realloc_threshold); - memmove(buffer, buffer + (bufsiz - numblocks * realloc_threshold), numblocks * realloc_threshold); - ptr -= (bufsiz - numblocks * realloc_threshold); - realsiz -= (bufsiz - numblocks * realloc_threshold); - buffer = (char *) realloc(buffer, bufsiz = (numblocks * realloc_threshold)); - } - - return count; -} - -bool Buffer::CanRead() const { - return true; -} - -bool Buffer::CanWrite() const { - return true; -} - -String Buffer::GetName() const { - return "Buffer"; -} - -Buffer Buffer::operator=(const Buffer & b) { - if (b.buffer != buffer) { - free(buffer); - realsiz = b.realsiz; - ptr = b.ptr; - if ((bufsiz = b.bufsiz)) { - buffer = (char *) malloc(bufsiz); - memcpy(buffer, b.buffer, realsiz); - } else { - buffer = 0; - } - } - return *this; -} - -bool Buffer::CanWatch() const { - return false; -} - -ssize_t Buffer::GetSize() const { - return realsiz; -} - -char Buffer::operator[](size_t p) const { - if (p >= realsiz) { - return 0; - } else { - return buffer[ptr + p]; - } -} - -char & Buffer::operator[](size_t p) { - if (p >= realsiz) { - return zero; - } else { - return buffer[ptr + p]; - } -} diff --git a/generic/Exceptions.cpp b/generic/Exceptions.cpp deleted file mode 100644 index 1159cdd..0000000 --- a/generic/Exceptions.cpp +++ /dev/null @@ -1,163 +0,0 @@ -#include <malloc.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <stddef.h> -#ifdef HAVE_GLIB -#include <glib.h> -#endif -#ifdef DEBUG -#include <iostream> -#endif -#include "String.h" -#include "Exceptions.h" -#include "generic.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -char GeneralException::t[BUFSIZ]; - -GeneralException::GeneralException(String emsg) : msg(emsg.strdup()) { -#ifdef DEBUG - cerr << _("Generating a General Exception error: '") << msg << "'.\n"; -#endif -} -GeneralException::GeneralException() : msg(0) { -#ifdef DEBUG - cerr << _("Generating a General Exception error: '") << msg << "'.\n"; -#endif -} -GeneralException::GeneralException(const GeneralException & e) : msg(strdup(e.msg)) { -#ifdef DEBUG - cerr << _("Generating a General Exception error: '") << msg << "'.\n"; -#endif -} - -GeneralException::~GeneralException() { - free(msg); -} - -TaskNotFound::TaskNotFound() : GeneralException("Task not found") { } - -const char * GeneralException::GetMsg() const { - return msg; -} - -MemoryException::MemoryException(ssize_t s) { - sprintf(t, _("Failed allocating %u bytes."), s); - msg = strdup(t); -} - -IOException::IOException(String fn, op_t op, ssize_t s) { - sprintf(t, _("An error has occured while %s %u bytes on %s: %s"), op == IO_WRITE ? _("writing") : _("reading"), - s, fn.to_charp(), strerror(errno)); - msg = strdup(t); -} - -IOGeneral::IOGeneral(String fn) : GeneralException(fn) { } - -IOGeneral::IOGeneral() { } - -IOAgain::IOAgain() : IOGeneral(_("No more bytes for reading or writing.")) { -#ifdef DEBUG - cerr << "Generating an IOAgain exception: '" << GetMsg() << "'.\n"; -#endif -} - -TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked environnement")) { -#ifdef DEBUG - cerr << "Generating a TaskSwitch exception: '" << GetMsg() << "'.\n"; -#endif -} - -Exit::Exit(int a_code) : GeneralException(_("Exitting with code " + a_code)), code(a_code) { -#ifdef DEBUG - cerr << "Generating an Exit exception: '" << GetMsg() << "'.\n"; -#endif -} - -int Exit::GetCode() { - return code; -} - -char * xstrdup(const char * s) { - char * r; - - r = (char *) xmalloc(strlen(s) + 1); - strcpy(r, s); - return r; -} - -void * xmalloc(size_t s) throw (GeneralException) { - char * r; - - if (!s) { - return 0; - } - - if (!(r = (char *) ::malloc(s))) { - throw MemoryException(s); - } -#ifdef DEBUG - fprintf(stderr, "Allocating %i bytes of memory, got it at %p\n", s, r); -#endif - - memset(r, 0, s); - - return (void *)(r); -} - -void * xrealloc(void * ptr, size_t s) { -#ifdef DEBUG - void * r = realloc(ptr, s); - fprintf(stderr, "Reallocating pointer at %p for %i bytes, now at %p\n", ptr, s, r); - return r; -#else - return realloc(ptr, s); -#endif -} - -void xfree(unsigned char *& p) { - xfree(((char *)p)); -} - -void xfree(void *& p) { - xfree(((char *)p)); -} - -void xfree(char *& p) { -#ifdef DEBUG - fprintf(stderr, "Freeing pointer at %p\n", p); -#endif - if (p) { - ::free(p); - p = 0; - } -} - -int xpipe(int * p, int flag) throw (GeneralException) { - if (pipe(p)) { - throw GeneralException(String(_("Error creating pipe: ")) + strerror(errno)); - } - - return p[flag]; -} - -pid_t xfork() throw (GeneralException) { - pid_t p; - - p = fork(); - - if (p == -1) { - throw GeneralException(_("Was not able to fork().\n")); - } - - return p; -} - -void xexit(int status) throw (GeneralException) { - throw Exit(status); -} diff --git a/generic/Handle.cpp b/generic/Handle.cpp deleted file mode 100644 index 8aa48b8..0000000 --- a/generic/Handle.cpp +++ /dev/null @@ -1,331 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <fcntl.h> -#include "Handle.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -Handle::Handle(const Handle & nh) : itell(0), h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed) -#ifdef HAVE_ZLIB -, zfile(0), z(0) -#endif -{ -// cerr << "Duplication of handle " << nh.h << " to " << h << endl; -#ifdef HAVE_ZLIB - if ((h >= 0) && (nh.z)) { - SetZ(nh.z); - } -#endif -} - -Handle::~Handle() { -// cerr << "Destroying handle " << h << endl; - close(); -} - -Handle::Handle(int nh) : h(nh), closed(false), nonblock(false) -#ifdef HAVE_ZLIB -, zfile(0), z(0) -#endif -{ -// cerr << "Initialising handle " << h << endl; -} - -int Handle::GetHandle() { - return h; -} - -int Handle::GetHandle() const { - return h; -} - -ssize_t Handle::write(const void *buf, size_t count) throw (GeneralException) { - ssize_t r, tr = 0; - bool done, full = false; - - do { - done = true; - errno = 0; - if ((r = uwrite(buf, count)) < 0) { - if ((!errno) || (errno == EAGAIN) || (errno == EINTR)) { - // Avant de déclarer une erreur, on vérifie si ce n'est pas un - // problème lié au fait qu'il n'y a plus de place libre. Cela peut - // arriver si l'on agit sur un pipe ou un handle. Nous - // attendons encore une fois avant de déclarer l'erreur, - // grace au drapeau full. - if (full) { - throw IOException(GetName(), IO_WRITE, count); - } else { - done = false; - full = true; - if (nonblock) { -// cerr << "write: throwing IOAgain for handle " << GetName() << endl; - throw IOAgain(); - } else { - sleep(1); - } - } - } else { - throw IOException(GetName(), IO_WRITE, count); - } - } else if (((size_t) r) != count) { - if (nonblock) { - return r; - } - full = done = false; - ((char *)buf) += r; - tr += r; - } - } while (!done); - - return r + tr; -} - -ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) { - ssize_t r; - - errno = 0; - while ((r = uread(buf, count)) < 0) { - if ((!errno) || (errno == EAGAIN) || (errno == EINTR)) { - // Avant de déclarer une erreur, on vérifie si ce n'est pas un - // problème lié au fait qu'il n'y a plus d'octets. - if (nonblock) { -// cerr << "read: throwing IOAgain for handle " << GetName() << endl; - throw IOAgain(); - } - } else { - throw IOException(GetName(), IO_READ, count); - } - } - - if (!r) { - close(); - } - - return r; -} - -bool Handle::IsClosed(void) const { - return closed; -} - -bool Handle::IsNonBlock(void) const { - return nonblock; -} - -void Handle::SetNonBlock(void) { - if ((h >= 0) || !nonblock) { - fcntl(h, F_SETFL, O_NONBLOCK); - } - nonblock = true; -} - -Handle & operator<<(Handle & h, const String & s) { - const char * p; - - p = s.to_charp(); - h.write(p, strlen(p)); - - return h; -} - -Handle & operator>>(Handle & h, String & s) { - char t[BUFSIZ]; - int i = 0, r; - - while ((r = h.read(&(t[i]), 1)) && (i != (BUFSIZ - 1))) { - // Il y a souvent des \r\n dans les sockets par exemple, - // ou bien en lisant des fichiers au format MS-DOS. On - // ignore le \r pour ne garder que le \n, standard sous Unix. - if (t[i] == '\r') { - continue; - } - if (t[i] == '\n') { - break; - } else { - i++; - } - } - - t[i] = '\0'; - s = t; - return h; -} - -void Handle::close() throw (GeneralException) { - if (IsClosed()) { - return; - } - - if (h >= 0) { -#ifdef HAVE_ZLIB - if (z) { -// cerr << "Performing gzclose on handle " << h << endl; - int err = gzclose(zfile); -// cerr << "gzclose returned " << err << endl; - if (err) { - if (err == Z_ERRNO) { - throw GeneralException(String(_("Error during close: ")) + strerror(errno)); - } else { - throw GeneralException(_("Error in zlib during gzclose.")); - } - } - } else { -#else - { -#endif - int err = ::close(h); - if (err) { - throw GeneralException(String(_("Error during close: ")) + strerror(errno)); - } - } - } - - h = -1; - - closed = 1; -} - -bool Handle::CanRead(void) const { - return false; -} - -bool Handle::CanWrite(void) const { - return false; -} - -String Handle::GetName(void) const { - return _("Bare Handle - should not happend"); -} - -ssize_t Handle::GetSize(void) const { - return -1; -} - -time_t Handle::GetModif(void) const { - return -1; -} - -bool Handle::CanWatch(void) const { - return true; -} - -void Handle::Dup(const Handle & H) { - close(); - if (H.h >= 0) { - h = dup(H.h); - } -} - -#ifdef HAVE_ZLIB -void Handle::SetZ(int az) throw (GeneralException) { - if (z) { - throw GeneralException(_("Can't SetZ a Handle twice.")); - } - if (h < 0) { - throw GeneralException(_("Can't SetZ a virtual Handle.")); - } - if (az) { - char format[4]; - int index = 0; - if (CanRead()) { - format[index++] = 'r'; - } - if (CanWrite()) { - format[index++] = 'w'; - } - format[index++] = (char) (az + '0'); - format[index] = 0; -// cerr << "Performing gzdopen on handle " << h << " with mode \"" << format << "\"\n"; - if (!(zfile = gzdopen(h, format))) { - throw GeneralException(_("Was not able to gzdopen.")); - } - z = az; - } -} -#endif - -ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException) { -#ifdef HAVE_ZLIB - if (z) { - itell += count; -// cerr << "Performing gzwrite of " << count << " byte for handle " << h << endl; -#ifdef HAVE_CLEAN_ZLIB - int err = gzwrite(zfile, buf, count); -#else - int err = gzwrite(zfile, (char *) buf, count); -#endif -// cerr << "gzwrite returned " << err << endl; - if (err == 0) { - const char * m = gzerror(zfile, &err); - if (err == Z_ERRNO) { - return -1; - } else { - throw GeneralException(String(_("Error in zlib during gzwrite: ")) + m); - } - } - return err; - } else { -#else - { -#endif - itell += count = ::write(h, buf, count); - return count; - } -} - -ssize_t Handle::uread(void * buf, size_t count) { -#ifdef HAVE_ZLIB - if (z) { - itell += count; -// cerr << "Performing gzread of " << count << " byte for handle " << h << endl; - int err = gzread(zfile, buf, count); -// cerr << "gzwrite returned " << err << endl; - if (err == -1) { - gzerror(zfile, &err); - if (err == Z_ERRNO) { - return -1; - } else { - return 0; - } - } - return err; - } else { -#else - { -#endif - itell += count = ::read(h, buf, count); - return count; - } -} - -off_t Handle::tell() const { - return itell; -} - -bool Handle::CanSeek() const { - return 0; -} - -off_t Handle::seek(off_t, int) throw(GeneralException) { - throw IOGeneral("Handle " + GetName() + " can't seek"); -} - -void copy(Handle * s, Handle * d, ssize_t size) { - long i; - unsigned char c; - long r; - - for (i = 0; (i < size) || (size < 0); i++) { - r = s->read(&c, 1); - if (r == 0) { - break; - } - d->write(&c, 1); - } -} diff --git a/generic/Image.cpp b/generic/Image.cpp deleted file mode 100644 index b8396b1..0000000 --- a/generic/Image.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "Image.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -Image::Image(unsigned int ax, unsigned int ay) : x(ax), y(ay), img((Color *) malloc(x * y * sizeof(Color))) { - Fill(); -} - -Image::~Image() { - free((void *)img); -} - -bool Image::CanWrite() const { - return false; -} - -String Image::GetName() const { - return String(_("Image ")) + x + "x" + y; -} - -void Image::Fill(Color c) { - for (unsigned int i = 0; i < x * y; i++) { - img[i] = c; - } -} - -Color Image::GetPixel(unsigned int px, unsigned int py) const { - if ((px >= x) || (py >= y)) { - return Color(0, 0, 0, 0); - } - - return img[x * py + px]; -} - -void Image::SetPixel(unsigned int px, unsigned int py, Color c) { - if ((px >= x) || (py >= y)) { - return; - } - - img[x * py + px] = c; -} - -#ifndef WORDS_BIGENDIAN -#define WORDS_BIGENDIAN 0 -#endif - -bool Image::Prepare(unsigned int f) { - if (GetSize()) return false; - - switch (f) { - case FORMAT_TGA_BASIC: - TGAHeader Header; - TGAFooter Footer; - - Header.IDLength = 0; - Header.ColorMapType = 0; - Header.ImageType = 2; - Header.CM_FirstEntry = 0; - Header.CM_Length = 0; - Header.CM_EntrySize = 0; - Header.IS_XOrigin = 0; - Header.IS_YOrigin = 0; - Header.IS_Width = WORDS_BIGENDIAN ? ((x & 0xff) << 8) | ((x & 0xff00) >> 8) : x; - Header.IS_Height = WORDS_BIGENDIAN ? ((y & 0xff) << 8) | ((y & 0xff00) >> 8) : y; - Header.IS_Depth = 32; - Header.IS_Descriptor = 0x20; - - Footer.ExtOffset = 0; - Footer.DevOffset = 0; - strcpy(Footer.Sig, "TRUEVISION-XFILE."); - - write(&Header, sizeof(Header)); - write(img, x * y * sizeof(Color)); - write(&Footer, sizeof(Footer)); - - return true; - - break; - default: - return false; - } -} - diff --git a/generic/Input.cpp b/generic/Input.cpp deleted file mode 100644 index 69d28e7..0000000 --- a/generic/Input.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include "Input.h" -#include "Exceptions.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -Input::Input(const String & no) throw (GeneralException) : - Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : dup(0)), - n(no) { - -#ifdef DEBUG - fprintf(stderr, "Opening file %s, Input at %p\n", no.to_charp(), this); -#endif - - if (GetHandle() < 0) { - throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno)); - } - - struct stat s; - fstat(GetHandle(), &s); - date_modif = s.st_mtime; - - if (S_ISREG(s.st_mode)) { - size = seek(0, SEEK_END); - seek(0, SEEK_SET); - } -} - -Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { -} - -bool Input::CanWrite() const { - return 0; -} - -bool Input::CanRead() const { - return 1; -} - -bool Input::CanSeek() const { - struct stat s; - - fstat(GetHandle(), &s); - - return S_ISREG(s.st_mode); -} - -String Input::GetName() const { - return n; -} - -ssize_t Input::GetSize() const { - return size; -} - -time_t Input::GetModif() const { - return date_modif; -} - -off_t Input::seek(off_t offset, int whence) throw (GeneralException) { - if ((itell = lseek(GetHandle(), offset, whence)) < 0) { - throw IOGeneral(String(_("Error seeking file ")) + GetName() + _(": ") + strerror(errno)); - } -#ifdef PARANOID_SEEK - if (itell != lseek(GetHandle(), 0, SEEK_CUR)) { - throw IOGeneral(String(_("Error seeking file ")) + GetName() + _(": the position does not match")); - } -#endif - return itell; -} - -Stdin_t::Stdin_t() { } - -bool Stdin_t::CanSeek() const { - return 0; -} - -String Stdin_t::GetName() const { - return "Stdin"; -} - -Stdin_t Stdin; diff --git a/generic/Main.cpp b/generic/Main.cpp deleted file mode 100644 index 774cf08..0000000 --- a/generic/Main.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "Main.h" -#include "generic.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -Main::Main() : setted(false) {} - -Main::~Main() {} - -extern Main * Application; - -void Main::set_args(int a_argc, char ** a_argv, char ** a_enve) { - if (setted) { - return; - } - argc = a_argc; - argv = a_argv; - enve = a_enve; - setted = true; -} - -int main(int argc, char ** argv, char ** enve) { - int r; - - try { - Application->set_args(argc, argv, enve); - r = Application->startup(); - } - catch (Exit e) { - r = e.GetCode(); - } - catch (GeneralException e) { - printm(M_ERROR, "The application caused an exception: %s\n", e.GetMsg()); - delete Application; - exit(-1); - } - catch (...) { - printm(M_ERROR, "The application caused an unknow exception\n"); - delete Application; - exit(-1); - } - delete Application; - exit(r); -} diff --git a/generic/Makefile b/generic/Makefile deleted file mode 100755 index 1e2b047..0000000 --- a/generic/Makefile +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/make -f - -CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DPARANOID_SEEK -DHAVE_ZLIB -#`pkg-config --cflags glib-2.0` -CXX=g++ -CC=gcc - -OBJECTS = Buffer.o Exceptions.o Handle.o Image.o Input.o Output.o Main.o generic.o String.o checkargs.o datecalc.o -TARGET = generic.a - -all: ${TARGET} Makefile - -generic.a: ${OBJECTS} - ar -r generic.a ${OBJECTS} - ranlib generic.a - -clean: - rm -f *.o *.a ${TARGET} compil.c diff --git a/generic/Output.cpp b/generic/Output.cpp deleted file mode 100644 index b072236..0000000 --- a/generic/Output.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <errno.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include "Output.h" -#include "Exceptions.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#else -#define _(x) x -#endif - -Output::Output(String no, int create, int trunc) throw (GeneralException) : - Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | (O_CREAT * (create ? 1 : 0)) | (O_TRUNC * (trunc ? 1 : 0)) -#if defined __linux__ || defined __CYGWIN32__ -, 00666 -#endif -) : dup(1)), - n(no) { - if (GetHandle() < 0) { - throw IOGeneral(String(_("Error opening file ")) + no + _(" for writing: ") + strerror(errno)); - } - - size = lseek(GetHandle(), 0, SEEK_END); - lseek(GetHandle(), 0, SEEK_SET); - - struct stat s; - - fstat(GetHandle(), &s); - - date_modif = s.st_mtime; -} - -Output::Output(const Output & o) : Handle(o), n(o.n) { -} - -bool Output::CanWrite() const { - return 1; -} - -bool Output::CanRead() const { - return 0; -} - -bool Output::CanSeek() const { - struct stat s; - - fstat(GetHandle(), &s); - - return S_ISREG(s.st_mode); -} - -off_t Output::seek(off_t offset, int whence) throw (GeneralException) { - if ((itell = lseek(GetHandle(), offset, whence)) < 0) { - throw IOGeneral(String(_("Error seeking file ")) + n + _(": ") + strerror(errno)); - } -#ifdef PARANOID_SEEK - if (itell != lseek(GetHandle(), 0, SEEK_CUR)) { - throw IOGeneral(String(_("Error seeking file ")) + n + _(": the position does not match")); - } -#endif - return itell; -} - -String Output::GetName() const { - return n; -} - -Stdout_t::Stdout_t() {} - -bool Stdout_t::CanSeek() const { - return 0; -} - -String Stdout_t::GetName() const { - return "Stdout"; -} - -Stderr_t::Stderr_t() : Handle(dup(2)) {} - -bool Stderr_t::CanWrite() const { - return 1; -} - -bool Stderr_t::CanRead() const { - return 0; -} - -bool Stderr_t::CanSeek() const { - return 0; -} - -String Stderr_t::GetName() const { - return "Stderr"; -} - -Stdout_t Stdout; -Stderr_t Stderr; diff --git a/generic/String.cpp b/generic/String.cpp deleted file mode 100644 index 4c8e399..0000000 --- a/generic/String.cpp +++ /dev/null @@ -1,414 +0,0 @@ -#include <iostream> -#include <string.h> -#include <stdarg.h> -#include <ctype.h> -#include "String.h" -#include "Exceptions.h" -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef USE_DATE -extern "C" { - double dateCalc(char *, char *); - int isDateArgument(char *); -} -#endif - -char String::t[BUFSIZ + 1]; - -String::String(const String & s) : str(Base::strdup(s.str)), siz(s.siz) { -#ifdef DEBUG - fprintf(stderr, "Duplicating string `%s', from %p to %p\n", str, s.str, str); -#endif -} - -String::String(char c) : siz(1) { - char * t = (char *) malloc(2); - - sprintf(t, "%c", c); - str = t; -} - -String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) { -#ifdef DEBUG - fprintf(stderr, "Creating a string with `%s' at %p\n", str, str); -#endif -} - -#if 0 -String::String(const char * s, ...) { - va_list ap; - -#ifdef DEBUG - fprintf(stderr, "Creating a String with s = '%s'\n", s); -#endif - - va_start(ap, s); - vsnprintf(t, BUFSIZ, s, ap); - str = Base::strdup(t); - va_end(ap); - siz = ::strlen(str); -} -#endif - -String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { } - -String::String(int i) { - char t[20]; - - sprintf(t, "%i", i); - str = Base::strdup(t); - siz = ::strlen(str); -} - -String::String(unsigned int i) { - char t[20]; - - sprintf(t, "%u", i); - str = Base::strdup(t); - siz = ::strlen(str); -} - -#ifdef USE_LONGLONG -String::String(long long l) { - char t[40]; - - sprintf(t, "%lld", l); - str = Base::strdup(t); - siz = ::strlen(str); -} - -String::String(unsigned long long l) { - char t[40]; - - sprintf(t, "%llu", l); - str = Base::strdup(t); - siz = ::strlen(str); -} -#endif - -String::String(double d) { - char t[30]; - - sprintf(t, "%g", d); - str = Base::strdup(t); - siz = ::strlen(str); -} - -String::~String() { - free(str); -} - -const char * String::set(const char * s, ...) { - va_list ap; - - if (!s) { - free(str); - str = Base::strdup(""); - t[0] = 0; - return t; - } - -/* This causes a warning: cannot pass objects of type `const String' through `...' - but it is not really a problem. */ - va_start(ap, s); - vsnprintf(t, BUFSIZ, s, ap); - free(str); - str = Base::strdup(t); - va_end(ap); - siz = ::strlen(str); - return t; -} - -const char * String::set(const String & s, ...) { - va_list ap; - - va_start(ap, s); - vsnprintf(t, BUFSIZ, s.str, ap); - free(str); - str = Base::strdup(t); - va_end(ap); - siz = ::strlen(str); - return t; -} - -const char * String::to_charp(size_t from, ssize_t to) const { - if (to < 0) { - strncpy(t, &(str[from]), BUFSIZ); - } else { - if (((size_t) to) >= siz) { - to = siz - 1; - } - - if ((((size_t) to) - from) > BUFSIZ) { - from -= (to - from) - BUFSIZ; - } - - if (((size_t) to) >= from) { - size_t i; - for (i = 0; i <= ((size_t) to) - from; i++) { - t[i] = str[i + from]; - } - t[i] = '\0'; - } else { - t[0] = '\0'; - } - } - return t; -} - -String String::extract(size_t from, ssize_t to) const { - return String(to_charp(from, to)); -} - -char * String::strdup(size_t from, ssize_t to) const { - return Base::strdup(to_charp(from, to)); -} - -int String::to_int(void) const { - int r; - - sscanf(str, "%i", &r); - return r; -} - -double String::to_double(void) const { - double r; - - sscanf(str, "%lf", &r); - return r; -} - -String & String::operator=(const String & s) { - if (str != s.str) { - // On évite l'autodestruction... - free(str); - str = s.strdup(); - siz = s.siz; - } - return *this; -} - -String String::operator+(const String & s) const { - char * t = (char *) malloc(s.siz + siz + 1), * u; - String o; - - strcpy((u = t), str); - u += siz; - strcpy(u, s.str); - o = String(siz + s.siz, t); - free(t); - return o; -} - -String & String::operator+=(const String & s) { - char * t = (char *) malloc(s.siz + siz + 1), * u; - - strcpy((u = t), str); - u += siz; - strcat(u, s.str); - free(str); - str = t; - siz += s.siz; - return (*this); -} - -std::ostream & operator<<(std::ostream & os, const String & s) { - return (os << s.to_charp()); -} - -std::istream & operator>>(std::istream & is, String & s) { - char c = 0; - - s.set(""); - - while (!is.eof()) { - c = is.get(); - if (c == '\n') return is; - if (c == '\r') continue; - s += c; - } - - return is; -} - -bool String::operator!=(const String & s) const { - return (strcmp(str, s.str) != 0); -} - -bool String::operator==(const String & s) const { - return (strcmp(str, s.str) == 0); -} - -bool String::operator<=(const String & s) const { - return (strcmp(str, s.str) <= 0); -} - -bool String::operator>=(const String & s) const { - return (strcmp(str, s.str) >= 0); -} - -bool String::operator<(const String & s) const { - return (strcmp(str, s.str) < 0); -} - -bool String::operator>(const String & s) const { - return (strcmp(str, s.str) > 0); -} - -size_t String::strlen() const { - return (siz); -} - -char String::operator[](size_t i) const { - if (i >= siz) { - return 0; - } else { - return str[i]; - } -} - -ssize_t String::strchr(char c, size_t from) const { - for (size_t i = from; i < siz; i++) { - if (str[i] == c) return i; - } - - return -1; -} - -ssize_t String::strrchr(char c) const { - for (size_t i = siz - 1; i >= 0; i--) { - if (str[i] == c) return i; - } - - return -1; -} - -ssize_t String::strstr(const String & s) const { - char * p = ::strstr(str, s.str); - - if (p) { - return p - str; - } else { - return -1; - } -} - -int String::strchrcnt(char c) const { - size_t i, cnt = 0; - for (i = 0; i < siz; i++) { - if (str[i] == c) cnt++; - } - - return cnt; -} - -#ifdef USE_DATE -String String::to_sqldate(void) const { -/* DD/MM/YYYY ==> YYYYMMMDD */ - return (is_date() ? extract(6, 9) + extract(3, 4) + extract(0, 1) : ""); -} -#endif - -String String::to_sqltime(void) const { -/* h:m ==> h * 60 + m */ - int p = strchr(':'); - return (is_time() ? String(extract(0, p - 1).to_int() * 60 + extract(p + 1).to_int()) : ""); -} - -#ifdef USE_DATE -String String::from_sqldate(void) const { -/* YYYYMMDD ==> DD/MM/YYYY */ - return ((strlen() == 8) && is_number() ? extract(6, 7) + '/' + extract(4, 5) + '/' + extract(0, 3) : ""); -} -#endif - -String String::from_sqltime(void) const { -/* t ==> (t / 60):(t % 60) */ - int t = to_int(); - return (is_number() ? String((int) (t / 60)) + ':' + (t % 60) : ""); -} - -#ifdef USE_DATE -bool String::is_date(void) const { -/* 'DD/MM/YYYY' - 0123456789 */ - - if (strlen() != 10) return false; - if ((str[2] != '/') || (str[5] != '/') || - (!extract(0, 1).is_number()) || - (!extract(3, 4).is_number()) || - (!extract(6, 9).is_number())) { - return (isDateArgument(to_sqldate().str)); - } - - return true; -} - -double String::datedif(const String & s) const { - double r; - if (is_date() && s.is_date()) { - r = dateCalc(str, s.str); - return r < 0 ? -r : r; - } - - return -1; -} -#endif - -bool String::is_number(void) const { - for (size_t i = ((str[0] == '-') ? 1 : 0); i < siz; i++) { - if ((str[i] > '9') || (str[i] < '0')) return false; - } - return true; -} - -bool String::is_float(void) const { - bool seendot = false; - - for (size_t i = ((str[0] == '-') ? 1 : 0); i < siz; i++) { - if ((str[i] > '9') || (str[i] < '0')) { - if ((str[i] == '.') && !seendot) { - seendot = true; - } else { - return false; - } - } - } - - return true; -} - -bool String::is_time(void) const { - int p = strchr(':'); - - if (p == -1) return false; - - // On accepte les heures sous le format xxxxxx:yy pour pouvoir indiquer des durées. - - if ((!extract(0, p - 1).is_number()) || (!extract(p + 1).is_number())) - return false; - - return (extract(p + 1).to_int() < 60) ? true : false; -} - -String operator+(const char * a, const String & b) { - return String(a) + b; -} - -String & String::toupper() { - for (int i = 0; i < strlen(); i++) { - str[i] = ::toupper(str[i]); - } - - return *this; -} - -String & String::tolower() { - for (int i = 0; i < strlen(); i++) { - str[i] = ::tolower(str[i]); - } - - return *this; -} diff --git a/generic/checkargs.c b/generic/checkargs.c deleted file mode 100644 index e1c97be..0000000 --- a/generic/checkargs.c +++ /dev/null @@ -1,85 +0,0 @@ -/* datedif - calculates the difference in days between two dates
- * Copyright (C) 2000 Micael Widell contact: xeniac@linux.nu
- *
- * 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.
- */
-
-#include <stdlib.h> -#include <string.h> -
-int isDateArgument(char* dateString) {
-
- const int MONTHS[] = {31,0,31,30,31,30,31,31,30,31,30,31};
- int i, day, month, year;
- char buffer[5];
-
- /* 'today' is a valid date */
- if (strcmp(dateString, "today") == 0)
- return 1;
-
- /* Numeric dates must be eight characters long */
- if (8 != strlen(dateString))
- return 0;
-
- /* Check that the date is entirely formed of numbers */
- for (i = 0; i < 8; i++) {
- if (dateString[i] < '0' || dateString[i] > '9')
- return 0;
- }
-
- /* Check that the date exists */
- memset(buffer, 0, 5);
- strncpy(buffer, dateString + 6, 2);
- day = atoi(buffer);
- strncpy(buffer, dateString + 4, 2);
- month = atoi(buffer);
- month -= 1;
- strncpy(buffer, dateString, 4);
- year = atoi(buffer);
-
- /* Validate month */
- if (month < 0 || month > 11)
- return 0;
-
- /* Validating dates is simple when the date does not fall into February */
- if (1 != month) {
- if (day < 1 || day > MONTHS[month])
- return 0;
- } else {
- int feb = 28;
-
- /* Februarys are a bit tougher issue */
- if (0 == year % 4) {
- if (0 == year % 100) {
- if (0 == year % 400) {
- feb = 29;
- } else {
- feb = 28;
- }
- } else {
- feb = 29;
- }
- }
- if (day < 1 || day > feb)
- return 0;
- }
-
- /* Avoid user from using dates before 16000301, since those will result in
- incorrect output */
- if(16000301 > atoi(dateString))
- return 0;
-
- return 1;
-}
diff --git a/generic/datecalc.c b/generic/datecalc.c deleted file mode 100644 index e637b26..0000000 --- a/generic/datecalc.c +++ /dev/null @@ -1,80 +0,0 @@ -/* datedif - calculates the difference in days between two dates - * Copyright (C) 2000 Micael Widell contact: xeniac@linux.nu - * - * 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. - */ - -#include <time.h> -#include <stdlib.h> -#include <string.h> - - -/* Gaus's formula - days since 1.3.1600 (Gregorian calendar) */ -int days(register int n, register int m, register int y) -{ - register int cy; - if((m -= 2) <= 0){ - m += 12; y--; - } - y -= 1600; cy = y/100; - return 365*y+y/4-cy+cy/4+367*m/12+n-31; -} - - -double dateCalc(char * date1, char * date2){ - - /* Declare the needed variables */ - char* date[2]; - struct tm *date_tm[2]; - time_t date_time_t[2]; - double dateDifference; - int isToday[2] = { 0, 0 }; - char buffer[5]; - int day[2], month[2], year[2], i; - - date[0] = date1; - date[1] = date2; - - /* If any of the arguments are "today", then include today's date in the - right variables */ - for(i = 0; i < 2; i++){ - if(!strcmp(date[i], "today")){ - time(&date_time_t[i]); - date_tm[i] = localtime(&date_time_t[i]); - day[i] = (*date_tm[i]).tm_mday; - month[i] = (*date_tm[i]).tm_mon + 1; - year[i] = (*date_tm[i]).tm_year + 1900; - isToday[i] = 1; - } - } - - /* Cut out the year, month and day from 8-digit datestrings */ - for (i = 0; i < 2; i++){ - if(!isToday[i]){ - memset(buffer, 0, 5); - strncpy(buffer, &date[i][6], 2); - day[i] = atoi(buffer); - strncpy(buffer, &date[i][4], 2); - month[i] = atoi(buffer); - strncpy(buffer, date[i], 4); - year[i] = atoi(buffer); - } - } - - /* Calculate the difference */ - dateDifference = days(day[1], month[1], year[1]) - days(day[0], month[0], year[0]); - - return dateDifference; -} diff --git a/generic/fileutils.cpp b/generic/fileutils.cpp deleted file mode 100644 index b04a414..0000000 --- a/generic/fileutils.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 - */ - -#include <string.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <unistd.h> -#include "generic.h" - -unsigned long filesize(int f_iso) -{ - long curpos, length; - - curpos = lseek(f_iso, 0, SEEK_CUR); - length = lseek(f_iso, 0, SEEK_END); - lseek(f_iso, curpos, SEEK_SET); - return length; -} - -void copy(int s, int d, long size) { - long i; - unsigned char c; - long r; - - for (i = 0; (i < size) || (size < 0); i++) { - r = read(s, &c, 1); - if (r == 0) { - break; - } - write(d, &c, 1); - } -} - -unsigned long filesize(FILE * f_iso) -{ - long curpos, length; - - curpos = ftell(f_iso); - fseek(f_iso, 0, SEEK_END); - length = ftell(f_iso); - fseek(f_iso, curpos, SEEK_SET); - return length; -} - -void copy(FILE * s, FILE * d, long size) { - long i; - unsigned char c; - long r; - - for (i = 0; (i < size) || (size < 0); i++) { - r = fread(&c, 1, 1, s); - if (r == 0) { - break; - } - fwrite(&c, 1, 1, d); - } -} diff --git a/generic/generic.cpp b/generic/generic.cpp deleted file mode 100644 index bade101..0000000 --- a/generic/generic.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 - */ - -#include <stdio.h> -#include <stdarg.h> - -#include "String.h" - -char verbosity = 0; - -char * heads[] = {"EE", "--", "WW", "II"}; - -void printm(int level, String m, ...) { - va_list ap; - - if (verbosity < level) { - return; - } - - if (level >= 0) { - fprintf(stderr, "(%s) ", heads[level]); - } - - va_start(ap, m); - vfprintf(stderr, m.to_charp(), ap); - va_end(ap); -} - -char ** split(char * s, char t) { - static char * p[100]; - int i; - - for (i = 1, p[0] = s; *s; s++) { - if (*s == t) { - *s = 0; - p[i++] = s + 1; - } - } - p[i] = 0; - - return p; -} diff --git a/includes/Buffer.h b/includes/Buffer.h deleted file mode 100644 index dc4d768..0000000 --- a/includes/Buffer.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef __BUFFER_H__ -#define __BUFFER_H__ -#ifdef __cplusplus - -#include <zlib.h> -#include <Exceptions.h> -#include <Handle.h> - -#ifndef realloc_threshold -#define realloc_threshold 256 -#endif - -class Buffer : public Handle { - public: - Buffer(); - Buffer(const Buffer &); - 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() const; - virtual bool CanWrite() const; - virtual String GetName() const; - virtual Buffer operator=(const Buffer &); - virtual bool CanWatch() const; - virtual ssize_t GetSize() const; - char operator[](size_t) const; - char & operator[](size_t); - - private: - char * buffer, zero; - size_t realsiz, bufsiz, ptr; -}; - -#else -#error This only works with a C++ compiler -#endif -#endif diff --git a/includes/Color.h b/includes/Color.h deleted file mode 100644 index 293c55c..0000000 --- a/includes/Color.h +++ /dev/null @@ -1,10 +0,0 @@ -#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/includes/Exceptions.h b/includes/Exceptions.h deleted file mode 100644 index 74ad938..0000000 --- a/includes/Exceptions.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef __EXCEPTIONS_H__ -#define __EXCEPTIONS_H__ -#ifdef __cplusplus - -#include <stdio.h> -#include <unistd.h> -#include <stddef.h> -#include <string.h> -#include <stdlib.h> - -#define INLINE __inline__ - -class Base { - public: - static char * strdup(const char * s); - static void * malloc(ssize_t s); - static void * realloc(void * p, size_t s); - static void * calloc(size_t n, size_t s); - void * operator new(size_t s); - void * operator new(size_t s, void * p); - 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; - -class GeneralException : public Base { - public: - GeneralException(String); - GeneralException(const GeneralException &); - ~GeneralException(); - const char * GetMsg() const; - - protected: - GeneralException(); - char * msg; - static char t[BUFSIZ]; -}; - -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); -} - -INLINE void * Base::malloc(ssize_t s) { - return xmalloc(s); -} - -INLINE void * Base::realloc(void * p, size_t s) { - return xrealloc(p, s); -} - -INLINE void * Base::calloc(size_t n, size_t s) { - return xmalloc(n * s); -} - -INLINE void * Base::operator new(size_t s) { - return xmalloc(s); -} - -INLINE void * Base::operator new(size_t s, void * p) { - return memset(p, 0, s); -} - -INLINE void Base::operator delete(void * p) { - xfree(p); -} - -INLINE void Base::free(void *& p) { - xfree(p); -} - -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); -} - -INLINE pid_t Base::fork() { - return xfork(); -} - -INLINE void Base::exit(int status) { - xexit(status); -} - -class MemoryException : public GeneralException { - public: - MemoryException(ssize_t); -}; - -class TaskNotFound : public GeneralException { - public: - TaskNotFound(); -}; - -enum op_t { - IO_WRITE = 1, - IO_READ -}; - -class IOGeneral : public GeneralException { - public: - IOGeneral(String); - protected: - IOGeneral(); -}; - -class IOException : public IOGeneral { - public: - IOException(String, op_t, ssize_t); -}; - -class IOAgain : public IOGeneral { - public: - IOAgain(); -}; - -class TaskSwitch : public GeneralException { - public: - TaskSwitch(); -}; - -class Exit : public GeneralException { - public: - Exit(int); - int GetCode(); - private: - int code; -}; - -#include <String.h> - -#else -#error This only works with a C++ compiler -#endif -#endif diff --git a/includes/General.h b/includes/General.h deleted file mode 100644 index 2b645c9..0000000 --- a/includes/General.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __GENERAL_H__ -#define __GENERAL_H__ - -#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/includes/Handle.h b/includes/Handle.h deleted file mode 100644 index b7eed41..0000000 --- a/includes/Handle.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef __HANDLE_H__ -#define __HANDLE_H__ -#ifdef __cplusplus - -#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) const; - bool IsNonBlock(void) const; - void SetNonBlock(void); - 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() const; - virtual void Dup(const Handle &); -#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 -#endif diff --git a/includes/Image.h b/includes/Image.h deleted file mode 100644 index 87a8ddd..0000000 --- a/includes/Image.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __IMAGE_H__ -#define __IMAGE_H__ -#ifdef __cplusplus - -#include <Buffer.h> -#include <generic.h> -#include <Color.h> - -enum { - FORMAT_TGA_BASIC -}; - -class Image : public Buffer { - public: - Image(unsigned int, unsigned int); - virtual ~Image(); - 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() const; - virtual bool CanWrite() const; - - private: - typedef unsigned char Byte; - typedef unsigned short int Word; - typedef unsigned long int DWord; - struct TGAHeader { - Byte IDLength; - Byte ColorMapType; - Byte ImageType; - Word CM_FirstEntry; - Word CM_Length; - Byte CM_EntrySize; - Word IS_XOrigin; - Word IS_YOrigin; - Word IS_Width; - Word IS_Height; - Byte IS_Depth; - Byte IS_Descriptor; - } PACKED; - - struct TGAFooter { - DWord ExtOffset; - DWord DevOffset; - char Sig[18]; - } PACKED; - - unsigned int x, y; - bool r; - Color * img; -}; - -#else -#error This only works with a C++ compiler -#endif -#endif diff --git a/includes/Input.h b/includes/Input.h deleted file mode 100644 index cb1428f..0000000 --- a/includes/Input.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef __INPUT_H__ -#define __INPUT_H__ -#ifdef __cplusplus - -#include <sys/types.h> -#include <time.h> -#include <String.h> -#include <Handle.h> - -class Input : public Handle { - public: - Input(const String & = "") throw (GeneralException); - Input(const Input &); - virtual ~Input() {} - 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; - off_t size; - time_t date_modif; -}; - -class Stdin_t : public Input { - public: - Stdin_t(); - virtual ~Stdin_t() {} - virtual bool CanSeek() const; - virtual String GetName() const; -}; - -extern Stdin_t Stdin; - -#else -#error This only works with a C++ compiler -#endif -#endif diff --git a/includes/Main.h b/includes/Main.h deleted file mode 100644 index 4a81b3e..0000000 --- a/includes/Main.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __MAIN_H__ -#define __MAIN_H__ - -#include "Exceptions.h" - -class Main : public Base { - public: - Main(); - virtual ~Main(); - virtual int startup() throw (GeneralException) = 0; - protected: - void set_args(int, char **, char **); - int argc; - char ** argv; - char ** enve; - bool setted; - - friend int main(int, char **, char **); -}; - -#define CODE_BEGINS class Appli : public Main { -#define CODE_ENDS } * Application = new Appli(); - -#endif diff --git a/includes/Output.h b/includes/Output.h deleted file mode 100644 index eb7b8a6..0000000 --- a/includes/Output.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef __OUTPUT_H__ -#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 create = 1, int trunc = 1) throw (GeneralException); - Output(const Output &); - virtual ~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; - - protected: - String n; - off_t size; - time_t date_modif; -}; - -class Stdout_t : public Output { - public: - Stdout_t(); - virtual ~Stdout_t() {} - virtual bool CanSeek() const; - virtual String GetName() const; -}; - -class Stderr_t : public Handle { - public: - Stderr_t(); - virtual ~Stderr_t() {} - virtual bool CanWrite() const; - virtual bool CanRead() const; - virtual bool CanSeek() const; - virtual String GetName() const; -}; - -extern Stdout_t Stdout; -extern Stderr_t Stderr; - -#else -#error This only works with a C++ compiler -#endif -#endif diff --git a/includes/String.h b/includes/String.h deleted file mode 100644 index 7e2f848..0000000 --- a/includes/String.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __STRING_H__ -#define __STRING_H__ -#ifdef __cplusplus - -#include <iostream> -#include <string.h> -#include <Exceptions.h> - -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_LONGLONG - String(long long); - String(unsigned long long); -#endif - String(double); - ~String(); - const char * set(const char *, ...); - const char * set(const String &, ...); - const char * to_charp(size_t = 0, ssize_t = -1) const; - String extract(size_t = 0, ssize_t = -1) const; - char * strdup(size_t = 0, ssize_t = -1) const; - int to_int() const; - double to_double() const; - String to_sqldate() const; - String to_sqltime() const; - String from_sqldate() const; - String from_sqltime() const; - double datedif(const String &) const; - bool is_date() const; - bool is_number() const; - bool is_float() const; - bool is_time() const; - size_t strlen() const; - ssize_t strchr(char, size_t = 0) const; - ssize_t strrchr(char) const; - ssize_t strstr(const String &) const; - int strchrcnt(char) const; - String & operator=(const String &); - String operator+(const String &) const; - String & operator+=(const String &); - bool operator!=(const String &) const; - bool operator==(const String &) const; - bool operator<=(const String &) const; - bool operator>=(const String &) const; - 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 *); - static char t[]; - char * str; - size_t siz; -}; - -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 -#endif diff --git a/includes/engine.h b/includes/engine.h deleted file mode 100644 index bf53bab..0000000 --- a/includes/engine.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __ENGINE_H__ -#define __ENGINE_H__ - -#include "Exceptions.h" - -namespace mogltk { - class engine : public Base { - public: - static int setup() throw(GeneralException); - static int GetInited(); - private: - static int inited; - }; -}; - -#endif diff --git a/includes/generic.h b/includes/generic.h deleted file mode 100644 index 62a9942..0000000 --- a/includes/generic.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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/includes/glbase.h b/includes/glbase.h deleted file mode 100644 index f8f0ae6..0000000 --- a/includes/glbase.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __GLBASE_H__ -#define __GLBASE_H__ - -#include <SDL.h> -#include "Exceptions.h" - -namespace mogltk { - class glbase : public Base { - public: - static int setup(int w = 640, int h = 480, int flags = 0) throw(GeneralException); - static int GetWidth(void); - static int GetHeight(void); - static int GetInited(void); - static void Enter2DMode(void); - static void Leave2DMode(void); - static void Flip(void); - static bool is2D(void); - private: - static int width, height, inited, twoD; - static SDL_Surface * surface; - }; -}; - -#endif diff --git a/includes/glfont.h b/includes/glfont.h deleted file mode 100644 index 831da5e..0000000 --- a/includes/glfont.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef __GLFONT_H__ -#define __GLFONT_H__ - -#include <SDL.h> -#include "String.h" -#include "gltexture.h" -#include "Color.h" - -namespace mogltk { - class font : public Base { - public: - font(const String & = "font.bin"); - virtual ~font(); - void drawentry(Uint16, Color = Color(255, 255, 255), int = -1, int = -1); - - private: - Uint8 * sizes; - Uint16 nbentries, nbcT, nbT; - Uint8 flags, maxX, maxY, nbcU, nbcV; - texture ** fonttex; - Uint16 * corresp; - }; -}; - -#endif diff --git a/includes/gltexture.h b/includes/gltexture.h deleted file mode 100644 index a094694..0000000 --- a/includes/gltexture.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __GLTEXTURE_H__ -#define __GLTEXTURE_H__ - -#include <GL/gl.h> -#include <SDL.h> -#include "Exceptions.h" - -namespace mogltk { - class texture : public Base { - public: - texture(int = 256, int = 256, bool = false) throw (GeneralException); - virtual ~texture(); - SDL_Surface * GetSurface() throw (GeneralException); - void Generate() throw (GeneralException); - void Bind(bool = true) throw (GeneralException); - GLuint GetWidth(); - GLuint GetHeight(); - static void Unbind(void); - private: - GLuint width, height, tex; - SDL_Surface * surface; - bool planar; - }; -}; - -#endif |