~registry/gcalctool/trunk

« back to all changes in this revision

Viewing changes to src/mp-equation.h

  • Committer: Robert Ancell
  • Date: 2012-10-14 03:31:40 UTC
  • Revision ID: git-v1:12ba2c81b0a81bb3ac776d1034a3c41b3173196a
Port to Vala

https://bugzilla.gnome.org/show_bug.cgi?id=640685

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004-2008 Sami Pietila
3
 
 * Copyright (C) 2008-2011 Robert Ancell.
4
 
 * 
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.
10
 
 */
11
 
 
12
 
#ifndef MP_EQUATION_H
13
 
#define MP_EQUATION_H
14
 
 
15
 
#include "mp.h"
16
 
 
17
 
typedef enum
18
 
{
19
 
    PARSER_ERR_NONE = 0,
20
 
    PARSER_ERR_INVALID,
21
 
    PARSER_ERR_OVERFLOW,
22
 
    PARSER_ERR_UNKNOWN_VARIABLE,
23
 
    PARSER_ERR_UNKNOWN_FUNCTION,
24
 
    PARSER_ERR_UNKNOWN_CONVERSION,
25
 
    PARSER_ERR_MP
26
 
} MPErrorCode;
27
 
 
28
 
/* Options for parser */
29
 
typedef struct {
30
 
    /* Default number base */
31
 
    int base;
32
 
 
33
 
    /* The wordlength for binary operations in bits (e.g. 8, 16, 32) */
34
 
    int wordlen;
35
 
 
36
 
    /* Units for angles (e.g. radians, degrees) */
37
 
    MPAngleUnit angle_units;
38
 
 
39
 
    // FIXME:
40
 
    // int enable_builtins;
41
 
 
42
 
    /* Data to pass to callbacks */
43
 
    void *callback_data;
44
 
  
45
 
    /* Function to check if a variable is defined */
46
 
    int (*variable_is_defined)(const char *name, void *data);
47
 
 
48
 
    /* Function to get variable values */
49
 
    int (*get_variable)(const char *name, MPNumber *z, void *data);
50
 
 
51
 
    /* Function to set variable values */
52
 
    void (*set_variable)(const char *name, const MPNumber *x, void *data);
53
 
 
54
 
    /* Function to check if a function is defined */
55
 
    int (*function_is_defined)(const char *name, void *data);
56
 
 
57
 
    /* Function to solve functions */
58
 
    int (*get_function)(const char *name, const MPNumber *x, MPNumber *z, void *data);
59
 
 
60
 
    /* Function to convert units */
61
 
    int (*convert)(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data);
62
 
} MPEquationOptions;
63
 
 
64
 
MPErrorCode mp_equation_parse(const char *expression, MPEquationOptions *options, MPNumber *result, char **error_token, glong *error_start, glong *error_end);
65
 
const char *mp_error_code_to_string(MPErrorCode error_code);
66
 
 
67
 
int sub_atoi(const char *data);
68
 
int super_atoi(const char *data);
69
 
#endif