From a3016fbf0d50bfe82e69a657328ef76370227979 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 24 Mar 2011 12:53:39 +0000 Subject: Initial commit of docgen. --- client/docgen/doc.h | 67 +++++++++++++++ client/docgen/docgen.cc | 162 +++++++++++++++++++++++++++++++++++ client/docgen/docgen.pro | 104 +++++++++++++++++++++++ client/docgen/generate.cc | 212 ++++++++++++++++++++++++++++++++++++++++++++++ client/docgen/generate.h | 39 +++++++++ client/docgen/genimage.cc | 163 +++++++++++++++++++++++++++++++++++ client/docgen/genimage.h | 35 ++++++++ client/docgen/parse.cc | 198 +++++++++++++++++++++++++++++++++++++++++++ client/docgen/parse.h | 37 ++++++++ client/docgen/style.css | 108 +++++++++++++++++++++++ 10 files changed, 1125 insertions(+) create mode 100644 client/docgen/doc.h create mode 100644 client/docgen/docgen.cc create mode 100644 client/docgen/docgen.pro create mode 100644 client/docgen/generate.cc create mode 100644 client/docgen/generate.h create mode 100644 client/docgen/genimage.cc create mode 100644 client/docgen/genimage.h create mode 100644 client/docgen/parse.cc create mode 100644 client/docgen/parse.h create mode 100644 client/docgen/style.css diff --git a/client/docgen/doc.h b/client/docgen/doc.h new file mode 100644 index 0000000..fc400fc --- /dev/null +++ b/client/docgen/doc.h @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * doc.h + * + * Thu Mar 24 12:07:27 CET 2011 + * Copyright 2011 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_DOC_H__ +#define __PRACRO_DOC_H__ + +#include +#include + +class Parameter { +public: + QString name; + QString description; +}; + +class Method { +public: + QString name; + QString description; + QString returns; + QVector parameters; +}; + +class Attribute { +public: + QString name; + QString description; +}; + +class Doc { +public: + QString title; + QString name; + QString tag; + QString extends; + bool screenshot; + bool container; + QString description; + QVector attributes; + QVector methods; +}; + +#endif/*__PRACRO_DOC_H__*/ diff --git a/client/docgen/docgen.cc b/client/docgen/docgen.cc new file mode 100644 index 0000000..e5a8bff --- /dev/null +++ b/client/docgen/docgen.cc @@ -0,0 +1,162 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * docgen.cc + * + * Tue Mar 15 11:20:09 CET 2011 + * Copyright 2011 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 +#include +#include +#include +#include +#include +#include + +#include + +#include "doc.h" +#include "parse.h" +#include "generate.h" + +#define INPUT "../widgets" +#define OUTPUT "html" + +QString output; + +QString header = + "\n" + "\n" + " \n" + " Pracro Widget Documentation\n" + " \n" + " \n" + " \n" + " \n"; + +QString footer = + " \n" + "\n"; + +void getInheritedAttributes(QMap > &atts, + QMap &docs, + QString name) +{ + if(name == "" || atts.contains(name)) return; + atts[name] = docs[name].attributes; + getInheritedAttributes(atts, docs, docs[name].extends); +} + +void getInheritedMethods(QMap > &meths, + QMap &docs, + QString name) +{ + if(name == "" || meths.contains(name)) return; + meths[name] = docs[name].methods; + getInheritedMethods(meths, docs, docs[name].extends); +} + + +void writeDoc(QMap &docs, QString name) +{ + Doc doc = docs[name]; + + QMap > atts; + getInheritedAttributes(atts, docs, doc.extends); + + QMap > meths; + getInheritedMethods(meths, docs, doc.extends); + + QString out = generate(doc, meths, atts); + + QFile::remove(output + "/" + name + ".html"); + QFile ofile(output + "/" + name + ".html"); + ofile.open(QIODevice::ReadWrite | QIODevice::Text); + ofile.write(header.toStdString().c_str(), header.length()); + ofile.write(out.toStdString().c_str()), out.length(); + ofile.write(footer.toStdString().c_str(), footer.length()); + ofile.close(); +} + +void writeIndex(QMap &docs) +{ + QString out; + + out += "

