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 12 #include <stdio.h> 13 14 #include "CalcApplication.h" 15 #include "ExpressionParser.h" 16 17 18 int 19 main(int argc, char* argv[]) 20 { 21 if (argc == 1) { 22 // run GUI 23 CalcApplication* app = new CalcApplication(); 24 25 app->Run(); 26 delete app; 27 } else { 28 // evaluate expression from command line 29 BString expression; 30 int32 i = 1; 31 while (i < argc) { 32 expression << argv[i]; 33 i++; 34 } 35 36 try { 37 ExpressionParser parser; 38 BString result = parser.Evaluate(expression.String()); 39 printf("%s\n", result.String()); 40 } catch (ParseException e) { 41 printf("%s at %" B_PRId32 "\n", e.message.String(), e.position + 1); 42 return 1; 43 } 44 } 45 46 return 0; 47 } 48