File: main.cpp

package info (click to toggle)
ktechlab 0.51.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,876 kB
  • sloc: cpp: 70,138; xml: 558; sh: 246; ansic: 19; makefile: 7
file content (97 lines) | stat: -rw-r--r-- 4,210 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/***************************************************************************
 *   Copyright (C) 2004-2005 by Daniel Clarke                              *
 *   Copyright (C) 2005 by David Saxton                                    *
 *   daniel.jc@gmail.com                                                   *
 *									   *
 *   24-04-2007                                                            *
 *   Modified to add pic 16f877,16f627 and 16f628 			   *
 *   by george john george@space-kerala.org,az.j.george@gmail.com	   *
 *   supported by SPACE www.space-kerala.org	 			   *
 *                                                                         *
 *   This program 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.                                   *
 *                                                                         *
 *   This program 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 this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "microbe.h"
#include "pic14.h"

#include <KAboutData>
#include <KLocalizedString>

#include <QCoreApplication>
#include <QCommandLineParser>

#include <iostream>
#include <fstream>
using namespace std;

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    KLocalizedString::setApplicationDomain("ktechlab"); // sharing strings with ktechlab

    KAboutData aboutData("microbe",
        i18n("Microbe"),
        QStringLiteral("0.3"),
        i18n("The Microbe Compiler"),
        KAboutLicense::GPL_V2,
        i18n("(C) 2004-2005, The KTechlab developers"),
        QString(),
        QStringLiteral("https://userbase.kde.org/KTechlab"));
    aboutData.addAuthor(i18n("Daniel Clarke"), QString(), QStringLiteral("daniel.jc@gmail.com"));
    aboutData.addAuthor(i18n("David Saxton"), QString(), QStringLiteral("david@bluehaze.org"));
    aboutData.addAuthor(i18n("George John"), i18n("Added pic 16f877,16f627 and 16f628"), QStringLiteral("az.j.george@gmail.com"));

    KAboutData::setApplicationData(aboutData);

    QCommandLineParser parser;
    aboutData.setupCommandLine(&parser);

    QCommandLineOption showSourceOption(QStringLiteral("show-source"), i18n( "Show source code lines in assembly output"));
    parser.addOption(showSourceOption);
    QCommandLineOption noOptimizeOption(QStringLiteral("no-optimize"), i18n( "Do not attempt optimization of generated instructions."));
    parser.addOption(noOptimizeOption);
    parser.addPositionalArgument( QStringLiteral("Input URL"), i18n( "Input filename" ));
    parser.addPositionalArgument( QStringLiteral("Output URL"), i18n( "Output filename" ));

    parser.process(app);
    aboutData.processCommandLine(&parser);

    const QStringList positionArguments = parser.positionalArguments();
    if (positionArguments.count() == 2 )
	{
		Microbe mb;	
//		QString s = mb.compile( positionArguments[0], parser.isSet(showSourceOption), !parser.isSet(noOptimizeOption));

		QString s = mb.compile( positionArguments[0], !parser.isSet(noOptimizeOption));

		QString errorReport = mb.errorReport();
		
		if ( !errorReport.isEmpty() )
		{
			cerr << mb.errorReport().toStdString();
			return 1; // If there was an error, don't write the output to file.
		}
		
		else
		{
			ofstream out(positionArguments[1].toStdString().c_str());
			out << s.toStdString();
			return 0;
		}
	}
	else parser.showHelp();
}