Pracro "VERSION" Documentation

\n"; + out += "

Overview

\n"; + + out += "
    \n"; + QMap::iterator i = docs.begin(); + while(i != docs.end()) { + Doc &doc = *i; + out += "
  • ["+doc.name+"] - "+ + doc.title+"
  • \n"; + i++; + } + out += "
\n"; + + QFile::remove(output + "/index.html"); + QFile ofile(output + "/index.html"); + ofile.open(QIODevice::ReadWrite | QIODevice::Text); + ofile.write(header.toStdString().c_str()); + ofile.write(out.toStdString().c_str()); + ofile.write(footer.toStdString().c_str()); + ofile.close(); +} + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + output = OUTPUT; + + QMap docs; + + QDir d; d.mkdir(output); + QFile::remove(output + "/style.css"); + QFile::copy("style.css", output + "/style.css"); + + QDir dir(INPUT); + QStringList filter; filter << "*.h"; + dir.setNameFilters(filter); + + if(!dir.exists()) return 1; + QStringList l = dir.entryList(QDir::Files); + foreach(QString file, l) { + Doc doc = parse(QString(INPUT) + "/" + file); + docs[doc.name] = doc; + } + + writeIndex(docs); + + QMap::iterator i = docs.begin(); + while(i != docs.end()) { + QString name = i.key(); + writeDoc(docs, name); + i++; + } + + // return app.exec(); + return 0; +} diff --git a/client/docgen/docgen.pro b/client/docgen/docgen.pro new file mode 100644 index 0000000..d495439 --- /dev/null +++ b/client/docgen/docgen.pro @@ -0,0 +1,104 @@ +# -*- Makefile -*- + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . .. ../widgets +QT += core gui xml svg network sql +RESOURCES += ../client.qrc + +include(../../VERSION) +DEFINES+=VERSION=\\\"$$VERSION\\\" + +win32 { + LIBPATH += lua/lib + INCLUDEPATH += lua/include + LIBS += -llua51 + DEFINES += HOST_WIN32 +} + +unix { + LIBS += -llua + LIBS += -lqjson +} + +# Input +SOURCES += \ + docgen.cc \ + genimage.cc \ + generate.cc \ + parse.cc \ + ../debug.cc \ + ../lua.cc \ + ../luawidget.cc \ + ../luadb.cc \ + ../messagebox.cc \ + ../macrowindow.cc \ + ../collapser.cc \ + ../netcom.cc \ + ../resumewidget.cc \ + ../mainwindow.cc \ + ../macro.cc \ + ../header.cc \ + ../viewer.cc \ + ../macrodrawer.cc \ + ../widgets/common.cc \ + ../widgets/widget.cc \ + ../widgets/label.cc \ + ../widgets/lineedit.cc \ + ../widgets/multilist.cc \ + ../widgets/textedit.cc \ + ../widgets/button.cc \ + ../widgets/combobox.cc \ + ../widgets/datetime.cc \ + ../widgets/listbox.cc \ + ../widgets/frame.cc \ + ../widgets/groupbox.cc \ + ../widgets/radiobutton.cc \ + ../widgets/radiobuttons.cc \ + ../widgets/checkbox.cc \ + ../widgets/checkgroupbox.cc \ + ../widgets/window.cc \ + ../widgets/altcombobox.cc \ + ../widgets/metawidget.cc + +HEADERS += \ + genimage.h \ + generate.h \ + parse.h \ + doc.h \ + ../debug.h \ + ../lua.h \ + ../luawidget.h \ + ../luadb.h \ + ../messagebox.h \ + ../macrowindow.h \ + ../collapser.h \ + ../netcom.h \ + ../resumewidget.h \ + ../mainwindow.h \ + ../entity.h \ + ../macro.h \ + ../header.h \ + ../viewer.h \ + ../macrodrawer.h \ + ../widgets.h \ + ../widgets/common.h \ + ../widgets/widget.h \ + ../widgets/label.h \ + ../widgets/lineedit.h \ + ../widgets/multilist.h \ + ../widgets/textedit.h \ + ../widgets/button.h \ + ../widgets/datetime.h \ + ../widgets/combobox.h \ + ../widgets/listbox.h \ + ../widgets/frame.h \ + ../widgets/groupbox.h \ + ../widgets/radiobutton.h \ + ../widgets/radiobuttons.h \ + ../widgets/checkbox.h \ + ../widgets/checkgroupbox.h \ + ../widgets/window.h \ + ../widgets/altcombobox.h \ + ../widgets/metawidget.h diff --git a/client/docgen/generate.cc b/client/docgen/generate.cc new file mode 100644 index 0000000..73734a5 --- /dev/null +++ b/client/docgen/generate.cc @@ -0,0 +1,212 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * generate.cc + * + * Thu Mar 24 12:09:33 CET 2011 + * Copyright 2011 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 "generate.h" + +#include +#include + +#include "genimage.h" + +static QString generateMethods(QVector meths) +{ + QString out; + + foreach(Method meth, meths) { + out += "
\n"; + out += "
" + meth.name + "
\n"; + out += "
" + meth.description + + "
\n"; + + if(meth.parameters.size()) { + out += "
\n"; + foreach(Parameter parm, meth.parameters) { + out += "
\n"; + out += "
" + parm.name + "
\n"; + out += "
" + + parm.description + "
\n"; + out += "
\n"; + } + out += "
\n"; + } + + if(meth.returns != "") { + out += "
Returns " + + meth.returns + "
\n"; + } + + out += "
\n"; + } + + return out; +} + +static QString generateAttributes(QVector attrs) +{ + QString out; + + foreach(Attribute attr, attrs) { + out += "
\n"; + out += "
" + attr.name + "
\n"; + out += "
" + attr.description + + "
\n"; + out += "
\n"; + } + + return out; +} + +static QString generateMethodOverview(Doc &doc, + QMap > &imeths) + +{ + QString out; + + out += "

