summaryrefslogtreecommitdiff
path: root/client/docgen/docgen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'client/docgen/docgen.cc')
-rw-r--r--client/docgen/docgen.cc162
1 files changed, 162 insertions, 0 deletions
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 <QApplication>
+#include <QDomNode>
+#include <QFont>
+#include <QFile>
+#include <QDir>
+#include <QMap>
+#include <QDate>
+
+#include <stdio.h>
+
+#include "doc.h"
+#include "parse.h"
+#include "generate.h"
+
+#define INPUT "../widgets"
+#define OUTPUT "html"
+
+QString output;
+
+QString header =
+ "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\""
+ " \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n"
+ "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+ " <head>\n"
+ " <title>Pracro Widget Documentation</title>\n"
+ " <meta http-equiv=\"Content-Type\" content=\"text/html\"/>\n"
+ " <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/>\n"
+ " </head> \n"
+ " <body>\n";
+
+QString footer =
+ " </body>\n"
+ "</html>\n";
+
+void getInheritedAttributes(QMap<QString, QVector<Attribute> > &atts,
+ QMap<QString, Doc> &docs,
+ QString name)
+{
+ if(name == "" || atts.contains(name)) return;
+ atts[name] = docs[name].attributes;
+ getInheritedAttributes(atts, docs, docs[name].extends);
+}
+
+void getInheritedMethods(QMap<QString, QVector<Method> > &meths,
+ QMap<QString, Doc> &docs,
+ QString name)
+{
+ if(name == "" || meths.contains(name)) return;
+ meths[name] = docs[name].methods;
+ getInheritedMethods(meths, docs, docs[name].extends);
+}
+
+
+void writeDoc(QMap<QString, Doc> &docs, QString name)
+{
+ Doc doc = docs[name];
+
+ QMap<QString, QVector<Attribute> > atts;
+ getInheritedAttributes(atts, docs, doc.extends);
+
+ QMap<QString, QVector<Method> > 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<QString, Doc> &docs)
+{
+ QString out;
+
+ out += "<h1>Pracro "VERSION" Documentation</h1>\n";
+ out += "<h2>Overview</h2>\n";
+
+ out += "<ul>\n";
+ QMap<QString, Doc>::iterator i = docs.begin();
+ while(i != docs.end()) {
+ Doc &doc = *i;
+ out += "<li><a href=\""+doc.name+".html\">["+doc.name+"]</a> - "+
+ doc.title+"</li>\n";
+ i++;
+ }
+ out += "</ul>\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<QString, Doc> 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<QString, Doc>::iterator i = docs.begin();
+ while(i != docs.end()) {
+ QString name = i.key();
+ writeDoc(docs, name);
+ i++;
+ }
+
+ // return app.exec();
+ return 0;
+}