/** @brief Enter choice mode and relating initialisations. */ int ChoiceFirstAvail( ChewingData *pgdata ) { /* save old cursor position */ pgdata->choiceInfo.oldChiSymbolCursor = pgdata->chiSymbolCursor; /* see if there is some word in the cursor position */ if ( pgdata->chiSymbolBufLen == pgdata->chiSymbolCursor ) { if ( pgdata->config.bPhraseChoiceRearward ) pgdata->chiSymbolCursor = pgdata->preferInterval[ pgdata->nPrefer - 1 ].from + CountSymbols( pgdata, pgdata->chiSymbolBufLen ); else pgdata->chiSymbolCursor--; } pgdata->bSelect = 1; SetAvailInfo( &( pgdata->availInfo ), pgdata->phoneSeq, pgdata->nPhoneSeq, PhoneSeqCursor( pgdata ), pgdata->bSymbolArrBrkpt ); if ( ! pgdata->availInfo.nAvail ) return ChoiceEndChoice( pgdata ); pgdata->availInfo.currentAvail = pgdata->availInfo.nAvail - 1; SetChoiceInfo( &( pgdata->choiceInfo ), &( pgdata->availInfo ), pgdata->phoneSeq, PhoneSeqCursor( pgdata ), pgdata->config.candPerPage ); return 0; }
/** @brief Enter choice mode and relating initialisations. */ int ChoiceInitAvail(ChewingData *pgdata) { int end, begin; /* save old cursor position */ pgdata->choiceInfo.oldChiSymbolCursor = pgdata->chiSymbolCursor; /* see if there is some word in the cursor position */ if (pgdata->chiSymbolBufLen == pgdata->chiSymbolCursor) { pgdata->chiSymbolCursor--; } end = PhoneSeqCursor(pgdata); if (pgdata->config.bPhraseChoiceRearward) { pgdata->chiSymbolCursor = SeekPhraseHead(pgdata) + CountSymbols(pgdata, pgdata->chiSymbolCursor); } begin = PhoneSeqCursor(pgdata); pgdata->bSelect = 1; SetAvailInfo(pgdata, begin, end); if (!pgdata->availInfo.nAvail) return ChoiceEndChoice(pgdata); pgdata->availInfo.currentAvail = pgdata->availInfo.nAvail - 1; SetChoiceInfo(pgdata); return 0; }
OSErr NSFindSymbol(CFragConnectionID inID, Str255 inSymName, Ptr* outMainAddr, CFragSymbolClass *outSymClass) { OSErr err; if (inSymName[0] > 63) { /* if there are greater than 63 characters in the name, CFM FindSymbol fails, so let's iterate through all of the symbols in the fragment and grab it that way. */ long symbolCount; Str255 curSymName; long curIndex; Boolean found; found = false; err = CountSymbols(inID, &symbolCount); if (noErr == err) { /* now iterate through all the symbols in the library */ /* per DTS the indices apparently go 0 to n-1 */ for (curIndex = 0; (curIndex <= symbolCount - 1 && !found); curIndex++) { err = GetIndSymbol(inID, curIndex, curSymName, outMainAddr, outSymClass); if (noErr == err && curSymName[0] == inSymName[0] && !strncmp((char*)curSymName + 1, (char*)inSymName + 1, curSymName[0])) { /* found our symbol */ found = true; } } /* if we didn't find it set the error code so below it won't take this symbol */ if (!found) err = cfragNoSymbolErr; } } else { err = FindSymbol(inID, inSymName, outMainAddr, outSymClass); } return (err); }
/** @brief Loading all possible phrases after the cursor from long to short into AvailInfo structure.*/ static void SetAvailInfo(ChewingData *pgdata, int begin, int end) { AvailInfo *pai = &(pgdata->availInfo); const uint16_t *phoneSeq = pgdata->phoneSeq; int nPhoneSeq = pgdata->nPhoneSeq; const int *bSymbolArrBrkpt = pgdata->bSymbolArrBrkpt; int symbolArrBrkpt[ARRAY_SIZE(pgdata->bSymbolArrBrkpt)] = { 0 }; const TreeType *tree_pos; int diff; uint16_t userPhoneSeq[MAX_PHONE_SEQ_LEN]; int i, head, head_tmp; int tail, tail_tmp; int pos; head = tail = 0; pai->nAvail = 0; /* * XXX: The phoneSeq, nPhoneSeq skip any symbol in preedit buffer, * while bSymbolArrBrkpt, does not skip any symbol in preedit * buffer. So we need to do some translate here. */ for (i = 0; i < pgdata->chiSymbolBufLen; ++i) { if (bSymbolArrBrkpt[i]) { /* * XXX: If preedit buffer starts with symbol, the pos * will become negative. In this case, we just ignore * this symbol because it does not create any break * point. */ pos = i - CountSymbols(pgdata, i + 1); if (pos >= 0) symbolArrBrkpt[pos] = 1; } } if (pgdata->config.bPhraseChoiceRearward) { for (i = end; i >= begin; i--) { if (symbolArrBrkpt[i]) break; head = i; } head_tmp = end; } else { head_tmp = head = begin; } if (pgdata->config.bPhraseChoiceRearward) { tail_tmp = tail = end; } else { for (i = begin; i < nPhoneSeq; i++) { tail = i; if (symbolArrBrkpt[i]) break; } tail_tmp = begin; } while (head <= head_tmp && tail_tmp <= tail) { diff = tail_tmp - head_tmp; tree_pos = TreeFindPhrase(pgdata, head_tmp, tail_tmp, phoneSeq); if (tree_pos) { /* save it! */ pai->avail[pai->nAvail].len = diff + 1; pai->avail[pai->nAvail].id = tree_pos; pai->nAvail++; } else { memcpy(userPhoneSeq, &phoneSeq[head_tmp], sizeof(uint16_t) * (diff + 1)); userPhoneSeq[diff + 1] = 0; if (UserGetPhraseFirst(pgdata, userPhoneSeq)) { /* save it! */ pai->avail[pai->nAvail].len = diff + 1; pai->avail[pai->nAvail].id = NULL; pai->nAvail++; } else { pai->avail[pai->nAvail].len = 0; pai->avail[pai->nAvail].id = NULL; } UserGetPhraseEnd(pgdata, userPhoneSeq); } if (pgdata->config.bPhraseChoiceRearward) { head_tmp--; } else { tail_tmp++; } } }