gcalctool r2086 - in trunk: . gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2086 - in trunk: . gcalctool
- Date: Tue, 29 Apr 2008 11:26:27 +0100 (BST)
Author: rancell
Date: Tue Apr 29 10:26:27 2008
New Revision: 2086
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2086&view=rev
Log:
Restructure display.[ch] to have consistent function names and work towards routing all display code through one point to support Unicode more easily (Bug #530532).
Modified:
trunk/ChangeLog
trunk/gcalctool/calctool.c
trunk/gcalctool/calctool.h
trunk/gcalctool/ce_parser.h
trunk/gcalctool/ce_parser.y
trunk/gcalctool/display.c
trunk/gcalctool/display.h
trunk/gcalctool/functions.c
trunk/gcalctool/functions.h
trunk/gcalctool/gtk.c
trunk/gcalctool/lr_parser.h
trunk/gcalctool/lr_parser.y
trunk/gcalctool/mp.c
trunk/gcalctool/unittest.c
Modified: trunk/gcalctool/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Tue Apr 29 10:26:27 2008
@@ -545,10 +545,8 @@
{
switch (v->syntax) {
case NPA:
- strncpy(v->display, errmes, MAXLINE - 1);
- v->display[MAXLINE - 1] = '\0';
ui_set_error_state(TRUE);
- ui_set_display(v->display, -1);
+ display_set_string(errmes);
ui_beep();
break;
@@ -620,7 +618,7 @@
* the second is the program version number.
*/
FPRINTF(stderr, _("%s version %s\n\n"), progname, VERSION);
- FPRINTF(stderr, _("Usage: %s: [-D] [-E] [-u] [-a accuracy] "), progname);
+ FPRINTF(stderr, _("Usage: %s: [-E] [-u] [-a accuracy] "), progname);
FPRINTF(stderr, _("\t\t [-?] [-v] [-h]\n"));
exit(1);
}
@@ -636,10 +634,6 @@
while (argc > 0) {
if (argv[0][0] == '-') {
switch (argv[0][1]) {
- case 'D' : /* MP debug info. to stderr. */
- v->MPdebug = TRUE;
- break;
-
case 'E' : /* MP errors to stderr. */
v->MPerrors = TRUE;
break;
@@ -695,19 +689,16 @@
v->dtype = FIX; /* Initial number display mode. */
v->ttype = DEG; /* Initial trigonometric type. */
v->modetype = BASIC; /* Initial calculator mode. */
- v->MPdebug = FALSE; /* No debug info by default. */
v->MPerrors = FALSE; /* No error information. */
acc = MAX_DIGITS + 12; /* MP internal accuracy. */
size = MP_SIZE;
mpset(&acc, &size, &size);
- v->error = 0; /* No calculator error initially. */
- v->key_exp = 0; /* Not entering an exponent number. */
-
+ v->error = 0; /* No calculator error initially. */
v->current = KEY_CALCULATE;
- v->shelf = NULL; /* No selection for shelf initially. */
- v->noparens = 0; /* No unmatched brackets initially. */
- v->numsptr = 0; /* Nothing on the parenthese numeric stack. */
+
+ v->ltr.key_exp = 0; /* Not entering an exponent number. */
+ v->ltr.noparens = 0; /* No unmatched brackets initially. */
init_constant(0, "0.621"); /* kms/hr <=> miles/hr. */
init_constant(1, "1.4142135623"); /* square root of 2 */
@@ -766,7 +757,7 @@
do_clear(); /* Initialise and clear display. */
- show_display(v->MPdisp_val); /* Output in correct display mode. */
+ display_set_number(v->MPdisp_val); /* Output in correct display mode. */
memset(&(v->h), 0, sizeof(struct exprm_state_history)); /* clear expression mode state history*/
e = get_state();
Modified: trunk/gcalctool/calctool.h
==============================================================================
--- trunk/gcalctool/calctool.h (original)
+++ trunk/gcalctool/calctool.h Tue Apr 29 10:26:27 2008
@@ -195,6 +195,18 @@
struct exprm_state e[UNDO_HISTORY_LENGTH]; /* Expression mode state */
};
+struct ltrCalcVars {
+ int new_input; /* New number input since last op. */
+ int noparens; /* Count of left brackets still to be matched. */
+ int pointed; /* Whether a decimal point has been given. */
+
+ int cur_op; /* Current arithmetic operation. */
+ int key_exp; /* Set if entering exponent number. */
+ int old_cal_value; /* Previous calculation operator. */
+ int toclear; /* Indicates if display should be cleared. */
+ char *exp_posn; /* Position of the exponent sign. */
+};
+
struct calcVars { /* Calctool variables and options. */
struct exprm_state_history h; /* History of expression mode states */
@@ -205,11 +217,7 @@
char *progname; /* Name of this program. */
char display[MAXLINE]; /* Current calculator display. */
- char *exp_posn; /* Position of the exponent sign. */
- char fnum[MAX_LOCALIZED]; /* Scratchpad for fixed numbers. */
const char *radix; /* Locale specific radix string. */
- char *shelf; /* PUT selection shelf contents. */
- char snum[MAX_LOCALIZED]; /* Scratchpad for scientific numbers. */
const char *tsep; /* Locale specific thousands separator. */
int tsep_count; /* Number of digits between separator. */
@@ -218,15 +226,11 @@
char con_names[MAX_CONSTANTS][MAXLINE]; /* Selectable constant names. */
int MPcon_vals[MAX_CONSTANTS][MP_SIZE]; /* Selectable constants. */
- int MPdebug; /* If set, debug info. to stderr. */
int MPerrors; /* If set, output errors to stderr. */
int MPdisp_val[MP_SIZE]; /* Value of the current display. */
- int MPexpr_val[MP_SIZE]; /* Value of the current expression. */
int MPlast_input[MP_SIZE]; /* Previous number input by user. */
int MPmvals[MAX_REGISTERS][MP_SIZE]; /* Memory register values. */
int MPresult[MP_SIZE]; /* Current calculator total value. */
- int MPimresult[MP_SIZE]; /* Current intermediate result. */
- int MPtresults[3][MP_SIZE]; /* Current trigonometric results. */
enum base_type base; /* Current base: BIN, OCT, DEC or HEX. */
enum mode_type modetype; /* Current calculator mode. */
@@ -236,25 +240,21 @@
enum syntax syntax; /* Calculation syntax mode */
int accuracy; /* Number of digits precision (Max 9). */
- int cur_op; /* Current arithmetic operation. */
+
int error; /* Indicates some kind of display error. */
int math_error; /* Math error (used in expression mode) */
- int key_exp; /* Set if entering exponent number. */
- int new_input; /* New number input since last op. */
- int noparens; /* Count of left brackets still to be matched. */
- int numsptr; /* Pointer into the parenthese numeric stack. */
- int old_cal_value; /* Previous calculation operator. */
- int pointed; /* Whether a decimal point has been given. */
int show_tsep; /* Set if the thousands separator should be shown. */
int show_zeroes; /* Set if trailing zeroes should be shown. */
- int toclear; /* Indicates if display should be cleared. */
+
+ /* Legacy left to right mode variables */
+ struct ltrCalcVars ltr;
};
typedef struct calcVars *Vars;
-extern Vars v; /* Calctool variables and options. */
-extern int basevals[]; /* Supported arithmetic bases. */
-extern struct button buttons[]; /* Calculator button values. */
+extern Vars v; /* Calctool variables and options. */
+extern int basevals[]; /* Supported arithmetic bases. */
+extern struct button buttons[]; /* Calculator button values. */
void doerr(char *);
Modified: trunk/gcalctool/ce_parser.h
==============================================================================
--- trunk/gcalctool/ce_parser.h (original)
+++ trunk/gcalctool/ce_parser.h Tue Apr 29 10:26:27 2008
@@ -36,6 +36,7 @@
extern struct parser_state parser_state;
+int celex();
int ceerror(); /* dummy definition TODO: this is a douple */
int ceparse(); /* dummy definition. */
int ceerror(char *s);
Modified: trunk/gcalctool/ce_parser.y
==============================================================================
--- trunk/gcalctool/ce_parser.y (original)
+++ trunk/gcalctool/ce_parser.y Tue Apr 29 10:26:27 2008
@@ -32,8 +32,6 @@
#include "parser_mac.h"
#include "ce_parser.h"
- extern struct parser_state parser_state;
-
%}
%union {
@@ -126,7 +124,7 @@
udf:
value '=' {
cp($1, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
| value '=' tSTO '(' tNUMBER ')' {
int val;
@@ -139,8 +137,8 @@
do_sto_reg(val, $1);
}
| tCLR {
- initialise();
- show_display(v->MPdisp_val);
+ display_reset();
+ display_set_number(v->MPdisp_val);
}
;
Modified: trunk/gcalctool/display.c
==============================================================================
--- trunk/gcalctool/display.c (original)
+++ trunk/gcalctool/display.c Tue Apr 29 10:26:27 2008
@@ -39,8 +39,6 @@
2.582249878e+120 /* Hexadecimal. */
};
-static char *make_eng_sci(int *, int);
-
/* Add in the thousand separators characters if required and if we are
* currently in the decimal numeric base, use the "right" radix character.
*/
@@ -133,36 +131,32 @@
void
-clear_display(int initialise)
+display_clear(int initialise)
{
- v->pointed = 0;
- v->toclear = 1;
+ v->ltr.pointed = 0;
+ v->ltr.toclear = 1;
do_zero(v->MPdisp_val);
- STRNCPY(v->display, make_number(v->MPdisp_val, v->base, FALSE),
- MAXLINE - 1);
- ui_set_display(v->display, -1);
+ display_set_number(v->MPdisp_val);
if (initialise == TRUE) {
- v->numsptr = 0;
- v->noparens = 0;
+ v->ltr.noparens = 0;
ui_set_hyperbolic_state(FALSE); /* Also clears v->hyperbolic. */
ui_set_inverse_state(FALSE); /* Also clears v->inverse. */
}
}
-/* TODO: perhaps this function should be renamed to reset. */
void
-initialise()
+display_reset()
{
- v->error = 0; /* Currently no display error. */
- v->cur_op = -1; /* No arithmetic operator defined yet. */
- v->old_cal_value = -1;
- do_zero(v->MPresult); /* No previous result yet. */
+ v->error = 0; /* Currently no display error. */
+ v->ltr.cur_op = -1; /* No arithmetic operator defined yet. */
+ v->ltr.old_cal_value = -1;
+ do_zero(v->MPresult); /* No previous result yet. */
do_zero(v->MPdisp_val);
do_zero(v->MPlast_input);
- v->new_input = 1; /* Value zero is on calculator display */
+ v->ltr.new_input = 1; /* Value zero is on calculator display */
exp_clear();
}
@@ -172,8 +166,8 @@
* maximum number of digits specified.
*/
-char *
-make_fixed(int *MPnumber, char *str, int base, int cmax, int toclear)
+void
+make_fixed(char *target, int target_len, int *MPnumber, int base, int cmax, int toclear)
{
char half[MAXLINE], *optr;
int MP1base[MP_SIZE], MP1[MP_SIZE], MP2[MP_SIZE], MPval[MP_SIZE];
@@ -181,7 +175,7 @@
int ddig; /* Number of digits to left of decimal sep. */
int dval, n, i;
- optr = str;
+ optr = target;
mpabs(MPnumber, MPval);
do_zero(MP1);
if (mplt(MPnumber, MP1)) {
@@ -229,60 +223,28 @@
}
*optr++ = '\0';
if (toclear == TRUE) {
- v->toclear = 1;
+ v->ltr.toclear = 1;
}
- v->pointed = 0;
+ v->ltr.pointed = 0;
/* Strip off trailing zeroes */
if (!v->show_zeroes) {
- for (i = strlen(str) - 1; i > 1 && str[i] == '0'; i--) {
- str[i] = '\0';
+ for (i = strlen(target) - 1; i > 1 && target[i] == '0'; i--) {
+ target[i] = '\0';
}
/* If no fractional part discard radix */
- if (strlen(str) >= strlen(v->radix) && strcmp(str + strlen(str) - strlen(v->radix), v->radix) == 0) {
- str[strlen(str) - strlen(v->radix)] = '\0';
+ if (strlen(target) >= strlen(v->radix) && strcmp(target + strlen(target) - strlen(v->radix), v->radix) == 0) {
+ target[strlen(target) - strlen(v->radix)] = '\0';
}
}
-
- return(str);
-}
-
-
-/* Convert MP number to character string in the given base. */
-
-char *
-make_number(int *MPnumber, int base, int ignoreError)
-{
- double number, val;
-
-/* NOTE: make_number can currently set v->error when converting to a double.
- * This is to provide the same look&feel as V3 even though gcalctool
- * now does internal arithmetic to "infinite" precision.
- *
- * XXX: Needs to be improved. Shouldn't need to convert to a double in
- * order to do these tests.
- */
-
- mpcmd(MPnumber, &number);
- val = fabs(number);
- if (v->error && !ignoreError) {
- return(_("Error"));
- }
- if ((v->dtype == ENG) ||
- (v->dtype == SCI) ||
- (v->dtype == FIX && val != 0.0 && (val > max_fix[base]))) {
- return(make_eng_sci(MPnumber, base));
- } else {
- return(make_fixed(MPnumber, v->fnum, base, MAX_DIGITS, TRUE));
- }
}
/* Convert engineering or scientific number in the given base. */
-static char *
-make_eng_sci(int *MPnumber, int base)
+void
+make_eng_sci(char *target, int target_len, int *MPnumber, int base)
{
char half[MAXLINE], fixed[MAX_DIGITS], *optr;
int MP1[MP_SIZE], MPatmp[MP_SIZE], MPval[MP_SIZE];
@@ -296,7 +258,7 @@
if (v->dtype == ENG) {
eng = 1;
}
- optr = v->snum;
+ optr = target;
mpabs(MPnumber, MPval);
do_zero(MP1);
if (mplt(MPnumber, MP1)) {
@@ -341,7 +303,7 @@
}
}
- STRNCPY(fixed, make_fixed(MPmant, v->fnum, base, MAX_DIGITS-6, TRUE), MAX_DIGITS - 1);
+ make_fixed(fixed, MAX_DIGITS, MPmant, base, MAX_DIGITS-6, TRUE);
len = strlen(fixed);
for (i = 0; i < len; i++) {
*optr++ = fixed[i];
@@ -377,10 +339,39 @@
mpaddi(MPval, &dval, MPval);
}
*optr++ = '\0';
- v->toclear = 1;
- v->pointed = 0;
+ v->ltr.toclear = 1;
+ v->ltr.pointed = 0;
+}
+
+
+/* Convert MP number to character string in the given base. */
+
+void
+make_number(char *target, int target_len, int *MPnumber, int base, int ignoreError)
+{
+ double number, val;
+
+/* NOTE: make_number can currently set v->error when converting to a double.
+ * This is to provide the same look&feel as V3 even though gcalctool
+ * now does internal arithmetic to "infinite" precision.
+ *
+ * XXX: Needs to be improved. Shouldn't need to convert to a double in
+ * order to do these tests.
+ */
- return(v->snum);
+ mpcmd(MPnumber, &number);
+ val = fabs(number);
+ if (v->error && !ignoreError) {
+ STRNCPY(target, _("Error"), target_len - 1);
+ return;
+ }
+ if ((v->dtype == ENG) ||
+ (v->dtype == SCI) ||
+ (v->dtype == FIX && val != 0.0 && (val > max_fix[base]))) {
+ make_eng_sci(target, target_len, MPnumber, base);
+ } else {
+ make_fixed(target, target_len, MPnumber, base, MAX_DIGITS, TRUE);
+ }
}
@@ -447,7 +438,7 @@
}
exp *= exp_sign;
- if (v->key_exp) {
+ if (v->ltr.key_exp) {
mppwr(MPbase, &exp, MP1);
mpmul(MPval, MP1, MPval);
}
@@ -481,10 +472,10 @@
switch (key) {
case -1:
case KEY_CLEAR:
- v->noparens = v->numsptr = 0;
- v->cur_op = -1;
+ v->ltr.noparens = 0;
+ v->ltr.cur_op = -1;
do_zero(v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
return;
case KEY_BACKSPACE:
if (!n) {
@@ -492,16 +483,15 @@
}
if (v->display[n-1] == ')') {
- v->noparens++;
+ v->ltr.noparens++;
} else if (v->display[n-1] == '(') {
- v->noparens--;
- if (!v->noparens) {
- v->numsptr = 0;
- v->cur_op = -1;
- show_display(v->MPdisp_val);
+ v->ltr.noparens--;
+ if (!v->ltr.noparens) {
+ v->ltr.cur_op = -1;
+ display_set_number(v->MPdisp_val);
return;
}
- } else if (v->display[n-1] == ')') v->noparens++;
+ } else if (v->display[n-1] == ')') v->ltr.noparens++;
v->display[n-1] = '\0';
break;
@@ -512,7 +502,7 @@
* to avoid the confusion of showing something like "0(".
*/
- if (v->noparens == 1 && v->cur_op == -1) {
+ if (v->ltr.noparens == 1 && v->ltr.cur_op == -1) {
n = 0;
v->display[0] = '\0';
}
@@ -532,74 +522,60 @@
ui_set_display(&v->display[n], -1);
}
-
void
-process_item(struct button *button, int arg)
+display_set_number(int *MPval)
{
- v->current = button->id;
-
- if (v->error) {
- /* Must press a valid key first. */
- if (v->current != KEY_CLEAR) {
- return;
- }
- ui_set_error_state(FALSE);
- }
-
- if (v->noparens > 0) {
- do_paren();
- return;
+ if (!v->error) {
+ make_number(v->display, MAXLINE, MPval, v->base, FALSE);
+ ui_set_display(v->display, -1);
}
-
- (*button->func)(arg);
}
-
void
-show_display(int *MPval)
+display_set_string(char *value)
{
- if (!v->error) {
- STRNCPY(v->display, make_number(MPval, v->base, FALSE), MAXLINE - 1);
- ui_set_display(v->display, -1);
- }
+ if(value != v->display)
+ STRNCPY(value, v->display, MAX_DIGITS - 1);
+ ui_set_display(v->display, -1);
}
-
/* In arithmetic precedence mode this routine should be called to redraw
* the display.
*/
void
-refresh_display(int cursor)
+display_refresh(int cursor)
{
int i, MP_reg[MP_SIZE];
- char localized[MAX_LOCALIZED], *str, *ans, reg[3], *t;
+ char localized[MAX_LOCALIZED], *str, reg[3], *t;
struct exprm_state *e;
+ char x[MAX_LOCALIZED], xx[MAX_LOCALIZED], ans[MAX_LOCALIZED];
switch (v->syntax) {
case NPA:
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
break;
case EXPRS:
e = get_state();
if (e->expression[0] == '\0') {
do_zero(MP_reg);
- str = gc_strdup(make_number(MP_reg, v->base, FALSE));
+ make_number(x, MAX_LOCALIZED, MP_reg, v->base, FALSE);
+ str = x;
} else {
str = gc_strdup(e->expression);
}
- ans = make_number(e->ans, v->base, TRUE);
-
+
+ /* Substitute answer register */
+ make_number(ans, MAX_LOCALIZED, e->ans, v->base, TRUE);
localize_expression(localized, ans, MAX_LOCALIZED);
- t = str_replace(str, "Ans", localized);
- free(str);
- str = t;
+ str = str_replace(str, "Ans", localized);
/* Replace registers with values. */
for (i = 0; i < 10; i++) {
SNPRINTF(reg, 3, "R%d", i);
do_rcl_reg(i, MP_reg);
- t = str_replace(str, reg, make_number(MP_reg, v->base, FALSE));
+ make_number(xx, MAX_LOCALIZED, MP_reg, v->base, FALSE);
+ t = str_replace(str, reg, xx);
free(str);
str = t;
}
@@ -619,8 +595,8 @@
switch (v->syntax) {
case NPA:
- if (v->old_cal_value < 0 ||
- v->old_cal_value == KEY_CALCULATE) {
+ if (v->ltr.old_cal_value < 0 ||
+ v->ltr.old_cal_value == KEY_CALCULATE) {
return TRUE;
}
break;
Modified: trunk/gcalctool/display.h
==============================================================================
--- trunk/gcalctool/display.h (original)
+++ trunk/gcalctool/display.h Tue Apr 29 10:26:27 2008
@@ -24,16 +24,17 @@
#include "calctool.h"
-void initialise();
+void display_reset();
void localize_expression(char *, const char *, int);
-char *make_fixed(int *, char *, int, int, int);
-char *make_number(int *, int, int);
-void clear_display(int);
-void MPstr_to_num(char *, enum base_type, int *);
+void display_clear(int);
void paren_disp(int);
-void refresh_display(int);
-void show_display(int *);
-void process_item(struct button *, int);
+void display_refresh(int);
+void display_set_number(int *);
+void display_set_string(char *);
gboolean display_is_result(void);
+void MPstr_to_num(char *, enum base_type, int *);
+void make_fixed(char *, int, int *, int, int, int);
+void make_number(char *, int, int *, int, int);
+
#endif /* DISPLAY_H */
Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c (original)
+++ trunk/gcalctool/functions.c Tue Apr 29 10:26:27 2008
@@ -191,7 +191,7 @@
update_undo_redo_button_sensitivity();
e = get_state();
- refresh_display(e->cursor);
+ display_refresh(e->cursor);
}
struct exprm_state *
@@ -258,7 +258,7 @@
} else if (v->current == KEY_FINC_TERM) {
calc_term(v->MPdisp_val);
}
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
@@ -329,16 +329,15 @@
static int
exp_backspace(int cursor)
{
- char buf[MAXLINE] = "", *display;
+ char buf[MAXLINE] = "", buf2[MAXLINE], *t;
struct exprm_state *e = get_state();
int i, MP_reg[MP_SIZE];
/* If cursor is at end of the line then delete the last character preserving accuracy */
if (cursor < 0) {
if (exp_has_postfix(e->expression, "Ans")) {
- char *ans = make_number(e->ans, v->base, FALSE);
- char *t;
- t = str_replace(e->expression, "Ans", ans);
+ make_number(buf, MAXLINE, e->ans, v->base, FALSE);
+ t = str_replace(e->expression, "Ans", buf);
free(e->expression);
e->expression = t;
} else {
@@ -346,9 +345,9 @@
SNPRINTF(buf, MAXLINE, "R%d", i);
if (exp_has_postfix(e->expression, buf)) {
do_rcl_reg(i, MP_reg);
- display = make_number(MP_reg, v->base, FALSE);
+ make_number(buf2, MAXLINE, MP_reg, v->base, FALSE);
/* Remove "Rx" postfix and replace with backspaced number */
- SNPRINTF(buf, MAXLINE, "%.*s%s", strlen(e->expression) - 2, e->expression - 3, display);
+ SNPRINTF(buf, MAXLINE, "%.*s%s", strlen(e->expression) - 2, e->expression - 3, buf2);
exp_replace(buf);
return cursor - 1;
}
@@ -357,8 +356,8 @@
SNPRINTF(buf, MAXLINE, "%.*s", strlen(e->expression) - 1, e->expression);
} else if (cursor > 0) {
- display = ui_get_display();
- SNPRINTF(buf, MAXLINE, "%.*s%s", cursor - 1, display, display + cursor);
+ t = ui_get_display();
+ SNPRINTF(buf, MAXLINE, "%.*s%s", cursor - 1, t, t + cursor);
} else {
return cursor; /* At the start of the line */
}
@@ -516,7 +515,8 @@
break;
case KEY_CONSTANT:
- cursor = exp_insert(make_number(v->MPcon_vals[arg], v->base, FALSE), cursor);
+ make_number(buf, MAXLINE, v->MPcon_vals[arg], v->base, FALSE);
+ cursor = exp_insert(buf, cursor);
break;
case KEY_BACKSPACE:
@@ -644,7 +644,7 @@
}
break;
}
- refresh_display(cursor);
+ display_refresh(cursor);
}
@@ -655,8 +655,8 @@
int MP1[MP_SIZE], MP2[MP_SIZE];
if (v->current == KEY_CALCULATE &&
- v->old_cal_value == KEY_CALCULATE) {
- if (v->new_input) {
+ v->ltr.old_cal_value == KEY_CALCULATE) {
+ if (v->ltr.new_input) {
mpstr(v->MPlast_input, v->MPresult);
} else {
mpstr(v->MPlast_input, v->MPdisp_val);
@@ -664,11 +664,11 @@
}
if (v->current != KEY_CALCULATE &&
- v->old_cal_value == KEY_CALCULATE) {
- v->cur_op = -1;
+ v->ltr.old_cal_value == KEY_CALCULATE) {
+ v->ltr.cur_op = -1;
}
- switch (v->cur_op) {
+ switch (v->ltr.cur_op) {
case KEY_SIN:
case KEY_SINH:
case KEY_ASIN:
@@ -754,19 +754,19 @@
break;
}
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
if (!(v->current == KEY_CALCULATE &&
- v->old_cal_value == KEY_CALCULATE)) {
+ v->ltr.old_cal_value == KEY_CALCULATE)) {
mpstr(v->MPdisp_val, v->MPlast_input);
}
mpstr(v->MPresult, v->MPdisp_val);
if (v->current != KEY_CALCULATE) {
- v->cur_op = v->current;
+ v->ltr.cur_op = v->current;
}
- v->old_cal_value = v->current;
- v->new_input = v->key_exp = 0;
+ v->ltr.old_cal_value = v->current;
+ v->ltr.new_input = v->ltr.key_exp = 0;
}
@@ -774,7 +774,7 @@
do_sin(void)
{
calc_trigfunc(sin_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -783,7 +783,7 @@
do_sinh(void)
{
calc_trigfunc(sinh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -792,7 +792,7 @@
do_asin(void)
{
calc_trigfunc(asin_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -801,7 +801,7 @@
do_asinh(void)
{
calc_trigfunc(asinh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -810,7 +810,7 @@
do_cos(void)
{
calc_trigfunc(cos_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -819,7 +819,7 @@
do_cosh(void)
{
calc_trigfunc(cosh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -828,7 +828,7 @@
do_acos(void)
{
calc_trigfunc(acos_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -837,7 +837,7 @@
do_acosh(void)
{
calc_trigfunc(acosh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -846,7 +846,7 @@
do_tan(void)
{
calc_trigfunc(tan_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -855,7 +855,7 @@
do_tanh(void)
{
calc_trigfunc(tanh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -864,7 +864,7 @@
do_atan(void)
{
calc_trigfunc(atan_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -873,7 +873,7 @@
do_atanh(void)
{
calc_trigfunc(atanh_t, v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -882,7 +882,7 @@
do_percent(void)
{
calc_percent(v->MPdisp_val, v->MPresult);
- show_display(v->MPresult);
+ display_set_number(v->MPresult);
mpstr(v->MPresult, v->MPdisp_val);
}
@@ -891,11 +891,11 @@
void
do_clear(void)
{
- clear_display(TRUE);
+ display_clear(TRUE);
if (v->error) {
ui_set_display("", -1);
}
- initialise();
+ display_reset();
}
@@ -903,7 +903,7 @@
void
do_clear_entry(void)
{
- clear_display(FALSE);
+ display_clear(FALSE);
}
@@ -945,7 +945,7 @@
break;
}
- refresh_display(-1);
+ display_refresh(-1);
}
@@ -959,7 +959,7 @@
MPval = v->MPcon_vals[index];
mpstr(MPval, v->MPdisp_val);
- v->new_input = 1;
+ v->ltr.new_input = 1;
syntaxdep_show_display();
}
@@ -979,23 +979,22 @@
* the exponent sign, then this reverts to entering a fixed point number.
*/
- if (v->key_exp && !(strchr(v->display, '+'))) {
- v->key_exp = 0;
+ if (v->ltr.key_exp && !(strchr(v->display, '+'))) {
+ v->ltr.key_exp = 0;
v->display[strlen(v->display)-1] = '\0';
}
/* If we've backspaced over the numeric point, clear the pointed flag. */
- if (v->pointed && !(strchr(v->display, '.'))) {
- v->pointed = 0;
+ if (v->ltr.pointed && !(strchr(v->display, '.'))) {
+ v->ltr.pointed = 0;
}
- ui_set_display(v->display, -1);
+ display_set_string(v->display);
MPstr_to_num(v->display, v->base, v->MPdisp_val);
if (v->dtype == FIX) {
- STRNCPY(v->fnum, v->display, MAX_LOCALIZED - 1);
- ui_set_display(v->fnum, -1);
+ display_set_string(v->display);
}
}
@@ -1034,7 +1033,7 @@
mpstr(MPexpr, v->MPmvals[index]);
mpstr(MPtemp, e->ans);
exp_replace("Ans");
- refresh_display(-1);
+ display_refresh(-1);
ui_make_registers();
}
break;
@@ -1043,7 +1042,7 @@
assert(0);
}
- v->new_input = 1;
+ v->ltr.new_input = 1;
syntaxdep_show_display();
}
@@ -1052,20 +1051,20 @@
void
do_expno(void)
{
- v->pointed = (strchr(v->display, '.') != NULL);
- if (!v->new_input) {
+ v->ltr.pointed = (strchr(v->display, '.') != NULL);
+ if (!v->ltr.new_input) {
STRNCPY(v->display, "1.0 +", MAX_LOCALIZED - 1);
- v->new_input = v->pointed = 1;
- } else if (!v->pointed) {
+ v->ltr.new_input = v->ltr.pointed = 1;
+ } else if (!v->ltr.pointed) {
STRNCAT(v->display, ". +", 3);
- v->pointed = 1;
- } else if (!v->key_exp) {
+ v->ltr.pointed = 1;
+ } else if (!v->ltr.key_exp) {
STRNCAT(v->display, " +", 2);
}
- v->toclear = 0;
- v->key_exp = 1;
- v->exp_posn = strchr(v->display, '+');
- ui_set_display(v->display, -1);
+ v->ltr.toclear = 0;
+ v->ltr.key_exp = 1;
+ v->ltr.exp_posn = strchr(v->display, '+');
+ display_set_string(v->display);
MPstr_to_num(v->display, v->base, v->MPdisp_val);
}
@@ -1149,7 +1148,7 @@
} else {
ui_set_statusbar(_("Malformed function"), "gtk-dialog-error");
}
- v->new_input = 1;
+ v->ltr.new_input = 1;
}
@@ -1217,15 +1216,15 @@
break;
case KEY_CHANGE_SIGN:
- if (v->key_exp) {
- if (*v->exp_posn == '+') {
- *v->exp_posn = '-';
+ if (v->ltr.key_exp) {
+ if (*v->ltr.exp_posn == '+') {
+ *v->ltr.exp_posn = '-';
} else {
- *v->exp_posn = '+';
+ *v->ltr.exp_posn = '+';
}
- ui_set_display(v->display, -1);
+ display_set_string(v->display);
MPstr_to_num(v->display, v->base, s);
- v->key_exp = 0;
+ v->ltr.key_exp = 0;
} else {
mpneg(s, t);
}
@@ -1238,7 +1237,7 @@
do_immed(void)
{
do_immedfunc(v->MPdisp_val, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
@@ -1247,9 +1246,9 @@
{
int offset;
- if (v->toclear) {
+ if (v->ltr.toclear) {
offset = 0;
- v->toclear = 0;
+ v->ltr.toclear = 0;
} else {
offset = strlen(v->display);
}
@@ -1257,9 +1256,9 @@
SNPRINTF(v->display+offset, MAXLINE-offset, "%s", buttons[v->current].symname);
}
- ui_set_display(v->display, -1);
+ display_set_string(v->display);
MPstr_to_num(v->display, v->base, v->MPdisp_val);
- v->new_input = 1;
+ v->ltr.new_input = 1;
}
@@ -1295,7 +1294,7 @@
assert(0);
}
- refresh_display(-1);
+ display_refresh(-1);
}
@@ -1306,20 +1305,20 @@
switch (v->current) {
case KEY_START_BLOCK:
- if (v->noparens == 0) {
- if (v->cur_op == -1) {
+ if (v->ltr.noparens == 0) {
+ if (v->ltr.cur_op == -1) {
v->display[0] = 0;
ui_set_statusbar(_("Cleared display, prefix without an operator is not allowed"), "");
} else {
- paren_disp(v->cur_op);
+ paren_disp(v->ltr.cur_op);
}
}
- v->noparens++;
+ v->ltr.noparens++;
break;
case KEY_END_BLOCK:
- v->noparens--;
- if (!v->noparens) {
+ v->ltr.noparens--;
+ if (!v->ltr.noparens) {
int ret, i = 0;
while (v->display[i++] != '(') {
/* do nothing */;
@@ -1327,7 +1326,7 @@
ret = lr_parse(&v->display[i], v->MPdisp_val);
if (!ret) {
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
return;
} else {
ui_set_statusbar(_("Malformed parenthesis expression"),
@@ -1388,7 +1387,7 @@
do_rcl(int index)
{
mpstr(v->MPmvals[index], v->MPdisp_val);
- v->new_input = 1;
+ v->ltr.new_input = 1;
syntaxdep_show_display();
}
@@ -1415,11 +1414,11 @@
{
switch (v->syntax) {
case NPA:
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
break;
case EXPRS:
- refresh_display(-1);
+ display_refresh(-1);
break;
default:
@@ -1431,16 +1430,16 @@
void
do_point(void) /* Handle numeric point. */
{
- if (!v->pointed) {
- if (v->toclear) {
+ if (!v->ltr.pointed) {
+ if (v->ltr.toclear) {
STRNCPY(v->display, ".", MAX_LOCALIZED - 1);
- v->toclear = 0;
+ v->ltr.toclear = 0;
} else {
STRCAT(v->display, ".");
}
- v->pointed = 1;
+ v->ltr.pointed = 1;
}
- ui_set_display(v->display, -1);
+ display_set_string(v->display);
MPstr_to_num(v->display, v->base, v->MPdisp_val);
}
@@ -1473,7 +1472,7 @@
do_portion(void)
{
do_portionfunc(v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
@@ -1499,7 +1498,7 @@
dval = setbool(temp);
mpcdm(&dval, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
mpstr(v->MPdisp_val, v->MPlast_input);
break;
@@ -1520,39 +1519,12 @@
assert(0);
}
- v->new_input = 1;
+ v->ltr.new_input = 1;
syntaxdep_show_display();
}
void
-do_trigtype(enum trig_type t) /* Change the current trigonometric type. */
-{
- v->ttype = t;
- set_resource(R_TRIG, Rtstr[(int) v->ttype]);
- switch (v->cur_op) {
- case KEY_SIN:
- case KEY_SINH:
- case KEY_ASIN:
- case KEY_ASINH:
- case KEY_COS:
- case KEY_COSH:
- case KEY_ACOS:
- case KEY_ACOSH:
- case KEY_TAN:
- case KEY_TANH:
- case KEY_ATAN:
- case KEY_ATANH:
- mpstr(v->MPtresults[(int) v->ttype], v->MPdisp_val);
- show_display(v->MPtresults[(int) v->ttype]);
- break;
-
- default:
- break;
- }
-}
-
-void
show_error(char *message)
{
ui_set_statusbar(message, "gtk-dialog-error");
Modified: trunk/gcalctool/functions.h
==============================================================================
--- trunk/gcalctool/functions.h (original)
+++ trunk/gcalctool/functions.h Tue Apr 29 10:26:27 2008
@@ -75,7 +75,6 @@
void do_tanh(void);
void do_atan(void);
void do_atanh(void);
-void do_trigtype(enum trig_type);
void do_percent(void);
void do_factorial(int *, int *);
int do_rcl_reg(int reg, int value[MP_SIZE]);
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Tue Apr 29 10:26:27 2008
@@ -452,7 +452,10 @@
GtkWidget *disp[MAXDISPMODES]; /* Numeric display mode. */
GtkWidget *trig[MAXTRIGMODES]; /* Trigonometric mode. */
+ //FIXME: Obsolete?
char *lnp; /* Localized numerical point (UTF8 format) */
+
+ char *shelf; /* PUT selection shelf contents. */
gboolean warn_change_mode; /* Should we warn user when changing modes? */
gboolean bitcalculating_mode;
@@ -479,9 +482,9 @@
switch (v->syntax) {
case NPA:
- v->noparens = 0;
+ v->ltr.noparens = 0;
MPstr_to_num("0", DEC, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
clear_undo_history();
break;
@@ -489,7 +492,7 @@
e = get_state();
MPstr_to_num("0", DEC, e->ans);
exp_clear();
- show_display(e->ans);
+ display_set_number(e->ans);
break;
default:
@@ -571,7 +574,7 @@
set_int_resource(R_ACCURACY, accuracy);
ui_make_registers();
- refresh_display(-1);
+ display_refresh(-1);
/* Hide the manual dialog */
gtk_widget_hide(X->spframe);
@@ -885,7 +888,7 @@
{
int bit_str_len, i, MP1[MP_SIZE], MP2[MP_SIZE];
int MP[MP_SIZE];
- char *bit_str, label[MAXLINE], tmp[MAXLINE];
+ char bit_str[MAXLINE], label[MAXLINE];
switch (v->syntax) {
case NPA:
@@ -895,7 +898,7 @@
int toclear = (v->current == KEY_CLEAR_ENTRY)
? TRUE : FALSE;
- bit_str = make_fixed(MP1, tmp, BIN, MAXLINE, toclear);
+ make_fixed(bit_str, MAXLINE, MP1, BIN, MAXLINE, toclear);
bit_str_len = strlen(bit_str);
if (bit_str_len <= MAXBITS) {
gtk_widget_set_sensitive(X->bit_panel, TRUE);
@@ -920,7 +923,7 @@
gtk_widget_set_sensitive(X->bit_panel, FALSE);
return;
}
- bit_str = make_fixed(MP, tmp, BIN, MAXLINE, FALSE);
+ make_fixed(bit_str, MAXLINE, MP, BIN, MAXLINE, FALSE);
bit_str_len = strlen(bit_str);
if (bit_str_len <= MAXBITS) {
gtk_widget_set_sensitive(X->bit_panel, TRUE);
@@ -954,7 +957,7 @@
if (str == NULL || str[0] == '\0') {
str = " ";
} else {
- if (v->noparens == 0) {
+ if (v->ltr.noparens == 0) {
localize_expression(localized, str, MAX_LOCALIZED);
str = localized;
}
@@ -1243,7 +1246,7 @@
ch = (char *) gtk_entry_get_text(GTK_ENTRY(X->aframe_ch));
val = ch[0];
mpcim(&val, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
gtk_widget_hide(dialog);
@@ -1309,11 +1312,25 @@
{
switch (v->syntax) {
case NPA:
- process_item(&buttons[function], arg);
+ v->current = buttons[function].id;
+
+ if (v->error) {
+ /* Must press a valid key first. */
+ if (v->current != KEY_CLEAR) {
+ return;
+ }
+ ui_set_error_state(FALSE);
+ }
+
+ if (v->ltr.noparens > 0) {
+ do_paren();
+ return;
+ }
+
+ buttons[function].func(arg);
set_bit_panel();
- if (v->new_input && v->dtype == FIX) {
- STRNCPY(v->fnum, v->display, MAX_DIGITS - 1);
- ui_set_display(v->fnum, -1);
+ if (v->ltr.new_input && v->dtype == FIX) {
+ display_set_string(v->display);
}
break;
@@ -1458,13 +1475,14 @@
static void
update_constants_menu(void)
{
- char mline[MAXLINE];
+ char mline[MAXLINE], value[MAXLINE];
int i;
for (i = 0; i < MAX_CONSTANTS; i++) {
+ make_number(value, MAXLINE, v->MPcon_vals[i], DEC, TRUE);
SNPRINTF(mline, MAXLINE,
"<span weight=\"bold\">%s_%1d:</span> %s [%s]", _("C"), i,
- make_number(v->MPcon_vals[i], DEC, TRUE),
+ value,
v->con_names[i]);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->constant_menu_labels[i]), mline);
}
@@ -1574,16 +1592,18 @@
gint i = 0;
GtkListStore *model;
GtkTreeIter iter;
+ char constant[MAXLINE];
model = gtk_list_store_new(NUM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_BOOLEAN);
for (i = 0; i < MAX_CONSTANTS; i++) {
gtk_list_store_append(model, &iter);
+ make_number(constant, MAXLINE, v->MPcon_vals[i], DEC, TRUE);
gtk_list_store_set(model, &iter,
COLUMN_NUMBER, i,
COLUMN_EDITABLE, TRUE,
- COLUMN_VALUE, g_strdup(make_number(v->MPcon_vals[i], DEC, TRUE)),
+ COLUMN_VALUE, g_strdup(constant),
COLUMN_DESCRIPTION, g_strdup(v->con_names[i]),
-1);
}
@@ -1620,15 +1640,16 @@
void
ui_make_registers() /* Calculate memory register frame values. */
{
- char *mval, key[MAXLINE];
+ char mval[MAXLINE], key[MAXLINE], value[MAXLINE];
int n;
for (n = 0; n < MAX_REGISTERS; n++) {
- mval = make_number(v->MPmvals[n], v->base, TRUE);
+ make_number(mval, MAXLINE, v->MPmvals[n], v->base, TRUE);
gtk_entry_set_width_chars(GTK_ENTRY(X->regs[n]), strlen(mval));
gtk_entry_set_text(GTK_ENTRY(X->regs[n]), mval);
SNPRINTF(key, MAXLINE, "register%d", n);
- set_resource(key, make_number(v->MPmvals[n], DEC, TRUE));
+ make_number(value, MAXLINE, v->MPmvals[n], DEC, TRUE);
+ set_resource(key, value);
}
}
@@ -1741,18 +1762,18 @@
switch (v->syntax) {
case NPA:
mpcdm(&number, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
break;
case EXPRS:
mpcdm(&number, e->ans);
exp_replace("Ans");
- refresh_display(-1);
+ display_refresh(-1);
break;
default:
assert(FALSE);
}
- v->toclear = 0;
+ v->ltr.toclear = 0;
return (TRUE);
}
@@ -1801,14 +1822,15 @@
static void
update_memory_menus()
{
- char mstr[MAXLINE];
+ char mstr[MAXLINE], value[MAXLINE];
int i;
for (i = 0; i < MAX_REGISTERS; i++) {
+ make_number(value, MAXLINE, v->MPmvals[i], v->base, TRUE);
SNPRINTF(mstr, MAXLINE, "<span weight=\"bold\">%s_%d:</span> %s",
/* translators: R is the short form of register used inter alia
in popup menus */
- _("R"), i, make_number(v->MPmvals[i], v->base, TRUE));
+ _("R"), i, value);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_store_labels[i]), mstr);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_recall_labels[i]), mstr);
gtk_label_set_markup_with_mnemonic(GTK_LABEL(X->memory_exchange_labels[i]), mstr);
@@ -1849,13 +1871,13 @@
string = ui_get_display();
}
- if (v->shelf != NULL) {
- free(v->shelf);
+ if (X->shelf != NULL) {
+ free(X->shelf);
}
- v->shelf = g_locale_from_utf8(string, strlen(string), NULL, NULL, NULL);
+ X->shelf = g_locale_from_utf8(string, strlen(string), NULL, NULL, NULL);
g_free(string);
- gtk_clipboard_set_text(gtk_clipboard_get(X->clipboard_atom), v->shelf, -1);
+ gtk_clipboard_set_text(gtk_clipboard_get(X->clipboard_atom), X->shelf, -1);
}
@@ -2172,7 +2194,7 @@
case NPA:
ret = lr_parse((char *) text, v->MPdisp_val);
if (!ret) {
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
} else {
ui_set_statusbar(_("Clipboard contained malformed calculation"),
"gtk-dialog-error");
@@ -2181,7 +2203,7 @@
case EXPRS:
exp_insert((char *) text, get_cursor()); // FIXME: Move out of gtk.c
- refresh_display(-1);
+ display_refresh(-1);
break;
default:
@@ -2234,7 +2256,7 @@
redo_cb(GtkWidget *widget)
{
perform_redo();
- refresh_display(-1);
+ display_refresh(-1);
}
@@ -2438,16 +2460,6 @@
/*ARGSUSED*/
-void
-trig_cb(GtkWidget *widget)
-{
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
- do_trigtype((enum trig_type) g_object_get_data(G_OBJECT(widget),
- "trig_mode"));
-}
-
-
-/*ARGSUSED*/
static void
show_thousands_separator_cb(GtkWidget *widget)
{
@@ -2542,7 +2554,6 @@
CONNECT_SIGNAL(mode_radio_cb);
CONNECT_SIGNAL(inv_cb);
CONNECT_SIGNAL(hyp_cb);
- CONNECT_SIGNAL(trig_cb);
CONNECT_SIGNAL(base_cb);
CONNECT_SIGNAL(disp_cb);
CONNECT_SIGNAL(quit_cb);
@@ -2855,6 +2866,7 @@
gtk_init(argc, argv);
X->lnp = ui_get_localized_numeric_point();
+ X->shelf = NULL; /* No selection for shelf initially. */
gtk_rc_get_default_files();
Modified: trunk/gcalctool/lr_parser.h
==============================================================================
--- trunk/gcalctool/lr_parser.h (original)
+++ trunk/gcalctool/lr_parser.h Tue Apr 29 10:26:27 2008
@@ -36,6 +36,7 @@
extern struct parser_state parser_state;
+int lrlex();
int lrerror(); /* Dummy definition. */
int lrparse(); /* Dummy definition. */
int ceerror(char *s);
Modified: trunk/gcalctool/lr_parser.y
==============================================================================
--- trunk/gcalctool/lr_parser.y (original)
+++ trunk/gcalctool/lr_parser.y Tue Apr 29 10:26:27 2008
@@ -33,8 +33,6 @@
#include "parser_mac.h"
#include "lr_parser.h"
-extern struct parser_state parser_state;
-
%}
%union {
@@ -119,7 +117,7 @@
udf:
value '=' {
cp($1, v->MPdisp_val);
- show_display(v->MPdisp_val);
+ display_set_number(v->MPdisp_val);
}
| value '=' tSTO '(' tINUMBER ')' {
int val;
@@ -132,8 +130,8 @@
do_sto_reg(val, $1);
}
| tCLR {
- initialise();
- show_display(v->MPdisp_val);
+ display_reset();
+ display_set_number(v->MPdisp_val);
}
;
Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c (original)
+++ trunk/gcalctool/mp.c Tue Apr 29 10:26:27 2008
@@ -1206,13 +1206,13 @@
accuracy = v->accuracy;
dtype = v->dtype;
- pointed = v->pointed;
- toclear = v->toclear;
+ pointed = v->ltr.pointed;
+ toclear = v->ltr.toclear;
v->dtype = FIX;
v->accuracy = MAX_DIGITS;
mpcmf(&x[1], tmp);
- STRNCPY(disp, make_number(tmp, v->base, FALSE), MAXLINE - 1);
+ make_number(disp, MAXLINE, tmp, v->base, FALSE);
if (disp[0] == '1') {
y[ll+1]++;
@@ -1220,8 +1220,8 @@
v->accuracy = accuracy;
v->dtype = dtype;
- v->pointed = pointed;
- v->toclear = toclear;
+ v->ltr.pointed = pointed;
+ v->ltr.toclear = toclear;
}
Modified: trunk/gcalctool/unittest.c
==============================================================================
--- trunk/gcalctool/unittest.c (original)
+++ trunk/gcalctool/unittest.c Tue Apr 29 10:26:27 2008
@@ -24,6 +24,7 @@
#include "display.h"
#include "functions.h"
#include "calctool.h"
+#include "ce_parser.h"
static void
test(char *expression, char *expected, int expected_error)
@@ -42,7 +43,7 @@
return;
}
- make_fixed(result, result_str, DEC, 10, FALSE);
+ make_fixed(result_str, MAXLINE, result, DEC, 10, FALSE);
if(strcmp(result_str, expected) != 0)
printf("FAIL: '%s' -> '%s', expected '%s'\n", expression, result_str, expected);
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]