File: main.cpp

package info (click to toggle)
mysql%2B%2B 3.2.1%2Bpristine-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 13,624 kB
  • ctags: 11,252
  • sloc: cpp: 35,659; sh: 3,034; makefile: 951; perl: 786
file content (132 lines) | stat: -rw-r--r-- 3,647 bytes parent folder | download | duplicates (6)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***********************************************************************
 ssx/main.cpp - Main driver module for ssqlsxlat, which does several
 	data translations related to the SSQLSv2 mechanism of MySQL++.  The
	primary one is SSQLSv2 language files (*.ssqls) to C++ source code,
	but there are others.  Run "ssqlsxlat -?" to get a complete list.

 Copyright (c) 2009 by Warren Young and (c) 2009-2010 by Educational
 Technology Resources, Inc.  Others may also hold copyrights on code
 in this file.  See the CREDITS.txt file in the top directory of the
 distribution for details.

 This file is part of MySQL++.

 MySQL++ is free software; you can redistribute it and/or modify it
 under the terms of the GNU Lesser General Public License as published
 by the Free Software Foundation; either version 2.1 of the License, or
 (at your option) any later version.

 MySQL++ 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 Lesser General Public
 License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with MySQL++; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
 USA
***********************************************************************/

#include "genv2.h"
#include "parsev2.h"

#include <cmdline.h>

#include <iostream>

using namespace std;
using namespace mysqlpp::ssqlsxlat;


//// parse_ssqls2 //////////////////////////////////////////////////////
// We were given the name of a putative SSQLS v2 source file; try to
// parse it.

static ParseV2*
parse_ssqls2(const char* file_name)
{
	try {
		cout << "Parsing SSQLS v2 file " << file_name << "..." << endl;
		ParseV2* pt = new ParseV2(file_name);
		cout << file_name << " parsed successfully, " <<
				(pt->end() - pt->begin()) << " interesting lines." <<
				endl;
		return pt;
	}
	catch (const ParseV2::FileException& e) {
		cerr << file_name << ":0" << 
				": file I/O error in SSQLS v2 parse: " <<
				e.what() << endl;
	}
	catch (const ParseV2::ParseException& e) {
		cerr << e.file_name() << ':' << e.line() << ':' <<
				e.what() << endl;
	}
	catch (const std::exception& e) {
		cerr << file_name << ":0" << 
				": critical error in SSQLS v2 parse: " <<
				e.what() << endl;
	}
	return 0;
}


//// main //////////////////////////////////////////////////////////////

int
main(int argc, char* argv[])
{
	// Parse the command line
	CommandLine cmdline(argc, argv);
	if (cmdline) {
		ParseV2* ptree = 0;

		switch (cmdline.input_source()) {
			case CommandLine::ss_ssqls2:
				ptree = parse_ssqls2(cmdline.input());
				break;

			default:
				cerr << "Sorry, I don't yet know what to do with input "
						"source type " << int(cmdline.input_source()) <<
						'!' << endl;
				return 2;
		}

		if (cmdline.output_sink() != CommandLine::ss_unknown) {
			if (ptree) {
				switch (cmdline.output_sink()) {
					case CommandLine::ss_ssqls2:
						if (generate_ssqls2(cmdline.output(), ptree)) {
							return 0;
						}
						else {
							return 2;
						}

					default:
						cerr << "Sorry, I don't yet know what to do "
								"with sink type " <<
								int(cmdline.output_sink()) << '!' <<
								endl;
						return 2;
				}
			}
			else {
				// Depending on someone farther up the line to write
				// the error message, explaining why we didn't get a
				// parse tree.
				return 2;
			}	
		}
		else {
			cerr << "Sorry, I don't know how to write C++ output yet." <<
					endl;
			return 2;
		}
	}
	else {
		return 1;
	}
}