summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/Exceptions.cc54
-rw-r--r--lib/HttpServ.cc6
-rw-r--r--lib/InPipe.cc3
-rw-r--r--lib/Main.cc45
-rw-r--r--lib/Makefile.am6
-rw-r--r--lib/String.cc31
6 files changed, 132 insertions, 13 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc
index b183b55..c46dcfc 100644
--- a/lib/Exceptions.cc
+++ b/lib/Exceptions.cc
@@ -93,7 +93,7 @@ char * xstrdup(const char * s) {
void * xmalloc(size_t s) throw (GeneralException) {
char * r;
- if (!s) {
+ if (s == 0) {
return 0;
}
@@ -160,3 +160,55 @@ pid_t xfork() throw (GeneralException) {
void xexit(int status) throw (GeneralException) {
throw Exit(status);
}
+
+char * Base::strdup(const char * s) {
+ return xstrdup(s);
+}
+
+void * Base::malloc(ssize_t s) {
+ return xmalloc(s);
+}
+
+void * Base::realloc(void * p, size_t s) {
+ return xrealloc(p, s);
+}
+
+void * Base::calloc(size_t n, size_t s) {
+ return xmalloc(n * s);
+}
+
+void * Base::operator new(size_t s) {
+ return xmalloc(s);
+}
+
+void * Base::operator new(size_t s, void * p) {
+ return memset(p, 0, s);
+}
+
+void Base::operator delete(void * p) {
+ xfree(p);
+}
+
+void Base::free(void *& p) {
+ xfree(p);
+}
+
+void Base::free(char *& p) {
+ xfree(p);
+}
+
+void Base::free(unsigned char *& p) {
+ xfree(p);
+}
+
+int Base::pipe(int * p, int flag) {
+ return xpipe(p, flag);
+}
+
+pid_t Base::fork() {
+ return xfork();
+}
+
+void Base::exit(int status) {
+ xexit(status);
+}
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index e258fd6..004567b 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -426,9 +426,13 @@ String ProcessRequest::GetMime(const String & f) {
return "text/plain";
}
-HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) : p(ap), name(nname), localport(port) {
+HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) {
bool r = true;
+ p = ap;
+ name = nname;
+ localport = port;
+
// std::cerr << "Initialising Mini HTTP-Server on port " << localport << std::endl;
r = Listener.SetLocal("", port);
diff --git a/lib/InPipe.cc b/lib/InPipe.cc
index 2048fae..efcab10 100644
--- a/lib/InPipe.cc
+++ b/lib/InPipe.cc
@@ -5,7 +5,8 @@
#include "Output.h"
#include "gettext.h"
-InPipe::InPipe() : Handle(pipe(p, 0)), hooked(0) { }
+InPipe::InPipe() : Handle(pipe(p, 0)), hooked(0) {
+}
InPipe::InPipe(const InPipe & i) : Handle(i), hooked(i.hooked) {
p[0] = GetHandle();
diff --git a/lib/Main.cc b/lib/Main.cc
new file mode 100644
index 0000000..774cf08
--- /dev/null
+++ b/lib/Main.cc
@@ -0,0 +1,45 @@
+#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/lib/Makefile.am b/lib/Makefile.am
index 3560bdc..3e921e6 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -1,7 +1,7 @@
localedir = $(datadir)/locale
DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
-AM_CFLAGS = -O3 -Wall -Wstrict-prototypes
-AM_CXXFLAGS = -O3 -Wall -Wstrict-prototypes
+AM_CFLAGS = -O3 -Wall -Wstrict-prototypes -g
+AM_CXXFLAGS = -O3 -Wall -Wstrict-prototypes -g
INCLUDES = -I.. -I../include -I$(includedir)
lib_LTLIBRARIES = libBaltisot.la
@@ -9,4 +9,4 @@ 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 generic.cc \
-fileutils.cc
+fileutils.cc Main.cc
diff --git a/lib/String.cc b/lib/String.cc
index c7cfce6..062587d 100644
--- a/lib/String.cc
+++ b/lib/String.cc
@@ -8,6 +8,8 @@
#include "String.h"
#include "Exceptions.h"
+char ** gruikptr;
+
#ifdef USE_DATE
extern "C" {
double dateCalc(char *, char *);
@@ -19,21 +21,30 @@ 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);
+ fprintf(stderr, "Duplicating string `%s', from %p to %p, from this %p to this %p\n", str, s.str, str, s, this);
#endif
+ ostr = Base::strdup(str);
}
String::String(char c) : siz(1) {
char * t = (char *) malloc(2);
+#ifdef DEBUG
+ fprintf(stderr, "Creating a string with `%c' at %p, this = %p\n", c, str, this);
+#endif
sprintf(t, "%c", c);
str = t;
+ ostr = Base::strdup(str);
}
String::String(const char * s) : str(Base::strdup(s)), siz(::strlen(str)) {
+ if (!strcmp(s, "testing")) {
+ gruikptr = &str;
+ }
#ifdef DEBUG
- fprintf(stderr, "Creating a string with `%s' at %p\n", str, str);
+ fprintf(stderr, "Creating a string with `%s' at %p from %p, this = %p\n", str, str, s, this);
#endif
+ ostr = Base::strdup(str);
}
#if 0
@@ -52,7 +63,12 @@ String::String(const char * s, ...) {
}
#endif
-String::String(int hs, const char * s) : str(s ? Base::strdup(s) : Base::strdup("")), siz(hs) { }
+String::String(int hs, char * s) : str(Base::strdup(s ? s : "")), siz(hs) {
+#ifdef DEBUG
+ fprintf(stderr, "Fast-Creating a string with `%s' at %p from %p, this = %p\n", str, str, s, this);
+#endif
+ ostr = Base::strdup(str);
+}
String::String(int i) {
char t[20];
@@ -97,6 +113,10 @@ String::String(double d) {
}
String::~String() {
+#ifdef DEBUG
+ fprintf(stderr, "Destroying string @ %p, freeing %p.\n", this, str);
+ fprintf(stderr, "Destroying string `%s'\n", ostr);
+#endif
free(str);
}
@@ -192,14 +212,11 @@ String & String::operator=(const String & s) {
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;
+ return String(siz + s.siz, t);
}
String & String::operator+=(const String & s) {