/**************************************************************************************************/
/* Glo_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Global definition for cal calculator
#include
#include
#include
#include
#include
#include
#define BLANC_SUR_NOIR 1
#define LEN_MAX 12 // Nombre de chiffes permis
#define LEN_MAX_DIG 12 // Lenght maxi of digits alowed
#define LEN_MAX_CHA_CON 26 // Lenght maxi of char used for conversion
void finish(int sig);
class Cf // Configuration class
{
public: //data
enum Cel_Fmt
{
EN_TH, // English format with thousand separator
EN, // English format without thousand separator
LA_TH, // Latin format with thousand separator
LA, // Latin format with thousand separator
CDS // Condensed format no thousand separator
}; // no decimal separator
int i_Nbr_Dec; // Number of decimal
enum Cel_Fmt i_Cel_Fmt;
private: //data
struct s_Cel_Fmt
{
char tc_Fmt_Lib[20]; // Libel for explanation
char tc_Fmt_Exe[10]; // Exemple of Format
int i_Len_Max; // Lenght maximum on the screen
};
static struct s_Cel_Fmt ts_Cel_Fmt[5];
public: //function
Cf(bool b_Fir_Cal);
~Cf();
private: //function
void Set_Def_Par(); // Set the default parameters
};
struct Cf::s_Cel_Fmt Cf:: ts_Cel_Fmt[5];
static Cf *pcl_Def_Cf; // Pointer on the default Configuration Class
class Cel
{
// Father of class Op and Rs
public: //data
static Cf *pcl_Cf; //Configuration
Cel *pcl_Nxt_Cel; //Next Cell
Cel *pcl_Pre_Cel; //Previous Cell
char c_Ope; // Operation sign (+,-,*,/)
char c_Ope_sv; // Operation sign (+,-,*,/)
// save for test modified
private: //data
public: //function
Cel();
~Cel();
//static void Put_Cf(Cf *pcl_Cf_) {pcl_Cf = pcl_Cf_;}
void Del_Cel(Cel *pcl_Cur_Cel);
void Del_All_Cel(Cel *pcl_Fir_Cel);
virtual void Set_Cur(WINDOW *Win_Cel,int i_Row_y,int i_Row_x)=0;
virtual void Prt_Row(WINDOW *Win_Cel,int i_Row_y,int i_Row_x)=0;
virtual int Get_Cel(WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x)=0;
virtual long double Get_Dig_Nbr()=0;
virtual bool Get_Cel_Mod()=0;
virtual void Sav_Cel()=0;
private: //function
};
static Cf *pcl_Cf ; // Pointer on Configuration Class
class Op : public Cel
{
public: //data
long double d_Nbr; // Number in decimal form
long double d_Nbr_sv; // Number in decimal form
// save for test modified
private : //data
enum Fld_Typ
{
SIG,
NBR,
OPE,
};
enum Fld_Typ e_Cur_Fld; // Current Field
char c_Sig; // Sign
char tc_Nbr[LEN_MAX]; // without '\0'
int i_Nbr_of_Cha; // Number of type digits
int i_Nbr_Cur_Pos; // Curent position in the number
public : //function
Op (
Cel *p_Cur_Cel
);
virtual ~Op ();
void Del_Cel();
void Prt_Row(WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Sig (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Nbr (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Ope (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Sig (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Nbr (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Ope (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
virtual void Set_Cur (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
virtual int Get_Cel (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
void Str_to_Num();
virtual long double Get_Dig_Nbr();
virtual bool Get_Cel_Mod();
virtual void Sav_Cel();
private : //function
int Get_Sig (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
int Get_Nbr (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
int Get_Ope (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
void Mve_Lft (); // Move to the left
void Mve_Rht_Bks (); // Move to the left for BackSpace
void Mve_Rht_Dc (); // Move to the left for Delete
};
class Acc
{
public: //data
Acc *pcl_Nxt_Acc; //Next Accumulator
Acc *pcl_Pre_Acc; //Previou Acc
long double d_Acc;
private: //data
public: //function
Acc(Acc *pcl_Acc);
~Acc();
long double Cal_Tot(Cel *pcl_Fir_Cel);
private: //function
};
class Rs : public Cel
{
public: //data
long double d_Acc; // Total in decimal form
private : //data
char c_Sig; // Sign
char tc_Acc[LEN_MAX_DIG]; //Result
char tc_Acc_Wrk[LEN_MAX_CHA_CON]; //Result
int i_Nbr_of_Cha; // Number digits
public : //function
Rs (
Cel *p_Cur_Cel,
Cel *p_Fir_Cel
);
virtual ~Rs ();
void Del_Cel();
void Prt_Row(WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Sig (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Acc (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Prt_Ope (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Sig (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Acc (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
void Clr_Ope (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
virtual void Set_Cur (WINDOW *Win_Cel,int i_Row_y,int i_Row_x);
int Get_Ope (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
virtual int Get_Cel (WINDOW *Win_Cel,int i_c,int i_Row_y,int i_Row_x);
virtual long double Get_Dig_Nbr();
virtual bool Get_Cel_Mod();
virtual void Sav_Cel();
private : //function
void Num_to_Alp(long double d_Acc);
void Clr_tc_Acc(void);
friend class Acc;
};
class Ca
{
public : //data
// Cf *pcl_Cf; // Configuration
Cel *pcl_Fir_Cel; // First Cell
Cel *pcl_Cur_Cel; // Curent Cell
Cel *pcl_Fir_Cel_Pag; // First Cell of page
Cel *pcl_Las_Cel_Pag; // Last Cell of page
int i_Cur_Row_Nbr; // Curent Row Number
// ( 0 to i_Win_Cel_Nli-1)
int i_Fir_Row_Nbr; // Number of First Row being printed
int i_Las_Row_Nbr; // Number of Last Row being printed
int i_c; // key pressed
public : //function
Ca(); // Constructor
~Ca(); // Destructor
void Get_Key(void); // Keyboard read
void Prt_Brd(); // Print Border
private : //data
WINDOW *pw_Brd_Cel; // Window Pointer for border
WINDOW *pw_Win_Cel; // Window Pointer for the cells
PANEL *pp_Pan_Brd; // Panel Pointer for border
PANEL *pp_Pan_Cel; // Panel Pointer for the cells
/**/
int i_Win_Brd_Ori_x; // Window Border Origine position
int i_Win_Brd_Ori_y;
int i_Win_Brd_Nli; // Window border nbr of lines
int i_Win_Brd_Nco; // Window border nbr of colones
/**/
int i_Win_Cel_Nli; // Window cell nbr of lines
int i_Win_Cel_Nco; // Window cell nbr of colones
int i_Win_Cel_x; // Window cell position
int i_Win_Cel_y;
char c_Wrk_Mod; // Working Mode
// ' ' = Normal mode
// 'm' = Moving Window mode
// 's' = Resizing Window mode
private : //funtion
void Cre_Win(); // Create the window
void Del_Win(); // Delete the window
void Mov_Prv_Cel(); // Move Previous Cell
void Mov_Nxt_Cel(); // Move Next Cell
void Mov_Nxt_Pag(); // Move Next Page
void Mov_Prv_Pag(); // Move Previous Page
void Add_Res_Cel(); // Add a New Result Cell
void Upd_Tot(); // Update the total
void Clr_All(); // Clear All
void Prt_Pag(Cel *pcl_Fir_Cel_Pag,int i_Fir_Row_Nbr);
// Print the current page
};
class Mai
{
public: // data
private: // data
public: // function
Mai();
private: // function
int Ini_Cur();
};
/**************************************************************************************************/
/* main.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
#include "Glo_Def.h"
int main(int argc, char *argv[])
{
Mai Mai1;
finish(0);
}
void finish(int sig)
{
endwin();
/* do your non-curses wrapup here */
exit(0);
}
/**************************************************************************************************/
/* Mai_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
#include "Glo_Def.h"
Mai::Mai()
{
/* initialize your non-curses data structures here */
Ini_Cur();
// choix ds couleur
int num = 1;
attrset(COLOR_PAIR(num % 8));
Ca Ca1;
Ca1.Get_Key();
}
int Mai::Ini_Cur()
{
/* md:teminal caracteristic and memory allocation */
(void) signal(SIGINT, finish); /* arrange interrupts to terminate */
(void) initscr(); /* initialize the curses library */
/* md:teminal caracteristic and memory allocation */
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
(void) cbreak(); /* take input chars one at a time, no wait for \n */
(void) noecho(); /* no echo input - in color */
if (has_colors())
{
start_color();
/*
* Simple color assignment, often all we need. Color pair 0 cannot
* be redefined. This example uses the same value for the color
* pair as for the foreground color, though of course that is not
* necessary:
*/
init_pair(BLANC_SUR_NOIR, COLOR_WHITE, COLOR_BLACK);
}
return 0;
}
/**************************************************************************************************/
/* Cal_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Classe function for Cal
// Function that handle one calculator window
#include "Glo_Def.h"
Ca::Ca()
{
pcl_Cf = new Cf(TRUE);
c_Wrk_Mod= ' ';
i_Win_Brd_Nli =10; // Window Border Nbr of lines
i_Win_Brd_Nco = LEN_MAX+8; // Window Border Nbr of colones
// 6 = 1 border + 1 sig + LEN_Max
// + 1 blank + 1 operation + 1 border
i_Win_Brd_Ori_x = 5; // Window Border Position above/left
i_Win_Brd_Ori_y = 5;
i_Cur_Row_Nbr = 0;
i_Fir_Row_Nbr = 0;
i_Las_Row_Nbr = 0;
pcl_Cur_Cel = new Op(NULL);
pcl_Fir_Cel = pcl_Cur_Cel;
pcl_Las_Cel_Pag = pcl_Cur_Cel;
pcl_Fir_Cel_Pag = pcl_Cur_Cel;
Cre_Win();
}
void Ca::Cre_Win()
{
pw_Brd_Cel = newwin( i_Win_Brd_Nli,
i_Win_Brd_Nco,
i_Win_Brd_Ori_x,
i_Win_Brd_Ori_y );
keypad(pw_Brd_Cel,TRUE); // keybord mapping
idlok(pw_Brd_Cel,TRUE); // insert delete lines
scrollok(pw_Brd_Cel,TRUE);
Prt_Brd();
pp_Pan_Brd = new_panel(pw_Brd_Cel);
i_Win_Cel_Nli = i_Win_Brd_Nli-2; // Window Cell Nbr of lines
i_Win_Cel_Nco = i_Win_Brd_Nco-2; // Window Cell Nbr of colones
i_Win_Cel_x = i_Win_Brd_Ori_x+1; // Window Cell Position above/left
i_Win_Cel_y = i_Win_Brd_Ori_y+1;
pw_Win_Cel = newwin( i_Win_Cel_Nli,
i_Win_Cel_Nco,
i_Win_Cel_x,
i_Win_Cel_y);
keypad(pw_Win_Cel,TRUE); // keybord mapping
idlok(pw_Win_Cel,TRUE); // insert delete lines
scrollok(pw_Win_Cel,TRUE);
pp_Pan_Cel = new_panel(pw_Win_Cel);
update_panels();
doupdate();
}
void Ca::Del_Win()
{
}
void Ca::Get_Key()
{
int i_Row_y = 0;
int i_Row_x = 0;
int b;
while (TRUE)
{
// reSet Cursor Position
pcl_Cur_Cel->Set_Cur(pw_Win_Cel,i_Row_y+i_Cur_Row_Nbr,i_Row_x);
i_c = wgetch(pw_Win_Cel);
i_c = pcl_Cur_Cel->Get_Cel(pw_Win_Cel,i_c,i_Row_y+i_Cur_Row_Nbr,i_Row_x);
// if cell modified recompute the total(s)
Upd_Tot();
// when blank, Get_Cel keep the control
if (i_c != ' ')
{
switch(c_Wrk_Mod)
{
case ' ':
switch(i_c)
{
case KEY_LEFT:
case KEY_UP:
Mov_Prv_Cel();
break;
case KEY_RIGHT:
case KEY_DOWN:
Mov_Nxt_Cel();
break;
case '=':
Add_Res_Cel();
break;
case KEY_NPAGE:
Mov_Nxt_Pag();
break;
case KEY_PPAGE:
Mov_Prv_Pag();
break;
// case 'm': // Change working mode to
// c_Wrk_Mod = 'm';
// mvwaddstr(pw_Win_Cel,0,0,"Move");
// break;
//
// case 's': // Change working mode to
// c_Wrk_Mod = 's';
// mvwaddstr(pw_Win_Cel,0,0,"Resize");
// break;
case 'c': // Clear the screen
Clr_All();
break;
case 'q':
return;
break;
case 'r':
Prt_Pag(pcl_Fir_Cel_Pag,i_Fir_Row_Nbr);
break;
default :
break;
}
break;
case 'm':
switch (i_c)
{
case KEY_UP:
break;
case KEY_DOWN:
break;
case KEY_LEFT:
break;
case KEY_RIGHT:
break;
case 'm':
c_Wrk_Mod=' ';
Prt_Pag(pcl_Fir_Cel_Pag,i_Fir_Row_Nbr);
break;
default:
break;
}
case 's':
break;
default:
break;
}
}
}
}
void Ca::Prt_Brd()
{
if (FALSE)
{
// Term: VT100 or other..
// ls,rs,ts,bs,tl,tr,bl,br
wborder(pw_Brd_Cel,'!','!','-','-','+','+','+','+');
}
else
{
// Term: Linux
wborder(pw_Brd_Cel,0,0,0,0,0,0,0,0);
}
}
void Ca::Prt_Pag(Cel *pcl_Fir_Cel_Pag,int i_Fir_Row_Nbr)
{
wclear(pw_Win_Cel);
Cel *pcl_Cel = pcl_Fir_Cel_Pag;
int i=i_Fir_Row_Nbr;
while (
i<=i_Win_Cel_Nli-1
&&
pcl_Cel->pcl_Nxt_Cel != NULL
)
{
pcl_Cel->Prt_Row(pw_Win_Cel,i,0);
i++;
pcl_Cel = pcl_Cel->pcl_Nxt_Cel;
}
pcl_Cel->Prt_Row(pw_Win_Cel,i,0);
}
void Ca::Mov_Nxt_Pag(void)
{
if(pcl_Las_Cel_Pag->pcl_Nxt_Cel != NULL)
{
wclear(pw_Win_Cel);
Cel *pcl_Cel = pcl_Las_Cel_Pag;
int i=0;
while (i<=i_Win_Cel_Nli-1)
{
pcl_Cel->Prt_Row(pw_Win_Cel,i,0);
if(pcl_Cel->pcl_Nxt_Cel == NULL || i==i_Win_Cel_Nli-1 )
{ break;}
else
{
pcl_Cel = pcl_Cel->pcl_Nxt_Cel;
i++;
}
}
i_Cur_Row_Nbr = 0;
i_Fir_Row_Nbr = 0;
i_Las_Row_Nbr = i;
pcl_Fir_Cel_Pag = pcl_Las_Cel_Pag;
pcl_Las_Cel_Pag = pcl_Cel;
pcl_Cur_Cel = pcl_Fir_Cel_Pag;
}
}
void Ca::Mov_Prv_Pag(void)
{
if(pcl_Fir_Cel_Pag->pcl_Pre_Cel != NULL)
{
wclear(pw_Win_Cel);
Cel *pcl_Cel = pcl_Fir_Cel_Pag;
int i=i_Win_Cel_Nli-1;
while ( i>=0 )
{
pcl_Cel->Prt_Row(pw_Win_Cel,i,0);
if (pcl_Cel->pcl_Pre_Cel == NULL || i==0 )
{
break;
}
else
{
pcl_Cel = pcl_Cel->pcl_Pre_Cel;
i--;
}
}
i_Fir_Row_Nbr = i;
i_Las_Row_Nbr = i_Win_Cel_Nli-1;
i_Cur_Row_Nbr = i_Las_Row_Nbr;
pcl_Las_Cel_Pag = pcl_Fir_Cel_Pag;
pcl_Fir_Cel_Pag = pcl_Cel;
pcl_Cur_Cel = pcl_Las_Cel_Pag;
}
}
void Ca::Mov_Prv_Cel(void)
{
if (pcl_Cur_Cel->pcl_Pre_Cel != NULL)
{
pcl_Cur_Cel = pcl_Cur_Cel->pcl_Pre_Cel;
if(i_Cur_Row_Nbr == 0)
{
wscrl(pw_Win_Cel,-1); //scroll down
pcl_Cur_Cel->Prt_Row(pw_Win_Cel,0,0);
pcl_Fir_Cel_Pag = pcl_Fir_Cel_Pag->pcl_Pre_Cel;
pcl_Las_Cel_Pag = pcl_Las_Cel_Pag->pcl_Pre_Cel;
}
else
{
i_Cur_Row_Nbr--;
}
}
}
void Ca::Mov_Nxt_Cel(void)
{
if (pcl_Cur_Cel->pcl_Nxt_Cel != NULL)
{
// Existing Cell
pcl_Cur_Cel = pcl_Cur_Cel->pcl_Nxt_Cel;
if(i_Cur_Row_Nbr == i_Win_Cel_Nli-1)
{
wscrl(pw_Win_Cel,+1); //scroll up
pcl_Cur_Cel->Prt_Row(pw_Win_Cel,i_Cur_Row_Nbr,0);
pcl_Las_Cel_Pag = pcl_Las_Cel_Pag->pcl_Nxt_Cel;
if (i_Fir_Row_Nbr > 0)
{
i_Fir_Row_Nbr--;
}
else
{
pcl_Fir_Cel_Pag = pcl_Fir_Cel_Pag->pcl_Nxt_Cel;
}
}
else
{
i_Cur_Row_Nbr++;
}
}
else
{
// Create New Cell
pcl_Cur_Cel = new Op (pcl_Cur_Cel);
if(i_Cur_Row_Nbr == i_Win_Cel_Nli-1)
{
wscrl(pw_Win_Cel,+1); //scroll up
pcl_Fir_Cel_Pag = pcl_Fir_Cel_Pag->pcl_Nxt_Cel;
}
else
{
i_Cur_Row_Nbr++;
i_Las_Row_Nbr++;
}
pcl_Las_Cel_Pag = pcl_Cur_Cel;
}
}
void Ca::Clr_All()
{
if(pcl_Fir_Cel != NULL)
{
pcl_Cur_Cel->Del_All_Cel(pcl_Fir_Cel);
wclear(pw_Win_Cel);
i_Cur_Row_Nbr=0;
i_Fir_Row_Nbr=0;
i_Las_Row_Nbr=0;
pcl_Cur_Cel = new Op(NULL);
pcl_Fir_Cel = pcl_Cur_Cel;
pcl_Fir_Cel_Pag = pcl_Cur_Cel;
pcl_Las_Cel_Pag = pcl_Cur_Cel;
}
}
void Ca::Add_Res_Cel()
{
if(pcl_Cur_Cel->pcl_Nxt_Cel != NULL)
{
//insertion
}
else
{
//creation
pcl_Cur_Cel = new Rs(pcl_Cur_Cel,pcl_Fir_Cel);
if(i_Cur_Row_Nbr == i_Win_Cel_Nli-1)
{
pcl_Fir_Cel_Pag = pcl_Fir_Cel_Pag->pcl_Nxt_Cel;
wscrl(pw_Win_Cel,+1); //scroll up
}
else
{
i_Cur_Row_Nbr++;
i_Las_Row_Nbr++;
}
pcl_Las_Cel_Pag = pcl_Cur_Cel;
pcl_Cur_Cel->Prt_Row(pw_Win_Cel,i_Cur_Row_Nbr,0);
}
}
void Ca::Upd_Tot(void)
{
if ( pcl_Cur_Cel->pcl_Nxt_Cel == NULL )
{
pcl_Cur_Cel->Sav_Cel();
}
else
{
if ( pcl_Cur_Cel->Get_Cel_Mod() )
{
Acc *pcl_Fir_Acc;
Acc *pcl_Cur_Acc;
pcl_Cur_Acc = new Acc(NULL);
pcl_Fir_Acc = pcl_Cur_Acc;
pcl_Fir_Acc->Cal_Tot(pcl_Fir_Cel);
delete pcl_Fir_Acc;
Prt_Pag(pcl_Fir_Cel_Pag,i_Fir_Row_Nbr);
// save the data
pcl_Cur_Cel->Sav_Cel();
}
}
}
Ca::~Ca()
{
if (pcl_Fir_Cel != NULL)
delete pcl_Fir_Cel;
}
/**************************************************************************************************/
/* Cfg_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Classe function for Cf
// Configuration Data
#include "Glo_Def.h"
Cf::Cf(bool b_Fir_Cal)
{
if (b_Fir_Cal)
{
// Set the static parameter (share by each objects
strcpy(ts_Cel_Fmt[EN_TH].tc_Fmt_Lib,"English th. sep");
strcpy(ts_Cel_Fmt[EN_TH].tc_Fmt_Exe,"34,123.02");
ts_Cel_Fmt[EN_TH].i_Len_Max = 16;
strcpy(ts_Cel_Fmt[EN ].tc_Fmt_Lib,"English no th. sep");
strcpy(ts_Cel_Fmt[EN ].tc_Fmt_Exe,"34123.02");
ts_Cel_Fmt[EN ].i_Len_Max = 13;
strcpy(ts_Cel_Fmt[LA_TH].tc_Fmt_Lib,"Latin th. sep");
strcpy(ts_Cel_Fmt[LA_TH].tc_Fmt_Exe,"34.123,02");
ts_Cel_Fmt[LA_TH].i_Len_Max = 16;
strcpy(ts_Cel_Fmt[LA ].tc_Fmt_Lib,"Latin no th. sep");
strcpy(ts_Cel_Fmt[LA ].tc_Fmt_Exe,"34123,02");
ts_Cel_Fmt[LA ].i_Len_Max = 13;
strcpy(ts_Cel_Fmt[CDS ].tc_Fmt_Lib,"Condensed no th/dec");
strcpy(ts_Cel_Fmt[CDS ].tc_Fmt_Exe,"3412302");
ts_Cel_Fmt[CDS ].i_Len_Max = 12;
// check if configuration file existe and save the data
//Create the default configuration parameter
Set_Def_Par();
}
else
{
}
}
void Cf::Set_Def_Par() // Set Default parameter
{
//set the default parameters
i_Nbr_Dec = 2; // Number of decimal
i_Cel_Fmt = LA_TH;
}
Cf::~Cf()
{
}
/**************************************************************************************************/
/* Cel_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Classe function for Cel
// Father class of Ope (Operation row) and Res(Result row)
#include "Glo_Def.h"
Cel::Cel()
{
}
void Cel::Del_Cel(Cel *pcl_Cur_Cel)
{
pcl_Cur_Cel->pcl_Nxt_Cel->pcl_Pre_Cel =
pcl_Cur_Cel->pcl_Pre_Cel;
pcl_Cur_Cel->pcl_Pre_Cel->pcl_Nxt_Cel =
pcl_Cur_Cel->pcl_Nxt_Cel;
}
void Cel::Del_All_Cel(Cel *pcl_Fir_Cel)
{
Cel *pcl_Cel= pcl_Fir_Cel;
Cel *pcl_Cel_sv;
while (pcl_Cel !=NULL)
{
pcl_Cel_sv = pcl_Cel->pcl_Nxt_Cel;
delete pcl_Cel;
pcl_Cel=pcl_Cel_sv;
}
}
Cel::~Cel()
{
}
/**************************************************************************************************/
/* Ope_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Classe Ope
// writing, updating, deleting a operation raw
// It is made with a signe , a number and an operation
#include "Glo_Def.h"
Op:: Op(Cel *pcl_Cur_Cel)
{
if (pcl_Cur_Cel == NULL) // First object
{
pcl_Pre_Cel = NULL;
Cf *pcl_Cf;
pcl_Cf= new Cf(TRUE);
// Cel::Put_Cf(pcl_Cf);
}
else
{
pcl_Pre_Cel = pcl_Cur_Cel ;
pcl_Pre_Cel->pcl_Nxt_Cel = this;
}
pcl_Nxt_Cel = NULL;
d_Nbr=0;
d_Nbr_sv=0;
i_Nbr_Cur_Pos = LEN_MAX-1;
i_Nbr_of_Cha = 0;
e_Cur_Fld = NBR;
c_Sig = ' ';
int i;
for (i=0;i(LEN_MAX -1 -i_Nbr_of_Cha))
{
i_Nbr_Cur_Pos--;
}
else
{
if (i_Nbr_of_Cha != 0)
e_Cur_Fld = SIG;
}
break;
case KEY_RIGHT:
if(i_Nbr_Cur_Pos < LEN_MAX-1)
{
i_Nbr_Cur_Pos++;
}
else
{
if (i_Nbr_of_Cha != 0)
e_Cur_Fld = OPE;
}
break;
case KEY_BACKSPACE:
if (i_Nbr_Cur_Pos<=LEN_MAX-i_Nbr_of_Cha )
{ /* Error no digits to delete at the left side of the cursor */
}
else
{ /* suppress caracter at the left */
Mve_Rht_Bks();
i_Nbr_of_Cha--;
Prt_Nbr(pw_Win_Cel,i_Row_y,i_Row_x);
}
break;
case KEY_DC:
if( i_Nbr_of_Cha == 0|| tc_Nbr[i_Nbr_Cur_Pos]==' ' )
{ /* Error No caracter to suppress */
}
else
{
if (i_Nbr_of_Cha== 1)
{
tc_Nbr[i_Nbr_Cur_Pos]= ' ';
i_Nbr_of_Cha= 0;
}
else
{ /* suppress caracter at the left */
Mve_Rht_Dc();
i_Nbr_of_Cha--;
if
(
i_Nbr_Cur_Pos= 'a', i_c <= 'z')
)
return i_c;
break;
}
}
return ' ';
}
int Op::Get_Ope(WINDOW *pw_Win_Cel,int i_c,int i_Row_y,int i_Row_x)
{
switch (i_c)
{
case '-':
case '+':
case '*':
case '/':
c_Ope = i_c;
Prt_Ope(pw_Win_Cel,i_Row_y,i_Row_x);
return KEY_RIGHT;
break;
case KEY_LEFT :
e_Cur_Fld = NBR;
break;
case '=' :
case 't' :
if (pcl_Nxt_Cel == NULL)
{
c_Ope = '=';
Prt_Ope(pw_Win_Cel,i_Row_y,i_Row_x);
return '=';
}
break;
default :
return i_c;
break;
}
return ' ';
}
void Op::Mve_Lft(void)
{
int i;
for (i= 0;i <= i_Nbr_Cur_Pos;i++)
{
tc_Nbr[i]=tc_Nbr[i+1];
}
}
void Op::Mve_Rht_Bks(void)
{
int i;
if (i_Nbr_of_Cha==LEN_MAX)
{
tc_Nbr[0]=' ';
}
else
{
for (i= i_Nbr_Cur_Pos-1;i>0;i--)
{
tc_Nbr[i]=tc_Nbr[i-1];
}
}
}
void Op::Mve_Rht_Dc (void)
{
int i;
for (i= i_Nbr_Cur_Pos; i>0 ;i--)
{
tc_Nbr[i]=tc_Nbr[i-1];
}
tc_Nbr[0]=' ';
}
void Op::Str_to_Num(void)
{
int i;
char tc_Sig_Nom[LEN_MAX+2];//+2 for the signe and for the string end
for (i= 0;i < LEN_MAX+2 ;i++)
{
tc_Sig_Nom[i]=' ';
}
tc_Sig_Nom[LEN_MAX+1] = '\0';
for (i= LEN_MAX-1;i >= LEN_MAX-i_Nbr_of_Cha ;i--)
{
tc_Sig_Nom[i+1]=tc_Nbr[i];
}
tc_Sig_Nom[i+1]=c_Sig;
d_Nbr = strtod(tc_Sig_Nom,NULL);
}
long double Op::Get_Dig_Nbr ()
{
return d_Nbr;
}
bool Op::Get_Cel_Mod ()
{
if(d_Nbr != d_Nbr_sv ||c_Ope !=c_Ope_sv)
{return true;}
else
{return false;}
}
void Op::Sav_Cel()
{
d_Nbr_sv = d_Nbr;
c_Ope_sv = c_Ope;
}
Op:: ~Op()
{
}
/**************************************************************************************************/
/* Res_Clf.C */
/**************************************************************************************************/
/* Although I am far away to think this calculator can be useful as an aplication for accounter,
Calc Vers 0.0001 Copyright (C) 2001 Marc Dechico
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
To contact the author: Marc Dechico
Kerfring
29390 SCAER France
tel: 06 80 83 74 99
Mail: Marc.DECHICO@wanadoo.fr
*/
// Classe Res
// writing, updating, deleting a Result-Cell
// a Result Cell is made with a signe and number(not updatable)
// and an operation (updatable)
#include "Glo_Def.h"
Rs:: Rs(Cel *pcl_Cur_Cel, Cel *pcl_Fir_Cel)
{
int b;
if (pcl_Cur_Cel != NULL) //
{
pcl_Pre_Cel = pcl_Cur_Cel ;
pcl_Pre_Cel->pcl_Nxt_Cel = this;
pcl_Nxt_Cel = NULL;
i_Nbr_of_Cha = 0;
c_Sig = ' ';
Acc *pcl_Fir_Acc;
Acc *pcl_Cur_Acc;
pcl_Cur_Acc = new Acc(NULL);
pcl_Fir_Acc = pcl_Cur_Acc;
d_Acc = pcl_Fir_Acc->Cal_Tot(pcl_Fir_Cel);
delete pcl_Fir_Acc;
// convert num to alpha
Num_to_Alp(d_Acc);
c_Ope = ' ';
c_Ope_sv = ' ';
}
}
void Rs::Prt_Row(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
Prt_Sig(pw_Win_Cel,i_Row_y,i_Row_x);
Prt_Acc(pw_Win_Cel,i_Row_y,i_Row_x);
Prt_Ope(pw_Win_Cel,i_Row_y,i_Row_x);
}
void Rs::Prt_Sig(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
mvwaddch(
pw_Win_Cel,
i_Row_y ,
i_Row_x,
c_Sig
);
}
void Rs::Prt_Acc(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
int x,y,i,l;
y= i_Row_y;
x= i_Row_x +LEN_MAX;
l= strlen(tc_Acc);
if (l<=LEN_MAX)
{
for(i=l-1;i >=1 ;i--)
{
mvwaddch(pw_Win_Cel,y,x--,tc_Acc[i]);
}
if (tc_Acc[i] != '-')
{ mvwaddch(pw_Win_Cel,y,x--,tc_Acc[i]);}
}
else
{
mvwaddstr(pw_Win_Cel,y,i_Row_x+1,tc_Acc);
}
}
void Rs::Prt_Ope(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
mvwaddch(
pw_Win_Cel,
i_Row_y,
i_Row_x + LEN_MAX +2,
c_Ope
);
}
void Rs::Clr_Sig(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
mvwaddch(
pw_Win_Cel,
i_Row_y ,
i_Row_x,
' '
);
}
void Rs::Clr_Acc(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
int x,y,i;
y= i_Row_y ;
x= i_Row_x + 1;
for(i=0;i < LEN_MAX ;i++)
{
mvwaddch(pw_Win_Cel,y,x++,' ');
}
}
void Rs::Clr_Ope(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
mvwaddch(
pw_Win_Cel,
i_Row_y ,
i_Row_x + LEN_MAX +2,
' '
);
}
void Rs::Set_Cur(WINDOW *pw_Win_Cel,int i_Row_y,int i_Row_x)
{
wmove(
pw_Win_Cel,
i_Row_y ,
i_Row_x + LEN_MAX + 2
);
}
int Rs::Get_Cel(WINDOW *pw_Win_Cel,int i_c,int i_Row_y,int i_Row_x)
{
i_c = Get_Ope(pw_Win_Cel,i_c,i_Row_y, i_Row_x);
// Do not allow to create a new cell without needed info
if (
(i_c == KEY_RIGHT || i_c == KEY_DOWN )
&&
( c_Ope == ' ')
)
{i_c = ' ';}
return (i_c);
}
int Rs::Get_Ope(WINDOW *pw_Win_Cel,int i_c,int i_Row_y,int i_Row_x)
{
switch (i_c)
{
case '-':
case '+':
case '*':
case '/':
c_Ope = i_c;
Prt_Ope(pw_Win_Cel,i_Row_y,i_Row_x);
return KEY_RIGHT;
break;
case '=':
case 't':
break;
default :
return i_c;
break;
}
return ' ';
}
long double Rs:: Get_Dig_Nbr()
{
return d_Acc;
}
void Rs:: Num_to_Alp(long double d_Acc)
{
int decpt;
int sign;
Clr_tc_Acc();
fcvt_r(d_Acc,0,&decpt,&sign,tc_Acc_Wrk,LEN_MAX_CHA_CON);
if ( sign != 0 ) c_Sig = '-';
if ( strlen(tc_Acc_Wrk) <= 12 )
{
strcpy( tc_Acc ,tc_Acc_Wrk );
}
else
{
strcpy( tc_Acc , "Ovrflow");
}
}
void Rs:: Clr_tc_Acc(void)
{
int i;
for (i=0;ipcl_Nxt_Acc = this;
}
pcl_Nxt_Acc = NULL;
}
long double Acc::Cal_Tot(Cel *pcl_Fir_Cel)
{
int b;
Cel *pcl_Cel = pcl_Fir_Cel;
d_Acc = pcl_Cel->Get_Dig_Nbr();
while (pcl_Cel->pcl_Nxt_Cel !=NULL)
{
pcl_Cel = pcl_Cel->pcl_Nxt_Cel;
switch(pcl_Cel->pcl_Pre_Cel->c_Ope)
{
case '+':
d_Acc += pcl_Cel->Get_Dig_Nbr();
break;
case '-':
d_Acc -= pcl_Cel->Get_Dig_Nbr();
break;
case '*':
d_Acc *= pcl_Cel->Get_Dig_Nbr();
break;
case '/':
d_Acc /= pcl_Cel->Get_Dig_Nbr();
break;
case '=':
Rs *pcl_Rs;
pcl_Rs = dynamic_cast(pcl_Cel);
if (pcl_Rs != NULL)
pcl_Rs->d_Acc=d_Acc;
pcl_Rs->Num_to_Alp(pcl_Rs->d_Acc);
break;
default :
break;
}
}
return d_Acc;
}
Acc::~Acc()
{
if (pcl_Nxt_Acc!=NULL)
delete pcl_Nxt_Acc;
}
#*************************************************************************************************
# Makefile
#*************************************************************************************************
LIBS = -lpanel -lncurses
DBG =
all:calc
calc: main.o Mai_Clf.o Cfg_Clf.o Cel_Clf.o Ope_Clf.o Acc_Clf.o Res_Clf.o Cal_Clf.o
g++ $(DBG) -o calc main.o Mai_Clf.o Cfg_Clf.o Cel_Clf.o Ope_Clf.o Acc_Clf.o Res_Clf.o Cal_Clf.o $(LIBS)
main.o: main.C Glo_Def.h
g++ $(DBG) -c main.C
Mai_Clf.o: Mai_Clf.C Glo_Def.h
g++ $(DBG) -c Mai_Clf.C
Cfg_Clf.o: Cfg_Clf.C Glo_Def.h
g++ $(DBG) -c Cfg_Clf.C
Cel_Clf.o: Cel_Clf.C Glo_Def.h
g++ $(DBG) -c Cel_Clf.C
Ope_Clf.o: Ope_Clf.C Glo_Def.h
g++ $(DBG) -c Ope_Clf.C
Acc_Clf.o: Acc_Clf.C Glo_Def.h
g++ $(DBG) -c Acc_Clf.C
Res_Clf.o: Res_Clf.C Glo_Def.h
g++ $(DBG) -c Res_Clf.C
Cal_Clf.o: Cal_Clf.C Glo_Def.h
g++ $(DBG) -c Cal_Clf.C
clean :
rm -f *.o