gcalctool r2146 - trunk/gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2146 - trunk/gcalctool
- Date: Mon, 4 Aug 2008 06:50:36 +0000 (UTC)
Author: rancell
Date: Mon Aug 4 06:50:36 2008
New Revision: 2146
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2146&view=rev
Log:
Refactor display code to make display object
Modified:
trunk/gcalctool/calctool.c
trunk/gcalctool/calctool.h
trunk/gcalctool/ce_parser.c
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.c
trunk/gcalctool/lr_parser.h
trunk/gcalctool/lr_parser.y
trunk/gcalctool/mp.c
trunk/gcalctool/mpmath.c
trunk/gcalctool/mpmath.h
Modified: trunk/gcalctool/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Mon Aug 4 06:50:36 2008
@@ -547,7 +547,7 @@
switch (v->syntax) {
case NPA:
ui_set_error_state(TRUE);
- display_set_string(errmes);
+ display_set_string(&v->display, errmes);
ui_beep();
break;
@@ -747,7 +747,7 @@
get_options(argc, argv); /* Get command line arguments. */
ui_init(&argc, &argv); /* Initialise UI */
resources_init(); /* Initialise configuration */
- display_init();
+ display_init(&v->display);
init_text(); /* Setup text strings depending upon language. */
read_resources(); /* Read resources from merged database. */
Modified: trunk/gcalctool/calctool.h
==============================================================================
--- trunk/gcalctool/calctool.h (original)
+++ trunk/gcalctool/calctool.h Mon Aug 4 06:50:36 2008
@@ -22,9 +22,6 @@
#ifndef CALCTOOL_H
#define CALCTOOL_H
-#include "config.h"
-#include "mp.h"
-
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
@@ -33,6 +30,10 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include "config.h"
+#include "mp.h"
+#include "display.h"
+
#define FCLOSE (void) fclose /* To make lint happy. */
#define FPRINTF (void) fprintf
#define FPUTS (void) fputs
@@ -161,8 +162,6 @@
#undef FALSE
#define FALSE 0
-#define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
-
#define MPMATH_ERR 20001
enum button_flags {
@@ -179,21 +178,6 @@
enum button_flags flags; /* Misc flags */
};
-/* Expression mode state */
-struct exprm_state {
- int ans[MP_SIZE]; /* Previously calculated answer */
- char *expression; /* Expression entered by user */
- int cursor;
-};
-
-/* Circular list of Arithmetic Precedence Mode states*/
-struct exprm_state_history {
- unsigned int begin;
- unsigned int end;
- unsigned int current;
- 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. */
@@ -203,19 +187,17 @@
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 */
-
int current; /* Current button/character pressed. */
char *appname; /* Application name for resources. */
char *home; /* Pathname for users home directory. */
char *progname; /* Name of this program. */
- char display[MAXLINE]; /* Current calculator display. */
+ GCDisplay display;
+
const char *radix; /* Locale specific radix string. */
const char *tsep; /* Locale specific thousands separator. */
int tsep_count; /* Number of digits between separator. */
Modified: trunk/gcalctool/ce_parser.c
==============================================================================
--- trunk/gcalctool/ce_parser.c (original)
+++ trunk/gcalctool/ce_parser.c Mon Aug 4 06:50:36 2008
@@ -26,7 +26,7 @@
/* TODO: This file is almost identical to lr-parser. */
int
-ce_parse_(char *expression, int result[MP_SIZE], int flags)
+ce_parse_(const char *expression, int result[MP_SIZE], int flags)
{
int ret = 0;
@@ -67,7 +67,7 @@
int
-ce_parse(char *expression, int result[MP_SIZE])
+ce_parse(const char *expression, int result[MP_SIZE])
{
return(ce_parse_(expression, result, ANS));
}
Modified: trunk/gcalctool/ce_parser.h
==============================================================================
--- trunk/gcalctool/ce_parser.h (original)
+++ trunk/gcalctool/ce_parser.h Mon Aug 4 06:50:36 2008
@@ -40,7 +40,7 @@
int ceerror(); /* dummy definition TODO: this is a douple */
int ceparse(); /* dummy definition. */
int ceerror(char *s);
-int ce_parse(char *expression, int result[MP_SIZE]);
+int ce_parse(const char *expression, int result[MP_SIZE]);
int ce_udf_parse(char *expression);
void reset_ce_tokeniser();
Modified: trunk/gcalctool/ce_parser.y
==============================================================================
--- trunk/gcalctool/ce_parser.y (original)
+++ trunk/gcalctool/ce_parser.y Mon Aug 4 06:50:36 2008
@@ -124,7 +124,7 @@
udf:
value '=' {
cp($1, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
| value '=' tSTO '(' tNUMBER ')' {
int val = mp_cast_to_int($5);
@@ -135,8 +135,8 @@
do_sto_reg(val, $1);
}
| tCLR {
- display_reset();
- display_set_number(v->MPdisp_val);
+ display_reset(&v->display);
+ display_set_number(&v->display, v->MPdisp_val);
}
;
@@ -267,8 +267,7 @@
number:
tNUMBER {cp($1, $$);}
| tANS {
- struct exprm_state *e = get_state();
- cp(e->ans, $$);
+ cp(display_get_answer(&v->display), $$);
}
;
Modified: trunk/gcalctool/display.c
==============================================================================
--- trunk/gcalctool/display.c (original)
+++ trunk/gcalctool/display.c Mon Aug 4 06:50:36 2008
@@ -1,4 +1,3 @@
-
/* $Header$
*
* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
@@ -30,6 +29,12 @@
#include "ui.h"
#include "ce_parser.h" // For ce_parse()
+static struct exprm_state *
+get_state(GCDisplay *display)
+{
+ return &(display->h.e[display->h.current]);
+}
+
static gboolean
exp_has_postfix(char *str, char *postfix)
{
@@ -54,15 +59,15 @@
static char *
str_replace(char *str, char *from, char *to)
{
- char output[MAXLINE];
+ char output[MAX_DISPLAY];
int offset = 0;
char *c;
int flen = strlen(from);
int tlen = strlen(to);
- for (c = str; *c && offset < MAXLINE - 1; c++, offset++) {
+ for (c = str; *c && offset < MAX_DISPLAY - 1; c++, offset++) {
if (strncasecmp(from, c, flen) == 0) {
- SNPRINTF(output + offset, MAXLINE - offset, to);
+ SNPRINTF(output + offset, MAX_DISPLAY - offset, to);
c += flen - 1;
offset += tlen - 1;
} else {
@@ -70,8 +75,8 @@
}
}
- if (offset >= MAXLINE)
- offset = MAXLINE - 1;
+ if (offset >= MAX_DISPLAY)
+ offset = MAX_DISPLAY - 1;
output[offset] = '\0';
return strdup(output);
@@ -174,14 +179,14 @@
void
-display_clear(int initialise)
+display_clear(GCDisplay *display, int initialise)
{
switch(v->syntax) {
case NPA:
v->ltr.pointed = 0;
v->ltr.toclear = 1;
mp_set_from_integer(0, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(display, v->MPdisp_val);
if (initialise == TRUE) {
v->ltr.noparens = 0;
@@ -191,7 +196,7 @@
break;
case EXPRS:
- display_set_string("");
+ display_set_string(display, "");
break;
default:
@@ -201,7 +206,7 @@
void
-display_reset()
+display_reset(GCDisplay *display)
{
v->error = 0; /* Currently no display error. */
v->ltr.cur_op = -1; /* No arithmetic operator defined yet. */
@@ -212,13 +217,63 @@
v->ltr.new_input = 1; /* Value zero is on calculator display */
- display_clear(TRUE);
+ display_clear(display, TRUE);
}
-/* Append the latest parenthesis char to the display item. */
+const char *
+display_get_text(GCDisplay *display)
+{
+ struct exprm_state *e;
+
+ switch(v->syntax) {
+ case NPA:
+ return display->display;
+
+ case EXPRS:
+ e = get_state(display);
+ return e->expression;
+
+ default:
+ assert(0);
+ }
+}
+
+int *display_get_answer(GCDisplay *display)
+{
+ struct exprm_state *e;
+ switch(v->syntax) {
+ case NPA:
+ return NULL; // FIXME?
+
+ case EXPRS:
+ e = get_state(display);
+ return e->ans;
+
+ default:
+ assert(0);
+ }
+}
+
+int
+display_get_cursor(GCDisplay *display)
+{
+ struct exprm_state *e;
+ switch(v->syntax) {
+ case NPA:
+ return -1; // FIXME?
+
+ case EXPRS:
+ e = get_state(display);
+ return e->cursor;
+ default:
+ assert(0);
+ }
+}
+
+/* Append the latest parenthesis char to the display item. */
void
-paren_disp(int key)
+paren_disp(GCDisplay *display, int key)
{
int n;
char *text;
@@ -233,7 +288,7 @@
* Otherwise just append the character.
*/
- n = strlen(v->display);
+ n = strlen(display->display);
text = buttons[key].symname;
switch (key) {
case -1:
@@ -241,24 +296,24 @@
v->ltr.noparens = 0;
v->ltr.cur_op = -1;
mp_set_from_integer(0, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(display, v->MPdisp_val);
return;
case KEY_BACKSPACE:
if (!n) {
return;
}
- if (v->display[n-1] == ')') {
+ if (display->display[n-1] == ')') {
v->ltr.noparens++;
- } else if (v->display[n-1] == '(') {
+ } else if (display->display[n-1] == '(') {
v->ltr.noparens--;
if (!v->ltr.noparens) {
v->ltr.cur_op = -1;
- display_set_number(v->MPdisp_val);
+ display_set_number(display, v->MPdisp_val);
return;
}
- } else if (v->display[n-1] == ')') v->ltr.noparens++;
- v->display[n-1] = '\0';
+ } else if (display->display[n-1] == ')') v->ltr.noparens++;
+ display->display[n-1] = '\0';
break;
case KEY_START_BLOCK:
@@ -270,7 +325,7 @@
if (v->ltr.noparens == 1 && v->ltr.cur_op == -1) {
n = 0;
- v->display[0] = '\0';
+ display->display[0] = '\0';
}
text = "(";
break;
@@ -281,36 +336,36 @@
}
if (text) {
- SNPRINTF(v->display+n, MAXLINE-n, "%s", text);
+ SNPRINTF(display->display+n, MAX_DISPLAY-n, "%s", text);
}
n = (n < MAX_DIGITS) ? 0 : n - MAX_DIGITS;
- ui_set_display(&v->display[n], -1);
+ ui_set_display(&display->display[n], -1);
}
void
-display_set_number(int *MPval)
+display_set_number(GCDisplay *display, int *MPval)
{
if (!v->error) {
- make_number(v->display, MAXLINE, MPval, v->base, FALSE);
- ui_set_display(v->display, -1);
+ make_number(display->display, MAX_DISPLAY, MPval, v->base, FALSE);
+ ui_set_display(display->display, -1);
}
}
void
-display_set_string(char *value)
+display_set_string(GCDisplay *display, const char *value)
{
struct exprm_state *e;
switch(v->syntax) {
case NPA:
- if(value != v->display)
- STRNCPY(value, v->display, MAX_DIGITS - 1);
- ui_set_display(v->display, -1);
+ if(value != display->display)
+ STRNCPY(display->display, value, MAX_DIGITS - 1);
+ ui_set_display(display->display, -1);
break;
case EXPRS:
- e = get_state();
+ e = get_state(display);
free(e->expression);
e->expression = strdup(value);
break;
@@ -321,7 +376,25 @@
}
void
-display_set_error(const char *message)
+display_set_cursor(GCDisplay *display, int cursor)
+{
+ struct exprm_state *e;
+ switch(v->syntax) {
+ case NPA:
+ break; // FIXME?
+
+ case EXPRS:
+ e = get_state(display);
+ e->cursor = cursor;
+ break;
+
+ default:
+ assert(0);
+ }
+}
+
+void
+display_set_error(GCDisplay *display, const char *message)
{
ui_set_statusbar(message, "gtk-dialog-error");
}
@@ -334,172 +407,173 @@
}
static void
-update_undo_redo_button_sensitivity(void)
+update_undo_redo_button_sensitivity(GCDisplay *display)
{
int undo = 0;
int redo = 0;
- if (v->h.current != v->h.end) {
+ if (display->h.current != display->h.end) {
redo = 1;
}
- if (v->h.current != v->h.begin) {
+ if (display->h.current != display->h.begin) {
undo = 1;
}
ui_set_undo_enabled(undo, redo);
}
-void display_clear_stack(void)
+void display_clear_stack(GCDisplay *display)
{
- int i = v->h.begin;
- while (i != v->h.end) {
- if (i != v->h.current) {
- free(v->h.e[i].expression);
- v->h.e[i].expression = NULL;
+ int i = display->h.begin;
+ while (i != display->h.end) {
+ if (i != display->h.current) {
+ free(display->h.e[i].expression);
+ display->h.e[i].expression = NULL;
}
i = ((i + 1) % UNDO_HISTORY_LENGTH);
}
- v->h.begin = v->h.end = v->h.current;
- update_undo_redo_button_sensitivity();
+ display->h.begin = display->h.end = display->h.current;
+ update_undo_redo_button_sensitivity(display);
}
-void display_push(void)
+void display_push(GCDisplay *display)
{
int c;
- if (v->h.current != v->h.end) {
- int i = v->h.current;
+ if (display->h.current != display->h.end) {
+ int i = display->h.current;
do {
i = ((i + 1) % UNDO_HISTORY_LENGTH);
- free(v->h.e[i].expression);
- v->h.e[i].expression = strdup("Ans");
- } while (i != v->h.end);
+ free(display->h.e[i].expression);
+ display->h.e[i].expression = strdup("Ans");
+ } while (i != display->h.end);
}
- v->h.end = v->h.current;
+ display->h.end = display->h.current;
- c = v->h.current;
- v->h.end = v->h.current = ((v->h.current + 1) % UNDO_HISTORY_LENGTH);
- if (v->h.current == v->h.begin) {
- free(v->h.e[v->h.begin].expression);
- v->h.e[v->h.begin].expression = NULL;
- v->h.begin = ((v->h.begin + 1) % UNDO_HISTORY_LENGTH);
+ c = display->h.current;
+ display->h.end = display->h.current = ((display->h.current + 1) % UNDO_HISTORY_LENGTH);
+ if (display->h.current == display->h.begin) {
+ free(display->h.e[display->h.begin].expression);
+ display->h.e[display->h.begin].expression = NULL;
+ display->h.begin = ((display->h.begin + 1) % UNDO_HISTORY_LENGTH);
}
- copy_state(&(v->h.e[v->h.current]), &(v->h.e[c]));
- update_undo_redo_button_sensitivity();
+ copy_state(&(display->h.e[display->h.current]), &(display->h.e[c]));
+ update_undo_redo_button_sensitivity(display);
}
-void display_pop(void)
+void display_pop(GCDisplay *display)
{
- struct exprm_state *e;
-
- if (v->h.current != v->h.begin) {
- v->h.current = ((v->h.current - 1) % UNDO_HISTORY_LENGTH);
+ if (display->h.current != display->h.begin) {
+ display->h.current = ((display->h.current - 1) % UNDO_HISTORY_LENGTH);
ui_set_statusbar("", "");
} else {
ui_set_statusbar(_("No undo history"), "gtk-dialog-warning");
}
- update_undo_redo_button_sensitivity();
+ update_undo_redo_button_sensitivity(display);
- e = get_state();
- display_refresh(e->cursor);
+ display_refresh(display, display_get_cursor(display));
}
void
-display_unpop(void)
+display_unpop(GCDisplay *display)
{
- if (v->h.current != v->h.end) {
- v->h.current = ((v->h.current + 1) % UNDO_HISTORY_LENGTH);
+ if (display->h.current != display->h.end) {
+ display->h.current = ((display->h.current + 1) % UNDO_HISTORY_LENGTH);
ui_set_statusbar("", "");
} else {
ui_set_statusbar(_("No redo steps"), "gtk-dialog-warning");
}
- update_undo_redo_button_sensitivity();
+ update_undo_redo_button_sensitivity(display);
+}
+
+gboolean
+display_is_undo_step(GCDisplay *display)
+{
+ return(display->h.current != display->h.begin);
}
int
-display_insert(const char *text, int cursor)
+display_insert(GCDisplay *display, const char *text, int cursor)
{
- char buf[MAXLINE], *display;
- struct exprm_state *e = get_state();
+ char buf[MAX_DISPLAY], *currentText;
if (cursor < 0) {
- SNPRINTF(buf, MAXLINE, "%s%s", e->expression, text);
+ SNPRINTF(buf, MAX_DISPLAY, "%s%s", display_get_text(display), text);
} else {
- display = ui_get_display();
- SNPRINTF(buf, MAXLINE, "%.*s%s%s", cursor, display, text, display + cursor);
+ currentText = ui_get_display();
+ SNPRINTF(buf, MAX_DISPLAY, "%.*s%s%s", cursor, currentText, text, currentText + cursor);
cursor += strlen(text);
}
- display_set_string(buf);
+ display_set_string(display, buf);
return cursor;
}
int
-display_backspace(int cursor)
+display_backspace(GCDisplay *display, int cursor)
{
- char buf[MAXLINE] = "", buf2[MAXLINE], *t;
- struct exprm_state *e = get_state();
+ char buf[MAX_DISPLAY] = "", buf2[MAX_DISPLAY], *t;
+ struct exprm_state *e = get_state(display);
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")) {
- make_number(buf, MAXLINE, e->ans, v->base, FALSE);
+ make_number(buf, MAX_DISPLAY, e->ans, v->base, FALSE);
t = str_replace(e->expression, "Ans", buf);
free(e->expression);
e->expression = t;
} else {
for (i = 0; i < 10; i++) {
- SNPRINTF(buf, MAXLINE, "R%d", i);
+ SNPRINTF(buf, MAX_DISPLAY, "R%d", i);
if (exp_has_postfix(e->expression, buf)) {
do_rcl_reg(i, MP_reg);
- make_number(buf2, MAXLINE, MP_reg, v->base, FALSE);
+ make_number(buf2, MAX_DISPLAY, 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, buf2);
- display_set_string(buf);
+ SNPRINTF(buf, MAX_DISPLAY, "%.*s%s", strlen(e->expression) - 2, e->expression - 3, buf2);
+ display_set_string(display, buf);
return cursor - 1;
}
}
}
- SNPRINTF(buf, MAXLINE, "%.*s", strlen(e->expression) - 1, e->expression);
+ SNPRINTF(buf, MAX_DISPLAY, "%.*s", strlen(e->expression) - 1, e->expression);
} else if (cursor > 0) {
t = ui_get_display();
- SNPRINTF(buf, MAXLINE, "%.*s%s", cursor - 1, t, t + cursor);
+ SNPRINTF(buf, MAX_DISPLAY, "%.*s%s", cursor - 1, t, t + cursor);
} else {
return cursor; /* At the start of the line */
}
- display_set_string(buf);
+ display_set_string(display, buf);
return cursor - 1;
}
int
-display_delete(int cursor)
+display_delete(GCDisplay *display, int cursor)
{
- char buf[MAXLINE] = "", *display;
+ char buf[MAX_DISPLAY] = "", *text;
if (cursor >= 0) {
- display = ui_get_display();
- SNPRINTF(buf, MAXLINE, "%.*s%s", cursor, display, display + cursor + 1);
- display_set_string(buf);
+ text = ui_get_display();
+ SNPRINTF(buf, MAX_DISPLAY, "%.*s%s", cursor, text, text + cursor + 1);
+ display_set_string(display, buf);
}
return cursor;
}
int
-display_surround(const char *prefix, const char *suffix, int cursor)
+display_surround(GCDisplay *display, const char *prefix, const char *suffix, int cursor)
{
- struct exprm_state *e = get_state();
- char buffer[MAXLINE];
+ char buffer[MAX_DISPLAY];
- SNPRINTF(buffer, MAXLINE, "%s%s%s", prefix, e->expression, suffix);
- display_set_string(buffer);
+ SNPRINTF(buffer, MAX_DISPLAY, "%s%s%s", prefix, display_get_text(display), suffix);
+ display_set_string(display, buffer);
return cursor;
}
@@ -508,7 +582,7 @@
* the display.
*/
void
-display_refresh(int cursor)
+display_refresh(GCDisplay *display, int cursor)
{
int i, MP_reg[MP_SIZE];
char localized[MAX_LOCALIZED], *str, reg[3], *t;
@@ -517,12 +591,12 @@
switch (v->syntax) {
case NPA:
- display_set_number(v->MPdisp_val);
+ display_set_number(display, v->MPdisp_val);
break;
case EXPRS:
- e = get_state();
- if (display_is_empty()) {
+ e = get_state(display);
+ if (display_is_empty(display)) {
mp_set_from_integer(0, MP_reg);
make_number(x, MAX_LOCALIZED, MP_reg, v->base, FALSE);
str = x;
@@ -555,17 +629,14 @@
}
gboolean
-display_is_empty(void)
+display_is_empty(GCDisplay *display)
{
- struct exprm_state *e;
-
switch (v->syntax) {
case NPA:
return v->ltr.toclear;
case EXPRS:
- e = get_state();
- return strcmp(e->expression, "") == 0;
+ return strcmp(display_get_text(display), "") == 0;
default:
assert(FALSE);
@@ -573,10 +644,8 @@
}
gboolean
-display_is_result(void)
+display_is_result(GCDisplay *display)
{
- struct exprm_state *e;
-
switch (v->syntax) {
case NPA:
if (v->ltr.old_cal_value < 0 ||
@@ -586,8 +655,7 @@
break;
case EXPRS:
- e = get_state();
- if (strcmp(e->expression, "Ans") == 0) {
+ if (strcmp(display_get_text(display), "Ans") == 0) {
return TRUE;
}
break;
@@ -600,39 +668,37 @@
}
gboolean
-display_is_usable_number(int MPnum[MP_SIZE])
+display_is_usable_number(GCDisplay *display, int MPnum[MP_SIZE])
{
- struct exprm_state *e = get_state();
- if (display_is_empty()) {
+ if (display_is_empty(display)) {
return ce_parse("0", MPnum);
} else {
- return ce_parse(e->expression, MPnum);
+ return ce_parse(display_get_text(display), MPnum);
}
}
void
-display_init(void)
+display_init(GCDisplay *display)
{
int i;
- memset(&(v->h), 0, sizeof(struct exprm_state_history)); /* clear expression mode state history */
+ memset(&(display->h), 0, sizeof(struct exprm_state_history)); /* clear expression mode state history */
for (i = 0; i < UNDO_HISTORY_LENGTH; i++)
- v->h.e[i].expression = strdup("");
+ display->h.e[i].expression = strdup("");
}
int
-display_solve(int *result)
+display_solve(GCDisplay *display, int *result)
{
- struct exprm_state *e;
- char *c;
GString *clean;
int errorCode;
+ const char *c, *text;
- e = get_state();
+ text = display_get_text(display);
/* Remove thousands separators and use english radix */
- clean = g_string_sized_new(strlen(e->expression));
- for (c = e->expression; *c; c++) {
+ clean = g_string_sized_new(strlen(text));
+ for (c = text; *c; c++) {
if (v->tsep[0] != '\0' && strncmp(c, v->tsep, strlen(v->tsep)) == 0) {
c += strlen(v->tsep) - 1;
} else if (strncmp(c, v->radix, strlen(v->radix)) == 0) {
Modified: trunk/gcalctool/display.h
==============================================================================
--- trunk/gcalctool/display.h (original)
+++ trunk/gcalctool/display.h Mon Aug 4 06:50:36 2008
@@ -1,4 +1,3 @@
-
/* $Header$
*
* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
@@ -22,33 +21,66 @@
#ifndef DISPLAY_H
#define DISPLAY_H
-#include "calctool.h"
+#include <glib.h>
+
+#include "mp.h"
+
+#define UNDO_HISTORY_LENGTH 16 /* Arithmetic mode undo history length */
+#define MAX_DISPLAY 512
+
+/* Expression mode state */
+struct exprm_state {
+ int ans[MP_SIZE]; /* Previously calculated answer */
+ char *expression; /* Expression entered by user */
+ int cursor;
+};
+
+/* Circular list of Arithmetic Precedence Mode states*/
+struct exprm_state_history {
+ unsigned int begin;
+ unsigned int end;
+ unsigned int current;
+ struct exprm_state e[UNDO_HISTORY_LENGTH]; /* Expression mode state */
+};
+
+typedef struct
+{
+ char display[MAX_DISPLAY]; /* Current calculator display. */
+ struct exprm_state_history h; /* History of expression mode states */
+} GCDisplay;
-void display_init(void);
+void display_init(GCDisplay *);
-void display_reset(void);
+void display_reset(GCDisplay *);
void localize_expression(char *, const char *, int, int *);
-void display_clear(int);
-void paren_disp(int);
-void display_refresh(int);
-void display_set_number(int *);
-void display_set_string(char *);
-void display_set_error(const char *);
-
-void display_clear_stack(void);
-void display_push(void);
-void display_pop(void);
-void display_unpop(void);
-
-int display_insert(const char *, int);
-int display_backspace(int cursor);
-int display_delete(int);
-int display_surround(const char *, const char *, int);
-
-gboolean display_is_empty(void);
-gboolean display_is_result(void);
-gboolean display_is_usable_number(int *);
+void display_clear(GCDisplay *, int);
+void paren_disp(GCDisplay *, int);
+void display_refresh(GCDisplay *, int);
+
+const char *display_get_text(GCDisplay *);
+int *display_get_answer(GCDisplay *);
+int display_get_cursor(GCDisplay *);
+
+void display_set_number(GCDisplay *, int *);
+void display_set_string(GCDisplay *, const char *);
+void display_set_cursor(GCDisplay *, int);
+void display_set_error(GCDisplay *, const char *);
+
+void display_clear_stack(GCDisplay *);
+void display_push(GCDisplay *);
+void display_pop(GCDisplay *);
+void display_unpop(GCDisplay *);
+gboolean display_is_undo_step(GCDisplay *display);
+
+int display_insert(GCDisplay *, const char *, int);
+int display_backspace(GCDisplay *, int cursor);
+int display_delete(GCDisplay *, int);
+int display_surround(GCDisplay *, const char *, const char *, int);
+
+gboolean display_is_empty(GCDisplay *);
+gboolean display_is_result(GCDisplay *);
+gboolean display_is_usable_number(GCDisplay *, int *);
-int display_solve(int *);
+int display_solve(GCDisplay *, int *);
#endif /* DISPLAY_H */
Modified: trunk/gcalctool/functions.c
==============================================================================
--- trunk/gcalctool/functions.c (original)
+++ trunk/gcalctool/functions.c Mon Aug 4 06:50:36 2008
@@ -74,35 +74,21 @@
void
clear_undo_history(void)
{
- display_clear_stack();
-}
-
-
-struct exprm_state *
-get_state(void)
-{
- return &(v->h.e[v->h.current]);
+ display_clear_stack(&v->display);
}
void
perform_undo(void)
{
- display_pop();
-}
-
-
-static int
-is_undo_step(void)
-{
- return(v->h.current != v->h.begin);
+ display_pop(&v->display);
}
void
perform_redo(void)
{
- display_unpop();
+ display_unpop(&v->display);
}
@@ -140,21 +126,21 @@
} else if (v->current == KEY_FINC_TERM) {
calc_term(v->MPdisp_val);
}
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
static void
exp_negate(void)
{
- display_surround("-(", ")", 0); // FIXME: Cursor
+ display_surround(&v->display, "-(", ")", 0); // FIXME: Cursor
}
static void
exp_inv(void)
{
- display_surround("1/(", ")", 0); // FIXME: Cursor
+ display_surround(&v->display, "1/(", ")", 0); // FIXME: Cursor
}
@@ -162,28 +148,28 @@
do_expression(int function, int arg, int cursor)
{
char buf[MAXLINE];
- struct exprm_state *e;
+ int *ans;
- display_push();
- e = get_state();
+ display_push(&v->display);
- e->cursor = cursor;
+ display_set_cursor(&v->display, cursor);
+ ans = display_get_answer(&v->display);
ui_set_statusbar("", "");
/* Starting a number after a calculation clears the display */
- if (display_is_result()) {
+ if (display_is_result(&v->display)) {
if (buttons[function].flags & NUMBER) {
- display_set_string("");
+ display_set_string(&v->display, "");
}
}
switch (buttons[function].id) {
case KEY_CLEAR:
case KEY_CLEAR_ENTRY:
- display_clear(FALSE);
+ display_clear(&v->display, FALSE);
ui_set_error_state(FALSE);
- MPstr_to_num("0", DEC, e->ans);
+ MPstr_to_num("0", DEC, ans);
break;
case KEY_SHIFT:
@@ -209,20 +195,20 @@
case KEY_RECALL:
SNPRINTF(buf, MAXLINE, "R%d", arg);
- cursor = display_insert(buf, cursor);
+ cursor = display_insert(&v->display, buf, cursor);
break;
case KEY_CONSTANT:
make_number(buf, MAXLINE, v->MPcon_vals[arg], v->base, FALSE);
- cursor = display_insert(buf, cursor);
+ cursor = display_insert(&v->display, buf, cursor);
break;
case KEY_BACKSPACE:
- cursor = display_backspace(cursor);
+ cursor = display_backspace(&v->display, cursor);
break;
case KEY_DELETE:
- cursor = display_delete(cursor);
+ cursor = display_delete(&v->display, cursor);
break;
case KEY_CHANGE_SIGN:
@@ -240,16 +226,15 @@
* this result */
/* TODO: Work out why two undo steps are required and why
* the cursor must be taken from the first undo */
- if (display_is_result()) {
+ if (display_is_result(&v->display)) {
perform_undo();
- e = get_state();
- cursor = e->cursor;
- if (is_undo_step()) {
+ cursor = display_get_cursor(&v->display);
+ if (display_is_undo_step(&v->display)) {
perform_undo();
}
/* Do nothing */
- } else if (display_is_empty()) {
+ } else if (display_is_empty(&v->display)) {
;
/* Solve the equation */
@@ -258,11 +243,11 @@
int result;
const char *message = NULL;
- result = display_solve(MPval);
+ result = display_solve(&v->display, MPval);
switch (result) {
case 0:
- mp_set_from_mp(MPval, e->ans);
- display_set_string("Ans");
+ mp_set_from_mp(MPval, ans);
+ display_set_string(&v->display, "Ans");
cursor = -1;
break;
@@ -296,25 +281,25 @@
break;
case KEY_NUMERIC_POINT:
- cursor = display_insert(v->radix, cursor);
+ cursor = display_insert(&v->display, v->radix, cursor);
break;
default:
/* If display is a number then perform functions on that number */
- if (buttons[function].flags & (PREFIXOP | FUNC) && display_is_result()) {
+ if (buttons[function].flags & (PREFIXOP | FUNC) && display_is_result(&v->display)) {
SNPRINTF(buf, MAXLINE, "%s(", buttons[function].symname);
- display_surround(buf, ")", 0); // FIXME: Cursor
+ display_surround(&v->display, buf, ")", 0); // FIXME: Cursor
} else {
if (buttons[function].flags & FUNC) {
SNPRINTF(buf, MAXLINE, "%s(", buttons[function].symname);
- cursor = display_insert(buf, cursor);
+ cursor = display_insert(&v->display, buf, cursor);
} else {
- cursor = display_insert(buttons[function].symname, cursor);
+ cursor = display_insert(&v->display, buttons[function].symname, cursor);
}
}
break;
}
- display_refresh(cursor);
+ display_refresh(&v->display, cursor);
}
@@ -425,7 +410,7 @@
break;
}
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
if (!(v->current == KEY_CALCULATE &&
v->ltr.old_cal_value == KEY_CALCULATE)) {
@@ -445,7 +430,7 @@
do_sin(void)
{
calc_trigfunc(sin_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -454,7 +439,7 @@
do_sinh(void)
{
calc_trigfunc(sinh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -463,7 +448,7 @@
do_asin(void)
{
calc_trigfunc(asin_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -472,7 +457,7 @@
do_asinh(void)
{
calc_trigfunc(asinh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -481,7 +466,7 @@
do_cos(void)
{
calc_trigfunc(cos_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -490,7 +475,7 @@
do_cosh(void)
{
calc_trigfunc(cosh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -499,7 +484,7 @@
do_acos(void)
{
calc_trigfunc(acos_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -508,7 +493,7 @@
do_acosh(void)
{
calc_trigfunc(acosh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -517,7 +502,7 @@
do_tan(void)
{
calc_trigfunc(tan_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -526,7 +511,7 @@
do_tanh(void)
{
calc_trigfunc(tanh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -535,7 +520,7 @@
do_atan(void)
{
calc_trigfunc(atan_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -544,7 +529,7 @@
do_atanh(void)
{
calc_trigfunc(atanh_t, v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -553,7 +538,7 @@
do_percent(void)
{
calc_percent(v->MPdisp_val, v->MPresult);
- display_set_number(v->MPresult);
+ display_set_number(&v->display, v->MPresult);
mp_set_from_mp(v->MPresult, v->MPdisp_val);
}
@@ -562,11 +547,11 @@
void
do_clear(void)
{
- display_clear(TRUE);
+ display_clear(&v->display, TRUE);
if (v->error) {
ui_set_display("", -1);
}
- display_reset();
+ display_reset(&v->display);
}
@@ -574,7 +559,7 @@
void
do_clear_entry(void)
{
- display_clear(FALSE);
+ display_clear(&v->display, FALSE);
}
@@ -582,7 +567,6 @@
void
do_base(enum base_type b)
{
- struct exprm_state *e;
int ret, MP[MP_SIZE];
switch (v->syntax) {
@@ -594,15 +578,14 @@
break;
case EXPRS:
- e = get_state();
- ret = display_is_usable_number(MP);
+ ret = display_is_usable_number(&v->display, MP);
if (ret) {
ui_set_statusbar(_("No sane value to convert"),
"gtk-dialog-error");
} else {
- mp_set_from_mp(MP, e->ans);
- display_set_string("Ans");
+ mp_set_from_mp(MP, display_get_answer(&v->display));
+ display_set_string(&v->display, "Ans");
}
v->base = b;
set_resource(R_BASE, Rbstr[(int) v->base]);
@@ -616,7 +599,7 @@
break;
}
- display_refresh(-1);
+ display_refresh(&v->display, -1);
}
@@ -640,33 +623,30 @@
do_backspace(void)
{
size_t len;
+ char buffer[MAX_DISPLAY];
+
+ SNPRINTF(buffer, MAX_DISPLAY, display_get_text(&v->display));
- len = strlen(v->display);
+ len = strlen(buffer);
if (len > 0) {
- v->display[len-1] = '\0';
+ buffer[len-1] = '\0';
}
-/* If we were entering a scientific number, and we have backspaced over
- * the exponent sign, then this reverts to entering a fixed point number.
- */
-
- if (v->ltr.key_exp && !(strchr(v->display, '+'))) {
+ /* If we were entering a scientific number, and we have backspaced over
+ * the exponent sign, then this reverts to entering a fixed point number.
+ */
+ if (v->ltr.key_exp && !(strchr(buffer, '+'))) {
v->ltr.key_exp = 0;
- v->display[strlen(v->display)-1] = '\0';
+ buffer[strlen(buffer)-1] = '\0';
}
-/* If we've backspaced over the numeric point, clear the pointed flag. */
-
- if (v->ltr.pointed && !(strchr(v->display, '.'))) {
+ /* If we've backspaced over the numeric point, clear the pointed flag. */
+ if (v->ltr.pointed && !(strchr(buffer, '.'))) {
v->ltr.pointed = 0;
}
- display_set_string(v->display);
- MPstr_to_num(v->display, v->base, v->MPdisp_val);
-
- if (v->dtype == FIX) {
- display_set_string(v->display);
- }
+ display_set_string(&v->display, buffer);
+ MPstr_to_num(buffer, v->base, v->MPdisp_val);
}
@@ -683,7 +663,6 @@
{
int MPtemp[MP_SIZE];
int MPexpr[MP_SIZE];
- struct exprm_state *e;
switch (v->syntax) {
case NPA:
@@ -694,17 +673,15 @@
break;
case EXPRS:
- e = get_state();
-
- if (display_is_usable_number(MPexpr)) {
+ if (display_is_usable_number(&v->display, MPexpr)) {
ui_set_statusbar(_("No sane value to store"),
"gtk-dialog-error");
} else {
mp_set_from_mp(v->MPmvals[index], MPtemp);
mp_set_from_mp(MPexpr, v->MPmvals[index]);
- mp_set_from_mp(MPtemp, e->ans);
- display_set_string("Ans");
- display_refresh(-1);
+ mp_set_from_mp(MPtemp, display_get_answer(&v->display));
+ display_set_string(&v->display, "Ans");
+ display_refresh(&v->display, -1);
ui_make_registers();
}
break;
@@ -722,21 +699,24 @@
void
do_expno(void)
{
- v->ltr.pointed = (strchr(v->display, '.') != NULL);
+ char buffer[MAX_DISPLAY];
+
+ SNPRINTF(buffer, MAX_DISPLAY, display_get_text(&v->display));
+
+ v->ltr.pointed = (strchr(buffer, '.') != NULL);
if (!v->ltr.new_input) {
- STRNCPY(v->display, "1.0 +", MAX_LOCALIZED - 1);
+ STRNCPY(buffer, "1.0 +", MAX_LOCALIZED - 1);
v->ltr.new_input = v->ltr.pointed = 1;
} else if (!v->ltr.pointed) {
- STRNCAT(v->display, ". +", 3);
+ STRNCAT(buffer, ". +", 3);
v->ltr.pointed = 1;
} else if (!v->ltr.key_exp) {
- STRNCAT(v->display, " +", 2);
+ STRNCAT(buffer, " +", 2);
}
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);
+ display_set_string(&v->display, buffer);
+ MPstr_to_num(buffer, v->base, v->MPdisp_val);
}
@@ -887,18 +867,8 @@
break;
case KEY_CHANGE_SIGN:
- if (v->ltr.key_exp) {
- if (*v->ltr.exp_posn == '+') {
- *v->ltr.exp_posn = '-';
- } else {
- *v->ltr.exp_posn = '+';
- }
- display_set_string(v->display);
- MPstr_to_num(v->display, v->base, s);
- v->ltr.key_exp = 0;
- } else {
- mp_invert_sign(s, t);
- }
+ // NOTE: Exponential sign changing is completely broken
+ mp_invert_sign(s, t);
break;
}
}
@@ -908,7 +878,7 @@
do_immed(void)
{
do_immedfunc(v->MPdisp_val, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
@@ -916,19 +886,23 @@
do_number(void)
{
int offset;
+ char buffer[MAX_DISPLAY];
+
+ SNPRINTF(buffer, MAX_DISPLAY, display_get_text(&v->display));
if (v->ltr.toclear) {
offset = 0;
v->ltr.toclear = 0;
} else {
- offset = strlen(v->display);
+ offset = strlen(buffer);
}
- if (offset < MAXLINE) {
- SNPRINTF(v->display+offset, MAXLINE-offset, "%s", buttons[v->current].symname);
+
+ if (offset < MAX_DISPLAY) {
+ SNPRINTF(buffer+offset, MAX_DISPLAY-offset, "%s", buttons[v->current].symname);
}
- display_set_string(v->display);
- MPstr_to_num(v->display, v->base, v->MPdisp_val);
+ display_set_string(&v->display, buffer);
+ MPstr_to_num(buffer, v->base, v->MPdisp_val);
v->ltr.new_input = 1;
}
@@ -936,7 +910,6 @@
void
do_numtype(enum num_type n) /* Set number display type. */
{
- struct exprm_state *e;
int ret, MP[MP_SIZE];
v->dtype = n;
@@ -948,14 +921,13 @@
break;
case EXPRS:
- e = get_state();
- ret = display_is_usable_number(MP);
+ ret = display_is_usable_number(&v->display, MP);
if (ret) {
ui_set_statusbar(_("No sane value to convert"),
"gtk-dialog-error");
} else {
- mp_set_from_mp(MP, e->ans);
- display_set_string("Ans");
+ mp_set_from_mp(MP, display_get_answer(&v->display));
+ display_set_string(&v->display, "Ans");
ui_make_registers();
}
clear_undo_history();
@@ -965,7 +937,7 @@
assert(0);
}
- display_refresh(-1);
+ display_refresh(&v->display, -1);
}
@@ -978,10 +950,10 @@
case KEY_START_BLOCK:
if (v->ltr.noparens == 0) {
if (v->ltr.cur_op == -1) {
- v->display[0] = 0;
+ display_set_string(&v->display, "");
ui_set_statusbar(_("Cleared display, prefix without an operator is not allowed"), "");
} else {
- paren_disp(v->ltr.cur_op);
+ paren_disp(&v->display, v->ltr.cur_op);
}
}
v->ltr.noparens++;
@@ -991,13 +963,14 @@
v->ltr.noparens--;
if (!v->ltr.noparens) {
int ret, i = 0;
- while (v->display[i++] != '(') {
+ const char *text = display_get_text(&v->display);
+ while (text[i++] != '(') {
/* do nothing */;
}
- ret = lr_parse(&v->display[i], v->MPdisp_val);
+ ret = lr_parse(&text[i], v->MPdisp_val);
if (!ret) {
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
return;
} else {
ui_set_statusbar(_("Malformed parenthesis expression"),
@@ -1010,7 +983,7 @@
/* Queue event */
break;
}
- paren_disp(v->current);
+ paren_disp(&v->display, v->current);
}
@@ -1023,7 +996,7 @@
break;
case EXPRS:
- if (display_is_usable_number(v->MPmvals[index])) {
+ if (display_is_usable_number(&v->display, v->MPmvals[index])) {
ui_set_statusbar(_("No sane value to store"),
"gtk-dialog-error");
}
@@ -1085,11 +1058,11 @@
{
switch (v->syntax) {
case NPA:
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
break;
case EXPRS:
- display_refresh(-1);
+ display_refresh(&v->display, -1);
break;
default:
@@ -1101,17 +1074,21 @@
void
do_point(void) /* Handle numeric point. */
{
+ char buffer[MAX_DISPLAY];
+
+ SNPRINTF(buffer, MAX_DISPLAY, display_get_text(&v->display));
+
if (!v->ltr.pointed) {
if (v->ltr.toclear) {
- STRNCPY(v->display, ".", MAX_LOCALIZED - 1);
+ STRNCPY(buffer, ".", MAX_LOCALIZED - 1);
v->ltr.toclear = 0;
} else {
- STRCAT(v->display, ".");
+ STRCAT(buffer, ".");
}
v->ltr.pointed = 1;
}
- display_set_string(v->display);
- MPstr_to_num(v->display, v->base, v->MPdisp_val);
+ display_set_string(&v->display, buffer);
+ MPstr_to_num(buffer, v->base, v->MPdisp_val);
}
@@ -1143,7 +1120,7 @@
do_portion(void)
{
do_portionfunc(v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
@@ -1152,12 +1129,11 @@
{
BOOLEAN temp;
double dval;
- struct exprm_state *e;
int MPtemp[MP_SIZE], MPval[MP_SIZE];
switch (v->syntax) {
case NPA:
- MPstr_to_num(v->display, v->base, MPtemp);
+ MPstr_to_num(display_get_text(&v->display), v->base, MPtemp);
dval = mp_cast_to_double(MPtemp);
temp = ibool(dval);
@@ -1169,21 +1145,19 @@
dval = setbool(temp);
mp_set_from_double(dval, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
mp_set_from_mp(v->MPdisp_val, v->MPlast_input);
break;
case EXPRS:
- e = get_state();
- if (display_is_usable_number(MPval) || !is_integer(MPval)) {
+ if (display_is_usable_number(&v->display, MPval) || !is_integer(MPval)) {
ui_set_statusbar(_("No sane value to do bitwise shift"),
"gtk-dialog-error");
break;
}
- calc_shift(MPval, e->ans, count);
-
- display_set_string("Ans");
+ calc_shift(MPval, display_get_answer(&v->display), count);
+ display_set_string(&v->display, "Ans");
break;
default:
Modified: trunk/gcalctool/functions.h
==============================================================================
--- trunk/gcalctool/functions.h (original)
+++ trunk/gcalctool/functions.h Mon Aug 4 06:50:36 2008
@@ -28,8 +28,6 @@
void make_exp(char *number, int t[MP_SIZE]);
-struct exprm_state *get_state(void);
-
void perform_undo(void);
void perform_redo(void);
void clear_undo_history(void);
Modified: trunk/gcalctool/gtk.c
==============================================================================
--- trunk/gcalctool/gtk.c (original)
+++ trunk/gcalctool/gtk.c Mon Aug 4 06:50:36 2008
@@ -475,21 +475,21 @@
static void
reset_display(void)
{
- struct exprm_state *e;
+ int *ans;
switch (v->syntax) {
case NPA:
v->ltr.noparens = 0;
MPstr_to_num("0", DEC, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
clear_undo_history();
break;
case EXPRS:
- e = get_state();
- MPstr_to_num("0", DEC, e->ans);
- display_clear(FALSE);
- display_set_number(e->ans);
+ ans = display_get_answer(&v->display);
+ MPstr_to_num("0", DEC, ans);
+ display_clear(&v->display, FALSE);
+ display_set_number(&v->display, ans);
break;
default:
@@ -571,7 +571,7 @@
set_int_resource(R_ACCURACY, accuracy);
ui_make_registers();
- display_refresh(-1);
+ display_refresh(&v->display, -1);
/* Hide the manual dialog */
gtk_widget_hide(X->spframe);
@@ -889,7 +889,7 @@
switch (v->syntax) {
case NPA:
- MPstr_to_num(v->display, v->base, MP1);
+ MPstr_to_num(display_get_text(&v->display), v->base, MP1);
mpcmim(MP1, MP2);
if (mp_is_equal(MP1, MP2)) {
int toclear = (v->current == KEY_CLEAR_ENTRY)
@@ -916,7 +916,7 @@
break;
case EXPRS:
- if (display_is_usable_number(MP) || !is_integer(MP)) {
+ if (display_is_usable_number(&v->display, MP) || !is_integer(MP)) {
gtk_widget_set_sensitive(X->bit_panel, FALSE);
return;
}
@@ -1259,7 +1259,7 @@
if (response_id == GTK_RESPONSE_OK) {
ch = (char *) gtk_entry_get_text(GTK_ENTRY(X->aframe_ch));
mp_set_from_integer(ch[0], v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
gtk_widget_hide(dialog);
@@ -1343,7 +1343,7 @@
buttons[function].func(arg);
set_bit_panel();
if (v->ltr.new_input && v->dtype == FIX) {
- display_set_string(v->display);
+ display_set_string(&v->display, display_get_text(&v->display));
}
break;
@@ -1740,7 +1740,6 @@
double number;
unsigned long long lval;
int n, MP1[MP_SIZE], index;
- struct exprm_state *e = get_state();
index = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(event_box),
"bit_index"));
@@ -1748,12 +1747,12 @@
switch (v->syntax) {
case NPA:
- MPstr_to_num(v->display, v->base, MP1);
+ MPstr_to_num(display_get_text(&v->display), v->base, MP1);
break;
case EXPRS: {
- int ret = display_is_usable_number(e->ans);
+ int ret = display_is_usable_number(&v->display, display_get_answer(&v->display));
assert(!ret);
- mp_set_from_mp(e->ans, MP1);
+ mp_set_from_mp(display_get_answer(&v->display), MP1);
}
break;
default:
@@ -1775,12 +1774,12 @@
switch (v->syntax) {
case NPA:
mp_set_from_double(number, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
break;
case EXPRS:
- mp_set_from_double(number, e->ans);
- display_set_string("Ans");
- display_refresh(-1);
+ mp_set_from_double(number, display_get_answer(&v->display));
+ display_set_string(&v->display, "Ans");
+ display_refresh(&v->display, -1);
break;
default:
assert(FALSE);
@@ -2207,7 +2206,7 @@
case NPA:
ret = lr_parse((char *) text, v->MPdisp_val);
if (!ret) {
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
} else {
ui_set_statusbar(_("Clipboard contained malformed calculation"),
"gtk-dialog-error");
@@ -2215,8 +2214,8 @@
break;
case EXPRS:
- display_insert((char *) text, get_cursor()); // FIXME: Move out of gtk.c
- display_refresh(-1);
+ display_insert(&v->display, (char *) text, get_cursor()); // FIXME: Move out of gtk.c
+ display_refresh(&v->display, -1);
break;
default:
@@ -2269,7 +2268,7 @@
redo_cb(GtkWidget *widget)
{
perform_redo();
- display_refresh(-1);
+ display_refresh(&v->display, -1);
}
@@ -2376,7 +2375,7 @@
*
* (unless we are in Scientific mode with Decimal numeric base and Fixed).
*/
- if (display_is_result() &&
+ if (display_is_result(&v->display) &&
((v->modetype != SCIENTIFIC) ||
(v->dtype == FIX && v->base == DEC))) {
v->modetype = mode;
Modified: trunk/gcalctool/lr_parser.c
==============================================================================
--- trunk/gcalctool/lr_parser.c (original)
+++ trunk/gcalctool/lr_parser.c Mon Aug 4 06:50:36 2008
@@ -26,7 +26,7 @@
/* TODO: This file is almost identical to ce-parser. */
int
-lr_parse_(char *expression, int result[MP_SIZE], int flags)
+lr_parse_(const char *expression, int result[MP_SIZE], int flags)
{
int ret = 0;
@@ -61,7 +61,7 @@
int
-lr_parse(char *expression, int result[MP_SIZE])
+lr_parse(const char *expression, int result[MP_SIZE])
{
return(lr_parse_(expression, result, ANS));
}
Modified: trunk/gcalctool/lr_parser.h
==============================================================================
--- trunk/gcalctool/lr_parser.h (original)
+++ trunk/gcalctool/lr_parser.h Mon Aug 4 06:50:36 2008
@@ -40,7 +40,7 @@
int lrerror(); /* Dummy definition. */
int lrparse(); /* Dummy definition. */
int ceerror(char *s);
-int lr_parse(char *expression, int result[MP_SIZE]);
+int lr_parse(const char *expression, int result[MP_SIZE]);
int lr_udf_parse(char *expression);
void reset_lr_tokeniser();
Modified: trunk/gcalctool/lr_parser.y
==============================================================================
--- trunk/gcalctool/lr_parser.y (original)
+++ trunk/gcalctool/lr_parser.y Mon Aug 4 06:50:36 2008
@@ -117,7 +117,7 @@
udf:
value '=' {
cp($1, v->MPdisp_val);
- display_set_number(v->MPdisp_val);
+ display_set_number(&v->display, v->MPdisp_val);
}
| value '=' tSTO '(' tINUMBER ')' {
int val;
@@ -130,8 +130,8 @@
do_sto_reg(val, $1);
}
| tCLR {
- display_reset();
- display_set_number(v->MPdisp_val);
+ display_reset(&v->display);
+ display_set_number(&v->display, v->MPdisp_val);
}
;
Modified: trunk/gcalctool/mp.c
==============================================================================
--- trunk/gcalctool/mp.c (original)
+++ trunk/gcalctool/mp.c Mon Aug 4 06:50:36 2008
@@ -3155,7 +3155,7 @@
else goto L70;
L10:
- display_set_error(_("Negative X and non-integer Y not supported"));
+ display_set_error(&v->display, _("Negative X and non-integer Y not supported"));
goto L50;
/* HERE X IS ZERO, RETURN ZERO IF Y POSITIVE, OTHERWISE ERROR */
Modified: trunk/gcalctool/mpmath.c
==============================================================================
--- trunk/gcalctool/mpmath.c (original)
+++ trunk/gcalctool/mpmath.c Mon Aug 4 06:50:36 2008
@@ -1033,7 +1033,7 @@
*/
void
-MPstr_to_num(char *str, enum base_type base, int *MPval)
+MPstr_to_num(const char *str, enum base_type base, int *MPval)
{
char *optr;
int MP1[MP_SIZE], MP2[MP_SIZE], MPbase[MP_SIZE];
Modified: trunk/gcalctool/mpmath.h
==============================================================================
--- trunk/gcalctool/mpmath.h (original)
+++ trunk/gcalctool/mpmath.h Mon Aug 4 06:50:36 2008
@@ -77,7 +77,7 @@
int
is_natural(int MPnum[MP_SIZE]);
-void MPstr_to_num(char *, enum base_type, int *);
+void MPstr_to_num(const char *, enum base_type, int *);
void make_fixed(char *, int, int *, int, int, int);
void make_number(char *, int, int *, int, int);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]