Method overview

\n"; + + QVector meths; + + meths += doc.methods; + + QMap >::iterator j = imeths.begin(); + while(j != imeths.end()) { + meths += j.value(); + j++; + } + + // sort + for(int i = 0; i < meths.size(); i++) { + for(int j = 0; j < meths.size(); j++) { + if(meths[i].name < meths[j].name) { + Method tmp = meths[i]; + meths[i] = meths[j]; + meths[j] = tmp; + } + } + } + + out += "
    \n"; + foreach(Method meth, meths) { + out += "
  • "+meth.name+" " + + meth.description.left(meth.description.indexOf(".") + 1) + "
  • \n"; + } + out += "
\n"; + + return out; +} + +QString generate(Doc &doc, QMap > &meths, + QMap > &atts) +{ + QString out; + + out += " \n"; + + out += "
\n"; + out += "

" + doc.title + "

\n"; + if(doc.tag != "" ){ + out += "
<" + doc.tag + " />
\n"; + } + + if(doc.container) { + out += "
Widget is a container.
\n"; + } + + if(doc.extends != "") { + out += " \n"; + } + + if(doc.screenshot) { + genImage(doc.tag); + out += "
\n"; + out += " \n"; + out += "
\n"; + } + + out += "
\n"; + out += doc.description; + out += "
\n"; + + out += "

Attributes

\n"; + out += "
\n"; + if(doc.attributes.size()) { + out += generateAttributes(doc.attributes); + } + + QMap >::iterator i = atts.begin(); + while(i != atts.end()) { + out += "

Attributes inherited from "+i.key()+":

\n"; + out += generateAttributes(i.value()); + i++; + } + out += "
\n"; + + out += generateMethodOverview(doc, meths); + + out += "

Methods

\n"; + out += "
\n"; + if(doc.methods.size()) { + out += generateMethods(doc.methods); + } + + QMap >::iterator j = meths.begin(); + while(j != meths.end()) { + out += "

Methods inherited from "+j.key()+":

