diff options
author | deva <deva> | 2005-04-05 11:22:05 +0000 |
---|---|---|
committer | deva <deva> | 2005-04-05 11:22:05 +0000 |
commit | 55a7afdedc7cee2df9012f600dd51aff92ad1af3 (patch) | |
tree | db6568a6aab7cfdec0d0afcb9bd7566939a4a318 | |
parent | 6f03a23e7876516d3ba011d23acf454138432654 (diff) |
Added validity checking on the conf parser.
Added error object to conf parser.
Cleaned up the configure.in script
-rw-r--r-- | TODO | 6 | ||||
-rw-r--r-- | configure.in | 166 | ||||
-rw-r--r-- | src/decoder.cc | 3 | ||||
-rw-r--r-- | src/decoder.h | 4 | ||||
-rw-r--r-- | src/encoder.cc | 4 | ||||
-rw-r--r-- | src/encoder.h | 3 | ||||
-rw-r--r-- | src/mainwindow.cc | 8 | ||||
-rw-r--r-- | src/mainwindow.h | 2 | ||||
-rw-r--r-- | src/messagebox.cc | 4 | ||||
-rw-r--r-- | src/messagebox.h | 5 | ||||
-rw-r--r-- | src/miav.conf | 2 | ||||
-rw-r--r-- | src/miav_config.cc | 65 | ||||
-rw-r--r-- | src/miav_config.h | 8 |
13 files changed, 120 insertions, 160 deletions
@@ -16,6 +16,7 @@ Mainwindow: [x] - Make generic gui layout code. [x] - Make icons. [x] - Make statusbar. + [ ] - Make flashing record bar. [ ] - Show network connection in statusbar. [ ] - Show camera connection in statusbar. [ ] - Test it. @@ -33,8 +34,8 @@ Decoder: [ ] - Enable sound decoding for the network stream. Camera: - [ ] - Add initialize method (constructor should do nothing). - [ ] - Add getStatus methods. + [x] - Add initialize method (constructor should do nothing). + [%] - Add getStatus methods. (implemented through error object) ========================================================================== TASKS (server) @@ -58,6 +59,7 @@ Makesystem: [x] - Make server standalone compilable (through flag to configure) [x] - Include pixmaps and tools in distdir. [x] - Make pixmaps correctly intalled. + [ ] - Make QT link correctly on fedora core 1 MiavConfig: [x] - Integrate file parser. diff --git a/configure.in b/configure.in index cb5514d..d53a1aa 100644 --- a/configure.in +++ b/configure.in @@ -1,4 +1,4 @@ -# Filnavn: configure.in +# Filename: configure.in AC_INIT(src/miav.cc) AM_INIT_AUTOMAKE( miav, 0.1.1 ) @@ -12,142 +12,37 @@ AM_CXXFLAGS="-O2" AC_STDC_HEADERS AC_ARG_WITH(gui, [ --without-gui build without GUI support]) - if test x$with_gui != xno && test -z "$GUI"; then -#dnl ==================== -#dnl Check for Qt library -#dnl ==================== -#AC_ARG_WITH(qt, [ --with-qt build with Qt utils. (autodetected)], -# [], with_qt=yes) -#dnl no X means no Qt -#test x$have_x != xyes && with_qt=no -# -#if test x$with_qt = xyes ; then -# AC_PATH_QT(200, test -z "$qt_version" && qt_version=0 -# AC_DEFINE_UNQUOTED(HAVE_LIBQT, $qt_version, [Define if using 'Qt' libraries.]), -# with_qt=no) -#else -# AC_MSG_RESULT([compilation of Qt utils disabled]) -#fi -# -#if test x$with_qt = xyes ; then -# AC_LANG_SAVE -# AC_LANG_CPLUSPLUS -# save_CXXFLAGS=$CXXFLAGS -# save_LIBS=$LIBS -# CXXFLAGS="$CXXFLAGS $QT_CFLAGS $X_CFLAGS" -# LIBS="$LIBS $QT_LIBS $X_LIBS $PTHREAD_LIBS" -# AC_CACHE_CHECK([for multithreading support in Qt], -# ac_cv_val_with_qt_multi, -# [ AC_TRY_LINK([ -# #define QT_THREAD_SUPPORT -# #include <qapplication.h> ], -# [ qApp->wakeUpGuiThread(); ], -# [ ac_cv_val_with_qt_multi=yes ], -# [ ac_cv_val_with_qt_multi=no ]) -# ]) -# CXXFLAGS=$save_CXXFLAGS -# LIBS=$save_LIBS -# -# if test x$ac_cv_val_with_qt_multi != xyes ; then -# AC_MSG_WARN([ -#*** Your Qt installation does not support multi-threading! -#*** Avifile will be compiled - however it might crash mysteriously -#*** Instalation of threaded Qt library version (qt-mt) is recommended -#*** When rebuilding Qt use configure option '-thread'.]) -# fi -# -# AC_MSG_CHECKING(Qt version for Avicap) -# if test $qt_version -ge 220 ; then -# AC_MSG_RESULT([yes]) -# else -# AC_MSG_RESULT([no (needs Qt 2.2.0 or better)]) -# build_avicap=no -# fi -# AC_LANG_RESTORE -#fi - +if test x$with_gui != xno && test -z "$GUI"; then + dnl ===================== + dnl Check for QT library + dnl ===================== + gw_CHECK_QT + CXXFLAGS="$CXXFLAGS $QT_CXXLAGS" + LDFLAGS="$LDFLAGS $QT_LDADD" + + dnl ===================== + dnl Check for SDL library + dnl ===================== + SDL_VERSION=1.2.0 + AM_PATH_SDL($SDL_VERSION,:,AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])) + CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" + LDFLAGS="$LDFLAGS $SDL_LIBS" + + dnl Make code aware of the gui + AC_DEFINE([USE_GUI], [], [Is defined if the project is configured to compile with gui]) +else + AC_MSG_WARN([*** Building without GUI support!]) +fi dnl ====================== dnl Check for Jpeg library dnl ====================== -AC_CHECK_HEADER(jpeglib.h, have_jpeglib=yes, have_jpeglib="no ") -if test x$have_jpeglib = xyes; then -dnl default action left - saving $LIBS is necessary - save_LIBS=$LIBS - AC_CHECK_LIB(jpeg, jpeg_start_compress, , have_jpeglib="no ") - LIBS=$save_LIBS -fi - -#dnl ===================== -#dnl Check for SDL library -#dnl ===================== -#AC_ARG_WITH(sdl, [ --with-sdl build with SDL. (autodetected)], -# [], with_sdl=yes) -# -#if test x$with_sdl != xyes; then -# with_sdl="no (video rendering unavailable as requested!)" -# AC_MSG_WARN([ -#*** there will be NO video rendering without SDL support!]) -#else -# SDL_MIN_VERSION=1.0.0 -# save_CFLAGS=$CFLAGS -# save_CPPFLAGS=$CPPFLAGS -# save_LIBS=$LD_FLAGS -# LIBS= -# AM_PATH_SDL($SDL_MIN_VERSION, -# AC_DEFINE(HAVE_LIBSDL, 1, [Define if using 'SDL' library (-lsdl).]), -# with_sdl="no (*** no SDL => no video rendering! ***)" -# AC_MSG_WARN([Could not find SDL >= $SDL_MIN_VERSION!]) ) -# CFLAGS=$save_CFLAGS -# CXXFLAGS=$save_CPPFLAGS -# LDFLAGS="$save_LIBS -#fi - - dnl QT lib check macro (located in acinclude.m4) - gw_CHECK_QT - CXXFLAGS="$CXXFLAGS $QT_CXXLAGS" - LDFLAGS="$LDFLAGS $QT_LDADD" - - dnl Check for SDL - SDL_VERSION=1.2.0 - AM_PATH_SDL($SDL_VERSION, - :, - AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!]) - ) - CXXFLAGS="$CXXFLAGS $SDL_CFLAGS" - LDFLAGS="$LDFLAGS $SDL_LIBS" - - dnl Make code aware of the gui - AC_DEFINE([USE_GUI], [], [Is defined if te project is configured to compile with gui]) - fi - -dnl ======================= -dnl Configure ffmpeg plugin -dnl ======================= -#AM_PATH_FFMPEG - -#LD_FLAGS=$LD_FLAGS $LIBS - -# And now for the conditionals (for ffmpeg) -#AM_CONDITIONAL(AMM_LINK_SHARED, test $lt_major_version -ge 1 -a $lt_minor_version -ge 4 -a $lt_micro_version -ge 3 ) -#AM_CONDITIONAL(AMM_FF_A52BIN, test x$enable_ffmpeg_a52bin = xyes) -#AM_CONDITIONAL(AMM_FF_FAAD, test x$have_faad = xyes ) -#AM_CONDITIONAL(AMM_FF_ALPHAOPT, test x$enable_alphaopt = xyes) -#AM_CONDITIONAL(AMM_FF_ARMOPT, test x$enable_armopt = xyes) -#AM_CONDITIONAL(AMM_FF_MIPSOPT, test x$enable_mipsopt = xyes) -#AM_CONDITIONAL(AMM_FF_MLIBOPT, test x$enable_mlibopt = xyes) -#AM_CONDITIONAL(AMM_FF_PPCOPT, test x$enable_ppcopt = xyes) -#AM_CONDITIONAL(AMM_FF_PS2OPT, test x$enable_ps2opt = xyes) -#AM_CONDITIONAL(AMM_FF_SH4OPT, test x$enable_sh4opt = xyes) -#AM_CONDITIONAL(AMM_FF_X86OPT, test x$enable_x86opt = xyes) -#AM_CONDITIONAL(AMM_USE_OSS, test x$enable_oss = xyes) -#AM_CONDITIONAL(AMM_USE_V4L, test x$enable_v4l = xyes ) - +AC_CHECK_HEADER(jpeglib.h, , AC_MSG_ERROR([*** LibJpeg not found!])) +AC_CHECK_LIB(jpeg, jpeg_start_compress, , AC_MSG_ERROR([*** LibJpeg not found!])) AC_SUBST(CFLAGS) AC_SUBST(CPPFLAGS) AC_SUBST(CXXFLAGS) - AC_SUBST(LDFLAGS) AC_OUTPUT( @@ -155,16 +50,3 @@ AC_OUTPUT( src/Makefile tools/Makefile pixmaps/Makefile) -# ffmpeg/Makefile -# ffmpeg/libavformat/Makefile -# ffmpeg/libavcodec/Makefile -# ffmpeg/libavcodec/alpha/Makefile -# ffmpeg/libavcodec/armv4l/Makefile -# ffmpeg/libavcodec/i386/Makefile -# ffmpeg/libavcodec/liba52/Makefile -# ffmpeg/libavcodec/libpostproc/Makefile -# ffmpeg/libavcodec/mlib/Makefile -# ffmpeg/libavcodec/ppc/Makefile -# ffmpeg/libavcodec/ps2/Makefile -# ffmpeg/libavcodec/sh4/Makefile -# ) diff --git a/src/decoder.cc b/src/decoder.cc index bf9b75c..c7a4e50 100644 --- a/src/decoder.cc +++ b/src/decoder.cc @@ -21,6 +21,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <config.h> +#ifdef USE_GUI #include "decoder.h" @@ -179,3 +180,5 @@ void Decoder::decode() void Decoder::run() { decode(); } + +#endif /*USE_GUI*/ diff --git a/src/decoder.h b/src/decoder.h index 846ac26..fcf61cf 100644 --- a/src/decoder.h +++ b/src/decoder.h @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <config.h> +#ifdef USE_GUI + #ifndef __RTVIDEOREC_DECODER_H #define __RTVIDEOREC_DECODER_H @@ -68,3 +70,5 @@ public: }; #endif + +#endif/*USE_GUI*/ diff --git a/src/encoder.cc b/src/encoder.cc index fc19921..3a4ade2 100644 --- a/src/encoder.cc +++ b/src/encoder.cc @@ -22,6 +22,8 @@ */ #include <config.h> +#ifdef USE_GUI + #include "encoder.h" Encoder::Encoder(Error* err, @@ -154,3 +156,5 @@ void Encoder::stop() { n = NULL; } } + +#endif /*USE_GUI*/ diff --git a/src/encoder.h b/src/encoder.h index 8a458c8..554839c 100644 --- a/src/encoder.h +++ b/src/encoder.h @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <config.h> +#ifdef USE_GUI + #ifndef __RTVIDEOREC_ENCODER_H #define __RTVIDEOREC_ENCODER_H @@ -96,3 +98,4 @@ private: #endif +#endif /*USE_GUI*/ diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 5da340b..8bfc53e 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -50,9 +50,15 @@ MainWindow::MainWindow( QWidget* parent, const char* name ) : QWidget( parent, name, WStyle_Customize | WStyle_NoBorder ) { - MiavConfig cfg("miav.conf"); + error = new Error(); + MiavConfig cfg("miav.conf", error); int resolution_w = cfg.readInt("pixel_width"); int resolution_h = cfg.readInt("pixel_height"); + while(error->hasError()) { + show(); + MessageBox(this, TXT_ERROR_TITLE, error->popErrorString().c_str(), + TYPE_OK, ICON_ERROR).exec(); + } unit = ((float)resolution_w / (float)(cfg.readFloat("screensize") * 3.1f)); move(0,0); diff --git a/src/mainwindow.h b/src/mainwindow.h index 18f616d..25a938b 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -82,6 +82,8 @@ public slots: void freeze_clicked(); private: + Error *error; + void checkErrors(); void createGui(); diff --git a/src/messagebox.cc b/src/messagebox.cc index fe5420f..63bbeee 100644 --- a/src/messagebox.cc +++ b/src/messagebox.cc @@ -22,7 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - +#include <config.h> +#ifdef USE_GUI #include "messagebox.h" //////////////////////////////////////////////////////////////////////////////////////// @@ -184,3 +185,4 @@ void MessageBox::bno_clicked() { done(MSG_NO); } +#endif/*USE_GUI*/ diff --git a/src/messagebox.h b/src/messagebox.h index 5cb2bd8..313d395 100644 --- a/src/messagebox.h +++ b/src/messagebox.h @@ -23,6 +23,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include <config.h> +#ifdef USE_GUI + #ifndef __MIAV_MESSAGEBOX_H__ #define __MIAV_MESSAGEBOX_H__ @@ -98,3 +101,5 @@ private: }; #endif/*__MIAV_MESSAGEBOX_H__*/ + +#endif /*USE_GUI*/ diff --git a/src/miav.conf b/src/miav.conf index 3fab263..ba2ceda 100644 --- a/src/miav.conf +++ b/src/miav.conf @@ -3,6 +3,8 @@ # # Cpr Database configuration +fisk = + = true cpr_host = "cpr.j.auh.dk" cpr_port = 10301 cpr_timeout = 10000 diff --git a/src/miav_config.cc b/src/miav_config.cc index 1c2d0c6..8a9307d 100644 --- a/src/miav_config.cc +++ b/src/miav_config.cc @@ -26,15 +26,20 @@ #include <config.h> #include "miav_config.h" -MiavConfig::MiavConfig(char *file) +MiavConfig::MiavConfig(char *file, Error* err) { + error = err; configs = NULL; + + filename = string(file); // Read config file FILE* fp = fopen(file, "r"); if(!fp) { - fprintf(stderr, "Error reading configuration file %s\n", file); + char errbuf[256]; + sprintf(errbuf, "Error reading configuration file %s\n", file); + if(error) error->pushError(errbuf); return; } fseek(fp, 0, SEEK_END); @@ -63,16 +68,39 @@ MiavConfig::~MiavConfig() if(die) free(die); } +/** + * Prints a reasonable error message when a parse error occurres. + */ +_cfg *MiavConfig::parseError(char* msg, char* line) +{ + char errbuf[512]; + sprintf(errbuf, "Error parsing file %s at line:\n\t%s\n\t%s\n", filename.c_str(), line, msg); + if(error) error->pushError(errbuf); + return NULL; +} + /** * Adds one configuration entry, from a single zero terminated line. */ _cfg *MiavConfig::addConfig(_cfg *parent, char* conf) { + // Check for wellformed input: + // Check for = + if(strstr(conf, "=") == 0) return parseError("Missing '='", conf); + /* + if(strstr(conf, "\"")) { + if(strstr(conf, "=") > strstr(conf, "\"")) + return parseError("Missing '=', first occurrence inside string", conf); + } + */ - // - // FIXME: Check for wellformedness - // + // Check for nonempty left side + if(strstr(conf, "=") == conf) return parseError("Empty left side", conf); + // Check for nonempty right side + if(strstr(conf, "=") == conf + strlen(conf) - 1) return parseError("Empty right side.", conf); + + // Parse this wellformed input. _cfg *cfg; cfg = (_cfg*) malloc(sizeof(_cfg)); @@ -86,6 +114,8 @@ _cfg *MiavConfig::addConfig(_cfg *parent, char* conf) char* val = (char*)calloc(vallen + 1, 1); strncpy(val, conf + strlen(conf) - vallen, vallen); + // TODO: Check valid rightside (true, false, number or "..") + cfg->name = new string((const char*)name); free(name); @@ -118,13 +148,12 @@ int MiavConfig::parse(char* raw) for(p = conf; p < conf_end; p++) { if(*p == '\n') { *p = '\0'; - cfg = addConfig(cfg, start); + if(!(cfg = addConfig(cfg, start))) return 1; start = p+1; } } // Allocated in strip free(conf); - printf("done!\n"); return 0; } @@ -186,22 +215,30 @@ char* MiavConfig::strip(char* conf) int MiavConfig::readInt(char *node) { - return findNode(node)->intval; + _cfg* n = findNode(node); + if(n) return n->intval; + else return 0; } bool MiavConfig::readBool(char *node) { - return findNode(node)->boolval; + _cfg* n = findNode(node); + if(n) return n->boolval; + else return false; } string *MiavConfig::readString(char *node) { - return findNode(node)->stringval; + _cfg* n = findNode(node); + if(n) return n->stringval; + else return &emptyString; } float MiavConfig::readFloat(char *node) { - return findNode(node)->floatval; + _cfg* n = findNode(node); + if(n) return n->floatval; + else return 0.0f; } _cfg *MiavConfig::findNode(char* node) @@ -212,6 +249,8 @@ _cfg *MiavConfig::findNode(char* node) if(!strcmp(node, cfg->name->c_str())) return cfg; cfg = cfg->next; } - fprintf(stderr, "ERROR: Request for nonexisting node \"%s\"!\n", node); - exit(1); + char errbuf[256]; + sprintf(errbuf, "Request for nonexisting node \"%s\"!\n", node); + if(error) error->pushError(errbuf); + return NULL; } diff --git a/src/miav_config.h b/src/miav_config.h index 1ca6e04..45eab0c 100644 --- a/src/miav_config.h +++ b/src/miav_config.h @@ -30,6 +30,8 @@ #include <string> using namespace std; +#include "error.h" + typedef struct __cfg { string *name; bool boolval; @@ -41,7 +43,7 @@ typedef struct __cfg { class MiavConfig { public: - MiavConfig(char *file); + MiavConfig(char *file, Error* err = NULL); ~MiavConfig(); int readInt(char *node); @@ -50,9 +52,13 @@ public: float readFloat(char *node); private: + string emptyString; + Error* error; + string filename; _cfg *addConfig(_cfg *parent, char* conf); int parse(char* conf); char *strip(char* conf); + _cfg *parseError(char* msg, char* line); _cfg *findNode(char* node); _cfg *configs; }; |