From: Mapi B. <ma...@us...> - 2011-02-28 22:07:20
|
Update of /cvsroot/easycalc/PPCport/core In directory vz-cvs-4.sog:/tmp/cvs-serv3275 Modified Files: core_globals.h core_main.cpp varmgr.cpp varmgr.h Added Files: finance.cpp finance.h graph.cpp graph.h grprefs.cpp grprefs.h grsetup.cpp grsetup.h memo.cpp memo.h solver.cpp solver.h Log Message: 1.25g Index: core_globals.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/core_globals.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** core_globals.h 2 Nov 2009 17:20:08 -0000 1.5 --- core_globals.h 28 Feb 2011 22:07:18 -0000 1.6 *************** *** 25,40 **** #define NB_KEYS BUTTON_COUNT // Keep KEY_SHIFT the smallest one in list, just after KEY_NONE ! #define KEY_CLR -1 ! #define KEY_BCKSPC -2 ! #define KEY_EXE -3 ! #define KEY_DOT -4 ! #define KEY_SHIFT -5 ! #define KEY_NONE -6 #define RESULT_AREA -99 /*********************/ /* Annunciator codes */ /*********************/ ! #define NB_ANNUN 19 #define ANN_SHIFT 0 #define ANN_DEG 1 --- 25,59 ---- #define NB_KEYS BUTTON_COUNT // Keep KEY_SHIFT the smallest one in list, just after KEY_NONE ! #define KEY_CLR -1 ! #define KEY_BCKSPC -2 ! #define KEY_EXE -3 ! #define KEY_DOT -4 ! #define KEY_CTRZONE -5 ! #define KEY_CTRWIDE -6 ! #define KEY_GPREFS -7 ! #define KEY_GCONF -8 ! #define KEY_GCALC -9 ! #define KEY_GSETX -10 ! #define KEY_ZONEIN -11 ! #define KEY_ZONEOUT -12 ! #define KEY_WIDEIN -13 ! #define KEY_WIDEOUT -14 ! #define KEY_NORMZON -15 ! #define KEY_SHIFT -16 ! #define KEY_NONE -17 ! ! /*******************/ ! /* Values for skey */ ! /*******************/ ! #define NOSKEY -1 ! #define ANNUNBASE -2 #define RESULT_AREA -99 + #define ZONE_AREA -100 + #define WVIEW_AREA -101 /*********************/ /* Annunciator codes */ /*********************/ ! #define NB_ANNUN 35 #define ANN_SHIFT 0 #define ANN_DEG 1 *************** *** 56,59 **** --- 75,94 ---- #define ANN_RESMENU 17 #define ANN_HSTMENU 18 + #define ANN_SELZONE 19 + #define ANN_MOVGRPH 20 + #define ANN_TRACKPT 21 + #define ANN_CTRWIDE 22 + #define ANN_ZONMAXY 23 + #define ANN_ZONMINY 24 + #define ANN_ZONMINX 25 + #define ANN_ZONMAXX 26 + #define ANN_WONZ_XR 27 + #define ANN_WONZ_YR 28 + #define ANN_PARAM0 29 + #define ANN_PARAM 30 + #define ANN_YVALUE 31 + #define ANN_XVALUE 32 + #define ANN_RVALUE 33 + #define ANN_CURVENB 34 /******************************/ *************** *** 76,79 **** --- 111,126 ---- #define ANNVAL_SCR_LEFT 1 #define ANNVAL_SCR_RIGHT 2 + // Effect on display zone Effect on wide view + #define ANNVAL_PEN_SELZONE 0 // Drag = define zone + upd(x0,x,y) = define zone + upd(x0,x,y) + // Tap = set(x,y) = set(x,y) + #define ANNVAL_PEN_MOVZONE 1 // Drag = set(x,y) = set(x,y) + // + move graph in zone + move graph in wide view + // Tap = set(x,y) = set(x,y) + set zone center + #define ANNVAL_PEN_TRACKPT 2 // Drag = upd(x0,x,Yn(x)) = set(x,Yn(x)) + deselect + // + define calc select zone + // Tap = set(x,Yn(x)) + deselect = set(x,Yn(x)) + deselect + #define ANNVAL_PEN_CTRWIDE 3 // Same as MOVZONE = move zone center + // + set(x,y) + // Same as MOVZONE = Same as MOVZONE --- NEW FILE: memo.h --- /* * $Id: memo.h,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. * */ #ifndef _MEMO_H_ #define _MEMO_H_ //#define MAX_DUMP 4000 #define MAX_DUMP 61000 #define EQUATIONS 999 Boolean memo_import_memo(Skin *skin, void *hWnd_p, const TCHAR *filename, Boolean unicode); void memo_dump(rpntype type, const TCHAR *filename, Boolean unicode); #endif --- NEW FILE: grprefs.h --- /* * $Id: grprefs.h,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999,2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. */ #ifndef _GRPREFS_H_ #define _GRPREFS_H_ #include "compat/segment.h" #include "core/mlib/defuns.h" #define MIN_LOG_VAL 1E-5 typedef enum { graph_func, graph_polar, graph_param, nb_func_types } Tfunctype; typedef struct { double xmin, ymin; double xmax, ymax; double xscale, yscale; double fimin, fimax, fistep; double tmin, tmax, tstep; Tfunctype functype; TCHAR funcFunc[MAX_GRFUNCS][MAX_FUNCNAME+1]; TCHAR funcPol[MAX_GRFUNCS][MAX_FUNCNAME+1]; TCHAR funcPar[MAX_GRFUNCS][2][MAX_FUNCNAME+1]; // Warning: compared to original EasyCalc // code, this is inverted: // 0 -> y // 1 -> x Boolean logx,logy; Boolean saved_reducePrecision; Int16 speed; IndexedColorType colors[9]; Boolean grEnable[nb_func_types][9]; Int8 grType[6]; } TgrPrefs; //Boolean GraphPrefsHandleEvent(EventPtr event) IFACE; CError grpref_comp_field(TCHAR *text, double *value); Int16 grpref_verify_values (void) IFACE; CError set_axis(Functype *func, CodeStack *stack) GRAPH; extern TgrPrefs graphPrefs; extern TgrPrefs viewPrefs; extern RGBColorType graphRGBColors[]; extern const TdispPrefs grDPrefs; #endif --- NEW FILE: solver.h --- /* * $Id: solver.h,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. */ #ifndef _SOLVER_H_ #define _SOLVER_H_ #define SOLVER_ID 201 #define SLV_OFF 1 #define SLV_SOLVE 2 #define SLV_CALCULATE 3 #define SLV_ON 4 #ifndef _SOLVER_C_ extern DmOpenRef slv_gDB; extern Int16 slv_selectedWorksheet; extern double worksheet_min; extern double worksheet_max; extern double worksheet_prec; TCHAR worksheet_title[]; extern TCHAR *worksheet_note; #endif Int16 slv_db_open(void); Int16 slv_db_close(void); void slv_init(void); void slv_close(void); Int16 slv_save_worksheet(void); void slv_select_worksheet(void); Int16 slv_new_worksheet(TCHAR *name); void slv_update_worksheet(void); void slv_destroy_varlist(void); Int16 slv_init_varlist(void); CError slv_solve(Int16 selection); void slv_calculate(void); void slv_create_initial_note(void); TCHAR *slv_getVar(int i); void slv_update_help(int i); Boolean slv_comp_field(TCHAR *text, double *value); Boolean slv_memo_import(TCHAR *text); Boolean slv_export_memo(FILE *f, TCHAR *separator); #endif --- NEW FILE: grprefs.cpp --- /* * $Id: grprefs.cpp,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999,2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. */ #include "stdafx.h" #include "compat/PalmOS.h" #include "core/mlib/display.h" #include "core/grprefs.h" #include "core/mlib/defuns.h" #include "compat/MathLib.h" #include "core/mlib/stack.h" #include "core/prefs.h" #include "core/Main.h" #include "core/calc.h" #include "core/mlib/mathem.h" #include "core/mlib/fp.h" /* Local structure - values in function mode */ TgrPrefs graphPrefs; TgrPrefs viewPrefs; /* Colors of functions and background, axis, grid */ RGBColorType graphRGBColors[] = { {0, 255, 0, 0}, {0, 0, 255, 0}, {0, 0, 0, 255}, {0, 128, 128, 0}, {0, 0, 128, 128}, {0, 128, 0, 128}, {0, 0x0b, 0x23, 0x27}, /* axis */ {0, 128, 128, 128}, /* grid */ {0, 0xa3, 0xb3, 0x9d} /* background */ }; /* Gray colors: 6 funcs + axis + grid + backgrnd */ IndexedColorType funcolors[9] = {15, 11, 7, 13, 9, 5, 15, 8, 0}; /* Display mode for preferences */ const TdispPrefs grDPrefs = {9, true, disp_normal, disp_decimal, false, false}; /*********************************************************************** * * FUNCTION: grpref_compl_field * * DESCRIPTION: Computes the 'real' value of a text field * * PARAMETERS: objectID - id of the field * * RETURN: CError - 0 on success * *value - the computed value * ***********************************************************************/ CError grpref_comp_field(TCHAR *text, double *value) { CError err; CodeStack *stack; stack = text_to_stack(text, &err); if (!err) { err = stack_compute(stack); if (!err) err = stack_get_val(stack, (void *) value, real); stack_delete(stack); } return ((CError) (err || !finite(*value))); } /*********************************************************************** * * FUNCTION: grpref_verify_values * * DESCRIPTION: Verify values for graph preferences * * PARAMETERS: None * * RETURN: 1 - success * 0 - error while computing * ***********************************************************************/ Int16 grpref_verify_values (void) { if ((graphPrefs.xscale < 0.0) || (graphPrefs.yscale < 0.0)) return (0); if ((graphPrefs.xmin >= graphPrefs.xmax) || (graphPrefs.ymin >= graphPrefs.ymax)) return (0); if (graphPrefs.logx && (graphPrefs.xmin <= 0.0)) return (0); if (graphPrefs.logy && (graphPrefs.ymin <= 0.0)) return (0); if (graphPrefs.functype == graph_polar) { if ((graphPrefs.fimin > graphPrefs.fimax) || ((graphPrefs.fimax-graphPrefs.fimin)/graphPrefs.fistep > 10000.0) || (graphPrefs.fistep <= 0.0)) /* check that min<max and step is reasonable */ return (0); } else if (graphPrefs.functype == graph_param) { if ((graphPrefs.tmin > graphPrefs.tmax) || ((graphPrefs.tmax-graphPrefs.tmin)/graphPrefs.tstep > 10000.0) || (graphPrefs.tstep <= 0.0)) /* check that min<max and step is reasonable */ return (0); } return (1); } /*********************************************************************** * * FUNCTION: set_axis * * DESCRIPTION: * * PARAMETERS: * * RETURN: * ***********************************************************************/ CError set_axis (Functype *func, CodeStack *stack) { List *lst, *lst2; double xscale = graphPrefs.xscale; double yscale = graphPrefs.yscale; int i; CError err; if (func->paramcount > 2) return (c_badargcount); else if (func->paramcount == 2) { err = stack_get_val(stack, &lst2, list); if (err) return (err); if (lst2->size != 2){ MemPtrFree(lst2); return (c_baddim); } if ((lst2->item[0].imag != 0.0) || (lst2->item[1].imag != 0.0)) { MemPtrFree(lst2); return (c_badarg); } xscale = lst2->item[0].real; yscale = lst2->item[1].real; MemPtrFree(lst2); if ((xscale <= 0.0) || (yscale <= 0.0)) return (c_badarg); } err = stack_get_val(stack, &lst, list); if (err) return (err); if (lst->size != 4) { MemPtrFree(lst); return (c_baddim); } for (i=0 ; i<4 ; i++) if (lst->item[i].imag != 0.0) { MemPtrFree(lst); return (c_badarg); } if((lst->item[0].real >= lst->item[1].real) || (lst->item[2].real >= lst->item[3].real)) { MemPtrFree(lst); return (c_badarg); } graphPrefs.xmin = lst->item[0].real; graphPrefs.xmax = lst->item[1].real; graphPrefs.ymin = lst->item[2].real; graphPrefs.ymax = lst->item[3].real; if (func->paramcount == 2) { graphPrefs.xscale = xscale; graphPrefs.yscale = yscale; graphPrefs.grEnable[graphPrefs.functype][7] = true; } else graphPrefs.grEnable[graphPrefs.functype][7] = false; err = stack_add_val(stack, &lst, list); MemPtrFree(lst); return (err); } Index: core_main.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/core_main.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** core_main.cpp 2 Nov 2009 17:20:08 -0000 1.4 --- core_main.cpp 28 Feb 2011 22:07:18 -0000 1.5 *************** *** 75,79 **** if (mode_shift != state) { mode_shift = state; ! shell_annunciators(ANNVAL_UNCH, state, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH); } } --- 75,79 ---- if (mode_shift != state) { mode_shift = state; ! shell_annunciators(ANNVAL_UNCH, state, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH); } } *************** *** 201,205 **** if (key != KEY_NONE) { if (mode_getkey && mode_running) ! shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, true); keydown(mode_shift, key); if (repeating != 0) { --- 201,205 ---- if (key != KEY_NONE) { if (mode_getkey && mode_running) ! shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, true); keydown(mode_shift, key); if (repeating != 0) { *************** *** 253,256 **** --- 253,269 ---- skin->insert_input_text(NULL, &flPointChar); break; + case KEY_CTRZONE: + case KEY_CTRWIDE: + case KEY_GPREFS: + case KEY_GCONF: + case KEY_GCALC: + case KEY_GSETX: + case KEY_ZONEIN: + case KEY_ZONEOUT: + case KEY_WIDEIN: + case KEY_WIDEOUT: + case KEY_NORMZON: + shell_graphAction(repeating_key); + break; default: main_btnrow_click(skin, repeating_key); --- NEW FILE: graph.cpp --- /* * $Id: graph.cpp,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999,2000,2001 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. * * 2001-09-31 - John Hodapp <bi...@em...> * Added code for display of trig mode and its selection * on the Graph screen. * * 2003-05-19 - Arno Welzel <arn...@gm...> * Added code to handle Sony Clie specific output using * Sony the HR lib */ #include "stdafx.h" #define _GRAPH_CPP_ #include "compat/PalmOS.h" //#include "clie.h" #include "core/mlib/defuns.h" #include "compat/MathLib.h" #include "core/mlib/konvert.h" #include "core/mlib/funcs.h" #include "core/mlib/calcDB.h" //#include "calcrsc.h" #include "core/prefs.h" #include "core/calc.h" #include "core/mlib/mathem.h" #include "core/mlib/stack.h" #include "core/varmgr.h" //#include "main.h" #include "core/grsetup.h" #include "core/Graph.h" #include "system - UI/Skin.h" //#include "grcalc.h" //#ifdef SUPPORT_DIA //#include "DIA.h" //#endif static struct { Boolean active; Boolean complete; int position; int funcnum; double start; double stop; double step; } graphState; Graph zoneGraph; Graph viewGraph; Tgraph_curves graphCurves[MAX_GRFUNCS]; TCHAR *lstGraphCalc[] = { _T("$$GRZERO"), _T("$$GRVALUE"), _T("$$GRMIN"), _T("$$GRMAX"), _T("$$GRDDX"), _T("d2/dx"), _T("$$GRINTEG"), _T("$$GRINTERSECT"), _T("dr/dt"), _T("dy/dx"), _T("dy/dt"), _T("dx/dt") }; t_grFuncType grcFunc[GRCFUNC_SZ] = {cp_zero, cp_value, cp_min, cp_max, cp_dydx1, cp_dydx2, cp_integ, cp_intersect}; t_grFuncType grcPolar[GRCPOLAR_SZ] = {cp_zero, cp_value, cp_min, cp_max, cp_odrdfi}; t_grFuncType grcParam[GRCPARAM_SZ] = {cp_pdydx, cp_pdydt, cp_pdxdt}; /*********************************************************************** * * FUNCTION: graph_init_cache * * DESCRIPTION: Initializes the field of precompiled functions with * NULLs * * PARAMETERS: Nothing * * RETURN: Nothing * ***********************************************************************/ void graph_init_cache (void) { Int16 i; for (i=0 ; i<MAX_GRFUNCS ; i++) { graphCurves[i].stack1 = NULL; graphCurves[i].stack2 = NULL; } } /*********************************************************************** * * FUNCTION: graph_clean_cache * * DESCRIPTION: Frees memory occupied by precompiled functions * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void graph_clean_cache (void) { Int16 i; for (i=0 ; i<MAX_GRFUNCS ; i++) { if (graphCurves[i].stack1) { stack_delete(graphCurves[i].stack1); graphCurves[i].stack1 = NULL; } if (graphCurves[i].stack2) { stack_delete(graphCurves[i].stack2); graphCurves[i].stack2 = NULL; } } } /*********************************************************************** * * FUNCTION: graph_compile_cache * * DESCRIPTION: Compiles functions that should be drawn and saves * for later use * * PARAMETERS: None * * RETURN: Nothing * ***********************************************************************/ static void graph_compile_cache (void) { int i; TCHAR *name; CodeStack *stack; CError err; graph_clean_cache(); if ((graphPrefs.functype == graph_func) || (graphPrefs.functype == graph_polar)) { for (i=0 ; i<MAX_GRFUNCS ; i++) { name = grsetup_get_fname(i); if (StrLen(name) == 0) continue; stack = db_read_function(name, &err); if (err) continue; /* Lookup variables to speed up execution */ stack_fix_variables(stack); graphCurves[i].stack1 = stack; } } else { /* Parametric */ for (i=0 ; i<MAX_GRFUNCS ; i++) { name = grsetup_get_fname(i*2); if (StrLen(name) == 0) continue; stack = db_read_function(name, &err); if (err) continue; /* Lookup variables to speed up execution */ stack_fix_variables(stack); graphCurves[i].stack1 = stack; name = grsetup_get_fname(i*2 + 1); if (StrLen(name) == 0) continue; stack = db_read_function(name, &err); if (err) continue; /* Lookup variables to speed up execution */ stack_fix_variables(stack); graphCurves[i].stack2 = stack; } } } /*********************************************************************** * * FUNCTION: graph_draw_stop, graph_draw_resume * * DESCRIPTION: Stop/resume drawing functions * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void graph_draw_resume (void) { graphState.active = true; } void graph_draw_stop (void) { graphState.active = false; } void graph_draw_complete (void) { graphState.active = false; graphState.complete = true; } bool is_graph_active (void) { return (graphState.active); } bool is_graph_complete (void) { return (graphState.complete); } /*********************************************************************** * * FUNCTION: graph_get_zoneOnView * * DESCRIPTION: Calculate coordinates of the zone in view reference. * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void graph_get_zoneOnView (long *top, long *left, long *bottom, long *right) { // Assumes being called only after view graph has been drawn on screen *top = viewGraph.graph_ygr2scr(graphPrefs.ymax); *left = viewGraph.graph_xgr2scr(graphPrefs.xmin); *bottom = viewGraph.graph_ygr2scr(graphPrefs.ymin); *right = viewGraph.graph_xgr2scr(graphPrefs.xmax); } /*********************************************************************** * * FUNCTION: graph_is_onscreen * * DESCRIPTION: If the coordinates fit on the screen * * PARAMETERS: x,y - coordinates of the original function * * RETURN: true - fits, false - outside * ***********************************************************************/ Boolean Graph::graph_is_onscreen (double x, double y) { if ((x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)) return (true); return (false); } /*********************************************************************** * * FUNCTION: graph_xgr2scr * * DESCRIPTION: Convert the 'x' or 'y' coordinate from the function to * screen coordinates * * PARAMETERS: x or y * * RETURN: coordinate * ***********************************************************************/ Coord Graph::graph_xgr2scr (double x) { if (graphPrefs.logx) { x = (log10(x) - ScrPrefs.logxmin) / ScrPrefs.logxtrans; return ((Coord) (round(x))); } return ((Coord) (round((x - xmin) / ScrPrefs.xtrans))); } Coord Graph::graph_ygr2scr (double y) { if (graphPrefs.logy) { y = (log10(y) - ScrPrefs.logymin) / ScrPrefs.logytrans; return ((Coord) (round(y))); } return ((Coord) (round((y - ymin) / ScrPrefs.ytrans))); } /*********************************************************************** * * FUNCTION: graph_xscr2gr * * DESCRIPTION: Convert a screen 'x' (or y) coordinate to a graph coordinate * * PARAMETERS: x or y * * RETURN: coordinate * ***********************************************************************/ double Graph::graph_xscr2gr (Coord scr_x) { double res; if (graphPrefs.logx) { res = ScrPrefs.logxmin + ((double) scr_x) * ScrPrefs.logxtrans; res = pow(10.0, res); } else res = xmin + ((double) scr_x) * ScrPrefs.xtrans; return (res); } double Graph::graph_yscr2gr (Coord scr_y) { double res; if (graphPrefs.logy) { res = ScrPrefs.logymin + ((double) scr_y) * ScrPrefs.logytrans; res = pow(10.0, res); } else res = ymin + ((double) scr_y) * ScrPrefs.ytrans; return (res); } /*********************************************************************** * * FUNCTION: graph_isec_y * * DESCRIPTION: Find an intersection of a line with a vertical line * - it is used when drawing lines towards a point outside of * the drawing area * * PARAMETERS: x1,y1 - point 1 * x2,y2 - point 2 * x3 - the vertical line * RETURN: y3 - the point on the vertical line * ***********************************************************************/ double Graph::graph_isec_y (double x1, double y1, double x2, double y2, double x3) { double sidea, sideb, parta; sidea = y2 - y1; sideb = x2 - x1; parta = x2 - x3; return (y2 - (sidea * parta) / sideb); } #define graph_isec_x(x1,y1,x2,y2,y3) (graph_isec_y(y1,x1,y2,x2,y3)) /*********************************************************************** * * FUNCTION: graph_outscreen * * DESCRIPTION: Find a point, where a line should be drawn instead of * the point outside of drawing area * * PARAMETERS: onx,ony - points in the drawing area * offx,offy - points outside drawing area * * RETURN: newx,newy - new points on the border of drawing area * ***********************************************************************/ void Graph::graph_outscreen (double *newx, double *newy, double onx, double ony, double offx, double offy) { double tmp; tmp = graph_isec_x(onx, ony, offx, offy, ymin); if ((offy < ymin) && (tmp >= xmin) && (tmp <= xmax)) { *newx = tmp; *newy = ymin; return; } tmp = graph_isec_x(onx, ony, offx, offy, ymax); if ((offy > ymax) && (tmp >= xmin) && (tmp <= xmax)) { *newx = tmp; *newy = ymax; return; } tmp = graph_isec_y(onx, ony, offx, offy, xmin); if ((offx < xmin) && (tmp >= ymin) && (tmp <= ymax)) { *newx = xmin; *newy = tmp; return; } tmp = graph_isec_y(onx, ony, offx, offy, xmax); if ((offx > xmax) && (tmp >= ymin) && (tmp <= ymax)) { *newx = xmax; *newy = tmp; return; } if (offx > onx) *newx = onx + ScrPrefs.xtrans; else *newx = onx - ScrPrefs.xtrans; if (offy > ony) *newy = ony + ScrPrefs.ytrans; else *newy = ony - ScrPrefs.ytrans; if((isinf(offy) > 0) && finite(offx)) *newy = ymax; else if ((isinf(offy) < 0) && finite(offx)) *newy = ymin; else if ((isinf(offx) > 0) && finite(offy)) *newx = xmax; else if ((isinf(offx) < 0) && finite(offy)) *newx = xmin; else{ *newx = onx; *newy = ony; } } /*********************************************************************** * * FUNCTION: graph_new_point * * DESCRIPTION: Adds a new point to graph. Depending on the selected * style this function chooses way of drawing, colors etc. * * PARAMETERS: x,y - coordinates of a new point * funcnum - function number, where the point belongs to * * RETURN: Nothing * ***********************************************************************/ void Graph::graph_new_point (Skin *skin, Coord scr_x, double x, double y, Int16 funcnum) { Coord scr_y; Boolean ison = graph_is_onscreen(x, y); switch (graphPrefs.grType[funcnum]) { case 0: // Dots if (ison) { if (scr_x < 0) scr_x = graph_xgr2scr(x); scr_y = graph_ygr2scr(y); skin->drawline(scr_x, scr_y-1, scr_x, scr_y+1); skin->drawline(scr_x-1, scr_y, scr_x+1, scr_y); } break; case 2: // Surface if (!isnan(y)) { Coord scr_y0; if ((x > xmax) || (x < xmin)) break; /* polar, parametric or DRAW_AT_ONCE !=1 */ if (y > ymax){ if (ymax < 0) break; if (ymin > 0) scr_y0 = 0; else scr_y0 = ScrPrefs.y0 + 1; scr_y = ScrPrefs.ymax; } else if (y < ymin) { if (ymin > 0) break; if (ymax < 0) scr_y0 = ScrPrefs.ymax; else scr_y0 = ScrPrefs.y0 - 1; scr_y = 0; } else { scr_y = graph_ygr2scr(y); if (ymax < 0) scr_y0 = ScrPrefs.ymax; else if (ymin > 0) scr_y0 = 0; else scr_y0 = ScrPrefs.y0 + (int) (sgn(y)); } if (scr_x < 0) scr_x = graph_xgr2scr(x); scr_y = graph_ygr2scr(y); skin->drawline(scr_x, scr_y0, scr_x, scr_y); } break; default: // Line { double oldx = graphCurves[funcnum].x; double oldy = graphCurves[funcnum].y; if (!graphCurves[funcnum].valid) { if (ison) { if (scr_x < 0) scr_x = graph_xgr2scr(x); scr_y = graph_ygr2scr(y); skin->drawline(scr_x, scr_y, scr_x, scr_y); } graphCurves[funcnum].valid = true; } else if (graphCurves[funcnum].valid) { if (ison) { if (graphCurves[funcnum].ison) { if (scr_x < 0) scr_x = graph_xgr2scr(x); scr_y = graph_ygr2scr(y); skin->drawline(graphCurves[funcnum].scr_x, graphCurves[funcnum].scr_y, scr_x, scr_y); } else { /* Only second point on screen */ double newx, newy; graph_outscreen(&newx, &newy, x, y, oldx, oldy); if (scr_x < 0) scr_x = graph_xgr2scr(x); scr_y = graph_ygr2scr(y); skin->drawline(graph_xgr2scr(newx), graph_ygr2scr(newy), scr_x, scr_y); } } else if (graphCurves[funcnum].ison) { /* Only first point on screen */ double newx, newy; graph_outscreen(&newx, &newy, oldx, oldy, x, y); scr_x = graph_xgr2scr(newx); scr_y = graph_ygr2scr(newy); skin->drawline(graphCurves[funcnum].scr_x, graphCurves[funcnum].scr_y, scr_x, scr_y); // We have a discontinuity, do not forget to draw last point skin->finishline(graphPrefs.colors[funcnum]); } } break; } } // Keep track of current point as last point drawn graphCurves[funcnum].x = x; graphCurves[funcnum].y = y; graphCurves[funcnum].scr_x = scr_x; graphCurves[funcnum].scr_y = scr_y; graphCurves[funcnum].ison = ison; } /* Initialize cache variables to * avoid this time-expensive computation in the future */ void Graph::cacheTrans (void) { ScrPrefs.xtrans = (xmax - xmin) / ((double) (ScrPrefs.width - 1)); ScrPrefs.ytrans = (ymax - ymin) / ((double) (ScrPrefs.height - 1)); if (graphPrefs.logx) { ScrPrefs.logxtrans = (log10(xmax) - log10(xmin)) / ((double) (ScrPrefs.width)); ScrPrefs.logxmin = log10(xmin); } if (graphPrefs.logy) { ScrPrefs.logytrans = (log10(ymax) - log10(ymin)) / ((double) (ScrPrefs.height)); ScrPrefs.logymin = log10(ymin); } } //static void graph_grid (RectangleType *bounds) { // double tmpx, tmpy, ystart, xscale, yscale; // Coord x, y; // // xscale = xscale; // yscale = yscale; // // if ((xscale == 0.0) || (yscale == 0.0)) // return; // // if ((((ymax - ymin) / yscale) > ((ScrPrefs.ymin - ScrPrefs.ymax) / 3)) // || (((xmax - xmin) / xscale) > ((ScrPrefs.xmax - ScrPrefs.xmin) / 3))) // return; // // graph_setcolor(-2); // // tmpy = graph_yscr2gr(bounds->topLeft.y + bounds->extent.y); // ystart = ceil(tmpy / yscale) * yscale; // tmpx = graph_xscr2gr(bounds->topLeft.x); // tmpx = ceil(tmpx / xscale) * xscale; // for ( ; tmpx<=xmax ; tmpx+=xscale) { // x = graph_xgr2scr(tmpx); // for (tmpy=ystart ; tmpy<=ymax ; tmpy+=yscale) { // y = graph_ygr2scr(tmpy); // if (gHrMode != hrNone) { // /* Draw crosses in hi res ... */ // skin->drawline(x, y-1, x, y+1); // skin->drawline(x-1, y, x+1, y); // } else // /* otherwise just dots */ // skin->drawline(x, y, x, y); // } // } // // graph_unsetcolor(); //} //#ifndef SUPPORT_DIA //#define HanderaCoord(x) (x) //#endif /* Initializes Graph gadget and shows the basic grid */ void Graph::graph_init_screen (Skin *skin, int width, int height) { if (graphPrefs.logx && (xmin <= 0.0)) xmin = MIN_LOG_VAL; if (graphPrefs.logy && (ymin <= 0.0)) ymin = MIN_LOG_VAL; // ScrPrefs.xmin = 0; // ScrPrefs.ymin = 0; ScrPrefs.xmax = (ScrPrefs.width = width) - 1; ScrPrefs.ymax = (ScrPrefs.height = height) - 1; cacheTrans(); /* Draw axes */ int x = graph_xgr2scr(0.0); int y = ScrPrefs.y0 = graph_ygr2scr(0.0); if (graphPrefs.grEnable[graphPrefs.functype][6]) { /* axes drawing enabled */ skin->selPen(6); /* y axis */ if ((x >= 0) && (x <= ScrPrefs.xmax)) { skin->drawline(x, 0, x, ScrPrefs.ymax); skin->finishline(graphPrefs.colors[6]); } /* x axis */ if ((y >= 0) && (y <= ScrPrefs.ymax)) { skin->drawline(0, y, ScrPrefs.xmax, y); skin->finishline(graphPrefs.colors[6]); } } } /*********************************************************************** * * FUNCTION: graph_get_vals * * DESCRIPTION: Return the coordinates on the resulting graph (in graph * coordinates) of the function given by funcnum and * from the parameter 'param'. * * PARAMETERS: fnum - the function number * param - parameter value * * RETURN: true - the resulting 'x' and 'y' coordinates are valid * false - an error occured - e.g. function not defined etc. * ***********************************************************************/ Boolean Graph::graph_get_vals (int fnum, double param, double *x, double *y, double *r) { if (graphPrefs.functype == graph_param) { if (!graphCurves[fnum].stack1 || !graphCurves[fnum].stack2) return (false); func_get_value(graphCurves[fnum].stack1, param, y, NULL); func_get_value(graphCurves[fnum].stack2, param, x, NULL); return (finite(*x) && finite(*y)); } else if (graphPrefs.functype == graph_func) { if (!graphCurves[fnum].stack1) return (false); *x = param; func_get_value(graphCurves[fnum].stack1, param, y, NULL); return (finite(*y) != 0); } else { /* graph_pol */ double radius; if (!graphCurves[fnum].stack1) return (false); func_get_value(graphCurves[fnum].stack1, math_rad_to_user(param), &radius, NULL); if (r != NULL) *r = radius; if (!finite(radius)) return (false); *x = radius * cos(param); *y = radius * sin(param); return (true); } } /*********************************************************************** * * FUNCTION: graph_zoom_out * * DESCRIPTION: Zoom out by making a window of a same center but * twice as high and twice as wide * * PARAMETERS: frm, objectId - id of the graph gadget * * RETURN: Nothing * ***********************************************************************/ //void Graph::graph_zoom_out (void) { // double width = xmax - xmin; // double height = ymax - ymin; // // xmin -= width / 2; // xmax += width / 2; // // ymin -= height / 2; // ymax += height / 2; //} /*********************************************************************** * * FUNCTION: graph_draw_start * * DESCRIPTION: Initialize the drawing procedure, that later occurs * in background (using nilEvent in the Palm version, * and a separate thread in other versions). * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void Graph::graph_draw_start (Skin *skin, int width, int height, TgrPrefs *pgr) { int i; xmin = pgr->xmin; xmax = pgr->xmax; ymin = pgr->ymin; ymax = pgr->ymax; for (i=0 ; i<MAX_GRFUNCS ; i++) graphCurves[i].valid = false; graph_compile_cache(); graph_init_screen(skin, width, height); graphState.active = true; graphState.complete = false; graphState.position = 0; graphState.funcnum = 0; if (graphPrefs.functype == graph_func) { graphState.start = xmin; graphState.stop = xmax; graphState.step = (xmax - xmin) / ScrPrefs.xmax; } else if (graphPrefs.functype == graph_polar) { graphState.start = graphPrefs.fimin; graphState.stop = graphPrefs.fimax; graphState.step = graphPrefs.fistep; } else if (graphPrefs.functype == graph_param) { graphState.start = graphPrefs.tmin; graphState.stop = graphPrefs.tmax; graphState.step = graphPrefs.tstep; } // grcalc_init(); } /*********************************************************************** * * FUNCTION: graph_draw_incr * * DESCRIPTION: Draws a piece of a function (called from nilEvent * in the original Palm version) * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void Graph::graph_draw_incr (Skin *skin) { Int32 i; double start; double x,y; if (graphState.funcnum >= MAX_GRFUNCS) { graph_draw_complete(); return; } if (graphState.position == 0) { // At start, do some checks + inits /* Check, if we have all functions to draw graph */ if (!graphPrefs.grEnable[graphPrefs.functype][graphState.funcnum] || (graphCurves[graphState.funcnum].stack1 == NULL) || ((graphPrefs.functype == graph_param) && (graphCurves[graphState.funcnum].stack2 == NULL))) { graphState.funcnum++; return; } skin->selPen(graphState.funcnum); } // Draw a small piece of graph and return if (graphPrefs.functype == graph_func) { for (i=0 ; ((i<DRAW_AT_ONCE) && (graphState.position<=ScrPrefs.xmax)); i+=graphPrefs.speed, graphState.position+=graphPrefs.speed) { graph_get_vals(graphState.funcnum, graph_xscr2gr(graphState.position), &x, &y, NULL); graph_new_point(skin, graphState.position, x, y, graphState.funcnum); } if (graphState.position > ScrPrefs.xmax) { /* Curve finished */ skin->finishline(graphPrefs.colors[graphState.funcnum]); // Draw last point // /* Redraw labels. They may have been overwritten */ // graph_draw_axes_labels(&stdbounds); graphState.position = 0; graphState.funcnum++; } } else { /* Parametric and polar */ start = graphState.start; for (i=0 ; ((i<DRAW_AT_ONCE) && (start<=graphState.stop)) ; i+=graphPrefs.speed, graphState.position+=graphPrefs.speed) { start = graphState.start + graphState.step * graphState.position; if (start > graphState.stop) { /* Draw slightly behind end on polar graphs * to compensate for rounding */ if (graphPrefs.functype == graph_polar) start -= graphState.step / 2; else break; /* Do not draw behind end on parametric */ } graph_get_vals(graphState.funcnum, start, &x, &y, NULL); graph_new_point(skin, -1, x, y, graphState.funcnum); } if (start >= graphState.stop) { /* Curve finished */ skin->finishline(graphPrefs.colors[graphState.funcnum]); // Draw last point graphState.position = 0; graphState.funcnum++; } } } /*********************************************************************** * * FUNCTION: grtaps_track_pol * * DESCRIPTION: Tracking of a polar graph * * PARAMETERS: x,y - first tap * * RETURN: true - Could calculate values * false - No result * ***********************************************************************/ Boolean Graph::grtaps_track_pol (int *x, int *y, double *r_x, double *r_y, double *th, double *r, int curve_nb) { double realx, realy; double angle, radius; int dx, dy; CodeStack *stack; stack = graphCurves[curve_nb].stack1; if (!stack) return (false); angle = (double)(*x) * (graphPrefs.fimax - graphPrefs.fimin) / (double) (ScrPrefs.width); angle = graphPrefs.fimin + round(angle / graphPrefs.fistep) * graphPrefs.fistep; if (finite(angle)) { func_get_value(stack, angle, &radius, NULL); realx = radius * cos(angle); realy = radius * sin(angle); dx = graph_xgr2scr(realx); dy = graph_ygr2scr(realy); } else { dx = dy = -1; realx = realy = NaN; } *x = dx; *y = dy; *th = angle; *r = radius; *r_x = realx; *r_y = realy; if (dy == -1) return (false); return (true); } /*********************************************************************** * * FUNCTION: grtaps_track_param * * DESCRIPTION: Tracking of a parametric graph * * PARAMETERS: x,y - first tap * * RETURN: true - Could calculate values * false - No result * ***********************************************************************/ Boolean Graph::grtaps_track_param (int *x, int *y, double *r_x, double *r_y, double *t, int curve_nb) { double realx, realy; double param; int dx, dy; CodeStack *stack1, *stack2; stack1 = graphCurves[curve_nb].stack1; stack2 = graphCurves[curve_nb].stack2; if (!stack1 || !stack2) return (false); param = (double)(*x) * (graphPrefs.tmax - graphPrefs.tmin) / (double) (ScrPrefs.width); param = graphPrefs.tmin + round(param / graphPrefs.tstep) * graphPrefs.tstep; if (finite(param)) { func_get_value(stack1, param, &realy, NULL); func_get_value(stack2, param, &realx, NULL); dx = graph_xgr2scr(realx); dy = graph_ygr2scr(realy); } else { dx = dy = -1; realx = realy = NaN; } *x = dx; *y = dy; *t = param; *r_x = realx; *r_y = realy; if (dy == -1) return (false); return (true); } /*********************************************************************** * * FUNCTION: grtaps_track_func * * DESCRIPTION: Tracking of a normal function * * PARAMETERS: x,y - first tap * * RETURN: true - Could calculate values * false - No result * ***********************************************************************/ Boolean Graph::grtaps_track_func (int *x, int *y, double *r_x, double *r_y, int curve_nb) { double realx, realy; CodeStack *stack; int dy; stack = graphCurves[curve_nb].stack1; if (!stack) return (false); realx = graph_xscr2gr(*x); func_get_value(stack, realx, &realy, NULL); dy = graph_ygr2scr(realy); if (!finite(realy)) dy = -1; *y = dy; *r_x = realx; *r_y = realy; if (dy == -1) return (false); return (true); } Index: varmgr.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/varmgr.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** varmgr.h 2 Nov 2009 17:20:08 -0000 1.4 --- varmgr.h 28 Feb 2011 22:07:18 -0000 1.5 *************** *** 43,48 **** Boolean varmgr_edit_save(TCHAR *namefield, TCHAR *varfield, TCHAR *paramfield, rpntype type, Boolean editname, void *hWnd_p) IFACE; - Boolean varmgr_get_double(double *value,TCHAR *title) IFACE; - Boolean varmgr_get_complex(Complex *value,TCHAR *title) IFACE; - Boolean varmgr_get_varstring(TCHAR *varname,TCHAR *title) IFACE; #endif --- 43,45 ---- --- NEW FILE: solver.cpp --- /* * $Id: solver.cpp,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2002 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, [...1055 lines suppressed...] _fputts(newline, f); _fputts(configuration, f); _fputts(newline, f); _fputts(record->equation, f); _fputts(newline, f); _fputts(noteptr, f); size = StrLen(noteptr); if (size && (noteptr[size-1] != _T('\n'))) // Add a '\n' if needed _fputts(newline, f); MemHandleUnlock(recordHandle); _fputts(separator, f); _fputts(newline, f); } slv_db_close(); return (true); } --- NEW FILE: memo.cpp --- /* * $Id: memo.cpp,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. * */ #include "stdafx.h" #include "compat/PalmOS.h" #include <string.h> #include "konvert.h" #include "calcDB.h" #include "display.h" #include "memo.h" #include "stack.h" //#include "calcrsc.h" #include "calc.h" #include "prefs.h" #include "funcs.h" //#include "result.h" #include "solver.h" #include <stdlib.h> #include "core_display.h" #include "system - UI/EasyCalc.h" #define EQ_SEPARATOR _T("--------------------") /*********************************************************************** * * FUNCTION: strslashcat * * DESCRIPTION: Make the string 'quote-safe' * * PARAMETERS: str1 - destination string * str2 - source string * * RETURN: Nothing * ***********************************************************************/ static void strslashcat(TCHAR *str1, TCHAR *str2) { str1+=StrLen(str1); while ((*str1++ = *str2++)) if ((*str2 == _T('\"')) || (*str2 == _T('\\'))) *(str1++) = _T('\\'); } static TCHAR *memo_dump_item (dbList *list, Int16 i) { TCHAR *dump = NULL; TCHAR *text; CError err; Trpn item; TCHAR parameter[MAX_FUNCNAME+1]; if (list->type[i] == function) { err = db_func_description(list->list[i], &text, parameter); if (err) return NULL; dump = (TCHAR *) MemPtrNew((StrLen(text)+StrLen(list->list[i])+30) * sizeof(TCHAR)); dump[0] = _T('\0'); /* Define the parameter */ StrCat(dump, _T("defparamn(\"")); StrCat(dump, parameter); //#ifdef _WINDOWS // StrCat(dump, _T("\")\r\n")); //#else StrCat(dump, _T("\")\n")); //#endif StrCat(dump, list->list[i]); StrCat(dump, _T("()=\"")); strslashcat(dump, text); //#ifdef _WINDOWS // StrCat(dump, _T("\"\r\n")); //#else StrCat(dump, _T("\"\n")); //#endif MemPtrFree(text); } /* Do not export matrices for now */ else if (list->type[i]==variable) { item = db_read_variable(list->list[i], &err); if (err) return NULL; /* Do not work with strings now */ if (item.type == string) { rpn_delete(item); return NULL; } // Mapi: let's not export function parameter ... if (StrCompare(list->list[i], parameter_name) == 0) { /* Special - parameter of a function */ rpn_delete(item); return NULL; } text = display_default(item, true, NULL); dump = (TCHAR *) MemPtrNew((StrLen(text)+StrLen(list->list[i])+5) * sizeof(TCHAR)); StrCopy(dump, list->list[i]); StrCat(dump, _T("=")); StrCat(dump, text); //#ifdef _WINDOWS // StrCat(dump, _T("\r\n")); //#else StrCat(dump, _T("\n")); //#endif rpn_delete(item); MemPtrFree(text); } return dump; } static void memo_new_record (FILE *f, TCHAR *text) { //#ifdef _WINDOWS // TCHAR *header = _T("EasyCalc data structures\r\n"); //#else TCHAR *header = _T("EasyCalc data structures\n"); //#endif if (text == NULL) { _fputts(header, f); } else { _fputts(text, f); } } /*********************************************************************** * * FUNCTION: memo_dump_db * * DESCRIPTION: Create a string dump of an EasyCalc's database * containing definitions of variables and functions * * PARAMETERS: type - function,variable or all * * RETURN: pointer to a newly allocated memo-dump * ***********************************************************************/ static void memo_dump_db (FILE *f, rpntype type) { TCHAR *text; dbList *list; Int16 i; TCHAR *dump; dump = (TCHAR *) MemPtrNew((MAX_DUMP+20)*sizeof(TCHAR)); StrCopy(dump, _T("")); list = db_get_list(type); // Start recording memo_new_record(f, NULL); /* Dump the list */ for (i=0 ; i<list->size ; i++) { text = memo_dump_item(list, i); if (!text) continue; if (StrLen(text) > MAX_DUMP) { MemPtrFree(text); continue; } if (StrLen(dump)+StrLen(text) > MAX_DUMP) { if (type != variable) //#ifdef _WINDOWS // StrCat(dump, _T("defparamn(\"x\")\r\n")); //#else StrCat(dump, _T("defparamn(\"x\")\n")); //#endif memo_new_record(f, dump); StrCopy(dump, _T("")); } StrCat(dump, text); MemPtrFree(text); } if (type != variable) //#ifdef _WINDOWS // StrCat(dump, _T("defparamn(\"x\")\r\n")); //#else StrCat(dump, _T("defparamn(\"x\")\n")); //#endif memo_new_record(f, dump); db_delete_list(list); MemPtrFree(dump); } /*********************************************************************** * * FUNCTION: memo_dump * * DESCRIPTION: Dump an EasyCalc db to file * * PARAMETERS: Nothing * * RETURN: Nothing * ***********************************************************************/ void memo_dump (rpntype type, const TCHAR *filename, Boolean unicode) { FILE *f; if (unicode) f = _tfopen(filename, _T("wb")); // Write unicode as is else f = _tfopen(filename, _T("w")); // Write unicode as MBCS if (f == NULL) return; if (type == EQUATIONS) { slv_export_memo(f, EQ_SEPARATOR); } else { memo_dump_db(f, type); } fclose(f); } static Boolean memo_execute(Skin *skin, void *hWnd_p, TCHAR *input) { int i, j; CodeStack *stack; CError err; Trpn result; i = 0; while (input[i]) { for (j=i ; input[j]!=_T('\n') && input[j] ; j++) ; input[j] = _T('\0'); if (input[j-1] == _T('\r')) input[j-1] = _T('\0'); if (StrLen(input+i) == 0) break; stack = text_to_stack(input+i, &err); if (!err) { err = stack_compute(stack); if (!err) { result = stack_pop(stack); set_ans_var(result); result_set(skin, hWnd_p, result); rpn_delete(result); } stack_delete(stack); } if (err) return false; i = j+1; } return true; } /*********************************************************************** * * FUNCTION: memo_import_memo * * DESCRIPTION: Executes a selected memo into easycalc * * PARAMETERS: filename - the file selected by user * * RETURN: true - operation ok * false - error during execution * ***********************************************************************/ Boolean memo_import_memo (Skin *skin, void *hWnd_p, const TCHAR *filename, Boolean unicode) { TCHAR *input; char *mbcs_input = NULL; int memolen, i=0; Boolean start = true; Boolean res; #ifdef SPECFUN_ENABLED TCHAR *next; Boolean is_equation = false; #endif FILE *f = _tfopen(filename, _T("rb")); // Read unicode and MBCS as is if (f == NULL) { return (false); } input = (TCHAR *) MemPtrNew((MAX_DUMP+1)*sizeof(TCHAR)); if (!unicode) mbcs_input = (char *) MemPtrNew((MAX_DUMP+1)); do { // Read a bunch of chars when previous bunch is exhausted if (unicode) { memolen = fread(input+i, sizeof(TCHAR), MAX_DUMP-i, f); input[memolen] = _T('\0'); } else { memolen = fread(mbcs_input+i, 1, MAX_DUMP-i, f); mbcs_input[memolen] = '\0'; TCHAR const *text = libLang->convert(mbcs_input+i); StrCopy(input+i, text); } if (start) { /* Skip the first line */ for (i=0 ; input[i]!=_T('\n') && i<memolen ; i++) ; i++; #ifdef SPECFUN_ENABLED if (input[i] == _T(':')) is_equation = true; #endif start = false; } #ifdef SPECFUN_ENABLED if (is_equation) { TCHAR *temp = input; while ((temp != NULL) && (*temp)) { // Find next "--------------------" next = _tcsstr(temp, EQ_SEPARATOR); if (next != NULL) { *next = _T('\0'); // Go to the end of EQ_SEPARATOR + '\n' do { next++; } while (*next && (*next != _T('\n'))); if (*next == _T('\n')) next++; // Skip '\n' also } if ((next != NULL) || feof(f)) { // If not at end of file, maybe the // equation separator is in the next // bunch of chars, so let's use this // only when we have a separator or // we are at end of file. res = slv_memo_import(temp); temp = next; } else { // No separator, and not at end of file, // let's not consume that piece. next = temp; temp = NULL; } } } else { #endif // Find last '\n' next = _tcsrchr(input+i, _T('\n')); if (next != NULL) { *next = _T('\0'); if (*(next-1) == _T('\r')) *(next-1) = _T('\0'); next++; } // Execute sequence till then res = memo_execute(skin, hWnd_p, input+i); #ifdef SPECFUN_ENABLED } #endif // Move unread sequence at begining of buffer, and read more chars if there are if (next) { i = memolen - (next-input); if (i > 0) memcpy(input, next, i*sizeof(TCHAR)); } else { i = 0; // All consumed } } while (res && !feof(f)); MemPtrFree(input); if (mbcs_input) MemPtrFree(mbcs_input); return res; } --- NEW FILE: finance.cpp --- /* * $Id: finance.cpp,v 1.1 2011/02/28 22:07:18 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2000 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. * */ #incl... [truncated message content] |