summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2012-08-04 20:41:18 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2012-08-04 20:41:18 +0200
commitb8195d45820378e3d09225d9a291c4951816276d (patch)
tree87a2e2f1b9a0ed93672d2e5e98214d0d2d05f4e2
Initial import.
-rw-r--r--gfx/kaiman.pngbin0 -> 103314 bytes
-rw-r--r--gfx/kaiman.xcfbin0 -> 1475517 bytes
-rw-r--r--src/kaiman.cc46
-rw-r--r--src/luascript.cc283
-rw-r--r--src/luascript.h86
-rw-r--r--src/mainwindow.cc39
-rw-r--r--src/mainwindow.h44
-rw-r--r--src/outputwindow.cc121
-rw-r--r--src/outputwindow.h62
-rwxr-xr-xtools/add_file110
10 files changed, 791 insertions, 0 deletions
diff --git a/gfx/kaiman.png b/gfx/kaiman.png
new file mode 100644
index 0000000..556cda2
--- /dev/null
+++ b/gfx/kaiman.png
Binary files differ
diff --git a/gfx/kaiman.xcf b/gfx/kaiman.xcf
new file mode 100644
index 0000000..b09b864
--- /dev/null
+++ b/gfx/kaiman.xcf
Binary files differ
diff --git a/src/kaiman.cc b/src/kaiman.cc
new file mode 100644
index 0000000..82dcfdd
--- /dev/null
+++ b/src/kaiman.cc
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * kaiman.cc
+ *
+ * Sat Aug 4 13:36:06 CEST 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Kaiman.
+ *
+ * Kaiman is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Kaiman is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kaiman; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include <QApplication>
+
+#include "mainwindow.h"
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2) {
+ printf("Usage: %s script\n", argv[0]);
+ return 1;
+ }
+
+ QApplication app(argc, argv);
+
+ MainWindow wnd(argv[1]);
+ // wnd.show();
+
+ return app.exec();
+}
+
diff --git a/src/luascript.cc b/src/luascript.cc
new file mode 100644
index 0000000..1699cdf
--- /dev/null
+++ b/src/luascript.cc
@@ -0,0 +1,283 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * luascript.cc
+ *
+ * Tue Jan 10 14:43:39 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "luascript.h"
+
+// For atoi
+#include <stdlib.h>
+
+//#include "luautil.h"
+
+#define GLOBAL_POINTER "_pracroGlobalLUAObjectPointerThisShouldBeANameThatIsNotAccidentallyOverwritten"
+
+#define DEBUG(x, fmt...) printf(fmt)
+#define ERR(x, fmt...) printf(fmt)
+
+static int _debug(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+ std::string msg = lua_tostring(L, lua_gettop(L));
+
+ printf("%s\n", msg.c_str());
+
+ return 0;
+}
+
+static int _forward(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+ int x = lua_tonumber(L, lua_gettop(L));
+
+ printf("forward %d\n", x);
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ lua->out->forward(x * 5);
+
+ return 0;
+}
+
+static int _turn(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+ int x = lua_tonumber(L, lua_gettop(L));
+
+ printf("turn %d\n", x);
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ lua->out->turn(-x);
+
+ return 0;
+}
+
+static int _reset(lua_State *L)
+{/*
+ Pracro::checkParameters(L,
+ Pracro::T_STRING,
+ Pracro::T_END);
+ */
+
+ printf("reset\n");
+
+ lua_getglobal(L, GLOBAL_POINTER);
+ LUAScript *lua = (LUAScript*)lua_touserdata(L, lua_gettop(L));
+
+ if(!lua) {
+ lua_pushstring(L, "No LUA pointer!");
+ lua_error(L);
+ return 1;
+ }
+
+ lua->out->reset();
+
+ return 0;
+}
+
+LUAScript::LUAScript(OutputWindow *o)
+{
+ DEBUG(luascript, "LUAScript()\n");
+ L = NULL;
+ out = o;
+}
+
+LUAScript::~LUAScript()
+{
+ if(L) {
+ free(L);
+ L = NULL;
+ }
+ DEBUG(luascript, "~LUAScript()\n");
+}
+
+void LUAScript::init()
+ throw(Exception)
+{
+ if(L) return;
+
+ L = luaL_newstate();
+ if(L == NULL) {
+ ERR(luascript, "Could not create LUA state.\n");
+ throw Exception("Could not create LUA state.");
+ }
+
+ luaL_openlibs(L);
+
+ lua_pushlightuserdata(L, this); // Push the pointer to 'this' instance
+ lua_setglobal(L, GLOBAL_POINTER); // Assign it to a global lua var.
+
+ lua_register(L, "debug", _debug);
+ lua_register(L, "fremad", _forward);
+ lua_register(L, "drej", _turn);
+ lua_register(L, "reset", _reset);
+
+ connect(&watcher, SIGNAL(fileChanged(const QString &)),
+ this, SLOT(reload()));
+}
+
+void LUAScript::addFile(std::string src)
+{
+ file = src.c_str();
+ FILE *fp = fopen(src.c_str(), "r");
+ if(fp) {
+ char buf[64];
+ size_t sz;
+ std::string inc;
+ while((sz = fread(buf, 1, sizeof(buf), fp)) != 0) {
+ inc.append(buf, sz);
+ }
+ fclose(fp);
+ addCode(inc, src);
+ }
+
+ watcher.addPath(file);
+}
+
+void LUAScript::reload()
+{
+ printf("Reload\n");
+ // luaL_error(L, "Terminated due to reload.");
+ // runScript();
+}
+
+void LUAScript::addCode(std::string c, std::string name)
+{
+ scripts.push_back(std::make_pair(c, name));
+}
+
+void LUAScript::run()
+{
+ /*
+ while(true) {
+ printf("."); fflush(stdout);
+ }
+ */
+ try {
+ runScript();
+ } catch(Exception &e) {
+ printf("LUA Error: %s\n", e.msg.c_str());
+ }
+}
+
+void LUAScript::runScript()
+ throw(Exception)
+{
+ try {
+ init();
+ } catch(Exception &e) {
+ throw Exception(e.msg);
+ }
+
+ if(L == NULL) {
+ ERR(luascript, "LUA state not initialized!");
+ return;
+ }
+
+ top = lua_gettop(L);
+
+ std::vector<std::pair<std::string, std::string> >::iterator i =
+ scripts.begin();
+ while(i != scripts.end()) {
+ std::string program = i->first;
+ std::string codename = name();
+ if(i->second != "") codename += ": " + i->second;
+
+ DEBUG(luascript, "Running %s: %s\n", codename.c_str(), program.c_str());
+
+ if(luaL_loadbuffer(L, program.c_str(), program.size(), codename.c_str())) {
+ ERR(luascript, "loadbuffer: %s\n", lua_tostring(L, lua_gettop(L)));
+ throw Exception(lua_tostring(L, lua_gettop(L)));
+ }
+
+ // Run the loaded code
+ if(lua_pcall(L, 0, LUA_MULTRET, 0)) {
+ ERR(luascript, "pcall: %s\n" , lua_tostring(L, lua_gettop(L)));
+ throw Exception(lua_tostring(L, lua_gettop(L)));
+ }
+
+ i++;
+ }
+}
+
+std::string LUAScript::resultString() throw(Exception)
+{
+ if(top != lua_gettop(L) - 1) {
+ ERR(luascript, "Program did not return a single value.\n");
+ throw Exception("Program did not return a single value.");
+ }
+
+ if(lua_isstring(L, lua_gettop(L)) == false) {
+ ERR(luascript, "Program did not return a string value.\n");
+ throw Exception("Program did not return a string value.");
+ }
+
+ std::string res = lua_tostring(L, lua_gettop(L));
+ lua_pop(L, 1);
+
+ return res;
+}
+
+#ifdef TEST_LUASCRIPT
+//Additional dependency files
+//deps:
+//Required cflags (autoconf vars may be used)
+//cflags:
+//Required link options (autoconf vars may be used)
+//libs:
+#include "test.h"
+
+TEST_BEGIN;
+
+// TODO: Put some testcode here (see test.h for usable macros).
+TEST_TRUE(false, "No tests yet!");
+
+TEST_END;
+
+#endif/*TEST_LUASCRIPT*/
diff --git a/src/luascript.h b/src/luascript.h
new file mode 100644
index 0000000..448fe5e
--- /dev/null
+++ b/src/luascript.h
@@ -0,0 +1,86 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * luascript.h
+ *
+ * Tue Jan 10 14:43:39 CET 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Pracro.
+ *
+ * Pracro is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Pracro is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Pracro; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __PRACRO_LUASCRIPT_H__
+#define __PRACRO_LUASCRIPT_H__
+
+#include <lua.hpp>
+#include <lauxlib.h>
+
+#include <string>
+#include <map>
+#include <vector>
+#include <QFileSystemWatcher>
+
+#include "outputwindow.h"
+
+#include <QThread>
+
+class LUAScript : public QThread {
+Q_OBJECT
+public:
+ class Exception {
+ public:
+ Exception(std::string m) : msg(m) {}
+ std::string msg;
+ };
+
+ LUAScript(OutputWindow *out);
+ ~LUAScript();
+
+ virtual const char *name() { return ""; }
+
+ void init() throw(Exception);
+
+ void addFile(std::string file);
+ void addCode(std::string code, std::string codename = "");
+
+ void run();
+ void runScript() throw(Exception);
+
+ std::string resultString() throw(Exception);
+
+ OutputWindow *out;
+
+public slots:
+ void reload();
+
+protected:
+ lua_State *L;
+
+private:
+ std::vector<std::pair<std::string, std::string> > scripts;
+ std::map<std::string, std::string> values;
+
+ int top;
+
+ QFileSystemWatcher watcher;
+ QString file;
+};
+
+
+#endif/*__PRACRO_LUASCRIPT_H__*/
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
new file mode 100644
index 0000000..784bfbb
--- /dev/null
+++ b/src/mainwindow.cc
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * mainwindow.cc
+ *
+ * Sat Aug 4 13:37:18 CEST 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Kaiman.
+ *
+ * Kaiman is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Kaiman is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kaiman; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "mainwindow.h"
+
+#include "outputwindow.h"
+
+MainWindow::MainWindow(QString program)
+{
+ out = new OutputWindow();
+ out->show();
+ l = new LUAScript(out);
+ l->addFile(program.toStdString());
+ l->start();
+}
diff --git a/src/mainwindow.h b/src/mainwindow.h
new file mode 100644
index 0000000..eeaaa1a
--- /dev/null
+++ b/src/mainwindow.h
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * mainwindow.h
+ *
+ * Sat Aug 4 13:37:17 CEST 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Kaiman.
+ *
+ * Kaiman is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Kaiman is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kaiman; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __KAIMAN_MAINWINDOW_H__
+#define __KAIMAN_MAINWINDOW_H__
+
+#include <QWidget>
+#include "outputwindow.h"
+#include "luascript.h"
+
+class MainWindow : public QWidget {
+public:
+ MainWindow(QString program);
+
+private:
+ OutputWindow *out;
+ LUAScript *l;
+};
+
+#endif/*__KAIMAN_MAINWINDOW_H__*/
diff --git a/src/outputwindow.cc b/src/outputwindow.cc
new file mode 100644
index 0000000..0f66a0b
--- /dev/null
+++ b/src/outputwindow.cc
@@ -0,0 +1,121 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * outputwindow.cc
+ *
+ * Sat Aug 4 13:44:41 CEST 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Kaiman.
+ *
+ * Kaiman is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Kaiman is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kaiman; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#include "outputwindow.h"
+
+#include <QPixmap>
+#include <QPainter>
+
+#include <math.h>
+
+OutputWindow::OutputWindow()
+{
+ QPixmap img("gfx/kaiman.png");
+ //QPixmap img("gfx/arrow.png");
+ kaiman = img.toImage();
+ /*
+ QTransform t;
+ t.scale(0.2, 0.2);
+ kaiman = kaiman.transformed(t, Qt::SmoothTransformation);
+ */
+ connect(&timer, SIGNAL(timeout()), this, SLOT(timeout()));
+ timer.setSingleShot(true);
+ timer.start(25);
+
+ reset();
+}
+
+void OutputWindow::timeout()
+{
+ /*
+ x++;
+ y++;
+ r++;
+ */
+ repaint();
+ timer.start(25);
+}
+
+void OutputWindow::paintEvent(QPaintEvent *)
+{
+ // sem.acquire();
+ QPainter p(this);
+
+ QTransform t;
+ t.rotate(-r + 90);
+ t.scale(100.0 / kaiman.width(), 100.0 / kaiman.width());
+ QImage img = kaiman.transformed(t, Qt::SmoothTransformation);
+ p.drawImage(x - img.width()/2, y - img.height()/2, img);
+
+ QPen pen(QColor(255,0,0,100));
+ pen.setWidth(4);
+ p.setPen(pen);
+ p.drawLines(points);
+
+ sem.release();
+}
+
+void OutputWindow::reset()
+{
+ points.clear();
+ x = width() / 2;
+ y = height() / 2;
+ r = 0;
+}
+
+static inline int sign(int x)
+{
+ if(x > 0) return 1;
+ return -1;
+}
+
+void OutputWindow::forward(int x)
+{
+ sem.acquire();
+ float target_x = sin(r * (M_PI / 180.0)) * x;
+ float target_y = cos(r * (M_PI / 180.0)) * x;
+
+ float source_x = this->x;
+ float source_y = this->y;
+
+ for(int i = 0; i < abs(x); i++) {
+ float d = (float)i / (float)x * sign(x);
+ this->x = source_x + target_x * d;
+ this->y = source_y + target_y * d;
+ points.append(QPointF(this->x, this->y));
+ sem.acquire();
+ }
+}
+
+void OutputWindow::turn(int x)
+{
+ sem.acquire();
+ for(int i = 0; i < abs(x) * 2; i++) {
+ this->r += sign(x) * 0.5;
+ sem.acquire();
+ }
+}
diff --git a/src/outputwindow.h b/src/outputwindow.h
new file mode 100644
index 0000000..88b94c8
--- /dev/null
+++ b/src/outputwindow.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * outputwindow.h
+ *
+ * Sat Aug 4 13:44:40 CEST 2012
+ * Copyright 2012 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of Kaiman.
+ *
+ * Kaiman is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Kaiman is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Kaiman; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+#ifndef __KAIMAN_OUTPUTWINDOW_H__
+#define __KAIMAN_OUTPUTWINDOW_H__
+
+#include <QGLWidget>
+#include <QTimer>
+#include <QImage>
+#include <QVector>
+#include <QPoint>
+#include <QSemaphore>
+
+class OutputWindow : public QGLWidget {
+Q_OBJECT
+public:
+ OutputWindow();
+
+ void reset();
+
+ void forward(int x);
+ void turn(int x);
+
+public slots:
+ void timeout();
+
+protected:
+ void paintEvent(QPaintEvent * event);
+
+private:
+ QImage kaiman;
+ double x, y, r;
+ QTimer timer;
+ QSemaphore sem;
+ QVector<QPointF> points;
+};
+
+#endif/*__KAIMAN_OUTPUTWINDOW_H__*/
diff --git a/tools/add_file b/tools/add_file
new file mode 100755
index 0000000..edde529
--- /dev/null
+++ b/tools/add_file
@@ -0,0 +1,110 @@
+#!/bin/bash
+PROJECT="Kaiman"
+
+function allfile() {
+ WHO="`whoami`"
+
+ echo "/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */" > $1;
+ echo "/* vim: set et sw=2 ts=2: */" >> $1;
+ echo "/***************************************************************************" >> $1;
+ echo " * $1" >> $1;
+ echo " *" >> $1 ;
+ echo " * `date`" >> $1;
+ echo -n " * Copyright " >> $1
+ echo -n `date +%Y | xargs` >> $1
+ if [ "$WHO" == "nemo" ];
+ then
+ echo " Jonas Suhr Christensen" >> $1;
+ echo " * jsc@umbraculum.org" >> $1;
+ fi
+ if [ "$WHO" == "deva" ];
+ then
+ echo " Bent Bisballe Nyeng" >> $1;
+ echo " * deva@aasimon.org" >> $1;
+ fi
+ if [ "$WHO" == "senator" ];
+ then
+ echo " Lars Bisballe Jensen" >> $1;
+ echo " * elsenator@gmail.com" >> $1;
+ fi
+ if [ "$WHO" == "piparum" ];
+ then
+ echo " Peter Skaarup" >> $1;
+ echo " * and piparum@piparum.dk" >> $1;
+ fi
+ echo " ****************************************************************************/" >> $1;
+ echo "" >> $1;
+ echo "/*" >> $1;
+ echo " * This file is part of $PROJECT." >> $1;
+ echo " *" >> $1;
+ echo " * $PROJECT is free software; you can redistribute it and/or modify" >> $1;
+ echo " * it under the terms of the GNU General Public License as published by" >> $1;
+ echo " * the Free Software Foundation; either version 2 of the License, or" >> $1;
+ echo " * (at your option) any later version." >> $1;
+ echo " *" >> $1;
+ echo " * $PROJECT is distributed in the hope that it will be useful," >> $1;
+ echo " * but WITHOUT ANY WARRANTY; without even the implied warranty of" >> $1;
+ echo " * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" >> $1;
+ echo " * GNU General Public License for more details." >> $1;
+ echo " *" >> $1;
+ echo " * You should have received a copy of the GNU General Public License" >> $1;
+ echo " * along with $PROJECT; if not, write to the Free Software" >> $1;
+ echo " * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA." >> $1;
+ echo " */" >> $1;
+}
+
+function ccfile() {
+ local hf=`echo -n $1 | cut -d'.' -f1`.h;
+ hfile $hf;
+
+ allfile $1;
+ echo -n '#include "' >> $1;
+ echo -n $hf >> $1;
+ echo '"' >> $1;
+ echo '' >> $1;
+
+ local hn=`echo $1 | cut -d'.' -f1 | tr 'a-z.' 'A-Z_'`
+ echo "#ifdef TEST_${hn}" >> $1;
+ echo "//Additional dependency files" >> $1;
+ echo "//deps:" >> $1;
+ echo "//Required cflags (autoconf vars may be used)" >> $1;
+ echo "//cflags:" >> $1;
+ echo "//Required link options (autoconf vars may be used)" >> $1;
+ echo "//libs:" >> $1;
+ echo "#include \"test.h\"" >> $1;
+ echo "" >> $1;
+ echo "TEST_BEGIN;" >> $1;
+ echo "" >> $1;
+ echo "// TODO: Put some testcode here (see test.h for usable macros)." >> $1;
+ echo "TEST_TRUE(false, \"No tests yet!\");" >> $1;
+ echo "" >> $1;
+ echo "TEST_END;" >> $1;
+ echo "" >> $1;
+ echo "#endif/*TEST_${hn}*/" >> $1;
+}
+
+function hfile() {
+ allfile $1;
+ local hn=`echo $1 | tr 'a-z.' 'A-Z_'`
+ local pr=`echo $PROJECT | tr 'a-z.' 'A-Z_'`
+ echo "#ifndef __${pr}_${hn}__" >> $1;
+ echo "#define __${pr}_${hn}__" >> $1;
+ echo "#endif/*__${pr}_${hn}__*/" >> $1;
+}
+
+if [ "$#" = "1" ]; then
+if [ "CC" = `echo $1 | cut -d'.' -f2 | tr 'a-z' 'A-Z'` ]; then
+ ccfile $1;
+fi;
+if [ "H" = `echo $1 | cut -d'.' -f2 | tr 'a-z' 'A-Z'` ]; then
+ hfile $1;
+fi;
+else
+ echo "Usage: $0 filename";
+ echo
+ echo "Examples:";
+ echo "$0 myclass.cc Which will produce both myclass.cc and myclass.h";
+ echo "$0 myinterface.h Which will only produce myinterface.h";
+ echo
+ echo "NOTE: The files will be created in the current directory!";
+fi;