static void solve(const char *equation) { MPEquationOptions options; MPErrorCode error; MPNumber result; char *result_str; memset(&options, 0, sizeof(options)); options.base = 10; options.wordlen = 32; options.angle_units = MP_DEGREES; options.convert = do_convert; error = mp_equation_parse(equation, &options, &result, NULL); if(error == PARSER_ERR_MP) { fprintf(stderr, "Error: %s\n", mp_get_error()); exit(1); } else if(error != 0) { fprintf(stderr, "Error: %s\n", mp_error_code_to_string(error)); exit(1); } else { result_str = mp_serializer_to_string(mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, 10, 9), &result); printf("%s\n", result_str); exit(0); } }
int main(int argc, char **argv) { char *equation, *line; size_t nbytes = MAXLINE; /* Seed random number generator. */ srand48((long) time((time_t *) 0)); #if !GLIB_CHECK_VERSION (2, 36, 0) g_type_init (); #endif setlocale(LC_ALL, ""); result_serializer = mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, 10, 9); equation = (char *) malloc(MAXLINE * sizeof(char)); while (1) { printf("> "); line = fgets(equation, nbytes, stdin); if (line != NULL) str_adjust(equation); if (line == NULL || strcmp(equation, "exit") == 0 || strcmp(equation, "quit") == 0 || strlen(equation) == 0) break; solve(equation); } free(equation); return 0; }
static void math_variables_init(MathVariables *variables) { variables->priv = G_TYPE_INSTANCE_GET_PRIVATE (variables, math_variables_get_type(), MathVariablesPrivate); variables->priv->registers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); variables->priv->file_name = g_build_filename(g_get_user_data_dir(), "gcalctool", "registers", NULL); variables->priv->serializer = mp_serializer_new(MP_DISPLAY_FORMAT_SCIENTIFIC, 10, 50); mp_serializer_set_radix(variables->priv->serializer, '.'); registers_load(variables); }