diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Action.cc | 4 | ||||
| -rw-r--r-- | lib/Buffer.cc | 16 | ||||
| -rw-r--r-- | lib/Confirm.cc | 4 | ||||
| -rw-r--r-- | lib/CopyJob.cc | 5 | ||||
| -rw-r--r-- | lib/Exceptions.cc | 84 | ||||
| -rw-r--r-- | lib/Form.cc | 4 | ||||
| -rw-r--r-- | lib/Handle.cc | 91 | ||||
| -rw-r--r-- | lib/HttpServ.cc | 4 | ||||
| -rw-r--r-- | lib/IRC.cc | 4 | ||||
| -rw-r--r-- | lib/Image.cc | 11 | ||||
| -rw-r--r-- | lib/InPipe.cc | 5 | ||||
| -rw-r--r-- | lib/Input.cc | 62 | ||||
| -rw-r--r-- | lib/Makefile.am | 7 | ||||
| -rw-r--r-- | lib/Menu.cc | 4 | ||||
| -rw-r--r-- | lib/Message.cc | 4 | ||||
| -rw-r--r-- | lib/OutPipe.cc | 5 | ||||
| -rw-r--r-- | lib/Output.cc | 66 | ||||
| -rw-r--r-- | lib/ReadJob.cc | 5 | ||||
| -rw-r--r-- | lib/Regex.cc | 5 | ||||
| -rw-r--r-- | lib/Socket.cc | 5 | ||||
| -rw-r--r-- | lib/String.cc | 70 | ||||
| -rw-r--r-- | lib/Table.cc | 4 | ||||
| -rw-r--r-- | lib/Task.cc | 5 | ||||
| -rw-r--r-- | lib/TaskMan.cc | 7 | ||||
| -rw-r--r-- | lib/Variables.cc | 4 | ||||
| -rw-r--r-- | lib/fileutils.cc | 74 | ||||
| -rw-r--r-- | lib/generic.cc | 58 | 
27 files changed, 498 insertions, 119 deletions
| diff --git a/lib/Action.cc b/lib/Action.cc index d7e8314..72b6800 100644 --- a/lib/Action.cc +++ b/lib/Action.cc @@ -1,7 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "String.h"  #include "Action.h"  #include "HttpServ.h" -#include "config.h"  Action * Action::start = 0; diff --git a/lib/Buffer.cc b/lib/Buffer.cc index 905090e..db8b3ee 100644 --- a/lib/Buffer.cc +++ b/lib/Buffer.cc @@ -1,7 +1,9 @@  #include <string.h> -#include "Buffer.h" -#include "General.h" +#ifdef HAVE_CONFIG_H  #include "config.h" +#endif +#include "Buffer.h" +#include "generic.h"  Buffer::Buffer() : Handle(-1), buffer(0), zero(0), realsiz(0), bufsiz(0), ptr(0) { } @@ -50,15 +52,15 @@ ssize_t Buffer::read(void *buf, size_t count) throw (GeneralException) {      return count;  } -bool Buffer::CanRead() { +bool Buffer::CanRead() const {      return true;  } -bool Buffer::CanWrite() { +bool Buffer::CanWrite() const {      return true;  } -String Buffer::GetName() { +String Buffer::GetName() const {      return "Buffer";  } @@ -77,11 +79,11 @@ Buffer Buffer::operator=(const Buffer & b) {      return *this;  } -bool Buffer::CanWatch() { +bool Buffer::CanWatch() const {      return false;  } -ssize_t Buffer::GetSize() { +ssize_t Buffer::GetSize() const {      return realsiz;  } diff --git a/lib/Confirm.cc b/lib/Confirm.cc index 1176db1..18e56e6 100644 --- a/lib/Confirm.cc +++ b/lib/Confirm.cc @@ -1,8 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "HttpServ.h"  #include "Confirm.h"  #include "Buffer.h"  #include "CopyJob.h" -#include "config.h"  Confirm::Confirm(const String & t, const String & m, const String & U, Action * y, Action * n) :      Action(U), tit(t), msg(m), NYes(y), NNo(n) { } diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index 7acc7c5..3e6180d 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -1,6 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "gettext.h"  #include "CopyJob.h"  #include "General.h" -#include "config.h"  CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz, bool ads, bool add) : s(as), d(ad), ds(ads), dd(add), siz(asiz), cursiz(0), r(0), w(0), tw(0) {      s->SetNonBlock(); diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index fa9c6da..b183b55 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -3,10 +3,19 @@  #include <string.h>  #include <errno.h>  #include <stddef.h> +#ifdef HAVE_GLIB +#include <glib.h> +#endif +#ifdef DEBUG +#include <iostream> +#endif +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "String.h"  #include "Exceptions.h" -#include "General.h" -#include "config.h" +#include "generic.h" +#include "gettext.h"  char GeneralException::t[BUFSIZ]; @@ -32,17 +41,17 @@ GeneralException::~GeneralException() {  TaskNotFound::TaskNotFound() : GeneralException("Task not found") { } -char * GeneralException::GetMsg() { +const char * GeneralException::GetMsg() const {      return msg;  }  MemoryException::MemoryException(ssize_t s) { -    sprintf(t, _("Failed allocating %ld bytes."), 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 %ld bytes on %s: %s"), op == IO_WRITE ? _("writing") : _("reading"), +    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);  } @@ -63,6 +72,16 @@ TaskSwitch::TaskSwitch() : GeneralException(_("Switching task in a non-tasked en  #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; @@ -78,51 +97,42 @@ void * xmalloc(size_t s) throw (GeneralException) {  	return 0;      } -    if (!(r = (char *) ::malloc(s + sizeof(size_t)))) { -	throw MemoryException(s + sizeof(size_t)); +    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 + sizeof(size_t)); +    memset(r, 0, s); -    *((size_t *)r) = s; - -    return (void *)(r + sizeof(size_t)); +    return (void *)(r);  }  void * xrealloc(void * ptr, size_t s) { -    char * r; -    size_t os; -     -    if (!ptr) { -	return xmalloc(s); -    } -     -    os = *(((size_t *) ptr) - 1); -     -    r = (char *) xmalloc(s); - -    if (s) { -	memcpy(r, ptr, MIN(s, os)); -    } -     -    xfree(ptr);     +#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  } -#ifdef OVER_FREE -#undef free -#endif +void xfree(unsigned char *& p) { +    xfree(((char *)p)); +}  void xfree(void *& p) { -    if (p) { -	::free(((char *)p) - sizeof(size_t)); -	p = 0; -    } +    xfree(((char *)p));  }  void xfree(char *& p) { +#ifdef DEBUG +    fprintf(stderr, "Freeing pointer at %p\n", p); +#endif      if (p) { -	::free(p - sizeof(size_t)); +	::free(p);  	p = 0;      }  } @@ -146,3 +156,7 @@ pid_t xfork() throw (GeneralException) {      return p;  } + +void xexit(int status) throw (GeneralException) { +    throw Exit(status); +} diff --git a/lib/Form.cc b/lib/Form.cc index 464dec3..fedfc3e 100644 --- a/lib/Form.cc +++ b/lib/Form.cc @@ -1,8 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Form.h"  #include "HttpServ.h"  #include "Buffer.h"  #include "CopyJob.h" -#include "config.h"  Form::Form(const String & titre, const String & url, const String & inv, String * names, String * invs,  	   String * defaults, String ** lists, String ** descs, int nb, Action * na) : diff --git a/lib/Handle.cc b/lib/Handle.cc index da29a51..0470929 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -3,14 +3,23 @@  #include <string.h>  #include <errno.h>  #include <fcntl.h> -#include "Handle.h" +#ifdef HAVE_CONFIG_H  #include "config.h" +#endif +#include "Handle.h" +#include "gettext.h" -Handle::Handle(const Handle & nh) : h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0) { +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() { @@ -18,7 +27,11 @@ Handle::~Handle() {      close();  } -Handle::Handle(int nh) : h(nh), closed(false), nonblock(false), zfile(0), z(0) { +Handle::Handle(int nh) : h(nh), closed(false), nonblock(false) +#ifdef HAVE_ZLIB +, zfile(0), z(0) +#endif +{  //    cerr << "Initialising handle " << h << endl;  } @@ -26,6 +39,10 @@ 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; @@ -92,11 +109,11 @@ ssize_t Handle::read(void *buf, size_t count) throw (GeneralException) {      return r;  } -bool Handle::IsClosed(void) { +bool Handle::IsClosed(void) const {      return closed;  } -bool Handle::IsNonBlock(void) { +bool Handle::IsNonBlock(void) const {      return nonblock;  } @@ -145,6 +162,7 @@ void Handle::close() throw (GeneralException) {      }      if (h >= 0) { +#ifdef HAVE_ZLIB  	if (z) {  //	    cerr << "Performing gzclose on handle " << h << endl;  	    int err = gzclose(zfile); @@ -157,6 +175,9 @@ void Handle::close() throw (GeneralException) {  		}  	    }  	} else { +#else +	{ +#endif  	    int err = ::close(h);  	    if (err) {  		throw GeneralException(String(_("Error during close: ")) + strerror(errno)); @@ -169,27 +190,27 @@ void Handle::close() throw (GeneralException) {      closed = 1;  } -bool Handle::CanRead(void) { +bool Handle::CanRead(void) const {      return false;  } -bool Handle::CanWrite(void) { +bool Handle::CanWrite(void) const {      return false;  } -String Handle::GetName(void) { +String Handle::GetName(void) const {      return _("Bare Handle - should not happend");  } -ssize_t Handle::GetSize(void) { +ssize_t Handle::GetSize(void) const {      return -1;  } -time_t Handle::GetModif(void) { +time_t Handle::GetModif(void) const {      return -1;  } -bool Handle::CanWatch(void) { +bool Handle::CanWatch(void) const {      return true;  } @@ -200,6 +221,7 @@ void Handle::Dup(const Handle & H) {      }  } +#ifdef HAVE_ZLIB  void Handle::SetZ(int az) throw (GeneralException) {      if (z) {  	throw GeneralException(_("Can't SetZ a Handle twice.")); @@ -225,11 +247,18 @@ void Handle::SetZ(int az) throw (GeneralException) {  	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); @@ -241,12 +270,18 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException)  	}  	return err;      } else { -	return ::write(h, buf, count); +#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; @@ -260,6 +295,36 @@ ssize_t Handle::uread(void * buf, size_t count) {  	}  	return err;      } else { -	return ::read(h, buf, count); +#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/lib/HttpServ.cc b/lib/HttpServ.cc index f649a78..e258fd6 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -1,3 +1,6 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Socket.h"  #include "Action.h"  #include "HttpServ.h" @@ -5,7 +8,6 @@  #include "ReadJob.h"  #include "CopyJob.h"  #include "Task.h" -#include "config.h"  String endhl = "\r\n", endnl = "\n"; @@ -1,7 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "String.h"  #include "IRC.h"  #include "HttpServ.h" -#include "config.h"  ircmsg_t ircmsgs[MSG_COUNT] =  diff --git a/lib/Image.cc b/lib/Image.cc index fedee9e..ad986f6 100644 --- a/lib/Image.cc +++ b/lib/Image.cc @@ -1,5 +1,8 @@ -#include "Image.h" +#ifdef HAVE_CONFIG_H  #include "config.h" +#endif +#include "Image.h" +#include "gettext.h"  Image::Image(unsigned int ax, unsigned int ay) : x(ax), y(ay), img((Color *) malloc(x * y * sizeof(Color))) {      Fill(); @@ -9,11 +12,11 @@ Image::~Image() {      free((void *)img);  } -bool Image::CanWrite() { +bool Image::CanWrite() const {      return false;  } -String Image::GetName() { +String Image::GetName() const {      return String(_("Image ")) + x + "x" + y;  } @@ -23,7 +26,7 @@ void Image::Fill(Color c) {      }  } -Color Image::GetPixel(unsigned int px, unsigned int py) { +Color Image::GetPixel(unsigned int px, unsigned int py) const {      if ((px >= x) || (py >= y)) {  	return Color(0, 0, 0, 0);      } diff --git a/lib/InPipe.cc b/lib/InPipe.cc index c61005f..2048fae 100644 --- a/lib/InPipe.cc +++ b/lib/InPipe.cc @@ -1,6 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "InPipe.h"  #include "Output.h" -#include "config.h" +#include "gettext.h"  InPipe::InPipe() : Handle(pipe(p, 0)), hooked(0) { } diff --git a/lib/Input.cc b/lib/Input.cc index 5652c57..5109d2a 100644 --- a/lib/Input.cc +++ b/lib/Input.cc @@ -5,61 +5,85 @@  #include <sys/types.h>  #include <sys/stat.h>  #include <fcntl.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Input.h"  #include "Exceptions.h" -#include "config.h" +#include "gettext.h" -Input::Input(String no) throw (GeneralException) : +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));      } -    size = lseek(GetHandle(), 0, SEEK_END); -    lseek(GetHandle(), 0, SEEK_SET); -          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() { +bool Input::CanWrite() const {      return 0;  } -bool Input::CanRead() { +bool Input::CanRead() const {      return 1;  } -String Input::GetName() { +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() { +ssize_t Input::GetSize() const {      return size;  } -time_t Input::GetModif() { +time_t Input::GetModif() const {      return date_modif;  } -Stdin_t::Stdin_t() : Handle(dup(0)) { } - -bool Stdin_t::CanWrite() { -    return 0; +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;  } -bool Stdin_t::CanRead() { -    return 1; +Stdin_t::Stdin_t() { } + +bool Stdin_t::CanSeek() const { +    return 0;  } -String Stdin_t::GetName() { +String Stdin_t::GetName() const {      return "Stdin";  } diff --git a/lib/Makefile.am b/lib/Makefile.am index eb8f82e..3560bdc 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -2,12 +2,11 @@ localedir = $(datadir)/locale  DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@  AM_CFLAGS = -O3 -Wall -Wstrict-prototypes  AM_CXXFLAGS = -O3 -Wall -Wstrict-prototypes -INCLUDES = -I../include -I$(includedir) +INCLUDES = -I.. -I../include -I$(includedir)  lib_LTLIBRARIES = libBaltisot.la  libBaltisot_la_SOURCES = Action.cc Buffer.cc checkargs.c Confirm.cc CopyJob.cc \  datecalc.c Exceptions.cc Form.cc Handle.cc HttpServ.cc Image.cc InPipe.cc \  Input.cc IRC.cc Menu.cc Message.cc OutPipe.cc Output.cc ReadJob.cc Regex.cc \ -Socket.cc String.cc Table.cc Task.cc TaskMan.cc Variables.cc - -libBaltisot_la_LDFLAGS = -release $(Baltisot_VERSION_INFO) +Socket.cc String.cc Table.cc Task.cc TaskMan.cc Variables.cc generic.cc \ +fileutils.cc diff --git a/lib/Menu.cc b/lib/Menu.cc index 05d7088..361189f 100644 --- a/lib/Menu.cc +++ b/lib/Menu.cc @@ -1,8 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Menu.h"  #include "HttpServ.h"  #include "CopyJob.h"  #include "Buffer.h" -#include "config.h"  Menu::Menu(const String & t, const String & U, String * ts, Action ** as, int nb) :      Action(U), tit(t), lt(ts), la(as), nba(nb) { } diff --git a/lib/Message.cc b/lib/Message.cc index 572b0a0..5cb8859 100644 --- a/lib/Message.cc +++ b/lib/Message.cc @@ -1,8 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "HttpServ.h"  #include "Message.h"  #include "Buffer.h"  #include "CopyJob.h" -#include "config.h"  Message::Message(const String & t, const String & m, const String & U, Action * n) :      Action(U), tit(t), msg(m), Next(n) { } diff --git a/lib/OutPipe.cc b/lib/OutPipe.cc index eb4b67e..a5404d6 100644 --- a/lib/OutPipe.cc +++ b/lib/OutPipe.cc @@ -1,6 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "OutPipe.h"  #include "Input.h" -#include "config.h" +#include "gettext.h"  OutPipe::OutPipe() : Handle(pipe(p, 1)), hooked(0) { } diff --git a/lib/Output.cc b/lib/Output.cc index e0a37ba..1ebf6db 100644 --- a/lib/Output.cc +++ b/lib/Output.cc @@ -5,58 +5,94 @@  #include <sys/types.h>  #include <sys/stat.h>  #include <fcntl.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Output.h"  #include "Exceptions.h" -#include "config.h" +#include "gettext.h" -Output::Output(String no, int trunc) throw (GeneralException) : -    Handle(no.strlen() ? open(no.to_charp(), O_WRONLY | O_CREAT | (trunc ? O_TRUNC : O_APPEND), 00666) : dup(1)), +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() { +bool Output::CanWrite() const {      return 1;  } -bool Output::CanRead() { +bool Output::CanRead() const {      return 0;  } -String Output::GetName() { -    return n; +bool Output::CanSeek() const { +    struct stat s; + +    fstat(GetHandle(), &s); + +    return S_ISREG(s.st_mode);      } -Stdout_t::Stdout_t() : Handle(dup(1)) {} +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; +} -bool Stdout_t::CanWrite() { -    return 1; +String Output::GetName() const { +    return n;  } -bool Stdout_t::CanRead() { +Stdout_t::Stdout_t() {} + +bool Stdout_t::CanSeek() const {      return 0;  } -String Stdout_t::GetName() { +String Stdout_t::GetName() const {      return "Stdout";  }  Stderr_t::Stderr_t() : Handle(dup(2)) {} -bool Stderr_t::CanWrite() { +bool Stderr_t::CanWrite() const {      return 1;  } -bool Stderr_t::CanRead() { +bool Stderr_t::CanRead() const { +    return 0; +} + +bool Stderr_t::CanSeek() const {      return 0;  } -String Stderr_t::GetName() { +String Stderr_t::GetName() const {      return "Stderr";  } diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc index 8df4863..c31b894 100644 --- a/lib/ReadJob.cc +++ b/lib/ReadJob.cc @@ -1,7 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "ReadJob.h"  #include "HttpServ.h"  #include "Regex.h" -#include "config.h" +#include "gettext.h"  ReadJob::ReadJob(Handle * as, Handle * ad, const Regex & aregex) : s(as), d(ad), regex(&aregex) {      s->SetNonBlock(); diff --git a/lib/Regex.cc b/lib/Regex.cc index 41f303c..7fd9741 100644 --- a/lib/Regex.cc +++ b/lib/Regex.cc @@ -1,5 +1,8 @@ -#include "Regex.h" +#ifdef HAVE_CONFIG_H  #include "config.h" +#endif +#include "Regex.h" +#include "gettext.h"  char t[1024]; diff --git a/lib/Socket.cc b/lib/Socket.cc index c5a43ab..5d09a1a 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -6,12 +6,15 @@  #include <string.h>  #include <strings.h>  #include <errno.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "String.h"  #include "Socket.h"  #include "Exceptions.h"  #include "Input.h"  #include "Output.h" -#include "config.h" +#include "gettext.h"  Socket::Socket() throw (GeneralException) : Handle(socket(AF_INET, SOCK_STREAM, 0)), connected(false), listening(false), writeclosed(false), readclosed(false) {  //    cerr << "Socket(): connected = " << connected << "; readclosed = " << readclosed << "; writeclosed = " << writeclosed << endl; diff --git a/lib/String.cc b/lib/String.cc index 786c623..c7cfce6 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -1,18 +1,27 @@  #include <iostream>  #include <string.h>  #include <stdarg.h> +#include <ctype.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "String.h"  #include "Exceptions.h" -#include "config.h" +#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) { } +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); @@ -21,9 +30,27 @@ String::String(char c) : siz(1) {      str = t;  } -String::String(const char * s) : str(s ? Base::strdup(s) : Base::strdup("")) { +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) { } @@ -43,6 +70,7 @@ String::String(unsigned int i) {      siz = ::strlen(str);  } +#ifdef USE_LONG_LONG  String::String(long long l) {      char t[40]; @@ -58,6 +86,7 @@ String::String(unsigned long long l) {      str = Base::strdup(t);      siz = ::strlen(str);  } +#endif  String::String(double d) {      char t[30]; @@ -74,6 +103,13 @@ String::~String() {  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); @@ -268,10 +304,12 @@ int String::strchrcnt(char c) const {      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 */ @@ -279,10 +317,12 @@ String String::to_sqltime(void) const {      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) */ @@ -290,6 +330,7 @@ String String::from_sqltime(void) const {      return (is_number() ? String((int) (t / 60)) + ':' + (t % 60) : "");  } +#ifdef USE_DATE  bool String::is_date(void) const {  /* 'DD/MM/YYYY'      0123456789 */ @@ -314,6 +355,7 @@ double String::datedif(const String & s) const {      return -1;  } +#endif  bool String::is_number(void) const {      for (size_t i = ((str[0] == '-') ? 1 : 0); i < siz; i++) { @@ -350,3 +392,23 @@ bool String::is_time(void) const {      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/lib/Table.cc b/lib/Table.cc index f2b7bad..2509e4e 100644 --- a/lib/Table.cc +++ b/lib/Table.cc @@ -1,8 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Table.h"  #include "HttpServ.h"  #include "CopyJob.h"  #include "Buffer.h" -#include "config.h"  Table::Table(const String & titre, const String & url, String * heads, String * cells, int nbc, int nbl, Action * na) :      Action(url), tit(titre), hds(heads), cls(cells), nc(nbc), nl(nbl), Next(na) { } diff --git a/lib/Task.cc b/lib/Task.cc index d554000..88f17fa 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -1,9 +1,12 @@  #include <sys/time.h>  #include <iostream> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "TaskMan.h"  #include "Task.h"  #include "String.h" -#include "config.h" +#include "gettext.h"  Task::Task() : current(0), state(TASK_ON_HOLD), stopped(false), suspended(false), wbta(0) {      TaskMan::AddTask(this); diff --git a/lib/TaskMan.cc b/lib/TaskMan.cc index 8cb2e8e..c1c60ae 100644 --- a/lib/TaskMan.cc +++ b/lib/TaskMan.cc @@ -7,8 +7,11 @@  #include <sys/types.h>  #include <unistd.h>  #include <vector> -#include "TaskMan.h" +#ifdef HAVE_CONFIG_H  #include "config.h" +#endif +#include "TaskMan.h" +#include "gettext.h"  #define USE_POLL 1 @@ -267,7 +270,7 @@ void TaskMan::MainLoop() throw (GeneralException) {  	event = E_TIMEOUT;  	if (!w4to.empty()) { -	    time_t curtime = time(); +	    time_t curtime = time(NULL);  	    for (std::vector<w4to_t>::iterator p = w4to.begin(); p != w4to.end(); p++) {  		int cur_to;  		cur_to = (p->to.tv_sec - curtime) * 1000 + p->to.tv_usec; diff --git a/lib/Variables.cc b/lib/Variables.cc index 8ba5374..cc67396 100644 --- a/lib/Variables.cc +++ b/lib/Variables.cc @@ -1,7 +1,9 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif  #include "Variables.h"  #include "HttpServ.h"  #include "String.h" -#include "config.h"  Variables::Variables(int nb) : Vars(nb), nbvars(nb) { } diff --git a/lib/fileutils.cc b/lib/fileutils.cc new file mode 100644 index 0000000..b04a414 --- /dev/null +++ b/lib/fileutils.cc @@ -0,0 +1,74 @@ +/*  + *  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/lib/generic.cc b/lib/generic.cc new file mode 100644 index 0000000..bade101 --- /dev/null +++ b/lib/generic.cc @@ -0,0 +1,58 @@ +/*  + *  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; +} | 
