[gcalctool/gcalctool-newui2] ...
- From: Robert Ancell <rancell src gnome org>
- To: svn-commits-list gnome org
- Subject: [gcalctool/gcalctool-newui2] ...
- Date: Mon, 6 Jul 2009 13:36:18 +0000 (UTC)
commit 9af5170b206c95ac9f5292f35bf8bee9446b7520
Author: Robert Ancell <robert ancell gmail com>
Date: Mon Jul 6 00:31:15 2009 +1000
...
data/gcalctool.ui | 42 +++++++++---------
src/calctool.c | 18 ++++++++-
src/calctool.h | 1 +
src/gtk.c | 105 ++++++++++++++++++----------------------------
src/mp-convert.c | 59 ++++++++++++++++++++------
src/mp-equation-lexer.l | 22 ++++++++--
src/mp-equation.c | 7 +++
src/unittest.c | 13 +++++-
8 files changed, 161 insertions(+), 106 deletions(-)
---
diff --git a/data/gcalctool.ui b/data/gcalctool.ui
index c6438d6..6754fbe 100644
--- a/data/gcalctool.ui
+++ b/data/gcalctool.ui
@@ -2126,7 +2126,7 @@
<property name="n_columns">5</property>
<child>
<object class="GtkButton" id="calc_4_button">
- <property name="label" translatable="yes" comments="Numeric 4 button">4</property>
+ <property name="label">4</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2149,7 +2149,7 @@
</child>
<child>
<object class="GtkButton" id="calc_7_button">
- <property name="label" translatable="yes" comments="Numeric 7 button">7</property>
+ <property name="label">7</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2170,7 +2170,7 @@
</child>
<child>
<object class="GtkButton" id="calc_8_button">
- <property name="label" translatable="yes" comments="Numeric 8 button">8</property>
+ <property name="label">8</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2193,7 +2193,7 @@
</child>
<child>
<object class="GtkButton" id="calc_9_button">
- <property name="label" translatable="yes" comments="Numeric 9 button">9</property>
+ <property name="label">9</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2216,7 +2216,7 @@
</child>
<child>
<object class="GtkButton" id="calc_5_button">
- <property name="label" translatable="yes" comments="Numeric 5 button">5</property>
+ <property name="label">5</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2241,7 +2241,7 @@
</child>
<child>
<object class="GtkButton" id="calc_6_button">
- <property name="label" translatable="yes" comments="Numeric 6 button">6</property>
+ <property name="label">6</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2290,7 +2290,7 @@
</child>
<child>
<object class="GtkButton" id="calc_1_button">
- <property name="label" translatable="yes" comments="Numeric 1 button">1</property>
+ <property name="label">1</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2338,7 +2338,7 @@
</child>
<child>
<object class="GtkButton" id="calc_0_button">
- <property name="label" translatable="yes" comments="Numeric 0 button">0</property>
+ <property name="label">0</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -2413,7 +2413,7 @@
</child>
<child>
<object class="GtkButton" id="calc_3_button">
- <property name="label" translatable="yes" comments="Numeric 3 button">3</property>
+ <property name="label">3</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
@@ -3172,8 +3172,8 @@
<property name="n_rows">2</property>
<property name="n_columns">10</property>
<child>
- <object class="GtkButton" id="calc_d_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit D button">D</property>
+ <object class="GtkButton" id="calc_13_button">
+ <property name="label">D</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -3188,8 +3188,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_e_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit E button">E</property>
+ <object class="GtkButton" id="calc_14_button">
+ <property name="label">E</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -3206,8 +3206,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_f_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit F button">F</property>
+ <object class="GtkButton" id="calc_15_button">
+ <property name="label">F</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -3224,8 +3224,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_a_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit A button">A</property>
+ <object class="GtkButton" id="calc_10_button">
+ <property name="label">A</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -3242,8 +3242,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_b_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit B button">B</property>
+ <object class="GtkButton" id="calc_11_button">
+ <property name="label">B</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
@@ -3262,8 +3262,8 @@
</packing>
</child>
<child>
- <object class="GtkButton" id="calc_c_button">
- <property name="label" translatable="yes" comments="Hexadecimal digit C button">C</property>
+ <object class="GtkButton" id="calc_12_button">
+ <property name="label">C</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
diff --git a/src/calctool.c b/src/calctool.c
index 1927a01..27a47fa 100644
--- a/src/calctool.c
+++ b/src/calctool.c
@@ -199,11 +199,27 @@ static void
init_state(void)
{
int acc, i;
+ /* Translators: Digits localized for the given language */
+ const char *digit_values = _("0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F");
+ const char *default_digits[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"};
+ gchar **digits;
+ gboolean use_default_digits = FALSE;
acc = MAX_DIGITS + 12; /* MP internal accuracy. */
mp_init(acc);
- v->error = FALSE; /* No calculator error initially. */
+ v->error = FALSE; /* No calculator error initially. */
+
+ digits = g_strsplit(digit_values, ",", -1);
+ for (i = 0; i < 16; i++) {
+ if (use_default_digits || digits[i] == NULL) {
+ use_default_digits = TRUE;
+ v->digits[i] = strdup(default_digits[i]);
+ }
+ else
+ v->digits[i] = strdup(digits[i]);
+ }
+ g_strfreev(digits);
v->radix = get_radix(); /* Locale specific radix string. */
v->tsep = get_tsep(); /* Locale specific thousands separator. */
v->tsep_count = get_tsep_count();
diff --git a/src/calctool.h b/src/calctool.h
index 4b4a615..db6954a 100644
--- a/src/calctool.h
+++ b/src/calctool.h
@@ -63,6 +63,7 @@ typedef struct {
GCDisplay display; /* Display stack */
+ const char *digits[16]; /* Localized digit values */
const char *radix; /* Locale specific radix string. */
const char *tsep; /* Locale specific thousands separator. */
int tsep_count; /* Number of digits between separator. */
diff --git a/src/gtk.c b/src/gtk.c
index d1d390e..ed03167 100644
--- a/src/gtk.c
+++ b/src/gtk.c
@@ -54,22 +54,6 @@ typedef struct {
} ButtonData;
static ButtonData button_data[] = {
- {"0", "0"},
- {"1", "1"},
- {"2", "2"},
- {"3", "3"},
- {"4", "4"},
- {"5", "5"},
- {"6", "6"},
- {"7", "7"},
- {"8", "8"},
- {"9", "9"},
- {"a", "A"},
- {"b", "B"},
- {"c", "C"},
- {"d", "D"},
- {"e", "E"},
- {"f", "F"},
{"pi", "Ï?"},
{"eulers_number", "e"},
{"random", "rand"},
@@ -268,7 +252,7 @@ static void set_data(GtkBuilder *ui, const gchar *object_name, const gchar *name
static void set_string_data(GtkBuilder *ui, const gchar *object_name, const gchar *name, const char *value)
{
- g_object_set_data(gtk_builder_get_object(ui, object_name), name, (gpointer)value);
+ g_object_set_data(gtk_builder_get_object(ui, object_name), name, (gpointer)value); // FIXME: Copy?
}
static void set_int_data(GtkBuilder *ui, const gchar *object_name, const gchar *name, gint value)
@@ -1354,8 +1338,9 @@ G_MODULE_EXPORT
gboolean
main_window_key_press_cb(GtkWidget *widget, GdkEventKey *event)
{
- int state;
- const char *c, *allowed_input = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+-*/^|!%¬~ \t\n=<>.,()";
+ int i, state;
+ const char *conversions[] = {"-", "*", "/", "\t", NULL};
+ const char *conversion_values[] = {"â??", "Ã?", "÷", " ", };
/* Only look at the modifiers we use */
state = event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK);
@@ -1457,45 +1442,32 @@ main_window_key_press_cb(GtkWidget *widget, GdkEventKey *event)
if (state != 0)
return FALSE;
-
- for (c = allowed_input; *c; c++) {
+
+ for (i = 0; conversions[i]; i++) {
// FIXME: event->string deprecated
- if (strncmp(event->string, c, 1) == 0) {
- switch(*c)
- {
- case ',':
- do_text(",");
- return TRUE;
- case '-':
- do_text("â??");
- return TRUE;
- case '*':
- do_text("Ã?");
- return TRUE;
- case '/':
- do_text("÷");
- return TRUE;
- case '\t':
- do_text(" ");
- return TRUE;
- case '<':
- button_cb(GET_WIDGET("calc_shift_left_button"), NULL);
- return TRUE;
- case '>':
- button_cb(GET_WIDGET("calc_shift_right_button"), NULL);
- return TRUE;
- case '=':
- case '\n':
- do_button(FN_CALCULATE, 0);
- return TRUE;
- default:
- do_text(event->string);
- return TRUE;
- }
+ if (strncmp(event->string, conversions[i], strlen(conversions[i])) == 0) {
+ do_text(conversion_values[i]);
+ return TRUE;
}
}
- return FALSE;
+ // FIXME: event->string deprecated
+ switch(*event->string)
+ {
+ case '<':
+ button_cb(GET_WIDGET("calc_shift_left_button"), NULL);
+ return TRUE;
+ case '>':
+ button_cb(GET_WIDGET("calc_shift_right_button"), NULL);
+ return TRUE;
+ case '=':
+ case '\n':
+ do_button(FN_CALCULATE, 0);
+ return TRUE;
+ default:
+ do_text(event->string); // FIXME: Only if printable
+ return TRUE;
+ }
}
@@ -1742,7 +1714,15 @@ create_main_window()
SNPRINTF(name, MAXLINE, "calc_%s_button", button_data[i].widget_name);
set_string_data(X.ui, name, "calc_text", button_data[i].data);
}
-
+
+ /* Localize buttons */
+ for (i = 0; i < 16; i++) {
+ SNPRINTF(name, MAXLINE, "calc_%d_button", i);
+ gtk_button_set_label(GTK_BUTTON(GET_OBJECT(name)), v->digits[i]);
+ set_string_data(X.ui, name, "calc_text", v->digits[i]);
+ }
+ gtk_button_set_label(GTK_BUTTON(GET_OBJECT("calc_numeric_point_button")), v->radix);
+
/* Connect super and subscript */
for (i = 0; i < 10; i++) {
static const char *subscript_digits[] = {"â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??", "â??"};
@@ -1840,9 +1820,6 @@ create_main_window()
set_int_data(X.ui, "view_scientific_menu", "calcmode", SCIENTIFIC);
set_int_data(X.ui, "view_programming_menu", "calcmode", PROGRAMMING);
- /* Localize label for numeric point */
- gtk_button_set_label(GTK_BUTTON(GET_OBJECT("calc_numeric_point_button")), v->radix);
-
/* Setup financial functions */
set_data(X.ui, "calc_finc_compounding_term_button", "finc_dialog", "ctrm_dialog");
set_data(X.ui, "calc_finc_double_declining_depreciation_button", "finc_dialog", "ddb_dialog");
@@ -1963,12 +1940,12 @@ add_buttons_to_size_group()
"calc_start_group_button",
"calc_end_group_button",
"calc_percentage_button",
- "calc_d_button",
- "calc_e_button",
- "calc_f_button",
- "calc_a_button",
- "calc_b_button",
- "calc_c_button",
+ "calc_10_button",
+ "calc_11_button",
+ "calc_12_button",
+ "calc_13_button",
+ "calc_14_button",
+ "calc_15_button",
"calc_and_button",
"calc_or_button",
"calc_not_button",
diff --git a/src/mp-convert.c b/src/mp-convert.c
index 7c885ea..d9da4e7 100644
--- a/src/mp-convert.c
+++ b/src/mp-convert.c
@@ -572,20 +572,55 @@ mp_cast_to_string(const MPNumber *x, int base, int accuracy, int trim_zeroes, ch
static int
-char_val(char chr, int base)
+char_val(char **c, int base)
{
- int value;
- if (chr >= '0' && chr <= '9') {
- value = chr - '0';
- } else if (chr >= 'a' && chr <= 'f') {
- value = chr - 'a' + 10;
- } else if (chr >= 'A' && chr <= 'F') {
- value = chr - 'A' + 10;
+ int i, j, value;
+ //á? á?¡á?¢á?£á?¤á?¥á?¦á?§á?¨á?©á ?á ?á ?á ?á ?á ?á ?á ?á ?á ?á¥?á¥?á¥?á¥?á¥?á¥?á¥?á¥?á¥?á¥?á§?á§?á§?á§?á§?á§?á§?á§?á§?á§?á?á?á?á?á?á?á?á?á?á?᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?á±?ê? ê?¡ê?¢ê?£ê?¤ê?¥ê?¦ê?§ê?¨ê?©ê£?ê£?ê£?ê£?ê£?ê£?ê£?ê£?ê£?ê£?ê¤?ê¤?ê¤?ê¤?ê¤?ê¤?ê¤?ê¤?ê¤?ê¤?ê©?ê©?ê©?ê©?ê©?ê©?ê©?ê©?ê©?ê©?ð?? ð??¡ð??¢ð??£ð??¤ð??¥ð??¦ð??§ð??¨ð??©
+ const char *digits[][10] = {{"Ù ", "Ù¡", "Ù¢", "Ù£", "Ù¤", "Ù¥", "Ù¦", "Ù§", "Ù¨", "Ù©"},
+ {"Û°", "Û±", "Û²", "Û³", "Û´", "Ûµ", "Û¶", "Û·", "Û¸", "Û¹"},
+ {"ß?", "ß?", "ß?", "ß?", "ß?", "ß?", "ß?", "ß?", "ß?", "ß?"},
+ {"०", "१", "२", "३", "४", "५", "६", "à¥", "८", "९"},
+ {"০", "১", "২", "৩", "৪", "৫", "৬", "à§", "৮", "৯"},
+ {"੦", "੧", "੨", "à©©", "੪", "à©«", "੬", "à©", "à©®", "੯"},
+ {"૦", "૧", "૨", "à«©", "૪", "à««", "૬", "à«", "à«®", "૯"},
+ {"à¦", "à§", "à¨", "à©", "àª", "à«", "à¬", "à", "à®", "à¯"},
+ {"௦", "௧", "௨", "௩", "௪", "௫", "௬", "à¯", "௮", "௯"},
+ {"౦", "౧", "౨", "౩", "౪", "౫", "౬", "à±", "à±®", "౯"},
+ {"೦", "೧", "೨", "೩", "೪", "೫", "೬", "à³", "à³®", "೯"},
+ {"൦", "൧", "൨", "൩", "൪", "൫", "൬", "àµ", "൮", "൯"},
+ {"�", "�", "�", "�", "�", "�", "�", "�", "�", "�"},
+ {"à»?", "à»?", "à»?", "à»?", "à»?", "à»?", "à»?", "à»?", "à»?", "à»?"},
+ {"༠", "༡", "༢", "༣", "༤", "༥", "༦", "༧", "༨", "༩"},
+ {"á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??"},
+ {"á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??", "á??"},
+ {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}};
+
+ if (**c >= '0' && **c <= '9') {
+ value = **c - '0';
+ (*c)++;
+ } else if (**c >= 'a' && **c <= 'f') {
+ value = **c - 'a' + 10;
+ (*c)++;
+ } else if (**c >= 'A' && **c <= 'F') {
+ value = **c - 'A' + 10;
+ (*c)++;
} else {
- return -1;
+ for (i = 0; digits[i][0]; i++) {
+ for (j = 0; j < 10; j++) {
+ if (strncmp(*c, digits[i][j], strlen(digits[i][j])) == 0)
+ break;
+ }
+ if (j != 10)
+ break;
+ }
+ if (digits[i][0] == NULL)
+ return -1;
+ value = j;
+ *c += strlen(digits[i][j]);
}
if (value >= base)
return -1;
+
return value;
}
@@ -632,10 +667,9 @@ mp_set_from_string(const char *str, MPNumber *z)
/* Convert integer part */
mp_set_from_integer(0, z);
- while ((i = char_val(*c, base)) >= 0) {
+ while ((i = char_val((char **)&c, base)) >= 0) {
mp_multiply_integer(z, base, z);
mp_add_integer(z, i, z);
- c++;
}
/* Look for fraction characters */
@@ -672,11 +706,10 @@ mp_set_from_string(const char *str, MPNumber *z)
mp_set_from_integer(0, &numerator);
mp_set_from_integer(1, &denominator);
- while ((i = char_val(*c, base)) >= 0) {
+ while ((i = char_val((char **)&c, base)) >= 0) {
mp_multiply_integer(&denominator, base, &denominator);
mp_multiply_integer(&numerator, base, &numerator);
mp_add_integer(&numerator, i, &numerator);
- c++;
}
mp_divide(&numerator, &denominator, &numerator);
mp_add(z, &numerator, z);
diff --git a/src/mp-equation-lexer.l b/src/mp-equation-lexer.l
index 0fd19fb..081c12a 100644
--- a/src/mp-equation-lexer.l
+++ b/src/mp-equation-lexer.l
@@ -67,13 +67,24 @@ static int sub_atoi(const char *data)
}
%}
+
+ZERO "0"|"Ù "|"Û°"|"ß?"|"०"|"০"|"੦"|"૦"|"à¦"|"௦"|"౦"|"೦"|"൦"|"à¹?"|"à»?"|"༠"|"á??"|"á??"|"á? "|"á ?"|"á¥?"|"á§?"|"á?"|"á®°"|"á±?"|"á±?"|"ê? "|"ê£?"|"ê¤?"|"ê©?"|"ð?? "
+ONE "1"|"Ù¡"|"Û±"|"ß?"|"१"|"১"|"੧"|"૧"|"à§"|"௧"|"౧"|"೧"|"൧"|"à¹?"|"à»?"|"༡"|"á??"|"á??"|"á?¡"|"á ?"|"á¥?"|"á§?"|"á?"|"á®±"|"á±?"|"á±?"|"ê?¡"|"ê£?"|"ê¤?"|"ê©?"|"ð??¡"
+TWO "2"|"Ù¢"|"Û²"|"ß?"|"२"|"২"|"੨"|"૨"|"à¨"|"௨"|"౨"|"೨"|"൨"|"à¹?"|"à»?"|"༢"|"á??"|"á??"|"á?¢"|"á ?"|"á¥?"|"á§?"|"á?"|"᮲"|"á±?"|"á±?"|"ê?¢"|"ê£?"|"ê¤?"|"ê©?"|"ð??¢"
+THREE "3"|"Ù£"|"Û³"|"ß?"|"३"|"৩"|"à©©"|"à«©"|"à©"|"௩"|"౩"|"೩"|"൩"|"à¹?"|"à»?"|"༣"|"á??"|"á??"|"á?£"|"á ?"|"á¥?"|"á§?"|"á?"|"᮳"|"á±?"|"á±?"|"ê?£"|"ê£?"|"ê¤?"|"ê©?"|"ð??£"
+FOUR "4"|"Ù¤"|"Û´"|"ß?"|"४"|"৪"|"੪"|"૪"|"àª"|"௪"|"౪"|"೪"|"൪"|"à¹?"|"à»?"|"༤"|"á??"|"á??"|"á?¤"|"á ?"|"á¥?"|"á§?"|"á?"|"á®´"|"á±?"|"á±?"|"ê?¤"|"ê£?"|"ê¤?"|"ê©?"|"ð??¤"
+FIVE "5"|"Ù¥"|"Ûµ"|"ß?"|"५"|"৫"|"à©«"|"à««"|"à«"|"௫"|"౫"|"೫"|"൫"|"à¹?"|"à»?"|"༥"|"á??"|"á??"|"á?¥"|"á ?"|"á¥?"|"á§?"|"á?"|"᮵"|"á±?"|"á±?"|"ê?¥"|"ê£?"|"ê¤?"|"ê©?"|"ð??¥"
+SIX "6"|"Ù¦"|"Û¶"|"ß?"|"६"|"৬"|"੬"|"૬"|"à¬"|"௬"|"౬"|"೬"|"൬"|"à¹?"|"à»?"|"༦"|"á??"|"á??"|"á?¦"|"á ?"|"á¥?"|"á§?"|"á?"|"᮶"|"á±?"|"á±?"|"ê?¦"|"ê£?"|"ê¤?"|"ê©?"|"ð??¦"
+SEVEN "7"|"Ù§"|"Û·"|"ß?"|"à¥"|"à§"|"à©"|"à«"|"à"|"à¯"|"à±"|"à³"|"àµ"|"à¹?"|"à»?"|"༧"|"á??"|"á??"|"á?§"|"á ?"|"á¥?"|"á§?"|"á?"|"á®·"|"á±?"|"á±?"|"ê?§"|"ê£?"|"ê¤?"|"ê©?"|"ð??§"
+EIGHT "8"|"Ù¨"|"Û¸"|"ß?"|"८"|"৮"|"à©®"|"à«®"|"à®"|"௮"|"à±®"|"à³®"|"൮"|"à¹?"|"à»?"|"༨"|"á??"|"á??"|"á?¨"|"á ?"|"á¥?"|"á§?"|"á?"|"᮸"|"á±?"|"á±?"|"ê?¨"|"ê£?"|"ê¤?"|"ê©?"|"ð??¨"
+NINE "9"|"Ù©"|"Û¹"|"ß?"|"९"|"৯"|"੯"|"૯"|"à¯"|"௯"|"౯"|"೯"|"൯"|"à¹?"|"à»?"|"༩"|"á??"|"á??"|"á?©"|"á ?"|"á¥?"|"á§?"|"á?"|"᮹"|"á±?"|"á±?"|"ê?©"|"ê£?"|"ê¤?"|"ê©?"|"ð??©"
DECIMAL "."|","
-BIN [0-1]
+BIN {ZERO}|{ONE}
BIN_SUFFIX "â??"
-OCT [0-7]
+OCT {ZERO}|{ONE}|{TWO}|{THREE}|{FOUR}|{FIVE}|{SIX}|{SEVEN}
OCT_SUFFIX "â??"
-DEC [0-9]
-HEX [0-9]|[A-F]|[a-f]
+DEC {ZERO}|{ONE}|{TWO}|{THREE}|{FOUR}|{FIVE}|{SIX}|{SEVEN}|{EIGHT}|{NINE}
+HEX {DEC}|[A-F]|[a-f]
HEX_SUFFIX "â??â??"
SI_SUFFIX "T"|"G"|"M"|"k"|"d"|"c"|"m"|"u"|"µ"|"n"|"p"|"f"
SUPER_DIGITS "�"|"¹"|"²"|"³"|"�"|"�"|"�"|"�"|"�"|"�"
@@ -89,7 +100,8 @@ BIN_NUM {BIN}+{BIN_SUFFIX}|{BIN}*{DECIMAL}{BIN}+{BIN_SUFFIX}
SUP_NUM {SUPER_DIGITS}+
SUB_NUM {SUB_DIGITS}+
NUMBER {BIN_NUM}|{OCT_NUM}|{DEC_NUM}|{HEX_NUM}
-VARIABLE {VARIABLE_C}+|"Ï?"|{VARIABLE_C}+{INVERSE}|{VARIABLE_C}+{SUB_NUM}
+GREEKS "α"|"β"|"γ"|"δ"|"ε"|"ζ"|"η"|"θ"|"ι"|"κ"|"λ"|"μ"|"ν"|"ξ"|"ο"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"|"Ï?"
+VARIABLE {VARIABLE_C}+|{GREEKS}|{VARIABLE_C}+{INVERSE}|{VARIABLE_C}+{SUB_NUM}
MOD [mM][oO][dD]
AND "â?§"|[aA][nN][dD]
diff --git a/src/mp-equation.c b/src/mp-equation.c
index dedfe38..c597a1d 100644
--- a/src/mp-equation.c
+++ b/src/mp-equation.c
@@ -44,6 +44,11 @@ get_variable(MPEquationParserState *state, const char *name, MPNumber *z)
mp_set_from_integer(0, z); // FIXME
}
+// FIXME: Accept "2sin" not "2 sin", i.e. let the tokenizer collect the multiple
+// Parser then distinguishes between "sin"="s*i*n" or "sin5" = "sin 5" = "sin(5)"
+// i.e. numbers+letters = variable or function depending on following arg
+// letters+numbers = numbers+letters+numbers = function
+
static void
get_function(MPEquationParserState *state, const char *name, const MPNumber *x, MPNumber *z)
@@ -54,6 +59,8 @@ get_function(MPEquationParserState *state, const char *name, const MPNumber *x,
for (c = lower_name; *c; c++)
*c = tolower(*c);
+ // FIXME: Re Im ?
+
if (strcmp(lower_name, "log") == 0)
mp_logarithm(10, x, z);
else if (strcmp(lower_name, "ln") == 0)
diff --git a/src/unittest.c b/src/unittest.c
index c6ff1e8..dc2e05c 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -144,6 +144,12 @@ test_parser()
test("2Ï?", "6.283185307", 0);
test("e", "2.718281828", 0);
test("2e", "5.436563657", 0);
+ test("Ï?e", "1", 0);
+ test("eÏ?", "1", 0);
+ test("2Ï?e", "1", 0);
+
+ test("١٢٣٤٥٦٧٨٩٠", "1234567890", 0);
+ test("Û±Û²Û³Û´ÛµÛ¶Û·Û¸Û¹Û°", "1234567890", 0);
test("0+0", "0", 0);
test("1+1", "2", 0);
@@ -220,6 +226,7 @@ test_parser()
test("4^3^2", "262144", 0);
test("4^(3^2)", "262144", 0);
test("(4^3)^2", "4096", 0);
+ //test("e^(iÏ?)", "1", 0);
test("â??4", "2", 0);
test("â??4â??2", "0", 0);
test("â??8", "2", 0);
@@ -250,8 +257,10 @@ test_parser()
test("|1|", "1", 0);
test("|â??1|", "1", 0);
test("|3â??5|", "2", 0);
- test("Abs(1)", "1", 0);
- test("Abs(â??1)", "1", 0);
+ test("|e|", "2.718281828", 0);
+ test("|Ï?|", "3.141592654", 0);
+ test("abs 1", "1", 0);
+ test("abs â??1", "1", 0);
test("log â??1", "", -20001);
test("log 0", "", -20001);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]