xref: /haiku/src/apps/deskcalc/DeskCalc.cpp (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright 2006 Haiku, Inc. All Rights Reserved.
3  * Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
4  * Distributed under the terms of the MIT License.
5  *
6  * Authors:
7  *		Timothy Wayper <timmy@wunderbear.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 
11 #include <stdio.h>
12 
13 #include "CalcApplication.h"
14 #include "ExpressionParser.h"
15 
16 int
17 main(int argc, char* argv[])
18 {
19 	if (argc == 1) {
20 		// run GUI
21 		CalcApplication* app = new CalcApplication();
22 
23 		app->Run();
24 		delete app;
25 	} else {
26 		// evaluate expression from command line
27 		BString expression;
28 		int32 i = 1;
29 		while (i < argc) {
30 			expression << argv[i];
31 			i++;
32 		}
33 
34 		try {
35 			ExpressionParser parser;
36 			BString result = parser.Evaluate(expression.String());
37 			printf("%s\n", result.String());
38 		} catch (ParseException e) {
39 			printf("%s at %ld\n", e.message.String(), e.position + 1);
40 			return 1;
41 		}
42 	}
43 
44 	return 0;
45 }
46