You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(36) |
Sep
(44) |
Oct
(25) |
Nov
(2) |
Dec
(5) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(1) |
Feb
(1) |
Mar
|
Apr
|
May
(9) |
Jun
|
Jul
(4) |
Aug
(8) |
Sep
(16) |
Oct
|
Nov
(2) |
Dec
(28) |
2008 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
(11) |
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(33) |
Jul
(5) |
Aug
(7) |
Sep
(9) |
Oct
(31) |
Nov
(25) |
Dec
(21) |
2011 |
Jan
(2) |
Feb
(12) |
Mar
|
Apr
(7) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Mapi B. <ma...@us...> - 2009-09-24 21:17:54
|
Update of /cvsroot/easycalc/PPCport/include In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14655 Removed Files: defuns.h MathLib.h Log Message: Subset of the code, compiling, but not yet linking --- MathLib.h DELETED --- --- defuns.h DELETED --- |
From: Mapi B. <ma...@us...> - 2009-09-24 21:17:32
|
Update of /cvsroot/easycalc/PPCport/discarded In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14571 Added Files: calc.rcp.in calcrsc.h Log Message: Subset of the code, compiling, but not yet linking --- NEW FILE: calc.rcp.in --- // // $Id: calc.rcp.in,v 1.1 2009/09/24 21:17:19 mapibid Exp $ // #include "calcrsc.h" #ifdef SUPPORT_DIA #include "resizeconsts.h" #endif //Handera support #ifdef HANDERA_SDK HEX "sKst" ID 1000 0x00 0x00 0x00 0x00 #endif VERSION "VERSION_HERE" APPLICATION ID 1 "OpCl" APPLICATIONICONNAME ID 100 "Easy Calc" [...1278 lines suppressed...] BITMAP "calc-8.bmp" BPP 8 DENSITY 72 TRANSPARENTINDEX 0 BITMAP "calc-8-hi.bmp" BPP 8 DENSITY 144 TRANSPARENTINDEX 0 END #else BITMAP ID abtLogo COMPRESS BEGIN BITMAP "calc.bmp" BPP 1 DENSITY 72 TRANSPARENTINDEX 0 BITMAP "calc-8.bmp" BPP 8 DENSITY 72 TRANSPARENTINDEX 0 END #endif #ifdef SUPPORT_DIA WORDLIST ID resize_index BEGIN frmGraph frmGraph frmAbout frmAbout frmHelp frmHelp END #endif --- NEW FILE: calcrsc.h --- // $Id: calcrsc.h,v 1.1 2009/09/24 21:17:19 mapibid Exp $ // // Resource constants for EasyCalc // 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. #define MAX_INPUT_LENGTH 1000 #define MAX_WORKSHEET_TITLE 32 #define MAX_WORKSHEET_NOTE 300 #define MAX_WORKSHEET_HELP 39 #define resize_index 1 #define frmBasic 1001 #define frmScientific 1002 #define frmInteger 1003 #define frmGraph 1004 #define finForm 1005 #define frmAbout 1006 #define altCompute 1007 #define altMathlib 1008 #define frmHelp 1009 #define altGuessNotFound 1010 #define altGraphBadVal 1011 #define altErrorMsg 1012 #define altAnsProblem 1013 #define altBadParameter 1015 #define frmListEdit 1016 #define frmMatrix 1017 #define frmBasicS 1018 #define slvForm 1019 #define slvTitleForm 1020 #define slvOptionsForm 1021 #define slvNoteForm 1022 #define slvExportOK 1023 #define slvExportError 1024 #define tdMenu 1000 #define resultGadget 1001 #define tdInput 1002 #define tdDoit 1003 #define btnBasic 1008 #define btnScientific 1009 #define btnInteger 1010 #define btnGraph 1011 #define tdBFin 1016 #define tdBPref 1017 #define btnHistory 1018 #define hlpMain1 1100 #define hlpMain2 1101 #define hlpMain2T 1102 #define hlpPref 1103 #define hlpFin 1104 #define hlpMemo 1105 #define hlpFunc 1106 #define hlpFuncT 1107 #define hlpGrPref 1108 #define hlpGrSetup 1109 #define hlpSolver 1110 #define btnMain0 2000 #define btnMain1 2001 #define btnMain2 2002 #define btnMain3 2003 #define btnMain4 2004 #define btnMain5 2005 #define btnMain6 2006 #define btnMain7 2007 #define btnMain8 2008 #define btnMain9 2009 #define btnMainBksp 2010 #define btnMainFwsp 2011 #define btnMainDel 2012 #define btnMainPlus 2015 #define btnMainMinus 2016 #define btnMainMult 2017 #define btnMainDivide 2018 #define btnMainNeg 2019 #define btnMainA 2071 #define btnMainB 2072 #define btnMainC 2073 #define btnMainD 2074 #define btnMainE 2075 #define btnMainF 2076 #define btnMainAnd 2077 #define btnMainOr 2078 #define btnMainShl 2079 #define btnMainShr 2080 #define btnMainClear 2081 #define btnMainAns 2082 #define btnMainOpBr 2083 #define btnMainPow 2084 #define btnMainLog 2085 #define btnMainSq1 2086 #define btnMainSqr 2087 #define btnMainSqrt 2088 #define btnMainClBr 2089 #define btnMainEE 2090 #define btnMainDot 2091 #define btnMainXor 2092 #define btnMainSel 2093 #define lstMainBtnRow 2094 #define popMainBtnRow 2095 #define btnMainInv 2096 #define btnMainLn 2097 #define btnMainSin 2098 #define btnMainCos 2099 #define btnMainTan 2101 #define btnMainExp 2102 #define btnMainPi 2103 #define btnMainDeg 2104 #define btnMainMin 2105 #define btnMainFact 2106 #define btnMainColn 2107 #define btnMainMagn 2108 #define btnMainAngl 2109 #define btnMain_i 2110 #define btnPrefMode 2111 #define btnRadixMode 2112 #define btnMatrixDone 2200 #define tblMatrix 2201 #define lstMatrix 2202 #define popMatrix 2203 #define popMatrixRows 2204 #define popMatrixCols 2205 #define lstMatrixDim 2206 #define sclMatrix 2207 #define btnMatrixLeft 2208 #define btnMatrixRight 2209 #define btnMainS1 3301 #define btnMainS2 3302 #define btnMainS3 3303 #define btnMainS4 3304 #define btnMainS5 3305 #define btnMainS6 3306 #define btnMainS7 3307 #define btnMainS8 3308 #define btnMainS9 3309 #define btnMainS10 3310 #define btnMainS11 3311 #define btnMainS12 3312 #define btnMainS13 3313 #define btnMainS14 3314 #define btnMainS15 3315 #define btnMainW1 3316 #define btnMainW2 3317 #define btnMainW3 3319 #define btnMainW4 3320 #define btnMainW5 3322 #define btnMainW6 3323 #define btnMainW7 3325 #define btnMainW8 3326 #define btnMainW9 3328 #define btnMainW10 3329 #define finFVButton 3000 #define finPVButton 3001 #define finPMTButton 3002 #define finNButton 3003 #define finIButton 3004 #define finBeginButton 3005 #define finEndButton 3006 #define finPYRButton 3007 #define finDoneButton 3010 #define finISet 3100 #define finILabel 3101 #define finPVSet 3102 #define finPVLabel 3103 #define finPMTSet 3104 #define finPMTLabel 3105 #define finNSet 3106 #define finNLabel 3107 #define finFVSet 3108 #define finFVLabel 3109 #define finPYRSet 3110 #define finPYRLabel 3111 #define varEditForm 3200 #define varEditField 3201 #define varEditOK 3202 #define varEditCancel 3203 #define varEditNameField 3204 #define altConfirmOverwrite 3205 #define varEditParam 3206 #define varEditParamLabel 3207 #define varFuncModTitle 3208 #define varVarModTitle 3209 #define varFuncNewTitle 3210 #define varVarNewTitle 3211 #define varStrVariable 3212 #define varStrFunction 3213 #define calcResPopupBut 3250 #define calcResList 3251 #define calcResPopup 3252 #define tdIntBin 3400 #define tdIntOct 3401 #define tdIntDec 3402 #define tdIntHex 3403 #define frmGrcSel 3500 #define btnGrcSelOK 3501 #define btnGrcSelCancel 3502 #define lstGrcSel 3503 #define altGrcSelectLeft 3504 #define altGrcSelectRight 3505 #define altGrcSelectValue 3506 #define altComputeResult 3507 #define altComputeCofirm 3508 #define altGrcBoundsErr 3509 #define altGrcFuncErr 3510 #define altOctalMode 3511 #define altSolverResult 3512 #define slvEquation 3601 #define slvUpdate 3602 #define slvVarList 3603 #define slvDone 3604 #define slvModify 3605 #define slvSolve 3606 #define slvCalculate 3608 #define slvWorksheet 3609 #define slvWorksheetList 3610 #define slvTitle 3611 #define slvTitleOK 3612 #define slvTitleCancel 3613 #define slvDelete 3615 #define slvOptions 3616 #define slvOptionsMin 3617 #define slvOptionsMax 3618 #define slvOptionsPrec 3619 #define slvOptionsOK 3620 #define slvOptionsCancel 3621 #define slvOptionsTitle 3622 #define slvNote 3623 #define slvNoteField 3624 #define slvNoteDone 3625 #define slvHelp 3626 #define slvMenu 3627 #define slvExport 3628 #define prefForm 4000 #define prefOK 4001 #define prefCancel 4002 #define prefNormal 4003 #define prefSci 4004 #define prefEng 4005 #define prefPrecPopup 4013 #define prefPrecList 4014 #define prefReducePrecision 4015 #define prefStrip 4016 #define prefParenth 4017 #define prefRadian 4018 #define prefDegree 4019 #define prefGrad 4020 #define prefDecimal 4022 #define prefBinary 4023 #define prefOctal 4024 #define prefHexa 4025 #define prefIntInput 4027 #define prefCvtUnits 4028 #define prefInsertHelp 4029 #define prefAcceptPref 4030 #define prefDispScien 4031 #define graphGadget 4100 #define btnGraphZoomIn 4101 #define btnGraphZoomOut 4102 #define btnGraphTrack 4103 #define graphTrackList 4104 #define graphTrackPopup 4105 #define btnGraphTrackGoto 4106 #define lstGraphCalcFunc 4107 #define btnGraphCalc 4108 #define lstGraphCalcParam 4109 #define strGrcDescription 4110 #define lstGraphCalcPolar 4111 #define btnGraphSpeed 4112 #define lstGraphSpeed 4113 #define graphMenu 4200 #define btnGraphPref 4201 #define btnGraphSetup 4202 #define btnGraphTable 4203 #define grPrefForm 4200 #define grPrefXmin 4202 #define grPrefXmax 4203 #define grPrefYmin 4204 #define grPrefYmax 4205 #define grPrefLabel1 4206 #define grPrefLabel2 4207 #define grPrefLabel3 4208 #define grPrefField1 4209 #define grPrefField2 4210 #define grPrefField3 4211 #define grPrefFunc 4212 #define grPrefPol 4213 #define grPrefPar 4214 #define grPrefDefault 4215 #define grPrefTrig 4216 #define grPrefXscale 4217 #define grPrefYscale 4218 #define ckbGrPrefLogX 4219 #define ckbGrPrefLogY 4220 #define grPrefLabel1u 4222 #define grPrefLabel2u 4223 #define grPrefLabel3u 4224 #define varList 4300 #define varListButton 4301 #define varListPopup 4302 #define varFuncListButton 4303 #define varBuiltinList 4304 #define varBuiltinListButton 4305 #define varBuiltinListPopup 4306 #define varEntryForm 4305 #define varEntryOK 4306 #define varEntryCancel 4307 #define varEntryField 4308 #define varEntryListBut 4309 #define varEntryList 4310 #define varEntryListPopup 4311 #define altBadVariableName 4312 #define histList 4400 #define histListPopup 4402 #define grSetupForm 4500 #define grSetupDone 4501 #define grSetupTable 4502 #define grSetupUp 4503 #define grSetupDown 4504 #define grSetupList 4505 #define grSetupPopup 4506 #define grSetupStrFunc 4508 #define grSetupNone 4509 #define grSetupUser 4510 #define ckbGrfun1 4511 #define ckbGrfun2 4512 #define ckbGrfun3 4513 #define ckbGrfun4 4514 #define ckbGrfun5 4515 #define ckbGrfun6 4516 #define ckbGrAxes 4517 #define ckbGrGrid 4518 #define grType1 4519 #define grType2 4520 #define grType3 4521 #define grType4 4522 #define grType5 4523 #define grType6 4524 #define grColor1 4525 #define grColor2 4526 #define grColor3 4527 #define grColor4 4528 #define grColor5 4529 #define grColor6 4530 #define grAxes 4531 #define grGrid 4532 #define grBgnd 4533 #define grBgndLbl 4534 #define grColorElem 4535 #define ckbGrAxesLabels 4536 #define grTableForm 4600 #define grTableTable 4601 #define grTableLeft 4602 #define grTableRight 4603 #define grTableDone 4604 #define grTableGoto 4605 #define grTableStep 4606 #define dinputForm 4700 #define dinputOK 4701 #define dinputCancel 4702 #define dinputField 4703 #define memoImportForm 4800 #define memoImportOK 4801 #define memoImportCancel 4802 #define memoImportList 4803 #define altMemoImportError 4804 #define memoExportQuestionForm 4805 #define memoExportOK 4806 #define memoExportCancel 4807 #define memoExportAll 4808 #define memoExportFunc 4809 #define memoExportVars 4810 #define btnListDone 4900 #define tblList 4901 #define popList1 4902 #define popList2 4903 #define popList3 4904 #define lstList 4905 #define btnListLong 4906 #define btnListInsert 4907 #define btnListDelete 4908 #define lblListLong 4909 #define sclList 4910 #define defForm 5000 #define defDone 5001 #define defList 5002 #define defNew 5003 #define defModify 5004 #define defDelete 5005 #define altConfirmDelete 5006 #define defPopupList 5007 #define defPopup 5008 #define abtLogo 6001 #define abtTitle 6002 #define abtVersion 6003 #define abtVerdate 6004 #define abthlpText 6005 #define abthlpOk 6006 #define abthlpUp 6007 #define abthlpDn 6008 #define bmpLArrow 7001 #define bmpRArrow 7002 #define bmpRootX 7003 #define bmpSquare 7004 #define bmpSquareRoot 7005 #define bmpExpon 7006 #define bmpInverse 7007 #define bmpPower 7008 #define bmpLdel 7009 #define bmpExe 7010 #define bmpIsPrime 7011 #define bmpPrevPrime 7012 #define bmpNextPrime 7013 #define frmUpdateVars 8000 #define frmUpdateResult 8001 #define frmUpdateWorksheet 8002 #define strErrCodes 8001 #define strMenuDescription 8002 #define strLocalNew 8003 #define strLocalDelete 8004 #define strLocalSaveAs 8005 #define strCredits 8006 #define strCreditsT 8007 #define strWorksheet 8008 #define strNewWorksheet 8009 #define strDescriptionVar 8010 #define strUndefined 8011 #define mitAbout 8500 #define mitListEdit 8501 #define mitMatrixEdit 8502 #define mitMemoExport 8503 #define mitMemoImport 8504 #define mitFinCalc 8505 #define mitDefMgr 8506 #define mitClearHistory 8507 #define mitCredits 8508 #define mitSolver 8509 #define sysEditMenuID 10000 #define sysEditMenuUndoCmd 10000 #define sysEditMenuCutCmd 10001 #define sysEditMenuCopyCmd 10002 #define sysEditMenuPasteCmd 10003 #define sysEditMenuSelectAllCmd 10004 #define sysEditMenuSeparator 10005 #define sysEditMenuKeyboardCmd 10006 #define sysEditMenuGraffitiCmd 10007 |
Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14503 Modified Files: calcDB.cpp display.cpp display.h fp.cpp funcs.cpp konvert.cpp stack.cpp Added Files: defuns.h guess.cpp Log Message: Subset of the code, compiling, but not yet linking Index: display.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/display.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** display.h 24 Jun 2009 21:39:59 -0000 1.2 --- display.h 24 Sep 2009 21:16:50 -0000 1.3 *************** *** 54,59 **** TCHAR * display_complex(Complex number) MLIB; TCHAR * display_integer(UInt32 number,Tbase mode) MLIB; ! TCHAR * display_default(Skin *skin, Trpn rpn,Boolean complete) MLIB; ! TCHAR * display_list(Skin *skin, List *list) MLIB; extern TdispPrefs dispPrefs; --- 54,59 ---- TCHAR * display_complex(Complex number) MLIB; TCHAR * display_integer(UInt32 number,Tbase mode) MLIB; ! TCHAR * display_default(Trpn rpn,Boolean complete) MLIB; ! TCHAR * display_list(List *list) MLIB; extern TdispPrefs dispPrefs; Index: display.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/display.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** display.cpp 5 Jul 2009 20:53:37 -0000 1.3 --- display.cpp 24 Sep 2009 21:16:50 -0000 1.4 *************** *** 27,36 **** #include "compat/PalmOS.h" #include "konvert.h" #include "Skin.h" #include "mathem.h" #include "display.h" #include "defuns.h" #include "funcs.h" ! #include "prefs.h" #include "fp.h" #include "stack.h" --- 27,38 ---- #include "compat/PalmOS.h" #include "konvert.h" + #include "core/core_display.h" #include "Skin.h" + #include "Easycalc.h" #include "mathem.h" #include "display.h" #include "defuns.h" #include "funcs.h" ! #include "core/prefs.h" #include "fp.h" #include "stack.h" *************** *** 123,127 **** /* for decimal display signed number */ if ((signednum = number) < 0) { ! number = -number; *result = _T('-'); result1 = result + 1; --- 125,129 ---- /* for decimal display signed number */ if ((signednum = number) < 0) { ! number = -signednum; *result = _T('-'); result1 = result + 1; *************** *** 152,156 **** TCHAR * ! display_list(Skin *skin, List *list) { TCHAR *result,*tmp; --- 154,158 ---- TCHAR * ! display_list(List *list) { TCHAR *result,*tmp; *************** *** 159,163 **** result = (TCHAR *) MemPtrNew((UInt32)(dispPrefs.decPoints*2+10)*list->size + 10); if (!result) { ! skin->alertErrorMessage(c_memory); return NULL; } --- 161,165 ---- result = (TCHAR *) MemPtrNew((UInt32)(dispPrefs.decPoints*2+10)*list->size + 10); if (!result) { ! alertErrorMessage(c_memory); return NULL; } *************** *** 240,244 **** ***********************************************************************/ TCHAR * ! display_default(Skin *skin, Trpn rpn, Boolean complete) { TCHAR *result; --- 242,246 ---- ***********************************************************************/ TCHAR * ! display_default(Trpn rpn, Boolean complete) { TCHAR *result; *************** *** 272,276 **** case list: if (complete) ! result = display_list(skin, rpn.u.listval); else { result = (TCHAR *) MemPtrNew(20); --- 274,278 ---- case list: if (complete) ! result = display_list(rpn.u.listval); else { result = (TCHAR *) MemPtrNew(20); Index: funcs.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** funcs.cpp 5 Jul 2009 20:53:37 -0000 1.3 --- funcs.cpp 24 Sep 2009 21:16:50 -0000 1.4 *************** *** 42,46 **** #include "complex.h" #include "history.h" ! #include "prefs.h" #include "fp.h" #include "slist.h" --- 42,46 ---- #include "complex.h" #include "history.h" ! #include "core/prefs.h" #include "fp.h" #include "slist.h" *************** *** 487,491 **** else for(i=0;i<lst2->size;i++){ lst->item[row-1]=lst2->item[i]; ! row+=sgn(dif); } list_delete(lst2); --- 487,491 ---- else for(i=0;i<lst2->size;i++){ lst->item[row-1]=lst2->item[i]; ! row+=(Int16)sgn(dif); } list_delete(lst2); *************** *** 869,919 **** convert_real_to_string(Functype *func,CodeStack *stack) { ! double arg; ! TCHAR *res,*tmp; ! CError err; ! err=stack_get_val(stack,&arg,real); ! if (err) ! return err; ! if (!finite(arg)) ! return c_badarg; ! res = (TCHAR *) MemPtrNew(MAX_FP_NUMBER+20); ! tmp = res; ! if (func->num==FUNC_RADIAN) { ! fp_print_double(res,arg/M_PIl); ! StrCat(res,_T("pi")); } ! else if (func->num==FUNC_DEGREE || func->num == FUNC_DEGREE2) { ! if (arg<0) { ! *tmp++=_T('-'); ! arg=-arg; ! } ! /* The numbers must be added 1E-12 to avoid ! cases like 1+5/60 -> 1o04' ! */ ! fp_print_double(tmp,trunc(arg+1E-12)); tmp+=StrLen(tmp); ! *tmp++=_T('°'); ! if (arg-trunc(arg)<1E-15) ! StrCopy(tmp,_T("0\'")); ! else { ! if (func->num == FUNC_DEGREE) { ! fp_print_double(tmp,trunc(60*(arg-trunc(arg+1E-12))+1E-12)); ! tmp+=StrLen(tmp); ! *tmp++=_T('\''); ! fp_print_double(tmp,60*(arg*60-trunc(arg*60+1E-12))); ! } else { /* FUNC_DEGREE2 */ ! fp_print_double(tmp,60*(arg-trunc(arg+1E-12))+1E-12); ! StrCat(tmp,_T("'")); ! } ! } } ! err = stack_add_val(stack,res,string); ! MemPtrFree(res); ! return err; } --- 869,919 ---- convert_real_to_string(Functype *func,CodeStack *stack) { ! double arg; ! TCHAR *res,*tmp; ! CError err; ! err=stack_get_val(stack,&arg,real); ! if (err) ! return err; ! if (!finite(arg)) ! return c_badarg; ! res = (TCHAR *) MemPtrNew(MAX_FP_NUMBER+20); ! tmp = res; ! if (func->num==FUNC_RADIAN) { ! fp_print_double(res,arg/M_PIl); ! StrCat(res,_T("pi")); ! } ! else if (func->num==FUNC_DEGREE || func->num == FUNC_DEGREE2) { ! if (arg<0) { ! *tmp++=_T('-'); ! arg=-arg; } ! /* The numbers must be added 1E-12 to avoid ! cases like 1+5/60 -> 1o04' ! */ ! fp_print_double(tmp,trunc(arg+1E-12)); ! tmp+=StrLen(tmp); ! *tmp++=_T('°'); ! if (arg-trunc(arg)<1E-15) ! StrCopy(tmp,_T("0\'")); ! else { ! if (func->num == FUNC_DEGREE) { ! fp_print_double(tmp,trunc(60*(arg-trunc(arg+1E-12))+1E-12)); tmp+=StrLen(tmp); ! *tmp++=_T('\''); ! fp_print_double(tmp,60*(arg*60-trunc(arg*60+1E-12))); ! } else { /* FUNC_DEGREE2 */ ! fp_print_double(tmp,60*(arg-trunc(arg+1E-12))+1E-12); ! StrCat(tmp,_T("'")); ! } } + } ! err = stack_add_val(stack,res,string); ! MemPtrFree(res); ! return err; } *************** *** 933,960 **** * ***********************************************************************/ ! Boolean ! varfunc_name_ok(TCHAR *name,rpntype type) ! { ! Int16 i; ! if (StrLen(name)==0 || StrLen(name)>MAX_FUNCNAME) ! return false; ! if (!IS_FUNC_1LETTER(name[0])) ! return false; ! for (i=0;name[i];i++) ! if (!IS_FUNC_LETTER(name[i])) ! return false; if (StrCompare(name,parameter_name)==0) ! return false; if (type==variable && is_constant(name)) ! return false; else if (type==function) { ! for (i=0;defined_funcs[i].name[0];i++) ! if (StrCompare(name,defined_funcs[i].name)==0) ! return false; } ! return true; } --- 933,958 ---- * ***********************************************************************/ ! Boolean varfunc_name_ok(TCHAR *name,rpntype type) { ! Int16 i; ! if (StrLen(name)==0 || StrLen(name)>MAX_FUNCNAME) ! return false; ! if (!IS_FUNC_1LETTER(name[0])) ! return false; ! for (i=0;name[i];i++) ! if (!IS_FUNC_LETTER(name[i])) ! return false; if (StrCompare(name,parameter_name)==0) ! return false; if (type==variable && is_constant(name)) ! return false; else if (type==function) { ! for (i=0;defined_funcs[i].name[0];i++) ! if (StrCompare(name,defined_funcs[i].name)==0) ! return false; } ! return true; } *************** *** 989,1029 **** CodeStack *addparams) { ! Trpn argument; ! CodeStack *stack; ! CError err; ! Boolean oldinput; ! oldinput = DisableInput; ! DisableInput = true; ! stack = stack_new(origstack->size); ! stack_copy(stack,origstack); ! argument.type = real; ! argument.allocsize = 0; ! argument.u.realval = param; ! if (addparams == NULL) { ! set_func_argument(&argument,1); ! } else { ! stack_push(addparams,argument); ! set_func_argument(addparams->stack,addparams->size); ! } ! err = stack_compute(stack); ! decr_func_argument(); ! if (addparams != NULL) { ! /* Return the addparams stack to the original state */ ! stack_pop(addparams); ! } ! if (!err) ! err = stack_get_val(stack,result,real); ! if (err) ! *result = NaN; ! stack_delete(stack); ! DisableInput = oldinput; ! return err; } --- 987,1027 ---- CodeStack *addparams) { ! Trpn argument; ! CodeStack *stack; ! CError err; ! Boolean oldinput; ! oldinput = DisableInput; ! DisableInput = true; ! stack = stack_new(origstack->size); ! stack_copy(stack,origstack); ! argument.type = real; ! argument.allocsize = 0; ! argument.u.realval = param; ! if (addparams == NULL) { ! set_func_argument(&argument,1); ! } else { ! stack_push(addparams,argument); ! set_func_argument(addparams->stack,addparams->size); ! } ! err = stack_compute(stack); ! decr_func_argument(); ! if (addparams != NULL) { ! /* Return the addparams stack to the original state */ ! stack_pop(addparams); ! } ! if (!err) ! err = stack_get_val(stack,result,real); ! if (err) ! *result = NaN; ! stack_delete(stack); ! DisableInput = oldinput; ! return err; } *************** *** 1048,1087 **** Complex *result) { ! CodeStack *stack; ! CError err = c_noerror; ! CodeStack *paramstack; ! UInt16 i; ! stack = stack_new(origstack->size); ! if (!stack) ! return c_memory; ! stack_copy(stack,origstack); ! paramstack = stack_new(paramcount); ! if (!paramstack) { ! stack_delete(stack); ! return c_memory; ! } ! for(i=0; i < paramcount && err == c_noerror; i++) { ! err = stack_add_val(paramstack, ¶ms[i], complex); ! } ! if (!err) { ! set_func_argument(paramstack->stack,paramstack->size); ! err = stack_compute(stack); ! decr_func_argument(); ! } ! if (!err) ! err = stack_get_val(stack,result,complex); ! if (err) { ! result->real = NaN; ! result->imag = NaN; ! } ! stack_delete(stack); ! stack_delete(paramstack); ! return err; } --- 1046,1085 ---- Complex *result) { ! CodeStack *stack; ! CError err = c_noerror; ! CodeStack *paramstack; ! UInt16 i; ! stack = stack_new(origstack->size); ! if (!stack) ! return c_memory; ! stack_copy(stack,origstack); ! paramstack = stack_new(paramcount); ! if (!paramstack) { ! stack_delete(stack); ! return c_memory; ! } ! for(i=0; i < paramcount && err == c_noerror; i++) { ! err = stack_add_val(paramstack, ¶ms[i], complex); ! } ! if (!err) { ! set_func_argument(paramstack->stack,paramstack->size); ! err = stack_compute(stack); ! decr_func_argument(); ! } ! if (!err) ! err = stack_get_val(stack,result,complex); ! if (err) { ! result->real = NaN; ! result->imag = NaN; ! } ! stack_delete(stack); ! stack_delete(paramstack); ! return err; } *************** *** 1090,1142 **** func_item(Functype *func, CodeStack *stack) { ! rpntype type1,type2; ! CError err; ! err = stack_item_type(stack,&type2,(func->paramcount-1)); ! if (err) ! return err; ! if (func->paramcount==2 && type2==list) ! err = stack_item_type_nr(stack,&type1,1); ! else if (func->paramcount==3) ! err = stack_item_type_nr(stack,&type1,2); ! else ! err = c_badargcount; ! if (err) ! return err; ! if (type1 == variable) { ! UInt32 arg1=0,arg2=0; ! Trpn item,ritem; ! err = stack_get_val(stack,&arg2,integer); ! if (err) ! return err; ! if (func->paramcount == 3) { ! err = stack_get_val(stack,&arg1,integer); ! if (err) ! return err; ! }else ! arg1=arg2; ! item = stack_pop(stack); ! ritem.allocsize = 0; ! ritem.type = litem; ! StrCopy(ritem.u.litemval.name,item.u.varname); ! ritem.u.litemval.row = arg1; ! ritem.u.litemval.col = arg2; ! stack_push(stack,ritem); ! rpn_delete(item); } else switch (type2){ ! case list: ! return list_item(func,stack); ! case matrix: ! return matrix_item(func,stack); ! case cmatrix: ! return cmatrix_item(func,stack); ! default: ! return c_badarg; } ! return c_noerror; } --- 1088,1140 ---- func_item(Functype *func, CodeStack *stack) { ! rpntype type1,type2; ! CError err; ! err = stack_item_type(stack,&type2,(func->paramcount-1)); ! if (err) ! return err; ! if (func->paramcount==2 && type2==list) ! err = stack_item_type_nr(stack,&type1,1); ! else if (func->paramcount==3) ! err = stack_item_type_nr(stack,&type1,2); ! else ! err = c_badargcount; ! if (err) ! return err; ! if (type1 == variable) { ! UInt32 arg1=0,arg2=0; ! Trpn item,ritem; ! err = stack_get_val(stack,&arg2,integer); ! if (err) ! return err; ! if (func->paramcount == 3) { ! err = stack_get_val(stack,&arg1,integer); ! if (err) ! return err; ! }else ! arg1=arg2; ! item = stack_pop(stack); ! ritem.allocsize = 0; ! ritem.type = litem; ! StrCopy(ritem.u.litemval.name,item.u.varname); ! ritem.u.litemval.row = arg1; ! ritem.u.litemval.col = arg2; ! stack_push(stack,ritem); ! rpn_delete(item); } else switch (type2){ ! case list: ! return list_item(func,stack); ! case matrix: ! return matrix_item(func,stack); ! case cmatrix: ! return cmatrix_item(func,stack); ! default: ! return c_badarg; } ! return c_noerror; } --- NEW FILE: guess.cpp --- /* * $Id: guess.cpp,v 1.1 2009/09/24 21:16:50 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 <StringMgr.h> #include "segment.h" #include "compat/MathLib.h" #include "stack.h" #include "funcs.h" #include "konvert.h" #include "complex.h" #include "display.h" #include "defuns.h" #include "mathem.h" #define MAX_DIV_F 1024 #define MAX_FORM_F 128 #define MAX_DIV_CONST 4 #define MAX_DIV_CONST_E 12 #define GUESS_MAX 131072 #define GUESS_FACTORS_MAX 1000000000 #define M_PI 3.14159265358979323846 #define M_E 2.7182818284590452354 static Boolean is_int(double t1) MLIB; static Boolean is_int(double t1) { if (IS_ZERO(t1-round(t1))) return true; return false; } static Boolean guess_pot(double t1,Int32 *cte_lo,Int32 *cte_up) MLIB; static Boolean guess_pot(double t1,Int32 *cte_lo,Int32 *cte_up) { Int16 i,j; double tmp; if (t1<=0) t1=-t1; for (i=2;i<MAX_FORM_F;i++) { tmp=t1/i; for (j=2;i<=tmp;j++) { tmp/=i; if (tmp==1) { if (t1<=0) *cte_lo=-i; else *cte_lo=i; *cte_up=j; return true; } } } return false; } static Boolean guess_div(double t1,Int32 *upper,Int32 *lower,Int16 maxlev) MLIB; static Boolean guess_div(double t1,Int32 *upper,Int32 *lower,Int16 maxlev) { Int16 i; double tmp; for (i=1;i<maxlev;i++) { tmp=i*t1; if (is_int(tmp)) { *upper=(Int32)round(tmp); *lower=i; return true; } } return false; } static Boolean guess_e_x(double t1,Int32 *upper,Int32 *lower,Int32 *cte_up,Int32 *cte_lo) MLIB; static Boolean guess_e_x(double t1,Int32 *upper,Int32 *lower,Int32 *cte_up,Int32 *cte_lo) { Int16 i; double tmp; if (t1<=0) t1=-t1; /* 1*e^(x/y) */ tmp=log(t1); if (guess_div(tmp,upper,lower,MAX_FORM_F)){ *cte_up=1; *cte_lo=1; return true; } /* x*e^(-y) */ tmp=t1; for (i=1;i<MAX_DIV_CONST_E;i++) { tmp*=M_E; if (guess_div(tmp,cte_up,cte_lo,MAX_FORM_F)) { *upper=-i; *lower=1; return true; } } /* x*e^(y) */ tmp=t1; for (i=1;i<MAX_DIV_CONST_E;i++) { tmp/=M_E; if (guess_div(tmp,cte_up,cte_lo,MAX_FORM_F)) { *upper=i; *lower=1; if(*cte_up==0) return false; return true; } } return false; } static Boolean guess_mult_pi(double t1,Int32 *upper,Int32 *lower,Int16 *power) MLIB; static Boolean guess_mult_pi(double t1,Int32 *upper,Int32 *lower,Int16 *power) { Int16 i; double tmp; /* First try dividing it */ tmp=t1; for (i=1;i<MAX_DIV_CONST;i++) { tmp/=M_PI; if (guess_div(tmp,upper,lower,MAX_FORM_F)) { *power=i; if(*upper==0) return false; return true; } } /* multiplying it */ tmp=t1; for (i=1;i<MAX_DIV_CONST;i++) { tmp*=M_PI; if (guess_div(tmp,upper,lower,MAX_FORM_F)) { *power=-i; return true; } } return false; } static Boolean guess_log_x(double t1,Int32 *upper,Int32 *lower) MLIB; static Boolean guess_log_x(double t1,Int32 *upper,Int32 *lower) { if(t1>26) return false; t1=exp(t1); if (guess_div(t1,upper,lower,MAX_FORM_F) && *upper!=0) return true; return false; } static Boolean guess_sqrt(double t1,Int32 *cte_up,Int32 *cte_lo,Int32 *power) MLIB; static Boolean guess_sqrt(double t1,Int32 *cte_up,Int32 *cte_lo,Int32 *power) { Int16 i; double tmp; if (t1<=0.0) t1=-t1; for (i=2;i<4;i++) { tmp=t1/sqrt(i); if (guess_div(tmp,cte_up,cte_lo,MAX_FORM_F)) { *power=i; return true; } } return false; } static Boolean guess_pow1(double t1,Int32 *upper,Int32 *lower,Int16 *power) MLIB; static Boolean guess_pow1(double t1,Int32 *upper,Int32 *lower,Int16 *power) { Int16 i; double tmp; if (t1<=0.0) t1=-t1; tmp=t1; for (i=2;i<MAX_DIV_CONST_E;i++) { tmp*=t1; if (guess_div(tmp,upper,lower,MAX_FORM_F)) { *power=i; if (*upper>GUESS_MAX) return false; return true; } } return false; } static Boolean guess_real(double t1,TCHAR *result) MLIB; static Boolean guess_real(double t1,TCHAR *result) { Int32 upper,lower,cte_up,cte_lo; Int16 power; if (!finite(t1)){ if (isnan(t1)){ StrPrintF(result,_T("NaN")); return true; } if(t1<0.0) StrCopy(result++,_T("-")); else StrCopy(result++,_T("+")); StrPrintF(result,_T("Inf")); return true; } if (IS_ZERO(t1)) { StrCopy(result,_T("0")); return true; } if (is_int(t1)) if (guess_pot(round(t1),&cte_lo,&cte_up)){ if(t1<0.0) StrCopy(result++,_T("-")); StrPrintF(result,_T("%ld^%ld"),cte_lo,cte_up); return true; }; if (fabs(t1)>GUESS_FACTORS_MAX) return false; if (is_int(t1)) { // print factors Int32 value = (Int32)round(t1); Int32 factors[32]; UInt8 fcount, i,k=0; TCHAR* tmp = result; fcount = factorize(value, factors); for(i=0; i<fcount; i++) { if (i < fcount - 1 && factors[i] == factors[i+1]) k++; else { StrPrintF(tmp,_T("%ld*"),factors[i]); while(*tmp) tmp++; if (k) StrPrintF(--tmp,_T("^%d*"),k+1); while(*tmp) tmp++; k=0; } } *--tmp = 0; return true; } if (fabs(t1)>GUESS_MAX) return false; if (guess_div(t1,&upper,&lower,MAX_DIV_F)) { StrPrintF(result,_T("%ld/%ld"),upper,lower); return true; } if (is_int(1/t1)) if (guess_pot(round(1/t1),&cte_lo,&cte_up)){ if(t1<0.0) StrCopy(result++,_T("-")); StrPrintF(result,_T("%ld^-%ld"),cte_lo,cte_up); return true; }; if (guess_sqrt(t1,&cte_up,&cte_lo,&upper)) { if(t1<0.0) StrCopy(result++,_T("-")); if (cte_up!=1){ StrPrintF(result,_T("%ld"),cte_up); result=result+StrLen(result); } if (cte_lo==1) StrPrintF(result,_T("sqrt(%ld)"),upper); else StrPrintF(result,_T("sqrt(%ld)/%ld"),upper,cte_lo); return true; } if (guess_mult_pi(t1,&upper,&lower,&power)) { if (upper<0){ StrCopy(result++,_T("-")); upper=-upper;} if (power>0) { if (upper>1){ StrPrintF(result,_T("%ld"),upper); result+=StrLen(result);} if (power==1) StrPrintF(result,_T("pi")); else StrPrintF(result,_T("pi^%d"),power); result+=StrLen(result); if (lower>1) StrPrintF(result,_T("/%ld"),lower); }else{ StrPrintF(result,_T("%ld/"),upper); result+=StrLen(result); if (lower>1){ StrPrintF(result,_T("%ld"),lower); result+=StrLen(result);} if (power<-1) StrPrintF(result,_T("pi^%d"),-power); else StrCat(result,_T("pi")); } return true; } if (guess_e_x(t1,&upper,&lower,&cte_up,&cte_lo)) { if(t1<0.0) StrCopy(result++,_T("-")); if(cte_lo!=1){ StrPrintF(result,_T("%ld/%ld*"),cte_up,cte_lo); result=result+StrLen(result); } else if(cte_up!=1){ StrPrintF(result,_T("%ld"),cte_up); result=result+StrLen(result); } if (lower==1 && upper>0) StrPrintF(result,_T("e^%ld"),upper); else if (lower==1) StrPrintF(result,_T("e^%ld"),upper); else StrPrintF(result,_T("e^(%ld/%ld)"),upper,lower); return true; } if (guess_log_x(t1,&upper,&lower)) { if (lower==1) StrPrintF(result,_T("ln(%ld)"),upper); else StrPrintF(result,_T("ln(%ld/%ld)"),upper,lower); return true; } if (guess_pow1(t1,&upper,&lower,&power)) { if (upper && lower) { if(t1<0.0) StrCopy(result++,_T("-")); if (power==2 && lower==1) StrPrintF(result,_T("sqrt(%ld)"),upper); else if (power==2) StrPrintF(result,_T("sqrt(%ld/%ld)"),upper,lower); else if (lower==1) StrPrintF(result,_T("%ld^(1/%d)"),upper,power); else StrPrintF(result,_T("(%ld/%ld)^(1/%d)"),upper,lower,power); return true; } } return false; } static Boolean guess_complex(Complex arg,TCHAR *result) MLIB; static Boolean guess_complex(Complex arg,TCHAR *result) { Complex_gon arg_gon; Int32 upper,lower,rad; Int16 i; double tmp; if (!finite(arg.real) || !finite(arg.imag)) return false; if (fabs(arg.real)>100000 || fabs(arg.imag)>100000) return false; arg_gon = cplx_to_gon(arg); if (!guess_real(arg_gon.r,result)) StrCopy(result,display_real(arg_gon.r)); if (is_int(arg_gon.r) && round(arg_gon.r)==1) StrCopy(result,_T("e^(")); else StrCat(result,_T("*e^(")); result=result+StrLen(result); tmp = arg_gon.angle/M_PI; if (is_int(tmp)){ StrPrintF(result,_T("%ldpi*i)"),(Int32)round(tmp)); return true; } if (guess_div(tmp,&upper,&lower,MAX_FORM_F)){ if (upper<0){ StrPrintF(result++,_T("-")); upper=-upper;} if (upper==1) StrPrintF(result,_T("pi/%ld*i)"),lower); else StrPrintF(result,_T("%ldpi/%ld*i)"),upper,lower); return true; } tmp=arg_gon.angle-MAX_DIV_CONST*2*M_PI; for(i=0;i<2*MAX_DIV_CONST;i++){ tmp+=2*M_PI; if (is_int(tmp)){ if (tmp<0){ StrPrintF(result++,_T("-")); tmp=-tmp;} if ((Int32)round(tmp)==1) StrPrintF(result,_T("i)")); else StrPrintF(result,_T("%ldi)"),(Int32)round(tmp)); return true; } if (guess_div(tmp,&upper,&lower,MAX_FORM_F)){ if (upper<0){ StrPrintF(result++,_T("-")); upper=-upper;} if (upper==1) StrPrintF(result,_T("i/%ld)"),lower); else StrPrintF(result,_T("%ldi/%ld)"),upper,lower); return true; } if (guess_sqrt(tmp,&upper,&lower,&rad)) { if(tmp<0.0) StrPrintF(result++,_T("-")); if(upper!=1){ StrPrintF(result,_T("%ld"),upper); result=result+StrLen(result); } if(lower==1) StrPrintF(result,_T("sqrt(%ld)*i)"),rad); else StrPrintF(result,_T("sqrt(%ld)/%ld*i)"),rad,lower); return true; } } return false; } TCHAR * guess(Trpn item) MLIB; TCHAR * guess(Trpn item) { TCHAR *result; Boolean guessed; if (item.type == real) { result = (TCHAR *) MemPtrNew(MAX_FP_NUMBER+1); guessed = guess_real(item.u.realval,result); if (!guessed) { MemPtrFree(result); return NULL; } return result; } else if (item.type == complex) { result = (TCHAR *) MemPtrNew(MAX_FP_NUMBER*3); if (IS_ZERO(item.u.cplxval->imag)){ if (guess_real(item.u.cplxval->real,result)) return result; else { MemPtrFree(result); return NULL;} } if (IS_ZERO(item.u.cplxval->real)) if (guess_real(item.u.cplxval->imag,result)){ StrPrintF(result+StrLen(result),_T("*i")); return result; }; guessed = guess_complex(*item.u.cplxval,result); if (!guessed) { MemPtrFree(result); return NULL; } return result; } return NULL; } --- NEW FILE: defuns.h --- /* * $Id: defuns.h,v 1.1 2009/09/24 21:16:50 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999 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 _DEFUNS_H_ #define _DEFUNS_H_ #include "segment.h" #include "konvert.h" #define MAX_FP_NUMBER 64 /* Application specific things */ #define APP_ID 'OpCl' #define LIB_ID 'OpCl' #define DBNAME _T("CalcDB-OpCl") #define HISTORYDBNAME _T("CalcDB-H-OpCl") #define SOLVERDBNAME _T("CalcDB-S-OpCl") #define DBTYPE 'Data' #define SOLVERDBTYPE 'Slvr' #define CARDNO 0 #define DBVERSION 5 #define HIST_DB_VERSION 6 #define SOLVER_DB_VERSION 1 #define PREF_DEFAULT 0 #define PREF_RESULT 1 #define PREF_GRAPH 3 #define PREF_LSTEDIT 4 #define PREF_MTXEDIT 5 #define PREF_DIA 6 /* Change this if you are changing contents of the preferences structure */ #define PREF_VERSION 44 #define PREF_RES_VERSION 2 #define PREF_GRAPH_VERSION 5 #define PREF_LSTEDIT_VERSION 1 #define PREF_MTXEDIT_VERSION 1 #define PREF_DIA_VERSION 1 /* Maximum length of normal strings copied from tSTR */ #define MAX_RSCLEN 30 #define MAX_RESULT 17 /* Rounding offset for reduce precision */ #define ROUND_OFFSET 13 #define PRECISION_TO_ZERO 1E-12 /* konvert.c constants */ #define MAX_RPNSIZE 105 #define MAX_OSTACK 45 //#define NaN ((double)(3-3)/(3-3)) TCHAR * guess(Trpn item) MLIB; //TCHAR * print_error(CError err); #endif Index: stack.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/stack.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** stack.cpp 5 Jul 2009 20:53:37 -0000 1.3 --- stack.cpp 24 Sep 2009 21:16:50 -0000 1.4 *************** *** 37,41 **** #include "cmatrix.h" #include "compat/MathLib.h" ! #include "prefs.h" /*********************************************************************** --- 37,41 ---- #include "cmatrix.h" #include "compat/MathLib.h" ! #include "core/prefs.h" /*********************************************************************** *************** *** 210,215 **** Int16 i; if (dest->allocated < orig->size) ! ErrFatalDisplayIf(1,"Trying to copy larger stack into smaller."); ! for (i=0;i<orig->size;i++) rpn_duplicate(&dest->stack[i],orig->stack[i]); dest->size = orig->size; --- 210,215 ---- Int16 i; if (dest->allocated < orig->size) ! ErrFatalDisplayIf(1, _T("Trying to copy larger stack into smaller.")); ! for (i=0 ; i<(orig->size) ; i++) rpn_duplicate(&dest->stack[i],orig->stack[i]); dest->size = orig->size; *************** *** 378,382 **** realarg = tmpitem.u.realval; if (-2147483648.0 <= realarg && realarg <= 2147483647.0) { ! *((Int32 *)arg1) = tmpitem.u.realval; } else --- 378,382 ---- realarg = tmpitem.u.realval; if (-2147483648.0 <= realarg && realarg <= 2147483647.0) { ! *((Int32 *)arg1) = ((Int32) tmpitem.u.realval); } else *************** *** 908,912 **** stack_pop(CodeStack *stack) { ! ErrFatalDisplayIf(stack->size==0,"Null stack size"); stack->size--; --- 908,912 ---- stack_pop(CodeStack *stack) { ! ErrFatalDisplayIf(stack->size==0, _T("Null stack size")); stack->size--; *************** *** 958,962 **** { ErrFatalDisplayIf(stack->size==stack->allocated, ! "RPN Stack overflow"); stack->stack[stack->size]=rpn; stack->size++; --- 958,962 ---- { ErrFatalDisplayIf(stack->size==stack->allocated, ! _T("RPN Stack overflow")); stack->stack[stack->size]=rpn; stack->size++; Index: konvert.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/konvert.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** konvert.cpp 5 Jul 2009 20:53:37 -0000 1.3 --- konvert.cpp 24 Sep 2009 21:16:50 -0000 1.4 *************** *** 36,40 **** #include "funcs.h" #include "stack.h" ! #include "prefs.h" #include "history.h" #include "integ.h" --- 36,40 ---- #include "funcs.h" #include "stack.h" ! #include "core/prefs.h" #include "history.h" #include "integ.h" Index: fp.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/fp.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** fp.cpp 5 Jul 2009 20:53:37 -0000 1.2 --- fp.cpp 24 Sep 2009 21:16:50 -0000 1.3 *************** *** 532,536 **** /* Extract decimal digits of mantissa */ for (i = 0; i < prec; ++i, --dec) { ! Int32 d = fcd.d; *s++ = d + _T('0'); if (!dec) --- 532,536 ---- /* Extract decimal digits of mantissa */ for (i = 0; i < prec; ++i, --dec) { ! Int32 d = (Int32) (fcd.d); *s++ = d + _T('0'); if (!dec) Index: calcDB.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/calcDB.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** calcDB.cpp 6 Aug 2009 21:41:40 -0000 1.3 --- calcDB.cpp 24 Sep 2009 21:16:50 -0000 1.4 *************** *** 313,316 **** --- 313,318 ---- MemPtrFree(record); *err = c_notvar; + memset(&result, 0, sizeof(result)); // Mapi: added this to return an initialized value + // in all cases. return result; } |
From: Mapi B. <ma...@us...> - 2009-09-24 21:16:24
|
Update of /cvsroot/easycalc/PPCport/core In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14251 Modified Files: core_globals.h Added Files: ansops.cpp ansops.h core_display.cpp core_display.h core_main.cpp core_main.h defmgr.cpp defmgr.h Main.cpp Main.h prefs.h varmgr.cpp varmgr.h Log Message: Subset of the code, compiling, but not yet linking Index: core_globals.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/core_globals.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** core_globals.h 22 Jun 2009 22:04:26 -0000 1.1 --- core_globals.h 24 Sep 2009 21:16:09 -0000 1.2 *************** *** 105,109 **** /* Annunciator codes */ /*********************/ ! #define NB_ANNUN 13 #define ANN_SHIFT 0 #define ANN_DEG 1 --- 105,109 ---- /* Annunciator codes */ /*********************/ ! #define NB_ANNUN 14 #define ANN_SHIFT 0 #define ANN_DEG 1 *************** *** 119,126 **** #define ANN_SG 11 #define ANN_RESMENU 12 ! /*********************/ ! /* Annunciator value */ ! /*********************/ #define ANNVAL_UNCH -1 #define ANNVAL_DEG 0 --- 119,128 ---- #define ANN_SG 11 #define ANN_RESMENU 12 + #define ANN_HSTMENU 13 ! /******************************/ ! /* Annunciator value */ ! /* Note: UNCH means unchanged */ ! /******************************/ #define ANNVAL_UNCH -1 #define ANNVAL_DEG 0 --- NEW FILE: Main.cpp --- /* * $Id: Main.cpp,v 1.1 2009/09/24 21:16:09 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-23 - John Hodapp <bi...@em...> * Added code to force insertion point for fwd/backspace * and delete keys to work on single character even if * entire selection is highlighted. * 2001-09-31 - John Hodapp - added code to display and select trig mode * on Basic and Scientific screen. Repeating fwd/backspace. * 2001-12-8 - John Hodapp - added code to dispaly and select Radix on * Basic and Scien screens. * 2003-05-19 - Arno Welzel - added code for Sony Clie support */ #include "StdAfx.h" #include "compat/PalmOS.h" #include "konvert.h" //#include "calc.h" //#include "calcrsc.h" #include "prefs.h" #include "fp.h" #include "varmgr.h" #include "stack.h" #include "funcs.h" #include "ansops.h" #include "history.h" //#include "memo.h" #define _MAIN_C_ #include "system - UI/Skin.h" #include "Main.h" #ifdef SUPPORT_DIA #include "DIA.h" #endif Main::Main(void) { } Main::~Main(void) { } const static struct { TCHAR *string; Boolean operatr; // Prepend Ans when in the beginning of line Boolean func; // Add ')' and backspace one position Boolean nostartparen; Boolean wide; const TCHAR *helptext; }buttonString[]={ {_T("0"),false}, {_T("1"),false}, {_T("2"),false}, {_T("3"),false}, {_T("4"),false}, {_T("5"),false}, {_T("6"),false}, {_T("7"),false}, {_T("8"),false}, {_T("9"),false}, {_T("A"),false}, {_T("B"),false}, {_T("C"),false}, {_T("D"),false}, {_T("E"),false}, {_T("F"),false}, {_T("&"),true}, {_T("|"),true}, {_T(""),true}, // xor {_T("<<"),true}, {_T(">>"),true}, {_T("+"),true}, {_T("-"),true}, {_T("-"),false}, {_T("*"),true}, {_T("/"),true}, {_T("ans")}, {_T(""),false,true}, // ?? {_T("^"),true}, // power {_T("log"),false,true}, {_T("ln"),false,true}, {_T("^(-1)"),true}, // 1/x {_T("^(1/"),true,true,true}, // nth root {_T("^2"),true}, {_T("sqrt"),false,true}, {_T("sin"),false,true}, {_T("cos"),false,true}, {_T("tan"),false,true}, {_T("exp"),false,true}, {_T("fact"),false,true}, {_T("pi")}, {_T("°")}, // degrees {_T("'")}, // minutes {_T("abs"),false,true}, // Magnitude {_T("angle"),false,true}, {_T("i")}, // Complex_i {_T(":")}, // column {_T(")")}, {_T("E")}, {_T("asin"),false,true}, {_T("acos"),false,true}, {_T("atan"),false,true}, {_T("sinh"),false,true}, {_T("cosh"),false,true}, {_T("tanh"),false,true}, {_T("asinh"),false,true}, {_T("acosh"),false,true}, {_T("atanh"),false,true}, {_T("log"),false,true}, {_T("10^")}, {_T("log2"),false,true}, {_T("2^")}, {_T("fact"),false,true}, {_T("ncr"),false,true}, {_T("npr"),false,true}, {_T("round"),false,true,false,true}, {_T("trunc"),false,true,false,true}, {_T("floor"),false,true,false,true}, {_T("gamma"),false,true,false,true}, {_T("beta"),false,true,false,true}, {_T("rand"),false,false}, {_T("rNorm"),false,false}, {_T("real"),false,true,false,true}, {_T("imag"),false,true,false,true}, {_T("conj"),false,true}, {_T("exp(i*"),false,true,true,false}, {_T("fzero"),false,true,false,true,_T("min:max:f[:err]")}, {_T("fvalue"),false,true,false,true,_T("min:max:val:f[:err]")}, {_T("fmin"),false,true,false,true,_T("min:max:f[:err]")}, {_T("fmax"),false,true,false,true,_T("min:max:f[:err]")}, {_T("fd_dx"),false,true,false,true,_T("x:f[:err]")}, // d/dx {_T("fromberg"),false,true,false,true,_T("min:max:f[:n]")}, // integ {_T("fd2_dx"),false,true,false,true,_T("x:f[:err]")}, // d2/dx {_T("()=\""),false,true,true,true}, {_T("\"")}, {_T("x")}, {_T("list"),false,true,false,true}, {_T("median"),false,true,false,true}, {_T("mean"),false,true,false,true}, {_T("sum"),false,true,false,true}, {_T("lmin"),false,true}, // min {_T("lmax"),false,true}, // max {_T("prod"),false,true}, {_T("variance"),false,true,false,true}, {_T("stddev"),false,true,false,true}, {_T("dim"),false,true}, {_T("[")}, {_T("matrix"),false,true,false,true}, {_T("identity"),false,true,false,true}, {_T("det"),false,true}, {_T("qrs"),false,true}, {_T("rref"),false,true}, {_T("qrq"),false,true}, {_T("qrr"),false,true}, {_T("["),true}, // x[] {_T("]")}, {_T("qBinomial"),false,true,false,true,_T("c:n:p")}, {_T("qBeta"),false,true,false,true,_T("x:a:b")}, {_T("qChiSq"),false,true,false,true,_T("ChiSq:df")}, {_T("qF"),false,true,false,true,_T("F:df1:df2")}, {_T("qPoisson"),false,true,false,true,_T("c:lam")}, {_T("qStudentt"),false,true,false,true,_T("t:df")}, {_T("qWeibull"),false,true,false,true,_T("t:a:b")}, {_T("qNormal"),false,true,false,true,_T("z")}, {_T("range"),false,true,false,true,_T("n:start[:step]")}, {_T("rNorm"),false,true,false,true}, {_T("find"),false,true,false,true,_T("expr:data")}, {_T("sample"),false,true,false,true,_T("data:indices")}, {_T("filter"),false,true,false,true,_T("b_coefs:a_coefs:data")}, {_T("conv"),false,true,false,true}, {_T("fft"),false,true,false,true,_T("data[:N]")}, {_T("ifft"),false,true,false,true,_T("data[:N]")}, {_T("prevprime"),false,true}, {_T("isprime"),false,true}, {_T("nextprime"),false,true}, {_T("gcd"),false,true}, {_T("lcm"),false,true}, {_T("phi"),false,true}, {_T("gcdex"),false,true,false,true}, {_T("chinese"),false,true,false,true}, {_T("modinv"),false,true,false,true}, {_T("modpow"),false,true,false,true}, {_T("factor"),false,true,false,true}, {_T("besseli"),false,true,false,true,_T("n:x")}, {_T("besselj"),false,true,false,true,_T("n:x")}, {_T("besselk"),false,true,false,true,_T("n:x")}, {_T("bessely"),false,true,false,true,_T("n:x")}, {_T("ellc1"),false,true,false,true}, {_T("ellc2"),false,true,false,true}, {_T("elli1"),false,true,false,true,_T("m:phi")}, {_T("elli2"),false,true,false,true,_T("m:phi")}, {_T("euler"),false,false,false,true}, {_T("cn"),false,true}, {_T("dn"),false,true}, {_T("sn"),false,true}, {_T("igamma"),false,true,false,true,_T("a:x")}, {_T("ibeta"),false,true,false,true,_T("a:b:x")}, {_T("erf"),false,true,false,true}, {_T("erfc"),false,true,false,true}, {0,NULL,false} }; #define BUTTON_COUNT 149 /*********************************************************************** * * FUNCTION: main_replace_enters * * DESCRIPTION: Replace \n by ; * ***********************************************************************/ static void main_replace_enters (TCHAR *text) { for (;*text;text++) if (*text=='\n') *text=';'; } /*********************************************************************** * * FUNCTION: main_input_exec * * DESCRIPTION: Execute contents of input line and show the result * * PARAMETERS: Nothing * * RETURN: err - Possible error that occurred during computation * ***********************************************************************/ CError main_input_exec (TCHAR *inp, Trpn *result) { CError err; // FieldPtr pole; int inpsize; CodeStack *stack; if (*inp == '\0') return c_syntax; inpsize = (int) wcslen(inp); main_replace_enters(inp); stack = text_to_stack(inp, &err); if (!err) { err = stack_compute(stack); /* Add line to history After computing and After succesful * compilation */ if (inpsize) history_add_line(inp); if (!err) { (*result) = stack_pop(stack); err=set_ans_var(*result); rpn_delete(*result); } stack_delete(stack); } return err; } /*********************************************************************** * * FUNCTION: main_insert * * DESCRIPTION: Insert a text on an input line, handle cases like * embracing a selected text with a function, auto-closing * of brackets etc. * * PARAMETERS: fieldid - id of field where to insert text * text - text to add to input line * operatr - prepend 'ans' if on the beginning of line * func - add opening and possibly closing bracket * nostartparen - is a function without opening bracket * helptext - description of parameters of a function * * RETURN: Nothing * ***********************************************************************/ void main_insert(Skin *skin, void *hwnd_edit, const TCHAR *text, Boolean operatr, Boolean func, Boolean nostartparen, const TCHAR *helptext) { unsigned long startp, endp; skin->get_select_text(hwnd_edit, &startp, &endp); if (operatr && !func) { /* Insert 'ans' if on the beginning */ if ((skin->get_insert_pos(hwnd_edit) == 0) || ((startp != endp) && (startp == 0))) skin->insert_input_text(hwnd_edit, _T("ans")); skin->insert_input_text(hwnd_edit, text); } else if (func) { /* if selected, insert in front of selection and * put brackets around selection */ if (startp != endp) { skin->select_input_text(hwnd_edit, startp, startp); } if ((skin->get_insert_pos(hwnd_edit) == 0) && operatr) { skin->insert_input_text(hwnd_edit, _T("ans")); if (startp != endp) endp += 3; } int len = _tcslen(text); if (len) skin->insert_input_text(hwnd_edit, text); if (!nostartparen) { skin->insert_input_text(hwnd_edit, _T("(")); startp += 1; endp += 1; } if (startp != endp) { startp += len; endp += len; skin->set_insert_pos(hwnd_edit, endp); if (text[len-1] == '"') skin->insert_input_text(hwnd_edit, _T("\"")); else skin->insert_input_text(hwnd_edit, _T(")")); skin->select_input_text(hwnd_edit, startp, endp); } else if (calcPrefs.matchParenth) { /* nothing selected */ if (text[len-1] == '"') skin->insert_input_text(hwnd_edit, _T("\"")); else skin->insert_input_text(hwnd_edit, _T(")")); skin->set_insert_pos(hwnd_edit, skin->get_insert_pos(hwnd_edit)-1); } if ((startp == endp) && helptext && calcPrefs.insertHelp) { startp = skin->get_insert_pos(hwnd_edit); skin->insert_input_text(hwnd_edit, helptext); skin->select_input_text(hwnd_edit, startp, startp+_tcslen(helptext)); } } else skin->insert_input_text(hwnd_edit, text); } /*********************************************************************** * * FUNCTION: main_btnrow_click * * DESCRIPTION: Handle the tap on the button on the screen, * insert the proper text on the input line * * PARAMETERS: btnid - id of pressed button * * RETURN: true - button is in the group * false - button doesn't exist * ***********************************************************************/ static Boolean main_btnrow_click(Skin *skin, int btnid) IFACE; static Boolean main_btnrow_click(Skin *skin, int btnid) { if ((btnid < 1) || (btnid > BUTTON_COUNT)) return false; int index = btnid - 1; main_insert(skin, NULL, buttonString[index].string, buttonString[index].operatr, buttonString[index].func, buttonString[index].nostartparen, buttonString[index].helptext ); return true; } --- NEW FILE: ansops.cpp --- /* * $Id: ansops.cpp,v 1.1 2009/09/24 21:16:09 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 "konvert.h" #include "stack.h" //#include "result.h" #include "core_display.h" #include "defuns.h" #include "ansops.h" #include "EasyCalc.h" //#include "calcrsc.h" /*********************************************************************** * * FUNCTION: ans_redisplay * * DESCRIPTION: Executes a code and display its result on display * If the result is string, display it as formatted * * PARAMETERS: text - code to execute * * RETURN: None * ***********************************************************************/ void ans_redisplay(Skin *skin, void *hWnd_p, TCHAR *text) { CError err; CodeStack *stack; Trpn vysledek; stack = text_to_stack(text,&err); if (!err) { err = stack_compute(stack); if (!err) { vysledek = stack_pop(stack); if (vysledek.type == string) result_set_pow(skin, hWnd_p, vysledek.u.stringval); else result_set(skin, hWnd_p, vysledek); rpn_delete(vysledek); } stack_delete(stack); } if (err) result_error(skin, hWnd_p, err); return; 1; //result_draw(); } /*********************************************************************** * * FUNCTION: ans_guess * * DESCRIPTION: Guesses last entered value and displays the result on display * * PARAMETERS: None * * RETURN: None * ***********************************************************************/ void ans_guess(Skin *skin, void *hWnd_p) { TCHAR *result; CError err; Trpn ans; ans = db_read_variable(_T("ans"),&err); if (err) { FrmAlert(altAnsProblem, hWnd_p); return; } result = guess(ans); if (!result) { FrmAlert(altGuessNotFound, hWnd_p); rpn_delete(ans); return; } result_set_pow(skin, hWnd_p, result); rpn_delete(ans); MemPtrFree(result); return; 1; //result_draw(); } --- NEW FILE: core_display.h --- /***************************************************************************** * EasyCalc -- a scientific calculator * Copyright (C) 2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, * as published by the Free Software Foundation. * * 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 *****************************************************************************/ #ifndef CORE_DISPLAY_H #define CORE_DISPLAY_H 1 //#include "EasyCalc.h" #include "system - UI/skin.h" #include "compat/PalmOS.h" #include "core/mlib/display.h" #include "core/prefs.h" typedef enum { plaintext, powtext, fmtnumber }printType; typedef struct { rpntype ansType; printType formatType; Tbase dispBase; }TresultPrefs; #define MENULEVEL_COMMAND 0 #define MENULEVEL_ALPHA 1 #define MENULEVEL_TRANSIENT 2 #define MENULEVEL_PLAIN 3 #define MENULEVEL_APP 4 #ifndef _CORE_DISPLAY_C_ extern TCHAR *resMenuDesc[]; // Array of strings for the result actions menu. extern TCHAR *strErrCodes[]; // Error strings #endif void squeak(void); void redisplay(void); void set_menu(int level, int menuid); void result_copy(Skin *skin) IFACE; void result_set(Skin *skin, void *hWnd_p, Trpn item) IFACE; void result_set_text(Skin *skin, void *hWnd_p, TCHAR *text,rpntype type) IFACE; void result_set_pow(Skin *skin, void *hWnd_p, TCHAR *text) IFACE; void result_popup(Skin *skin, void *hWnd_p) IFACE; void result_action(Skin *skin, void *hWnd_p, void *hWnd_calc, int selection); void result_error(Skin *skin, void *hWnd_p, CError errcode) IFACE; TCHAR *print_error(CError err); #endif --- NEW FILE: core_main.h --- /***************************************************************************** * EasyCalc -- a scientific calculator * Copyright (C) 2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, * as published by the Free Software Foundation. * * 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 *****************************************************************************/ #ifndef CORE_MAIN_H #define CORE_MAIN_H 1 #include "EasyCalc.h" /*******************/ /* Keyboard repeat */ /*******************/ extern int repeating; extern int repeating_shift; extern int repeating_key; /**********************************/ /* Shell/Core interface functions */ /**********************************/ int core_repeat() MAIN_SECT; void core_keytimeout1() MAIN_SECT; void core_keytimeout2() MAIN_SECT; void core_timeout3(int repaint) MAIN_SECT; int core_alpha_menu() MAIN_SECT; int core_hex_menu() MAIN_SECT; int core_keydown(int key, int *enqueued, int *repeat) MAIN_SECT; int core_keyup() MAIN_SECT; /*******************/ /* Other functions */ /*******************/ void set_running(bool state) MAIN_SECT; void continue_running() MAIN_SECT; #endif --- NEW FILE: core_main.cpp --- /***************************************************************************** * EasyCalc -- a scientific calculator * Copyright (C) 2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, * as published by the Free Software Foundation. * * The name and many features come from * - EasyCalc on Palm: * * It also is reusing elements from * - Free42: Thomas Okken * for its adaptation to the PocketPC world. * * 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 *****************************************************************************/ /* core_main.cpp : core functions which are not dependent on the running OS. *****************************************************************************/ #include "stdafx.h" #include "core_main.h" #include "core/core_globals.h" #include "core_tables.h" #include "core_display.h" #include <stdlib.h> /*------------------------------------------------------------------------------- - Constants. - -------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------- - Type declarations. - -------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------- - Global variables. - -------------------------------------------------------------------------------*/ int repeating = 0; int repeating_shift; int repeating_key; /*------------------------------------------------------------------------------- - Module variables. - -------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------- - Forward declarations. - -------------------------------------------------------------------------------*/ static void stop_interruptible() MAIN_SECT; static int handle_error(int error) MAIN_SECT; /*------------------------------------------------------------------------------- - Procedures. - -------------------------------------------------------------------------------*/ /******************************************************************************** * FUNCTION: set_shift() * * Set the shift state. * ********************************************************************************/ static void set_shift(bool state) { if (mode_shift != state) { mode_shift = state; shell_annunciators(ANNVAL_UNCH, state, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH); } } /******************************************************************************** * FUNCTION: core_repeat() * * This function is called by the shell to signal auto-repeating key events. * * It is the core's responsibility to keep track of *which* key is repeating. * * The function can return 0, to request repeating to stop; 1, which requests * * a slow repeat rate, for SST/BST; or 2, which requests a fast repeat rate, * * for number/alpha entry. * ********************************************************************************/ int core_repeat() { // For EasyCalc, no repeat. // keydown(repeating_shift, repeating_key); // int rpt = repeating; int rpt = 0; repeating = 0; return (rpt); } /******************************************************************************** * FUNCTION: core_keytimeout1() * * This function informs the emulator core that the currently pressed key has * * been held down for 1/4 of a second. (If the key is released less than 1/4 * * second after being pressed, this function is not called.) * * For keys that do not execute immediately, this marks the moment when the * * calculator displays the key's function name. * ********************************************************************************/ void core_keytimeout1() { // Function not used by EasyCalc // if ((pending_command == CMD_LINGER1) || (pending_command == CMD_LINGER2)) // return; // if ((pending_command == CMD_RUN) || (pending_command == CMD_SST)) { // int saved_pending_command = pending_command; // if (pc == -1) // pc = 0; // prgm_highlight_row = 1; // flags.f.prgm_mode = 2; /* HACK - magic value to tell redisplay() */ // /* not to suppress option menu highlights */ // pending_command = CMD_NONE; // redisplay(); // flags.f.prgm_mode = 0; // pending_command = saved_pending_command; // } else if ((pending_command != CMD_NONE) && (pending_command != CMD_CANCELLED) // && ((cmdlist(pending_command)->flags & FLAG_NO_SHOW) == 0)) { // display_command(0); // /* If the program catalog was left up by GTO or XEQ, // * don't paint over it */ // if ((mode_transientmenu == MENU_NONE) || (pending_command == CMD_NULL)) // display_x(1); // flush_display(); // } } /******************************************************************************** * FUNCTION: core_keytimeout2() * * This function informs the emulator core that 2 seconds have passed since * * core_keytimeout1() was called. (If the key is released less than 2 seconds * * after core_keytimeout1() is called, this function is not called.) * * This marks the moment when the calculator switches from displaying the key's * * function name to displaying 'NULL' (informing the user that the key has been * * annulled and so no operation will be performed when it is released). * ********************************************************************************/ void core_keytimeout2() { // Function not used by EasyCalc // if ((pending_command == CMD_LINGER1) || (pending_command == CMD_LINGER2)) // return; // remove_program_catalog = 0; // if ((pending_command != CMD_NONE) && (pending_command != CMD_CANCELLED) // && ((cmdlist(pending_command)->flags & FLAG_NO_SHOW) == 0)) { // clear_row(0); // draw_string(0, 0, "NULL", 4); // display_x(1); // flush_display(); // pending_command = CMD_CANCELLED; // } } /******************************************************************************** * FUNCTION: core_timeout3() * * A wakeup call that the core can request by calling shell_request_timeout3(). * * Used to implement the brief linger period after MEM, SHOW, and shift- * * VARMENU. The 'repaint' parameter says whether the callback is invoked * * because the timeout period expired (1), or because a key event is on its * * way (0); if a key event is on its way, the emulator core should not repaint * * the screen, in order to avoid flashing. * ********************************************************************************/ void core_timeout3(int repaint) { // Function not used by EasyCalc // /* Remove the output of SHOW, MEM, or shift-VARMENU from the display */ // if (pending_command == CMD_LINGER1) // pending_command = CMD_CANCELLED; // else if (pending_command == CMD_LINGER2) { // flags.f.message = 0; // flags.f.two_line_message = 0; // pending_command = CMD_NONE; // if (repaint) // redisplay(); // } } /******************************************************************************** * FUNCTION: core_alpha_menu() * * The shell uses this function to check if the core is in "alpha" mode (i.e. * * the ALPHA menu or any of its submenus is active). This affects how events * * from the keyboard (the real PC keyboard, not the on-screen one emulated by * * the calc) or PalmOS Graffiti device are handled: in alpha mode, printable * * ASCII characters are sent straight to the core; outside alpha mode, all * * key events are translated sequences of key events according to the keymap * * file. * ********************************************************************************/ int core_alpha_menu() { // int *menu = get_front_menu(); // return ((menu != NULL) && (*menu >= MENU_ALPHA1) && (*menu <= MENU_ALPHA_MISC2)); return (0); } /******************************************************************************** * FUNCTION: core_hex_menu() * * The shell uses this function to check if the core is in "hex" mode (i.e. * * the A..F submenu of the BASE application is active). This affects how events * * from the keyboard (the real PC keyboard, not the on-screen one emulated by * * the calc) are handled: in hex mode, 'A' through 'F' and 'a' through 'f' are * * translated to keycodes 1 through 6, regardless of the keyboard map. * ********************************************************************************/ int core_hex_menu() { // int *menu = get_front_menu(); // return ((menu != NULL) && (*menu == MENU_BASE_A_THRU_F)); return (0); } /******************************************************************************** * FUNCTION: core_keydown() * * This function informs the emulator core that a key was pressed. Keys * * are identified using a numeric key code, which corresponds to the key * * numbers returned by the 'GETKEY' function: 'Sigma+' is 1, '1/x' is 2, * * and so on. The shift key is 28 -- 'shift' handling is performed by the * * emulator core, so it needs to receive raw key codes, unlike the 'GETKEY' * * function, which handles the shift key itself and then returns key codes in * * the range 38..74 for shifted keys. The core_keydown() function should only * * be called with key codes from 1 to 37, inclusive. * * Keys that cause immediate action should be handled immediately when this * * function is called, and calls to core_keytimeout1(), core_keytimeout2(), * * and core_keyup() should be ignored (until the next core_keydown(), that * * is!). Keys that are handled only when *released* should not be handled * * immediately when this function is called; the emulator core should store the * * key code, handle core_keytimeout1() and core_keytimeout2() as appropriate, * * and not perform any action until core_keyup() is called. * * RETURNS: a flag indicating whether or not the front end should call this * * function again as soon as possible. This will be 1 if the calculator is * * running a user program, and is only returning execution to the shell because * * it has detected that there is a pending event. * * The 'enqueued' pointer is a return parameter that the emulator core uses to * * tell the shell if it has enqueued the keystroke. If this is 1, the shell * * should not send call timeout1(), timeout2(), or keyup() for this keystroke. * * NOTE: a key code of 0 (zero) signifies 'no key'; this is needed if the shell * * is calling this function because it asked to be called (by returning 1 the * * last time) but no keystrokes are available. It is not necessary to balance * * the keydown call with a keyup in this case. * * The 'repeat' pointer is a return parameter that the emulator core uses to * * ask the shell to auto-repeat the current key. If this is set to 1 or 2, the * * shell will not call timeout1() and timeout2(), but will repeatedly call * * core_repeat() until the key is released. (1 requests a slow repeat rate, for * * SST/BST; 2 requests a fast repeat rate, for number/alpha entry.) * ********************************************************************************/ int core_keydown(int key, int *enqueued, int *repeat) { *enqueued = 0; *repeat = 0; if (key == KEY_SHIFT) { set_shift(!mode_shift); return (mode_running || (keybuf_head != keybuf_tail)); } if (mode_interruptible != NULL) { /* We're in the middle of an interruptible function * (e.g., INVRT, PRP); queue up any keystrokes and invoke * the appropriate callback to keep the funtion moving along */ int error, keep_running; if (key != 0) { /* Enqueue... */ *enqueued = 1; if (key == KEY_EXIT || (mode_stoppable && !mode_shift && (key == KEY_RUN))) { keybuf_tail = keybuf_head; stop_interruptible(); return (0); } else { if (((keybuf_head + 1) & 15) != keybuf_tail) { if (mode_shift) key = -key; keybuf[keybuf_head] = key; keybuf_head = (keybuf_head + 1) & 15; } } set_shift(false); } error = mode_interruptible(0); if (error == ERR_INTERRUPTIBLE) /* Still not done */ return (1); mode_interruptible = NULL; keep_running = handle_error(error); if (mode_running) { if (!keep_running) set_running(false); } else { shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, false); pending_command = CMD_NONE; } if (mode_running || (keybuf_tail != keybuf_head)) return (1); else { redisplay(); return (0); } } if (mode_running && !mode_getkey) { /* We're running; queue up any keystrokes and invoke * continue_running() to keep the program moving along */ if (key != 0) { if (key == KEY_EXIT) { keybuf_tail = keybuf_head; set_shift(false); set_running(false); pending_command = CMD_CANCELLED; return (0); } /* Enqueue... */ *enqueued = 1; if (!mode_shift && (key == KEY_RUN)) { keybuf_tail = keybuf_head; set_running(false); redisplay(); return (0); } if (((keybuf_head + 1) & 15) != keybuf_tail) { if (mode_shift) key = -key; keybuf[keybuf_head] = key; keybuf_head = (keybuf_head + 1) & 15; } set_shift(false); } continue_running(); if ((mode_running && !mode_getkey) || (keybuf_tail != keybuf_head)) return (1); else { if (mode_getkey) /* Technically, the program is still running, but we turn * off the 'running' annunciator so that the user has some * cue that they may now type. */ shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, false); else redisplay(); return (0); } } /* If we get here, mode_running must be false. * or a program is running but hanging in GETKEY; */ if (keybuf_tail != keybuf_head) { /* We're not running, or a program is waiting in GETKEY; * feed queued-up keystroke to keydown() */ int oldshift = 0; int oldkey = keybuf[keybuf_tail]; if (oldkey < 0) { oldkey = -oldkey; oldshift = 1; } keybuf_tail = (keybuf_tail + 1) & 15; /* If we're in GETKEY mode, the 'running' annunciator is off; * see the code circa 30 lines back. * We now turn it back on since program execution resumes. */ if (mode_getkey && mode_running) shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, true); /* Feed the dequeued key to the usual suspects */ #define keydown(a,b) keydown(oldshift, oldkey); core_keyup(); /* We've just de-queued a key; may have to enqueue * one as well, if the user is actually managing to * type while we're unwinding the keyboard buffer */ if (key != 0) { if (((keybuf_head + 1) & 15) != keybuf_tail) { if (mode_shift) key = -key; keybuf[keybuf_head] = key; keybuf_head = (keybuf_head + 1) & 15; } set_shift(false); } return (mode_running || (keybuf_head != keybuf_tail)); } /* No program is running, or it is running but waiting for a * keystroke (GETKEY); handle any new keystroke that has just come in */ if (key != 0) { int shift = mode_shift; set_shift(false); if (mode_getkey && mode_running) shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, true); keydown(shift, key); if (repeating != 0) { *repeat = repeating; repeating = 0; } return (mode_running && !mode_getkey); } /* Nothing going on at all! */ return (0); } /******************************************************************************** * FUNCTION: core_keyup() * * This function informs the emulator core that the currently pressed key (that * * is, the one whose key code was given to it in the most recent call to * * core_keydown()) has been released. * * This function is always called when a key is released, regardless of how * * long it was held down, and regardless of whether or not core_keytimeout1() * * and core_keytimeout2() were called following the most recent * * core_keydown(). * * RETURNS: a flag indicating whether or not the front end should call this * * function again as soon as possible. This will be 1 if the calculator is * * running a user program, and is only returning execution to the shell because * * it has detected that there is a pending event. * ********************************************************************************/ int core_keyup() { int error = ERR_NONE; if ((pending_command == CMD_LINGER1) || (pending_command == CMD_LINGER2)) { pending_command = CMD_LINGER2; return (mode_running || (keybuf_head != keybuf_tail)); } if (pending_command == CMD_SILENT_OFF) { shell_powerdown(); pending_command = CMD_NONE; return (0); } if (pending_command == CMD_NONE) return (mode_running || (keybuf_head != keybuf_tail)); /* if (remove_program_catalog) { if (mode_transientmenu == MENU_CATALOG) set_menu(MENULEVEL_TRANSIENT, MENU_NONE); else if (mode_plainmenu == MENU_CATALOG) set_menu(MENULEVEL_PLAIN, MENU_NONE); remove_program_catalog = 0; } if ((pending_command == CMD_CANCELLED) || (pending_command == CMD_NULL)) { pending_command = CMD_NONE; redisplay(); return (mode_running || (keybuf_head != keybuf_tail)); } mode_varmenu = (pending_command == CMD_VMSTO) || (pending_command == CMD_VMSTO2) || (pending_command == CMD_VMSOLVE) || (pending_command == CMD_VMEXEC); if (input_length > 0) { */ /* INPUT active */ /* if ((pending_command == CMD_RUN) || (pending_command == CMD_SST)) { int err = generic_sto(&input_arg, 0); if ((flags.f.trace_print || flags.f.normal_print) && flags.f.printer_exists) { char lbuf[12], rbuf[100]; int llen, rlen; string_copy(lbuf, &llen, input_name, input_length); lbuf[llen++] = '='; rlen = vartype2string(reg_x, rbuf, 100); print_wide(lbuf, llen, rbuf, rlen); } input_length = 0; if (err != ERR_NONE) { pending_command = CMD_NONE; display_error(err, 1); redisplay(); return (mode_running || (keybuf_head != keybuf_tail)); } } else if ((pending_command == CMD_GTO) || (pending_command == CMD_GTODOT) || (pending_command == CMD_GTODOTDOT) || (pending_command == CMD_RTN)) */ /* NOTE: set_running(true) also ends INPUT mode, so commands that * cause program execution to start do not have to be handled here. */ /* input_length = 0; } if (pending_command == CMD_VMEXEC) { string_copy(reg_alpha, ®_alpha_length, pending_command_arg.val.text, pending_command_arg.length); goto do_run; } if (pending_command == CMD_RUN) { do_run: if ((flags.f.trace_print || flags.f.normal_print) && flags.f.printer_exists) print_command(pending_command, &pending_command_arg); pending_command = CMD_NONE; if (pc == -1) pc = 0; set_running(true); return (1); } if (pending_command == CMD_SST) { int cmd; arg_struct arg; oldpc = pc; if (pc == -1) pc = 0; get_next_command(&pc, &cmd, &arg, 1); if ((flags.f.trace_print || flags.f.normal_print) && flags.f.printer_exists) print_program_line(current_prgm, oldpc); mode_disable_stack_lift = false; set_running(true); error = cmdlist(cmd)->handler(&arg); set_running(false); } else { if ((flags.f.trace_print || flags.f.normal_print) && flags.f.printer_exists) print_command(pending_command, &pending_command_arg); mode_disable_stack_lift = false; error = cmdlist(pending_command)->handler(&pending_command_arg); } if (error == ERR_INTERRUPTIBLE) { shell_annunciators(-1, -1, -1, 1, -1, -1); return (1); } handle_error(error); pending_command = CMD_NONE; if (!mode_getkey) redisplay(); */ return ((mode_running && !mode_getkey) || (keybuf_head != keybuf_tail)); } /******************************************************************************** * FUNCTION: set_running * * Go to running mode and display it. * ********************************************************************************/ void set_running(bool state) { if (mode_running != state) { mode_running = state; shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, state); } if (state) { /* Cancel any pending INPUT command */ // input_length = 0; // mode_goose = -2; // prgm_highlight_row = 1; } } /******************************************************************************** * FUNCTION: stop_interruptible() * * Run programs. * ********************************************************************************/ void continue_running() { /* int error; while (!shell_wants_cpu()) { int cmd; arg_struct arg; oldpc = pc; if (pc == -1) pc = 0; else if (pc >= prgms[current_prgm].size) { pc = -1; set_running(false); return; } get_next_command(&pc, &cmd, &arg, 1); if (flags.f.trace_print && flags.f.printer_exists) print_program_line(current_prgm, oldpc); mode_disable_stack_lift = false; error = cmdlist(cmd)->handler(&arg); if (error == ERR_INTERRUPTIBLE) return; if (!handle_error(error)) return; if (mode_getkey) return; }*/ } /******************************************************************************** * FUNCTION: stop_interruptible() * * Stops current running function. * ********************************************************************************/ static void stop_interruptible() { int error = mode_interruptible(1); handle_error(error); mode_interruptible = NULL; if (mode_running) set_running(false); else shell_annunciators(ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, ANNVAL_UNCH, false); pending_command = CMD_NONE; redisplay(); } /******************************************************************************** * FUNCTION: handle_error() * ********************************************************************************/ static int handle_error(int error) { /* if (mode_running) { if (error == ERR_RUN) error = ERR_NONE; if (error == ERR_NONE || error == ERR_NO || error == ERR_YES || error == ERR_STOP) flags.f.stack_lift_disable = mode_disable_stack_lift; if (error == ERR_NO) { if (prgms[current_prgm].text[pc] != CMD_END) pc += get_command_length(current_prgm, pc); } else if (error == ERR_STOP) { if (pc >= prgms[current_prgm].size) pc = -1; set_running(false); return 0; } else if (error != ERR_NONE && error != ERR_YES) { if (flags.f.error_ignore) { flags.f.error_ignore = 0; return 1; } if (solve_active() && (error == ERR_OUT_OF_RANGE || error == ERR_DIVIDE_BY_0 || error == ERR_INVALID_DATA || error == ERR_STAT_MATH_ERROR)) { unwind_stack_until_solve(); error = return_to_solve(1); if (error == ERR_STOP) set_running(false); if (error == ERR_NONE || error == ERR_RUN || error == ERR_STOP) return 0; } pc = oldpc; display_error(error, 1); set_running(false); return 0; } return 1; } else if (pending_command == CMD_SST) { if (error == ERR_RUN) error = ERR_NONE; if (error == ERR_NONE || error == ERR_NO || error == ERR_YES || error == ERR_STOP) flags.f.stack_lift_disable = mode_disable_stack_lift; if (error == ERR_NO) { if (prgms[current_prgm].text[pc] != CMD_END) pc += get_command_length(current_prgm, pc); goto noerr; } else if (error == ERR_NONE || error == ERR_YES || error == ERR_STOP) { noerr: error = ERR_NONE; if (pc > prgms[current_prgm].size) pc = -1; } else { if (flags.f.error_ignore) { flags.f.error_ignore = 0; goto noerr; } if (solve_active() && (error == ERR_OUT_OF_RANGE || error == ERR_DIVIDE_BY_0 || error == ERR_INVALID_DATA || error == ERR_STAT_MATH_ERROR)) { unwind_stack_until_solve(); error = return_to_solve(1); if (error == ERR_NONE || error == ERR_RUN || error == ERR_STOP) goto noerr; } pc = oldpc; display_error(error, 1); } return 0; } else { if (error == ERR_RUN) { set_running(true); error = ERR_NONE; } if (error == ERR_NONE || error == ERR_NO || error == ERR_YES || error == ERR_STOP) flags.f.stack_lift_disable = mode_disable_stack_lift; else if (flags.f.error_ignore) { flags.f.error_ignore = 0; error = ERR_NONE; } if (error != ERR_NONE && error != ERR_STOP) display_error(error, 1); return 0; }*/ return (0); } --- NEW FILE: varmgr.h --- /* * $Id: varmgr.h,v 1.1 2009/09/24 21:16:09 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 _VARMGR_H_ #define _VARMGR_H_ #define MAX_LIST_LENGTH 13 #define MAX_EDIT_TITLE 30 #include "Skin.h" void history_popup(Skin *skin, void *hWnd) IFACE; TCHAR *history_action(Skin *skin, void *hWnd_p, void *hWnd_calc, int selection); void varmgr_popup(Skin *skin, void *hWnd, rpntype type); TCHAR *varmgr_action(int selection); void varmgr_listVar(Skin *skin, void *hWnd); void varmgr_listVar_action(TCHAR *text, void *hWnd_calc, bool saveasvar); void varmgr_popup_builtin(Skin *skin, void *hWnd); TCHAR *varmgr_builtinAction(int selection); bool varmgr_getVarDef (TCHAR *varname, TCHAR **varDef); bool varmgr_getFctDef (TCHAR *fctname, TCHAR **fctDef, TCHAR *fctParam); 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 --- NEW FILE: ansops.h --- /* * $Id: ansops.h,v 1.1 2009/09/24 21:16:09 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 _ANSOPS_H_ #define _ANSOPS_H_ void ans_guess(Skin *skin, void *hdc) IFACE; void ans_redisplay(Skin *skin, void *hdc, TCHAR *text) IFACE; #endif --- NEW FILE: prefs.h --- /* * $Id: prefs.h,v 1.1 2009/09/24 21:16:09 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 _PREFS_H_ #define _PREFS_H_ #include "segment.h" //#include "calcrsc.h" #include "konvert.h" #include "defuns.h" #include "display.h" // Coming from calcrsc.h #define MAX_INPUT_LENGTH 1000 #define MAX_WORKSHEET_TITLE 32 #define MAX_WORKSHEET_NOTE 300 #define MAX_WORKSHEET_HELP 39 typedef struct { UInt16 form; /* last form */ UInt16 btnRow; /* Selected btnrow on scientific form */ UInt16 insertPos; /* last insert position */ UInt16 selPosStart, selPosEnd; Boolean finBegin; /* Begin/end selector in financial form */ Boolean matchParenth; /* Add ')' to functions ending with '(' */ Ttrigo_mode trigo_mode; TdispPrefs dispPrefs; Boolean insertHelp; /* Insert help strings where appropriate */ Boolean acceptPalmPref; /* Accept Palm settings about number formatting */ Boolean reducePrecision; Boolean dispScien; Int16 solverWorksheet; TCHAR input[MAX_INPUT_LENGTH+1]; }tPrefs; void prefs_read_preferences() IFACE; void prefs_save_preferences() IFACE; //Boolean PreferencesHandleEvent(EventPtr event) IFACE; extern tPrefs calcPrefs; #endif --- NEW FILE: varmgr.cpp --- /* * $Id: varmgr.cpp,v 1.1 2009/09/24 21:16:09 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 <LstGlue.h> //#include <WinGlue.h> #include "konvert.h" #include "calcDB.h" #include "display.h" #include "varmgr.h" //#include "calcrsc.h" #include "stack.h" //#include "calc.h" #include "core/core_display.h" #include "funcs.h" #include "history.h" #include "defuns.h" #include "main.h" #include "EasyCalc.h" #ifdef HANDERA_SDK #include "Vga.h" #endif #ifdef SUPPORT_DIA #include "DIA.h" #endif /*********************************************************************** * * FUNCTION: history_popup * * DESCRIPTION: Displays a history list popup. * * PARAMETERS: hWnd is a pointer at an OS specific structure describing * the history popup list object. * * RETURN: Nothing * ***********************************************************************/ void history_popup (Skin *skin, void *hWnd) { int i; int numitems; bool isrpn; Trpn item; TCHAR *text; numitems = history_total(); for (i=0 ; i<numitems ; i++) { isrpn = history_isrpn(i); if (isrpn) { item = history_get_item(i); text = display_default(item,false); rpn_delete(item); } else { text = history_get_line(i); } skin->historyAddActionPopup(text, hWnd); MemPtrFree(text); } } /*********************************************************************** * * FUNCTION: history_action * * DESCRIPTION: Execute action from the history popup dialog. * * PARAMETERS: hWnd_p OS specific handle to the dialog window * hWnd_calc OS specific handle to the calculator window * * RETURN: None * ***********************************************************************/ TCHAR *history_action(Skin *skin, void *hWnd_p, void *hWnd_calc, int selection) { TCHAR *result = NULL; // Execute the action if (history_isrpn(selection)) { Trpn item = history_get_item(selection); result = display_default(item,true); rpn_delete(item); if (_tcslen(result) > 25) StrPrintF(result,_T("history(%d)"),selection); } else result = history_get_line(selection); return (result); } /*********************************************************************** * * FUNCTION: varmgr_popup * * DESCRIPTION: Popups a menu with list of variables/functions * and their values * * PARAMETERS: hWnd is a pointer at an OS specific structure describing * the popup list object. * type is the type of what to display. * * RETURN: Name of selected variable/function or NULL * ***********************************************************************/ static dbList *varlist; static TCHAR **values; void varmgr_popup(Skin *skin, void *hWnd, rpntype type) { Trpn item; ... [truncated message content] |
From: Mapi B. <ma...@us...> - 2009-09-24 21:15:38
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14137 Modified Files: DataManager.cpp PalmOS.h Added Files: PalmOS.cpp Log Message: Subset of the code, compiling, but not yet linking Index: PalmOS.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/PalmOS.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PalmOS.h 6 Aug 2009 21:41:01 -0000 1.4 --- PalmOS.h 24 Sep 2009 21:15:27 -0000 1.5 *************** *** 70,74 **** #define SysRandom(x) (srand(x), rand()) #define sysRandomMax RAND_MAX ! unsigned long nan[2]={0xffffffff, 0x7fffffff}; #define NaN (*((double *) nan)) --- 70,74 ---- #define SysRandom(x) (srand(x), rand()) #define sysRandomMax RAND_MAX ! extern unsigned long nan[]; #define NaN (*((double *) nan)) *************** *** 77,81 **** ! #define ErrFatalDisplayIf(a,b) #define SYS_TRAP(a) --- 77,81 ---- ! void ErrFatalDisplayIf(int cond, TCHAR *msg); // Declared in Easycalc.cpp #define SYS_TRAP(a) --- NEW FILE: PalmOS.cpp --- /***************************************************************************** * EasyCalc -- a scientific calculator * Copyright (C) 2008 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2, * as published by the Free Software Foundation. * * 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 *****************************************************************************/ #include "StdAfx.h" unsigned long nan[2]={0xffffffff, 0x7fffffff}; Index: DataManager.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DataManager.cpp 6 Aug 2009 21:41:00 -0000 1.2 --- DataManager.cpp 24 Sep 2009 21:15:27 -0000 1.3 *************** *** 550,556 **** // Insert in the array if (i+1 < num) { ! memcpy (dbP->sortArray+i+1, ! dbP->sortArray+i, ! (num-i-1) * sizeof(DataRecord **)); } dbP->sortArray[i] = temp; --- 550,556 ---- // Insert in the array if (i+1 < num) { ! memmove (dbP->sortArray+i+1, ! dbP->sortArray+i, ! (num-i-1) * sizeof(DataRecord **)); } dbP->sortArray[i] = temp; |
From: Mapi B. <ma...@us...> - 2009-09-24 21:14:11
|
Update of /cvsroot/easycalc/PPCport In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13858 Modified Files: EasyCalc.vcproj Log Message: Subset of the code, compiling, but not yet linking Index: EasyCalc.vcproj =================================================================== RCS file: /cvsroot/easycalc/PPCport/EasyCalc.vcproj,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** EasyCalc.vcproj 6 Aug 2009 21:40:37 -0000 1.6 --- EasyCalc.vcproj 24 Sep 2009 21:14:00 -0000 1.7 *************** *** 380,399 **** UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" > - <File - RelativePath=".\core_main.cpp" - > - </File> - <File - RelativePath=".\Main.cpp" - > - </File> <Filter Name="system - UI" > <File - RelativePath=".\system - UI\core_display.cpp" - > - </File> - <File RelativePath=".\system - UI\EasyCalc.cpp" > --- 380,387 ---- *************** *** 452,458 **** --- 440,470 ---- > <File + RelativePath=".\core\ansops.cpp" + > + </File> + <File + RelativePath=".\core\core_display.cpp" + > + </File> + <File RelativePath=".\core\core_globals.cpp" > </File> + <File + RelativePath=".\core\core_main.cpp" + > + </File> + <File + RelativePath=".\core\defmgr.cpp" + > + </File> + <File + RelativePath=".\core\Main.cpp" + > + </File> + <File + RelativePath=".\core\varmgr.cpp" + > + </File> <Filter Name="mlib" *************** *** 475,478 **** --- 487,494 ---- </File> <File + RelativePath=".\core\mlib\guess.cpp" + > + </File> + <File RelativePath=".\core\mlib\history.cpp" > *************** *** 512,515 **** --- 528,535 ---- </File> <File + RelativePath=".\compat\PalmOS.cpp" + > + </File> + <File RelativePath=".\compat\Preferences.cpp" > *************** *** 523,538 **** > <File - RelativePath=".\ansops.h" - > - </File> - <File RelativePath=".\chkstack.h" > </File> <File - RelativePath=".\core_main.h" - > - </File> - <File RelativePath=".\core_tables.h" > --- 543,550 ---- *************** *** 542,557 **** > </File> - <File - RelativePath=".\Main.h" - > - </File> - <File - RelativePath=".\prefs.h" - > - </File> - <File - RelativePath=".\varmgr.h" - > - </File> <Filter Name="include" --- 554,557 ---- *************** *** 570,577 **** </File> <File - RelativePath=".\include\defuns.h" - > - </File> - <File RelativePath=".\include\integ.h" > --- 570,573 ---- *************** *** 610,617 **** > <File - RelativePath=".\system - UI\core_display.h" - > - </File> - <File RelativePath=".\system - UI\EasyCalc.h" > --- 606,609 ---- *************** *** 674,680 **** --- 666,700 ---- > <File + RelativePath=".\core\ansops.h" + > + </File> + <File + RelativePath=".\core\core_display.h" + > + </File> + <File RelativePath=".\core\core_globals.h" > </File> + <File + RelativePath=".\core\core_main.h" + > + </File> + <File + RelativePath=".\core\defmgr.h" + > + </File> + <File + RelativePath=".\core\Main.h" + > + </File> + <File + RelativePath=".\core\prefs.h" + > + </File> + <File + RelativePath=".\core\varmgr.h" + > + </File> <Filter Name="mlib" *************** *** 685,688 **** --- 705,712 ---- </File> <File + RelativePath=".\core\mlib\defuns.h" + > + </File> + <File RelativePath=".\core\mlib\display.h" > |
Update of /cvsroot/easycalc/PPCport In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv13758 Removed Files: ansops.h calcrsc.h core_main.cpp core_main.h Main.cpp Main.h prefs.h test.txt varmgr.h Log Message: Subset of the code, compiling, but not yet linking --- Main.cpp DELETED --- --- core_main.h DELETED --- --- core_main.cpp DELETED --- --- varmgr.h DELETED --- --- calcrsc.h DELETED --- --- ansops.h DELETED --- --- prefs.h DELETED --- --- Main.h DELETED --- --- test.txt DELETED --- |
From: Mapi B. <ma...@us...> - 2009-08-06 21:43:25
|
Update of /cvsroot/easycalc/PPCport In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv23301 Modified Files: EasyCalc.vcproj.CLIENT5.Admin.user Log Message: More complex DataManager, and some other updates |
From: Mapi B. <ma...@us...> - 2009-08-06 21:43:10
|
Update of /cvsroot/easycalc/PPCport/system - UI In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv23077 Modified Files: Skin.cpp Skin.h Log Message: More complex DataManager, and some other updates |
From: Mapi B. <ma...@us...> - 2009-08-06 21:42:19
|
Update of /cvsroot/easycalc/PPCport/system - UI In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22687 Modified Files: StateManager.h Log Message: More complex DataManager, and some other updates Index: StateManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/system - UI/StateManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StateManager.h 22 Jun 2009 22:13:35 -0000 1.1 --- StateManager.h 6 Aug 2009 21:42:06 -0000 1.2 *************** *** 30,33 **** --- 30,34 ---- int4 version; DataManager historyDB; + DataManager calcDB; StateManager(void); |
From: Mapi B. <ma...@us...> - 2009-08-06 21:41:58
|
Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22454 Modified Files: calcDB.cpp Log Message: More complex DataManager, and some other updates Index: calcDB.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/calcDB.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** calcDB.cpp 5 Jul 2009 20:53:37 -0000 1.2 --- calcDB.cpp 6 Aug 2009 21:41:40 -0000 1.3 *************** *** 183,187 **** dbPackedRecord *record; dbPackedStack *pstack; ! UInt16 psize,rsize; TCHAR *ptr; CError err; --- 183,187 ---- dbPackedRecord *record; dbPackedStack *pstack; ! Int16 psize,rsize; TCHAR *ptr; CError err; *************** *** 467,471 **** dbPackedRecord *result; ! result = MemPtrNew(MemHandleSize(theRecordMemHandle)); if (result) memcpy(result,record,MemHandleSize(theRecordMemHandle)); --- 467,471 ---- dbPackedRecord *result; ! result = (dbPackedRecord *) MemPtrNew(MemHandleSize(theRecordMemHandle)); if (result) memcpy(result,record,MemHandleSize(theRecordMemHandle)); |
From: Mapi B. <ma...@us...> - 2009-08-06 21:41:33
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22333 Added Files: MemoryManager.cpp MemoryManager.h Log Message: More complex DataManager, and some other updates --- NEW FILE: MemoryManager.h --- #pragma once #ifndef MEM_MANAGER_H #define MEM_MANAGER_H 1 #include "PalmOS.h" typedef void *MemPtr; class c_MemHandle { public: // int size; void *memPtr; int lock; c_MemHandle(void); ~c_MemHandle(void); int serialize(FILE *f); int deSerialize(FILE *f); }; typedef c_MemHandle *MemHandle; #define MemPtrNew malloc #define MemPtrFree free MemHandle MemHandleNew (UInt32 size); Err MemHandleFree (MemHandle h); MemPtr MemHandleLock (MemHandle h); Err MemHandleUnlock (MemHandle h); UInt32 MemHandleSize (MemHandle h); Err MemHandleResize (MemHandle h, UInt32 newSize); #endif --- NEW FILE: MemoryManager.cpp --- #include "StdAfx.h" #include "compat/PalmOS.h" #include "MemoryManager.h" c_MemHandle::c_MemHandle(void) { // size = 0; memPtr = NULL; lock = 0; } c_MemHandle::~c_MemHandle(void) { if (memPtr != NULL) free(memPtr); } /*********************************************************************** * Store the c_MemHandle object to a file, in binary mode. ***********************************************************************/ int c_MemHandle::serialize(FILE *f) { // size = 0; if (fwrite(&memPtr, sizeof(memPtr), 1, f) != 1) return (-1); if (fwrite(&lock, sizeof(lock), 1, f) != 1) return (-1); if (memPtr != 0) { size_t siz = _msize(memPtr); if (fwrite(&siz, sizeof(siz), 1, f) != 1) return (-1); if (fwrite(memPtr, siz, 1, f) != 1) return (-1); } return (0); } /*********************************************************************** * Retrieve the c_MemHandle object from a file, in binary mode. ***********************************************************************/ int c_MemHandle::deSerialize(FILE *f) { // size = 0; if (fread(&memPtr, sizeof(memPtr), 1, f) != 1) return (-1); if (fread(&lock, sizeof(lock), 1, f) != 1) return (-1); if (memPtr != 0) { size_t siz; if (fread(&siz, sizeof(siz), 1, f) != 1) return (-1); memPtr = malloc(siz); if (fread(memPtr, siz, 1, f) != 1) return (-1); } return (0); } MemHandle MemHandleNew (UInt32 size) { MemHandle h = new c_MemHandle; if (h != NULL) { if ((h->memPtr = malloc(size)) != NULL) { // h->size = size; } else { delete h; h = NULL; } } return (h); } Err MemHandleFree (MemHandle h) { delete h; return (0); } MemPtr MemHandleLock (MemHandle h) { h->lock++; return (h->memPtr); } Err MemHandleUnlock (MemHandle h) { if (h->lock > 0) h->lock--; return (0); } UInt32 MemHandleSize (MemHandle h) { if (h->memPtr == NULL) return (0); else return (_msize(h->memPtr)); } Err MemHandleResize (MemHandle h, UInt32 newSize) { if (h->lock > 0) return (-1); h->memPtr = realloc(h->memPtr, newSize); if ((newSize != 0) && (h->memPtr == NULL)) return (-2); return (0); } |
From: Mapi B. <ma...@us...> - 2009-08-06 21:41:12
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22113 Modified Files: DataManager.cpp DataManager.h PalmOS.h Log Message: More complex DataManager, and some other updates Index: PalmOS.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/PalmOS.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PalmOS.h 5 Jul 2009 20:52:48 -0000 1.3 --- PalmOS.h 6 Aug 2009 21:41:01 -0000 1.4 *************** *** 42,53 **** #define StrPrintF _stprintf #define StrIToA(s,i) _itot(i,s,10) ! #define MemPtrNew malloc ! #define MemPtrFree free ! typedef void *MemHandle; typedef void *WinHandle; typedef void *ListPtr; - #define MemHandleLock(a) ((MemHandle) a) - #define MemHandleUnlock(a) #define noListSelection -1 --- 42,52 ---- #define StrPrintF _stprintf #define StrIToA(s,i) _itot(i,s,10) + // No _tcsicoll / _wcsicoll /_stricoll in MSVC for Pocket PC unfortunately, + // so for now, using _tcsicmp. + #define StrCaselessCompare _tcsicmp ! #include "MemoryManager.h" typedef void *WinHandle; typedef void *ListPtr; #define noListSelection -1 Index: DataManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** DataManager.h 5 Jul 2009 20:52:48 -0000 1.2 --- DataManager.h 6 Aug 2009 21:41:01 -0000 1.3 *************** *** 5,8 **** --- 5,9 ---- #include "PalmOS.h" + #include <stdio.h> #define dmModeReadWrite 1 *************** *** 14,25 **** UInt32 magic; UInt32 size; ! char *ptr; DataRecord *next; DataRecord(void); ! DataRecord(UINT32 s, void *p, DataRecord *n); ~DataRecord(void); }; class DataManager { public: --- 15,41 ---- UInt32 magic; UInt32 size; ! int num; ! MemHandle h; DataRecord *next; DataRecord(void); ! DataRecord(UINT32 s, MemHandle p, DataRecord *n); ~DataRecord(void); + int serialize(FILE *f); + int deSerialize(FILE *f); }; + typedef struct { + UInt8 attributes; + UInt8 uniqueID[3]; + } SortRecordInfoType; + + typedef SortRecordInfoType *SortRecordInfoPtr; + + typedef Int16 DmComparF (void *rec1, void *rec2, Int16 other, + SortRecordInfoPtr rec1SortInfo, + SortRecordInfoPtr rec2SortInfo, + MemHandle appInfoH); + class DataManager { public: *************** *** 31,51 **** UInt16 numRecords; DataRecord *head; DataManager(void); ~DataManager(void); }; - typedef struct { - UInt8 attributes; - UInt8 uniqueID[3]; - } SortRecordInfoType; - - typedef SortRecordInfoType *SortRecordInfoPtr; - - typedef DataManager *DmOpenRef; typedef void *LocalID; ! void registerDmDatabase (UINT16 cardNo, const TCHAR *nameP, LocalID dbId); LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP); --- 47,63 ---- UInt16 numRecords; DataRecord *head; + DataRecord **sortArray; // To support binary searches in DmFindSortPosition + TCHAR *name; DataManager(void); ~DataManager(void); + int serialize(FILE *f); + int deSerialize(FILE *f); }; typedef DataManager *DmOpenRef; typedef void *LocalID; ! void registerDmDatabase (UINT16 cardNo, const TCHAR *nameP, DataManager *dbId); LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP); *************** *** 66,72 **** --- 78,88 ---- UInt16 DmNumRecords (DmOpenRef dbP); MemHandle DmNewRecord (DmOpenRef dbP, UInt16 *atP, UInt32 size); + MemHandle DmGetRecord (DmOpenRef dbP, UInt16 index); Err DmWrite (void *recordP, UInt32 offset, const void *srcP, UInt32 bytes); Err DmRemoveRecord (DmOpenRef dbP, UInt16 index); MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index); + UInt16 DmFindSortPosition (DmOpenRef dbP, void *newRecord, SortRecordInfoPtr newRecordInfo, + DmComparF *compar, Int16 other); + //Err DmReleaseRecord (DmOpenRef dbP, UInt16 index, Boolean dirty); Index: DataManager.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DataManager.cpp 22 Jun 2009 21:57:16 -0000 1.1 --- DataManager.cpp 6 Aug 2009 21:41:00 -0000 1.2 *************** *** 12,70 **** numRecords = 0; head = NULL; } DataManager::~DataManager(void) { } ! static DataManager *stateMgrHistDB; // This one comes from EasyCalc.cpp ! void registerDmDatabase (UINT16 cardNo, const TCHAR *nameP, LocalID dbId) { ! stateMgrHistDB = (DataManager *) dbId; } LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP) { ! return ((LocalID) stateMgrHistDB); } ! int DmDatabaseInfo ( ! UINT16 cardNo, ! LocalID dbID, ! TCHAR *nameP, ! UINT16 *attributesP, ! UINT16 *versionP, ! UINT32 *crDateP, ! UINT32 *modDateP, ! UINT32 *bckUpDateP, ! UINT32 *modNumP, ! LocalID *appInfoIDP, ! LocalID *sortInfoIDP, ! UINT32 *typeP, ! UINT32 *creatorP) { ! if (dbID == (LocalID) stateMgrHistDB) { ! *attributesP = stateMgrHistDB->attr; ! *versionP = (UINT16) (stateMgrHistDB->version); ! *typeP = stateMgrHistDB->type; ! *creatorP = stateMgrHistDB->creator; } ! return (0); } ! int DmSetDatabaseInfo ( ! UINT16 cardNo, ! LocalID dbID, ! const TCHAR *nameP, ! UINT16 *attributesP, ! UINT16 *versionP, ! UINT32 *crDateP, ! UINT32 *modDateP, ! UINT32 *bckUpDateP, ! UINT32 *modNumP, ! LocalID appInfoIDP, ! LocalID sortInfoIDP, ! UINT32 *typeP, ! UINT32 *creatorP) { if (dbID == (LocalID) stateMgrHistDB) { stateMgrHistDB->attr = *attributesP; stateMgrHistDB->version = *versionP; } return (0); --- 12,231 ---- numRecords = 0; head = NULL; + sortArray = NULL; + name = NULL; } DataManager::~DataManager(void) { + if (head != NULL) { + // Free all records in the DB + DataRecord *temp; + do { + temp = head->next; + MemHandleFree(head->h); + delete head; + head = temp; + } while (temp != NULL); + } + if (sortArray != NULL) free(sortArray); + if (name != NULL) free(name); } ! /*********************************************************************** ! * Store the DataManager object to a file, in binary mode. ! ***********************************************************************/ ! int DataManager::serialize(FILE *f) { ! // Save previous file mode for restoring later. ! int prev_mode = _setmode(f, _O_BINARY); ! // Save object itself ! if (fwrite(&in_state, sizeof(in_state), 1, f) != 1) ! return (-1); ! if (fwrite(&attr, sizeof(attr), 1, f) != 1) ! return (-1); ! if (fwrite(&type, sizeof(type), 1, f) != 1) ! return (-1); ! if (fwrite(&creator, sizeof(creator), 1, f) != 1) ! return (-1); ! if (fwrite(&version, sizeof(version), 1, f) != 1) ! return (-1); ! if (fwrite(&numRecords, sizeof(numRecords), 1, f) != 1) ! return (-1); ! if (fwrite(&head, sizeof(head), 1, f) != 1) ! return (-1); ! if (fwrite(&sortArray, sizeof(sortArray), 1, f) != 1) ! return (-1); ! if (fwrite(&name, sizeof(name), 1, f) != 1) ! return (-1); ! ! // Save elements pointed at by the object. ! // First, the name ! if (name != NULL) { ! size_t siz = _msize(name); ! if (fwrite(&siz, sizeof(siz), 1, f) != 1) ! return (-1); ! if (fwrite(name, siz, 1, f) != 1) ! return (-1); ! } ! // Then, the records, numbering them ! int num = 0; ! if (head != NULL) { ! DataRecord *temp = head; ! while (temp != NULL) { ! temp->num = num++; ! if (temp->serialize(f) != 0) ! return (-1); ! temp = temp->next; ! } ! } ! // And last, the sort array. Save record numbers instead of addresses, ! // for rebuild at read. ! if (sortArray != NULL) { ! // size_t siz = _msize(sortArray); ! // if (fwrite(&siz, sizeof(siz), 1, f) != 1) ! // return (-1); ! // if (fwrite(sortArray, siz, 1, f) != 1) ! // return (-1); ! size_t siz = num * sizeof(int); ! if (fwrite(&siz, sizeof(siz), 1, f) != 1) ! for (int i=0 ; i<num ; i++) { ! if (fwrite(&(sortArray[i]->num), sizeof(int), 1, f) != 1) ! return (-1); ! } ! } ! ! // Restore previous file mode. ! _setmode(f, prev_mode); ! ! return (0); ! } ! ! /*********************************************************************** ! * Retrieve the DataManager object from a file, in binary mode. ! ***********************************************************************/ ! int DataManager::deSerialize(FILE *f) { ! // Save previous file mode for restoring later. ! int prev_mode = _setmode(f, _O_BINARY); ! ! // Load object itself ! if (fread(&in_state, sizeof(in_state), 1, f) != 1) ! return (-1); ! if (fread(&attr, sizeof(attr), 1, f) != 1) ! return (-1); ! if (fread(&type, sizeof(type), 1, f) != 1) ! return (-1); ! if (fread(&creator, sizeof(creator), 1, f) != 1) ! return (-1); ! if (fread(&version, sizeof(version), 1, f) != 1) ! return (-1); ! if (fread(&numRecords, sizeof(numRecords), 1, f) != 1) ! return (-1); ! if (fread(&head, sizeof(head), 1, f) != 1) ! return (-1); ! if (fread(&sortArray, sizeof(sortArray), 1, f) != 1) ! return (-1); ! if (fread(&name, sizeof(name), 1, f) != 1) ! return (-1); ! ! // Load elements pointed at by the object. ! // First, the name ! if (name != NULL) { ! size_t siz; ! if (fread(&siz, sizeof(siz), 1, f) != 1) ! return (-1); ! name = (TCHAR *) malloc(siz); ! if (fread(name, siz, 1, f) != 1) ! return (-1); ! } ! // Then, numbered records, storing their allocated address ! DataRecord **listArray = (DataRecord **) malloc (numRecords * sizeof(DataRecord *)); ! if (head != NULL) { ! DataRecord *temp1 = NULL, *temp2; ! for (int i=0 ; i<numRecords ; i++) { ! temp2 = new DataRecord; ! if (temp2->deSerialize(f) != 0) ! return (-1); ! // Remember its address by index ! listArray[temp2->num] = temp2; ! if (temp1 == NULL) { ! head = temp1 = temp2; ! } else { ! temp1->next = temp2; ! temp1 = temp2; ! } ! } ! } ! // And last, the sort array. Record numbers have been saved instead of addresses. ! if (sortArray != NULL) { ! size_t siz; ! if (fread(&siz, sizeof(siz), 1, f) != 1) ! return (-1); ! // sortArray = (DataRecord **) malloc(siz); ! // if (fread(sortArray, siz, 1, f) != 1) ! // return (-1); ! sortArray = (DataRecord **) malloc(numRecords * sizeof(DataRecord **)); ! int index; ! for (int i=0 ; i<numRecords ; i++) { ! if (fwrite(&index, sizeof(int), 1, f) != 1) ! return (-1); ! // We got the record number, now convert it to its allocated ! // address in memory. ! sortArray[i] = listArray[index]; ! } ! } ! free (listArray); ! ! // Restore the previous file mode. ! _setmode(f, prev_mode); ! ! return (0); ! } ! ! static DataManager *stateMgrDB = NULL; // This one comes from CalcDB.cpp ! static DataManager *stateMgrHistDB = NULL; // This one comes from EasyCalc.cpp ! ! void registerDmDatabase (UINT16 cardNo, const TCHAR *nameP, DataManager *dbId) { ! if (wcscmp (nameP, HISTORYDBNAME) == 0) { ! stateMgrHistDB = (DataManager *) dbId; ! } else if (wcscmp (nameP, DBNAME) == 0) { ! stateMgrDB = (DataManager *) dbId; ! } } LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP) { ! LocalID dbId = NULL; ! if (wcscmp (nameP, HISTORYDBNAME) == 0) { ! dbId = (LocalID) stateMgrHistDB; ! } else if (wcscmp (nameP, DBNAME) == 0) { ! dbId = (LocalID) stateMgrDB; ! } ! return (dbId); } ! int DmDatabaseInfo (UINT16 cardNo, LocalID dbID, TCHAR *nameP, UINT16 *attributesP, ! UINT16 *versionP, UINT32 *crDateP, UINT32 *modDateP, UINT32 *bckUpDateP, ! UINT32 *modNumP, LocalID *appInfoIDP, LocalID *sortInfoIDP, ! UINT32 *typeP, UINT32 *creatorP) { ! int rc = -1; ! DataManager *db = (DataManager *) dbID; ! if ((db == stateMgrHistDB) || (db == stateMgrDB)) { ! *attributesP = db->attr; ! *versionP = (UINT16) (db->version); ! *typeP = db->type; ! *creatorP = db->creator; ! rc = 0; } ! return (rc); } ! int DmSetDatabaseInfo (UINT16 cardNo, LocalID dbID, const TCHAR *nameP, UINT16 *attributesP, ! UINT16 *versionP, UINT32 *crDateP, UINT32 *modDateP, UINT32 *bckUpDateP, ! UINT32 *modNumP, LocalID appInfoIDP, LocalID sortInfoIDP, ! UINT32 *typeP, UINT32 *creatorP) { if (dbID == (LocalID) stateMgrHistDB) { stateMgrHistDB->attr = *attributesP; stateMgrHistDB->version = *versionP; + } else if (dbID == (LocalID) stateMgrDB) { + stateMgrDB->attr = *attributesP; + stateMgrDB->version = *versionP; } return (0); *************** *** 74,77 **** --- 235,240 ---- if (dbID == (LocalID) stateMgrHistDB) { return (stateMgrHistDB); + } else if (dbID == (LocalID) stateMgrDB) { + return (stateMgrDB); } return (NULL); *************** *** 82,96 **** } ! int DmCreateDatabase ( ! UINT16 cardNo, ! const TCHAR *nameP, ! UINT32 creator, ! UINT32 type, ! bool resDB) { if (wcscmp (nameP, HISTORYDBNAME) == 0) { stateMgrHistDB->creator = creator; stateMgrHistDB->type = type; } ! return (0); } --- 245,271 ---- } ! int DmCreateDatabase (UINT16 cardNo, const TCHAR *nameP, UINT32 creator, ! UINT32 type, bool resDB) { ! int rc = 0; if (wcscmp (nameP, HISTORYDBNAME) == 0) { + if (stateMgrHistDB == NULL) + stateMgrHistDB = new DataManager; stateMgrHistDB->creator = creator; stateMgrHistDB->type = type; + int l = _tcslen(nameP); + stateMgrDB->name = (TCHAR *) malloc(2*l+1); + _tcscpy (stateMgrDB->name, nameP); + rc = 0; + } else if (wcscmp (nameP, DBNAME) == 0) { + if (stateMgrHistDB == NULL) + stateMgrDB = new DataManager; + stateMgrDB->creator = creator; + stateMgrDB->type = type; + int l = _tcslen(nameP); + stateMgrDB->name = (TCHAR *) malloc(2*l+1); + _tcscpy (stateMgrDB->name, nameP); + rc = 0; } ! return (rc); } *************** *** 100,103 **** --- 275,284 ---- int DmDeleteDatabase (UINT16 cardNo, LocalID dbID) { + DataManager *db = (DataManager *) dbID; + if ((db == stateMgrHistDB) || (db == stateMgrDB)) { + if (db == stateMgrHistDB) stateMgrHistDB = NULL; + else stateMgrDB = NULL; + delete db; + } return (0); } *************** *** 108,145 **** MemHandle DmNewRecord (DmOpenRef dbP, UInt16 *atP, UInt32 size) { ! if (dbP == stateMgrHistDB) { ! char *p = (char *) malloc ((size+8) & 0xFFFFFFFC); // Add 4 bytes, round up to next 4 bytes limit ! if (p == NULL) return (NULL); ! DataRecord *prec = NULL; ! DataRecord *temp = stateMgrHistDB->head; ! if (*atP > stateMgrHistDB->numRecords) *atP = stateMgrHistDB->numRecords; ! for (int i=0 ; (i<*atP) && (temp != NULL) ; i++) temp = (prec = temp)->next; ! stateMgrHistDB->numRecords++; ! if (prec == NULL) { // Insert at head ! temp = stateMgrHistDB->head = new DataRecord(size, p, stateMgrHistDB->head); ! } else { ! temp = prec->next = new DataRecord(size, p, temp); } - // Put the father record address at beginning of the allocated space - *((UInt32 *) p) = (UInt32) temp; - return (p+4); } ! return (NULL); } Err DmRemoveRecord (DmOpenRef dbP, UInt16 index) { ! if (dbP == stateMgrHistDB) { DataRecord *prec = NULL; ! DataRecord *temp = stateMgrHistDB->head; ! if (index >= stateMgrHistDB->numRecords) return (-1); ! for (int i=0 ; (i<index) && (temp != NULL) ; i++) temp = (prec = temp)->next; ! stateMgrHistDB->numRecords--; if (prec == NULL) { // Delete at head ! stateMgrHistDB->head = stateMgrHistDB->head->next; } else { prec->next = temp->next; } ! free (temp->ptr); delete temp; return (0); --- 289,397 ---- MemHandle DmNewRecord (DmOpenRef dbP, UInt16 *atP, UInt32 size) { ! MemHandle p = NULL; ! if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { ! // Add 4 bytes, round up to next 4 bytes limit ! // char *p = (char *) malloc ((size+8) & 0xFFFFFFFC); ! if ((p = MemHandleNew((size+8) & 0xFFFFFFFC)) != NULL) { ! DataRecord *prec = NULL; ! DataRecord *temp = dbP->head; ! if (*atP > dbP->numRecords) ! *atP = dbP->numRecords; ! dbP->numRecords++; ! // Locate the records around the one to insert ! if (dbP->sortArray == NULL) { // No sort array to maintain, and no direct access ! for (int i=0 ; (i<*atP)&&(temp!=NULL) ; i++) ! temp = (prec = temp)->next; ! } else { // Maintain the sort array in sync ! DataRecord **destArray = (DataRecord **) malloc(dbP->numRecords * sizeof(DataRecord **)); ! if (*atP > 0) { ! memcpy (destArray, ! dbP->sortArray, ! *atP * sizeof(DataRecord **)); ! prec = dbP->sortArray[*atP-1]; ! } ! if (1 < dbP->numRecords - *atP) { ! memcpy (destArray+*atP+1, ! dbP->sortArray+*atP, ! (dbP->numRecords-*atP-1) * sizeof(DataRecord **)); ! temp = dbP->sortArray[*atP]; ! } else ! temp = NULL; // Insert at end. ! // Switch sortArray to the new allocated array ! free(dbP->sortArray); ! dbP->sortArray = destArray; ! } ! if (prec == NULL) { // Insert at head ! temp = dbP->head = new DataRecord(size, p, dbP->head); ! } else { ! temp = prec->next = new DataRecord(size, p, temp); ! } ! // Put the metadata DataRecord address in the allocated memory ! *((UInt32 *) p->memPtr) = (UInt32) temp; ! // And update the new sortArray entry with the new DataRecord address, if needed ! if (dbP->sortArray != NULL) { ! dbP->sortArray[*atP] = temp; ! } ! } ! } ! return (p); ! } ! MemHandle DmGetRecord (DmOpenRef dbP, UInt16 index) { ! MemHandle p = NULL; ! if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { ! DataRecord *temp = dbP->head; ! // Find the record ! if (dbP->sortArray == NULL) { // No sort array, no direct access ! if (index < dbP->numRecords) { ! for (int i=0 ; i<index ; i++) ! temp = temp->next; ! p = temp->h; ! } ! } else { // Direct access ! p = dbP->sortArray[(int)index]->h; } } ! return (p); } Err DmRemoveRecord (DmOpenRef dbP, UInt16 index) { ! if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { DataRecord *prec = NULL; ! DataRecord *temp = dbP->head; ! if (index >= dbP->numRecords) ! return (-1); ! dbP->numRecords--; ! // Locate the record to delete ! if (dbP->sortArray == NULL) { // No sort array to maintain, and no direct access ! for (int i=0 ; (i<index)&&(temp!=NULL) ; i++) ! temp = (prec = temp)->next; ! } else { // Maintain the sort array in sync ! DataRecord **destArray = NULL; ! if (dbP->numRecords > 0) { // Do not allocate a new array if size is 0 ! destArray = (DataRecord **) malloc(dbP->numRecords * sizeof(DataRecord **)); ! if (index > 0) { ! memcpy (destArray, ! dbP->sortArray, ! index * sizeof(DataRecord **)); ! prec = dbP->sortArray[index-1]; ! } ! if (index < dbP->numRecords) { ! memcpy (destArray+index, ! dbP->sortArray+index+1, ! (dbP->numRecords-index) * sizeof(DataRecord **)); ! } ! temp = dbP->sortArray[index]; ! } ! // Switch sortArray to the new allocated array ! free(dbP->sortArray); ! dbP->sortArray = destArray; ! } if (prec == NULL) { // Delete at head ! dbP->head = dbP->head->next; } else { prec->next = temp->next; } ! MemHandleFree(temp->h); delete temp; return (0); *************** *** 148,156 **** } ! Err DmWrite ( ! void *recordP, ! UInt32 offset, ! const void *srcP, ! UInt32 bytes) { char *p = (char *) recordP; --- 400,404 ---- } ! Err DmWrite (void *recordP, UInt32 offset, const void *srcP, UInt32 bytes) { char *p = (char *) recordP; *************** *** 164,176 **** MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index) { ! if (dbP == stateMgrHistDB) { ! DataRecord *temp = stateMgrHistDB->head; ! if (index >= stateMgrHistDB->numRecords) return (NULL); for (int i=0 ; (i<index) && (temp != NULL) ; i++) temp = temp->next; ! return (temp->ptr+4); } return (NULL); } //Err DmReleaseRecord (DmOpenRef dbP, UInt16 index, Boolean dirty) { // return (0); --- 412,573 ---- MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index) { ! if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { ! DataRecord *temp = dbP->head; ! if (index >= dbP->numRecords) return (NULL); for (int i=0 ; (i<index) && (temp != NULL) ; i++) temp = temp->next; ! return (temp->h); } return (NULL); } + /*********************************************************** + * Binary search on a non empty sorted array. * + ***********************************************************/ + int binSearch (DataRecord **sortArray, int numRecords, + void *newRecord, SortRecordInfoPtr newRecordInfo, + DmComparF *compar, Int16 other) { + int i, imin, imax; + imax = numRecords - 1; + imin = 0; + int c; + + // First, initiate conditions on boundaries of the recurring algorithm + if (compar(newRecord, + sortArray[imax]->h->memPtr, + other, + NULL, // newRecordInfo, not used, so not implemented + NULL, // sortArray[imax]->, not used, so not implemented + NULL // Not used, so not implemented + ) >= 0) { + // After last one + i = numRecords; + } else if ((numRecords == 1) // First == last ! No need to redo the comparison. + || (c = compar(newRecord, + sortArray[0]->h->memPtr, + other, + NULL, // newRecordInfo, not used, so not implemented + NULL, // sortArray[0]->, not used, so not implemented + NULL // Not used, so not implemented + ) + ) < 0) { + // Before first one + i = 0; + } else if ((c == 0) // Matches with first one + || (numRecords == 2)) { // Optimization .. We know it's neither 0 or 1, + // but between them ... means insert at 1. + i = 1; + // If several with the same key, then insert after all of them + while ((i < imax) // We already compared with imax, and if we reach this point, + // we already know that they are not equal. + // And note: when numRecords == 2, imax is 1. + && (compar(newRecord, + sortArray[i]->h->memPtr, + other, + NULL, // newRecordInfo, not used, so not implemented + NULL, // sortArray[i]->, not used, so not implemented + NULL // Not used, so not implemented + ) == 0) + ) { + i++; + } + } else { // Regular condition as of now: somewhere between imin and imax, + // neither of them, and imax - imin > 1. + // This will be the recursive and propagated property. + bool found = false; + while (!found) { + // Get to the middle point of current scope + i = (imax + imin) >> 1; + c = compar(newRecord, + sortArray[i]->h->memPtr, + other, + NULL, // newRecordInfo, not used, so not implemented + NULL, // sortArray[i]->, not used, so not implemented + NULL // Not used, so not implemented + ); + if (c == 0) { + // If several with the same key, then insert after all of them + while ((i < numRecords) + && (compar(newRecord, + sortArray[i]->h->memPtr, + other, + NULL, // newRecordInfo, not used, so not implemented + NULL, // sortArray[i]->, not used, so not implemented + NULL // Not used, so not implemented + ) == 0) + ) { + i++; + } + found = true; + } else if (c < 0) { // Between imin and i, and neither of them. + // We didn't find it yet, but if scope is reduced to 0, + // we have found the place to insert. + if (i - imin <= 1) { + // Insert at i (i.e. it will shift i by 1) + found = true; + } else { + imax = i; + } + } else { // Between i and imax, and neither of them. + // We didn't find it yet, but if scope is reduced to 0, + // we have found the place to insert. + if (imax - i <= 1) { + // Insert at imax (i.e., just after i) + i = imax; + found = true; + } else { + imin = i; + } + } + } + } + + return (i); + } + + UInt16 DmFindSortPosition (DmOpenRef dbP, void *newRecord, SortRecordInfoPtr newRecordInfo, + DmComparF *compar, Int16 other) { + int i = -1; + if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { + // If DB is empty .. do nothing ! + if (dbP->numRecords == 0) + i = 0; + else { // There something in the DB to compare to + // If not yet sorted, then sort the DB + if (dbP->sortArray == NULL) { + // Allocate the sort array + dbP->sortArray = (DataRecord **) malloc(dbP->numRecords * sizeof(DataRecord **)); + // Then fill it by adding elements to it in a sorted manner. + // Add the first element from the list. + dbP->sortArray[0] = dbP->head; + // Add next elements of the linked list + int num = 1; + DataRecord *temp = dbP->head->next; + while (temp != NULL) { + // Find position + i = binSearch(dbP->sortArray, num, + newRecord, NULL, // newRecord Info is not used + compar, other); + // Insert in the array + if (i+1 < num) { + memcpy (dbP->sortArray+i+1, + dbP->sortArray+i, + (num-i-1) * sizeof(DataRecord **)); + } + dbP->sortArray[i] = temp; + + // Next element + num++; + temp = temp->next; + } + } + // Find the record by a binary search. + i = binSearch(dbP->sortArray, dbP->numRecords, + newRecord, newRecordInfo, + compar, other); + } + } + return (i); + } + //Err DmReleaseRecord (DmOpenRef dbP, UInt16 index, Boolean dirty) { // return (0); *************** *** 180,193 **** magic = RECORD_MAGIC; size = 0; ! ptr = NULL; next = NULL; } ! DataRecord::DataRecord(UINT32 s, void *p, DataRecord *n) { ! size = s; ! ptr = (char *) p; ! next = n; } DataRecord::~DataRecord(void) { ! } \ No newline at end of file --- 577,622 ---- magic = RECORD_MAGIC; size = 0; ! h = NULL; next = NULL; } ! DataRecord::DataRecord(UINT32 s, MemHandle p, DataRecord *n) { ! size = s; ! h = p; ! next = n; } DataRecord::~DataRecord(void) { ! } ! ! /*********************************************************************** ! * Store the DataRecord object to a file, in binary mode. ! ***********************************************************************/ ! int DataRecord::serialize(FILE *f) { ! if (fwrite(&magic, sizeof(magic), 1, f) != 1) ! return (-1); ! if (fwrite(&size, sizeof(size), 1, f) != 1) ! return (-1); ! if (fwrite(&num, sizeof(num), 1, f) != 1) ! return (-1); ! if (h->serialize(f) != 0) ! return (-1); ! ! return (0); ! } ! ! /*********************************************************************** ! * Retrieve the DataRecord object from a file, in binary mode. ! ***********************************************************************/ ! int DataRecord::deSerialize(FILE *f) { ! if (fread(&magic, sizeof(magic), 1, f) != 1) ! return (-1); ! if (fread(&size, sizeof(size), 1, f) != 1) ! return (-1); ! if (fread(&num, sizeof(num), 1, f) != 1) ! return (-1); ! if (h->deSerialize(f) != 0) ! return (-1); ! ! return (0); ! } |
From: Mapi B. <ma...@us...> - 2009-08-06 21:40:53
|
Update of /cvsroot/easycalc/PPCport In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv22044 Modified Files: EasyCalc.vcproj Log Message: More complex DataManager, and some other updates Index: EasyCalc.vcproj =================================================================== RCS file: /cvsroot/easycalc/PPCport/EasyCalc.vcproj,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** EasyCalc.vcproj 5 Jul 2009 20:52:30 -0000 1.5 --- EasyCalc.vcproj 6 Aug 2009 21:40:37 -0000 1.6 *************** *** 508,511 **** --- 508,515 ---- </File> <File + RelativePath=".\compat\MemoryManager.cpp" + > + </File> + <File RelativePath=".\compat\Preferences.cpp" > *************** *** 654,657 **** --- 658,665 ---- </File> <File + RelativePath=".\compat\MemoryManager.h" + > + </File> + <File RelativePath=".\compat\PalmOS.h" > |
From: Mapi B. <ma...@us...> - 2009-07-05 20:54:04
|
Update of /cvsroot/easycalc/PPCport/include In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17393 Modified Files: defuns.h Log Message: MathLib compatibility Index: defuns.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/include/defuns.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** defuns.h 24 Jun 2009 21:41:44 -0000 1.3 --- defuns.h 5 Jul 2009 20:53:52 -0000 1.4 *************** *** 72,76 **** #define MAX_OSTACK 45 ! #define NaN ((double)(3-3)/(3-3)) TCHAR * guess(Trpn item) MLIB; --- 72,76 ---- #define MAX_OSTACK 45 ! //#define NaN ((double)(3-3)/(3-3)) TCHAR * guess(Trpn item) MLIB; |
From: Mapi B. <ma...@us...> - 2009-07-05 20:53:40
|
Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17375 Modified Files: calcDB.cpp display.cpp fp.cpp funcs.cpp funcs.h konvert.cpp stack.cpp Log Message: MathLib compatibility Index: display.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/display.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** display.cpp 24 Jun 2009 21:39:59 -0000 1.2 --- display.cpp 5 Jul 2009 20:53:37 -0000 1.3 *************** *** 35,39 **** #include "fp.h" #include "stack.h" ! #include "MathLib.h" TdispPrefs dispPrefs; --- 35,39 ---- #include "fp.h" #include "stack.h" ! #include "compat/MathLib.h" TdispPrefs dispPrefs; Index: funcs.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/funcs.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** funcs.cpp 24 Jun 2009 21:39:59 -0000 1.2 --- funcs.cpp 5 Jul 2009 20:53:37 -0000 1.3 *************** *** 36,40 **** #include "funcs.h" #include "calcDB.h" ! #include "MathLib.h" #include "stack.h" //#include "calc.h" --- 36,40 ---- #include "funcs.h" #include "calcDB.h" ! #include "compat/MathLib.h" #include "stack.h" //#include "calc.h" Index: stack.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/stack.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** stack.cpp 24 Jun 2009 21:39:59 -0000 1.2 --- stack.cpp 5 Jul 2009 20:53:37 -0000 1.3 *************** *** 36,40 **** #include "matrix.h" #include "cmatrix.h" ! #include "MathLib.h" #include "prefs.h" --- 36,40 ---- #include "matrix.h" #include "cmatrix.h" ! #include "compat/MathLib.h" #include "prefs.h" Index: konvert.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/konvert.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** konvert.cpp 24 Jun 2009 21:39:59 -0000 1.2 --- konvert.cpp 5 Jul 2009 20:53:37 -0000 1.3 *************** *** 30,34 **** #include "defuns.h" ! #include "MathLib.h" #include "konvert.h" #include "mathem.h" --- 30,34 ---- #include "defuns.h" ! #include "compat/MathLib.h" #include "konvert.h" #include "mathem.h" Index: fp.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/core/mlib/fp.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** fp.cpp 24 Jun 2009 21:44:22 -0000 1.1 --- fp.cpp 5 Jul 2009 20:53:37 -0000 1.2 *************** *** 35,39 **** #include "compat/PalmOS.h" //#include <StringMgr.h> ! #include <MathLib.h> #endif #include "defuns.h" --- 35,39 ---- #include "compat/PalmOS.h" //#include <StringMgr.h> ! #include "compat/MathLib.h" #endif #include "defuns.h" *************** *** 41,46 **** #include "fp.h" - #include "compat/FloatManager.h" - static double SCI_LIMIT_MAX; /* Above this number show it as xEy */ static double SCI_LIMIT_MIN; /* Under this number show as xE-y */ --- 41,44 ---- |
From: Mapi B. <ma...@us...> - 2009-07-05 20:53:20
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17350 Added Files: MathLib.cpp MathLib.h Preferences.cpp Preferences.h Log Message: MathLib compatibility --- NEW FILE: Preferences.cpp --- #include "StdAfx.h" #include "Preferences.h" #include <winnls.h> #define DEC_DOT 0 #define DEC_COM 1 #define TH_SPC 0 #define TH_COM 1 #define TH_DOT 2 #define TH_APO 3 unsigned int PrefGetPreference(SystemPreferencesChoice choice) { unsigned int returnVal; switch (choice) { case prefNumberFormat: { int dec, th; TCHAR cdec[10], cth[10]; int rcdec = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, cdec, 9 ); int rcth = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, cth, 9 ); if (rcdec <= 0) dec = DEC_DOT; // By default .. else { cdec[rcdec] = 0; if (_tcsstr(cdec, _T(",")) != NULL) { dec = DEC_COM; } else { dec = DEC_DOT; // By default } } if (rcth <= 0) th = TH_SPC; // By default .. else { cth[rcth] = 0; if (_tcsstr(cth, _T("'")) != NULL) { th = TH_APO; } else if (_tcsstr(cth, _T(".")) != NULL) { th = TH_DOT; } else if (_tcsstr(cth, _T(",")) != NULL) { th = TH_COM; } else { th = TH_SPC; // By default } } if ((th == TH_APO) && (dec == DEC_COM)) returnVal = nfApostropheComma; else if ((th == TH_APO) && (dec == DEC_DOT)) returnVal = nfApostrophePeriod; else if ((th == TH_SPC) && (dec == DEC_COM)) returnVal = nfSpaceComma; else if ((th == TH_DOT) && (dec == DEC_COM)) returnVal = nfPeriodComma; else returnVal = nfCommaPeriod; } break; default: returnVal = 0; } return (returnVal); } --- NEW FILE: Preferences.h --- #pragma once #ifndef PREFERENCES_H #define PREFERENCES_H 1 typedef enum { nfCommaPeriod, nfPeriodComma, nfSpaceComma, nfApostrophePeriod, nfApostropheComma } NumberFormatType; typedef enum { prefNumberFormat } SystemPreferencesChoice; unsigned int PrefGetPreference(SystemPreferencesChoice choice); #endif --- NEW FILE: MathLib.h --- /* MathLib: Pilot shared library of IEEE-754 double math functions * * Library function prototypes for the calling application. This is * the file that the calling application should include in order to * get access to the routines in the library; it serves the same * function as the file "math.h" normally used on systems with * standard math libraries. Each function in the library has two * prototypes listed; the first is for the programmer-friendly * wrapper function in MathLib.c, the second is for the raw SYS_TRAP() * invocation that actually calls the library routine. * * Copyright (C) 1997 Rick Huebner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; see file COPYING.LIB. If not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA * * Version 1.01, 23 August 1997, Rick Huebner */ #ifndef __MATHLIB_H__ #define __MATHLIB_H__ // This is the major version number of the library. If new functions // are added to this library, this version number must be incremented // to protect programs which are compiled with this header from trying // to invoke the new functions in an old version of MathLib.prc, // which would be fatal. Do NOT delete any functions from this list, // or any older programs which try to use them will die. Any changes // other than adding new functions should be reflected in the minor // part of the version number, e.g. 1.1 if a bug fix, 2.0 if new // functions added. #define MathLibVersion 1 // Possible Err values from MathLib functions typedef enum MathLibErrorCode { mlErrNone = 0, mlErrOldVersion, // library is older than version passed to open() mlErrNotOpen, // close() without having called open() first mlErrNoMemory // can't allocate global data block } MathLibErrorCode; // Library reference returned by SysLibFind() or SysLibLoad() extern UInt16 MathLibRef; /***************************** * Library control functions * *****************************/ Err MathLibOpen(UInt16 refnum, UInt16 version) // Initialize library for use SYS_TRAP(sysLibTrapOpen); Err MathLibClose(UInt16 refnum, UInt16 *usecountP)// Free library resources when finished SYS_TRAP(sysLibTrapClose); Err MathLibSleep(UInt16 refnum) // Called by OS when Pilot sleeps SYS_TRAP(sysLibTrapSleep); Err MathLibWake(UInt16 refnum) // Called by OS when Pilot wakes SYS_TRAP(sysLibTrapWake); /*************************** * Trigonometric functions * ***************************/ //double acos(double x); // Arc cosine of x //double asin(double x); // Arc sine of x //double atan(double x); // Arc tangent of x //double atan2(double y, double x); // Arc tangent of y/x //double cos(double x); // Cosine of x //double sin(double x); // Sine of x //double tan(double x); // Tangent of x void sincos(double x, double *sinx, double *cosx); // Sine and cosine of x /************************ * Hyperbolic functions * ************************/ //double cosh(double x); // Hyperbolic cosine of x //double sinh(double x); // Hyperbolic sine of x //double tanh(double x); // Hyperbolic tangent of x double acosh(double x); // Hyperbolic arc cosine of x double asinh(double x); // Hyperbolic arc sine of x double atanh(double x); // Hyperbolic arc tangent of x /***************************************** * Exponential and logarithmic functions * *****************************************/ //double exp(double x); // Exponential function of x [pow(e,x)] //double frexp(double x, Int16 *exponent); // Break x into normalized fraction and an integral power of 2 //double ldexp(double x, Int16 exponent); // x * pow(2,exponent) //double log(double x); // Natural logarithm of x //double log10(double x); // Base 10 logarithm of x //double modf(double x, double *intpart); // Break x into integral and fractional parts double expm1(double x); // exp(x) - 1 double log1p(double x); // log(1+x) //double logb(double x); // Base 2 signed integral exponent of x #define logb(x) _logb(x) double log2(double x); // Base 2 logarithm of x /******************* * Power functions * *******************/ //double pow(double x, double y); // x to the y power [x**y] //double sqrt(double x); // Square root of x [x**0.5] //double hypot(double x, double y); // sqrt(x*x + y*y) [hypotenuse of right triangle] #define hypot(x,y) _hypot(x,y) double cbrt(double x); // Cube root of x [x**(1/3)] /************************************************************ * Nearest integer, absolute value, and remainder functions * ************************************************************/ //double ceil(double x); // Smallest integral value not less than x //double fabs(double x); // Absolute value of x //double floor(double x); // Largest integral value not greater than x //double fmod(double x, double y); // Modulo remainder of x/y /*************************** * Miscellaneous functions * ***************************/ //Int16 isinf(double x); // Return 0 if x is finite or NaN, +1 if +Infinity, or -1 if -Infinity int isinf(double x); //Int16 finite(double x); // Return nonzero if x is finite and not NaN #define finite(x) _finite(x) //double scalbn(double x, Int16 exponent); // x * pow(2,exponent) #define scalbn(x,exponent) _scalb(x,(long)exponent) double drem(double x, double y); // Remainder of x/y double significand(double x); // Fractional part of x after dividing out ilogb(x) //double copysign(double x, double y); // Return x with its sign changed to match y's #define copysign(x,y) _copysign(x,y) //Int16 isnan(double x); // Return nonzero if x is NaN (Not a Number) #define isnan(x) _isnan(x) //Int16 ilogb(double x); // Binary exponent of non-zero x int ilogb(double x); double rint(double x); // Integral value nearest x in direction of prevailing rounding mode //double nextafter(double x, double y); // Next machine double value after x in the direction towards y #define nextafter(x,y) _nextafter(x,y) //double remainder(double x, double y); // Remainder of integer division x/y with infinite precision #define remainder(x,y) drem(x,y) // Not used by EasyCalc, and not worth a fudge ... //double scalb(double x, double exponent);// x * pow(2,exponent) double round(double x); // Round x to nearest integral value away from zero double trunc(double x); // Round x to nearest integral value not larger than x //UInt32 signbit(double x); // Return signbit of x's machine representation #define signbit(x) ((_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_NN | _FPCLASS_ND | _FPCLASS_NZ) != 0) #endif // __MATHLIB_H__ --- NEW FILE: MathLib.cpp --- /* MathLib: Pilot shared library of IEEE-754 double math functions * * Convenience functions for the calling application. These functions * provide a programmer-friendly wrapper around the raw system trap * invocations which actually call the library routines. The idea * is to allow the programmer to say: * y = sqrt(x); * instead of requiring: * MathLibSqrt(MathLibRef, x, &y); * like the system trap interface requires. The system trap form is * not only harder to read, but can't directly replace the traditional * function call in ported code, and can't be nested inside an expression. * Just add this source file to your project or makefile, and include * "MathLib.h" in any source file that needs to call these. * * The downside to these routines is that they'll take up some space * in your program, though CodeWarrior at least is smart enough to * only link in the ones which you actually use, so it doesn't really * cost you that much. In fact, if you call these enough they'll pay * for themselves, since "x=sqrt(x)" generates much less code than * calling MathLibSqrt() directly. * * Copyright (C) 1997 Rick Huebner * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library 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 Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this program; see file COPYING.LIB. If not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * Version 1.01, 23 August 1997, Rick Huebner */ #include "stdafx.h" #include "PalmOS.h" #include "MathLib.h" #include "defuns.h" // Library reference returned by SysLibFind() or SysLibLoad() UInt16 MathLibRef; //double acos(double x) { // double result; // MathLibACos(MathLibRef, x, &result); // return result; //} //double asin(double x) { // double result; // MathLibASin(MathLibRef, x, &result); // return result; //} //double atan(double x) { // double result; // MathLibATan(MathLibRef, x, &result); // return result; //} //double atan2(double y, double x) { // double result; // MathLibATan2(MathLibRef, y, x, &result); // return result; //} //double cos(double x) { // double result; // MathLibCos(MathLibRef, x, &result); // return result; //} //double sin(double x) { // double result; // MathLibSin(MathLibRef, x, &result); // return result; //} //double tan(double x) { // double result; // MathLibTan(MathLibRef, x, &result); // return result; //} //void sincos(double x, double *sinx, double *cosx) { // MathLibSinCos(MathLibRef, x, sinx, cosx); //} void sincos(double x, double *sinx, double *cosx) { // Note: could also be calculated with: //1. Reduce the angle x to the range (0, pi/2) //2. Let z = tan(x/2), // then sin(x) = 2*z/(1+z*z), cos(x) = (1-z*z)/(1+z*z) . // But with a floating point unit around ... not sure that // the perf/accuracy tradeoff is so beneficial. // The ARM processor does not have a sincos function like on Intel/AMD. *sinx = sin(x); *cosx = cos(x); } //double cosh(double x) { // double result; // MathLibCosH(MathLibRef, x, &result); // return result; //} //double sinh(double x) { // double result; // MathLibSinH(MathLibRef, x, &result); // return result; //} //double tanh(double x) { // double result; // MathLibTanH(MathLibRef, x, &result); // return result; //} //double acosh(double x) { // double result; // MathLibACosH(MathLibRef, x, &result); // return result; //} double acosh(double x) { //acosh(x) = ln(x + sqrt(x-1) * sqrt(x+1)) // = ln(x + sqrt(x*x-1)) //for x > 1 //Note: acosh(1) = 0 double result = 0.0; if (x < 1.0) result = NaN; else if (isinf(x)) result = x; else if (x > 1.0) result = log(x + sqrt(x*x - 1.0)); return (result); } //double asinh(double x) { // double result; // MathLibASinH(MathLibRef, x, &result); // return result; //} double asinh(double x) { //asinh(x) = ln(x + sqrt(x*x+1)) //for x > 0 //asinh(0) = 0 //If x<0, take the opposite or the result calculated with -x. double result = 0.0; if (isinf(x) || _isnan(x)) result = x; else if (x > 0.0) result = log(x + sqrt(x*x + 1.0)); else if (x < 0.0) result = -log(-x + sqrt(x*x + 1.0)); return (result); } //double atanh(double x) { // double result; // MathLibATanH(MathLibRef, x, &result); // return result; //} double atanh(double x) { //atan(x) = 1/2 * ln((1+x)/(1-x)) //for -1 < x < 1 //atanh(-1) = -infinity //atanh(1) = +infinity double result = 0.0; if (_isnan(x) || (x < -1.0) || (x > 1.0)) result = NaN; else if ((x == 1.0) || (x == -1.0)) result = x / 0.0; else if (x != 0.0) // result = 0.5 * log((1.0 + x) * (1.0 - x)); result = _scalb(log((1.0 + x) * (1.0 - x)), -1); return (result); } //double exp(double x) { // double result; // MathLibExp(MathLibRef, x, &result); // return result; //} //double frexp(double x, Int16 *exponent) { // double fraction; // MathLibFrExp(MathLibRef, x, &fraction, exponent); // return fraction; //} //double ldexp(double x, Int16 exponent) { // double result; // MathLibLdExp(MathLibRef, x, exponent, &result); // return result; //} //double log(double x) { // double result; // MathLibLog(MathLibRef, x, &result); // return result; //} //double log10(double x) { // double result; // MathLibLog10(MathLibRef, x, &result); // return result; //} //double modf(double x, double *intpart) { // double fraction; // MathLibModF(MathLibRef, x, intpart, &fraction); // return fraction; //} //double expm1(double x) { // double result; // MathLibExpM1(MathLibRef, x, &result); // return result; //} /*************************************************************** * The following is imported from the Free42 source code 1.4.50 at * http://free42.sourceforge.net/ , from pocketpc/mathfudge.c, * itself borrowing the log1p() and expm1() parts from the GNU C * Library, version 2.2.5, originally donated by Sun Microsystems. * Indeed, the Microsoft Visual series are missing those functions. ***************************************************************/ static double //one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ //ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ //two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ vast= 1.00000000000000000000e+300; #define int32_t int #define u_int32_t unsigned int /* __FLOAT_WORD_ORDER == LITTLE_ENDIAN */ typedef union { double d; struct { int lx, hx; } w; } double_words; /* Get the more significant 32 bit int from a double. */ typedef union { double value; struct { u_int32_t lsw; u_int32_t msw; } parts; } ieee_double_shape_type; #define GET_HIGH_WORD(i,d) \ do { \ ieee_double_shape_type gh_u; \ gh_u.value = (d); \ (i) = gh_u.parts.msw; \ } while (0) /* Get the less significant 32 bit int from a double. */ #define GET_LOW_WORD(i,d) \ do { \ ieee_double_shape_type gl_u; \ gl_u.value = (d); \ (i) = gl_u.parts.lsw; \ } while (0) /* Set the more significant 32 bits of a double from an int. */ #define SET_HIGH_WORD(d,v) \ do { \ ieee_double_shape_type sh_u; \ sh_u.value = (d); \ sh_u.parts.msw = (v); \ (d) = sh_u.value; \ } while (0) /*---------------------------------------------------------------------------*/ /* @(#)s_expm1.c 5.1 93/09/24 */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ /* Modified by Naohiko Shimizu/Tokai University, Japan 1997/08/25, for performance improvement on pipelined processors. */ /* expm1(x) * Returns exp(x)-1, the exponential of x minus 1. * * Method * 1. Argument reduction: * Given x, find r and integer k such that * * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 * * Here a correction term c will be computed to compensate * the error in r when rounded to a floating-point number. * * 2. Approximating expm1(r) by a special rational function on * the interval [0,0.34658]: * Since * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... * we define R1(r*r) by * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) * That is, * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... * We use a special Reme algorithm on [0,0.347] to generate * a polynomial of degree 5 in r*r to approximate R1. The * maximum error of this polynomial approximation is bounded * by 2**-61. In other words, * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 * where Q1 = -1.6666666666666567384E-2, * Q2 = 3.9682539681370365873E-4, * Q3 = -9.9206344733435987357E-6, * Q4 = 2.5051361420808517002E-7, * Q5 = -6.2843505682382617102E-9; * (where z=r*r, and the values of Q1 to Q5 are listed below) * with error bounded by * | 5 | -61 * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 * | | * * expm1(r) = exp(r)-1 is then computed by the following * specific way which minimize the accumulation rounding error: * 2 3 * r r [ 3 - (R1 + R1*r/2) ] * expm1(r) = r + --- + --- * [--------------------] * 2 2 [ 6 - r*(3 - R1*r/2) ] * * To compensate the error in the argument reduction, we use * expm1(r+c) = expm1(r) + c + expm1(r)*c * ~ expm1(r) + c + r*c * Thus c+r*c will be added in as the correction terms for * expm1(r+c). Now rearrange the term to avoid optimization * screw up: * ( 2 2 ) * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) * ( ) * * = r - E * 3. Scale back to obtain expm1(x): * From step 1, we have * expm1(x) = either 2^k*[expm1(r)+1] - 1 * = or 2^k*[expm1(r) + (1-2^-k)] * 4. Implementation notes: * (A). To save one multiplication, we scale the coefficient Qi * to Qi*2^i, and replace z by (x^2)/2. * (B). To achieve maximum accuracy, we compute expm1(x) by * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) * (ii) if k=0, return r-E * (iii) if k=-1, return 0.5*(r-E)-0.5 * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) * else return 1.0+2.0*(r-E); * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else * (vii) return 2^k(1-((E+2^-k)-r)) * * Special cases: * expm1(INF) is INF, expm1(NaN) is NaN; * expm1(-INF) is -1, and * for finite argument, only expm1(0)=0 is exact. * * Accuracy: * according to an error analysis, the error is always less than * 1 ulp (unit in the last place). * * Misc. info. * For IEEE double * if x > 7.09782712893383973096e+02 then expm1(x) overflow * * Constants: * The hexadecimal values are the intended ones for the following * constants. The decimal values may be used, provided that the * compiler will convert from decimal to binary accurately enough * to produce the hexadecimal values shown. */ #define one Q[0] static double /*vast = 1.0e+300,*/ tiny = 1.0e-300, o_threshold = 7.09782712893383973096e+02,/* 0x40862E42, 0xFEFA39EF */ /*ln2_hi = 6.93147180369123816490e-01,*/ /* 0x3fe62e42, 0xfee00000 */ /*ln2_lo = 1.90821492927058770002e-10,*/ /* 0x3dea39ef, 0x35793c76 */ invln2 = 1.44269504088896338700e+00,/* 0x3ff71547, 0x652b82fe */ /* scaled coefficients related to expm1 */ Q[] = {1.0, -3.33333333333331316428e-02, /* BFA11111 111110F4 */ 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ -2.01099218183624371326e-07}; /* BE8AFDB7 6E09C32D */ double expm1(double x) { double y,hi,lo,c,t,e,hxs,hfx,r1,h2,h4,R1,R2,R3; int32_t k,xsb; u_int32_t hx; GET_HIGH_WORD(hx,x); xsb = hx&0x80000000; /* sign bit of x */ if(xsb==0) y=x; else y= -x; /* y = |x| */ hx &= 0x7fffffff; /* high word of |x| */ /* filter out vast and non-finite argument */ if(hx >= 0x4043687A) { /* if |x|>=56*ln2 */ if(hx >= 0x40862E42) { /* if |x|>=709.78... */ if(hx>=0x7ff00000) { u_int32_t low; GET_LOW_WORD(low,x); if(((hx&0xfffff)|low)!=0) return x+x; /* NaN */ else return (xsb==0)? x:-1.0;/* exp(+-inf)={inf,-1} */ } if(x > o_threshold) return vast*vast; /* overflow */ } if(xsb!=0) { /* x < -56*ln2, return -1.0 with inexact */ if(x+tiny<0.0) /* raise inexact */ return tiny-one; /* return -1 */ } } /* argument reduction */ if(hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ if(hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ if(xsb==0) {hi = x - ln2_hi; lo = ln2_lo; k = 1;} else {hi = x + ln2_hi; lo = -ln2_lo; k = -1;} } else { k = (int32_t) (invln2*x+((xsb==0)?0.5:-0.5)); t = k; hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ lo = t*ln2_lo; } x = hi - lo; c = (hi-x)-lo; } else if(hx < 0x3c900000) { /* when |x|<2**-54, return x */ t = vast+x; /* return x with inexact flags when x!=0 */ return x - (t-(vast+x)); } else k = 0; /* x is now in primary range */ hfx = 0.5*x; hxs = x*hfx; #ifdef DO_NOT_USE_THIS r1 = one+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); #else R1 = one+hxs*Q[1]; h2 = hxs*hxs; R2 = Q[2]+hxs*Q[3]; h4 = h2*h2; R3 = Q[4]+hxs*Q[5]; r1 = R1 + h2*R2 + h4*R3; #endif t = 3.0-r1*hfx; e = hxs*((r1-t)/(6.0 - x*t)); if(k==0) return x - (x*e-hxs); /* c is 0 */ else { e = (x*(e-c)-c); e -= hxs; if(k== -1) return 0.5*(x-e)-0.5; if(k==1) { if(x < -0.25) return -2.0*(e-(x+0.5)); else return one+2.0*(x-e); } if (k <= -2 || k>56) { /* suffice to return exp(x)-1 */ u_int32_t high; y = one-(e-x); GET_HIGH_WORD(high,y); SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ return y-one; } t = one; if(k<20) { u_int32_t high; SET_HIGH_WORD(t,0x3ff00000 - (0x200000>>k)); /* t=1-2^-k */ y = t-(e-x); GET_HIGH_WORD(high,y); SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ } else { u_int32_t high; SET_HIGH_WORD(t,((0x3ff-k)<<20)); /* 2^-k */ y = x-(e+t); y += one; GET_HIGH_WORD(high,y); SET_HIGH_WORD(y,high+(k<<20)); /* add k to y's exponent */ } } return y; } //double log1p(double x) { // double result; // MathLibLog1P(MathLibRef, x, &result); // return result; //} /*---------------------------------------------------------------------------*/ /* @(#)s_log1p.c 5.1 93/09/24 */ /* * ==================================================== * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. * * Developed at SunPro, a Sun Microsystems, Inc. business. * Permission to use, copy, modify, and distribute this * software is freely granted, provided that this notice * is preserved. * ==================================================== */ /* Modified by Naohiko Shimizu/Tokai University, Japan 1997/08/25, for performance improvement on pipelined processors. */ /* double log1p(double x) * * Method : * 1. Argument Reduction: find k and f such that * 1+x = 2^k * (1+f), * where sqrt(2)/2 < 1+f < sqrt(2) . * * Note. If k=0, then f=x is exact. However, if k!=0, then f * may not be representable exactly. In that case, a correction * term is need. Let u=1+x rounded. Let c = (1+x)-u, then * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), * and add back the correction term c/u. * (Note: when x > 2**53, one can simply return log(x)) * * 2. Approximation of log1p(f). * Let s = f/(2+f) ; based on log(1+f) = log(1+s) - log(1-s) * = 2s + 2/3 s**3 + 2/5 s**5 + ....., * = 2s + s*R * We use a special Reme algorithm on [0,0.1716] to generate * a polynomial of degree 14 to approximate R The maximum error * of this polynomial approximation is bounded by 2**-58.45. In * other words, * 2 4 6 8 10 12 14 * R(z) ~ Lp1*s +Lp2*s +Lp3*s +Lp4*s +Lp5*s +Lp6*s +Lp7*s * (the values of Lp1 to Lp7 are listed in the program) * and * | 2 14 | -58.45 * | Lp1*s +...+Lp7*s - R(z) | <= 2 * | | * Note that 2s = f - s*f = f - hfsq + s*hfsq, where hfsq = f*f/2. * In order to guarantee error in log below 1ulp, we compute log * by * log1p(f) = f - (hfsq - s*(hfsq+R)). * * 3. Finally, log1p(x) = k*ln2 + log1p(f). * = k*ln2_hi+(f-(hfsq-(s*(hfsq+R)+k*ln2_lo))) * Here ln2 is split into two floating point number: * ln2_hi + ln2_lo, * where n*ln2_hi is always exact for |n| < 2000. * * Special cases: * log1p(x) is NaN with signal if x < -1 (including -INF) ; * log1p(+INF) is +INF; log1p(-1) is -INF with signal; * log1p(NaN) is that NaN with no signal. * * Accuracy: * according to an error analysis, the error is always less than * 1 ulp (unit in the last place). * * Constants: * The hexadecimal values are the intended ones for the following * constants. The decimal values may be used, provided that the * compiler will convert from decimal to binary accurately enough * to produce the hexadecimal values shown. * * Note: Assuming log() return accurate answer, the following * algorithm can be used to compute log1p(x) to within a few ULP: * * u = 1+x; * if(u==1.0) return x ; else * return log(u)*(x/(u-1.0)); * * See HP-15C Advanced Functions Handbook, p.193. */ static double //ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ //ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ two54 = 1.80143985094819840000e+16, /* 43500000 00000000 */ Lp[] = {0.0, 6.666666666666735130e-01, /* 3FE55555 55555593 */ 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ 2.857142874366239149e-01, /* 3FD24924 94229359 */ 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ 1.479819860511658591e-01}; /* 3FC2F112 DF3E5244 */ static double zero = 0.0; double log1p(double x) { double hfsq,f,c,s,z,R,u,z2,z4,z6,R1,R2,R3,R4; int32_t k,hx,hu,ax; GET_HIGH_WORD(hx,x); ax = hx&0x7fffffff; k = 1; if (hx < 0x3FDA827A) { /* x < 0.41422 */ if(ax>=0x3ff00000) { /* x <= -1.0 */ if(x==-1.0) return -two54/(x-x);/* log1p(-1)=+inf */ else return (x-x)/(x-x); /* log1p(x<-1)=NaN */ } if(ax<0x3e200000) { /* |x| < 2**-29 */ if(two54+x>zero /* raise inexact */ &&ax<0x3c900000) /* |x| < 2**-54 */ return x; else return x - x*x*0.5; } if(hx>0||hx<=((int32_t)0xbfd2bec3)) { k=0;f=x;hu=1;} /* -0.2929<x<0.41422 */ } if (hx >= 0x7ff00000) return x+x; if(k!=0) { if(hx<0x43400000) { u = 1.0+x; GET_HIGH_WORD(hu,u); k = (hu>>20)-1023; c = (k>0)? 1.0-(u-x):x-(u-1.0);/* correction term */ c /= u; } else { u = x; GET_HIGH_WORD(hu,u); k = (hu>>20)-1023; c = 0; } hu &= 0x000fffff; if(hu<0x6a09e) { SET_HIGH_WORD(u,hu|0x3ff00000); /* normalize u */ } else { k += 1; SET_HIGH_WORD(u,hu|0x3fe00000); /* normalize u/2 */ hu = (0x00100000-hu)>>2; } f = u-1.0; } hfsq=0.5*f*f; if(hu==0) { /* |f| < 2**-20 */ if(f==zero) { if(k==0) return zero; else {c += k*ln2_lo; return k*ln2_hi+c;} } R = hfsq*(1.0-0.66666666666666666*f); if(k==0) return f-R; else return k*ln2_hi-((R-(k*ln2_lo+c))-f); } s = f/(2.0+f); z = s*s; #ifdef DO_NOT_USE_THIS R = z*(Lp1+z*(Lp2+z*(Lp3+z*(Lp4+z*(Lp5+z*(Lp6+z*Lp7)))))); #else R1 = z*Lp[1]; z2=z*z; R2 = Lp[2]+z*Lp[3]; z4=z2*z2; R3 = Lp[4]+z*Lp[5]; z6=z4*z2; R4 = Lp[6]+z*Lp[7]; R = R1 + z2*R2 + z4*R3 + z6*R4; #endif if(k==0) return f-(hfsq-s*(hfsq+R)); else return k*ln2_hi-((hfsq-(s*(hfsq+R)+(k*ln2_lo+c)))-f); } //double logb(double x) { // double result; // MathLibLogB(MathLibRef, x, &result); // return result; //} //double log2(double x) { // double result; // MathLibLog2(MathLibRef, x, &result); // return result; //} double log2(double x) { //log2(x) = ln(x)/ln(2) //for x > 0 //Note: log2(1) = 0, log2(0) = -infinity, log2(+infinity) = +infinity double result = 0.0; if (x < 0.0) result = NaN; else if (x == 0.0) result = -1.0 / x; else if (isinf(x)) result = x; else result = log(x) / log(2.0); return (result); } //double pow(double x, double y) { // double result; // MathLibPow(MathLibRef, x, y, &result); // return result; //} //double sqrt(double x) { // double result; // MathLibSqrt(MathLibRef, x, &result); // return result; //} //double hypot(double x, double y) { // double result; // MathLibHypot(MathLibRef, x, y, &result); // return result; //} //double cbrt(double x) { // double result; // MathLibCbrt(MathLibRef, x, &result); // return result; //} double cbrt(double x) { //cbrt(x) = x**(1/3) = exp(ln(x)/3) double result; if (_isnan(x) || (x == 0.0) || (x == 1.0) || (x == -1.0) || isinf(x)) result = x; else result = pow(x, 1.0/3.0); // else if (x > 0.0) // result = exp(log(x)/3.0); // else result = - exp(log(-x)/3.0); return (result); } //double ceil(double x) { // double result; // MathLibCeil(MathLibRef, x, &result); // return result; //} //double fabs(double x) { // double result; // MathLibFAbs(MathLibRef, x, &result); // return result; //} //double floor(double x) { // double result; // MathLibFloor(MathLibRef, x, &result); // return result; //} //double fmod(double x, double y) { // double result; // MathLibFMod(MathLibRef, x, y, &result); // return result; //} //Int16 isinf(double x) { // Int16 result; // MathLibIsInf(MathLibRef, x, &result); // return result; //} int isinf(double x) { int rc = _fpclass(x); if ((rc & _FPCLASS_NINF) != 0) return (-1); else if ((rc & _FPCLASS_PINF) != 0) return (1); else return (0); } //Int16 finite(double x) { // Int16 result; // MathLibFinite(MathLibRef, x, &result); // return result; //} //double scalbn(double x, Int16 exponent) { // double result; // MathLibScalBN(MathLibRef, x, exponent, &result); // return result; //} //double drem(double x, double y) { // double result; // MathLibDRem(MathLibRef, x, y, &result); // return result; //} double drem(double x, double y) { // The function drem is like fmod and compute the remainder r = x - ny when y is nonzero // except that it rounds the internal quotient n to the nearest integer // instead of towards zero to an integer. // For example, drem (6.5, 2.3) returns -0.4, which is 6.5 minus 6.9. // The absolute value of the result is less than or equal to half the absolute value // of the denominator. The difference between fmod (numerator, denominator) // and drem (numerator, denominator) is always either denominator, minus denominator, // or zero. // If the absolute value |n-x/y| = 0.5, n is chosen to be even. // For example, drem (5.5, 2.2) returns 1.1, which is 5.5 minus 2 * 2.2 = 4.4, // and drem (7.7, 2.2) returns -1.1, which is 7.7 minus 4 * 2.2 = 8.8. // If denominator is zero, drem returns NaN, just like fmod. // If x or y is a NaN, a NaN is returned. // If x is an infinity, a NaN is returned. // If y is an infinity, x is returned. double result; if ((y == 0.0) || _isnan(x) || _isnan(y) || isinf(x)) result = NaN; else if (isinf(y)) result = x; else { // result = fmod(x, y); // double r1 = result - y; // Takes care of the positive case, with n+1 // double r2 = result + y; // Takes care of the negative case, with n-1 // double fr = fabs(result); // double fr1 = fabs(r1); // double fr2 = fabs(r2); // if (fr1 < fr) { // Keep the one with lowest absolute value // result = r1; // fr = fr1; // } else if (fr2 < fr) { // result = r2; // fr = fr2; // } else if (fr1 == fr) { // Equidistant // } else if (fr2 == fr) { // Equidistant // } double q = x / y; int n = (int) rint(q); result = x - (double) n * y; } return (result); } //double significand(double x) { // double result; // MathLibSignificand(MathLibRef, x, &result); // return result; //} double significand(double x) { //The Math.significand() function returns the mantissa of x scaled to the range [1,2]. //It is equivalent to scalb(x, (double) -ilogb(x)). //This function exists mainly for use in certain standardized tests for IEEE 754 conformance. //The function significand(x) isn't defined when x is one of: //* 0, //* positive or negative infinity, //* NAN. double result; if ((x == 0.0) || _isnan(x) || isinf(x)) result = NaN; else result = _scalb(x, (long) ilogb(x)); return result; } //double copysign(double x, double y) { // double result; // MathLibCopySign(MathLibRef, x, y, &result); // return result; //} //Int16 isnan(double x) { // Int16 result; // MathLibIsNaN(MathLibRef, x, &result); // return result; //} //Int16 ilogb(double x) { // Int16 result; // MathLibILogB(MathLibRef, x, &result); // return result; //} int ilogb(double x) { //The ilogb() function returns the exponent part of x. //Formally, the return value is the integral part of logr|x| as a signed integral value, //for non-zero x, where r is the radix of the machine's floating point arithmetic. //The call ilogb(x) is equivalent to (int)logb(x). //If x is 0, then ilogb() returns INT_MIN. //If x is NaN or ±Inf, then ilogb() returns INT_MAX. int result; if (_isnan(x) || isinf(x)) result = INT_MAX; else if (x == 0.0) result = INT_MIN; else result = (int) _logb(x); return result; } //double rint(double x) { // double result; // MathLibRInt16(MathLibRef, x, &result); // return result; //} double rint(double x) { //Round x to an integer value according to the current rounding mode. //The default rounding mode is to round to the nearest integer. //Some machines support other modes, but round-to-nearest is always used unless //you explicitly select another. //This implementation will use round-to-nearest. //Note: for halfway numbers, rint() is to pick the even closest integer. double result; if (_isnan(x) || isinf(x) || (x == 0.0)) result = x; else { double fract, n; int nn, nn1; fract = modf(x, &n); nn = (int) n; nn1 = nn >> 1; nn1 <<= 1; if (x > 0.0) { if (fract > 0.5) n += 1.0; else if (fract == 0.5) { if (nn != nn1) n += 1.0; } } else { if (fract < -0.5) n -= 1.0; else if (fract == -0.5) { if (nn != nn1) n -= 1.0; } } result = n; } return (result); } //double nextafter(double x, double y) { // double result; // MathLibNextAfter(MathLibRef, x, y, &result); // return result; //} //double remainder(double x, double y) { // double result; // MathLibRemainder(MathLibRef, x, y, &result); // return result; //} //double scalb(double x, double exponent) { // double result; // MathLibScalB(MathLibRef, x, exponent, &result); // return result; //} //double round(double x) { // double result; // MathLibRound(MathLibRef, x, &result); // return result;floor //} double round(double x) { double result; if (_isnan(x) || isinf(x)) result = NaN; else if (x == trunc(x)) result = x; else if (x < 0.0) result = trunc(x-0.5); else result = trunc(x+0.5); return (result); } //double trunc(double x) { // double result; // MathLibTrunc(MathLibRef, x, &result); // return result; //} double trunc(double x) { double result; if (_isnan(x) || isinf(x)) result = NaN; modf(x, &result); return (result); } //UInt32 signbit(double x) { // UInt32 result; // MathLibSignBit(MathLibRef, x, &result); // return result; //} |
From: Mapi B. <ma...@us...> - 2009-07-05 20:52:54
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17289 Modified Files: DataManager.h FloatManager.h PalmOS.h Log Message: MathLib compatibility Index: FloatManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/FloatManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** FloatManager.h 24 Jun 2009 21:44:45 -0000 1.1 --- FloatManager.h 5 Jul 2009 20:52:48 -0000 1.2 *************** *** 6,38 **** #include "PalmOS.h" ! class FlpDoubleBits { ! public: UInt32 sign : 1; Int32 exp : 11; UInt32 manH : 20; UInt32 manL; ! FlpDoubleBits(void); ! ~FlpDoubleBits(void); ! }; ! class FlpCompDouble { ! public: double d; ! // FlpDouble fd; ! // Defined in Palm OS FloatMgr.h as: ! // typedef _sfpe_64_bits FlpDouble; ! // typedef struct { ! // SDWord high; ! // SDWord low; ! // } _sfpe_64_bits; ! // and SDWord is obviously a typedef from Int32. ! // Lets ignore that, it does not seem to be used anyway in EasyCalc core code. UInt32 ul[2]; FlpDoubleBits fdb; ! FlpCompDouble(void); ! ~FlpCompDouble(void); ! }; #endif \ No newline at end of file --- 6,50 ---- #include "PalmOS.h" ! typedef struct { UInt32 sign : 1; Int32 exp : 11; UInt32 manH : 20; UInt32 manL; + } FlpDoubleBits; ! // Inferring from definitions in Palm OS FloatMgr.h as, and the fact that Windows CE ! // supports only little endian, even on ARM platforms which are bi-endian. ! typedef unsigned int SDWord; ! typedef struct { ! SDWord low; ! SDWord high; ! } _sfpe_64_bits; ! typedef _sfpe_64_bits FlpDouble; ! typedef union { double d; ! FlpDouble fd; UInt32 ul[2]; FlpDoubleBits fdb; + } FlpCompDouble; ! // Inferring those ... ! #define __HI32(x) (x)->fd.high ! #define __LO32(x) (x)->fd.low ! #define __HIX 1 ! ! // Defined in Palm OS FloatMgr.h as: ! #define FlpIsZero(x) (((__HI32((FlpCompDouble *)&x) & 0x7fffffff) | (__LO32((FlpCompDouble *)&x))) == 0) ! #define FlpIsZero1(x) ((_fpclass(x) & (_FPCLASS_NZ | _FPCLASS_PZ)) != 0) ! #define FlpGetSign(x) ((__HI32((FlpCompDouble *)&x) & 0x80000000) != 0) ! #define FlpGetSign1(x) ((_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_NN | _FPCLASS_ND | _FPCLASS_NZ)) != 0) ! #define FlpGetExponent(x) (((__HI32((FlpCompDouble *)&x) & 0x7ff00000) >> 20) - 1023) ! // Can be replaced by a function using frexp() ! #define FlpNegate(x) (((FlpCompDouble *)&x)->ul[__HIX] ^= 0x80000000) ! #define FlpNegate1(x) (x = _chgsign(x)) ! #define FlpSetNegative(x) (((FlpCompDouble *)&x)->ul[__HIX] |= 0x80000000) ! #define FlpSetNegative1(x) (x = -fabs(x)) ! #define FlpSetPositive(x) (((FlpCompDouble *)&x)->ul[__HIX] &= ~0x80000000) ! #define FlpSetPositive1(x) (x = fabs(x)) #endif \ No newline at end of file Index: PalmOS.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/PalmOS.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PalmOS.h 24 Jun 2009 21:39:34 -0000 1.2 --- PalmOS.h 5 Jul 2009 20:52:48 -0000 1.3 *************** *** 35,44 **** #define IndexedColorType int ! #define StrCopy _tcscpy ! #define StrLen _tcslen ! #define StrNCompare _tcsncmp ! #define StrCompare _tcscmp ! #define StrCat _tcscat ! #define StrPrintF _stprintf #define MemPtrNew malloc --- 35,45 ---- #define IndexedColorType int ! #define StrCopy _tcscpy ! #define StrLen _tcslen ! #define StrNCompare _tcsncmp ! #define StrCompare _tcscmp ! #define StrCat _tcscat ! #define StrPrintF _stprintf ! #define StrIToA(s,i) _itot(i,s,10) #define MemPtrNew malloc *************** *** 64,67 **** --- 65,80 ---- #include "DataManager.h" + #include "FloatManager.h" + #include "Preferences.h" + + #include <stdlib.h> + #define SysRandom(x) (srand(x), rand()) + #define sysRandomMax RAND_MAX + unsigned long nan[2]={0xffffffff, 0x7fffffff}; + #define NaN (*((double *) nan)) + + #include <time.h> + #define TimGetSeconds() ((UInt32) time(NULL)) + #define ErrFatalDisplayIf(a,b) Index: DataManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DataManager.h 22 Jun 2009 21:57:16 -0000 1.1 --- DataManager.h 5 Jul 2009 20:52:48 -0000 1.2 *************** *** 36,39 **** --- 36,47 ---- }; + typedef struct { + UInt8 attributes; + UInt8 uniqueID[3]; + } SortRecordInfoType; + + typedef SortRecordInfoType *SortRecordInfoPtr; + + typedef DataManager *DmOpenRef; typedef void *LocalID; *************** *** 42,93 **** LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP); ! Err DmDatabaseInfo ( ! UInt16 cardNo, ! LocalID dbID, ! Char *nameP, ! UInt16 *attributesP, ! UInt16 *versionP, ! UInt32 *crDateP, ! UInt32 *modDateP, ! UInt32 *bckUpDateP, ! UInt32 *modNumP, ! LocalID appInfoIDP, ! LocalID sortInfoIDP, ! UInt32 *typeP, ! UInt32 *creatorP ! ); ! Err DmSetDatabaseInfo ( ! UInt16 cardNo, ! LocalID dbID, ! const Char *nameP, ! UInt16 *attributesP, ! UInt16 *versionP, ! UInt32 *crDateP, ! UInt32 *modDateP, ! UInt32 *bckUpDateP, ! UInt32 *modNumP, ! LocalID appInfoIDP, ! LocalID sortInfoIDP, ! UInt32 *typeP, ! UInt32 *creatorP ! ); DmOpenRef DmOpenDatabase (UInt16 cardNo, LocalID dbID, UInt16 mode); Err DmGetLastErr (void); ! Err DmCreateDatabase ( ! UInt16 cardNo, ! const Char *nameP, ! UInt32 creator, ! UInt32 type, ! Boolean resDB); Err DmCloseDatabase (DmOpenRef dbP); Err DmDeleteDatabase (UInt16 cardNo, LocalID dbID); UInt16 DmNumRecords (DmOpenRef dbP); MemHandle DmNewRecord (DmOpenRef dbP, UInt16 *atP, UInt32 size); ! Err DmWrite ( ! void *recordP, ! UInt32 offset, ! const void *srcP, ! UInt32 bytes ! ); Err DmRemoveRecord (DmOpenRef dbP, UInt16 index); MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index); --- 50,70 ---- LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP); ! Err DmDatabaseInfo (UInt16 cardNo, LocalID dbID, Char *nameP, UInt16 *attributesP, ! UInt16 *versionP, UInt32 *crDateP, UInt32 *modDateP, UInt32 *bckUpDateP, ! UInt32 *modNumP, LocalID appInfoIDP, LocalID sortInfoIDP, ! UInt32 *typeP, UInt32 *creatorP); ! Err DmSetDatabaseInfo (UInt16 cardNo, LocalID dbID, const Char *nameP, ! UInt16 *attributesP, UInt16 *versionP, UInt32 *crDateP, ! UInt32 *modDateP, UInt32 *bckUpDateP, UInt32 *modNumP, ! LocalID appInfoIDP, LocalID sortInfoIDP, UInt32 *typeP, ! UInt32 *creatorP); DmOpenRef DmOpenDatabase (UInt16 cardNo, LocalID dbID, UInt16 mode); Err DmGetLastErr (void); ! Err DmCreateDatabase (UInt16 cardNo, const Char *nameP, UInt32 creator, UInt32 type, Boolean resDB); Err DmCloseDatabase (DmOpenRef dbP); Err DmDeleteDatabase (UInt16 cardNo, LocalID dbID); UInt16 DmNumRecords (DmOpenRef dbP); MemHandle DmNewRecord (DmOpenRef dbP, UInt16 *atP, UInt32 size); ! Err DmWrite (void *recordP, UInt32 offset, const void *srcP, UInt32 bytes); Err DmRemoveRecord (DmOpenRef dbP, UInt16 index); MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index); |
From: Mapi B. <ma...@us...> - 2009-07-05 20:52:36
|
Update of /cvsroot/easycalc/PPCport In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17250 Modified Files: EasyCalc.vcproj Log Message: MathLib compatibility Index: EasyCalc.vcproj =================================================================== RCS file: /cvsroot/easycalc/PPCport/EasyCalc.vcproj,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** EasyCalc.vcproj 24 Jun 2009 21:38:50 -0000 1.4 --- EasyCalc.vcproj 5 Jul 2009 20:52:30 -0000 1.5 *************** *** 503,506 **** --- 503,514 ---- > </File> + <File + RelativePath=".\compat\MathLib.cpp" + > + </File> + <File + RelativePath=".\compat\Preferences.cpp" + > + </File> </Filter> </Filter> *************** *** 570,577 **** </File> <File - RelativePath=".\include\MathLib.h" - > - </File> - <File RelativePath=".\include\matrix.h" > --- 578,581 ---- *************** *** 646,652 **** --- 650,664 ---- </File> <File + RelativePath=".\compat\MathLib.h" + > + </File> + <File RelativePath=".\compat\PalmOS.h" > </File> + <File + RelativePath=".\compat\Preferences.h" + > + </File> </Filter> <Filter |
From: Mapi B. <ma...@us...> - 2009-06-24 21:44:48
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv18336 Added Files: FloatManager.h Log Message: 2nd upload, getting closer --- NEW FILE: FloatManager.h --- #pragma once #ifndef FLOAT_MANAGER_H #define FLOAT_MANAGER_H 1 #include "PalmOS.h" class FlpDoubleBits { public: UInt32 sign : 1; Int32 exp : 11; UInt32 manH : 20; UInt32 manL; FlpDoubleBits(void); ~FlpDoubleBits(void); }; class FlpCompDouble { public: double d; // FlpDouble fd; // Defined in Palm OS FloatMgr.h as: // typedef _sfpe_64_bits FlpDouble; // typedef struct { // SDWord high; // SDWord low; // } _sfpe_64_bits; // and SDWord is obviously a typedef from Int32. // Lets ignore that, it does not seem to be used anyway in EasyCalc core code. UInt32 ul[2]; FlpDoubleBits fdb; FlpCompDouble(void); ~FlpCompDouble(void); }; #endif |
From: Mapi B. <ma...@us...> - 2009-06-24 21:44:44
|
Update of /cvsroot/easycalc/PPCport/include In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv18171 Removed Files: calcDB.h fp.h Log Message: 2nd upload, getting closer --- fp.h DELETED --- --- calcDB.h DELETED --- |
From: Mapi B. <ma...@us...> - 2009-06-24 21:44:25
|
Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv18295 Added Files: calcDB.cpp calcDB.h fp.cpp fp.h Log Message: 2nd upload, getting closer --- NEW FILE: fp.h --- /* * $Id: fp.h,v 1.1 2009/06/24 21:44:22 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 _FP_H_ #define _FP_H_ void fp_setup_flpoint(void) PARSER; void fp_print_double(TCHAR *strP, double value) PARSER; void fp_print_g_double(TCHAR *s, double value, Int16 prec) PARSER; void fp_set_base(Tbase base) PARSER; TdispPrefs fp_set_prefs(TdispPrefs prefs) PARSER; Tdisp_mode fp_set_dispmode(Tdisp_mode newmode) PARSER; extern TCHAR flSpaceChar, flPointChar; #endif --- NEW FILE: fp.cpp --- /* * $Id: fp.cpp,v 1.1 2009/06/24 21:44:22 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999 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" #ifdef UNIX #define StrChr(x,y) strchr(x,y) #define StrCopy(x,y) strcpy(x,y) #define StrLen(x) strlen(x) #include <stdlib.h> #include <string.h> #else #include "compat/PalmOS.h" //#include <StringMgr.h> #include <MathLib.h> #endif #include "defuns.h" #include "display.h" #include "fp.h" #include "compat/FloatManager.h" static double SCI_LIMIT_MAX; /* Above this number show it as xEy */ static double SCI_LIMIT_MIN; /* Under this number show as xE-y */ //static double DISP_MIN_LIMIT = 1E-15; /* Show numbers as sin(pi) as 1E-16, // it's 0 */ //static double DISP_MAX_LIMIT = 1E300; /* Don't show bigger numbers, it // * makes problems */ static double BASE = 10.0; TCHAR flPointChar = _T('.'); TCHAR flSpaceChar = _T(' '); /* If the number is smaller, reduce the number of * decimal points, so we do not get something like * 9.999999987E-10 */ //static double REDUCE_PREC = 1E-6; #define REDUCE_TO 6 void fp_setup_flpoint(void) PARSER; void fp_setup_flpoint(void) { /* Set the floating 'point' to '.' or ',' */ switch (PrefGetPreference(prefNumberFormat)) { case nfCommaPeriod: flSpaceChar=_T(','); flPointChar=_T('.'); break; case nfApostrophePeriod: flSpaceChar=_T('\''); flPointChar=_T('.'); break; case nfPeriodComma: flSpaceChar=_T('.'); flPointChar=_T(','); break; case nfSpaceComma: flSpaceChar=_T(' '); flPointChar=_T(','); break; case nfApostropheComma: default: flSpaceChar=_T('\''); flPointChar=_T(','); break; } } /*********************************************************************** * * FUNCTION: fp_reread_prefs * * DESCRIPTION: Setups some maximum/miniums according to displayPrefs * * PARAMETERS: Nothing * * RETURN: Nothing * ***********************************************************************/ static void fp_reread_prefs(void) PARSER; static void fp_reread_prefs(void) { BASE = dispPrefs.base; switch (dispPrefs.mode) { case disp_normal: // SCI_LIMIT_MAX=1E10; SCI_LIMIT_MAX=pow(BASE,10); // SCI_LIMIT_MIN=1E-5; SCI_LIMIT_MIN=pow(BASE,-5); break; case disp_sci: case disp_eng: SCI_LIMIT_MAX=1.00; SCI_LIMIT_MIN=1.01; break; } // if (dispPrefs.reducePrecision) { // DISP_MIN_LIMIT = 1E-15; // REDUCE_PREC = 1E-6; // } else { // DISP_MIN_LIMIT = 1E-100; // REDUCE_PREC = 1E-90; // } } TdispPrefs fp_set_prefs(TdispPrefs prefs) PARSER; TdispPrefs fp_set_prefs(TdispPrefs prefs) { TdispPrefs oldprefs = dispPrefs; dispPrefs = prefs; fp_reread_prefs(); return oldprefs; } void fp_set_base(Tbase base) PARSER; void fp_set_base(Tbase base) { dispPrefs.base = base; fp_reread_prefs(); } Tdisp_mode fp_set_dispmode(Tdisp_mode newmode) PARSER; Tdisp_mode fp_set_dispmode(Tdisp_mode newmode) { Tdisp_mode oldmode = dispPrefs.mode; dispPrefs.mode = newmode; return oldmode; } /*********************************************************************** * * FUNCTION: cvt_fltoa * * DESCRIPTION: Convert a truncated float to ascii * * PARAMETERS: value * * RETURN: strP - converted value * ***********************************************************************/ static void cvt_fltoa(TCHAR *strP,double value) PARSER; static void cvt_fltoa(TCHAR *strP,double value) { TCHAR *cP; TCHAR tmpstr[MAX_FP_NUMBER+3]; Int16 i,ichar; if (value==0.0) { StrCopy(strP,_T("0")); return; } /* We convert the number backwards */ for (i=MAX_FP_NUMBER-2;i>=0;i--) { ichar = (Int16)fmod(value,BASE) + _T('0'); tmpstr[i] = ichar>_T('9')?ichar-_T('9')-1+_T('A'):ichar; value /= BASE; value=trunc(value); } tmpstr[MAX_FP_NUMBER-1] = _T('\0'); for( cP = tmpstr; *cP && (*cP == _T('0')); ) ++cP; StrCopy(strP,cP); } /*********************************************************************** * * FUNCTION: fp_print * * DESCRIPTION: Prints a double to string * * PARAMETERS: value * * RETURN: strP - converted value * ***********************************************************************/ static void fp_print(TCHAR *strP,double value,Int16 myfrac) PARSER; static void fp_print(TCHAR *strP,double value,Int16 myfrac) { Int16 i; double ipart; double fpart; double limit; TCHAR str[MAX_FP_NUMBER*2]; if (isinf(value)) { if (isinf(value)>0) StrCopy(strP,_T("+Inf")); else StrCopy(strP,_T("-Inf")); return; } if (!finite(value)) { StrCopy(strP,_T("NaN")); return; } if( value < 0.0 ) { *strP++ = _T('-'); value = -value; } ipart = trunc(value); value -= ipart; /* recover frac part */ for (limit = 1.0,i=myfrac; i> 0;i--) { value *= BASE; limit *= BASE; } value += 0.5; if( value >= limit ) { fpart = 0.0; /* overflowed */ ipart++; } else fpart = value; cvt_fltoa(strP,ipart); if (myfrac || !dispPrefs.stripZeros) { cvt_fltoa(str,fpart); strP += StrLen(strP); if (!dispPrefs.stripZeros && fpart < 1.0) { *strP++ = flPointChar; for (i = 0; i < myfrac; i++) { *strP++ = _T('0'); } *strP++ = _T('\0'); } if (dispPrefs.stripZeros) { /* remove trailing 0's */ for (i = StrLen(str)-1;i>=0 && str[i]==_T('0');i--) { str[i]=_T('\0'); myfrac--; } } if (StrLen(str)>0) { *strP++ = flPointChar; for(i=StrLen(str); i<myfrac;i++ ) *strP++ = _T('0'); /* need some padding at the beginning */ StrCopy(strP,str); /* and now the value */ } } } static const TCHAR expNames[] = {_T('f'),_T('p'),_T('n'),_T('u'),_T('m'),0,_T('k'),_T('M'),_T('G'),_T('T')}; static void fp_print_exp(TCHAR *str,Int16 expon) PARSER; static void fp_print_exp(TCHAR *str,Int16 expon) { Int16 i; if (dispPrefs.base == disp_decimal) { if (dispPrefs.mode == disp_eng && dispPrefs.cvtUnits) { i = expon/3 + 5; if (i<0 || i>9) StrPrintF(str,_T("E%d"),expon); else StrPrintF(str,_T("%c"),expNames[i]); } else StrPrintF(str,_T("E%d"),expon); } else StrPrintF(str, _T("*%d^%d"),(Int16)dispPrefs.base, expon); } /*********************************************************************** * * FUNCTION: fp_print_double * * DESCRIPTION: Function used for general number formatting according * all rules from dispPrefs, adds the 'E+-' things * for too big numbers, scientific & engineer purposes * * PARAMETERS: value * * RETURN: strP - converted value * ***********************************************************************/ void fp_print_double(TCHAR *strP,double value) PARSER; void fp_print_double(TCHAR *strP, double value) { Int16 ex; TCHAR tmpstr[MAX_FP_NUMBER*2]; if (!finite(value)) { /* Handle the NaN, +Inf & -Inf cases */ fp_print(strP,value,dispPrefs.decPoints); } // else if (fabs(value)>DISP_MAX_LIMIT) { // StrCopy(strP,_T("It's too big")); // } // else if (fabs(value)<DISP_MIN_LIMIT) { // /* Don't show too small numbers */ // fp_print(strP,0,dispPrefs.decPoints); // if (dispPrefs.mode!=disp_normal) // fp_print_exp(strP+StrLen(strP),0); // } else if (fabs(value)>=1 && dispPrefs.mode==disp_eng) { /* Engineer mode selected */ Int16 mydec = dispPrefs.decPoints - 1; for (ex=0;fabs(value)>=pow(BASE,3) || (ex % 3);ex++,value/=BASE) ; if (fabs(value) >= 100.0) mydec -= 2; else if (fabs(value) >= 10.0) mydec -= 1; if (mydec < 0) mydec = 0; fp_print(strP,value,mydec); fp_print_exp(tmpstr,ex); StrCat(strP,tmpstr); } else if (fabs(value)<1.0 && dispPrefs.mode==disp_eng) { Int16 mydec = dispPrefs.decPoints - 1; /* Engineer mode selected */ for (ex=0;fabs(value)<0.99999999 || (ex % 3);ex++,value*=BASE) ; if (fabs(value) >= 100.0) mydec -= 2; else if (fabs(value) >= 10.0) mydec -= 1; if (mydec < 0) mydec = 0; fp_print(strP,value,mydec); fp_print_exp(tmpstr,-ex); StrCat(strP,tmpstr); } else if (dispPrefs.base == disp_binary || dispPrefs.base == disp_octal || dispPrefs.base == disp_hexa) { if (fabs(value) > 1E14) StrCopy(strP,_T("Cannot display number.")); else fp_print(strP,value,dispPrefs.decPoints); } else if (fabs(value)>SCI_LIMIT_MAX) { /* Normal/Scientific mode */ for (ex=0;fabs(value)>=BASE;value/=BASE,ex++) ; fp_print(strP,value,dispPrefs.decPoints); fp_print_exp(tmpstr,ex); StrCat(strP,tmpstr); } else if(fabs(value)<SCI_LIMIT_MIN && fabs(value)>0) { /* Normal/Scientific mode */ for (ex=0;fabs(value)<0.99999999;value*=BASE,ex--) ; fp_print(strP,value,dispPrefs.decPoints); fp_print_exp(tmpstr,ex); StrCat(strP,tmpstr); } else { /* No special formatting required */ fp_print(strP,value,dispPrefs.decPoints); } } /*********************************************************************** * * FUNCTION: fp_print_g_double * * DESCRIPTION: Formats double numbers for output on the graph screen * using a Fortran like %g format. * The code is derived from the printDouble function in lispme: * http://www.lispme.de/lispme/gcc/tech.html#fpio * * PARAMETERS: s - output string * value - value to be formatted * * RETURN: nothing * ***********************************************************************/ /* Conversion constants */ static double pow1[] = { 1e256, 1e128, 1e064, 1e032, 1e016, 1e008, 1e004, 1e002, 1e001 }; static double pow2[] = { 1e-256, 1e-128, 1e-064, 1e-032, 1e-016, 1e-008, 1e-004, 1e-002, 1e-001 }; void fp_print_g_double(Char *s, double value, Int16 prec) PARSER; void fp_print_g_double(Char *s, double value, Int16 prec) { FlpCompDouble fcd; double round_factor; short e, e1, i; double *pd, *pd1; TCHAR sign = _T('\0'); short dec = 0; /* Check for reasonable value of prec. IEEE double. IEEE double * precision has about 16 significant decimal digits */ if (prec < 0 || prec > 16) prec = 7; /* Initialize round_factor */ round_factor = 0.5; for (i = 0; i < prec; i++) round_factor /= 10.0; /* Check for NaN, +Inf, -Inf, 0 */ fcd.d = value; if ((fcd.ul[0] & 0x7ff00000) == 0x7ff00000) { if (fcd.fdb.manH == 0 && fcd.fdb.manL == 0) { if (fcd.fdb.sign) StrCopy(s, _T("-Inf")); else StrCopy(s, _T("Inf")); } else { StrCopy(s, _T("NaN")); } return; } if (FlpIsZero(fcd)) { StrCopy(s, _T("0")); return; } /* Make positive and store sign */ if (FlpGetSign(fcd)) { *s++ = _T('-'); FlpSetPositive(fcd); value = fcd.d; } /* Compute round_factor */ if ((unsigned) fcd.fdb.exp < 0x3ff) { /* round_factor for value < 1.0 */ for (e = 1, e1 = 256, pd = pow1, pd1 = pow2; e1; e1 >>= 1, ++pd, ++pd1) { if (*pd1 > fcd.d) { e += e1; fcd.d *= *pd; round_factor *= *pd1; } } } else { /* round_factor for value >= 1.0 */ for (e = 0, e1 = 256, pd = pow1, pd1 = pow2; e1; e1 >>= 1, ++pd, ++pd1) { if (*pd <= fcd.d) { e += e1; fcd.d *= *pd1; round_factor *= *pd; } } round_factor *= 10.0; } fcd.d = value + round_factor; if ((unsigned) fcd.fdb.exp < 0x3ff) { /* Build negative exponent */ for (e = 1, e1 = 256, pd = pow1, pd1 = pow2; e1; e1 >>= 1, ++pd, ++pd1) { if (*pd1 > fcd.d) { e += e1; fcd.d = fcd.d * *pd; } } fcd.d = fcd.d * 10.0; /* Do not print exponent for the -0.xxxx case */ if (e <= 1) { *s++ = _T('0'); *s++ = _T('.'); dec = -1; } else sign = _T('-'); } else { /* Build positive exponent */ for (e = 0, e1 = 256, pd = pow1, pd1 = pow2; e1; e1 >>= 1, ++pd, ++pd1) { if (*pd <= fcd.d) { e += e1; fcd.d = fcd.d * *pd1; } } if (e < prec) dec = e; else sign = _T('+'); } /* Extract decimal digits of mantissa */ for (i = 0; i < prec; ++i, --dec) { Int32 d = fcd.d; *s++ = d + _T('0'); if (!dec) *s++ = _T('.'); fcd.d = fcd.d - (double)d; fcd.d = fcd.d * 10.0; } /* Remove trailing zeros and decimal point */ while (s[-1] == _T('0')) *--s = _T('\0'); if (s[-1] == _T('.')) *--s = _T('\0'); /* Append exponent */ if (sign) { *s++ = _T('E'); *s++ = sign; StrIToA(s, e); } else *s = _T('\0'); } --- NEW FILE: calcDB.cpp --- /* * $Id: calcDB.cpp,v 1.1 2009/06/24 21:44:22 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 <string.h> #include "defuns.h" #include "konvert.h" #include "calcDB.h" #include "stack.h" #include "dbutil.h" static DmOpenRef gDB; static Int16 CompareRecordFunc(dbPackedRecord *rec1,dbPackedRecord *rec2, Int16 unesedInt16,SortRecordInfoPtr unused1,SortRecordInfoPtr unused2, MemHandle appInfoH) MLIB; static Int16 CompareRecordFunc(dbPackedRecord *rec1,dbPackedRecord *rec2, Int16 unesedInt16,SortRecordInfoPtr unused1,SortRecordInfoPtr unused2, MemHandle appInfoH) { Int16 tmp; /* This will sort it somewhat intelligently, regardless of capitalized * letters */ tmp=StrCaselessCompare(rec1->name,rec2->name); if (tmp) return tmp; return StrCompare(rec1->name,rec2->name); } /*********************************************************************** * * FUNCTION: db_create_record * * DESCRIPTION: Create a record in a database, possibly overwriting * an existing one * * PARAMETERS: newRecord - pointer to a new record * size - size of a new record * * RETURN: Nothing * ***********************************************************************/ static CError db_create_record(dbPackedRecord *newRecord,UInt16 size) MLIB; static CError db_create_record(dbPackedRecord *newRecord,UInt16 size) { UInt16 recordNumber; MemHandle myRecordMemHandle; dbPackedRecord *newRecordPtr; CError err = c_noerror; recordNumber = DmFindSortPosition(gDB,newRecord,0, (DmComparF *)CompareRecordFunc,0); if (recordNumber > 0) { /* We might modify the record */ dbPackedRecord *record; MemHandle recordMemHandle; Int16 foundIt; recordMemHandle = DmQueryRecord(gDB,recordNumber - 1); record = (dbPackedRecord *) MemHandleLock(recordMemHandle); foundIt = StrCompare(newRecord->name,record->name) == 0; MemHandleUnlock(recordMemHandle); if (foundIt) { /* OK, we have to modify existing record */ MemHandle modRecord = DmGetRecord(gDB,recordNumber-1); /* resize the handle */ if (!MemHandleResize(modRecord,size)) { record = (dbPackedRecord *) MemHandleLock(modRecord); DmWrite(record,0,newRecord,size); MemHandleUnlock(modRecord); } else err = c_memory; DmReleaseRecord(gDB,recordNumber-1,true); return err; } } myRecordMemHandle = DmNewRecord(gDB,&recordNumber,size); if (myRecordMemHandle ) { newRecordPtr = (dbPackedRecord *) MemHandleLock(myRecordMemHandle); DmWrite(newRecordPtr,0,newRecord,size); MemHandleUnlock(myRecordMemHandle); DmReleaseRecord(gDB,recordNumber,true); /* Now the recordNumber contains real index */ } else err = c_memory; return err; } /*********************************************************************** * * FUNCTION: db_recompile_all * * DESCRIPTION: Recompiles functions stored in database and removes * functions where a recompile fails. It should be called * whenever a function is inserted into konvert.c * * PARAMETERS: None * * RETURN: Nothing * ***********************************************************************/ void db_recompile_all(void) { dbList *list; Int16 i; TCHAR *origtext; CError err; CodeStack *stack; TCHAR oldparam[MAX_FUNCNAME+1]; /* Save the default parameter name */ StrCopy(oldparam,parameter_name); list = db_get_list(function); for (i=0;i<list->size;i++) { err = db_func_description(list->list[i],&origtext,parameter_name); if (err) { db_delete_record(list->list[i]); continue; } stack = text_to_stack(origtext,&err); if (err) { MemPtrFree(origtext); db_delete_record(list->list[i]); continue; } db_write_function(list->list[i],stack,origtext); stack_delete(stack); MemPtrFree(origtext); } db_delete_list(list); StrCopy(parameter_name,oldparam); } /*********************************************************************** * * FUNCTION: db_write_function * * DESCRIPTION: Write a defined piece of code into database * * PARAMETERS: name - name of function * stack - compiled code * origtext - original uncompiled code * * RETURN: Nothing * ***********************************************************************/ CError db_write_function(const TCHAR *name,CodeStack *stack,TCHAR *origtext) MLIB; CError db_write_function(const TCHAR *name,CodeStack *stack,TCHAR *origtext) { dbPackedRecord *record; dbPackedStack *pstack; UInt16 psize,rsize; TCHAR *ptr; CError err; pstack = stack_pack(stack,&psize); record = (dbPackedRecord *) MemPtrNew(sizeof(*record)+psize+StrLen(origtext)+1); if (!record) return c_memory; record->type = function; StrCopy(record->name,name); memcpy(&record->u.stack,pstack,psize); StrCopy(record->u.stack.header.param_name,parameter_name); // ptr = &record->u.stack.data; ptr = record->u.stack.data; ptr += record->u.stack.header.orig_offset; StrCopy(ptr,origtext); rsize = sizeof(*record)+psize+StrLen(origtext)+1; rsize -= sizeof(dbStackItem)>sizeof(dbPackedStack)?sizeof(dbStackItem):sizeof(dbPackedStack); err = db_create_record(record,rsize); MemPtrFree(record); MemPtrFree(pstack); return err; } /*********************************************************************** * * FUNCTION: db_read_function * * DESCRIPTION: Read a compiled function from database * * PARAMETERS: name - name of the function * * RETURN: CodeStack - compiled code * err - error code or 0 * ***********************************************************************/ CodeStack * db_read_function(const TCHAR *name,CError *err) MLIB; CodeStack * db_read_function(const TCHAR *name,CError *err) { dbPackedRecord *record; CodeStack *result; *err = c_noerror; record = db_read_record(name); if (!record || record->type!=function) { if (record) MemPtrFree(record); *err = c_notvar; return NULL; } result = stack_unpack(&record->u.stack); MemPtrFree(record); return result; } /*********************************************************************** * * FUNCTION: db_write_variable * * DESCRIPTION: Write variable to database * * PARAMETERS: name - name of the variable * contents - the value of the variable * * RETURN: Nothing * ***********************************************************************/ CError db_write_variable(const TCHAR *name,Trpn contents) MLIB; CError db_write_variable(const TCHAR *name,Trpn contents) { dbPackedRecord *record; dbStackItem *packitem; UInt16 adatalen; /* Additional data size */ CError err; packitem = rpn_pack_record(contents); if(!packitem) return c_memory; adatalen = packitem->datasize; record = (dbPackedRecord *) MemPtrNew(sizeof(*record) + adatalen); if (!record) { MemPtrFree(packitem); return c_memory; } record->type = variable; StrCopy(record->name,name); memcpy(record->u.data,packitem,sizeof(*packitem)+adatalen); MemPtrFree(packitem); err = db_create_record(record,sizeof(*record)+adatalen); MemPtrFree(record); return err; } /*********************************************************************** * * FUNCTION: db_read_variable * * DESCRIPTION: Read a variable value from database * * PARAMETERS: name - name of the requested variable * * RETURN: Trpn - value of the variable * err - error code or zero * ***********************************************************************/ Trpn db_read_variable(const TCHAR *name,CError *err) MLIB; Trpn db_read_variable(const TCHAR *name,CError *err) { Trpn result; dbPackedRecord *record; *err = c_noerror; record = db_read_record(name); if (!record || record->type!=variable) { if (record) MemPtrFree(record); *err = c_notvar; return result; } result = rpn_unpack_record(record->u.data); MemPtrFree(record); return result; } /*********************************************************************** * * FUNCTION: db_delete_list * * DESCRIPTION: Free memory allocated by list * * PARAMETERS: list - list to free * * RETURN: Nothing * ***********************************************************************/ void db_delete_list(dbList *list) { Int16 i; for (i=0;i<list->size;i++) MemPtrFree(list->list[i]); if (list->type) MemPtrFree(list->type); MemPtrFree(list); } /*********************************************************************** * * FUNCTION: db_get_list * * DESCRIPTION: Creates a dynamic list of all requested records * * PARAMETERS: type - type of records to build a list * or 0 for all types * * RETURN: dbList - array of all records of given type * ***********************************************************************/ dbList * db_get_list(rpntype type) { UInt16 totalItems = DmNumRecords(gDB); UInt16 count,i; MemHandle recordHandle; dbPackedRecord *record; dbList *result; result = (dbList *) MemPtrNew(sizeof(dbList)+totalItems*sizeof(result->list[0])); result->type = (rpntype *) MemPtrNew(sizeof(result->type[0])*totalItems); for (i=0,count=0;i<totalItems;i++) { recordHandle = DmQueryRecord(gDB,i); record = (dbPackedRecord *) MemHandleLock(recordHandle); if (!type || record->type == type || (record->type == variable && record->u.data[0].rpn.type == type)) { result->type[count] = record->type; result->list[count] = (TCHAR *) MemPtrNew(StrLen(record->name)+1); StrCopy(result->list[count],record->name); count++; } MemHandleUnlock(recordHandle); } result->size = count; return result; } /*********************************************************************** * * FUNCTION: db_func_description * * DESCRIPTION: Return function pre-compilation text * * PARAMETERS: funcname - name of the requested function * * RETURN: CError - c_noerror on success * dest - pointer to a dynamically allocated chunk of memory * param - parameter name ('x'), that was used for compialtion * ***********************************************************************/ CError db_func_description(const TCHAR *funcname,TCHAR **dest,TCHAR *param) MLIB; CError db_func_description(const TCHAR *funcname,TCHAR **dest,TCHAR *param) { dbPackedRecord *tmp; tmp = db_read_record(funcname); if (!tmp) return c_notvar; if (tmp->type != function) { MemPtrFree(tmp); return c_badarg; } *dest = (TCHAR *) MemPtrNew(StrLen(&tmp->u.stack.data[tmp->u.stack.header.orig_offset])+1); StrCopy(*dest,&tmp->u.stack.data[tmp->u.stack.header.orig_offset]); if (param) StrCopy(param,tmp->u.stack.header.param_name); MemPtrFree(tmp); return c_noerror; } void db_save_real(const TCHAR *name, double number) { CodeStack *stack; Trpn item; stack = stack_new(1); stack_add_val(stack,&number,real); item = stack_pop(stack); stack_delete(stack); db_write_variable(name,item); rpn_delete(item); } /*********************************************************************** * * FUNCTION: db_read_record * * DESCRIPTION: Reads a record from a database * * PARAMETERS: name - name of the record (variable or function) * * RETURN: pointer to a dynamical record or NULL on error * ***********************************************************************/ dbPackedRecord * db_read_record(const TCHAR *name) MLIB; dbPackedRecord * db_read_record(const TCHAR *name) { UInt16 recordNumber; Int16 foundIt=0; dbPackedRecord tmp; StrCopy(tmp.name,name); recordNumber=DmFindSortPosition(gDB,&tmp,0, (DmComparF *)CompareRecordFunc,0); if (recordNumber >0) { MemHandle theRecordMemHandle; dbPackedRecord *record; theRecordMemHandle = DmQueryRecord(gDB,recordNumber - 1); record = (dbPackedRecord *) MemHandleLock(theRecordMemHandle); foundIt = StrCompare(name,record->name)==0; if (foundIt) { dbPackedRecord *result; result = MemPtrNew(MemHandleSize(theRecordMemHandle)); if (result) memcpy(result,record,MemHandleSize(theRecordMemHandle)); MemHandleUnlock(theRecordMemHandle); return result; } MemHandleUnlock(theRecordMemHandle); } return NULL; } /*********************************************************************** * * FUNCTION: db_record_exists * * DESCRIPTION: Check, if there is a corresponding record in the * database * * PARAMETERS: name - name of the record * * RETURN: true - record exists, otherwise false * ***********************************************************************/ Boolean db_record_exists(const TCHAR *name) MLIB; Boolean db_record_exists(const TCHAR *name) { UInt16 recordNumber; bool foundIt=false; dbPackedRecord tmprec; StrCopy(tmprec.name,name); recordNumber=DmFindSortPosition(gDB,&tmprec,0, (DmComparF *)CompareRecordFunc,0); if (recordNumber >0) { MemHandle theRecordMemHandle; dbPackedRecord *record; theRecordMemHandle = DmQueryRecord(gDB,recordNumber - 1); record = (dbPackedRecord *) MemHandleLock(theRecordMemHandle); foundIt = (StrCompare(tmprec.name,record->name)==0); MemHandleUnlock(theRecordMemHandle); } return foundIt; } /*********************************************************************** * * FUNCTION: db_delete_record * * DESCRIPTION: Deletes a record of a given name from the database * * PARAMETERS: name - name of the record * * RETURN: true - record existed in database * false - there was no such record * ***********************************************************************/ Int16 db_delete_record(const TCHAR *name) MLIB; Int16 db_delete_record(const TCHAR *name) { UInt16 recordNumber; Int16 foundIt=0; dbPackedRecord tmprec; StrCopy(tmprec.name,name); recordNumber=DmFindSortPosition(gDB,&tmprec,0, (DmComparF *)CompareRecordFunc,0); if (recordNumber >0) { MemHandle theRecordMemHandle; dbPackedRecord *record; theRecordMemHandle = DmQueryRecord(gDB,recordNumber - 1); record = (dbPackedRecord *) MemHandleLock(theRecordMemHandle); foundIt = StrCompare(tmprec.name,record->name)==0; MemHandleUnlock(theRecordMemHandle); if (foundIt) DmRemoveRecord(gDB,recordNumber-1); } return foundIt; } /*********************************************************************** * * FUNCTION: db_open * * DESCRIPTION: Open a main database for EasyCalc, creates a new one, * if there isn't such a database or if the old database * is bad version * * PARAMETERS: Nothing * * RETURN: 0 - on success * other - on error * ***********************************************************************/ Int16 db_open() MLIB; Int16 db_open() { return open_db(DBNAME, DBVERSION, LIB_ID, DBTYPE, &gDB); } Int16 db_close() MLIB; Int16 db_close() { return DmCloseDatabase(gDB); } --- NEW FILE: calcDB.h --- /* * $Id: calcDB.h,v 1.1 2009/06/24 21:44:22 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999 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 _CALCDB_H_ #define _CALCDB_H_ #include "compat/PalmOS.h" #include "konvert.h" typedef struct { Int16 size; rpntype *type; TCHAR **list; /* Do not add anything here, it gets overwritten */ }dbList; typedef struct { Int16 count; Int16 orig_offset; TCHAR param_name[MAX_FUNCNAME+1]; }dbStackHeader; typedef struct { Trpn rpn; UInt16 datasize; /* size of additional packed data */ TCHAR *data; }dbStackItem; typedef struct { dbStackHeader header; TCHAR *data; }dbPackedStack; typedef struct { rpntype type; /* This can be ONLY variable/function, nothing else can be * stored in databases */ TCHAR name[MAX_FUNCNAME+1]; union { dbStackItem data[1]; /* Variable */ dbPackedStack stack; }u; }dbPackedRecord; CError db_write_function(const TCHAR *name,CodeStack *stack,TCHAR *origtext) MLIB; CodeStack * db_read_function(const TCHAR *name,CError *err) MLIB; CError db_write_variable(const TCHAR *name,Trpn contents) MLIB; Trpn db_read_variable(const TCHAR *name,CError *err) MLIB; CError db_func_description(const TCHAR *funcname,TCHAR **dest,TCHAR *param) MLIB; dbPackedRecord * db_read_record(const TCHAR *name) MLIB; Int16 db_delete_record(const TCHAR *name) MLIB; void db_recompile_all(void) MLIB; Int16 db_open() MLIB; Int16 db_close() MLIB; Boolean db_record_exists(const TCHAR *name) MLIB; void db_delete_list(dbList *list) MLIB; dbList * db_get_list(rpntype type) MLIB; void db_save_real(const TCHAR *name, double number) MLIB; #endif |
From: Mapi B. <ma...@us...> - 2009-06-24 21:43:28
|
Update of /cvsroot/easycalc/PPCport/discarded In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17828 Added Files: calc.cpp calc.h Log Message: 2nd upload, getting closer --- NEW FILE: calc.cpp --- /* * $Id: calc.cpp,v 1.1 2009/06/24 21:40:25 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...'. * * Antonio Fiol Bonnín" <Ant...@en...> submitted patches * for the financial part. * * 2003-05-19 - Arno Welzel - added code for Sony Clie support */ #include <PalmOS.h> #include <StringMgr.h> #include <stdio.h> #include "about.h" #ifdef SONY_SDK #include <SonyCLIE.h> #endif #ifdef HANDERA_SDK #include "Vga.h" #endif #include "clie.h" #include "defuns.h" #include "calc.h" #include "calcDB.h" #include "result.h" #include "defmgr.h" #include "calcrsc.h" #include "graph.h" #include "finance.h" #include "varmgr.h" #include "prefs.h" #include "memo.h" #include "main.h" #include "history.h" #include "fp.h" #include "lstedit.h" #include "mtxedit.h" #include "chkstack.h" #ifdef SPECFUN_ENABLED #include "solver.h" #endif #ifdef GRAPHS_ENABLED #include "grprefs.h" #include "grsetup.h" #include "graph.h" #include "grtable.h" #endif /* GRAPH_ENABLED */ #ifdef SUPPORT_DIA #include "DIA.h" #endif Boolean palmOS3=false; Boolean palmOS35=false; Boolean handera=false; Boolean colorDisplay=false; Boolean grayDisplay=false; void *GetObjectPtr(UInt16 objectID) { FormPtr frm; frm=FrmGetActiveForm(); return (FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,objectID))); } void gadget_bounds(FormType *frm, Int16 gadget, RectangleType *natbounds, RectangleType *stdbounds) { UInt16 index = FrmGetObjectIndex(frm, gadget); FrmGetObjectBounds(frm, index, stdbounds); RctCopyRectangle(stdbounds, natbounds); // If Sony HR Lib is available, adjust coordinates for high resolution #ifdef SONY_SDK if(gHrMode == hrSony) { natbounds->topLeft.x = natbounds->topLeft.x*2 +2; natbounds->topLeft.y *= 2; natbounds->extent.x *= 2; natbounds->extent.y *= 2; } #endif if(gHrMode == hrPalm) { UInt16 save; save = WinSetCoordinateSystem(kCoordinatesNative); WinScaleRectangle(natbounds); WinSetCoordinateSystem(save); natbounds->topLeft.x+=2; } natbounds->extent.x++; natbounds->extent.y++; } static void calc_init_application() { prefs_read_preferences(); } /* Change to the next screen */ void GotHardKey(void) { UInt16 formId = 0; switch (FrmGetActiveFormID()) { case frmBasic: case frmBasicS: formId = frmScientific; break; case frmScientific: formId = frmInteger; break; case frmInteger: #ifdef GRAPHS_ENABLED formId = frmGraph; #else if (calcPrefs.dispScien) formId = frmBasicS; else formId = frmBasic; #endif break; case frmGraph: if (calcPrefs.dispScien) formId = frmBasicS; else formId = frmBasic; break; default: } if (formId) ChangeForm(formId); } /* Generic button action - actions for buttons on all screens */ Int16 chooseForm(Int16 button) { Boolean handled = true; switch (button) { case hlpMain2: doHelp(hlpMain2T, hlpMain2); break; case hlpFunc: doHelp(hlpFuncT, hlpFunc); break; case mitCredits: doHelp(strCreditsT, strCredits); break; case mitAbout: doAbout(hlpMain1); break; case btnInteger: ChangeForm(frmInteger); break; case btnBasic: if (calcPrefs.dispScien) ChangeForm(frmBasicS); else ChangeForm(frmBasic); break; case btnScientific: ChangeForm(frmScientific); break; #ifdef GRAPHS_ENABLED case btnGraph: ChangeForm(frmGraph); break; #endif default: handled = false; } return handled; } Boolean calc_rom_greater(UInt16 major, UInt16 minor) { UInt32 romVersion; UInt16 maj; UInt16 min; FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); maj = sysGetROMVerMajor(romVersion); min = sysGetROMVerMinor(romVersion); if (maj > major) return true; else if ((maj == major) && (min >= minor)) return true; return false; } static Err StartApplication(void) { Err error; UInt32 version, attr; /* Get version of PalmOS */ palmOS3 = calc_rom_greater(3,0); /* for stack check */ palmOS35 = calc_rom_greater(3,5); /* for color/grayscale support */ /* Get stack boundaries */ initChkStack(); /* Are we on a Handera ? */ #ifdef HANDERA_SDK if (FtrGet(TRGSysFtrID, TRGVgaFtrNum, &version) == errNone) handera = true; #endif gHrMode = hrNone; FtrGet(sysFtrCreator, sysFtrNumWinVersion, &version); if (version >= 4) { WinScreenGetAttribute(winScreenDensity, &attr); if (attr > kDensityLow) gHrMode = hrPalm; } #ifdef SONY_SDK gHrLibApiVersion = GetHRLibVersion(&gHrLibRefNum); // HR Lib available? if (gHrLibApiVersion && gHrMode == hrNone) { UInt32 width,height,depth; HROpen(gHrLibRefNum); // Open HR Lib width = hrWidth; height = hrHeight; depth = 8; /* Following call fails for grayscale HiRes devices. * Taken care of below in the 'if (palmOS35)' part */ HRWinScreenMode(gHrLibRefNum, winScreenModeSet, &width, &height, &depth, NULL); gHrMode = hrSony; gSonyFactor = 2; } #endif if (palmOS35){ WinScreenMode(winScreenModeGet,NULL,NULL,NULL,&colorDisplay); if (!colorDisplay){ UInt32 depth=4; #ifdef SONY_SDK if (gHrMode == hrSony){ /* Set Sony Hires grayscale devices to HiRes */ UInt32 width = hrWidth; UInt32 height = hrHeight; if (!HRWinScreenMode(gHrLibRefNum, winScreenModeSet, &width, &height, &depth, NULL)) grayDisplay = true; } else #endif if (!WinScreenMode(winScreenModeSet,NULL,NULL,&depth,NULL)) grayDisplay=true; } } /* Initialize all modules */ if (mlib_init_mathlib()) return 1; #ifdef SUPPORT_DIA InitializeResizeSupport(resize_index); LoadResizePrefs(APP_ID, PREF_DIA); #endif error = db_open(); ErrFatalDisplayIf(error, "Can't open CalcDB"); error = history_open(); ErrFatalDisplayIf(error, "Can't open History DB"); calc_init_application(); /* also calls FrmGotoForm */ fp_setup_flpoint(); #ifdef GRAPHS_ENABLED grpref_init(); #endif return 0; } static void StopApplication(void) { FrmSaveAllForms(); FrmCloseAllForms(); /* close all modules */ result_destroy(); mlib_close_mathlib(); prefs_save_preferences(); db_close(); history_close(); #ifdef GRAPHS_ENABLED grpref_close(); #endif #ifdef SUPPORT_DIA SaveResizePrefs(APP_ID, PREF_DIA, PREF_DIA_VERSION); TerminateResizeSupport(); #endif #ifdef SONY_SDK if (gHrMode == hrSony) { /* Set screen back to defaults and close HR library */ HRWinScreenMode(gHrLibRefNum, winScreenModeSetToDefaults, NULL, NULL, NULL, NULL); HRClose(gHrLibRefNum); } #endif } char * print_error(CError err) { char *res; res = MemPtrNew(MAX_RSCLEN); SysStringByIndex(strErrCodes,err,res,MAX_RSCLEN-1); return res; } void alertErrorMessage(CError err) { Char *txt; txt = print_error(err); FrmCustomAlert(altErrorMsg, txt, NULL, NULL); MemPtrFree(txt); } void ChangeForm(Int16 formID) { Int16 activefrm = FrmGetActiveFormID(); if (activefrm==formID) return; FrmGotoForm(formID); } static WinHandle saved_window; void wait_draw(void) { RectangleType rec,frame; UInt16 error; frame.topLeft.x = 50; frame.topLeft.y = 50; frame.extent.x = 60; frame.extent.y = 20; rec.topLeft.x = 48; rec.topLeft.y = 48; rec.extent.x = 64; rec.extent.y = 24; saved_window = WinCreateOffscreenWindow(rec.extent.x,rec.extent.y, nativeFormat,&error); /* Save the screen */ WinCopyRectangle(NULL,saved_window,&rec,0,0,winPaint); WinEraseRectangle(&rec,2); WinDrawRectangleFrame(boldRoundFrame,&frame); WinDrawChars("Please wait...",14,55,55); } void wait_erase(void) { RectangleType rec; rec.topLeft.x = 0; rec.topLeft.y = 0; rec.extent.x = 64; rec.extent.y = 24; WinCopyRectangle(saved_window,NULL,&rec,48,48,winPaint); WinDeleteWindow(saved_window,0); } static Boolean ApplicationHandleEvent(EventPtr event) { FormPtr frm; Int16 formId; Boolean handled = false; if (event->eType == frmLoadEvent) { formId = event->data.frmLoad.formID; // Load the form resource specified in the event then activate it, // except for the About and Help forms which are already loaded. if (formId != frmAbout && formId != frmHelp) frm = FrmInitForm(formId); else frm = FrmGetFormPtr(formId); FrmSetActiveForm(frm); // Set the event handler for the form. The handler of the currently // active form is called by FrmDispatchEvent each time it is called switch (formId) { #ifdef GRAPHS_ENABLED case grSetupForm: FrmSetEventHandler(frm,GraphSetupHandleEvent); break; case grPrefForm: FrmSetEventHandler(frm,GraphPrefsHandleEvent); break; case grTableForm: FrmSetEventHandler(frm,GraphTableHandleEvent); break; case frmGraph: #ifdef SUPPORT_DIA SetResizePolicy(formId); #endif FrmSetEventHandler(frm,GraphFormHandleEvent); break; #endif /* GRAPHS_ENABLED */ case frmAbout: case frmHelp: #ifdef SUPPORT_DIA SetResizePolicy(formId); #endif FrmSetEventHandler(frm,aboutEventHandler); break; case prefForm: FrmSetEventHandler(frm,PreferencesHandleEvent); break; case frmInteger: case frmBasic: case frmBasicS: case frmScientific: FrmSetEventHandler(frm, MainFormHandleEvent); break; case defForm: FrmSetEventHandler(frm, DefmgrHandleEvent); break; case finForm: FrmSetEventHandler(frm, FinHandleEvent); break; case varEntryForm: FrmSetEventHandler(frm,VarmgrEntryHandleEvent); break; case memoImportForm: FrmSetEventHandler(frm,MemoImportHandleEvent); break; #ifdef SPECFUN_ENABLED case slvForm: FrmSetEventHandler(frm, SolverHandleEvent); break; case frmListEdit: FrmSetEventHandler(frm,ListEditHandleEvent); break; case frmMatrix: FrmSetEventHandler(frm,MatrixHandleEvent); break; #endif } handled = true; } return handled; } Int32 evtTimeout = evtWaitForever; void calc_nil_timeout(Int32 timeout) { evtTimeout = timeout; } /* Allow some hardkeys to track graphs through */ Boolean hard_key_to_pass_through(EventPtr event) { return (FrmGetActiveFormID() == frmGraph && CtlGetValue(GetObjectPtr(btnGraphTrack)) && TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr) && ((event->data.keyDown.chr == vchrHard2) || (event->data.keyDown.chr == vchrHard3))); } static void EventLoop(void) { EventType event; UInt16 error; do { EvtGetEvent(&event, evtTimeout); /* Only the button assigned to EasyCalc should switch modes */ if (hard_key_to_pass_through(&event) || ! SysHandleEvent(&event)) { if (event.eType == keyDownEvent && TxtCharIsHardKey(event.data.keyDown.modifiers, event.data.keyDown.chr) && ! (event.data.keyDown.modifiers & poweredOnKeyMask) && ! (hard_key_to_pass_through(&event))) GotHardKey(); else if (! MenuHandleEvent(0, &event, &error)) if (! ApplicationHandleEvent(&event)) FrmDispatchEvent(&event); } } while (event.eType != appStopEvent); } UInt32 PilotMain(UInt16 launchCode, MemPtr cmdPBP, UInt16 launchFlags) { Err err=0; if (launchCode == sysAppLaunchCmdNormalLaunch) { if ((err = StartApplication()) == 0) { EventLoop(); StopApplication(); } } #ifdef SUPPORT_DIA else if (launchCode == sysAppLaunchCmdNotify) { HandleResizeNotification(((SysNotifyParamType *)cmdPBP)->notifyType); } #endif else return sysErrParamErr; return err; } --- NEW FILE: calc.h --- /* * $Id: calc.h,v 1.1 2009/06/24 21:40:25 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 _CALC_H_ #define _CALC_H_ void *GetObjectPtr(UInt16 objectID); void GotHardKey(void); Int16 chooseForm(Int16 button); void alertErrorMessage(CError err); void ChangeForm(Int16 formID); void wait_draw(void); void wait_erase(void); void calc_nil_timeout(Int32 timeout); Int16 calc_input_exec(void); void gadget_bounds(FormType *frm, Int16 gadget, RectangleType *natbounds, RectangleType *stdbounds); extern Boolean palmOS3; extern Boolean palmOS35; extern Boolean handera; extern Boolean colorDisplay; extern Boolean grayDisplay; #endif |
From: Mapi B. <ma...@us...> - 2009-06-24 21:42:21
|
Update of /cvsroot/easycalc/PPCport/system - UI In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv18060 Modified Files: Skin.cpp Skin.h Log Message: 2nd upload, getting closer Index: Skin.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/system - UI/Skin.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Skin.h 22 Jun 2009 22:13:35 -0000 1.1 --- Skin.h 24 Jun 2009 21:42:12 -0000 1.2 *************** *** 146,149 **** --- 146,150 ---- int gets(char *buf, int buflen); int make_dib(HDC hdc); + TCHAR *print_error(CError err); public: *************** *** 182,185 **** --- 183,187 ---- int resultActionsPopup(resSelection choices[], int length); void display_set_enabled(bool enable); + void alertErrorMessage(CError err); }; Index: Skin.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/system - UI/Skin.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Skin.cpp 22 Jun 2009 22:13:35 -0000 1.1 --- Skin.cpp 24 Jun 2009 21:42:12 -0000 1.2 *************** *** 1323,1325 **** --- 1323,1344 ---- void Skin::display_set_enabled(bool enable) { display_enabled = enable; + } + + /******************************************************************************** + * Print a system error on screen. * + ********************************************************************************/ + TCHAR *print_error(CError err) { + TCHAR *res; + + res = MemPtrNew(MAX_RSCLEN); + SysStringByIndex(strErrCodes,err,res,MAX_RSCLEN-1); + return (res); + } + + void alertErrorMessage(CError err) { + Char *txt; + + txt = print_error(err); + FrmCustomAlert(altErrorMsg, txt, NULL, NULL); + MemPtrFree(txt); } \ No newline at end of file |
From: Mapi B. <ma...@us...> - 2009-06-24 21:41:54
|
Update of /cvsroot/easycalc/PPCport/include In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv17989 Modified Files: cmatrix.h complex.h dbutil.h defuns.h integ.h mathem.h matrix.h meqstack.h segment.h slist.h specfun.h txtask.h Log Message: 2nd upload, getting closer |