Boolean StartScummVM() { Char **argvP; UInt8 lightspeed, argc = 0; UInt32 stackSize; Boolean toLauncher, direct, isARM; UInt8 engine; Char num[6]; UInt16 index = GamGetSelected(); argvP = ArgsInit(); direct = false; // start command line (exec name) ArgsAdd(&argvP[argc], "-", NULL, &argc); // no game selected if (index == dmMaxRecordIndex) { ListPtr listP; UInt16 whichButton; // init form FormPtr frmP = FrmInitForm(EngineForm); listP = (ListType *)FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, EngineListList)); itemsText = (Char **)MemPtrNew(ENGINE_COUNT * sizeof(Char *)); for (int i = 0; i < ENGINE_COUNT; i++) itemsText[i] = (Char *)engines[i].nameP; LstSetListChoices (listP, itemsText, ENGINE_COUNT); LstSetSelection(listP, 0); whichButton = FrmDoDialog(frmP); engine = LstGetSelection(listP); FrmDeleteForm(frmP); MemPtrFree(itemsText); itemsText = NULL; if (whichButton == EngineCancelButton) { if (bDirectMode) { // and force exit if nothing selected EventType event; event.eType = keyDownEvent; event.data.keyDown.chr = vchrLaunch; event.data.keyDown.modifiers = commandKeyMask; EvtAddUniqueEventToQueue(&event, 0, true); } // free args ArgsFree(argvP); return false; } // default values if (bDirectMode) gPrefs->card.volRefNum = parseCards(); // always use the first removable card available (?) gVars->filter = true; gVars->palmVolume = 50; gVars->fmQuality = FM_QUALITY_INI; direct = true; // somthing selected } else { Char pathP[256]; MemHandle recordH; GameInfoType *gameInfoP; recordH = DmQueryRecord(gameDB,index); gameInfoP = (GameInfoType *)MemHandleLock(recordH); engine = gameInfoP->engine; // build path StrCopy(pathP,"/Palm/Programs/ScummVM/Games/"); if (gameInfoP->pathP[0] == '/') StrCopy(pathP, gameInfoP->pathP); else if (!(gameInfoP->pathP[0] == '.' && StrLen(gameInfoP->pathP) == 1)) StrCat(pathP, gameInfoP->pathP); // path ArgsAdd(&argvP[argc], "-p", pathP, &argc); // language if (gameInfoP->language > 0) { const Char *lang = "zh\0cz\0gb\0en\0fr\0de\0hb\0it\0jp\0kr\0pl\0pt\0ru\0es\0se\0"; ArgsAdd(&argvP[argc], "-q", (lang + (gameInfoP->language - 1) * 3), &argc); } // fullscreen ? if (gameInfoP->fullscreen) ArgsAdd(&argvP[argc], "-f", NULL, &argc); // aspect-ratio ? ArgsAdd(&argvP[argc], (gameInfoP->aspectRatio ? "--aspect-ratio" : "--no-aspect-ratio"), NULL, &argc); // gfx mode gVars->filter = gameInfoP->filter; switch (gameInfoP->renderMode) { case 1: ArgsAdd(&argvP[argc], "--render-mode=", "amiga", &argc); break; case 2: ArgsAdd(&argvP[argc], "--render-mode=", "cga", &argc); break; case 3: ArgsAdd(&argvP[argc], "--render-mode=", "ega", &argc); break; case 4: ArgsAdd(&argvP[argc], "--render-mode=", "hercAmber", &argc); break; case 5: ArgsAdd(&argvP[argc], "--render-mode=", "hercGreen", &argc); break; } switch (gameInfoP->gfxMode) { case 1: ArgsAdd(&argvP[argc], "-g", "wide", &argc); break; default: ArgsAdd(&argvP[argc], "-g", "1x", &argc); break; } // load state if (gameInfoP->autoLoad) { StrIToA(num, gameInfoP->loadSlot); ArgsAdd(&argvP[argc], "-x", num, &argc); } // boot script parameter if (gameInfoP->bootParam) { StrIToA(num, gameInfoP->bootValue); ArgsAdd(&argvP[argc], "-b", num, &argc); } // not a PC version if (gameInfoP->setPlatform) { static const char *platform[] = { "3do", "acorn", "amiga", "atari", "c64", "pc", "fmtowns", "linux", "mac", "nes", "segacd", "windows" }; ArgsAdd(&argvP[argc], "--platform=", platform[gameInfoP->platform], &argc); } // subtitles if (gameInfoP->subtitles) ArgsAdd(&argvP[argc], "-n", NULL, &argc); // multi midi ? if (gameInfoP->musicInfo.sound.multiMidi) ArgsAdd(&argvP[argc], "--multi-midi", NULL, &argc); if (engine == ENGINE_SCUMM) { // music tempo StrIToA(num, gameInfoP->musicInfo.sound.tempo); ArgsAdd(&argvP[argc], "--tempo=", num, &argc); } // talk speed if (gameInfoP->talkSpeed) { StrIToA(num, gameInfoP->talkValue); ArgsAdd(&argvP[argc], "--talkspeed=", num, &argc); } // music driver if (gameInfoP->musicInfo.sound.music) { static char *drv[] = { "auto", "null", "adlib", "towns", "pcjr", "native", "pcspk" }; if (StrCompare(drv[gameInfoP->musicInfo.sound.drvMusic], "native") == 0) { if (OPTIONS_TST(kOptDeviceZodiac)) ArgsAdd(&argvP[argc], "-e", "zodiac", &argc); // Tapwave Zodiac else if (OPTIONS_TST(kOptSonyPa1LibAPI)) ArgsAdd(&argvP[argc], "-e", "ypa1", &argc); // Pa1Lib devices else ArgsAdd(&argvP[argc], "-e", "auto", &argc); // no driver, switch to auto } else { ArgsAdd(&argvP[argc], "-e", drv[gameInfoP->musicInfo.sound.drvMusic], &argc); } // output rate UInt32 rates[] = {4000, 8000, 11025, 22050, 44100}; StrIToA(num, rates[gameInfoP->musicInfo.sound.rate]); ArgsAdd(&argvP[argc], "--output-rate=", num, &argc); // FM quality gVars->fmQuality = gameInfoP->fmQuality; } else { ArgsAdd(&argvP[argc], "-e", "null", &argc); } // volume control StrIToA(num, gameInfoP->musicInfo.volume.sfx); ArgsAdd(&argvP[argc], "-s", num, &argc); StrIToA(num, gameInfoP->musicInfo.volume.music); ArgsAdd(&argvP[argc], "-m", num, &argc); StrIToA(num, gameInfoP->musicInfo.volume.speech); ArgsAdd(&argvP[argc], "-r", num, &argc); // game name ArgsAdd(&argvP[argc], gameInfoP->gameP, NULL, &argc); // others globals data gVars->CD.enable = gameInfoP->musicInfo.sound.CD; gVars->CD.driver = gameInfoP->musicInfo.sound.drvCD; gVars->CD.format = gameInfoP->musicInfo.sound.frtCD; gVars->CD.volume = gameInfoP->musicInfo.volume.audiocd; gVars->CD.defaultTrackLength = gameInfoP->musicInfo.sound.defaultTrackLength; gVars->CD.firstTrack = gameInfoP->musicInfo.sound.firstTrack; gVars->palmVolume = gameInfoP->musicInfo.sound.music ? gameInfoP->musicInfo.volume.palm : 0; MemHandleUnlock(recordH); } // end no game / game selected // common command line options // debug level if (gPrefs->debug) { StrIToA(num, gPrefs->debugLevel); ArgsAdd(&argvP[argc], "-d", num, &argc); } if (engine == ENGINE_QUEEN || engine == ENGINE_SKY) { // alternative intro ? if (gPrefs->altIntro) ArgsAdd(&argvP[argc], "--alt-intro", NULL, &argc); } if (engine == ENGINE_SCUMM) { // demo mode ? if (gPrefs->demoMode) ArgsAdd(&argvP[argc], "--demo-mode", NULL, &argc); } // copy protection ? if (gPrefs->copyProtection) ArgsAdd(&argvP[argc], "--copy-protection", NULL, &argc); // exceed max args ? if (argc > MAX_ARG) FrmCustomAlert(FrmErrorAlert, "Too many parameters.",0,0); // set some common options stackSize = (gPrefs->setStack ? STACK_LARGER : STACK_DEFAULT); lightspeed= (gPrefs->lightspeed.enable ? gPrefs->lightspeed.mode : 255); toLauncher= (gPrefs->exitLauncher); // gVars values // (gVars->HRrefNum defined in checkHRmode on Clié) gVars->VFS.volRefNum = gPrefs->card.volRefNum; gVars->vibrator = gPrefs->vibrator; gVars->stdPalette = gPrefs->stdPalette; gVars->VFS.cacheSize = (gPrefs->card.useCache ? gPrefs->card.cacheSize : 0); gVars->indicator.showLED= gPrefs->card.showLED; gVars->stylusClick = gPrefs->stylusClick; gVars->autoSave = (gPrefs->autoSave ? gPrefs->autoSavePeriod : -1); gVars->advancedMode = gPrefs->advancedMode; gVars->arrowKeys = gPrefs->arrowKeys; // user params HWR_RSTALL(); if (gPrefs->goLCD) HWR_SET(INIT_GOLCD); else OPTIONS_RST(kOptGoLcdAPI); if (!gPrefs->autoOff) HWR_SET(INIT_AUTOOFF); if (gVars->vibrator) HWR_SET(INIT_VIBRATOR); /* ???? if ( musicDriver == 1 || musicDriver == 3 || musicDriver == 4 || musicDriver == sysInvalidRefNum) { HWR_SET(INIT_PA1LIB); } */ if (ModImport(gVars->VFS.volRefNum, engine, &isARM) != errNone) { if (bDirectMode) { // and force exit if nothing selected EventType event; event.eType = keyDownEvent; event.data.keyDown.chr = vchrLaunch; event.data.keyDown.modifiers = commandKeyMask; EvtAddUniqueEventToQueue(&event, 0, true); } ArgsFree(argvP); return false; } // reset mode if screen rotation occured (DIA only) if (!direct && OPTIONS_TST(kOptCollapsible)) { UInt8 mode = PalmScreenSize(0,0, &(gVars->screenFullWidth), &(gVars->screenFullHeight)); OPTIONS_RST(kOptModeLandscape); OPTIONS_SET((mode == PALM_LANDSCAPE) ? kOptModeLandscape : kOptNone); } // free and save globals pref memory GamCloseDatabase(false); FrmCloseAllForms(); SavePrefs(); { UInt16 cardNo; UInt32 dbID; LaunchParamType *cmdPBP = (LaunchParamType *)MemPtrNew(sizeof(LaunchParamType)); MemPtrSetOwner(cmdPBP, 0); MemPtrSetOwner(gVars, 0); ArgsSetOwner(argvP, 0); cardNo = 0; dbID = DmFindDatabase(0, "ScummVM-Engine"); if (isARM) FtrSet(appFileCreator, ftrStack , (stackSize * 4)); else ModSetStack(stackSize, cardNo, dbID); cmdPBP->args.argc = argc; cmdPBP->args.argv = argvP; cmdPBP->gVars = gVars; cmdPBP->lightspeed = lightspeed; cmdPBP->exitLauncher = toLauncher; SysUIAppSwitch(cardNo, dbID, sysAppLaunchCmdNormalLaunch, cmdPBP); bLaunched = true; } return false; }
void free(void *p) { if (p) MemPtrFree(p); }
/* ** FinishXferMode */ void FinishXferMode(void) { KleenexType kleenex; DtbkRepeatInfoType repeat; FormType* frm = FrmGetActiveForm(); SysDBListItemType* pluglistP = NULL; Int16 current_plug = -1; UInt32 result; Boolean is_goto = false; Err err = errNone; Char cat_name[dmCategoryLength]; Char* note = NULL; UInt16 attr; /* Zero the kleenex */ MemSet(&kleenex, sizeof(KleenexType), 0); /* Bail if no plugins installed */ if (!d.xfer.pluglistH) { FrmAlert(NoPluginInstalled); return; } /* Lock the plugin list */ pluglistP = MemHandleLock(d.xfer.pluglistH); current_plug = GetCurrentXferAppListIndex(); if (current_plug == -1) { FrmAlert(NoPluginSelected); MemHandleUnlock(d.xfer.pluglistH); return; } /* Set the version */ if (pluglistP[current_plug].version & IBVERSION_PICTURE) kleenex.version = IBVERSION_PICTURE; else if (pluglistP[current_plug].version & IBVERSION_ORIG) kleenex.version = IBVERSION_ORIG; else abort(); /* Add flag notifier */ kleenex.version |= IBVERSION_FLAGS; /* Set flags */ if (d.hires) kleenex.flags = IBFLAG_HIRES; /* Set the current record index */ kleenex.sketchRecordNum = p.dbI; /* Set the pick text */ kleenex.text = GetLink(FldGetTextPtr(GetObjectPointer(frm, XferField))); if (!kleenex.text) { FlashWaitMessage(XferNoTextString); MemHandleUnlock(d.xfer.pluglistH); return; } /* Set the title text */ kleenex.title = MemHandleLock(d.record_name); /* Set the category text */ DmRecordInfo(d.dbR, p.dbI, &attr, NULL, NULL); CategoryGetName(d.dbR, attr & dmRecAttrCategoryMask, cat_name); kleenex.category = cat_name; /* Set the note */ note = MemHandleLock(d.record_note); if (StrLen(note)) kleenex.note = note; /* Set the seconds for the alarm */ if (recordIsAlarmSet) kleenex.alarm_secs = d.record.alarmSecs; /* Set the repeat information */ kleenex.repeat = &repeat; switch (d.record.repeatInfo.repeatType) { case repeatDaily: case repeatWeekly: case repeatMonthlyByDay: case repeatMonthlyByDate: case repeatYearly: repeat.repeatType = d.record.repeatInfo.repeatType - 1; /* fix offset caused by repeatHourly */ repeat.repeatFrequency = d.record.repeatInfo.repeatFrequency; repeat.repeatEndDate = d.record.repeatInfo.repeatEndDate; repeat.repeatOn = d.record.repeatInfo.repeatOn; repeat.repeatStartOfWeek = d.record.repeatInfo.repeatStartOfWeek; break; case repeatNone: case repeatHourly: default: kleenex.repeat = NULL; } /* Set the priority */ kleenex.priority = d.record.priority + 1; /* DiddleBug priority is zero-based */ /* Set the completion flag */ if ((d.xfer.complete || (xferCompleteIsAlways)) && !(xferCompleteIsNever)) kleenex.is_complete = 1; else kleenex.is_complete = 0; /* Load the sketch data */ if (kleenex.version & IBVERSION_PICTURE) { if (!d.sonyClie || !d.hires) { kleenex.data = BmpGetBits(WinGetBitmap(d.winbufM)); kleenex.data_size = BmpBitsSize(WinGetBitmap(d.winbufM)); } else { kleenex.data = BmpGetBits(WinGetBitmap(d.winbufM)); kleenex.data_size = HRBmpBitsSize(d.sonyHRRefNum, WinGetBitmap(d.winbufM)); } } /* Call the plugin */ err = SysAppLaunch(pluglistP[current_plug].cardNo, pluglistP[current_plug].dbID, 0, boogerPlugLaunchCmdBlowNose, (MemPtr)&kleenex, &result); /* Clean up some stuff */ MemHandleUnlock(d.xfer.pluglistH); MemPtrFree(kleenex.text); if (err || result) { FrmAlert(PluginError); return; } /* Just to save some typing */ is_goto = (((p.flags&PFLAGS_XFER_GOTO) || (xferGotoIsAlways)) && !(xferGotoIsNever)); if (!is_goto) FlashWaitMessage(XferSavingString); /* Clean up some more */ MemHandleUnlock(d.record_name); MemHandleUnlock(d.record_note); /* Delete the sketch if selected */ if (p.flags&PFLAGS_XFER_DELETE) DoCmdRemove(); /* Goto the new sketch if required */ if (is_goto) { /* Clean up */ MemHandleFree(d.xfer.pluglistH); d.xfer.pluglistH = NULL; /* Switch to other application */ err = SysUIAppSwitch(kleenex.booger.cardNo, kleenex.booger.dbID, kleenex.booger.cmd, kleenex.booger.cmdPBP); /* Clean up on error */ if (err && kleenex.booger.cmdPBP) MemPtrFree(kleenex.booger.cmdPBP); } else { if (kleenex.booger.cmdPBP) MemPtrFree(kleenex.booger.cmdPBP); } CancelXferMode(); }
static void AppEventLoop(void) { Err error; EventType event; do { /* we should wait for 100ms only so we can server the audio */ EvtGetEvent(&event, evtWaitForever); if (SysHandleEvent(&event)) continue; if (MenuHandleEvent(0, &event, &error)) continue; if (AppHandleEvent(&event)) continue; FrmDispatchEvent(&event); /* Serve playing */ if (FlopPlay == true) { if (!flite->samples) { /* Got stuff to play and we're not currently playing */ flite->type = FlopOutputType; /* words, phones, wave, stream */ flite->text = input; /* text to be synthesized */ flite_synth_text(flite); /* do the synthesis */ flite->WavePosition = flite->start; flite->start += flite->utt_length; /* update position */ /* highlight the area being spoken */ if (flite->type != FliteOutputTypeWave) FlopPlay = false; /* we don't do async play on words/ph */ } if (playdata.samples && !playdata.active) /* stop and tidy up anything that's finished playing */ StopPlayStream(); else if (flite->samples && !playdata.active) { /* create a new stream and start it playing */ flite->PlayPosition = flite->WavePosition; SetupPlayStream(flite); SndStreamStart(playstream); } else if (!playdata.active) /* go into stop mode as there is nothing more to play */ FlopPlay = false; /* nothing more to play */ } else { if (flite && flite->output) StrPrintF(flite->output,"stopped %d",flite->PlayPosition); StopPlayStream(); /* flush any other waveform waiting to play */ if (flite->samples) { MemPtrFree(flite->samples); flite->num_samples = 0; flite->samples = 0; } } if (flite && flite->output) { /* should be within if above, but for debugging ... */ /* Update the output field with any new information */ SetField(FlopForm, FlopOutput, flite->output); FrmDrawForm(FrmGetFormPtr(FlopForm)); } } while ((FlopStop==false) && (event.eType != appStopEvent)); return; }
/******************************************************************************** * Description: this is the function responsible for checking the * input password value of the authentication form. * ******************************************************************************/ static void checkPassword (void) { MemPtr pass1, scratch = NULL; char *input; UInt16 index = 0; MemHandle rec; mdKey in; ListType *list; // compact text and get a pointer. FldCompactText (GetObjectFromActiveForm (PasswordField)); input = FldGetTextPtr (GetObjectFromActiveForm (PasswordField)); list = GetObjectFromActiveForm (selPopupList); // if SysPass is defined, free it. this happens when Strip locks // itself after the timeout. if (SysPass) MemPtrFree (SysPass); // if its the first time the user has used the program we need // to set some things up. if (input && StrLen (input)) { // read the password from the database, decrypt with the input text. if ((rec = DmQueryRecord (PasswordDB, index))) { pass1 = MemHandleLock (rec); if ((scratch = MemPtrNew (24))) { UInt16 chk = LstGetSelection (list); //printf("%d\n", LstGetSelection(list)); switch (chk) { case 0: UnpackPassword_old (pass1, scratch, input, 1); break; case 1: UnpackPassword_old (pass1, scratch, input, 2); break; case 2: UnpackPassword_old (pass1, scratch, input, 0); break; } } MemHandleUnlock (rec); } // the message digest of the password they provided should be exactly the // same as the message digest that was just decrypted out of the password // database. Do a MemCmp to make sure they are the same. md5_string (input, in); if ((!MemCmp (in, scratch, 16)) && input) { // if so, copy the password onto the system-password if ((SysPass = MemPtrNew (StrLen (input) + 1))) StrCopy (SysPass, input); if (scratch) MemPtrFree (scratch); md_string(SysPass, NewSysPass); cryptSwitch (LstGetSelection (list)); } else { // FAILURE!!!!!! // free the memory and tell the user they entered the wrong password. FieldType *fld = GetObjectFromActiveForm (PasswordField); FrmCustomAlert (GenericError, "The password you entered is incorrect", NULL, NULL); FldSetSelection (fld, 0, FldGetTextLength (fld)); LstDrawList (list); if (scratch) { MemPtrFree (scratch); SysPass = NULL; } } } // null string is always wrong!!! else { FrmCustomAlert (GenericError, "You forgot to enter a password!!", NULL, NULL); LstDrawList (list); } }
/*********************************************************************** * handling for form and control actions * menu actions are forwarded to MainFormDoCommand ***********************************************************************/ static Boolean MainFormHandleEvent (EventPtr event) { FormType *frm; Boolean handled = false; Boolean categoryEdited, reDraw=false; UInt16 category, numRecords; ControlType *ctl; UInt32 *recordList; if (event->eType == ctlSelectEvent) { // button handling handled = true; switch (event->data.ctlSelect.controlID) { // the ok button - this leaves the application case LIST_cat_trigger: frm = FrmGetActiveForm(); category=DatabaseGetCat(); numRecords=DmNumRecordsInCategory(DatabaseGetRef(), DELETE_CATEGORY); recordList=(UInt32 *)MemPtrNew(numRecords * sizeof(UInt32)); CatPreEdit(numRecords, recordList); categoryEdited = CategorySelect(DatabaseGetRef(), frm, LIST_cat_trigger, LIST_cat, false, &category, gCategoryName, 0, STRING_cat_edit); // categoryDefaultEditCategoryString if (categoryEdited || (category != DatabaseGetCat())) { reDraw=true; DatabaseSetCat(category); ctl = GetObjectPtr(LIST_cat_trigger); CategoryGetName(DatabaseGetRef(), DatabaseGetCat(), gCategoryName); CategorySetTriggerLabel(ctl, gCategoryName); } CatPostEdit(numRecords, recordList); if (reDraw) { GadgetSetNeedsCompleteRedraw(true); FrmDrawForm(frm); } if (recordList != NULL) MemPtrFree((MemPtr)recordList); break; case BUTTON_beam: BeamCourse(GadgetGetHintCourseIndex()); break; case BUTTON_edit: gMenuCurrentForm=FORM_main; EditTime(); break; case BUTTON_next: GadgetDrawHintNext(); break; default: break; } } else if (event->eType == keyDownEvent) { // We have a hard button assigned and it was pressed if (TxtCharIsHardKey(event->data.keyDown.modifiers, event->data.keyDown.chr)) { if (! (event->data.keyDown.modifiers & poweredOnKeyMask)) { GadgetDrawHintNext(); handled = true; } } else if (EvtKeydownIsVirtual(event)) { // Up or down keys pressed switch (event->data.keyDown.chr) { case vchrPageUp: if (event->data.keyDown.modifiers & autoRepeatKeyMask) { if (! gMainRepeat) { GadgetSwitchScreen(); gMainRepeat = true; } } else { GadgetDrawStep(winUp); gMainRepeat = false; } handled=true; break; case vchrPageDown: if (event->data.keyDown.modifiers & autoRepeatKeyMask) { if (! gMainRepeat) { GadgetSwitchScreen(); gMainRepeat = true; } } else { GadgetDrawStep(winDown); gMainRepeat = false; } handled=true; break; case vchrSendData: BeamCourse(GadgetGetHintCourseIndex()); handled=true; break; default: break; } } } else if (event->eType == menuEvent) { // forwarding of menu events return HandleMenuEvent(event->data.menu.itemID); } else if (event->eType == menuOpenEvent) { return HandleMenuOpenEvent(event); } else if (event->eType == frmUpdateEvent) { // redraws the form if needed frm = FrmGetActiveForm(); FrmDrawForm(frm); // GadgetDrawHintNext(); handled = true; } else if (event->eType == frmOpenEvent) { ControlType *ctl; LocalID dbID; UInt16 cardNo; Boolean newKeyP4=false; UInt16 newKeyP2=0xFFFF; // initializes and draws the form at program launch frm = FrmGetActiveForm(); GadgetSet(frm, GADGET_main, GADGET_hint); FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_main), GadgetHandler); FrmSetGadgetHandler(frm, FrmGetObjectIndex(frm, GADGET_hint), GadgetHintHandler); FrmDrawForm(frm); GadgetDrawHintNext(); ctl = GetObjectPtr(LIST_cat_trigger); CategoryGetName (DatabaseGetRef(), DatabaseGetCat(), gCategoryName); CategorySetTriggerLabel (ctl, gCategoryName); DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL); SysNotifyRegister(cardNo, dbID, sysNotifyLateWakeupEvent, HandleNotification, sysNotifyNormalPriority, NULL); KeyRates(false,&gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4); KeyRates(true, &gKeyP1, &newKeyP2, &gKeyP3, &newKeyP4); handled = true; } else if (event->eType == frmCloseEvent) { // this is done if program is closed LocalID dbID; UInt16 cardNo; DmOpenDatabaseInfo(DatabaseGetRefN(DB_MAIN), &dbID, NULL, NULL, &cardNo, NULL); SysNotifyUnregister(cardNo, dbID, sysNotifyLateWakeupEvent, sysNotifyNormalPriority); // Restore original key rates KeyRates(true, &gKeyP1, &gKeyP2, &gKeyP3, &gKeyP4); } return (handled); }
/***************************************************************************** * Function: GadgetDrawHintCurrent * * Description: Draw hint for current gTimeIndex if needed (may be forced NOT * to draw with GadgetSetNeedsRedraw(false)); *****************************************************************************/ void GadgetDrawHintCurrent(void) { Char *tmp, *bot, begin[timeStringLength], end[timeStringLength], *day; MemHandle mc, mt, mh, type; CourseDBRecord c; TimeDBRecord *tc; RectangleType rect, bounds; UInt16 gadgetIndex = FrmGetObjectIndex(gForm, gGadgetID); RGBColorType color, prevColor; UInt16 attr; // Need to check that due to damn f*** DmRecordInfo which will show a // fatal alert when called on non-existing record (this happens for example // right after creating the new database... if ((gTimeIndex >= DmNumRecords(DatabaseGetRef())) || (gCourseIndex >= DmNumRecords(DatabaseGetRef())) ) return; if (gHintDrawn) { // Delete border around previous entry if ( (gTimeDrawnIndex < DmNumRecords(DatabaseGetRef())) && (DmRecordInfo(DatabaseGetRef(), gTimeDrawnIndex, &attr, NULL, NULL) == errNone) ) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { mt = DmQueryRecord(DatabaseGetRef(), gTimeDrawnIndex); if (mt) { // mt may be null, for example if next is drawn after delete! tc = (TimeDBRecord *)MemHandleLock(mt); if ((tc->type == TYPE_TIME) && GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } color.r=tc->color[0]; color.g=tc->color[1]; color.b=tc->color[2]; if (gPrefs.showTimeline) GadgetDrawTimeline(gtErase); if (gtl != NULL) { GadgetDrawTime(tc->begin, tc->end, tc->day, &color, tc->course, gtl->num, gtl->pos); } if (gPrefs.showTimeline) GadgetDrawTimeline(gtDraw); } MemHandleUnlock(mt); } } } } gTimeDrawnIndex=gTimeIndex; gHintDrawn=true; if (DmRecordInfo(DatabaseGetRef(), gCourseIndex, &attr, NULL, NULL) == errNone) { attr &= dmRecAttrCategoryMask; if (attr == DatabaseGetCat()) { // Record is in currently displayed category mc = DmQueryRecord(DatabaseGetRef(), gCourseIndex); if (! mc) return; mt = DmQueryRecord(DatabaseGetRef(), gTimeIndex); if (! mt) return; UnpackCourse(&c, MemHandleLock(mc)); tc = (TimeDBRecord *)MemHandleLock(mt); if ( GadgetEventIsVisible(tc) ) { TNlist *tmpl = gGadgetTimeList; GadgetTimeListType *gtl = NULL; while (tmpl != NULL) { gtl = tmpl->data; if (gtl->index == gTimeDrawnIndex) { break; } tmpl = tmpl->next; } mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); day = (Char *)MemHandleLock(mh); // Lecture Name (Teacher) [Typ] tmp=(Char *)MemPtrNew(StrLen(c.name)+StrLen(c.teacherName)+4+3+CTYPE_SHORT_MAXLENGTH); MemSet(tmp, MemPtrSize(tmp), 0); type = MemHandleNew(1); CourseTypeGetShort(&type, c.ctype); StrPrintF(tmp, "%s (%s) [%s]", c.name, c.teacherName, (Char *)MemHandleLock(type)); MemHandleUnlock(type); MemHandleFree(type); // Fr 08:00 - 09:30 (Room) <-- Example // 3 5 3 5 3+StrLen(room) <-- Num Chars for MemPtrNew bot=(Char *)MemPtrNew(20+sizeof(tc->room)+MemPtrSize(day)); MemSet(bot, MemPtrSize(bot), 0); TimeToAscii(tc->begin.hours, tc->begin.minutes, GadgetGetTimeFormat(), begin); TimeToAscii(tc->end.hours, tc->end.minutes, GadgetGetTimeFormat(), end); mh = DmGetResource(strRsc, GADGET_STRINGS_WDAYSTART+tc->day); StrPrintF(bot, "%s %s - %s (%s)", day, begin, end, tc->room); FrmGetObjectBounds(gForm, gadgetIndex, &bounds); if (gtl != NULL) { GadgetTimeSetRect(&rect, tc->begin, tc->end, tc->day, gtl->num, gtl->pos); RctSetRectangle(&rect, // + inset (two boxes, one black, one white) rect.topLeft.x + 2, rect.topLeft.y + 2, // width - 2 * inset rect.extent.x - 4, // height - 2 * inset rect.extent.y - 4 ); /* Invert color, looks not so nice aka bad color.r=255- tc->color[0]; color.g=255- tc->color[1]; color.b=255- tc->color[2]; */ color.r=255; color.g=255; color.b=255; TNSetForeColorRGB(&color, &prevColor); WinDrawRectangleFrame(simpleFrame, &rect); color.r=0; color.g=0; color.b=0; RctSetRectangle(&rect, rect.topLeft.x-1, rect.topLeft.y-1, rect.extent.x+2, rect.extent.y+2); TNSetForeColorRGB(&color, NULL); WinDrawRectangleFrame(simpleFrame, &rect); TNSetForeColorRGB(&prevColor, NULL); } // WinInvertRectangleFrame(simpleFrame, &rect); GadgetDrawHint(tmp, bot, tc->note); MemPtrFree((MemPtr) tmp); MemPtrFree((MemPtr) bot); MemHandleUnlock(mh); } else { MemHandleUnlock(mc); MemHandleUnlock(mt); GadgetDrawHintNext(); return; } MemHandleUnlock(mc); MemHandleUnlock(mt); } // End attr == current category } }
/*************************************************************************** * Function: cryptSwitch * Description: handles changing the system password based upon the * password change screen. Basically checks that current password is correct, * checks that the new password was entered correctly, then re-encrypts the * databases based upon the new password. * ************************************************************************/ static void cryptSwitch (int v) { // total number of records to re-write UInt16 totalAItems = DmNumRecordsInCategory (AccountDB, dmAllCategories); UInt16 totalSItems = DmNumRecordsInCategory (SystemDB, dmAllCategories); MemPtr pac = NULL, scratch = NULL, scratch2 = NULL; UInt16 i = 0, senc = 0, aenc = 0; MemHandle rH; char s[5], a[5]; StripPrefType prefs; UInt16 prefsSize, prefsVersion; FormType *preF = FrmGetActiveForm (); FormType *f = FrmInitForm (pleaseWait); FrmDrawForm (f); // re-encrypt the password if ((rH = DmGetRecord (PasswordDB, 0))) { if ((scratch = MemPtrNew (getSCSize(sizeof(md_hash))))) { PackPassword (scratch, &NewSysPass); writeRecord (scratch, rH); MemPtrFree (scratch); } DmReleaseRecord (PasswordDB, 0, true); } // loop through the systems and re-encrypt for (i = 0; i < totalSItems; i++) { System_old sys; if ((rH = DmGetRecord (SystemDB, i))) { pac = MemHandleLock (rH); if ((scratch = MemPtrNew (MemPtrSize (pac)))) { // decrypt the system with old password switch (v) { case 0: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 1); scratch2 = MemPtrNew (getSystemSize((System *)&sys, true)); break; case 1: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 2); scratch2 = MemPtrNew (getSystemSize ((System *)&sys,true) ); break; case 2: UnpackSystem_old (&sys, pac, scratch, SysPass, MemHandleSize (rH), true, 0); scratch2 = MemPtrNew (getSystemSize ((System *)&sys, true )); break; } if (scratch2) { PackSystem(scratch2, *((System *) &sys), &NewSysPass, true); MemHandleUnlock (rH); writeRecord (scratch2, rH); senc++; MemPtrFree (scratch2); } MemPtrFree (scratch); } DmReleaseRecord (SystemDB, i, true); } } // loop through the accounts and re-encrypt for (i = 0; i < totalAItems; i++) { Account_old ac; Account ac_new; if ((rH = DmGetRecord (AccountDB, i))) { pac = MemHandleLock (rH); if ((scratch = MemPtrNew (MemPtrSize (pac)))) { // decrypt the system with old password switch (v) { case 0: UnpackAccount_old(&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 1); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new, true)); break; case 1: UnpackAccount_old (&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 2); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new, true)); break; case 2: UnpackAccount_old(&ac, pac, scratch, SysPass, MemHandleSize (rH), true, true, 0); ChangeAccountFormat(i, &ac, &ac_new); scratch2 = MemPtrNew (getAccountSize(&ac_new,true)); break; } if (scratch2) { PackAccount(scratch2, ac_new, &NewSysPass, true); MemHandleUnlock (rH); writeRecord (scratch2, rH); aenc++; MemPtrFree (scratch2); } MemPtrFree (scratch); } DmReleaseRecord (AccountDB, i, true); } } FrmEraseForm (f); FrmDeleteForm (f); FrmSetActiveForm (preF); // close databases. DmCloseDatabase (SystemDB); DmCloseDatabase (AccountDB); DmCloseDatabase (PasswordDB); { UInt16 cardNo; UInt32 type; LocalID dbID; DmSearchStateType search; type = systemDBType; DmGetNextDatabaseByTypeCreator(true, &search, systemDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); type = accountDBType; DmGetNextDatabaseByTypeCreator(true, &search, accountDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); type = passwordDBType; DmGetNextDatabaseByTypeCreator(true, &search, passwordDBTypeOld, StripCreator, true, &cardNo, &dbID); DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &type, NULL); } prefsSize = sizeof (StripPrefType); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); if (prefsVersion != StripVersionNumber) { prefs.smart_beaming = false; PrefSetAppPreferences (StripCreator, StripPrefID, StripVersionNumber, &prefs, sizeof (StripPrefType), true); prefsVersion = PrefGetAppPreferences (StripCreator, StripPrefID, &prefs, &prefsSize, true); } StrIToA (s, senc); StrIToA (a, aenc); FrmCustomAlert (infoDialog, s, a, NULL); StopApplication (); SysReset (); }
/*********************************************************************** * * FUNCTION: PrvDeleteTimeZoneArray * * DESCRIPTION: Undo what PrvCreateTimeZoneArray has done, by deleting * the array of time zone entries, and unlocking the list of names. * * PARAMETERS: * tzArrayP -> Ptr to allocated array of time zone entries. * tzNamesH -> Handle to string list resource containing time zone names. * * RETURNED: * Nothing. * * HISTORY: * 07/31/00 kwk Created by Ken Krugler. * ***********************************************************************/ static void PrvDeleteTimeZoneArray(TimeZoneEntryType* tzArrayP, MemHandle tzNamesH) { MemPtrFree((MemPtr)tzArrayP); MemHandleUnlock(tzNamesH); } // PrvDeleteTimeZoneArray
void __sys_free(void* ptr) { (void) MemPtrFree(ptr); }
void IntlInit(void) { Err result; MemHandle localeCodeH; MemHandle tableListH; MemHandle featureTableH; ROMFtrTableType* featureTableP; ROMFtrCreatorType* creatorTableP; UInt16 creators; Boolean fastSort = true; Boolean fastSearch = true; Boolean fastAttr = true; UInt16 index; UInt32 intlFtrFlags; #if (EMULATION_LEVEL == EMULATION_NONE) UInt16 systemCard; LocalID systemID; DmSearchStateType* searchStateP; MemHandle localeNameH; LocalID moduleID; DmOpenRef moduleRef; // Locate the system DB, so that we know where to look (which card) // for the locale module. searchStateP = (DmSearchStateType*)MemPtrNew(sizeof(DmSearchStateType)); result = DmGetNextDatabaseByTypeCreator( true, searchStateP, sysFileTSystem, sysFileCSystem, true, // onlyLatestVers &systemCard, &systemID); ErrNonFatalDisplayIf((result != errNone) || (systemID == 0), "Can't find system DB"); MemPtrFree((MemPtr)searchStateP); localeNameH = DmGetResource(strRsc, localeModuleNameStrID); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); MemHandleUnlock(localeNameH); if (moduleID != 0) { moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen); ErrNonFatalDisplayIf(moduleRef == 0, "Can't open locale module"); if (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion) { DmCloseDatabase(moduleRef); moduleID = 0; } } // If we couldn't find the locale module, or it has the wrong version, then // default to the ROM locale's locale module. if (moduleID == 0) { SysNVParamsType* romParamsP; OmLocaleType romLocale; Char* overlayName; LocalID overlayID; DmOpenRef overlayRef; Char* systemName; // Open up the system overlay that corresponds to the ROM's locale. // Note that (assuming the ROM locale != current locale) we have to // try to open up the overlay explicitly, since the Overlay Mgr // won't be opening it automatically. We also have to handle the case // of a ROM built without overlays, in which case the ROM locale's // locale module name string is located in the base, which means we // have to make a low-level resource call to get it (otherwise we'll // get the string from the system overlay). romParamsP = (SysNVParamsType*)MemPtrNew(sizeof(SysNVParamsType)); MemGetRomNVParams(romParamsP); romLocale.country = romParamsP->localeCountry; romLocale.language = romParamsP->localeLanguage; MemPtrFree((MemPtr)romParamsP); // Get the name of the system DB, so that we can construct the overlay // name. systemName = (Char*)MemPtrNew(dmDBNameLength); overlayName = (Char*)MemPtrNew(dmDBNameLength); result = DmDatabaseInfo(systemCard, systemID, systemName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); ErrNonFatalDisplayIf(result != errNone, "Can't get system DB info"); result = OmLocaleToOverlayDBName(systemName, &romLocale, overlayName); ErrNonFatalDisplayIf(result != errNone, "Can't make ROM locale system overlay name"); overlayID = DmFindDatabaseWithTypeCreator(systemCard, overlayName, sysFileTOverlay, sysFileCSystem); MemPtrFree(systemName); MemPtrFree((MemPtr)overlayName); if (overlayID != 0) { overlayRef = DmOpenDatabase(systemCard, overlayID, dmModeReadOnly); ErrNonFatalDisplayIf(overlayRef == 0, "Can't open system overlay"); // Now load the locale module name string from this overlay, and use // it to find the locale module. localeNameH = DmGet1Resource(strRsc, localeModuleNameStrID); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); MemHandleUnlock(localeNameH); DmCloseDatabase(overlayRef); } else { // Assume it's a ROM built without overlays, in which case we need to // get the locale name handle from the system base. DmOpenRef sysRef = NULL; Int16 index; do { LocalID dbID; sysRef = DmNextOpenResDatabase(sysRef); if ((sysRef != NULL) && (DmOpenDatabaseInfo(sysRef, &dbID, NULL, NULL, NULL, NULL) == errNone) && (dbID == systemID)) { break; } } while (sysRef != NULL); ErrNonFatalDisplayIf(sysRef == NULL, "Can't find system DB"); index = DmFindResource(sysRef, strRsc, localeModuleNameStrID, NULL); ErrNonFatalDisplayIf(index == -1, "Missing locale module name string"); localeNameH = DmGetResourceIndex(sysRef, index); ErrNonFatalDisplayIf(localeNameH == NULL, "Missing locale module name string"); moduleID = DmFindDatabaseWithTypeCreator( systemCard, (Char*)MemHandleLock(localeNameH), sysFileTLocaleModule, sysFileCSystem); } // If we found the locale module DB, open it up and make sure it has // the right version. if (moduleID != 0) { moduleRef = DmOpenDatabase(systemCard, moduleID, dmModeReadOnly | dmModeLeaveOpen); if ((moduleRef == 0) || (ResLoadConstant(kIntlLMVersResID) != kIntlLMVersion)) { // Trigger fatal alert below. No need to close the DB in that case. moduleID = 0; } else { // We found a valid locale module, using the ROM locale, so set // the current locale to be the ROM locale. result = FtrSet(sysFtrCreator, sysFtrNumLanguage, romLocale.language); if (result == errNone) { result = FtrSet(sysFtrCreator, sysFtrNumCountry, romLocale.country); } ErrNonFatalDisplayIf(result != errNone, "Can't switch current locale to ROM locale"); } } ErrFatalDisplayIf(moduleID == 0, "No valid locale module"); } result = DmDatabaseProtect(systemCard, moduleID, true); if (result != dmErrROMBased) { ErrNonFatalDisplayIf(result != errNone, "Can't protect locale module"); } #else // Give the locale module code in the Simulator a chance to // initialize itself. If there's no such code (e.g. with latin) then the // routine in SimStubs.cp does nothing. StubPalmOSInitLocaleModule(); #endif // If there's a locale module code resource, load & call it now. localeCodeH = DmGet1Resource(kIntlLMCodeType, kIntlLMCodeResID); if (localeCodeH != NULL) { ProcPtr localeCodeP = (ProcPtr)MemHandleLock(localeCodeH); (*localeCodeP)(); MemHandleUnlock(localeCodeH); } // If the IntlMgr data ptr hasn't been set up by the locale module code, // allocate it now. if (GIntlMgrGlobalsP == NULL) { UInt16 numCustomTransTables; MemPtr globalPtr; numCustomTransTables = ResLoadConstant(kIntlLMCustomTransCountID); ErrNonFatalDisplayIf(numCustomTransTables > kIntlMaxCustomTransliterations, "Too many custom transliterations"); globalPtr = MemPtrNew(sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*))); ErrNonFatalDisplayIf(globalPtr == NULL, "Out of memory"); MemSet(globalPtr, sizeof(IntlGlobalsType) + (numCustomTransTables * sizeof(void*)), 0); GIntlMgrGlobalsP = globalPtr; GIntlData->numCustomTransliterations = numCustomTransTables; } else { // If any of the sorting tables are already configured, we can't do // our fast sorting optimization. for (index = 0; index < kIntlMaxSortLevels; index++) { if (GIntlData->sortTables[index] != NULL) { fastSort = false; break; } } // If the word start or word match tables are already configured, we // can't do our fast word search optimization. if ((GIntlData->findWordStartTable != NULL) || (GIntlData->findWordMatchTable != NULL)) { fastSearch = false; } // If the character attribute table is already configured, we can't do // our fast attribute optimization. if (GIntlData->charAttrTable != NULL) { fastAttr = false; } } // Loop over all of the table resources, locking & setting up pointers in // the IntlMgr global data structure. tableListH = DmGet1Resource(kIntlLMTableListType, kIntlLMTableListResID); if (tableListH != NULL) { IntlLMTableEntryType* curTable; UInt8* globalsP = (UInt8*)GIntlMgrGlobalsP; IntlLMTableResType* tableListP = (IntlLMTableResType*)MemHandleLock(tableListH); for (index = 0, curTable = tableListP->resources; index < tableListP->numResources; index++, curTable++) { void** ptrLocation; MemHandle tableH; tableH = DmGet1Resource(curTable->resType, curTable->resID); ErrFatalDisplayIf(tableH == NULL, "Missing table resource from locale module"); ErrFatalDisplayIf(curTable->tableIndex >= intlLMNumTableIndexes, "Invalid table index"); ptrLocation = (void**)(globalsP + kIntlGlobalOffsets[curTable->tableIndex]); ErrFatalDisplayIf(*ptrLocation != NULL, "Resource overriding existing table ptr"); *ptrLocation = MemHandleLock(tableH); } MemHandleUnlock(tableListH); } // Note that we can't check for the presence of tables here, as a table that // is required by a Text Mgr routine might be NULL if the locale module has // patched out that routine. // As an optimization, see if all of the sorting tables are byte-indexed 8-bit // values. If so, then replace the table ptrs with ptrs to the actual data, // and set the fast sorting intl mgr flag. for (index = 0; (index < kIntlMaxSortLevels) && fastSort; index++) { void* sortTable = GIntlData->sortTables[index]; if (sortTable == NULL) { break; } else if (PrvGetByteIndexedTable(sortTable, 8) == NULL) { fastSort = false; } } if (fastSort) { GIntlData->intlFlags |= kByteSortingFlag; for (index = 0; index < kIntlMaxSortLevels; index++) { GIntlData->sortTables[index] = PrvGetByteIndexedTable(GIntlData->sortTables[index], 8); } } // As an optimization, see if all of the searching tables are byte-indexed 8-bit // values. If so, then replace the table ptrs with ptrs to the actual data, // and set the fast searching intl mgr flag. Note that PrvGetByteIndexedTable // will return NULL if findWordMatchTable is NULL, which is OK because then // TxtFindString must be patched out anyway. The findWordStartTable is optional, // and thus it can either be NULL or a byte indexed byte table. if ((fastSearch) && ((GIntlData->findWordStartTable == NULL) || (PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8) != NULL)) && (PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8) != NULL)) { GIntlData->intlFlags |= kByteSearchingFlag; GIntlData->findWordStartTable = PrvGetByteIndexedTable(GIntlData->findWordStartTable, 8); GIntlData->findWordMatchTable = PrvGetByteIndexedTable(GIntlData->findWordMatchTable, 8); } // As an optimization, see if the character attribute table is a byte-indexed // table of 16-bit values. If so, then replace the table ptr with a ptr to // the data, and set the kByteCharAttrFlag flag. if (fastAttr && (PrvGetByteIndexedTable(GIntlData->charAttrTable, 16) != NULL)) { GIntlData->intlFlags |= kByteCharAttrFlag; GIntlData->charAttrTable = PrvGetByteIndexedTable(GIntlData->charAttrTable, 16); // As an optimization, see if the character attribute table is a stage index map // table of 16-bit values. If so, then replace the table ptr with a ptr to // the sub-table offsets, set up the result table ptr, and set the // kStageCharAttrFlag flag. } else if (fastAttr && PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16)) { GIntlData->intlFlags |= kStageCharAttrFlag; GIntlData->charAttrTable = PrvGetStageIndexMapTable(GIntlData->charAttrTable, 16); } // If there's a doubleCharTable, we want to (a) verify that it's a byte-indexed // byte table, and (b) set up the pointer now. if (GIntlData->doubleCharTable != NULL) { void* tableP = PrvGetByteIndexedTable(GIntlData->doubleCharTable, 8); ErrNonFatalDisplayIf(tableP == NULL, "Double-char table isn't byte-indexed byte table"); GIntlData->doubleCharTable = tableP; } // Load the 'feat' resource from the locale module, and use it to initialize // various locale-specific features. Typically this includes sysFtrNumCharEncodingFlags, // sysFtrNumEncoding, sysFtrDefaultFont, and sysFtrDefaultBoldFont. // Try to load the 'feat' resource. featureTableH = DmGet1Resource(sysResTFeatures, kIntlLMFeatureResID); ErrFatalDisplayIf(featureTableH == NULL, "Missing feature table"); featureTableP = (ROMFtrTableType*)MemHandleLock(featureTableH); creatorTableP = featureTableP->creator; for (creators = 0; creators < featureTableP->numEntries; creators++) { UInt16 features; for (features = 0; features < creatorTableP->numEntries; features++) { result = FtrSet( creatorTableP->creator, creatorTableP->feature[features].num, creatorTableP->feature[features].value); ErrNonFatalDisplayIf(result != errNone, "Can't set locale feature"); } // Advance to next creator table. creatorTableP = (ROMFtrCreatorType*)((UInt8*)creatorTableP + sizeof(ROMFtrCreatorType) + (creatorTableP->numEntries * sizeof(ROMFtrFeatureType))); } MemHandleUnlock(featureTableH); // Now, set up our internal kByteSearchingFlag flag based on the sysFtrNumCharEncodingFlags // feature value. This means that sysFtrNumCharEncodingFlags is read-only, since if // anybody uses FtrSet to change the settings of the flags, that won't update // our internal flag(s). if ((FtrGet(sysFtrCreator, sysFtrNumCharEncodingFlags, &intlFtrFlags) == errNone) && ((intlFtrFlags & charEncodingOnlySingleByte) != 0)) { GIntlData->intlFlags |= kSingleByteOnlyFlag; } // Finally set the bit that tells everybody we're ready to support IntlMgr/TextMgr calls. FtrSet(sysFtrCreator, sysFtrNumIntlMgr, intlMgrExists); } // IntlInit
static Boolean URLFormDoCommand(UInt16 command) { GlobalsPtr gP = GetGlobals(); Boolean handled = false; if (!gP) return false; switch (command) { // Menus // Control Objects case kURLOpenButton: { Char *navigationText = FldGetTextPtr(GetObjectPtr(kURLField)); Boolean openInNewTab = false; if (navigationText && StrLen(navigationText)) { if (gP->navigationOpen) { MemPtrFree(gP->navigationOpen); } gP->navigationOpen = StrDup(navigationText); if (CtlGetValue(GetObjectPtr(kURLOpenInNewTabCheckbox))) { openInNewTab = true; } FrmReturnToForm(0); if (openInNewTab) { FrmUpdateForm(kMainForm, frmUpdateNewTab); } FrmUpdateForm(kMainForm, URLFormDetermineRequestType(navigationText)); } } break; case kURLCancelButton: FrmReturnToForm(0); break; // Handle inserting text using the insert buttons, or list. case kWWWPushButton: case kCOMPushButton: case kORGPushButton: case kNETPushButton: case kSlashPushButton: case kDotPushButton: case kHTMLPushButton: { FieldPtr urlFldP = GetObjectPtr(kURLField); const Char *buttonLabelP = CtlGetLabel(GetObjectPtr(command)); FldInsert(urlFldP, buttonLabelP, StrLen(buttonLabelP)); CtlSetValue(GetObjectPtr(command), 0); handled = true; } break; case kMoreTrigger: { ListPtr moreListP = GetObjectPtr(kMoreList); FieldPtr urlFldP = GetObjectPtr(kURLField); Int16 selection = LstPopupList(moreListP); if (selection >= 0) { const Char *selectionP = LstGetSelectionText(moreListP, selection); FldInsert(urlFldP, selectionP, StrLen(selectionP)); } handled = true; } break; // Default default: break; } return handled; }
void set_lookup(const char*l) {if(lookup)MemPtrFree(lookup);lookup=0; if(!(l&&StrLen(l)))return; lookup=MemPtrNew(StrLen(l)+1);if(lookup)StrCopy(lookup,l); }const char*
Err free(MemPtr memP) { if (memP) return MemPtrFree(memP); return memErrInvalidParam; }
/** * @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; }