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