Updated kn translations
[gcalctool.git] / src / gcalccmd.vala
blobbc5e7a0b01e0d8fbf0ffa0f44e3a6b1dbf26f5bc
1 /*
2 * Copyright (C) 2009 Rich Burridge
3 * Copyright (C) 2012 Robert Ancell
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 2 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
9 * license.
12 private const int MAXLINE = 1024;
14 private static Serializer result_serializer;
16 static void solve (string equation)
18 var e = new Equation (equation);
19 e.base = 10;
20 e.wordlen = 32;
21 e.angle_units = AngleUnit.DEGREES;
23 ErrorCode ret;
24 var z = e.parse (out ret, null);
26 if (z != null)
27 stdout.printf ("%s\n", result_serializer.to_string (z));
28 else if (ret == ErrorCode.MP)
29 stderr.printf ("Error %s\n", mp_get_error ());
30 else
31 stderr.printf ("Error %d\n", ret);
34 public static int main (string[] args)
36 /* Seed random number generator. */
37 var now = new DateTime.now_utc ();
38 Random.set_seed (now.get_microsecond ());
40 Intl.setlocale (LocaleCategory.ALL, "");
42 result_serializer = new Serializer (DisplayFormat.AUTOMATIC, 10, 9);
44 var buffer = new char[1024];
45 while (true)
47 stdout.printf ("> ");
48 var line = stdin.gets (buffer);
50 line = line.strip ();
51 if (line == null || line == "exit" || line == "quit" || line == "")
52 break;
54 solve (line);
57 return Posix.EXIT_SUCCESS;