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/docgen.cc | 162 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 client/docgen/docgen.cc (limited to 'client/docgen/docgen.cc') 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; +} -- cgit v1.2.3