Update of /cvsroot/easycalc/PPCport/core/mlib In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv24055/mlib Added Files: display.cpp display.h funcs.cpp funcs.h history.cpp history.h konvert.cpp konvert.h stack.cpp stack.h Log Message: 2nd upload, getting closer --- NEW FILE: display.h --- /* * $Id: display.h,v 1.1 2009/06/22 22:04:26 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 _DISPLAY_H_ #define _DISPLAY_H_ #include "konvert.h" typedef enum { disp_decimal=10, disp_hexa=16, disp_octal=8, disp_binary=2 }Tbase; typedef enum { disp_normal, disp_sci, disp_eng }Tdisp_mode; typedef struct { Int8 decPoints; Boolean stripZeros; Tdisp_mode mode; Tbase base; Boolean forceInteger; Boolean cvtUnits; }TdispPrefs; TCHAR * display_real(double number) MLIB; 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; #endif --- NEW FILE: konvert.cpp --- /* * $Id: konvert.cpp,v 1.1 2009/06/22 22:04:26 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999,2000,2001,2002 Ondrej Palkovsky * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, [...1179 lines suppressed...] if (IS_FUNC_1LETTER(defined_funcs[i].name[0])) (*count)++; names = (TCHAR **) MemPtrNew(*count * sizeof(*names)); for (i=0,j=0;defined_funcs[i].name[0];i++) if (IS_FUNC_1LETTER(defined_funcs[i].name[0])) names[j++]=(TCHAR *)defined_funcs[i].name; /* Shell sort the array */ for (gap = *count/2;gap > 0; gap/=2) for (i = gap;i < *count;i++) for (j=i-gap;j>=0 && StrCompare(names[j],names[j+gap])>0; j-=gap) { temp = names[j]; names[j] = names[j+gap]; names[j+gap] = temp; } return names; } --- NEW FILE: display.cpp --- /* * $Id: display.cpp,v 1.1 2009/06/22 22:04:26 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 "calc.h" #include "mathem.h" #include "display.h" #include "defuns.h" #include "funcs.h" #include "prefs.h" #include "fp.h" #include "stack.h" #include "MathLib.h" TdispPrefs dispPrefs; /*********************************************************************** * * FUNCTION: display_complex * * DESCRIPTION: Return a textualy formated complex number * * NOTE; Returns a dynamically allocated structure, * it must be freed after use * * PARAMETERS: number * * RETURN: textualy formated number * ***********************************************************************/ char * display_complex(Complex number) { char *result; result = MemPtrNew(dispPrefs.decPoints*2+45); result[0] = '\0'; if (number.real != 0.0 || number.imag==0.0) { fp_print_double(result,number.real); if (number.imag > 0.0 && finite(number.imag)) StrCat(result,"+"); } if (number.imag != 0.0 && !isnan(number.imag)) { fp_print_double(result+StrLen(result),number.imag); StrCat(result,"i"); } return result; } /*********************************************************************** * * FUNCTION: double_real * * DESCRIPTION: Return a nicely formatted real number * * NOTE: Result is a dynamically allocated text! * * PARAMETERS: number * * RETURN: formatted text * ***********************************************************************/ char * display_real(double number) { char *result; result = MemPtrNew(dispPrefs.decPoints+64); /* The ipart shouldn't be more then 10 */ fp_print_double(result,number); return result; } Char * display_integer(UInt32 number, Tbase mode) { Int16 base; Int16 i, j; Int32 signednum; Char *result, *result1, tmp; result = MemPtrNew(33); /* 32 bits + '\0' */ result1 = result; /* result1 points to digits after possible '-' sign */ switch (mode) { case disp_binary: base=2; break; case disp_octal: base=8; break; case disp_hexa: base=16; break; case disp_decimal: default: /* for decimal display signed number */ if ((signednum = number) < 0) { number = -number; *result = '-'; result1 = result + 1; } base=10; break; } for (i=0; number; i++, number /= base) if ((number % base) < 10) result1[i]='0'+(number % base); else result1[i]='A'+(number % base) - 10; result1[i]='\0'; /* Reverse the string */ for (j = 0, i--; j < i; j++, i--) { tmp = result1[i]; result1[i] = result1[j]; result1[j] = tmp; } if (StrLen(result) == 0) StrCopy(result,"0"); return result; } char * display_list(List *list) { char *result,*tmp; Int16 i; result = MemPtrNew((UInt32)(dispPrefs.decPoints*2+10)*list->size + 10); if (!result) { alertErrorMessage(c_memory); return NULL; } StrCopy(result,"["); for (i=0;i<list->size;i++) { tmp = display_complex(list->item[i]); StrCat(result,tmp); StrCat(result,":"); MemPtrFree(tmp); } /* Cut off the last ':' */ result[StrLen(result)-1] = '\0'; StrCat(result,"]"); return result; } char * display_matrix(Matrix *m) { Int16 i,j; char *result,*tmp; result = MemPtrNew((dispPrefs.decPoints+15)*m->rows*m->cols + 10); StrPrintF(result,"["); for (i=0;i<m->rows;i++) { if (i) StrCat(result,":"); StrCat(result,"["); for (j=0;j<m->cols;j++) { if (j) StrCat(result,":"); tmp = display_real(MATRIX(m,i,j)); StrCat(result,tmp); MemPtrFree(tmp); } StrCat(result,"]"); } StrCat(result,"]"); return result; } char * display_cmatrix(CMatrix *m) { Int16 i,j; char *result,*tmp; result = MemPtrNew((dispPrefs.decPoints+15)*m->rows*m->cols*2 + 10); StrPrintF(result,"["); for (i=0;i<m->rows;i++) { if (i) StrCat(result,":"); StrCat(result,"["); for (j=0;j<m->cols;j++) { if (j) StrCat(result,":"); tmp = display_complex(MATRIX(m,i,j)); StrCat(result,tmp); MemPtrFree(tmp); } StrCat(result,"]"); } StrCat(result,"]"); return result; } /*********************************************************************** * * FUNCTION: display_default * * DESCRIPTION: Default displaying routine, automatically detects * type of input and formats it accordingly * * NOTE: Result is a dynamically allocated, muste be freed after use. * * PARAMETERS: rpn * complete - if true, the result can be chewed in be * the compiler and produces itself * * RETURN: formatted rpn suitable for output * ***********************************************************************/ char * display_default(Trpn rpn, Boolean complete) { char *result; CError err; Boolean deleterpn = false; if (rpn.type==variable || rpn.type == litem) { if (rpn.type == litem) deleterpn = true; err=rpn_eval_variable(&rpn,rpn); if (err) { result = print_error(err); return result; } } switch (rpn.type) { case integer: result = display_integer(rpn.u.intval,dispPrefs.base); break; case complex: result = display_complex(*rpn.u.cplxval); break; case real: result = display_real(rpn.u.realval); break; case string: result = MemPtrNew(StrLen(rpn.u.stringval)+1); StrCopy(result,rpn.u.stringval); break; case list: if (complete) result = display_list(rpn.u.listval); else { result = MemPtrNew(20); StrPrintF(result,"list(..%d..)",rpn.u.listval->size); } break; case matrix: if (complete) result = display_matrix(rpn.u.matrixval); else { result = MemPtrNew(20); StrPrintF(result,"matrix(%d,%d)", rpn.u.matrixval->rows,rpn.u.matrixval->cols); } break; case cmatrix: if (complete) result = display_cmatrix(rpn.u.cmatrixval); else { result = MemPtrNew(20); StrPrintF(result,"cmatrix(%d,%d)", rpn.u.cmatrixval->rows, rpn.u.cmatrixval->cols); } break; case funcempty: result = MemPtrNew(StrLen(rpn.u.funcname)+5); StrCopy(result,rpn.u.funcname); StrCat(result,"()"); break; default: result = MemPtrNew(16); StrCopy(result,"Unknown type."); break; } if (deleterpn) rpn_delete(rpn); return result; } --- NEW FILE: funcs.cpp --- /* * $Id: funcs.cpp,v 1.1 2009/06/22 22:04:26 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, [...1139 lines suppressed...] void dummy_dummy2(void) GRAPH; void dummy_dummy2(void) { } void dummy_dummy3(void) NEWFUNC; void dummy_dummy3(void) { } void dummy_dummy4(void) MATFUNC; void dummy_dummy4(void) { } --- NEW FILE: funcs.h --- /* * $Id: funcs.h,v 1.1 2009/06/22 22:04:26 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 _FUNCS_H_ #define _FUNCS_H_ #define FUNC_IF 0 /* Constants as indices to funcInterDef table */ #define FUNC_COV 0 #define FUNC_CORR 1 #define FUNC_QBINOM 2 #define FUNC_QBETA 3 #define FUNC_QCHISQ 4 #define FUNC_QF 5 #define FUNC_QPOISSON 6 #define FUNC_QSTUDENTT 7 #define FUNC_QWEIBULL 8 #define FUNC_QNORMAL 9 /* Maximal depth in user functions */ #define MAX_RECURS 10 /* When the 'real' argument is zero */ #define IS_ZERO(x) (fabs(x)<1E-6) #define FUNC_EMPTY 0 #define FUNC_PLUS 1 #define FUNC_MINUS 2 #define FUNC_MULTIPLY 3 #define FUNC_DIVIDE 4 #define FUNC_POWER 5 #define FUNC_EQUAL 6 #define FUNC_NEGATE 7 #define FUNC_DISCARD 8 #define FUNC_AND 9 #define FUNC_OR 10 #define FUNC_SHL 11 #define FUNC_SHR 12 #define FUNC_X 13 #define FUNC_MOD 14 #define FUNC_XOR 15 #define FUNC_ISEQUAL 16 #define FUNC_GRTHEN 17 #define FUNC_LETHEN 18 #define FUNC_GREQ 19 #define FUNC_LEEQ 20 #define FUNC_CONJ 21 #define FUNC_ITEM 22 #define FUNC_DEGREE 1 #define FUNC_RADIAN 2 #define FUNC_GONIO 3 #define FUNC_TOCIS 4 #define FUNC_DEGREE2 5 #define RAND_NUM ((double) SysRandom(0) / (double)sysRandomMax) CError convert_real_to_string(Functype *func,CodeStack *stack) PARSER; CError convert_cplx_to_string(Functype *func,CodeStack *stack) PARSER; CError define_func(Functype *func,CodeStack *stack) PARSER; CError change_param_name(Functype *func,CodeStack *stack) PARSER; CError unset_variable(Functype *func,CodeStack *stack) PARSER; CError discard_arg(Functype *func,CodeStack *stack) PARSER; CError empty_arg(Functype *func,CodeStack *stack) PARSER; CError rpn_eval_variable(Trpn *dest,Trpn source) PARSER; CError set_ans_var(Trpn ans) PARSER; CError eval_x(Functype *func,CodeStack *stack) PARSER; CError text_function(TCHAR *name,Int16 paramcount,CodeStack *stack) PARSER; void set_func_argument(Trpn *arg,UInt16 argcount) PARSER; void decr_func_argument(void) PARSER; Boolean varfunc_name_ok(TCHAR *name,rpntype type) PARSER; CError func_get_value(CodeStack *origstack,double param, double *result, CodeStack *addparms) PARSER; CError func_get_value_cplx(CodeStack *origstack,Complex* params, UInt16 paramcount, Complex *result) PARSER; CError exec_function(CodeStack *funcstack,CodeStack *varstack, Int16 paramcount) PARSER; CError func_interdef(Functype *func,CodeStack *stack) PARSER; CError func_if(Functype *func,CodeStack *stack) PARSER; CError func_item(Functype *func, CodeStack *stack) PARSER; Boolean is_constant(TCHAR *name) PARSER; extern Boolean DisableInput; #endif --- NEW FILE: stack.cpp --- /* * $Id: stack.cpp,v 1.1 2009/06/22 22:04:26 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, [...977 lines suppressed...] * FUNCTION: stack_delete * * DESCRIPTION: Deletes existing stack and frees all associated memory * * PARAMETERS: stack * * RETURN: Nothing * ***********************************************************************/ void stack_delete(CodeStack *stack) { while (stack->size) { stack->size--; rpn_delete(stack->stack[stack->size]); } MemPtrFree(stack->stack); MemPtrFree(stack); } --- NEW FILE: history.cpp --- /* * $Id: history.cpp,v 1.1 2009/06/22 22:04:26 mapibid Exp $ * * Scientific Calculator for Palms. * Copyright (C) 2000 Ondrej Palkovsky * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. */ #include "StdAfx.h" #include "compat/PalmOS.h" #include <string.h> #include "calcDB.h" #include "stack.h" #include "defuns.h" #include "history.h" #include "display.h" #include "dbutil.h" static DmOpenRef dbRef; UInt16 history_total(void) MLIB; UInt16 history_total(void) { return DmNumRecords(dbRef); } void history_add_line(TCHAR *line) { tHistory *item,*newitem; UInt16 size; MemHandle newHandle; UInt16 recordNumber; size = sizeof(*item) + StrLen(line) + 1; item = (tHistory *) MemPtrNew(size); item->isrpn = false; StrCopy(item->u.text,line); recordNumber = 0; newHandle = DmNewRecord(dbRef,&recordNumber,size); newitem = (tHistory *) MemHandleLock(newHandle); DmWrite(newitem,0,item,size); MemHandleUnlock(newHandle); DmReleaseRecord(dbRef,recordNumber,true); MemPtrFree(item); } /*********************************************************************** * * FUNCTION: history_add * * DESCRIPTION: Add a record in a records database * * PARAMETERS: item - the record that should be added * * RETURN: None * ***********************************************************************/ void history_add_item(Trpn item) { dbStackItem *packitem; UInt16 size,psize; MemHandle newHandle; UInt16 recordNumber; tHistory *histitem,*newitem; packitem = rpn_pack_record(item); if (!packitem) return; size = sizeof(*histitem) + packitem->datasize; psize = sizeof(*packitem) + packitem->datasize; histitem = (tHistory *) MemPtrNew(size); if (!histitem) { MemPtrFree(packitem); return; } histitem->isrpn = true; memcpy((void *)&histitem->u.item,(void *)packitem,psize); recordNumber = 0; newHandle = DmNewRecord(dbRef,&recordNumber,size); if (!newHandle) { MemPtrFree(packitem); MemPtrFree(histitem); return; } newitem = (tHistory *) MemHandleLock(newHandle); DmWrite(newitem,0,histitem,size); MemHandleUnlock(newHandle); DmReleaseRecord(dbRef,recordNumber,true); MemPtrFree(packitem); MemPtrFree(histitem); } /*********************************************************************** * * FUNCTION: history_shrink * * DESCRIPTION: Shrink the history detabase to a defined * number of records * * PARAMETERS: How many records leave in database * * RETURN: None * ***********************************************************************/ void history_shrink(Int16 count) { Int16 i; if (DmNumRecords(dbRef)==0) return; i = DmNumRecords(dbRef)-1; while (i>=count) { DmRemoveRecord(dbRef,i--); } } /*********************************************************************** * * FUNCTION: history_get * * DESCRIPTION: Return a history record * * PARAMETERS: num - how old the item is * * RETURN: item * ***********************************************************************/ Trpn history_get_item(UInt16 num) { MemHandle recordHandle; tHistory *historyitem; Trpn result; recordHandle = DmQueryRecord(dbRef,num); historyitem = (tHistory *) MemHandleLock(recordHandle); result = rpn_unpack_record(&historyitem->u.item); MemHandleUnlock(recordHandle); return result; } TCHAR * history_get_line(UInt16 num) { MemHandle recordHandle; tHistory *historyitem; TCHAR *result; recordHandle = DmQueryRecord(dbRef,num); historyitem = (tHistory *) MemHandleLock(recordHandle); result = (TCHAR *) MemPtrNew(StrLen(historyitem->u.text) + 1); StrCopy(result,historyitem->u.text); MemHandleUnlock(recordHandle); return result; } Boolean history_isrpn(UInt16 num) { MemHandle recordHandle; tHistory *historyitem; Boolean result; recordHandle = DmQueryRecord(dbRef,num); historyitem = (tHistory *) MemHandleLock(recordHandle); result = historyitem->isrpn; MemHandleUnlock(recordHandle); return result; } /*********************************************************************** * * FUNCTION: history_command * * DESCRIPTION: This function is evaluated directly from a normal * mathematical equation * * PARAMETERS: On stack - 1 number convertible to integer * * RETURN: On stack - value from history database * ***********************************************************************/ CError history_command(Functype *func,CodeStack *stack) { CError err; UInt32 arg; if ((err=stack_get_val(stack,&arg,integer))) return err; if (arg > DmNumRecords(dbRef)) return c_badarg; if (!history_isrpn(arg)) return c_badarg; stack_push(stack,history_get_item(arg)); return c_noerror; } /*********************************************************************** * * FUNCTION: history_open * * DESCRIPTION: Open a history database * * PARAMETERS: None * * RETURN: 0 on success * ***********************************************************************/ Int16 history_open(void) { return open_db(HISTORYDBNAME, HIST_DB_VERSION, LIB_ID, DBTYPE, &dbRef); } /*********************************************************************** * * FUNCTION: history_close * * DESCRIPTION: Close a history database * * PARAMETERS: None * * RETURN: 0 on success * ***********************************************************************/ Int16 history_close(void) { history_shrink(HISTORY_RECORDS); return DmCloseDatabase(dbRef); } --- NEW FILE: history.h --- /* * $Id: history.h,v 1.1 2009/06/22 22:04:26 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 _HISTORY_H_ #define _HISTORY_H_ #define HISTORY_RECORDS 30 typedef struct { Boolean isrpn; Int16 xxxpad; union { dbStackItem item; TCHAR *text; }u; }tHistory; CError history_command(Functype *func,CodeStack *stack) MLIB; Int16 history_close(void) MLIB; Int16 history_open(void) MLIB; void history_shrink(Int16 count) MLIB; void history_add_line(TCHAR *line) MLIB; void history_add_item(Trpn item) MLIB; Boolean history_isrpn(UInt16 num) MLIB; UInt16 history_total(void) MLIB; TCHAR * history_get_line(UInt16 num) MLIB; Trpn history_get_item(UInt16 num) MLIB; #endif --- NEW FILE: konvert.h --- /* * $Id: konvert.h,v 1.1 2009/06/22 22:04:26 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 _konvert_h_ #define _konvert_h_ #include "segment.h" #define MAX_FUNCNAME 10 #define MAX_VARNAME 10 /* First function/variable character */ #define IS_FUNC_1LETTER(x) (((x)>='a' && (x)<='z') || (x)=='_' || (x)==(TCHAR)181 || \ ((x)>='G' && (x)<='Z')) /* Other characters, inside varname can be numbers */ #define IS_FUNC_LETTER(x) (IS_FUNC_1LETTER(x) || ((x)>='0' && (x)<='9') || \ ((x)>='A' && (x)<='Z')) typedef enum { degree, radian, grad }Ttrigo_mode; typedef enum { notype=0, integer, real, function, functext, funcempty, variable, string, /* These 2 next shouldn't be in rpn, it's temporary */ oper, discard, complex, list, matrix, litem, cmatrix }rpntype; typedef enum { c_noerror=0, c_syntax, c_badfunc, c_noarg, c_badarg, c_internal, c_badmode, c_noresult, c_divbyzero, c_notvar, c_badresult, c_deeprec, c_compimp, c_range, c_badargcount, c_baddim, c_singular, c_interrupted, c_memory, c_stacklow }CError; typedef struct { double real; double imag; }Complex; typedef struct { double r; double angle; }Complex_gon; typedef struct { Int16 offs; Int16 num; Int16 paramcount; }Functype; typedef struct { Int16 paramcount; TCHAR name[MAX_FUNCNAME+1]; }TextFunctype; typedef struct { Int16 row; Int16 col; TCHAR name[MAX_FUNCNAME+1]; }LitemType; typedef struct { UInt16 size; Complex *item; }List; #define MATRIX(m,r,c) m->item[m->cols * (r) + (c)] typedef struct { Int16 rows,cols; double *item; }Matrix; typedef struct { Int16 rows,cols; Complex *item; }CMatrix; /* item on the RPN stack */ typedef struct { rpntype type; UInt16 allocsize; /* If we should free the item or not */ union { UInt32 intval; double realval; Functype funcval; /* Internal function call */ TextFunctype textfunc; /* User defined function call */ LitemType litemval; TCHAR funcname[MAX_FUNCNAME+1]; /* Empty function */ TCHAR varname[MAX_FUNCNAME+1]; TCHAR *stringval; Complex *cplxval; TCHAR *data; List *listval; Matrix *matrixval; CMatrix *cmatrixval; }u; }Trpn; typedef struct { Boolean evalRight; Int16 priority; Int16 operpri; Trpn rpn; }Tmeq; /* stack */ typedef struct { UInt16 size; UInt16 allocated; Trpn *stack; }CodeStack; struct Tdefined_funcs { const TCHAR name[MAX_FUNCNAME+1]; Int16 funcnum; CError (*function)(Functype *func,CodeStack *stack); Int16 paramcount; Boolean listsimul; Boolean matrixsimul; }; CodeStack *text_to_stack(TCHAR *buf, CError *error); Err mlib_init_mathlib(void) MLIB; void mlib_close_mathlib(void) MLIB; TCHAR ** konvert_get_sorted_fn_list(Int16 *count); extern const struct Tdefined_funcs defined_funcs[]; extern Ttrigo_mode trigo_mode; extern TCHAR parameter_name[MAX_FUNCNAME+1]; #endif --- NEW FILE: stack.h --- /* * $Id: stack.h,v 1.1 2009/06/22 22:04:26 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 _STACK_H_ #define _STACK_H_ #include "calcDB.h" #include "segment.h" dbPackedStack * stack_pack(CodeStack *stack,Int16 *size) MLIB; CodeStack * stack_unpack(dbPackedStack *packed) MLIB; dbStackItem * rpn_pack_record(Trpn item) MLIB; Trpn rpn_unpack_record(dbStackItem *record) MLIB; void rpn_delete(Trpn item) MLIB; void rpn_duplicate(Trpn *dest,Trpn source) MLIB; CError stack_get_val(CodeStack *stack,void *arg1,rpntype reqtype) MLIB; CError stack_get_val2(CodeStack *stack,void *arg1,void *arg2,rpntype reqtype) MLIB; CError stack_add_val(CodeStack *stack,void *arg,rpntype reqtype) MLIB; CError stack_item_type(CodeStack *stack,rpntype *type,Int16 itnum) MLIB; CError stack_compute(CodeStack *instack) MLIB; Trpn stack_pop(CodeStack *stack) MLIB; void stack_push(CodeStack *stack,Trpn rpn) MLIB; CodeStack * stack_new(Int16 count) MLIB; void stack_delete(CodeStack *stack) MLIB; void stack_copy(CodeStack *dest,CodeStack *orig) MLIB; CError stack_item_type_nr(CodeStack *stack,rpntype *type,Int16 itnum) MLIB; void stack_reverse(CodeStack *stack) MLIB; double reduce_precision(double value) MLIB; void stack_fix_variables(CodeStack *stack) MLIB; #endif |