Int16 AnalizeOneRecord(UInt16 addrattr, Char* src, HappyDays* hd, Boolean *ignore) { Char *p, *q; UInt16 index; Int16 err; Int16 year, month, day; Int16 nth[20]; Int16 count = 0; while (*src == ' ' || *src == '\t') src++; // skip white space // ignore record with exclamation mark if (*src == '!') { if (gPrefsR.ignoreexclamation) return 0; else src++; } if ((q = StrChr(src, '['))) { // [ 이 있는 경우 duration으로 판단 p = q; q = StrChr(src, ']'); if (q) *q = 0; else return 0; do { p++; nth[count++] = StrAToI(p); if (count >= 20) break; } while ((p = StrChr(p, ','))); } if (*src == '*') { // this is multiple event hd->flag.bits.multiple_event = true; if ((p = StrChr(src, ' '))) *p = 0; else goto ErrHandler; if ( *(src+1) != 0 ) { // if src have 'custom' tag hd->custom = src+1; UnderscoreToSpace(src+1); } else hd->custom = 0; src = p+1; while (*src == ' ' || *src == '\t') src++; // skip white space if ((p = StrChr(src, ' '))) *p = 0; else goto ErrHandler; if (*src == '.') { hd->name1 = src+1; hd->name2 = 0; } else { hd->name2 = src; } UnderscoreToSpace(src); src = p+1; while (*src == ' ' || *src == '\t') src++; // skip white space } if (!AnalysisHappyDays(src, &hd->flag, &year, &month, &day)) goto ErrHandler; // convert into date format // if (hd->flag.bits.year) { if ((year < 1904) || (year > 2031) ) goto ErrHandler; else hd->date.year = year - 1904; } else hd->date.year = 0; hd->date.month = month; hd->date.day = day; // maintain address book order(name order) // list order is determined by sort err = HDNewRecord(MainDB, hd, &index); if (!err) { UInt16 attr; // set the category of the new record to the category // it belongs in DmRecordInfo(MainDB, index, &attr, NULL, NULL); attr &= ~dmRecAttrCategoryMask; attr |= addrattr; DmSetRecordInfo(MainDB, index, &attr, NULL); DmReleaseRecord(MainDB, index, true); } if (count > 0) { Int16 i; HappyDays hdr; for (i = 0; i < count; i++) { MemMove(&hdr, hd, sizeof(hdr)); hdr.flag.bits.nthdays = 1; hdr.nth = nth[i]; if (!hdr.flag.bits.year) goto ErrHandler; err = HDNewRecord(MainDB, &hdr, &index); if (!err) { UInt16 attr; // set the category of the new record to the category // it belongs in DmRecordInfo(MainDB, index, &attr, NULL, NULL); attr &= ~dmRecAttrCategoryMask; attr |= addrattr; DmSetRecordInfo(MainDB, index, &attr, NULL); DmReleaseRecord(MainDB, index, true); } } } return 0; ErrHandler: if (*ignore) return 0; switch (FrmCustomAlert(InvalidFormat, ((!hd->name2) ? ((!hd->name1) ? " " : hd->name1) : hd->name2), " ", " ")) { case 0: // EDIT if (!GotoAddress(hd->addrRecordNum)) return -1; case 2: // Ignore all *ignore = true; case 1: break; // Ignore } return 0; }
static Boolean ExamDetailsFormSave(void) { MemHandle newExam=NULL; UInt16 index = dmMaxRecordIndex; ListType *course; ControlType *course_tr, *date_tr, *time_tr; Char *room; Char empty[1]={'\0'}; FieldType *fldRoom; course = GetObjectPtr(LIST_exd_course); course_tr = GetObjectPtr(LIST_exd_course_trigger); date_tr = GetObjectPtr(SELECTOR_exd_date); time_tr = GetObjectPtr(SELECTOR_exd_time); fldRoom = GetObjectPtr(FIELD_exd_room); room = FldGetTextPtr(fldRoom); if (room == NULL) room=empty; if (gExamsLastSelRowUID == 0) { // New record newExam = DmNewRecord(DatabaseGetRefN(DB_MAIN), &index, sizeof(ExamDBRecord)); } else { // Load record DmFindRecordByID(DatabaseGetRefN(DB_MAIN), gExamsLastSelRowUID, &index); newExam = DmGetRecord(DatabaseGetRefN(DB_MAIN), index); } if (! newExam) { // Could not create entry FrmAlert(ALERT_nomem); return false; } else { UInt16 attr=0; ExamDBRecord ex, *ep; ep = (ExamDBRecord *)MemHandleLock(newExam); ex.type=TYPE_EXAM; ex.course=gExamDetailsItemIDs[LstGetSelection(course)]; ex.note = (gExamsLastSelRowUID == 0) ? 0 : ep->note; ex.date.year = gExamDetailsDate.year; ex.date.month = gExamDetailsDate.month; ex.date.day = gExamDetailsDate.day; ex.begin.hours = gExamDetailsBegin.hours; ex.begin.minutes = gExamDetailsBegin.minutes; ex.end.hours = gExamDetailsEnd.hours; ex.end.minutes = gExamDetailsEnd.minutes; ex.flags = 0x0000; StrNCopy(ex.room, room, sizeof(ex.room)); DmWrite(ep, 0, &ex, sizeof(ExamDBRecord)); MemHandleUnlock(newExam); DmReleaseRecord(DatabaseGetRef(), index, false); DmRecordInfo(DatabaseGetRef(), index, &attr, NULL, NULL); attr |= DatabaseGetCat(); DmSetRecordInfo(DatabaseGetRef(), index, &attr, NULL); DatabaseSort(); } AlarmReset(DatabaseGetRef()); return true; }
/** * @brief Read the happydays information from address db, and insert into Happydays DB * @param frm StartForm to display indicator bars * @return If success, return true, or return false */ Boolean NewUpdateHappyDaysDB(FormPtr frm) { UInt16 currIndex = 0; PrvAddrPackedDBRecord *rp; AddrDBRecordType r; MemHandle recordH = 0; UInt16 recordNum; int i = 0, indicateNext; int step; // create the happydays cache db HappyDays hd; Boolean ignore = false; // ignore error record Char* hdField; UInt16 addrattr, index; Char *p, *q, *end; Int16 err; // display collecting information // FrmDrawForm(frm); // clean up old database // CleanupHappyDaysCache(MainDB); recordNum = DmNumRecords(AddressDB); indicateNext = step = recordNum / INDICATE_NUM; if (recordNum > 50) initIndicate(); while (1) { char *name1, *name2; Int8 whichField; // birthday field or note field? recordH = DmQueryNextInCategory(AddressDB, &currIndex, dmAllCategories); if (!recordH) break; if (i++ == indicateNext) { if (recordNum > 50) displayNextIndicate( (i-1) / step); indicateNext += step; } DmRecordInfo(AddressDB, currIndex, &addrattr, NULL, NULL); addrattr &= dmRecAttrCategoryMask; // get category info rp = (PrvAddrPackedDBRecord*)MemHandleLock(recordH); /* * Build the unpacked structure for an AddressDB record. It * is just a bunch of pointers into the rp structure. */ NewAddrUnpack(rp, &r); if ( (gHappyDaysField <= 0 || !r.fields[gHappyDaysField]) // there is no birthday info(trick. should check flags, but I think it is ok) // && DateToInt(r.birthdayInfo.birthdayDate) == 0 && !(gPrefsR.scannote && r.fields[note] && StrStr(r.fields[note], gPrefsR.notifywith) ) ) { // If there is not exist Happydays field or note field, or internal birthday field(in NEW PIMS) // MemHandleUnlock(recordH); currIndex++; continue; } MemSet(&hd, sizeof(hd), 0); hd.addrRecordNum = currIndex; if (DetermineRecordName(&r, gSortByCompany, &hd.name1, &hd.name2)) { // name 1 has priority; hd.flag.bits.priority_name1 = 1; } // =========================================================== // Process Birthday field first // =========================================================== if (DateToInt(r.birthdayInfo.birthdayDate) != 0) { hd.date = r.birthdayInfo.birthdayDate; hd.flag.bits.year = 1; hd.flag.bits.solar = 1; // maintain address book order(name order) // list order is determined by sort err = HDNewRecord(MainDB, &hd, &index); if (!err) { UInt16 attr; // set the category of the new record to the category // it belongs in DmRecordInfo(MainDB, index, &attr, NULL, NULL); attr &= ~dmRecAttrCategoryMask; attr |= addrattr; DmSetRecordInfo(MainDB, index, &attr, NULL); DmReleaseRecord(MainDB, index, true); } } // =========================================================== // save the temporary name name1 = hd.name1; name2 = hd.name2; if (gHappyDaysField >= 0 && r.fields[gHappyDaysField]) { whichField = gHappyDaysField; } else if (gPrefsR.scannote // scanNote & exists && r.fields[note] && StrStr(r.fields[note], gPrefsR.notifywith)) { whichField = note; } else whichField = -1; while (whichField >= 0) { if (whichField == note) { p = StrStr(r.fields[note], gPrefsR.notifywith) + StrLen(gPrefsR.notifywith) + 1; if ( StrLen(r.fields[note]) < (p - r.fields[note]) ) break; } else { p = r.fields[whichField]; } hdField = MemPtrNew(StrLen(r.fields[whichField]) - (p - r.fields[whichField])+1); SysCopyStringResource(gAppErrStr, NotEnoughMemoryString); ErrFatalDisplayIf(!hdField, gAppErrStr); p = StrCopy(hdField, p); if (whichField == note && (end = StrStr(p, gPrefsR.notifywith))) { // end delimeter // *end = 0; } while ((q = StrChr(p, '\n'))) { // multiple event // *q = 0; if (AnalizeOneRecord(addrattr, p, &hd, &ignore)) goto Update_ErrHandler; p = q+1; // restore the saved name hd.name1 = name1; hd.name2 = name2; // reset multiple flag hd.flag.bits.multiple_event = 0; while (*p == ' ' || *p == '\t' || *p == '\n') p++; // skip white space } // last record if (*p) { // check the null '\n' if (AnalizeOneRecord(addrattr, p, &hd, &ignore)) goto Update_ErrHandler; } if (whichField == gHappyDaysField // next is note field && (gPrefsR.scannote // scanNote & exists && r.fields[note] && StrStr(r.fields[note], gPrefsR.notifywith)) ) { whichField = note; } else whichField = -1; MemPtrFree(hdField); } MemHandleUnlock(recordH); currIndex++; } if (recordNum > 50) displayNextIndicate( INDICATE_NUM -1); return true; Update_ErrHandler: MemPtrFree(hdField); MemHandleUnlock(recordH); return false; }