summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac21
-rw-r--r--include/Exceptions.h54
-rw-r--r--include/Main.h24
-rw-r--r--include/Makefile.am2
-rw-r--r--include/String.h4
-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
-rw-r--r--src/Main.cc20
-rw-r--r--src/Makefile.am6
13 files changed, 185 insertions, 91 deletions
diff --git a/configure.ac b/configure.ac
index 972279b..eb96f64 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,8 +3,8 @@
AC_PREREQ(2.56)
-PACKAGE=Baltisot
-VERSION=0.1.0
+AC_DEFINE(PACKAGE, [Baltisot], "Package name")
+AC_DEFINE(VERSION, [0.1.0], "Version")
AC_SUBST(PACKAGE, [Baltisot])
AC_SUBST(VERSION, [0.1.0])
@@ -81,17 +81,8 @@ if test x$ac_cv_search_deflate != xno ; then
)
)
CPPFLAGS=$OLDCPPFLAGS
-fi
+fi
-AC_CACHE_CHECK([usable long long], ac_cv_use_longlong,
- AC_TRY_COMPILE(
- [],
- [unsigned long long t;],
- [AC_DEFINE([USE_LONG_LONG], 1, [Can use Long Long])
- ac_cv_use_longlong="yes"],
- [ac_cv_use_longlong="no"]
- )
-)
AC_CHECK_FUNCS(gethostbyname)
AC_CHECK_FUNCS(regcomp)
@@ -107,7 +98,10 @@ else
AC_MSG_RESULT($system)
fi
-
+
+AC_DEFINE(USE_LONG_LONG, 1, [Use long long])
+AC_DEFINE(USE_DATE, 1, [Use the String's date extension])
+AC_DEFINE(DEBUG, 1, [Enable verbose debugging])
AC_CONFIG_FILES([Makefile
doc/Makefile
@@ -135,4 +129,3 @@ if test _"$gmakepath" = _; then
else
echo configure complete, now type \'gmake\'
fi
- \ No newline at end of file
diff --git a/include/Exceptions.h b/include/Exceptions.h
index 74ad938..4e84bc4 100644
--- a/include/Exceptions.h
+++ b/include/Exceptions.h
@@ -8,7 +8,7 @@
#include <string.h>
#include <stdlib.h>
-#define INLINE __inline__
+/* #define INLINE __inline__ */
class Base {
public:
@@ -52,58 +52,6 @@ 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);
diff --git a/include/Main.h b/include/Main.h
new file mode 100644
index 0000000..4a81b3e
--- /dev/null
+++ b/include/Main.h
@@ -0,0 +1,24 @@
+#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/include/Makefile.am b/include/Makefile.am
index de443e0..5d895be 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -2,4 +2,4 @@
pkginclude_HEADERS = \
Exceptions.h Handle.h String.h Output.h Socket.h HttpServ.h Variables.h Menu.h \
Action.h Message.h Form.h Confirm.h Table.h IRC.h Task.h Buffer.h General.h \
-CopyJob.h ReadJob.h Regex.h TaskMan.h InPipe.h OutPipe.h Input.h Image.h
+CopyJob.h ReadJob.h Regex.h TaskMan.h InPipe.h OutPipe.h Input.h Image.h Main.h
diff --git a/include/String.h b/include/String.h
index 27a7f2c..72fc135 100644
--- a/include/String.h
+++ b/include/String.h
@@ -57,9 +57,9 @@ class String : public Base {
String & tolower();
private:
- String(int hs, const char *);
+ String(int hs, char *);
static char t[];
- char * str;
+ char * str, * ostr;
size_t siz;
};
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) {
diff --git a/src/Main.cc b/src/Main.cc
index d70c310..333328a 100644
--- a/src/Main.cc
+++ b/src/Main.cc
@@ -1,3 +1,6 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include <unistd.h>
#include <list>
#include <sys/types.h>
@@ -18,6 +21,7 @@
#include "Image.h"
#include "CopyJob.h"
#include "IRC.h"
+#include "Main.h"
InPipe * in;
@@ -137,17 +141,21 @@ Send this file: <INPUT NAME=\"userfile\" TYPE=\"file\">
Action * Liste[] = {a1, a2, a3, a4, a5, ad, java, up};
String Labels[] = {"Action 1", "Action 2", "Action 3", "Action 4", "Action 5", "Action dynamique", "Essai de java", "Test d'upload"};
+CODE_BEGINS
+
Action * buildmenu(void) {
- return new Menu("Menu Principal", "start", Labels, Liste, 8);
+ Action * m = new Menu("Menu Principal", "start", Labels, Liste, 8);
+ return m;
}
-int main(int argc, char ** argv) {
+int startup() {
int c;
String port = "1500";
std::list<String> testlist;
testlist.push_front("poide");
-
+
+/*
in = new InPipe();
in->Hook();
@@ -160,6 +168,7 @@ int main(int argc, char ** argv) {
std::cerr << "The stdout redirect has failed.\n";
exit(-1);
}
+*/
while ((c = getopt(argc, argv, "p:")) != EOF) {
switch (c) {
@@ -173,7 +182,7 @@ int main(int argc, char ** argv) {
}
try {
- HttpServ h(buildmenu(), port.to_int());
+ HttpServ h(buildmenu(), port.to_int(), "testing");
// IRC i("botalacon");
// i.Connect();
// i.MainLoop();
@@ -190,5 +199,6 @@ int main(int argc, char ** argv) {
}
delete in;
- exit(0);
+ return 0;
}
+CODE_ENDS
diff --git a/src/Makefile.am b/src/Makefile.am
index 4e790cf..e923faa 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,8 +2,8 @@ SUBDIRS = datas
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)
bin_PROGRAMS = Baltisot
@@ -14,7 +14,7 @@ bin_PROGRAMS = Baltisot
Baltisot_SOURCES = Main.cc
-LDADD = ../lib/libBaltisot.la
+LDADD = ../lib/libBaltisot.la -lefence
Baltisot_LDADD = $(LDADD)