From: Mapi B. <ma...@us...> - 2009-10-17 13:44:32
|
Update of /cvsroot/easycalc/PPCport/compat In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv30679 Modified Files: DataManager.cpp DataManager.h dbutil.cpp Lang.cpp Lang.h MathLib.h MemoryManager.cpp MemoryManager.h PalmOS.cpp PalmOS.h Log Message: 1.25a Compiling, linking, running, limited function set, with bugs Index: Lang.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/Lang.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Lang.cpp 22 Jun 2009 21:57:16 -0000 1.1 --- Lang.cpp 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 21,27 **** --- 21,44 ---- #include "StdAfx.h" #include "compat/Lang.h" + #include "winnls.h" #include <locale.h> #ifdef UNICODE + #ifdef WINCE + static TCHAR _tlocaleInfo[64]; + TCHAR *Lang::_tsetlocale (int category, const TCHAR *locale) { + char localeTmp[64]; + + wcstombs(localeTmp, locale, 64); + // This uses the current locale, which I didn't find how to set in Win CE + // mbstowcs(_tlocaleInfo, localeInfo, 64);MultiByteToWideChar(); + if (MultiByteToWideChar(codePage, MB_PRECOMPOSED, localeTmp, -1, _tlocaleInfo, 64) == 0) { + // Failed to convert to the target codepage + return (NULL); + } + return (_tlocaleInfo); + } + #else #define _tsetlocale _wsetlocale + #endif #else #define _tsetlocale setlocale *************** *** 39,44 **** --- 56,65 ---- langName.assign(name); // Try to set the locale with the provided string first. + #ifdef WINCE + { + #else if ((localeInfo = _tsetlocale(LC_ALL, name)) != NULL) { } else { // Not recognized by windows. + #endif // Map using the Palm EasyCalc PilRC names if (_tcscmp(name, _T("cs")) == 0) { *************** *** 369,372 **** --- 390,394 ---- // Set it to english by default. setLang(_T("en")); + defLang = curLang; // Remember it as default language } *************** *** 407,412 **** curLang = (Lang *) getLang(langName); ! TCHAR *localeInfo = _tsetlocale(LC_ALL, curLang->localeInfo); ! return (localeInfo == NULL); } --- 429,440 ---- curLang = (Lang *) getLang(langName); ! if (curLang != NULL) { ! #ifdef WINCE ! return (0); ! #else ! TCHAR *localeInfo = _tsetlocale(LC_ALL, curLang->localeInfo); ! return (localeInfo == NULL); ! #endif ! } else return (-1); } *************** *** 420,426 **** /******************************************************************************** * Translate a token with current language. * ********************************************************************************/ const TCHAR *LibLang::translate(TCHAR *token) { ! return (curLang->get(token)); } --- 448,464 ---- /******************************************************************************** * Translate a token with current language. * + * If not found, try the default one. * + * If not found, return initial string. * ********************************************************************************/ const TCHAR *LibLang::translate(TCHAR *token) { ! const TCHAR *text = curLang->get(token); ! if (text == NULL) { ! if (defLang != curLang) { ! text = defLang->get(token); ! } ! if (text == NULL) ! text = token; ! } ! return (text); } Index: MathLib.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/MathLib.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MathLib.h 5 Jul 2009 20:53:14 -0000 1.1 --- MathLib.h 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 147,151 **** 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__ --- 147,154 ---- 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 ! // From OpenGroup specifications ! // http://www.opengroup.org/onlinepubs/9699919799/functions/signbit.html ! // Return non zero only if arg is negative. ! #define signbit(x) (((_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_NN | _FPCLASS_ND | _FPCLASS_NZ)) != 0)) #endif // __MATHLIB_H__ Index: DataManager.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataManager.cpp 24 Sep 2009 21:15:27 -0000 1.3 --- DataManager.cpp 17 Oct 2009 13:44:17 -0000 1.4 *************** *** 1,7 **** --- 1,10 ---- #include "StdAfx.h" #include "compat/PalmOS.h" + #define _DATAMANAGER_C_ #include "DataManager.h" #include "defuns.h" + #define RECD_MAGIC 0x52454344 + DataManager::DataManager(void) { in_state = false; *************** *** 16,30 **** } ! 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); --- 19,32 ---- } ! static void freeDR (DataRecord *dr) { ! if (dr != NULL) { ! freeDR(dr->next); ! delete dr; } + } + + DataManager::~DataManager(void) { + // Free all records in the DB + freeDR(head); if (sortArray != NULL) free(sortArray); if (name != NULL) free(name); *************** *** 88,91 **** --- 90,94 ---- size_t siz = num * sizeof(int); if (fwrite(&siz, sizeof(siz), 1, f) != 1) + return (-1); for (int i=0 ; i<num ; i++) { if (fwrite(&(sortArray[i]->num), sizeof(int), 1, f) != 1) *************** *** 143,148 **** 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; --- 146,153 ---- for (int i=0 ; i<numRecords ; i++) { temp2 = new DataRecord; ! if (temp2->deSerialize(f) != 0) { ! delete temp2; return (-1); + } // Remember its address by index listArray[temp2->num] = temp2; *************** *** 163,170 **** // 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 --- 168,175 ---- // 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 (fread(&index, sizeof(int), 1, f) != 1) return (-1); // We got the record number, now convert it to its allocated *************** *** 175,179 **** free (listArray); ! // Restore the previous file mode. _setmode(f, prev_mode); --- 180,184 ---- free (listArray); ! // Restore previous file mode. _setmode(f, prev_mode); *************** *** 181,186 **** } ! 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) { --- 186,191 ---- } ! DataManager *stateMgrDB = NULL; // This one comes from CalcDB.cpp ! DataManager *stateMgrHistDB = NULL; // This one comes from EasyCalc.cpp void registerDmDatabase (UINT16 cardNo, const TCHAR *nameP, DataManager *dbId) { *************** *** 205,209 **** 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; --- 210,214 ---- 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; *************** *** 220,224 **** 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) { --- 225,229 ---- 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) { *************** *** 232,236 **** } ! DmOpenRef DmOpenDatabase (UINT cardNo, LocalID dbID, UINT16 mode) { if (dbID == (LocalID) stateMgrHistDB) { return (stateMgrHistDB); --- 237,241 ---- } ! DmOpenRef DmOpenDatabase (UINT16 cardNo, LocalID dbID, UINT16 mode) { if (dbID == (LocalID) stateMgrHistDB) { return (stateMgrHistDB); *************** *** 249,268 **** 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; } --- 254,275 ---- int rc = 0; if (wcscmp (nameP, HISTORYDBNAME) == 0) { ! if (stateMgrHistDB == NULL) { stateMgrHistDB = new DataManager; ! stateMgrHistDB->creator = creator; ! stateMgrHistDB->type = type; ! int l = _tcslen(nameP); ! stateMgrHistDB->name = (TCHAR *) malloc(2*(l+1)); ! _tcscpy (stateMgrHistDB->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; } *************** *** 270,274 **** } ! Err DmCloseDatabase (DmOpenRef dbP) { return (0); } --- 277,281 ---- } ! int DmCloseDatabase (DmOpenRef dbP) { return (0); } *************** *** 291,297 **** 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; --- 298,302 ---- MemHandle p = NULL; if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { ! if ((p = MemHandleNew(size)) != NULL) { DataRecord *prec = NULL; DataRecord *temp = dbP->head; *************** *** 323,333 **** } 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; --- 328,338 ---- } if (prec == NULL) { // Insert at head ! temp = dbP->head = new DataRecord(p, dbP->head); } else { ! temp = prec->next = new DataRecord(p, temp); } ! // Sign the mem handle ! p->setOwner((void *) RECD_MAGIC); ! // And update the new sortArray entry with new DataRecord address, if needed if (dbP->sortArray != NULL) { dbP->sortArray[*atP] = temp; *************** *** 338,360 **** } ! 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; --- 343,351 ---- } ! MemHandle DmGetRecord (DmOpenRef dbP, UINT16 index) { ! return (DmQueryRecord(dbP, index)); } ! int DmRemoveRecord (DmOpenRef dbP, UINT16 index) { if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { DataRecord *prec = NULL; *************** *** 363,367 **** 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++) --- 354,358 ---- return (-1); dbP->numRecords--; ! // Locate 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++) *************** *** 400,422 **** } ! Err DmWrite (void *recordP, UInt32 offset, const void *srcP, UInt32 bytes) { ! char *p = (char *) recordP; ! ! // Find the record to which this data belongs ! DataRecord *r = (DataRecord *) (* ((UInt32 *) (((UInt32) recordP) - 4))); ! if (r->magic != RECORD_MAGIC) return (-1); ! if (offset + bytes > r->size) return (-2); ! memcpy (p+offset, srcP, bytes); return (0); } ! 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); } --- 391,420 ---- } ! int DmWrite (void *recordP, UINT32 offset, const void *srcP, UINT32 bytes) { ! // Find record to which this data belongs ! MemHandle p = c_MemHandle::GetMemHandle(recordP); ! if (p == NULL) return (-1); ! if (((UInt32) (p->getOwner())) != RECD_MAGIC) return (-1); ! if (offset + bytes > p->getSize()) return (-2); ! memcpy (((byte *) (recordP))+offset, srcP, bytes); return (0); } ! MemHandle DmQueryRecord (DmOpenRef dbP, UINT16 index) { ! MemHandle p = NULL; if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { DataRecord *temp = dbP->head; ! // Find 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); } *************** *** 434,438 **** // First, initiate conditions on boundaries of the recurring algorithm if (compar(newRecord, ! sortArray[imax]->h->memPtr, other, NULL, // newRecordInfo, not used, so not implemented --- 432,436 ---- // First, initiate conditions on boundaries of the recurring algorithm if (compar(newRecord, ! sortArray[imax]->h->getMemAddr(), other, NULL, // newRecordInfo, not used, so not implemented *************** *** 444,448 **** } 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 --- 442,446 ---- } else if ((numRecords == 1) // First == last ! No need to redo the comparison. || (c = compar(newRecord, ! sortArray[0]->h->getMemAddr(), other, NULL, // newRecordInfo, not used, so not implemented *************** *** 462,466 **** // And note: when numRecords == 2, imax is 1. && (compar(newRecord, ! sortArray[i]->h->memPtr, other, NULL, // newRecordInfo, not used, so not implemented --- 460,464 ---- // And note: when numRecords == 2, imax is 1. && (compar(newRecord, ! sortArray[i]->h->getMemAddr(), other, NULL, // newRecordInfo, not used, so not implemented *************** *** 479,483 **** i = (imax + imin) >> 1; c = compar(newRecord, ! sortArray[i]->h->memPtr, other, NULL, // newRecordInfo, not used, so not implemented --- 477,481 ---- i = (imax + imin) >> 1; c = compar(newRecord, ! sortArray[i]->h->getMemAddr(), other, NULL, // newRecordInfo, not used, so not implemented *************** *** 489,493 **** while ((i < numRecords) && (compar(newRecord, ! sortArray[i]->h->memPtr, other, NULL, // newRecordInfo, not used, so not implemented --- 487,491 ---- while ((i < numRecords) && (compar(newRecord, ! sortArray[i]->h->getMemAddr(), other, NULL, // newRecordInfo, not used, so not implemented *************** *** 526,530 **** UInt16 DmFindSortPosition (DmOpenRef dbP, void *newRecord, SortRecordInfoPtr newRecordInfo, ! DmComparF *compar, Int16 other) { int i = -1; if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { --- 524,528 ---- UInt16 DmFindSortPosition (DmOpenRef dbP, void *newRecord, SortRecordInfoPtr newRecordInfo, ! DmComparF *compar, INT16 other) { int i = -1; if ((dbP == stateMgrHistDB) || (dbP == stateMgrDB)) { *************** *** 570,586 **** } ! //Err DmReleaseRecord (DmOpenRef dbP, UInt16 index, Boolean dirty) { // return (0); //} DataRecord::DataRecord(void) { ! magic = RECORD_MAGIC; ! size = 0; h = NULL; next = NULL; } ! DataRecord::DataRecord(UINT32 s, MemHandle p, DataRecord *n) { ! size = s; h = p; next = n; --- 568,585 ---- } ! //int DmReleaseRecord (DmOpenRef dbP, UInt16 index, Boolean dirty) { // return (0); //} DataRecord::DataRecord(void) { ! magic = RECD_MAGIC; ! // size = 0; h = NULL; next = NULL; } ! DataRecord::DataRecord(/*UINT32 s, */MemHandle p, DataRecord *n) { ! magic = RECD_MAGIC; ! // size = s; h = p; next = n; *************** *** 588,591 **** --- 587,592 ---- DataRecord::~DataRecord(void) { + if (h != NULL) + MemHandleFree(h); } *************** *** 596,604 **** 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); --- 597,607 ---- 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 (fwrite(&h, sizeof(h), 1, f) != 1) ! return (-1); ! if ((h != NULL) && (h->serialize(f) != 0)) return (-1); *************** *** 612,621 **** 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); --- 615,630 ---- 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 (fread(&h, sizeof(h), 1, f) != 1) return (-1); + if (h != NULL) { + h = new c_MemHandle (); + if (h->deSerialize(f) != 0) { + return (-1); + } + } return (0); Index: PalmOS.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/PalmOS.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PalmOS.h 24 Sep 2009 21:15:27 -0000 1.5 --- PalmOS.h 17 Oct 2009 13:44:17 -0000 1.6 *************** *** 73,79 **** #define NaN (*((double *) nan)) ! #include <time.h> ! #define TimGetSeconds() ((UInt32) time(NULL)) ! void ErrFatalDisplayIf(int cond, TCHAR *msg); // Declared in Easycalc.cpp --- 73,77 ---- #define NaN (*((double *) nan)) ! UInt32 TimGetSeconds (void); void ErrFatalDisplayIf(int cond, TCHAR *msg); // Declared in Easycalc.cpp Index: PalmOS.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/PalmOS.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PalmOS.cpp 24 Sep 2009 21:15:27 -0000 1.1 --- PalmOS.cpp 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 18,20 **** --- 18,36 ---- #include "StdAfx.h" + #include "compat/PalmOS.h" + unsigned long nan[2]={0xffffffff, 0x7fffffff}; + + UInt32 TimGetSeconds (void) { + SYSTEMTIME syst_time; + FILETIME file_time; + UInt32 t; + + GetSystemTime(&syst_time); + SystemTimeToFileTime(&syst_time, &file_time); + // We got the number of 100-nanosecond intervals since January 1, 1601 + // Convert to seconds since then. + // 1 s = 1000000 µs = 10000000 * 100 ns + t = (UInt32) (((ULARGE_INTEGER*) &file_time)->QuadPart / 10000000L); + return (t); + } Index: DataManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/DataManager.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** DataManager.h 6 Aug 2009 21:41:01 -0000 1.3 --- DataManager.h 17 Oct 2009 13:44:17 -0000 1.4 *************** *** 10,18 **** #define dmHdrAttrBackup 2 - #define RECORD_MAGIC 0x52454344 class DataRecord { public: UInt32 magic; ! UInt32 size; int num; MemHandle h; --- 10,17 ---- #define dmHdrAttrBackup 2 class DataRecord { public: UInt32 magic; ! // UInt32 size; int num; MemHandle h; *************** *** 20,24 **** DataRecord(void); ! DataRecord(UINT32 s, MemHandle p, DataRecord *n); ~DataRecord(void); int serialize(FILE *f); --- 19,23 ---- DataRecord(void); ! DataRecord(/*UINT32 s, */MemHandle p, DataRecord *n); ~DataRecord(void); int serialize(FILE *f); *************** *** 62,86 **** 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); ! 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); --- 61,85 ---- LocalID DmFindDatabase (UINT16 cardNo, const TCHAR *nameP); ! 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 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); ! int DmGetLastErr (void); ! int DmCreateDatabase (UINT16 cardNo, const Char *nameP, UINT32 creator, UINT32 type, Boolean resDB); ! int DmCloseDatabase (DmOpenRef dbP); ! int DmDeleteDatabase (UINT16 cardNo, LocalID dbID); UInt16 DmNumRecords (DmOpenRef dbP); ! MemHandle DmNewRecord (DmOpenRef dbP, UINT16 *atP, UINT32 size); ! MemHandle DmGetRecord (DmOpenRef dbP, UINT16 index); ! int DmWrite (void *recordP, UINT32 offset, const void *srcP, UINT32 bytes); ! int DmRemoveRecord (DmOpenRef dbP, UINT16 index); MemHandle DmQueryRecord (DmOpenRef dbP, UInt16 index); ! UINT16 DmFindSortPosition (DmOpenRef dbP, void *newRecord, SortRecordInfoPtr newRecordInfo, DmComparF *compar, Int16 other); *************** *** 89,92 **** --- 88,95 ---- #define DmReleaseRecord(a,b,c) + #ifndef _DATAMANAGER_C_ + extern DataManager *stateMgrDB; + extern DataManager *stateMgrHistDB; + #endif #endif \ No newline at end of file Index: Lang.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/Lang.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Lang.h 22 Jun 2009 21:57:16 -0000 1.1 --- Lang.h 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 39,42 **** --- 39,45 ---- Lang(const TCHAR *name); ~Lang(void); + #ifdef WINCE + TCHAR *_tsetlocale (int category, const TCHAR *locale); + #endif bool insert(const TCHAR *key, const TCHAR *value); const TCHAR *get(TCHAR *key); *************** *** 51,54 **** --- 54,58 ---- bool firstCalled; Lang *curLang; + Lang *defLang; TCHAR *wcstr; size_t allocLen; Index: MemoryManager.h =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/MemoryManager.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MemoryManager.h 6 Aug 2009 21:41:25 -0000 1.1 --- MemoryManager.h 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 9,34 **** 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 \ No newline at end of file --- 9,50 ---- class c_MemHandle { ! protected: ! UInt32 magic; ! void *owner; ! UInt32 size; ! void *memPtr; ! int lockCnt; + public: c_MemHandle(void); ~c_MemHandle(void); int serialize(FILE *f); int deSerialize(FILE *f); + + static c_MemHandle *MemHandleNew (UInt32 size); + static Err MemHandleFree (c_MemHandle *h); + void setOwner (void *owner); + void *getOwner (void); + MemPtr lock (void); + MemPtr getMemAddr (void); + static c_MemHandle *GetMemHandle (MemPtr p); + Err unlock (void); + UInt32 getSize (void); + Err resize (UInt32 newSize); }; typedef c_MemHandle *MemHandle; + #ifndef _MEMORYMANAGER_C_ + #define MemHandleNew c_MemHandle::MemHandleNew + #define MemHandleFree c_MemHandle::MemHandleFree + #define MemHandleLock(h) ((h)->lock()) + #define MemHandleUnlock(h) ((h)->unlock()) + #define MemHandleSize(h) ((h)->getSize()) + #define MemHandleResize(h,ns) ((h)->resize(ns)) + #endif + #define MemPtrNew malloc #define MemPtrFree free #endif \ No newline at end of file Index: MemoryManager.cpp =================================================================== RCS file: /cvsroot/easycalc/PPCport/compat/MemoryManager.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** MemoryManager.cpp 6 Aug 2009 21:41:25 -0000 1.1 --- MemoryManager.cpp 17 Oct 2009 13:44:17 -0000 1.2 *************** *** 1,10 **** #include "StdAfx.h" #include "compat/PalmOS.h" #include "MemoryManager.h" c_MemHandle::c_MemHandle(void) { ! // size = 0; ! memPtr = NULL; ! lock = 0; } --- 1,16 ---- #include "StdAfx.h" + + #define _MEMORYMANAGER_C_ #include "compat/PalmOS.h" #include "MemoryManager.h" + #define MEMH_MAGIC 0x4D454D48 + c_MemHandle::c_MemHandle(void) { ! magic = MEMH_MAGIC; ! owner = NULL; ! size = 0; ! memPtr = NULL; ! lockCnt = 0; } *************** *** 18,27 **** ***********************************************************************/ 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) --- 24,38 ---- ***********************************************************************/ int c_MemHandle::serialize(FILE *f) { ! if (fwrite(&magic, sizeof(magic), 1, f) != 1) ! return (-1); ! if (fwrite(&owner, sizeof(owner), 1, f) != 1) ! return (-1); ! if (fwrite(&size, sizeof(size), 1, f) != 1) ! return (-1); if (fwrite(&memPtr, sizeof(memPtr), 1, f) != 1) return (-1); ! if (fwrite(&lockCnt, sizeof(lockCnt), 1, f) != 1) return (-1); ! if (memPtr != NULL) { size_t siz = _msize(memPtr); if (fwrite(&siz, sizeof(siz), 1, f) != 1) *************** *** 38,47 **** ***********************************************************************/ 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) --- 49,63 ---- ***********************************************************************/ int c_MemHandle::deSerialize(FILE *f) { ! if (fread(&magic, sizeof(magic), 1, f) != 1) ! return (-1); ! if (fread(&owner, sizeof(owner), 1, f) != 1) ! return (-1); ! if (fread(&size, sizeof(size), 1, f) != 1) ! return (-1); if (fread(&memPtr, sizeof(memPtr), 1, f) != 1) return (-1); ! if (fread(&lockCnt, sizeof(lockCnt), 1, f) != 1) return (-1); ! if (memPtr != NULL) { size_t siz; if (fread(&siz, sizeof(siz), 1, f) != 1) *************** *** 50,53 **** --- 66,71 ---- if (fread(memPtr, siz, 1, f) != 1) return (-1); + // Re-establish proper link to this object at beginning of memPtr + *((UInt32 *) memPtr) = (UInt32) this; } *************** *** 55,63 **** } ! MemHandle MemHandleNew (UInt32 size) { MemHandle h = new c_MemHandle; if (h != NULL) { ! if ((h->memPtr = malloc(size)) != NULL) { ! // h->size = size; } else { delete h; --- 73,85 ---- } ! /* Static method */ ! MemHandle c_MemHandle::MemHandleNew (UInt32 size) { MemHandle h = new c_MemHandle; if (h != NULL) { ! // Add 4 bytes, round up to next 4 bytes limit ! if ((h->memPtr = malloc((size+7) & 0xFFFFFFFC)) != NULL) { ! // Put metadata MemHandle address in allocated memory ! *((UInt32 *) h->memPtr) = (UInt32) h; ! h->size = size; } else { delete h; *************** *** 68,97 **** } ! 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); } --- 90,157 ---- } ! /* Static method */ ! Err c_MemHandle::MemHandleFree (MemHandle h) { delete h; return (0); } ! void c_MemHandle::setOwner (void *owner) { ! this->owner = owner; } ! void *c_MemHandle::getOwner (void) { ! return (this->owner); ! } ! ! MemPtr c_MemHandle::lock (void) { ! this->lockCnt++; ! // Skip metadata pointer ! return ((MemPtr) (((UInt32 *) (this->memPtr)) + 1)); ! } ! ! MemPtr c_MemHandle::getMemAddr (void) { ! return ((MemPtr) (((UInt32 *) (this->memPtr)) + 1)); ! } ! ! /* Static method */ ! MemHandle c_MemHandle::GetMemHandle (MemPtr p) { ! // Retrieve metadata pointer ! MemHandle h = (MemHandle) (*(((UInt32 *) p) - 1)); ! if (h->magic != MEMH_MAGIC) { ! h = NULL; ! } ! return (h); ! } ! ! Err c_MemHandle::unlock (void) { ! if (this->lockCnt > 0) this->lockCnt--; return (0); } ! UInt32 c_MemHandle::getSize (void) { ! return (this->size); } ! Err c_MemHandle::resize (UInt32 newSize) { ! if (this->lockCnt > 0) return (-1); ! if (this->size == newSize) // No resize to do ! return (0); ! if ((newSize == 0) && (this->memPtr)) { // Free existing allocated memory ! free(this->memPtr); ! this->memPtr = NULL; ! this->size = 0; ! } else { ! // Add 4 bytes, round up to next 4 bytes limit ! void *p = realloc(this->memPtr, (newSize+7) & 0xFFFFFFFC); ! if (p != NULL) { ! this->memPtr = p; ! // Put metadata MemHandle address in allocated memory ! *((UInt32 *) this->memPtr) = (UInt32) this; ! this->size = newSize; ! } else { ! return (-2); ! } ! } return (0); } |