// null fields are considered less than others // static Int16 HDComparePackedRecords(PackedHappyDays *rec1, PackedHappyDays *rec2, Int16 unusedInt, SortRecordInfoPtr unused1, SortRecordInfoPtr unused2, MemHandle appInfoH) { Int16 result; Int16 whichKey1 = 1, whichKey2 = 1; char *key1, *key2; do { HDFindKey(rec1, &key1, &whichKey1); HDFindKey(rec2, &key2, &whichKey2); if (!key1 || *key1 == 0) { if (!key2 || *key2 == 0) { result = 0; return result; } else result = -1; } else if (!key2 || *key2 == 0) result = 1; else { result = StrCaselessCompare(key1, key2); if (result == 0) result = StrCompare(key1, key2); } } while (!result); return result; }
static Int16 BookmarksByNameCompare(char * r1, char * r2, Int16 sortOrder, SortRecordInfoPtr /* info1 */, SortRecordInfoPtr /* info2 */, MemHandle /* appInfoH */) { // need to use that to have the same sorting as in list of words #ifndef I_NOAH return p_istrcmp(r1,r2); #else return StrCaselessCompare(r1, r2); #endif }
int osip_strcasecmp(const char *s1, const char *s2) { #if defined(__VXWORKS_OS__) || defined( __PSOS__) while ((*s1 != '\0') && (tolower(*s1) == tolower(*s2))) { s1++; s2++; } return (tolower(*s1) - tolower(*s2)); #elif defined(__PALMOS__) && (__PALMOS__ < 0x06000000) return StrCaselessCompare(s1, s2); #elif defined(__PALMOS__) || (!defined WIN32 && !defined _WIN32_WCE) return strcasecmp(s1, s2); #else return _stricmp(s1, s2); #endif }
/* Create new item in app database */ static UInt16 DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index) { MemoItemType memo; UInt16 ii, category, result; Char catName[dmCategoryLength]; const UInt32 titleLen = StrLen(kleenexP->text); const UInt32 noteLen = kleenexP->note ? StrLen(kleenexP->note) : 0; Char* note = MemPtrNew(noteLen ? titleLen + 2 + noteLen + 1 : titleLen + 1); // Create memo text StrCopy(note, kleenexP->text); if (noteLen) { StrCat(note, "\n\n"); StrCat(note, kleenexP->note); } // Set up the new item memo.note = note; // Set up category category = dmUnfiledCategory; if (kleenexP->category) { StrCopy(catName, ""); for (ii=0; ii<dmRecNumCategories; ii++) { CategoryGetName(dbR, ii, catName); if (!StrCaselessCompare(catName, kleenexP->category)) { category = ii; break; } } } // Add it to the DB result = MemoNewRecord(dbR, &memo, category, index); // Clean up MemPtrFree(note); return result; }
Boolean NewFindHappyDaysField() { AddrAppInfoPtr addrInfoPtr; Int16 i; gHappyDaysField = -1; if ((addrInfoPtr = (AddrAppInfoPtr)AppInfoGetPtr(AddressDB))) { for (i= firstRenameableLabel; i <= lastRenameableLabel; i++) { if (!StrCaselessCompare(addrInfoPtr->fieldLabels[i], gPrefsR.custom)) { gHappyDaysField = i; break; } } MemPtrUnlock(addrInfoPtr); } if (gHappyDaysField < 0) { // Custom field에 일치하는 게 없는 경우에는 note field를 조사 return true; } return true; }
/* Create new item in app database */ static UInt16 DoTheBoogie(KleenexPtr kleenexP, DmOpenRef dbR, UInt16 *index) { AddrDBRecordType addr; UInt16 ii, category; Char catName[dmCategoryLength]; Char *fn, *cn; MemSet(&addr, sizeof(AddrDBRecordType), 0); // Set up the new record addr.options.phones.phone1 = workLabel; addr.options.phones.phone2 = homeLabel; addr.options.phones.phone3 = faxLabel; addr.options.phones.phone4 = otherLabel; addr.options.phones.phone5 = emailLabel; // Add user data if (((*kleenexP->text >= '0') && (*kleenexP->text <= '9')) || (*kleenexP->text == '+')) { // User provided a phone number addr.fields[phone1] = kleenexP->text; } else if ((fn = StrChr(kleenexP->text, (WChar)';')) && (cn = StrChr(&fn[1], (WChar)';'))) { // Format is 'last name; first name; company name' *fn = '\0'; do { fn++; } while (*fn == ' '); *cn = '\0'; do { cn++; } while (*cn == ' '); if (*kleenexP->text) addr.fields[name] = kleenexP->text; if (*fn) addr.fields[firstName] = fn; if (*cn) addr.fields[company] = cn; } else if (StrChr(kleenexP->text, (WChar)' ')) { // If it has a space, put it in the company name field addr.fields[company] = kleenexP->text; } else { // Assume a single word is just a last name addr.fields[name] = kleenexP->text; } // Set up category category = dmUnfiledCategory; if (kleenexP->category) { StrCopy(catName, ""); for (ii=0; ii<dmRecNumCategories; ii++) { CategoryGetName(dbR, ii, catName); if (!StrCaselessCompare(catName, kleenexP->category)) { category = ii; break; } } } // Add it to the DB return (AddrDBNewRecord(dbR, &addr, category, index)); }
/*-----------------------------------------CIRexxApp::initializeIndexDatabase-+ | | +----------------------------------------------------------------------------*/ void CIRexxApp::initializeIndexDatabase() { m_isScriptIndexDBInitialized = true; Err err; char categoryName[dmCategoryLength]; // Open MemoPad's DB as a source for scripts. m_memoDB = new CDatabase( 0, "MemoDB", sysFileCMemo, 'data', false, false, dmModeReadOnly ); for (m_memoCategory = 0; m_memoCategory < dmRecNumCategories; ++m_memoCategory) { CategoryGetName(m_memoDB->GetDatabasePtr(), m_memoCategory, categoryName); if (!StrCaselessCompare(categoryName, "REXX")) { break; } } if (m_memoCategory == dmRecNumCategories || m_memoDB->NumRecordsInCategory(m_memoCategory) == 0) { delete m_memoDB; m_memoDB = 0; } //<<<JAL TODO: I think CategoryGetName() will core dump // if the db has no categories. So, we should probably // check the db attrs before doing this. // Open pedit's DB as a source for scripts. // Since this DB may not exist (unlike MmeoPad's) // then Open() or CategoryGetName() may throw an exception // that we'll have to handle properly. try { m_pedit32DB = new CDatabase(); err = m_pedit32DB->Open(0, "Memo32DB", dmModeReadOnly); for (m_pedit32Category = 0; m_pedit32Category < dmRecNumCategories; ++m_pedit32Category) { CategoryGetName(m_pedit32DB->GetDatabasePtr(), m_pedit32Category, categoryName); if (!StrCaselessCompare(categoryName, "REXX")) { break; } } if (m_pedit32Category == dmRecNumCategories || m_pedit32DB->NumRecordsInCategory(m_pedit32Category) == 0) { delete m_pedit32DB; m_pedit32DB = 0; } } catch (...) { delete m_pedit32DB; m_pedit32DB = 0; } // Open our own DB as a source for scripts. try { m_rexxDB = new CDatabase(); err = m_rexxDB->Open(0, "RexxDB", dmModeReadOnly); for (m_rexxCategory = 0; m_rexxCategory < dmRecNumCategories; ++m_rexxCategory) { CategoryGetName(m_rexxDB->GetDatabasePtr(), m_rexxCategory, categoryName); if (!StrCaselessCompare(categoryName, "REXX")) { break; } } if (m_rexxCategory == dmRecNumCategories || m_rexxDB->NumRecordsInCategory(m_rexxCategory) == 0) { delete m_rexxDB; m_rexxDB = 0; } } catch (...) { delete m_rexxDB; m_rexxDB = 0; } if (m_memoDB == 0 && m_pedit32DB == 0 && m_rexxDB == 0) { return; } // Create an index and then index each database so that we can // serialize the index into a actual POL database for grid mapping. CArray<ScriptRecord *> records; addRecordsToIndex(records, m_pedit32DB, m_pedit32Category, "P"); addRecordsToIndex(records, m_memoDB, m_memoCategory, "M"); addRecordsToIndex(records, m_rexxDB, m_rexxCategory, "R"); m_scriptIndexDB = new CDatabase(0, "RexxScriptIndexDB", CREATORID, 'temp'); m_scriptIndexDB->RemoveAllRecords(); for (int i = 0; i < records.GetCount(); ++i) { ScriptRecord * sr = records[i]; CRecordStream rs(m_scriptIndexDB); rs << sr->m_title; //<<<JAL TODO: YUCK! MOVE ACCESS TO ScriptRecord CLASS! rs << sr->m_dbi; rs << (UInt32)sr->m_db; rs << sr->m_indexes.GetCount(); for (int j = 0; j < sr->m_indexes.GetCount(); ++j) { rs << sr->m_indexes[j] << sr->m_segments[j]; } } for (int i = 0; i < records.GetCount(); ++i) { delete records[i]; } return; }
/*------------------------------------------------------CIRexxApp::FindLaunch-+ | | +----------------------------------------------------------------------------*/ Err CIRexxApp::FindLaunch(FindParamsPtr pFindParams) { //<<<JAL TODO: This is currently dependent on the Rexx category. // I'm not sure if we'll ever need to change/add-to this, // but if we do, then this code will have to be changed // along with the GoTo command. Err err; LocalID dbID; UInt16 cardNo = 0; DmOpenRef dbP; DmSearchStateType searchState; UInt16 recordNum; MemHandle hRecord; UInt32 pos; UInt16 matchLength; Boolean match, full; RectangleType r; UInt32 type; UInt32 creator; // Open our database (should we search MemoPad and pedit, too?) // and do our Find. We define the semantics of Find, so // instead of searching the whole records for the search string, // let's just search for scripts with the search string as their "name." if (FindDrawHeader(pFindParams, "Rexx Scripts")) { goto m_return; } if ((err = DmGetNextDatabaseByTypeCreator( true, &searchState, 'data', CREATORID, true, &cardNo, &dbID)) != errNone) { pFindParams->more = false; return errNone; } if ((err = DmDatabaseInfo(0, dbID, 0, 0, 0, 0, 0, 0, 0, 0, 0, &type, &creator)) != errNone || (type != 'data' && creator != CREATORID)) { pFindParams->more = false; return errNone; } if ((dbP = DmOpenDatabase(cardNo, dbID, pFindParams->dbAccesMode)) == 0 || DmGetAppInfoID(dbP) == 0) { /* if categories not initialized then CategoryGetName throws fatal error */ pFindParams->more = false; return errNone; } UInt16 category; char categoryName[dmCategoryLength]; for (category = 0; category < dmRecNumCategories; ++category) { CategoryGetName(dbP, category, categoryName); if (!StrCaselessCompare(categoryName, "REXX")) { break; } } if (category == dmRecNumCategories) { goto m_return; } // set it to dmAllCategories? UInt32 romVersion; FtrGet(sysFtrCreator, sysFtrNumROMVersion, &romVersion); full = false; recordNum = pFindParams->recordNum; while (true) { // Because applications can take a long time to finish a Find when // the result may already be on the screen, or for other reasons, // users like to be able to stop the Find. So, stop it if any event // is pending, i.e., if the user does something with the device. // Because actually checking if an event is pending slows the // search itself, just check it every so many records. if ((recordNum & 0x000f) == 0 && EvtSysEventAvail(true)) { pFindParams->more = true; break; } if (!(hRecord = DmQueryNextInCategory(dbP, &recordNum, category))) { pFindParams->more = false; break; } Char * p = (char *)MemHandleLock(hRecord); UInt32 isInternational; err = FtrGet(sysFtrCreator, sysFtrNumIntlMgr, &isInternational); if (err == errNone && isInternational) { match = TxtFindString(p, pFindParams->strToFind, &pos, &matchLength); } else { match = TxtGlueFindString(p, pFindParams->strToFind, &pos, &matchLength); } if (match) { // Add the match to the find paramter block. // If there is no room to display the match // then the following function will return true. full = FindSaveMatch(pFindParams, recordNum, (UInt16)pos, 0, 0, cardNo, dbID); if (!full) { // Get the bounds of the region where we will draw the results, and // display the title of the description neatly in that area. FindGetLineBounds(pFindParams, &r); Int16 x = r.topLeft.x + 1; Int16 y = r.topLeft.y; Int16 w = r.extent.x - 2; Char * cr = StrChr(p, linefeedChr); UInt16 titleLen = (cr == 0)? StrLen(p) : cr - p; Int16 fntWidthToOffset; if (romVersion >= sysMakeROMVersion(3, 1, 0, sysROMStageRelease, 0)) { fntWidthToOffset = FntWidthToOffset(p, titleLen, w, 0, 0); } else { fntWidthToOffset = FntGlueWidthToOffset(p, titleLen, w, 0, 0); } if (fntWidthToOffset == titleLen) { WinDrawChars(p, titleLen, x, y); } else { Int16 titleWidth; titleLen = FntWidthToOffset(p, titleLen, w - FntCharWidth(chrEllipsis), 0, &titleWidth); WinDrawChars(p, titleLen, x, y); WinDrawChar (chrEllipsis, x + titleWidth, y); } ++pFindParams->lineNumber; } } MemHandleUnlock(hRecord); if (full) { break; } ++recordNum; } m_return: DmCloseDatabase(dbP); return errNone; }
static Err FlickrDetectExtensionAndType(const ExgSocketType* socket, const char*& ext, const char*& type, const char*& name) { const char* url = socket->name; if (NULL == url) return exgErrBadData; name = StrChr(url, ':'); if (NULL == name) return exgErrBadData; ++name; ext = NULL; type = NULL; bool extFromType = false; const char* pos = StrChr(url, '.'); if (NULL != pos) { while (NULL != pos) { ext = pos; pos = StrChr(pos + 1, '.'); } if (0 == StrCaselessCompare(ext, EXT_JPG) || 0 == StrCaselessCompare(ext, EXT_JPEG)) type = TYPE_JPEG; else if (0 == StrCaselessCompare(ext, EXT_PNG)) type = TYPE_PNG; else if (0 == StrCaselessCompare(ext, EXT_GIF)) type = TYPE_GIF; else { DMSG("FlickrDetectExtensionAndType() unknown file extension: "); DMSG(ext); DENDL; return exgErrBadData; } } else extFromType = true; if (NULL == socket->type) { if (extFromType) { DMSG("FlickrDetectExtensionAndType() no extension nor mimeType"); DENDL; return exgErrBadData; } assert(type != NULL); return errNone; } if (NULL != type && 0 != StrCaselessCompare(type, socket->type)) { DMSG("FlickrDetectExtensionAndType() extension and mimeType mismatch; ext: "); DMSG(ext); DMSG("; type: "); DMSG(type); DENDL; } type = socket->type; if (extFromType) { if (0 == StrCaselessCompare(type, TYPE_JPEG)) ext = EXT_JPG; else if (0 == StrCaselessCompare(type, TYPE_PNG)) ext = EXT_PNG; else if (0 == StrCaselessCompare(type, TYPE_GIF)) ext = EXT_GIF; else { DMSG("FlickrDetectExtensionAndType() unknown mimeType: "); DMSG(type); DENDL; return exgErrBadData; } } return errNone; }