summaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/Buffer.cpp106
-rw-r--r--generic/Exceptions.cpp163
-rw-r--r--generic/Handle.cpp331
-rw-r--r--generic/Image.cpp86
-rw-r--r--generic/Input.cpp91
-rw-r--r--generic/Main.cpp45
-rwxr-xr-xgeneric/Makefile18
-rw-r--r--generic/Output.cpp101
-rw-r--r--generic/String.cpp414
-rw-r--r--generic/checkargs.c85
-rw-r--r--generic/datecalc.c80
-rw-r--r--generic/fileutils.cpp74
-rw-r--r--generic/generic.cpp58
13 files changed, 0 insertions, 1652 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;
-}