\n"; + out += generateMethods(j.value()); + j++; + } + out += "
\n"; + + out += "
\n"; + + out += "
This documentation is generated for" + " Pracro version "VERSION" at "+QDate::currentDate().toString()+"
\n"; + return out; +} + +#ifdef TEST_GENERATE +//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_GENERATE*/ diff --git a/client/docgen/generate.h b/client/docgen/generate.h new file mode 100644 index 0000000..24a3191 --- /dev/null +++ b/client/docgen/generate.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * generate.h + * + * Thu Mar 24 12:09:33 CET 2011 + * Copyright 2011 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_GENERATE_H__ +#define __PRACRO_GENERATE_H__ + +#include +#include + +#include "doc.h" + +QString generate(Doc &doc, QMap > &meths, + QMap > &atts); + +#endif/*__PRACRO_GENERATE_H__*/ diff --git a/client/docgen/genimage.cc b/client/docgen/genimage.cc new file mode 100644 index 0000000..332887c --- /dev/null +++ b/client/docgen/genimage.cc @@ -0,0 +1,163 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * genimage.cc + * + * Wed Mar 16 11:56:22 CET 2011 + * Copyright 2011 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 "genimage.h" + +#include +#include + +#include +#include + +#include +#include + +QString cpr; +QString user; +QFont fixedfont; + +Viewer *viewer = NULL; + +extern QString output; + +void genImage(QString widget) +{ + QDomDocument node; + + QDomElement elem = node.createElement(widget); + elem.setAttribute("name", widget); + elem.setAttribute("caption", "Caption"); + elem.setAttribute("layout", "vbox"); + + if(widget == "lineedit" || widget == "textedit") { + elem.setAttribute("value", "Some text"); + } + + if(widget == "checkbox" || widget == "checkgroupbox") { + elem.setAttribute("truevalue", "true"); + elem.setAttribute("falsevalue", "false"); + elem.setAttribute("value", "true"); + } + + if(widget == "combobox" || widget == "listbox") { + { + QDomElement e = node.createElement("item"); + e.setAttribute("caption", "List item 1"); + e.setAttribute("value", "item1"); + elem.appendChild(e); + } + { + QDomElement e = node.createElement("item"); + e.setAttribute("caption", "List item 2"); + e.setAttribute("value", "item2"); + elem.appendChild(e); + } + + { + QDomElement e = node.createElement("item"); + e.setAttribute("caption", "List item 3"); + e.setAttribute("value", "item3"); + elem.appendChild(e); + } + + elem.setAttribute("value", "item1"); + } + + if(widget == "altcombobox") { + QDomElement e = node.createElement("altitem"); + e.setAttribute("caption", "Alt item"); + e.setAttribute("value", "altitem"); + e.setAttribute("innerwidget", "altitem"); + elem.appendChild(e); + + QDomElement a = node.createElement("lineedit"); + a.setAttribute("name", "altitem"); + a.setAttribute("value", "Some alt text"); + e.appendChild(a); + + elem.setAttribute("value", "altitem"); + } + + if(widget == "multilist") { + QDomElement a = node.createElement("lineedit"); + a.setAttribute("name", "altitem"); + a.setAttribute("value", "Value ready to be added"); + elem.appendChild(a); + elem.setAttribute("value", "Some value\nAnother value"); + } + + if(widget == "frame" || widget == "checkgroupbox") { + QDomElement e = node.createElement("label"); + e.setAttribute("caption", "Contained widgets."); + elem.appendChild(e); + } + + if(widget == "radiobuttons") { + QDomElement e1 = node.createElement("radiobutton"); + e1.setAttribute("caption", "Radio Button 1"); + elem.appendChild(e1); + + QDomElement e2 = node.createElement("radiobutton"); + e2.setAttribute("caption", "Radio Button 2"); + elem.appendChild(e2); + } + + node.appendChild(elem); + + Window w(node, NULL); + w.setValues(); + w.qwidget()->show(); + QPixmap pix = QPixmap::grabWidget(w.qwidget(), 0, 0); + QImage img = pix.toImage(); + QRgb bg = img.pixel(img.width() - 1, img.height() - 1); + + int cropvert = img.height(); + int crophorz = img.width(); + for(int y = img.height() - 1; y > 0; y--) { + for(int x = 0; x < img.width(); x++) { + if(img.pixel(x, y) != bg) { + cropvert = y; + y = -1; // break out of y for-loop + break; + } + } + } + + for(int x = img.width() - 1; x > 0; x--) { + for(int y = 0; y < img.height(); y++) { + if(img.pixel(x, y) != bg) { + crophorz = x; + x = -1; // break out of x for-loop + break; + } + } + } + + img = img.copy(0,0, crophorz + 12, cropvert + 12); + QDir d;d.mkdir(output + "/gfx/"); + img.save(output + "/gfx/" + widget + ".png"); +} diff --git a/client/docgen/genimage.h b/client/docgen/genimage.h new file mode 100644 index 0000000..079ae91 --- /dev/null +++ b/client/docgen/genimage.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * genimage.h + * + * Wed Mar 16 11:56:22 CET 2011 + * Copyright 2011 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_GENIMAGE_H__ +#define __PRACRO_GENIMAGE_H__ + +#include + +void genImage(QString widget); + +#endif/*__PRACRO_GENIMAGE_H__*/ diff --git a/client/docgen/parse.cc b/client/docgen/parse.cc new file mode 100644 index 0000000..bcf137b --- /dev/null +++ b/client/docgen/parse.cc @@ -0,0 +1,198 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * parse.cc + * + * Thu Mar 24 12:07:16 CET 2011 + * Copyright 2011 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 "parse.h" + +#include +#include + +typedef enum { + none, + indesc, + inatt, + inmeth, + inpar, + inret, +} state_t; + +Doc parse(QString filename) +{ + Doc doc; + doc.screenshot = false; + doc.container = false; + + QFileInfo fi(filename); + QString name = fi.fileName(); + doc.name = name.left(name.length() - 2); // Strip ".h" + + state_t state = none; + + fprintf(stderr, "Processing file: %s\n", filename.toStdString().c_str()); + QFile file(filename); + if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) { + fprintf(stderr, "Could not open %s for reading.\n", + filename.toStdString().c_str()); + return doc; + } + + bool running = false; + QByteArray data; + while(!file.atEnd()) { + QString line = file.readLine(); + if(line.right(1) == "\n") line = line.left(line.length() - 1); + + if(line.contains("*/")) running = false; + + if(running) { + line.remove(QRegExp("^[ \t*]*")); + printf("line [%s]\n", line.toStdString().c_str()); + + if(state == indesc && line.left(1) == "@") state = none; + if(state == inatt && line.left(1) == "@") state = none; + if(state == inpar && line.left(1) == "@") state = inmeth; + if(state == inret && line.left(1) == "@") state = inmeth; + + if(state == none && doc.title == "") { + doc.title = line; + continue; + } + + if(state == none && line.left(4) == "@tag") { + doc.tag = line.right(line.length() - line.indexOf(" ") - 1); + continue; + } + + if(state == none && line.left(8) == "@extends") { + doc.extends = line.right(line.length() - line.indexOf(" ") - 1); + continue; + } + + if(state == none && line.left(11) == "@screenshot") { + doc.screenshot = true; + continue; + } + + if(state == none && line.left(10) == "@container") { + doc.container = true; + continue; + } + + if(state == none && line.left(1) != "@" && doc.description == "") { + state = indesc; + } + + + if(state == indesc) { + doc.description += line + "\n"; + continue; + } + + if(state == none && line.left(4) == "@att") { + Attribute att; + att.name = line.mid(5, line.indexOf(" ", 5) - 5); + att.description = + line.right(line.length() - line.indexOf(" ", 6) - 1) + "\n"; + doc.attributes.push_back(att); + state = inatt; + continue; + } + + if(state == inatt) { + Attribute &a = doc.attributes[doc.attributes.size() - 1]; + a.description += line + "\n"; + continue; + } + + if((state == none || state == inmeth) && line.left(7) == "@method") { + Method meth; + meth.name = line.right(line.length() - 7 - 1); + doc.methods.push_back(meth); + state = inmeth; + continue; + } + + if(state == inmeth && line.left(1) != "@") { + Method &m = doc.methods[doc.methods.size() - 1]; + m.description += line + "\n"; + continue; + } + + if(state == inmeth && line.left(6) == "@param") { + Method &m = doc.methods[doc.methods.size() - 1]; + Parameter par; + par.name = line.mid(7, line.indexOf(" ", 7) - 7); + par.description = + line.right(line.length() - line.indexOf(" ", 7) - 1) + "\n"; + m.parameters.push_back(par); + state = inpar; + continue; + } + + if(state == inpar) { + Method &m = doc.methods[doc.methods.size() - 1]; + Parameter &p = m.parameters[m.parameters.size() - 1]; + p.description += line + "\n"; + continue; + } + + if(state == inmeth && line.left(7) == "@return") { + Method &m = doc.methods[doc.methods.size() - 1]; + m.returns = line.right(line.length() - line.indexOf(" ", 7) - 1) + "\n"; + state = inret; + continue; + } + + if(state == inret) { + Method &m = doc.methods[doc.methods.size() - 1]; + m.returns += line + "\n"; + continue; + } + } + + if(line == "/***") running = true; + } + + return doc; +} + +#ifdef TEST_PARSE +//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_PARSE*/ diff --git a/client/docgen/parse.h b/client/docgen/parse.h new file mode 100644 index 0000000..3f1f73e --- /dev/null +++ b/client/docgen/parse.h @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * parse.h + * + * Thu Mar 24 12:07:16 CET 2011 + * Copyright 2011 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_PARSE_H__ +#define __PRACRO_PARSE_H__ + +#include + +#include "doc.h" + +Doc parse(QString filename); + +#endif/*__PRACRO_PARSE_H__*/ diff --git a/client/docgen/style.css b/client/docgen/style.css new file mode 100644 index 0000000..778c69d --- /dev/null +++ b/client/docgen/style.css @@ -0,0 +1,108 @@ +body { + font-family: Verdana; + font-size: 12px; +} + +a { + color: #5c7b8b; +} + +a:visited { + color: #465d69; +} + +a:hover { + color: #000; +} + +.doc { + padding: 10px; +} + +.doc .title { + font-weight: bold; + font-size: 1.5em; + text-align: center; +} + +.doc .tagname { + text-align: center; + font-family: courier; +} + +.doc .extends {} +.doc .container {} +.doc .screenshot { + text-align: center; +} +.doc .description { + padding-top: 4px; + padding-bottom: 4px; +} + +.attributes {} +.attribute {} +.attribute .name { + font-weight: normal; + font-style: italic; + border: 0px; + border-radius: 0px 0px 0px 0px; + background-color: transparent; + display: inline; + color: green; + font-family: courier; + padding-right: 4px; + padding-left: 4px; + font-size: 1.2em; +} +.attribute .name:before { + content:"- "; +} +.attribute .description { + display: inline; +} + +.attributes, +.parameters { + margin-top: 8px; + border-top: solid #DEDEEE 1px; + padding-top: 8px; + + margin-bottom: 8px; + border-bottom: solid #DEDEEE 1px; + padding-bottom: 8px; +} + +.method { + background-color: #EEF3F5; + border: solid #DEDEEE 1px; + padding: 4px; + border-radius: 8px 8px 8px 8px; + margin-bottom: 8px; +} + +.method .name { + background-color: #D5E1E8; + width: *; + border: solid #84B0C7 1px; + font-weight: bold; + padding: 4px; + border-radius: 8px 8px 8px 8px; +} + + +.method .description {} +.method .returns {} + +.parameter {} +.parameter .name { + font-weight: normal; + font-style: italic; + border: 0px; + border-radius: 0px 0px 0px 0px; + background-color: transparent; + display: inline; +} +.parameter .description { + display: inline; +} -- cgit v1.2.3