static void DoTasks(int fd) { int processID; processID=fork(); if(processID>=0) { if(processID) // =0 for the child, =PID of the child for the parent { WriteDevice(TTYIN,fd); // will run until done=true if(kill(processID,SIGKILL)<0) { ReportString(REPORT_ERROR,"terminal: failed to kill sub-task\n"); } } else { ReadDevice(fd,TTYOUT); // child task, will run until done=true } } else { ReportString(REPORT_ERROR,"terminal: failed to fork\n"); } }
int Terminal(int fd) { struct termios params, oldParams; done=0; ReportString(REPORT_INFO,"entered terminal mode. type <ctrl-X> to exit, <ESC> to reset the target\n"); if(tcgetattr(TTYIN,&oldParams)>=0) { params=oldParams; params.c_iflag=ISTRIP; params.c_oflag=OPOST|ONLCR; params.c_lflag=0; params.c_cc[VMIN]=1; // at least 1 character in params.c_cc[VTIME]=1; // or, 1/10th of a second if(tcsetattr(TTYIN,TCSANOW,¶ms)>=0) { DoTasks(fd); if(tcsetattr(TTYIN,TCSANOW,&oldParams)>=0) { ReportString(REPORT_INFO,"\n exiting terminal...\n"); return(1); } } } return(0); }
void CGitProgressList::ReportError(const CString& sError) { if (CRegDWORD(_T("Software\\TortoiseGit\\NoSounds"), FALSE) == FALSE) PlaySound((LPCTSTR)SND_ALIAS_SYSTEMEXCLAMATION, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict)); m_bErrorsOccurred = true; }
static void WriteDevice(int theTTY,int fd) // read the tty, send characters to the serial device { char buffer[2048]; int action, // indicates if external action is to be taken -- don't send the command characters to the device numRead, idx; while(!done) { // read some characters from the tty numRead=read(theTTY,buffer,2048); if(numRead>0) { // scan for the exit and reset codes action=0; for(idx=0;!done&&idx<numRead;idx++) { if(buffer[idx]==exitCode) { action=1; done=1; } if(buffer[idx]==resetCode) { // reset the target, if able if(ResetTarget(fd)>=0) { action=1; ReportString(REPORT_INFO,"\n resetting target...\n"); } } } // send characters to the serial device (read return value to silence the compiler) if(!action) { numRead=write(fd,buffer,numRead); } } } }
// Creates a report of the error rate. The report_level controls the detail // that is reported to stderr via tprintf: // 0 -> no output. // >=1 -> bottom-line error rate. // >=3 -> font-level error rate. // boosting_mode determines the return value. It selects which (un-weighted) // error rate to return. // The fontinfo_table from MasterTrainer provides the names of fonts. // The it determines the current subset of the training samples. // If not NULL, the top-choice unichar error rate is saved in unichar_error. // If not NULL, the report string is saved in fonts_report. // (Ignoring report_level). double ErrorCounter::ReportErrors(int report_level, CountTypes boosting_mode, const UnicityTable<FontInfo>& fontinfo_table, const SampleIterator& it, double* unichar_error, STRING* fonts_report) { // Compute totals over all the fonts and report individual font results // when required. Counts totals; int fontsize = font_counts_.size(); for (int f = 0; f < fontsize; ++f) { // Accumulate counts over fonts. totals += font_counts_[f]; STRING font_report; if (ReportString(font_counts_[f], &font_report)) { if (fonts_report != NULL) { *fonts_report += fontinfo_table.get(f).name; *fonts_report += ": "; *fonts_report += font_report; *fonts_report += "\n"; } if (report_level > 2) { // Report individual font error rates. tprintf("%s: %s\n", fontinfo_table.get(f).name, font_report.string()); } } } if (report_level > 0) { // Report the totals. STRING total_report; if (ReportString(totals, &total_report)) { tprintf("TOTAL Scaled Err=%.4g%%, %s\n", scaled_error_ * 100.0, total_report.string()); } // Report the worst substitution error only for now. if (totals.n[CT_UNICHAR_TOP1_ERR] > 0) { const UNICHARSET& unicharset = it.shape_table()->unicharset(); int charsetsize = unicharset.size(); int shapesize = it.CompactCharsetSize(); int worst_uni_id = 0; int worst_shape_id = 0; int worst_err = 0; for (int u = 0; u < charsetsize; ++u) { for (int s = 0; s < shapesize; ++s) { if (unichar_counts_(u, s) > worst_err) { worst_err = unichar_counts_(u, s); worst_uni_id = u; worst_shape_id = s; } } } if (worst_err > 0) { tprintf("Worst error = %d:%s -> %s with %d/%d=%.2f%% errors\n", worst_uni_id, unicharset.id_to_unichar(worst_uni_id), it.shape_table()->DebugStr(worst_shape_id).string(), worst_err, totals.n[CT_UNICHAR_TOP1_ERR], 100.0 * worst_err / totals.n[CT_UNICHAR_TOP1_ERR]); } } } double rates[CT_SIZE]; if (!ComputeRates(totals, rates)) return 0.0; // Set output values if asked for. if (unichar_error != NULL) *unichar_error = rates[CT_UNICHAR_TOP1_ERR]; return rates[boosting_mode]; }
UINT CGitProgressList::ProgressThread() { // The SetParams function should have loaded something for us CString temp; CString sWindowTitle; bool bSuccess = false; if(m_pPostWnd) m_pPostWnd->PostMessage(WM_PROG_CMD_START, (WPARAM)m_Command); if(m_pProgressLabelCtrl) { m_pProgressLabelCtrl->ShowWindow(SW_SHOW); m_pProgressLabelCtrl->SetWindowText(_T("")); } // SetAndClearProgressInfo(m_hWnd); m_itemCount = m_itemCountTotal; InterlockedExchange(&m_bThreadRunning, TRUE); iFirstResized = 0; bSecondResized = FALSE; m_bFinishedItemAdded = false; DWORD startTime = GetCurrentTime(); if (m_pTaskbarList && m_pPostWnd) m_pTaskbarList->SetProgressState(m_pPostWnd->GetSafeHwnd(), TBPF_INDETERMINATE); m_TotalBytesTransferred = 0; if (m_Command) bSuccess = m_Command->Run(this, sWindowTitle, m_itemCountTotal, m_itemCount); else bSuccess = false; if (!bSuccess) temp.LoadString(IDS_PROGRS_TITLEFAILED); else temp.LoadString(IDS_PROGRS_TITLEFIN); sWindowTitle = sWindowTitle + _T(" ") + temp; if (m_bSetTitle && m_pPostWnd) ::SetWindowText(m_pPostWnd->GetSafeHwnd(), sWindowTitle); KillTimer(TRANSFERTIMER); KillTimer(VISIBLETIMER); if (m_pTaskbarList && m_pPostWnd) { if (DidErrorsOccur()) { m_pTaskbarList->SetProgressState(m_pPostWnd->GetSafeHwnd(), TBPF_ERROR); m_pTaskbarList->SetProgressValue(m_pPostWnd->GetSafeHwnd(), 100, 100); } else m_pTaskbarList->SetProgressState(m_pPostWnd->GetSafeHwnd(), TBPF_NOPROGRESS); } if (m_pInfoCtrl) { CString info; if (!bSuccess) info.LoadString(IDS_PROGRS_INFOFAILED); else // this implies that command is not nullptr info = BuildInfoString(); m_pInfoCtrl->SetWindowText(info); } ResizeColumns(); DWORD time = GetCurrentTime() - startTime; CString sFinalInfo; if (!m_sTotalBytesTransferred.IsEmpty()) { temp.Format(IDS_PROGRS_TIME, (time / 1000) / 60, (time / 1000) % 60); sFinalInfo.Format(IDS_PROGRS_FINALINFO, m_sTotalBytesTransferred, (LPCTSTR)temp); if (m_pProgressLabelCtrl) m_pProgressLabelCtrl->SetWindowText(sFinalInfo); } else { if (m_pProgressLabelCtrl) m_pProgressLabelCtrl->ShowWindow(SW_HIDE); } if (m_pProgControl) m_pProgControl->ShowWindow(SW_HIDE); if (!m_bFinishedItemAdded) { CString log, str; if (bSuccess) str.LoadString(IDS_SUCCESS); else str.LoadString(IDS_FAIL); log.Format(_T("%s (%lu ms @ %s)"), str, time, CLoglistUtils::FormatDateAndTime(CTime::GetCurrentTime(), DATE_SHORTDATE, true, false)); // there's no "finished: xxx" line at the end. We add one here to make // sure the user sees that the command is actually finished. ReportString(log, CString(MAKEINTRESOURCE(IDS_PROGRS_FINISHED)), bSuccess? RGB(0,0,255) : RGB(255,0,0)); } int count = GetItemCount(); if ((count > 0)&&(m_bLastVisible)) EnsureVisible(count-1, FALSE); CLogFile logfile(g_Git.m_CurrentDir); if (logfile.Open()) { logfile.AddTimeLine(); for (size_t i = 0; i < m_arData.size(); ++i) { NotificationData * data = m_arData[i]; temp.Format(_T("%-20s : %s"), (LPCTSTR)data->sActionColumnText, (LPCTSTR)data->sPathColumnText); logfile.AddLine(temp); } if (!sFinalInfo.IsEmpty()) logfile.AddLine(sFinalInfo); logfile.Close(); } m_bCancelled = TRUE; InterlockedExchange(&m_bThreadRunning, FALSE); if (m_pPostWnd) m_pPostWnd->PostMessage(WM_PROG_CMD_FINISH, (WPARAM)m_Command, 0L); //Don't do anything here which might cause messages to be sent to the window //The window thread is probably now blocked in OnOK if we've done an auto close return 0; }
void CGitProgressList::ReportCmd(const CString& sCmd) { ReportString(sCmd, CString(MAKEINTRESOURCE(IDS_PROGRS_CMDINFO)), m_Colors.GetColor(CColors::Cmd)); }
void CGitProgressList::ReportNotification(const CString& sNotification) { if (CRegDWORD(_T("Software\\TortoiseGit\\NoSounds"), FALSE) == FALSE) PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE))); }
void CGitProgressList::ReportWarning(const CString& sWarning) { if (CRegDWORD(_T("Software\\TortoiseGit\\NoSounds"), FALSE) == FALSE) PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict)); }
void CGitProgressList::ReportNotification(const CString& sNotification) { PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sNotification, CString(MAKEINTRESOURCE(IDS_WARN_NOTE))); }
void CGitProgressList::ReportWarning(const CString& sWarning) { PlaySound((LPCTSTR)SND_ALIAS_SYSTEMDEFAULT, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sWarning, CString(MAKEINTRESOURCE(IDS_WARN_WARNING)), m_Colors.GetColor(CColors::Conflict)); }
void CGitProgressList::ReportError(const CString& sError) { PlaySound((LPCTSTR)SND_ALIAS_SYSTEMEXCLAMATION, NULL, SND_ALIAS_ID | SND_ASYNC); ReportString(sError, CString(MAKEINTRESOURCE(IDS_ERR_ERROR)), m_Colors.GetColor(CColors::Conflict)); m_bErrorsOccurred = true; }
void WhereNone::Print(OutStream &out) const { out << "Report: " << ReportString(m_report_kind); }
// Creates a report of the error rate. The report_level controls the detail // that is reported to stderr via tprintf: // 0 -> no output. // >=1 -> bottom-line error rate. // >=3 -> font-level error rate. // boosting_mode determines the return value. It selects which (un-weighted) // error rate to return. // The fontinfo_table from MasterTrainer provides the names of fonts. // The it determines the current subset of the training samples. // If not NULL, the top-choice unichar error rate is saved in unichar_error. // If not NULL, the report string is saved in fonts_report. // (Ignoring report_level). double ErrorCounter::ReportErrors(int report_level, CountTypes boosting_mode, const FontInfoTable& fontinfo_table, const SampleIterator& it, double* unichar_error, STRING* fonts_report) { // Compute totals over all the fonts and report individual font results // when required. Counts totals; int fontsize = font_counts_.size(); for (int f = 0; f < fontsize; ++f) { // Accumulate counts over fonts. totals += font_counts_[f]; STRING font_report; if (ReportString(false, font_counts_[f], &font_report)) { if (fonts_report != NULL) { *fonts_report += fontinfo_table.get(f).name; *fonts_report += ": "; *fonts_report += font_report; *fonts_report += "\n"; } if (report_level > 2) { // Report individual font error rates. tprintf("%s: %s\n", fontinfo_table.get(f).name, font_report.string()); } } } // Report the totals. STRING total_report; bool any_results = ReportString(true, totals, &total_report); if (fonts_report != NULL && fonts_report->length() == 0) { // Make sure we return something even if there were no samples. *fonts_report = "NoSamplesFound: "; *fonts_report += total_report; *fonts_report += "\n"; } if (report_level > 0) { // Report the totals. STRING total_report; if (any_results) { tprintf("TOTAL Scaled Err=%.4g%%, %s\n", scaled_error_ * 100.0, total_report.string()); } // Report the worst substitution error only for now. if (totals.n[CT_UNICHAR_TOP1_ERR] > 0) { int charsetsize = unicharset_.size(); int worst_uni_id = 0; int worst_result_id = 0; int worst_err = 0; for (int u = 0; u < charsetsize; ++u) { for (int v = 0; v < charsetsize; ++v) { if (unichar_counts_(u, v) > worst_err) { worst_err = unichar_counts_(u, v); worst_uni_id = u; worst_result_id = v; } } } if (worst_err > 0) { tprintf("Worst error = %d:%s -> %s with %d/%d=%.2f%% errors\n", worst_uni_id, unicharset_.id_to_unichar(worst_uni_id), unicharset_.id_to_unichar(worst_result_id), worst_err, totals.n[CT_UNICHAR_TOP1_ERR], 100.0 * worst_err / totals.n[CT_UNICHAR_TOP1_ERR]); } } tprintf("Multi-unichar shape use:\n"); for (int u = 0; u < multi_unichar_counts_.size(); ++u) { if (multi_unichar_counts_[u] > 0) { tprintf("%d multiple answers for unichar: %s\n", multi_unichar_counts_[u], unicharset_.id_to_unichar(u)); } } tprintf("OK Score histogram:\n"); ok_score_hist_.print(); tprintf("ERROR Score histogram:\n"); bad_score_hist_.print(); } double rates[CT_SIZE]; if (!ComputeRates(totals, rates)) return 0.0; // Set output values if asked for. if (unichar_error != NULL) *unichar_error = rates[CT_UNICHAR_TOP1_ERR]; return rates[boosting_mode]; }