LookUpWindow::LookUpWindow(Controller *controller, QString word, QWidget *parent) : QMainWindow(parent), ui(new Ui::LookUpWindow), controller(controller) { ui->setupUi(this); this->move(this->parentWidget()->pos()); this->setStyleSheet(controller->setTheme("lookup")); lookUpWord = word; lookUpData = this->controller->findWord(word.toStdString()); setWindowTitle(tr("查单词:%1").arg(lookUpWord)); ui->returnBtn->setDefault(true); showWord(lookUpData); setBtn(); }
void Dictionary<Entry>::print() { for(unsigned i = 0; i < states_.size(); i++) { std::cout << "s="<<i<<", f="<<states_[i]->failure<<", o='"; for(unsigned j = 0; j < states_[i]->output.size(); j++) { if(j!=0) std::cout << " "; // std::cout << util_->showString(entries_[states_[i]->output[j]]->word); std::cout << showWord(util_, entries_[states_[i]->output[j]]); } std::cout << "' g='"; for(unsigned j = 0; j < states_[i]->gotos.size(); j++) { if(j!=0) std::cout << " "; std::cout << util_->showChar(states_[i]->gotos[j].first) << "->" << states_[i]->gotos[j].second; } std::cout << "'" << std::endl; } }
void hangedGame(char* word) { int i; int* found; int size = strlen(word); found = malloc(size * sizeof(int)); for ( i = 0; i < size; i++) { found[i] = 0; } char character = 0; int loop = 10; while (loop && !checkWin(word, found)) { printf("Il vous reste %d coups a jouer \n", loop); printf("Quel est le mot secret ? "); showWord(word, found); printf("\nProposez une lettre : "); character = lireCaractere(); checkCharacter(word, found, character); loop--; } if(checkWin(word, found)) { printf("\nBravo ! Vous avez gagné en %d coups !", loop); printf("\nLe mot secret était bien '%s'", word); } else { printf("Perdu ! Le mot secret était : %s", word); } free(found); }
void LookUpWindow::refresh() { showWord(lookUpData); }
Error WordViewer::showDocument(QString& path) { Error errorHR = Success(); HRESULT hr = S_OK; // Allow Word to become the foreground window. CoAllowSetForegroundWindow // would be preferable here, since we'd be able to restrict activation to // only the process we started, but it is not exposed by MinGW headers. // Note that AllowSetForegroundWindow already limits activation to processes // initiated by the foreground process, and self-expires on user input. AllowSetForegroundWindow(ASFW_ANY); // If we have an active IDispatch pointer to Word, check to see whether // it has been closed if (idispWord_ != NULL) { // Test the interface by looking up a known DISPID const WCHAR* wstrQuit = L"Quit"; DISPID dispid; hr = idispWord_->GetIDsOfNames(IID_NULL, const_cast<WCHAR**>(&wstrQuit), 1, LOCALE_USER_DEFAULT, &dispid); // If the lookup fails, release this IDispatch pointer--it's stale. // We'll CoCreate a new instance of Word below. if (FAILED(hr) && SCODE_CODE(hr) == RPC_S_SERVER_UNAVAILABLE) { idispWord_->Release(); idispWord_ = NULL; } } // Get an IDispatch for the Word Application root object if (idispWord_ == NULL) { CLSID clsid; LPCOLESTR progId = L"Word.Application"; CoInitialize(NULL); VERIFY_HRESULT(CLSIDFromProgID(progId, &clsid)); VERIFY_HRESULT(CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, reinterpret_cast<void**>(&idispWord_))); idispWord_->AddRef(); } // Make Word visible errorHR = showWord(); if (errorHR) return errorHR; IDispatch* idispDocs; IDispatch* idispDoc; VERIFY_HRESULT(getIDispatchProp(idispWord_, L"Documents", &idispDocs)); // Open the documenet path = path.replace(QChar(L'/'), QChar(L'\\')); errorHR = openDocument(path, idispDocs, &idispDoc); if (errorHR) return errorHR; if (docPath_ == path) { // Reopening the last-opened doc: apply the scroll position if we have // one cached if (docScrollX_ > 0 || docScrollY_ > 0) setDocumentPosition(idispDoc, docScrollX_, docScrollY_); } else { // Opening a different doc: forget scroll position and save the doc name docScrollX_ = 0; docScrollY_ = 0; docPath_ = path; } // Bring Word to the foreground VERIFY_HRESULT(invokeDispatch(DISPATCH_METHOD, NULL, idispWord_, L"Activate", 0)); LErrExit: return errorHR; }
int main(int ac, char** av){ char fname[1024], *W; W=(char *)malloc(33*sizeof(char)); FILE *f1, *f2, *f3; hashentry he; uint64_t i=0; location spos; uint64_t nW=0,maxF=0, aveF=0; int flagV=0; int64_t freq[PEQ]; if(ac<2)terror("USE: leehd prefixNameOUT [v=verbose]\n"); if (ac==3) flagV=1; for (i=0;i<PEQ;i++) freq[i]=0; sprintf(fname,"%s.d2hW",av[1]); // Words file (first level of hash table) if ((f1 = fopen(fname,"rb"))==NULL) terror("opening prefix.h2dW file"); sprintf(fname,"%s.d2hP",av[1]); // Positions file if ((f2 = fopen(fname,"rb"))==NULL) terror("opening prefix.h2dP file"); sprintf(fname,"%s.freq",av[1]); // output if ((f3 = fopen(fname,"wt"))==NULL) terror("opening prefix.freq OUT file"); // kick-off if(fread(&he,sizeof(hashentry),1,f1)!=1) terror("Empty dictionary"); while(!feof(f1)){ if (flagV) {showWord(&he.w, W);fprintf(stdout, "%.32s", W);} if (flagV) fprintf(stdout," : num=%-7" PRIu64 ":",he.num); if (he.num>=PEQ) { fprintf(f3, "%" PRIu64 "\t", he.num); showWord(&he.w, W); fprintf(f3, "%.32s", W); fprintf(f3, "%" PRIu64 "\n", he.num); } else freq[he.num]++; nW++; if (he.num>maxF) maxF=he.num; aveF+=he.num; fseek(f2,0, he.pos); if (flagV) { for (i=0;i<he.num;i++){ if(fread(&spos,sizeof(location),1,f2)!=1) terror("Error reading the word occurrences"); fprintf(stdout,"(%" PRIu64 ",%" PRIu64 ") ",spos.pos,spos.seq); } fprintf(stdout,"\n"); } if(fread(&he,sizeof(hashentry),1,f1)!=1) if(ferror(f1)) terror("Error reading a dictionary entry"); } free(W); fclose(f1); fclose(f2); // store PEQ freqs-------- fprintf(f3,"freqs of words that appear\nTimes\tnWords\n"); for (i=0;i<PEQ;i++) if (freq[i]) fprintf(f3,"%" PRId64 "\t%" PRId64 "\n",i,freq[i]); fclose(f3); fprintf(stdout,"Num.Words=%" PRIu64 " MaxFreq=%" PRIu64 " TotRepeat=%" PRIu64 " AveragFreq=%f\n",nW,maxF,aveF, (float)aveF/(float)nW); exit(0); }