summaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/Buffer.cpp10
-rw-r--r--generic/Exceptions.cpp20
-rw-r--r--generic/Handle.cpp28
-rw-r--r--generic/Image.cpp6
-rw-r--r--generic/Input.cpp16
-rwxr-xr-xgeneric/Makefile5
-rw-r--r--generic/Output.cpp22
-rw-r--r--generic/String.cpp23
8 files changed, 83 insertions, 47 deletions
diff --git a/generic/Buffer.cpp b/generic/Buffer.cpp
index 940b0a8..36c56a9 100644
--- a/generic/Buffer.cpp
+++ b/generic/Buffer.cpp
@@ -54,15 +54,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";
}
@@ -81,11 +81,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/generic/Exceptions.cpp b/generic/Exceptions.cpp
index b7c00a6..510e0a3 100644
--- a/generic/Exceptions.cpp
+++ b/generic/Exceptions.cpp
@@ -3,7 +3,9 @@
#include <string.h>
#include <errno.h>
#include <stddef.h>
+#ifdef HAVE_GLIB
#include <glib.h>
+#endif
#ifdef DEBUG
#include <iostream>
#endif
@@ -40,7 +42,7 @@ GeneralException::~GeneralException() {
TaskNotFound::TaskNotFound() : GeneralException("Task not found") { }
-char * GeneralException::GetMsg() {
+const char * GeneralException::GetMsg() const {
return msg;
}
@@ -71,6 +73,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;
@@ -108,9 +120,9 @@ void * xrealloc(void * ptr, size_t s) {
#endif
}
-#ifdef OVER_FREE
-#undef free
-#endif
+void xfree(unsigned char *& p) {
+ xfree(((char *)p));
+}
void xfree(void *& p) {
xfree(((char *)p));
diff --git a/generic/Handle.cpp b/generic/Handle.cpp
index e95a28a..4e318c6 100644
--- a/generic/Handle.cpp
+++ b/generic/Handle.cpp
@@ -30,6 +30,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;
@@ -96,11 +100,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;
}
@@ -177,27 +181,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;
}
@@ -241,7 +245,11 @@ ssize_t Handle::uwrite(const void * buf, size_t count) throw (GeneralException)
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);
@@ -286,11 +294,11 @@ ssize_t Handle::uread(void * buf, size_t count) {
}
}
-off_t Handle::tell() {
+off_t Handle::tell() const {
return itell;
}
-bool Handle::CanSeek() {
+bool Handle::CanSeek() const {
return 0;
}
diff --git a/generic/Image.cpp b/generic/Image.cpp
index 1270a6a..b8396b1 100644
--- a/generic/Image.cpp
+++ b/generic/Image.cpp
@@ -13,11 +13,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;
}
@@ -27,7 +27,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/generic/Input.cpp b/generic/Input.cpp
index d415279..69d28e7 100644
--- a/generic/Input.cpp
+++ b/generic/Input.cpp
@@ -38,15 +38,15 @@ Input::Input(const String & no) throw (GeneralException) :
Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) {
}
-bool Input::CanWrite() {
+bool Input::CanWrite() const {
return 0;
}
-bool Input::CanRead() {
+bool Input::CanRead() const {
return 1;
}
-bool Input::CanSeek() {
+bool Input::CanSeek() const {
struct stat s;
fstat(GetHandle(), &s);
@@ -54,15 +54,15 @@ bool Input::CanSeek() {
return S_ISREG(s.st_mode);
}
-String Input::GetName() {
+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;
}
@@ -80,11 +80,11 @@ off_t Input::seek(off_t offset, int whence) throw (GeneralException) {
Stdin_t::Stdin_t() { }
-bool Stdin_t::CanSeek() {
+bool Stdin_t::CanSeek() const {
return 0;
}
-String Stdin_t::GetName() {
+String Stdin_t::GetName() const {
return "Stdin";
}
diff --git a/generic/Makefile b/generic/Makefile
index 7107501..1e2b047 100755
--- a/generic/Makefile
+++ b/generic/Makefile
@@ -1,10 +1,11 @@
#!/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`
+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 generic.o String.o checkargs.o datecalc.o
+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
diff --git a/generic/Output.cpp b/generic/Output.cpp
index 55ab158..b072236 100644
--- a/generic/Output.cpp
+++ b/generic/Output.cpp
@@ -14,7 +14,7 @@
#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)) | (trunc ? O_TRUNC : O_APPEND)
+ 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
@@ -37,15 +37,15 @@ Output::Output(String no, int create, int trunc) throw (GeneralException) :
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;
}
-bool Output::CanSeek() {
+bool Output::CanSeek() const {
struct stat s;
fstat(GetHandle(), &s);
@@ -65,35 +65,35 @@ off_t Output::seek(off_t offset, int whence) throw (GeneralException) {
return itell;
}
-String Output::GetName() {
+String Output::GetName() const {
return n;
}
Stdout_t::Stdout_t() {}
-bool Stdout_t::CanSeek() {
+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() {
+bool Stderr_t::CanSeek() const {
return 0;
}
-String Stderr_t::GetName() {
+String Stderr_t::GetName() const {
return "Stderr";
}
diff --git a/generic/String.cpp b/generic/String.cpp
index 24961c5..d879308 100644
--- a/generic/String.cpp
+++ b/generic/String.cpp
@@ -1,6 +1,7 @@
#include <iostream>
#include <string.h>
#include <stdarg.h>
+#include <ctype.h>
#include "String.h"
#include "Exceptions.h"
#ifdef HAVE_CONFIG_H
@@ -27,14 +28,13 @@ String::String(char c) : siz(1) {
str = t;
}
-#if 0
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
}
-#endif
+#if 0
String::String(const char * s, ...) {
va_list ap;
@@ -42,14 +42,13 @@ String::String(const char * s, ...) {
fprintf(stderr, "Creating a String with s = '%s'\n", s);
#endif
-/* 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);
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) { }
@@ -389,3 +388,19 @@ bool String::is_time(void) const {
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;
+}