Commit 179c3e04 authored by Julien Wintz's avatar Julien Wintz

initial revision

parents
*~
.DS_Store
build
This diff is collapsed.
### dtkConfig.cmake.in ---
##
## Author: Julien Wintz
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Jul 20 22:51:02 2009 (+0200)
## Version: $Id$
## Last-Updated: Tue Jul 21 13:17:58 2009 (+0200)
## By: Julien Wintz
## Update #: 14
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
@dtk_CONFIG_INSTALL_ONLY@
set(dtk_VERSION_MAJOR "@dtk_VERSION_MAJOR@")
set(dtk_VERSION_MINOR "@dtk_VERSION_MINOR@")
set(dtk_VERSION_BUILD "@dtk_VERSION_BUILD@")
set(dtk_VERSION "@dtk_VERSION@")
set(dtk_LIBRARIES "@dtk_LIBRARIES@")
set(dtk_CMAKE_DIR "@dtk_CMAKE_DIR_CONFIG@")
set(dtk_USE_FILE "@dtk_USE_FILE_CONFIG@")
set(dtk_BUILD_SETTINGS_FILE "@dtk_BUILD_SETTINGS_FILE_CONFIG@")
set(dtk_LIBRARY_DIRS "@dtk_LIBRARY_DIRS_CONFIG@")
set(dtk_RUNTIME_DIRS "@dtk_RUNTIME_DIRS_CONFIG@")
set(dtk_INCLUDE_DIRS "@dtk_INCLUDE_DIRS_CONFIG@")
if(NOT dtk_NO_LIBRARY_DEPENDS AND EXISTS "@dtk_LIBRARY_DEPENDS_FILE@")
include("@dtk_LIBRARY_DEPENDS_FILE@")
endif(NOT dtk_NO_LIBRARY_DEPENDS AND EXISTS "@dtk_LIBRARY_DEPENDS_FILE@")
set(dtk_CONFIGURATION_TYPES @dtk_CONFIGURATION_TYPES_CONFIG@)
set(dtk_BUILD_TYPE @dtk_BUILD_TYPE_CONFIG@)
### dtkUninstall.cmake.in ---
##
## Author: Julien Wintz
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Tue Jul 21 10:22:14 2009 (+0200)
## Version: $Id$
## Last-Updated: Tue Jul 21 10:24:22 2009 (+0200)
## By: Julien Wintz
## Update #: 3
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
if(EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval
)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
endif(NOT "${rm_retval}" STREQUAL 0)
else(EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
endif(EXISTS "$ENV{DESTDIR}${file}")
endforeach(file)
### dtkUse.cmake.in ---
##
## Author: Julien Wintz
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Tue Jul 21 10:52:39 2009 (+0200)
## Version: $Id$
## Last-Updated: Tue Jul 21 13:34:52 2009 (+0200)
## By: Julien Wintz
## Update #: 7
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
if(NOT @PROJECT_NAME@_USE_FILE_INCLUDED)
set(@PROJECT_NAME@_USE_FILE_INCLUDED 1)
include(CMakeImportBuildSettings)
cmake_import_build_settings(${@PROJECT_NAME@_BUILD_SETTINGS_FILE})
include_directories(${@PROJECT_NAME@_INCLUDE_DIRS})
link_directories(${@PROJECT_NAME@_LIBRARY_DIRS})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${@PROJECT_NAME@_CMAKE_DIR}")
endif(NOT @PROJECT_NAME@_USE_FILE_INCLUDED)
### CMakeLists.txt ---
##
## Author: Julien Wintz
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Mar 9 21:06:43 2009 (+0100)
## Version: $Id$
## Last-Updated: Fri Jul 31 22:39:16 2009 (+0200)
## By: Julien Wintz
## Update #: 2
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
add_subdirectory(dtkInterpreter)
add_subdirectory(dtkLog)
add_subdirectory(dtkTagCloud)
add_subdirectory(dtkTextEditor)
add_subdirectory(dtkUpdater)
### CMakeLists.txt ---
##
## Author: Julien Wintz
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Fri Apr 10 09:15:55 2009 (+0200)
## Version: $Id$
## Last-Updated: Mon Jul 20 22:36:15 2009 (+0200)
## By: Julien Wintz
## Update #: 10
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
project(dtkInterpreter)
## #################################################################
## Sources
## #################################################################
set(${PROJECT_NAME}_HEADERS_MOC
tstMainWindow.h
)
set(${PROJECT_NAME}_SOURCES
anyoption.cpp
tstMainWindow.cpp
main.cpp
)
## #################################################################
## Build rules
## #################################################################
qt4_wrap_cpp(${PROJECT_NAME}_SOURCES_MOC ${${PROJECT_NAME}_HEADERS_MOC})
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
${${PROJECT_NAME}_SOURCES_MOC}
${${PROJECT_NAME}_SOURCES}
)
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
dtkCore
dtkScript
dtkGui
)
This diff is collapsed.
#ifndef _ANYOPTION_H
#define _ANYOPTION_H
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#define COMMON_OPT 1
#define COMMAND_OPT 2
#define FILE_OPT 3
#define COMMON_FLAG 4
#define COMMAND_FLAG 5
#define FILE_FLAG 6
#define COMMAND_OPTION_TYPE 1
#define COMMAND_FLAG_TYPE 2
#define FILE_OPTION_TYPE 3
#define FILE_FLAG_TYPE 4
#define UNKNOWN_TYPE 5
#define DEFAULT_MAXOPTS 10
#define MAX_LONG_PREFIX_LENGTH 2
#define DEFAULT_MAXUSAGE 3
#define DEFAULT_MAXHELP 10
#define TRUE_FLAG "true"
using namespace std;
class AnyOption
{
public:
AnyOption();
AnyOption(int maxoptions );
AnyOption(int maxoptions , int maxcharoptions);
~AnyOption();
/*
* following set methods specifies the
* special characters and delimiters
* if not set traditional defaults will be used
*/
void setCommandPrefixChar( char _prefix ); /* '-' in "-w" */
void setCommandLongPrefix( char *_prefix ); /* '--' in "--width" */
void setFileCommentChar( char _comment ); /* '#' in shellscripts */
void setFileDelimiterChar( char _delimiter );/* ':' in "width : 100" */
/*
* provide the input for the options
* like argv[] for commndline and the
* option file name to use;
*/
void useCommandArgs( int _argc, char **_argv );
void useFiileName( const char *_filename );
/*
* turn off the POSIX style options
* this means anything starting with a '-' or "--"
* will be considered a valid option
* which alo means you cannot add a bunch of
* POIX options chars together like "-lr" for "-l -r"
*
*/
void noPOSIX();
/*
* prints warning verbose if you set anything wrong
*/
void setVerbose();
/*
* there are two types of options
*
* Option - has an associated value ( -w 100 )
* Flag - no value, just a boolean flag ( -nogui )
*
* the options can be either a string ( GNU style )
* or a character ( traditional POSIX style )
* or both ( --width, -w )
*
* the options can be common to the commandline and
* the optionfile, or can belong only to either of
* commandline and optionfile
*
* following set methods, handle all the aboove
* cases of options.
*/
/* options comman to command line and option file */
void setOption( const char *opt_string );
void setOption( char opt_char );
void setOption( const char *opt_string , char opt_char );
void setFlag( const char *opt_string );
void setFlag( char opt_char );
void setFlag( const char *opt_string , char opt_char );
/* options read from commandline only */
void setCommandOption( const char *opt_string );
void setCommandOption( char opt_char );
void setCommandOption( const char *opt_string , char opt_char );
void setCommandFlag( const char *opt_string );
void setCommandFlag( char opt_char );
void setCommandFlag( const char *opt_string , char opt_char );
/* options read from an option file only */
void setFileOption( const char *opt_string );
void setFileOption( char opt_char );
void setFileOption( const char *opt_string , char opt_char );
void setFileFlag( const char *opt_string );
void setFileFlag( char opt_char );
void setFileFlag( const char *opt_string , char opt_char );
/*
* process the options, registerd using
* useCommandArgs() and useFileName();
*/
void processOptions();
void processCommandArgs();
void processCommandArgs( int max_args );
bool processFile();
/*
* process the specified options
*/
void processCommandArgs( int _argc, char **_argv );
void processCommandArgs( int _argc, char **_argv, int max_args );
bool processFile( const char *_filename );
/*
* get the value of the options
* will return NULL if no value is set
*/
char *getValue( const char *_option );
bool getFlag( const char *_option );
char *getValue( char _optchar );
bool getFlag( char _optchar );
/*
* Print Usage
*/
void printUsage();
void printAutoUsage();
void addUsage( const char *line );
void printHelp();
/* print auto usage printing for unknown options or flag */
void autoUsagePrint(bool flag);
/*
* get the argument count and arguments sans the options
*/
int getArgc();
char* getArgv( int index );
bool hasOptions();
private:
int argc; /* commandline arg count */
char **argv; /* commndline args */
const char* filename; /* the option file */
char* appname; /* the application name from argv[0] */
int *new_argv; /* arguments sans options (index to argv) */
int new_argc; /* argument count sans the options */
int max_legal_args; /* ignore extra arguments */
/* option strings storage + indexing */
int max_options; /* maximum number of options */
const char **options; /* storage */
int *optiontype; /* type - common, command, file */
int *optionindex; /* index into value storage */
int option_counter; /* counter for added options */
/* option chars storage + indexing */
int max_char_options; /* maximum number options */
char *optionchars; /* storage */
int *optchartype; /* type - common, command, file */
int *optcharindex; /* index into value storage */
int optchar_counter; /* counter for added options */
/* values */
char **values; /* common value storage */
int g_value_counter; /* globally updated value index LAME! */
/* help and usage */
const char **usage; /* usage */
int max_usage_lines; /* max usage lines reseverd */
int usage_lines; /* number of usage lines */
bool command_set; /* if argc/argv were provided */
bool file_set; /* if a filename was provided */
bool mem_allocated; /* if memory allocated in init() */
bool posix_style; /* enables to turn off POSIX style options */
bool verbose; /* silent|verbose */
bool print_usage; /* usage verbose */
bool print_help; /* help verbose */
char opt_prefix_char; /* '-' in "-w" */
char long_opt_prefix[MAX_LONG_PREFIX_LENGTH]; /* '--' in "--width" */
char file_delimiter_char; /* ':' in width : 100 */
char file_comment_char; /* '#' in "#this is a comment" */
char equalsign;
char comment;
char delimiter;
char endofline;
char whitespace;
char nullterminate;
bool set; //was static member
bool once; //was static member
bool hasoptions;
bool autousage;
private:
void init();
void init(int maxopt, int maxcharopt );
bool alloc();
void cleanup();
bool valueStoreOK();
/* grow storage arrays as required */
bool doubleOptStorage();
bool doubleCharStorage();
bool doubleUsageStorage();
bool setValue( const char *option , char *value );
bool setFlagOn( const char *option );
bool setValue( char optchar , char *value);
bool setFlagOn( char optchar );
void addOption( const char* option , int type );
void addOption( char optchar , int type );
void addOptionError( const char *opt);
void addOptionError( char opt);
bool findFlag( char* value );
void addUsageError( const char *line );
bool CommandSet();
bool FileSet();
bool POSIX();
char parsePOSIX( char* arg );
int parseGNU( char *arg );
bool matchChar( char c );
int matchOpt( char *opt );
/* dot file methods */
char *readFile();
char *readFile( const char* fname );
bool consumeFile( char *buffer );
void processLine( char *theline, int length );
char *chomp( char *str );
void valuePairs( char *type, char *value );
void justValue( char *value );
void printVerbose( const char *msg );
void printVerbose( char *msg );
void printVerbose( char ch );
void printVerbose( );
};
#endif /* ! _ANYOPTION_H */
/* main.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Sat Apr 11 13:49:30 2009 (+0200)
* Version: $Id$
* Last-Updated: Fri May 15 11:08:18 2009 (+0200)
* By: Julien Wintz
* Update #: 17
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include <QtGui/QApplication>
#include "anyoption.h"
#include "tstMainWindow.h"
#include <dtkScript/dtkScriptInterpreter.h>
#include <dtkScript/dtkScriptInterpreterTcl.h>
#include <dtkScript/dtkScriptInterpreterPython.h>
#include <dtkGui/dtkInterpreter.h>
int main(int argc, char *argv[])
{
QApplication application(argc, argv);
AnyOption options;
options.addUsage("Usage: ./dtkInterpreter [FLAG] ... [OPTION=VALUE] ...");
options.addUsage("");
options.addUsage("Script:");
options.addUsage(" -i --interpreter");
options.addUsage(" --interpreter=tcl Run tcl gui interpreter");
options.addUsage(" --interpreter=python Run python gui interpreter");
options.setOption("interpreter", 'i');
options.processCommandArgs(argc, argv);
tstMainWindow window;
if (options.getValue("interpreter") != NULL || options.getValue('i') != NULL) {
dtkScriptInterpreter *interpreter;
if(QString(options.getValue('i')) == "python")
interpreter = new dtkScriptInterpreterPython;
else
interpreter = new dtkScriptInterpreterTcl;
window.interpreter()->registerInterpreter(interpreter);
QObject::connect(interpreter, SIGNAL(stopped()), &application, SLOT(quit()));
QObject::connect(&application, SIGNAL(aboutToQuit()), interpreter, SLOT(stop()));
} else {
options.printUsage();
return 0;
}
window.show();
return application.exec();
}
/* tstMainWindow.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Apr 10 09:19:56 2009 (+0200)
* Version: $Id$
* Last-Updated: Fri Apr 17 13:54:28 2009 (+0200)
* By: Julien Wintz
* Update #: 20
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include <QtGui>
#include "tstMainWindow.h"
#include <dtkGui/dtkTextEditorCompleter.h>
#include <dtkGui/dtkInterpreter.h>
#include <dtkGui/dtkInterpreterPreferencesWidget.h>
class tstMainWindowPrivate
{
public:
QMenu *fileMenu;
QAction *preferencesAction;
dtkTextEditorCompleter *completer;
dtkInterpreter *interpreter;
public:
tstMainWindow *q;
};
tstMainWindow::tstMainWindow(QWidget *parent) : QMainWindow(parent)
{
d = new tstMainWindowPrivate;
d->interpreter = new dtkInterpreter(this);
d->interpreter->readSettings();
d->completer = new dtkTextEditorCompleterPath(d->interpreter);
d->interpreter->setCompleter(d->completer);
d->preferencesAction = new QAction("Preferences", this);
d->preferencesAction->setShortcut(Qt::ControlModifier + Qt::Key_Comma);
connect(d->preferencesAction, SIGNAL(triggered()), this, SLOT(showPreferences()));
d->fileMenu = this->menuBar()->addMenu("File");
d->fileMenu->addAction(d->preferencesAction);
d->q = this;
this->setWindowTitle("dtk Gui Interpreter");
this->setCentralWidget(d->interpreter);
}
tstMainWindow::~tstMainWindow(void)
{
delete d->interpreter;
delete d;
}
dtkInterpreter *tstMainWindow::interpreter(void)
{
return d->interpreter;
}
void tstMainWindow::showPreferences(void)
{
dtkInterpreterPreferencesWidget *widget = d->interpreter->preferencesWidget(this);
widget->setWindowFlags(Qt::Sheet);
widget->show();
}
void tstMainWindow::closeEvent(QCloseEvent *event)
{
d->interpreter->writeSettings();
event->accept();
}
/* tstMainWindow.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008 - Julien Wintz, Inria.
* Created: Fri Apr 10 09:19:37 2009 (+0200)
* Version: $Id$
* Last-Updated: Tue Apr 14 10:31:21 2009 (+0200)
* By: Julien Wintz
* Update #: 6
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef TSTMAINWINDOW_H
#define TSTMAINWINDOW_H
#include <QMainWindow>