|
From: <ho...@us...> - 2004-01-20 01:33:44
|
Update of /cvsroot/ganc/ganc/src
In directory sc8-pr-cvs1:/tmp/cvs-serv28642/src
Modified Files:
Makefile.am callbacks.c callbacks.h evaluate.c interface.c
main.c parser_stuff.c syntax.y
Added Files:
display.c history.c variables.c
Removed Files:
reader_communication.c reader_stuff.c terminal_stuff.c
Log Message:
Changed maaaaaaaaaaany things:
- Eliminated dependency on libzvt and readline, now the whole thing is
pure gtk (using GtkTextView for the display) and it looks nice
- Thus, now there's no 'forking' around and no pipes
- Major rearrangement of files (yes again!)
Added: display.c history.c variables.c defines.h parser.h
Removed: reader_communication.c reader_stuff.c terminal_stuff.c
evaluate_stuff.h mytypes.h pipe_stuff.h
- Now, and so far, is not possible to compile text only version
--- NEW FILE: display.c ---
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "include/defines.h"
#include "include/functions.h"
/***********************************************************************
*
* External Variables
*
***********************************************************************/
extern GtkTextBuffer *display_text_buffer;
extern GtkWidget *display;
/***********************************************************************
*
* Global Variables
*
***********************************************************************/
GtkTextMark *start_mark;
GtkTextMark *end_mark;
GtkTextMark *insert_mark;
GtkTextMark *selection_mark;
GtkTextMark *cursor_mark;
/***********************************************************************
*
* Local Variables
*
***********************************************************************/
#define MAX_NUMBER_LINES 100
/***********************************************************************
*
* Local Variables
*
***********************************************************************/
static const char prompt[]="> ";
static char *parse_errors[]={ // Texts of parse errors
"unknown variable", // 1
"syntax error",
"parse error",
"isolated decimal dot",
"", // 5
"base out of range",
"base conversion error",
"invalid argument to LN",
"invalid argument to LOG",
"invalid argument to factorial", // 10
"invalid argument to SQRT",
"invalid argument to ASIN",
"invalid argument to ACOS",
"division by zero",
"overflow", // 15
"NaN",
"assignment of constant",
"illegal identifier",
"illegal constant"
};
/***********************************************************************
*
* Local Functions
*
***********************************************************************/
static void LimitNumberEntries (void);
static char *PreparePrintedResult (void);
static int *ExtractSublines (char *line, int *num_sublines);
static int LineIsEmpty (char *line);
//
// prints prompt in display
//
void PrintPrompt (GtkTextIter *point_iter)
{
gtk_text_buffer_insert (display_text_buffer, point_iter, prompt, -1);
}
//
//
//
void TravelEntryHistory (guint keyval)
{
char *line, *line2=NULL;
GtkTextIter start_iter, end_iter;
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &end_iter, end_mark);
line= gtk_text_buffer_get_text (display_text_buffer, &start_iter, &end_iter, FALSE);
if (keyval==GDK_Up) {
line2= PreviousHistory (line);
} else if (keyval==GDK_Down) {
line2= NextHistory (line);
} else if (keyval==GDK_Page_Up) {
line2= PreviousHistory (line);
} else if (keyval==GDK_Page_Down) {
line2= NextHistory (line);
}
free (line);
if (line2!=NULL) {
gtk_text_buffer_delete (display_text_buffer, &start_iter, &end_iter);
gtk_text_buffer_insert (display_text_buffer, &start_iter, line2, -1);
gtk_text_buffer_place_cursor (display_text_buffer, &start_iter);
}
}
//
// Inserts text in display at cursor's position
// checks insert point is not in forbidden zone
//
void InsertText (char *text)
{
GtkTextIter start_iter, sel_iter, insert_iter;
gtk_text_buffer_get_selection_bounds (display_text_buffer, &sel_iter, &insert_iter);
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
if (gtk_text_iter_compare (&sel_iter, &start_iter)<0 ||
gtk_text_iter_compare (&insert_iter, &start_iter)<0) {
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, end_mark);
gtk_text_buffer_place_cursor (display_text_buffer, &insert_iter);
}
gtk_text_buffer_insert_at_cursor (display_text_buffer, text, -1);
}
//
// deletes the input line
//
void ClearInputLine (void)
{
GtkTextIter start_iter, end_iter;
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &end_iter, end_mark);
gtk_text_buffer_delete (display_text_buffer, &start_iter, &end_iter);
gtk_text_buffer_place_cursor (display_text_buffer, &start_iter);
}
//
//
//
static void LimitNumberEntries (void)
{
int lines;
GtkTextIter iter, start_iter;
GtkTextTag *result_tag;
lines= gtk_text_buffer_get_line_count (display_text_buffer);
if (lines>MAX_NUMBER_LINES) {
gtk_text_buffer_get_iter_at_offset (display_text_buffer, &start_iter, 0);
gtk_text_buffer_get_iter_at_offset (display_text_buffer, &iter, 0);
result_tag= gtk_text_tag_table_lookup (gtk_text_buffer_get_tag_table (display_text_buffer), "result");
gtk_text_iter_forward_to_tag_toggle (&iter, result_tag); // start result
gtk_text_iter_forward_to_tag_toggle (&iter, result_tag); // end result
gtk_text_buffer_delete (display_text_buffer, &start_iter, &iter);
}
}
//
// prepare text that will be outputed as output
//
static char *PreparePrintedResult (void)
{
unsigned long result;
int digits, i, d, aux;
unsigned int base;
char *output_text;
int printbase, extra_size=0;
base= GetResultOutputFormat (OUTPUT_FORMAT_BASE);
printbase= GetResultOutputFormat (OUTPUT_FORMAT_PRINTBASE);
if (printbase) extra_size= 3;
if (base==10) { // base 10 -> EASY
output_text= (char *) malloc (50 + extra_size);
sprintf (output_text, "%15.10Lg\n", ResultValue ());
} else { // other base
result= ResultValue ();
// calculate number of digits number 'result' takes in base 'base'
digits= (int) (log (result)/log (base) + 1);
// malloc: 2 for '\n\0' and 2 for safety margin
output_text= (char *) malloc (digits + 2 + 2 + extra_size);
i= 0;
while (result >= base) {
d= result % base;
if (d<10) output_text[i++]= d + '0';
else output_text[i++]= (d - 10) + 'a';
result/= base;
}
if (result<10) output_text[i]= result + '0';
else output_text[i]= (result - 10) + 'a';
output_text[i + 1]= '\n';
output_text[i + 2]= '\0';
d= 0;
while (d<i) {
aux= output_text[i];
output_text[i]= output_text[d];
output_text[d]= aux;
--i;
d++;
}
}
if (printbase) {
i= strlen (output_text) - 1;
if (base<10) sprintf (output_text + i, "_%1d\n", base);
else sprintf (output_text + i, "_%2d\n", base);
}
return output_text;
}
//
// Extracts position of sublines (indicated by ';' character)
// Returns array with positions of ';' characters, i.e. ends of sublines
// and number of sublines found (minimum 1) in 'num_sublines'
// array contains at least one element, i.e. end of line
// Returned array needs to be freed later
//
static int *ExtractSublines (char *line, int *num_sublines)
{
int *sublines;
int count, i, j, size;
// store size of line
size= strlen (line);
// find sub-lines embeded in input
// run through the input to find ';' characters, store positions in 'sublines'
for (i= 0, count= 0; i<size; ++i) if (line[i]==';') ++count;
++count; // at least 1: case of no sub-lines
sublines= malloc (count*sizeof (int));
// If some sub-lines are found, store their positions
if (count>1) { // there were some ';'
for (i= 0, j= 0; i<size; ++i)
if (line[i]==';') {
sublines[j]= i;
++j;
}
}
// consider end of input as the end of another sub-line
// it makes the case with no sub-lines work
sublines[count - 1]= size;
*num_sublines= count;
return sublines;
}
//
// returns 1 if line is empty (0 or more spaces); returns 0 otherwise
//
static int LineIsEmpty (char *line)
{
int i;
i= strlen (line) - 1;
while (i>=0 && line[i]==' ') --i;
if (i>=0) return 0;
return 1;
}
//
// called when expression is ready to be evaluated (RETURN pressed)
//
void ExpressionReady (void)
{
GtkTextIter point_iter, start_iter;
gchar *line, *extra;
int error;
int num_sublines, start, i;
int *sublines = NULL;
char *output_text;
int perror, size;
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
gtk_text_buffer_get_iter_at_mark (display_text_buffer, &point_iter, end_mark);
line= gtk_text_buffer_get_text (display_text_buffer, &start_iter, &point_iter, FALSE);
// check line is not empty
if (LineIsEmpty (line)) return;
// add current line to history
AddHistory (line);
gtk_text_buffer_insert (display_text_buffer, &point_iter, "\n", -1);
// extract sub-lines from input
sublines= ExtractSublines (line, &num_sublines);
start= 0; // stores starting position of sub-line
for (i= 0; i<num_sublines; ++i) {
line[sublines[i]]= '\0';
error= ParseTypedExpression (line + start);
if (error) {
// see if there's any extra text to add to error output
perror= ParseError ();
extra= ParseErrorExtra ();
if (extra==NULL) {
size= 20;
size+= strlen (parse_errors[perror - 1]);
output_text= (char *) malloc (size);
sprintf (output_text, "error: %s\n", parse_errors[perror - 1]);
} else {
size= 30;
size+= strlen (parse_errors[perror - 1]);
size+= strlen (extra);
output_text= (char *) malloc (size);
sprintf (output_text, "error: %s: %s\n",
parse_errors[perror - 1], extra);
free (extra);
}
gtk_text_buffer_insert_with_tags_by_name
(display_text_buffer, &point_iter, output_text, -1, "result", "error", NULL);
} else { // No error, print result
output_text= PreparePrintedResult ();
gtk_text_buffer_insert_with_tags_by_name
(display_text_buffer, &point_iter, output_text, -1, "result", NULL);
}
// print output_text (it should already end in '\n') using tag 'result'
// free memory of output text
free (output_text);
// set start of next subline
start= sublines[i] + 1;
}
// free memory
free (sublines);
g_free (line);
PrintPrompt (&point_iter);
// set 'start' and 'end' marks and position cursor
gtk_text_buffer_move_mark (display_text_buffer, start_mark, &point_iter);
gtk_text_buffer_move_mark (display_text_buffer, end_mark, &point_iter);
gtk_text_buffer_place_cursor (display_text_buffer, &point_iter);
// scroll display to show cursor (if necessary)
gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (display), insert_mark,
0., FALSE, 0., 0.);
// make sure number of entries in display doesn't exceed a maximum
LimitNumberEntries ();
}
/*
Local Variables:
c-file-style: "gnu"
c-file-offsets: ((case-label . +))
End:
*/
--- NEW FILE: history.c ---
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
/***********************************************************************
*
* Local Types
*
***********************************************************************/
struct history_struct {
char *line; // contains name of variable
struct history_struct *ant; // previous member in list
struct history_struct *sig;
};
typedef struct history_struct history_type;
/***********************************************************************
*
* Local Variables
*
***********************************************************************/
static history_type *history_current; // current displayed entry
static history_type *history_first; // first entry in history
static history_type *history_last; // tail of history
static int history_size;
static int history_size_max=100;
//
// initialize history
//
void InitializeHistory (void)
{
history_type *h;
h= (history_type *) malloc (sizeof (history_type));
h->line= strdup ("");
h->ant= NULL;
h->sig= NULL;
history_current= history_last= history_first= h;
history_size= 1;
}
//
// add another entry (line) to the history
//
void AddHistory (char *text)
{
history_type *h;
// if text already in last entry is diff than given text make a new copy
if (strcmp (history_last->line, text)!=0) {
free (history_last->line);
history_last->line= strdup (text);
}
// if entering item is equal to previous in history, ignore this entry
if (history_last->ant!=NULL && strcmp (history_last->ant->line, text)==0) {
free (history_last->line);
history_last->line= strdup ("");
history_current= history_last;
return;
}
// create new entry
h= (history_type *) malloc (sizeof (history_type));
h->line= strdup ("");
h->ant= history_last;
h->sig= NULL;
history_last->sig= h;
// update control variables
history_current= history_last= h;
// if history is at maximum size, eliminate first element
if (history_size==history_size_max) {
h= history_first->sig;
h->ant= NULL;
free (history_first->line);
free (history_first);
history_first= h;
} else ++history_size;
}
//
// goes to previous item in history (if any)
// given text is stored if is not the same as it was before
// returns a pointer to the text of previous item in history (don't free!!)
//
char *PreviousHistory (char *text)
{
// if we're at the first entry, return NULL
if (history_current->ant==NULL) return NULL;
// if given text is diff than text in current entry, copy new
if (strcmp (history_current->line, text)!=0) {
free (history_current->line);
history_current->line= strdup (text);
}
history_current= history_current->ant;
return history_current->line;
}
//
// goes to next item in history (if any)
// given text is stored if is not the same as it was before
// returns a pointer to the text of next item in history (don't free!!)
//
char *NextHistory (char *text)
{
// if we're at the last entry, return NULL
if (history_current->sig==NULL) return NULL;
// if given text is diff than text in current entry, copy new
if (strcmp (history_current->line, text)!=0) {
free (history_current->line);
history_current->line= strdup (text);
}
history_current= history_current->sig;
return history_current->line;
}
//
// removes history from memory (frees the memory)
//
void RemoveHistory (void)
{
history_type *h;
h= history_first;
while (h!=NULL) {
history_first= h->sig;
free (h->line);
free (h);
h= history_first;
}
}
/*
Local Variables:
c-file-style: "gnu"
c-file-offsets: ((case-label . +))
End:
*/
--- NEW FILE: variables.c ---
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "include/defines.h"
#include "include/functions.h"
/***********************************************************************
*
* Local Types
*
***********************************************************************/
// Name list used to keep the list of defined variables (typedef in mytypes.h)
struct var_list_struct {
char *name; // contains name of variable
short attr; // attributes of variable
VALUE_TYPE value; // value of variable
struct var_list_struct *ant; // previous member in list
};
typedef struct var_list_struct var_list;
/***********************************************************************
*
* Local Functions
*
***********************************************************************/
static int ValidVariableName (char *name);
static var_list *FindVariable (char *name);
static void DestroyVariableList (var_list *ini);
static void CreateNewVariable (char *new_name, VALUE_TYPE value, short attributes);
/***********************************************************************
*
* Local Variables
*
***********************************************************************/
static var_list *var_list_ini; // Initial node of variable list
static var_list *copy_var_list_ini;
// system variables
static struct {
int ibase;
int obase;
} system_vars;
//
// Checks whether 'name' is a valid variable identifier
// Returns: 1 if name is ok, 0 if name can't be a variable
//
static int ValidVariableName (char *name)
{
int i=1;
int ok=0;
if (isalpha (name[0]) || name[0]=='_') {
while (isalpha (name[i]) || isdigit (name[i]) || name[i]=='_') ++i;
if (name[i]=='\0') ok= 1;
}
return ok;
}
// Looks for a variable name in the variable list
// If variable found returns the address of its entry in var_list
// If not found returns NULL
static var_list *FindVariable (char *name)
{
var_list *v;
int found=0;
v= var_list_ini;
while (v!=NULL && !found) {
if (strcmp (v->name, name)==0) found= 1;
else v= v->ant;
}
if (!found) return NULL;
return v;
}
//
// Destroys the given variable list (the initial node is given)
//
static void DestroyVariableList (var_list *ini)
{
var_list *v;
while (ini!=NULL) {
free (ini->name);
v= ini->ant;
free (ini);
ini= v;
}
}
// Creates a new variable and adds it to the list
// It doesn't check if the variable exists, it's the programmer responsibility
// not to duplicate variables
static void CreateNewVariable (char *new_name, VALUE_TYPE value, short attributes)
{
var_list *v;
if (ValidVariableName (new_name)) { // new_name is a valid var identifier
v= malloc (sizeof (var_list));
v->name= strdup (new_name);
v->attr= attributes;
v->value= value;
v->ant= var_list_ini;
var_list_ini= v;
} else { // new_name is not a valid var identifier -> ERROR
NotifyError (PERROR_ILLEGAL_IDENTIFIER, new_name);
}
}
//
// Initialize variable list by setting top item of list to NULL
//
void InitMainVarList (void)
{
// variable list is empty to start with
var_list_ini= NULL;
// Add default variables to variable list
CreateNewVariable ("pi", CONSTANT_PI, VAR_ATTR_READONLY);
CreateNewVariable ("PI", CONSTANT_PI, VAR_ATTR_READONLY);
CreateNewVariable ("ans", (VALUE_TYPE) 0., VAR_ATTR_READONLY); // ans (previous answer)
CreateNewVariable ("ibase", (VALUE_TYPE) 10., VAR_ATTR_SYSTEM); // ibase (input base)
CreateNewVariable ("obase", (VALUE_TYPE) 10., VAR_ATTR_SYSTEM); // obase (output base)
}
//
// Destroy variable list (called at program exit to clean up)
//
void DestroyMainVarList (void)
{
DestroyVariableList (var_list_ini);
}
//
// Evaluates a variable and returns its value, if not defined call error
//
VALUE_TYPE EvaluateVariable (char *name)
{
var_list *v;
VALUE_TYPE value;
v= FindVariable (name);
if (v==NULL) { // New variable, ERROR
NotifyError (PERROR_UNKNOWN_VAR, name); // indicate error hapenned
value= 0.;
} else { // existing variable, return its value
value= v->value;
CheckNumber (value); // check value is well behavied
}
return value;
}
// Assigns a value to a variable, if it's a new variable creates it and
// adds it to the list
// Returns the newly updated value of the variable
VALUE_TYPE AssignVariable (char *name, VALUE_TYPE value)
{
var_list *v;
v= FindVariable (name);
if (v==NULL) { // new variable, create new one
CreateNewVariable (name, value, VAR_ATTR_NORMAL);
} else { // old variable, just assign new value
if (v->attr&VAR_ATTR_READONLY) { // readonly variable
NotifyError (PERROR_ASSIGNMENT_CONSTANT, NULL);
value= (VALUE_TYPE) 0.;
return value;
}
if (v->attr&VAR_ATTR_SYSTEM) { // system variable
if (strcmp (v->name, "ibase")==0) SetSystemVariable (SYSTEMVAR_IBASE, (int) value);
if (strcmp (v->name, "obase")==0) SetSystemVariable (SYSTEMVAR_OBASE, (int) value);
}
v->value= value;
}
return value;
}
//
// Makes a copy of current variable list
//
void MakeCopyVariableList (void)
{
var_list *copy;
var_list *v;
copy_var_list_ini= NULL;
v= var_list_ini;
while (v!=NULL) {
// make copy of v
copy= malloc (sizeof (var_list));
copy->name= strdup (v->name);
copy->attr= v->attr;
copy->value= v->value;
copy->ant= copy_var_list_ini;
copy_var_list_ini= copy;
// next v
v= v->ant;
}
}
//
// swaps main and copied variable list
//
void SwapVariableLists (void)
{
var_list *v;
v= var_list_ini;
var_list_ini= copy_var_list_ini;
copy_var_list_ini= v;
}
//
// destroys copied variable list
//
void DestroyCopyVariableList (void)
{
DestroyVariableList (copy_var_list_ini);
}
//
// Checks 'entry' to see if it's a known variable
// Returns: 1 if found, 0 if not found
//
int CheckVariable (char *entry)
{
var_list *v;
int found=0;
v= var_list_ini;
while (v!=NULL && !found) {
if (strcmp (v->name, entry)==0) found= 1;
else v= v->ant;
}
return found;
}
//
// Updates value of 'ans' variable
//
void UpdateAnswerVariable (void)
{
var_list *v;
// find 'ans' first
v= FindVariable ("ans");
// update value
v->value= ResultValue ();
}
//
// called after a succesful evaluation of an expression
// updates system variables in case they have been changed by user
//
void UpdateSystemVariables (void)
{
var_list *v;
v= FindVariable ("ibase");
system_vars.ibase= (int) v->value;
v= FindVariable ("obase");
system_vars.ibase= (int) v->value;
}
//
// set system variable
//
void SetSystemVariable (int which, int value)
{
switch (which) {
case SYSTEMVAR_IBASE:
if (value<2 || value>36) NotifyError (PERROR_BASE_RANGE, NULL);
system_vars.ibase= value;
break;
case SYSTEMVAR_OBASE:
if (value<2 || value>36) NotifyError (PERROR_BASE_RANGE, NULL);
system_vars.obase= value;
break;
}
}
//
// get system variable
//
int GetSystemVariable (int which)
{
int value=0;
switch (which) {
case SYSTEMVAR_IBASE:
value= system_vars.ibase;
break;
case SYSTEMVAR_OBASE:
value= system_vars.obase;
break;
}
return value;
}
//
// Initialize system variables
//
void InitializeSystemVars (void)
{
system_vars.ibase= 10;
system_vars.obase= 10;
}
/*
Local Variables:
c-file-style: "gnu"
c-file-offsets: ((case-label . +))
End:
*/
Index: Makefile.am
===================================================================
RCS file: /cvsroot/ganc/ganc/src/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Makefile.am 7 Dec 2003 21:52:22 -0000 1.3
--- Makefile.am 20 Jan 2004 01:33:40 -0000 1.4
***************
*** 10,14 ****
## GUI extra sources and headers
if BUILD_GUI
! GUISRC = support.c interface.c callbacks.c reader_communication.c
GUIHDR = callbacks.h interface.h support.h
else
--- 10,14 ----
## GUI extra sources and headers
if BUILD_GUI
! GUISRC = support.c interface.c callbacks.c
GUIHDR = callbacks.h interface.h support.h
else
***************
*** 18,23 ****
! ganc_SOURCES = main.c reader_stuff.c evaluate.c syntax.y parser_stuff.c \
! terminal_stuff.c $(GUISRC)
ganc_LDADD = @LIBS@ @PACKAGE_LIBS@
--- 18,23 ----
! ganc_SOURCES = main.c display.c evaluate.c syntax.y parser_stuff.c \
! history.c variables.c $(GUISRC)
ganc_LDADD = @LIBS@ @PACKAGE_LIBS@
Index: callbacks.c
===================================================================
RCS file: /cvsroot/ganc/ganc/src/callbacks.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** callbacks.c 12 Dec 2003 23:57:37 -0000 1.9
--- callbacks.c 20 Jan 2004 01:33:40 -0000 1.10
***************
*** 9,17 ****
#include <string.h>
#include "include/functions.h"
#include "callbacks.h"
#include "interface.h"
#include "support.h"
- #include "pipe_stuff.h"
--- 9,17 ----
#include <string.h>
+ #include "include/defines.h"
#include "include/functions.h"
#include "callbacks.h"
#include "interface.h"
#include "support.h"
***************
*** 25,29 ****
--- 25,44 ----
extern GtkWidget *inv_button;
extern GtkWidget *hyp_button;
+ extern GtkTextBuffer *display_text_buffer;
+ extern GtkTextView *display;
+ extern GtkTextMark *start_mark;
+ extern GtkTextMark *end_mark;
+ extern GtkTextMark *insert_mark;
+ extern GtkTextMark *selection_mark;
+ extern GtkTextMark *cursor_mark;
+
+
+ /***********************************************************************
+ *
+ * Local Variables
+ *
+ ***********************************************************************/
+ static int user_action=0;
***************
*** 44,55 ****
void button_clicked (GtkWidget *widget, gpointer data)
{
! char *text;
! int i, pos;
! /* GdkEventKey event; */
const char *label;
int found=0;
label= gtk_button_get_label (GTK_BUTTON (widget));
- text= (char *) malloc (strlen (label) + 3);
strcpy (text, label);
--- 59,68 ----
void button_clicked (GtkWidget *widget, gpointer data)
{
! int i;
const char *label;
+ char text[20];
int found=0;
label= gtk_button_get_label (GTK_BUTTON (widget));
strcpy (text, label);
***************
*** 57,64 ****
--- 70,79 ----
if (!found && strcmp (text, "EE")==0 && ++found) strcpy (text, "E");
if (!found && strcmp (text, "1/x")==0 && ++found) strcpy (text, "^-1");
+ // add space to these ones
if (!found && (strcmp (text, "exp")==0 || strcmp (text, "ln")==0 ||
strcmp (text, "sqrt")==0 || strcmp (text, "log")==0)
&& ++found)
strcpy (text + strlen (text), " ");
+ // check inv or hyp for these ones
if (!found && (strcmp (text, "sin")==0 || strcmp (text, "cos")==0 ||
strcmp (text, "tan")==0) && ++found) {
***************
*** 73,76 ****
--- 88,92 ----
strcpy (text + strlen (text), " ");
}
+ // modify these ones
if (!found && strcmp (text, "x^2")==0 && ++found) strcpy (text, "^2");
if (!found && strcmp (text, "10^x")==0 && ++found) strcpy (text, "10^");
***************
*** 78,113 ****
if (!found && strcmp (text, "x!")==0 && ++found) strcpy (text, "!");
! SendInputRequest (PIPE_REQUEST_TEXT, text);
!
! /*
! // emulate event to send text as input to terminal
! event.type= GDK_KEY_PRESS;
! event.window= widget->window;
! event.send_event= FALSE;
! event.time= GDK_CURRENT_TIME;
! event.state= 0;
! event.keyval= GDK_5; // text inserted is in event.string
! event.length= strlen (text);
! event.string= strdup (text);
! gtk_widget_event (terminal, (GdkEvent *) &event);
! */
!
! /*pos= gtk_editable_get_position (GTK_EDITABLE (entry));
! gtk_editable_insert_text (GTK_EDITABLE (entry), text, strlen (text), &pos);
! gtk_editable_set_position (GTK_EDITABLE (entry), pos);*/
! //pos= gtk_editable_get_position (GTK_EDITABLE (textbox));
! pos= 0;
! //gtk_editable_insert_text (GTK_EDITABLE (textbox), text, strlen (text), &pos);
! // gtk_editable_set_position (GTK_EDITABLE (textbox), pos);
!
! // g_print ("Button %s pressed\n", (char *) data);
if (GTK_TOGGLE_BUTTON (inv_button)->active)
g_signal_emit_by_name (GTK_OBJECT (inv_button), "clicked");
- //gtk_signal_emit_by_name (GTK_OBJECT (inv_button), "clicked");
if (GTK_TOGGLE_BUTTON (hyp_button)->active)
g_signal_emit_by_name (GTK_OBJECT (hyp_button), "clicked");
- //gtk_signal_emit_by_name (GTK_OBJECT (hyp_button), "clicked");
- free (text);
- //gtk_widget_grab_focus (entry);
}
--- 94,104 ----
if (!found && strcmp (text, "x!")==0 && ++found) strcpy (text, "!");
! InsertText (text);
!
! // untoggle 'inv' and 'hyp' buttons if set
if (GTK_TOGGLE_BUTTON (inv_button)->active)
g_signal_emit_by_name (GTK_OBJECT (inv_button), "clicked");
if (GTK_TOGGLE_BUTTON (hyp_button)->active)
g_signal_emit_by_name (GTK_OBJECT (hyp_button), "clicked");
}
***************
*** 119,138 ****
void on_button_exe_clicked (GtkWidget *button, gpointer user_data)
{
! /* GdkEventKey event;
! char ret[]="\n";*/
!
! SendInputRequest (PIPE_REQUEST_EXECUTE, NULL);
! /*
! // emulate event to send text as input to terminal
! event.type= GDK_KEY_PRESS;
! event.window= GTK_WIDGET (button)->window;
! event.send_event= FALSE;
! event.time= GDK_CURRENT_TIME;
! event.state= 0;
! event.keyval= GDK_Return;
! event.length= 0;
! event.string= strdup (ret);
! gtk_widget_event (terminal, (GdkEvent *) &event);
! */
}
--- 110,114 ----
void on_button_exe_clicked (GtkWidget *button, gpointer user_data)
{
! ExpressionReady ();
}
***************
*** 151,219 ****
//
! // Callback to clear button
//
! void on_button_clear_clicked (GtkWidget *widget, gpointer data)
{
! /*GdkEventKey event;
! char text='\0';*/
! SendInputRequest (PIPE_REQUEST_BACKSPACE, NULL);
! /*
! // emulate event to send text as input to terminal
! event.type= GDK_KEY_PRESS;
! event.window= widget->window;
! event.send_event= FALSE;
! event.state= 0;
! event.time= GDK_CURRENT_TIME;
! event.keyval= GDK_BackSpace;
! event.length= strlen (&text);
! event.string= strdup (&text);
! gtk_widget_event (terminal, (GdkEvent *) &event);
! */
}
//
! // Callback to AC button (all clear). It clears the whole display screen
//
! void on_button_AC_clicked (GtkWidget *widget, gpointer data)
{
! /*GdkEventKey event;
! char text[]=" ";*/
!
! // send input request to clear line
! SendInputRequest (PIPE_REQUEST_CLEAR, NULL);
! /*
! // emulate event to send text as input to terminal
! event.type= GDK_KEY_PRESS;
! event.window= widget->window;
! event.send_event= FALSE;
!
! // send C-a ('a' with control mask set)
! event.state= GDK_CONTROL_MASK;
! event.time= GDK_CURRENT_TIME;
! event.keyval= GDK_a;
! text[0]= (char) 1; // this is the text produced by C-a
! event.length= strlen (text);
! event.string= strdup (text);
! gtk_widget_event (terminal, (GdkEvent *) &event);
! // send C-k ('k' with control mask set)
! event.time= GDK_CURRENT_TIME;
! event.keyval= GDK_k;
! text[0]= (char) 11; // this is the text produced by C-k
! event.string= strdup (text);
! gtk_widget_event (terminal, (GdkEvent *) &event);
! */
}
! // Function that creates a VTE_TERMINAL widget
! // Necessary because widget is defined as custom in glade
! // The actual 'terminal' widget is created in terminal_stuff.c
! GtkWidget* create_display (gchar *widget_name, gchar *string1, gchar *string2,
! gint int1, gint int2)
{
! return (terminal);
}
--- 127,184 ----
//
! // Callback to BackSpace button
//
! void on_button_bs_clicked (GtkWidget *widget, gpointer data)
{
! GtkTextIter sel_iter, insert_iter, start_iter;
! gtk_text_buffer_get_selection_bounds (display_text_buffer, &sel_iter, &insert_iter);
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! // if either mark is before start, just put insert at end and do nothing
! if (gtk_text_iter_compare (&sel_iter, &start_iter)<0 ||
! gtk_text_iter_compare (&insert_iter, &start_iter)<0) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, end_mark);
! gtk_text_buffer_place_cursor (display_text_buffer, &insert_iter);
! gtk_text_buffer_get_selection_bounds (display_text_buffer, &sel_iter, &insert_iter);
! }
! // if nothing selected move sel_iter one backward
! if (gtk_text_iter_equal (&sel_iter, &insert_iter) &&
! gtk_text_iter_compare (&sel_iter, &start_iter)>0) {
! gtk_text_iter_backward_char (&sel_iter);
! }
! gtk_text_buffer_delete (display_text_buffer, &sel_iter, &insert_iter);
}
//
! // Callback to DEL button
//
! void on_button_del_clicked (GtkWidget *widget, gpointer data)
{
! GtkTextIter sel_iter, insert_iter, start_iter;
! gtk_text_buffer_get_selection_bounds (display_text_buffer, &sel_iter, &insert_iter);
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! // if either mark is before start, just put insert at end and do nothing
! if (gtk_text_iter_compare (&sel_iter, &start_iter)<0 ||
! gtk_text_iter_compare (&insert_iter, &start_iter)<0) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, end_mark);
! gtk_text_buffer_place_cursor (display_text_buffer, &insert_iter);
! } else {
! // if nothing selected move insert_iter one forward
! if (gtk_text_iter_equal (&sel_iter, &insert_iter)) {
! gtk_text_iter_forward_char (&insert_iter);
! }
! gtk_text_buffer_delete (display_text_buffer, &sel_iter, &insert_iter);
! }
}
! //
! // Callback to AC button (all clear). It clears the whole display screen
! //
! void on_button_AC_clicked (GtkWidget *widget, gpointer data)
{
! ClearInputLine ();
}
***************
*** 242,249 ****
//
! // handle normal keys, notify reader of incoming input
//
! return FALSE; // let the normal process go through
}
--- 207,361 ----
//
! // handle normal keys
//
+ GtkTextIter insert_iter, start_iter;
+
+ // when key pressed produces text or is one of the list check that the
+ // cursor is not in the 'forbidden zone'
+ if (event->length>0 ||
+ event->keyval==GDK_BackSpace || event->keyval==GDK_Delete ||
+ event->keyval==GDK_Left || event->keyval==GDK_Right ||
+ event->keyval==GDK_Up || event->keyval==GDK_Down ||
+ event->keyval==GDK_Home || event->keyval==GDK_End) {
+ GtkTextIter sel_start, sel_end;
+
+ gtk_text_buffer_get_selection_bounds (display_text_buffer, &sel_start, &sel_end);
+ gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
+ if (gtk_text_iter_compare (&sel_start, &start_iter)<0 ||
+ gtk_text_iter_compare (&sel_end, &start_iter)<0) {
+ gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, cursor_mark);
+ gtk_text_buffer_place_cursor (display_text_buffer, &insert_iter);
+ }
+ }
! // RETURN
! if (event->keyval==GDK_Return) {
! ExpressionReady ();
!
! // stop signal
! gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key-press-event");
! return TRUE;
! }
! // LEFT cursor (with or without Ctrl) or backspace
! if (event->keyval==GDK_Left || event->keyval==GDK_BackSpace) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, insert_mark);
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! if (gtk_text_iter_compare (&insert_iter, &start_iter)<=0) {
! gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key-press-event");
! return TRUE;
! }
! }
! // UP, DOWN, PGUP, PGDN -> travel around history
! if (event->keyval==GDK_Up || event->keyval==GDK_Down ||
! event->keyval==GDK_Page_Up || event->keyval==GDK_Page_Down) {
! TravelEntryHistory (event->keyval);
! gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key-press-event");
! return TRUE;
! }
! // HOME pressed
! if (event->keyval==GDK_Home) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! if (event->state&GDK_SHIFT_MASK) {
! gtk_text_buffer_move_mark (display_text_buffer, insert_mark, &start_iter);
! } else {
! gtk_text_buffer_place_cursor (display_text_buffer, &start_iter);
! }
! gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key-press-event");
! return TRUE;
! }
! // C-k pressed
! if (event->keyval==GDK_k && event->state&GDK_CONTROL_MASK) {
! gtk_text_buffer_get_selection_bounds (display_text_buffer, &start_iter, &insert_iter);
! if (gtk_text_iter_equal (&start_iter, &insert_iter))
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &insert_iter, end_mark);
! gtk_text_buffer_delete (display_text_buffer, &start_iter, &insert_iter);
! gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key-press-event");
! return TRUE;
! }
!
! return FALSE; // let the default callback be called
! }
!
!
! //
! // callback function called before any insertion of text happens
! // makes sure text doesn't get inserted in the 'forbidden zone'
! //
! void insert_event (GtkTextBuffer *textbuffer, GtkTextIter *iter,
! gchar *text, gint len, gpointer user_data)
! {
! GtkTextIter start_iter;
! int i=0;
!
! if (user_action) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! if (gtk_text_iter_compare (iter, &start_iter) < 0) {
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, iter, start_mark);
! }
! gtk_text_buffer_place_cursor (display_text_buffer, iter);
! while (text[i]!='\n' && i<len) ++i;
! if (i<len) {
! g_signal_stop_emission_by_name ((gpointer) textbuffer, "insert-text");
! g_signal_emit_by_name ((gpointer) textbuffer, "insert-text", iter, text, i);
! }
! if (len>1) gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (display), insert_mark,
! 0., FALSE, 0., 0.);
! }
! }
!
!
! //
! // callback function called before a range of text is deleted
! //
! void delete_range_event (GtkTextBuffer *textbuffer, GtkTextIter *selstart,
! GtkTextIter *selend, gpointer user_data)
! {
! }
!
!
! //
! // callback function called whenever a tag is applied
! // filters tags applied by user_action (like paste text from result tag area)
! //
! void apply_tag_event (GtkTextBuffer *textbuffer, GtkTextTag *tag,
! GtkTextIter *start, GtkTextIter *end, gpointer user_data)
! {
! if (user_action) {
! g_signal_stop_emission_by_name ((gpointer)textbuffer, "apply-tag");
! }
! }
!
!
! //
! // callback function called anytime a user action happens
! //
! void begin_user_action_event (GtkTextBuffer *textbuffer, gpointer user_data)
! {
! user_action= 1;
! }
!
!
! //
! // callback function called anytime a user action ends
! //
! void end_user_action_event (GtkTextBuffer *textbuffer, gpointer user_data)
! {
! user_action= 0;
! }
!
!
! //
! // callback function called before a select-all event happens
! // makes sure all means only current input line
! //
! void select_all_event (GtkTextView *textview, gboolean arg1, gpointer user_data)
! {
! GtkTextIter start_iter, end_iter;
!
! gtk_signal_emit_stop_by_name (GTK_OBJECT (textview), "select-all");
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &start_iter, start_mark);
! gtk_text_buffer_get_iter_at_mark (display_text_buffer, &end_iter, end_mark);
! gtk_text_buffer_move_mark (display_text_buffer, selection_mark, &start_iter);
! gtk_text_buffer_move_mark (display_text_buffer, insert_mark, &end_iter);
}
***************
*** 261,262 ****
--- 373,383 ----
gtk_dialog_run (GTK_DIALOG (about));
}
+
+
+
+ /*
+ Local Variables:
+ c-file-style: "gnu"
+ c-file-offsets: ((case-label . +))
+ End:
+ */
Index: callbacks.h
===================================================================
RCS file: /cvsroot/ganc/ganc/src/callbacks.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** callbacks.h 12 Dec 2003 23:57:37 -0000 1.2
--- callbacks.h 20 Jan 2004 01:33:40 -0000 1.3
***************
*** 6,10 ****
void on_radiobutton_toggled (GtkToggleButton *button, gpointer data);
! void on_button_clear_clicked (GtkWidget *widget, gpointer data);
void on_button_AC_clicked (GtkWidget *widget, gpointer data);
--- 6,12 ----
void on_radiobutton_toggled (GtkToggleButton *button, gpointer data);
! void on_button_bs_clicked (GtkWidget *widget, gpointer data);
!
! void on_button_del_clicked (GtkWidget *widget, gpointer data);
void on_button_AC_clicked (GtkWidget *widget, gpointer data);
***************
*** 19,22 ****
--- 21,38 ----
gpointer user_data);
+ void insert_event (GtkTextBuffer *textbuffer, GtkTextIter *arg1,
+ gchar *arg2, gint arg3, gpointer user_data);
+ void delete_range_event (GtkTextBuffer *textbuffer, GtkTextIter *arg1,
+ GtkTextIter *arg2, gpointer user_data);
+ void apply_tag_event (GtkTextBuffer *textbuffer, GtkTextTag *arg1,
+ GtkTextIter *arg2, GtkTextIter *arg3, gpointer user_data);
+ void begin_user_action_event (GtkTextBuffer *textbuffer, gpointer user_data);
+ void end_user_action_event (GtkTextBuffer *textbuffer, gpointer user_data);
+ void select_all_event (GtkTextView *textview, gboolean arg1, gpointer user_data);
+
+
+
+
+
void
call_about_dialog (GtkMenuItem *menuitem,
Index: evaluate.c
===================================================================
RCS file: /cvsroot/ganc/ganc/src/evaluate.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** evaluate.c 13 Dec 2003 23:55:56 -0000 1.8
--- evaluate.c 20 Jan 2004 01:33:40 -0000 1.9
***************
*** 5,21 ****
#include <math.h>
#include <stdlib.h>
- #include <signal.h>
#include <string.h>
! #include "include/evaluate_stuff.h"
!
!
! /***********************************************************************
! *
! * Extern functions
! *
! ***********************************************************************/
! void CreateNewVariable (char *new_name, VALUE_TYPE value, short attributes);
! int GetInputBase (void);
--- 5,12 ----
#include <math.h>
#include <stdlib.h>
#include <string.h>
! #include "include/defines.h"
! #include "include/functions.h"
***************
*** 27,66 ****
***********************************************************************/
static VALUE_TYPE rad_to_any; // factor used in angle conversion
- static VALUE_TYPE PI; // value of PI
- /*static int math_error=0; // stores error in case of math error
- // (not volatile anymore since we don't handle FPE exceptions)*/
- // obsolete piece of code
- /*
- // Floating points exception (FPE) handler
- void FPE_handler (int signum)
- {
- math_error= PERROR_MATH_FPE_ERROR;
- }
-
- // Installs the math handler
- void install_FPE_handler (void)
- {
- signal (SIGFPE, FPE_handler);
- }
-
- */
-
-
- //
- // Sets up value for PI (called at start up when Initializing variables)
- //
- void SetUpPI (void)
- {
- PI= ((VALUE_TYPE) 4.)*atanl ((VALUE_TYPE) 1.);
- // define PI variable in calculator
- CreateNewVariable ("pi", PI, VAR_ATTR_READONLY);
- CreateNewVariable ("PI", PI, VAR_ATTR_READONLY);
- }
-
-
//
// Sets up rad_to_any to perform the right angle conversion
--- 18,25 ----
***************
*** 69,78 ****
{
if (strcmp (label, "Deg")==0) { // deg selected
! rad_to_any= ((VALUE_TYPE) 360./2.)/PI;
} else {
if (strcmp (label, "Rad")==0) { // rad selected
! rad_to_any= 1.;
} else { // grad selected
! rad_to_any= ((VALUE_TYPE) 400./2.)/PI;
}
}
--- 28,37 ----
{
if (strcmp (label, "Deg")==0) { // deg selected
! rad_to_any= ((VALUE_TYPE) 360./2.)/CONSTANT_PI;
} else {
if (strcmp (label, "Rad")==0) { // rad selected
! rad_to_any= (VALUE_TYPE) 1.;
} else { // grad selected
! rad_to_any= ((VALUE_TYPE) 400./2.)/CONSTANT_PI;
}
}
***************
*** 266,291 ****
}
- /*
- //
- // Used to query if there has been a math error
- // returns the value of 'math_error'
- //
- int MathError (void)
- {
- return math_error;
- }
-
//
- // Resets the value of math_error.
- // Called when math error has been detected and handled
- //
- void ResetMathError (void)
- {
- math_error= 0;
- }
- */
-
// evaluates a number taking into account the default input basis
VALUE_TYPE EvaluateNumber (char *strnumber)
{
--- 225,232 ----
}
//
// evaluates a number taking into account the default input basis
+ //
VALUE_TYPE EvaluateNumber (char *strnumber)
{
***************
*** 295,299 ****
// get current input base
! base= GetInputBase ();
if (base==10) { // base 10, we can do non integer stuff
--- 236,240 ----
// get current input base
! base= GetSystemVariable (SYSTEMVAR_IBASE);
if (base==10) { // base 10, we can do non integer stuff
Index: interface.c
===================================================================
RCS file: /cvsroot/ganc/ganc/src/interface.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** interface.c 14 Dec 2003 00:26:55 -0000 1.3
--- interface.c 20 Jan 2004 01:33:40 -0000 1.4
***************
*** 95,102 ****
GtkWidget *handlebox1;
GtkWidget *menubar1;
GtkWidget *vbox2;
! GtkWidget *hbox2;
GtkWidget *display;
- GtkWidget *vscrollbar1;
GtkWidget *frame1;
GtkWidget *hbox1;
--- 95,102 ----
GtkWidget *handlebox1;
GtkWidget *menubar1;
+ GtkAccelGroup *accel_group;
GtkWidget *vbox2;
! GtkWidget *scrolledwindow1;
GtkWidget *display;
GtkWidget *frame1;
GtkWidget *hbox1;
***************
*** 109,113 ****
GtkWidget *button1;
GtkWidget *button2;
- GtkWidget *button3;
GtkWidget *button6;
--- 109,112 ----
***************
*** 129,137 ****
gtk_box_pack_start (GTK_BOX (vbox1), handlebox1, FALSE, TRUE, 0);
menubar1 = gtk_menu_bar_new ();
gtk_widget_show (menubar1);
gtk_container_add (GTK_CONTAINER (handlebox1), menubar1);
gnome_app_fill_menu (GTK_MENU_SHELL (menubar1), menubar1_uiinfo,
! NULL, FALSE, 0);
vbox2 = gtk_vbox_new (FALSE, 0);
--- 128,140 ----
gtk_box_pack_start (GTK_BOX (vbox1), handlebox1, FALSE, TRUE, 0);
+ // create accelerator group
+ accel_group = gtk_accel_group_new ();
+ gtk_window_add_accel_group (GTK_WINDOW (window1), accel_group);
+
menubar1 = gtk_menu_bar_new ();
gtk_widget_show (menubar1);
gtk_container_add (GTK_CONTAINER (handlebox1), menubar1);
gnome_app_fill_menu (GTK_MENU_SHELL (menubar1), menubar1_uiinfo,
! accel_group, FALSE, 0);
vbox2 = gtk_vbox_new (FALSE, 0);
***************
*** 140,156 ****
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 5);
! hbox2 = gtk_hbox_new (FALSE, 0);
! gtk_widget_show (hbox2);
! gtk_box_pack_start (GTK_BOX (vbox2), hbox2, TRUE, TRUE, 0);
! display = create_display ("display", "", NULL, 40, 20);
gtk_widget_show (display);
! gtk_box_pack_start (GTK_BOX (hbox2), display, TRUE, TRUE, 0);
! GTK_WIDGET_SET_FLAGS (display, GTK_CAN_FOCUS);
! GTK_WIDGET_SET_FLAGS (display, GTK_CAN_DEFAULT);
!
! vscrollbar1 = gtk_vscrollbar_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 0, 0, 0, 0)));
! gtk_widget_show (vscrollbar1);
! gtk_box_pack_start (GTK_BOX (hbox2), vscrollbar1, FALSE, TRUE, 0);
frame1 = gtk_frame_new (NULL);
--- 143,155 ----
gtk_container_set_border_width (GTK_CONTAINER (vbox2), 5);
! scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
! gtk_widget_show (scrolledwindow1);
! gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow1, TRUE, TRUE, 0);
! gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
! display = gtk_text_view_new ();
! gtk_widget_set_size_request (display, 250, 200);
gtk_widget_show (display);
! gtk_container_add (GTK_CONTAINER (scrolledwindow1), display);
frame1 = gtk_frame_new (NULL);
***************
*** 192,199 ****
button1 = make_empty_space (table1, 2, 3, 0, 1);
button2 = make_empty_space (table1, 3, 4, 0, 1);
- button3 = make_empty_space (table1, 4, 5, 0, 1);
make_button (window1, "button4", _("AC"), on_button_AC_clicked,
table1, 5, 0);
! make_button (window1, "button5", _("C"), on_button_clear_clicked,
table1, 6, 0);
--- 191,199 ----
button1 = make_empty_space (table1, 2, 3, 0, 1);
button2 = make_empty_space (table1, 3, 4, 0, 1);
make_button (window1, "button4", _("AC"), on_button_AC_clicked,
+ table1, 4, 0);
+ make_button (window1, "button5", _("<-"), on_button_bs_clicked,
table1, 5, 0);
! make_button (window1, "button5", _("DEL"), on_button_del_clicked,
table1, 6, 0);
***************
*** 287,293 ****
GLADE_HOOKUP_OBJECT (window1, menuitem5_menu_uiinfo[0].widget, "menuitem6");
GLADE_HOOKUP_OBJECT (window1, vbox2, "vbox2");
- GLADE_HOOKUP_OBJECT (window1, hbox2, "hbox2");
GLADE_HOOKUP_OBJECT (window1, display, "display");
- GLADE_HOOKUP_OBJECT (window1, vscrollbar1, "vscrollbar1");
GLADE_HOOKUP_OBJECT (window1, frame1, "frame1");
GLADE_HOOKUP_OBJECT (window1, hbox1, "hbox1");
--- 287,291 ----
***************
*** 298,302 ****
GLADE_HOOKUP_OBJECT (window1, button1, "button1");
GLADE_HOOKUP_OBJECT (window1, button2, "button2");
- GLADE_HOOKUP_OBJECT (window1, button3, "button3");
GLADE_HOOKUP_OBJECT (window1, button6, "button6");
--- 296,299 ----
***************
*** 307,311 ****
GLADE_HOOKUP_OBJECT (window1, statusbar1, "statusbar1");
! gtk_widget_grab_default (display);
return window1;
}
--- 304,308 ----
GLADE_HOOKUP_OBJECT (window1, statusbar1, "statusbar1");
! //gtk_widget_grab_default (display);
return window1;
}
***************
*** 316,320 ****
const gchar *authors[] = {
"Xavier Martinez Hidalgo",
! "Jose Marino\t",
NULL
};
--- 313,317 ----
const gchar *authors[] = {
"Xavier Martinez Hidalgo",
! "Jose Marino",
NULL
};
Index: main.c
===================================================================
RCS file: /cvsroot/ganc/ganc/src/main.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** main.c 12 Dec 2003 19:10:01 -0000 1.8
--- main.c 20 Jan 2004 01:33:40 -0000 1.9
***************
*** 6,14 ****
#include <string.h>
#include <stdio.h>
- #include <signal.h>
#include <sys/wait.h>
#ifdef BUILD_GUI
#include <gtk/gtk.h>
#include "callbacks.h"
#include "support.h"
--- 6,15 ----
#include <string.h>
#include <stdio.h>
#include <sys/wait.h>
#ifdef BUILD_GUI
#include <gtk/gtk.h>
+ #include <gconf/gconf-client.h>
+ #include <pango/pango-font.h>
#include "callbacks.h"
#include "support.h"
***************
*** 16,21 ****
#endif
#include "include/functions.h"
! #include "include/evaluate_stuff.h"
--- 17,23 ----
#endif
+ #include "include/defines.h"
#include "include/functions.h"
!
***************
*** 29,34 ****
--- 31,43 ----
GtkWidget *inv_button;
GtkWidget *hyp_button;
+ GtkTextBuffer *display_text_buffer;
+ GtkWidget *display;
#endif
+ extern GtkTextMark *start_mark;
+ extern GtkTextMark *end_mark;
+ extern GtkTextMark *insert_mark;
+ extern GtkTextMark *selection_mark;
+ extern GtkTextMark *cursor_mark;
/***********************************************************************
***************
*** 38,41 ****
--- 47,51 ----
***********************************************************************/
static void InitializeVars (void);
+ static void SetUpInterface (void);
static void CleanUp (void);
***************
*** 50,61 ****
InitMainVarList ();
- /* // Add default variables to variable list
- CreateNewVariable ("ans", 0., VAR_ATTR_READONLY); // define ans (previous answer)
- */
// First calculator is in degree mode
SetUpAngleConversion ("Deg");
! // FPE signals are not raised, so we don't bother setting up the handler
! // install_FPE_handler ();
}
--- 60,71 ----
InitMainVarList ();
// First calculator is in degree mode
SetUpAngleConversion ("Deg");
! // initialize history
! InitializeHistory ();
!
! // initialize system vars
! InitializeSystemVars ();
}
***************
*** 68,71 ****
--- 78,83 ----
// free memory of variable list
DestroyMainVarList ();
+ // free history's memory
+ RemoveHistory ();
}
***************
*** 77,113 ****
// It set ups everything and then gives control to GUI (gtk_main)
//
! void RunMainProcess (FILE *from_reader, FILE *to_reader)
{
GtkWidget *window;
! GtkWidget *scrollbar1;
// create interface
window= create_window1 ();
! TerminalSetGeometry (window);
gtk_widget_show (window); // show main window
// extract widgets
! scrollbar1= lookup_widget (window, "vscrollbar1");
inv_button= lookup_widget (window, "togglebutton1");
hyp_button= lookup_widget (window, "togglebutton2");
- // do some stuff with terminal
- TerminalConnectScrollbar (terminal, scrollbar1);
! // pipe streams stored as data in window
! gtk_object_set_data (GTK_OBJECT (window), "from_reader",
! (gpointer) from_reader);
! gtk_object_set_data (GTK_OBJECT (window), "to_reader",
! (gpointer) to_reader);
! // Attach a callback to the pipe from the reader
! /* gtk_input_add_full (fileno (from_reader), GDK_INPUT_READ,
! ReaderHasLine, NULL, (gpointer) window, NULL);*/
! gtk_main (); // start gtk loop
}
#endif
//
// main function
--- 89,167 ----
// It set ups everything and then gives control to GUI (gtk_main)
//
! static void SetUpInterface (void)
{
GtkWidget *window;
! GtkTextIter start_iter;
// create interface
window= create_window1 ();
! //TerminalSetGeometry (window);
gtk_widget_show (window); // show main window
// extract widgets
! //scrollbar1= lookup_widget (window, "vscrollbar1");
inv_button= lookup_widget (window, "togglebutton1");
hyp_button= lookup_widget (window, "togglebutton2");
! // set up text buffer stuff
! display= lookup_widget (window, "display");
!
! // get font from gnome preferences and set it
! {
! PangoFontDescription *monospace_font_desc;
! GConfClient *conf_client;
!
! conf_client= gconf_client_get_default ();
! monospace_font_desc= pango_font_description_from_string (gconf_client_get_string (conf_client, "/desktop/gnome/interface/monospace_font_name", NULL));
! gtk_widget_modify_font (display, monospace_font_desc);
! pango_font_description_free (monospace_font_desc);
! g_object_unref (G_OBJECT (conf_client));
! }
! display_text_buffer= gtk_text_view_get_buffer (GTK_TEXT_VIEW (display));
! gtk_text_view_set_editable (GTK_TEXT_VIEW (display), TRUE);
! gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (display), GTK_WRAP_CHAR);
! // create tags
! gtk_text_buffer_create_tag (display_text_buffer, "error",
! "foreground", "red",
! NULL);
! gtk_text_buffer_create_tag (display_text_buffer, "result",
! "justification", GTK_JUSTIFY_RIGHT,
! "right-margin", 10,
! NULL);
!
! // create initial mark for start of line
! gtk_text_buffer_get_iter_at_offset (display_text_buffer, &start_iter, 0);
! PrintPrompt (&start_iter);
! start_mark= gtk_text_buffer_create_mark (display_text_buffer, "start-line",
! &start_iter, TRUE);
! end_mark= gtk_text_buffer_create_mark (display_text_buffer, "end-line",
! &start_iter, FALSE);
! cursor_mark= gtk_text_buffer_create_mark (display_text_buffer, "cursor",
! &start_iter, FALSE);
! insert_mark= gtk_text_buffer_get_insert (display_text_buffer);
! selection_mark= gtk_text_buffer_get_mark (display_text_buffer, "selection_bound");
!
!
! // signal connections
! g_signal_connect ((gpointer) display_text_buffer, "insert-text",
! G_CALLBACK (insert_event), NULL);
! g_signal_connect ((gpointer) display_text_buffer, "delete-range",
! G_CALLBACK (delete_range_event), NULL);
! g_signal_connect ((gpointer) display_text_buffer, "apply-tag",
! G_CALLBACK (apply_tag_event), NULL);
! g_signal_connect ((gpointer) display_text_buffer, "begin-user-action",
! G_CALLBACK (begin_user_action_event), NULL);
! g_signal_connect ((gpointer) display_text_buffer, "end-user-action",
! G_CALLBACK (end_user_action_event), NULL);
! g_signal_connect ((gpointer) display, "select-all",
! G_CALLBACK (select_all_event), NULL);
}
#endif
+
//
// main function
***************
*** 124,134 ****
InitializeVars ();
! // create terminal widget that'll be used as display
! CreateTerminal ();
! // fork processes:
! // - main_process (with gtk)
! // - reader_process (with readline)
! StartProcesses ();
// clean up everything before leaving
--- 178,186 ----
InitializeVars ();
! // set up gtk interface
! SetUpInterface ();
! // start gtk loop
! gtk_main ();
// clean up everything before leaving
Index: parser_stuff.c
===================================================================
RCS file: /cvsroot/ganc/ganc/src/parser_stuff.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** parser_stuff.c 14 Jan 2004 20:16:22 -0000 1.12
--- parser_stuff.c 20 Jan 2004 01:33:40 -0000 1.13
***************
*** 4,13 ****
#include <stdlib.h>
- #include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "include/functions.h"
- #include "include/evaluate_stuff.h"
#include "syntax.h" // include header file generated by bison
--- 4,13 ----
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+ //#include <stdio.h>
+ #include "include/defines.h"
#include "include/functions.h"
#include "syntax.h" // include header file generated by bison
***************
*** 15,29 ****
/***********************************************************************
*
! * Local Types
*
***********************************************************************/
! // Name list used to keep the list of defined variables (typedef in mytypes.h)
! struct var_list_struct {
! char *name; // contains name of variable
! short attr; // attributes of variable
! VALUE_TYPE value; // value of variable
! struct var_list_struct *ant; // previous member in list
! };
// Name list used to keep track of names defined during parsing, (typedef in mytypes.h)
// it allows efficient memory usage in case of parsing error
--- 15,29 ----
/***********************************************************************
*
! * External Functions
*
***********************************************************************/
! int yyparse (void);
!
+ /***********************************************************************
+ *
+ * Local Types
+ *
+ ***********************************************************************/
// Name list used to keep track of names defined during parsing, (typedef in mytypes.h)
// it allows efficient memory usage in case of parsing error
***************
*** 32,35 ****
--- 32,36 ----
struct name_list_struct *ant;
};
+ typedef struct name_list_struct name_list;
***************
*** 40,51 ****
***********************************************************************/
static char *NewNameListEntry (char *newname);
- static int ValidVariableName (char *name);
- static var_list *MakeCopyVariableList (void);
- static void DestroyVariableList (var_list *ini);
static void DestroyNameList (void);
- static void UpdateAnswerVariable (void);
- static var_list *FindVariable (char *name);
static void ResetParseError (void);
! static void ResetOutputFormat (void);
--- 41,47 ----
***********************************************************************/
static char *NewNameListEntry (char *newname);
static void DestroyNameList (void);
static void ResetParseError (void);
! static void ResetResultData (void);
***************
*** 56,65 ****
*
***********************************************************************/
- static var_list *var_list_ini; // Initial node of variable list
static name_list *name_list_ini; // Initial node of name list (local to this file)
static int pos; // position on input text of parse position
static char *input; // input text to be parsed
- static VALUE_TYPE expression_value; // Variable where final result of parsing is given
- static int ibase=10, obase=10; // input and output base
static char *function_names[]={ // Names of defined functions
"abs", //0
--- 52,58 ----
***************
*** 83,123 ****
""
};
! static struct {
! int set;
! int base...
[truncated message content] |