void malAtomDefinition(stream *out, str name, int tpe) { int i; if (strlen(name) >= IDLENGTH) { showException(out, SYNTAX, "atomDefinition", "Atom name '%s' too long", name); return; } if (ATOMindex(name) >= 0) { #ifndef HAVE_EMBEDDED /* we can restart embedded MonetDB, making this an expected error */ showException(out, TYPE, "atomDefinition", "Redefinition of atom '%s'", name); #endif return; } if (tpe < 0 || tpe >= GDKatomcnt) { showException(out, TYPE, "atomDefinition", "Undefined atom inheritance '%s'", name); return; } if (strlen(name) >= sizeof(BATatoms[0].name)) return; i = ATOMallocate(name); /* overload atom ? */ if (tpe) { BATatoms[i] = BATatoms[tpe]; strncpy(BATatoms[i].name, name, sizeof(BATatoms[i].name)); BATatoms[i].name[sizeof(BATatoms[i].name) - 1] = 0; /* make coverity happy */ BATatoms[i].storage = ATOMstorage(tpe); } else { /* cannot overload void atoms */ BATatoms[i].storage = i; BATatoms[i].linear = 0; } }
/* * The administrator should be initialized to enable interpretation of * the command line arguments, before it starts serviceing statements */ int MCinitClientThread(Client c) { Thread t; char cname[11 + 1]; snprintf(cname, 11, OIDFMT, c->user); cname[11] = '\0'; t = THRnew(cname); if (t == 0) { showException(c->fdout, MAL, "initClientThread", "Failed to initialize client"); MPresetProfiler(c->fdout); return -1; } /* * The GDK thread administration should be set to reflect use of * the proper IO descriptors. */ t->data[1] = c->fdin; t->data[0] = c->fdout; c->mythread = t; c->errbuf = GDKerrbuf; if (c->errbuf == NULL) { char *n = GDKzalloc(GDKMAXERRLEN); if ( n == NULL){ showException(GDKout, MAL, "initClientThread", "Failed to initialize client"); return -1; } GDKsetbuf(n); c->errbuf = GDKerrbuf; } else c->errbuf[0] = 0; return 0; }
void malAtomDefinition(stream *out, str name, int tpe) { int i; if (strlen(name) >= IDLENGTH) { showException(out, SYNTAX, "atomDefinition", "Atom name '%s' too long", name); return; } if (ATOMindex(name) >= 0) { showException(out, TYPE, "atomDefinition", "Redefinition of atom '%s'", name); return; } if (tpe < 0 || tpe >= GDKatomcnt) { showException(out, TYPE, "atomDefinition", "Undefined atom inheritance '%s'", name); return; } if (strlen(name) >= sizeof(BATatoms[0].name)) return; i = ATOMallocate(name); /* overload atom ? */ if (tpe) { BATatoms[i] = BATatoms[tpe]; strncpy(BATatoms[i].name, name, sizeof(BATatoms[i].name)); BATatoms[i].name[sizeof(BATatoms[i].name) - 1] = 0; /* make coverity happy */ BATatoms[i].storage = BATatoms[tpe].storage; } else { /* cannot overload void atoms */ BATatoms[i].storage = i; BATatoms[i].linear = 0; } }
void CMakeAviDlg::loadPicture(const String &fileName) { try { m_currentPicture.load(fileName); } catch(Exception e) { showException(e); } }
void CGridDlg::OnBnClickedButtonDiagram() { if(!validate()) return; windowToValue(); const GridParameters v = getCurrentValue(); PearlDiagram diagram; PixRect *tmp = v.calculateImage(getImage(), &diagram); SAFEDELETE(tmp); const String dumpFileName = createTempFileName(_T("txt")); FILE *f = NULL; try { const String dstr = diagram.toString(); f = MKFOPEN(dumpFileName,_T("w")); _ftprintf(f, _T("%s"), dstr.cstr()); fclose(f); f = NULL; ExternProcess::run(false, _T("c:\\windows\\system32\\notepad.exe"), dumpFileName.cstr(), NULL); UNLINK(dumpFileName); } catch (Exception e) { if(f) { fclose(f); f = NULL; } showException(e); } }
str malAtomDefinition(str name, int tpe) { int i; if (strlen(name) >= IDLENGTH) { throw (SYNTAX, "atomDefinition", "Atom name '%s' too long", name); } if (ATOMindex(name) >= 0) { #ifndef HAVE_EMBEDDED /* we can restart embedded MonetDB, making this an expected error */ showException(out, TYPE, "atomDefinition", "Redefinition of atom '%s'", name); return -1; #endif } if (tpe < 0 || tpe >= GDKatomcnt) { throw(TYPE, "atomDefinition", "Undefined atom inheritance '%s'", name); } if (strlen(name) >= sizeof(BATatoms[0].name)) throw(TYPE, "atomDefinition", "Atom name too long '%s'", name); i = ATOMallocate(name); if (is_int_nil(i)) throw(TYPE,"atomDefinition", SQLSTATE(HY001) MAL_MALLOC_FAIL); /* overload atom ? */ if (tpe) { BATatoms[i] = BATatoms[tpe]; strncpy(BATatoms[i].name, name, sizeof(BATatoms[i].name)); BATatoms[i].name[sizeof(BATatoms[i].name) - 1] = 0; /* make coverity happy */ BATatoms[i].storage = ATOMstorage(tpe); } else { /* cannot overload void atoms */ BATatoms[i].storage = i; BATatoms[i].linear = false; } return MAL_SUCCEED; }
void FileEditorWnd::save() { auto file = getFile(); if (!file) return; try { if (!gWorkspace->saveFile(m_file->id)) throw std::runtime_error(cz::formatString("Error saving file '%s'", m_file->fullpath.c_str())); } catch(std::exception& e) { showException(e); } }
BOOL CTestWebCamApp::InitInstance() { AfxEnableControlContainer(); try { CTestWebCamDlg dlg; m_pMainWnd = &dlg; INT_PTR nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } } catch(Exception e) { showException(e); } return FALSE; }
void FindDlg::OnFindClick(wxCommandEvent& event) { try { gFindResultsWnd->find(m_whatTxtCtrl->GetValue(), LookWhere(m_whereCbx->GetSelection()), m_matchCaseChk->GetValue(), m_matchWholeWordChk->GetValue()); Close(); gFindResultsWnd->Show(); gMainWnd->showFindResultsWnd(); } catch (std::exception& e) { showException(e); } }
bool CShowGrafView::paintAll(CDC &dc, const CRect &rect, CFont *axisFont, CFont *buttonFont) { if(axisFont == NULL) { axisFont = &m_axisFont; } if(buttonFont == NULL) { buttonFont = &m_buttonFont; } CWnd *systemPanel = GetDlgItem(IDC_SYSTEMPANEL); CWnd *buttonPanel = GetDlgItem(IDC_BUTTONPANEL); if(systemPanel == NULL || buttonPanel == NULL) { return false; } const GraphArray &ga = getDoc()->getGraphArray(); WINDOWPLACEMENT wpl; systemPanel->GetWindowPlacement(&wpl); int buttonPanelWidth = ga.getMaxButtonWidth(dc,*buttonFont) + 30; wpl.rcNormalPosition.left = 0; wpl.rcNormalPosition.top = 0; wpl.rcNormalPosition.right = rect.right - buttonPanelWidth; wpl.rcNormalPosition.bottom = rect.bottom; systemPanel->SetWindowPlacement(&wpl); buttonPanel->GetWindowPlacement(&wpl); wpl.rcNormalPosition.left = rect.right - buttonPanelWidth; wpl.rcNormalPosition.top = 0; wpl.rcNormalPosition.right = rect.right; wpl.rcNormalPosition.bottom = rect.bottom; buttonPanel->SetWindowPlacement(&wpl); m_coordinateSystem.SetFont(axisFont,FALSE); m_coordinateSystem.setGrid(theApp.getMainWindow()->hasGrid()); try { m_coordinateSystem.OnPaint(); CClientDC dc(&m_coordinateSystem); m_coordinateSystem.setDC(dc); ga.paint(m_coordinateSystem, *buttonFont, getRelativeClientRect(this,IDC_BUTTONPANEL)); // debugLog(_T("Cells Occupied:\n%s"), m_coordinateSystem.getOccupationMap().toString().cstr()); return true; } catch(Exception e) { showException(e); return false; } }
/* * @- * Currently each user can define a new scenario, provided we have a free slot. * Scenarios not hardwired can always be dropped. */ Scenario getFreeScenario(void) { int i; Scenario scen = NULL; MT_lock_set(&scenarioLock, "getFreeScenario"); for (i = 0; i < MAXSCEN && scenarioRec[i].name; i++) ; if (i == MAXSCEN) { showException(GDKout, MAL,"freeScenario", "no scenario space left (%d); adjust MAXSCEN and recompile", MAXSCEN); } else { scen = scenarioRec + i; } MT_lock_unset(&scenarioLock, "getFreeScenario"); return scen; }
void Options::save() { try { RegistryKey settings = getKey(); settings.setValue(_T("dirlist") ,m_dirList ); settings.setValue(_T("startselectdir") ,m_startSelectDir ); settings.setValue(_T("confirmchoise") ,m_confirmChoise ); settings.setValue(_T("autoselect") ,m_autoSelect ); settings.setValue(_T("allowduplicates") ,m_allowDuplicates ); // settings.setValue(_T("password") ,m_md5password ); // NB settings.setValue(_T("maxchoise") ,m_maxChoise ); settings.setValue(_T("volume") ,m_volume ); settings.setValue(_T("backgroundcolor") ,m_backgroundColor ); settings.setValue(_T("currentcolor") ,m_currentTrackColor ); settings.setValue(_T("playqueuecolor") ,m_mediaQueueColor ); } catch(Exception e) { showException(e); } }
void Options::load() { try { RegistryKey settings = getKey(); const DefaultOptions defaultOptions; m_dirList = settings.getString(_T("dirlist") , defaultOptions.m_dirList ); m_startSelectDir = settings.getString(_T("startselectdir") , defaultOptions.m_startSelectDir ); m_confirmChoise = settings.getBool( _T("confirmchoise") , defaultOptions.m_confirmChoise ); m_autoSelect = settings.getBool( _T("autoselect") , defaultOptions.m_autoSelect ); m_allowDuplicates = settings.getBool( _T("allowduplicates") , defaultOptions.m_allowDuplicates ); m_md5password = settings.getString(_T("password") , defaultOptions.m_md5password ); m_maxChoise = settings.getInt( _T("maxchoise") , defaultOptions.m_maxChoise ); m_volume = settings.getInt( _T("volume") , defaultOptions.m_volume ); m_backgroundColor = settings.getUint( _T("backgroundcolor") , defaultOptions.m_backgroundColor ); m_currentTrackColor = settings.getUint( _T("currentcolor") , defaultOptions.m_currentTrackColor ); m_mediaQueueColor = settings.getUint( _T("playqueuecolor") , defaultOptions.m_mediaQueueColor ); } catch(Exception e) { showException(e); } }
void CMainFrame::onFileMruFile(int index) { TextView *view = getActiveTextView(); if(view == NULL) return; try { const String fname = theApp.getRecentFile(index); if(ACCESS(fname, 4) < 0) { const int errorCode = errno; showWarning(getErrnoText()); if(errorCode == ENOENT) { theApp.removeFromRecentFiles(index); } return; } CWinDiffDoc *doc = view->getDocument(); doc->setDoc(view->getId(),DIFFDOC_FILE, fname); Invalidate(FALSE); //view->refreshBoth(); } catch(Exception e) { showException(e); } }
void MCinit(void) { char *max_clients = GDKgetenv("max_clients"); int maxclients = 0; if (max_clients != NULL) maxclients = atoi(max_clients); if (maxclients <= 0) { maxclients = 64; GDKsetenv("max_clients", "64"); } MAL_MAXCLIENTS = /* console */ 1 + /* client connections */ maxclients; mal_clients = GDKzalloc(sizeof(ClientRec) * MAL_MAXCLIENTS); if( mal_clients == NULL){ showException(GDKout, MAL, "MCinit",MAL_MALLOC_FAIL); mal_exit(); } }
BOOL CShwgraphApp::InitInstance() { AfxEnableControlContainer(); // Standard initialization // If you are not using these features and wish to reduce the size // of your final executable, you should remove from the following // the specific initialization routines you do not need. CShwGraphDlg dlg; m_pMainWnd = &dlg; try { intptr_t nResponse = dlg.DoModal(); if (nResponse == IDOK) { } else if (nResponse == IDCANCEL) { } } catch(Exception e) { showException(e); } // Since the dialog has been closed, return FALSE so that we exit the // application, rather than start the application's message pump. return FALSE; }
void CShowGrafView::OnDraw(CDC *pDC) { try { if(m_firstDraw) { m_coordinateSystem.substituteControl(this, IDC_SYSTEMPANEL); m_firstDraw = false; } const CRect rect = getClientRect(this); if(paintAll(*pDC, rect, &m_axisFont, &m_buttonFont)) { DoubleInterval maxNormInterval(0,1); const DataRange dr = m_coordinateSystem.getDataRange(); enableMenuItem(ID_VIEW_SCALE_X_LOGARITHMIC , dr.getMinX() > 0); enableMenuItem(ID_VIEW_SCALE_Y_LOGARITHMIC , dr.getMinY() > 0); enableMenuItem(ID_VIEW_SCALE_X_NORMALDIST , maxNormInterval.contains(dr.getXInterval())); enableMenuItem(ID_VIEW_SCALE_Y_NORMALDIST , maxNormInterval.contains(dr.getYInterval())); checkMenuItem( ID_VIEW_RETAINASPECTRATIO , m_coordinateSystem.isRetainingAspectRatio()); enableMenuItem(ID_VIEW_RETAINASPECTRATIO , m_coordinateSystem.canRetainAspectRatio() ); checkMenuItem( ID_VIEW_ROLLAVG , getDoc()->getRollAvg() ); } } catch(Exception e) { showException(e); } }
BOOL CZoomDlg::OnInitDialog() { __super::OnInitDialog(); try { m_diff.compareStrings(m_s1.cstr(), m_s2.cstr(), m_cmp); } catch(Exception e) { showException(e); } m_fontScale = 1; m_editBox.substituteControl(this, IDC_EDIT2LINES, m_diff); m_hIcon = theApp.LoadIcon(IDR_MAINFRAME); SetIcon(m_hIcon, false); createAndSetFont( m_fontScale); m_accelTable = LoadAccelerators(theApp.m_hInstance,MAKEINTRESOURCE(IDR_ACCELERATORZOOM)); m_layoutManager.OnInitDialog(this); m_layoutManager.addControl(IDC_EDIT2LINES , RELATIVE_WIDTH | RELATIVE_HEIGHT); m_layoutManager.addControl(IDC_CHECKIGNORECASE, RELATIVE_Y_POS ); m_layoutManager.addControl(IDOK , PCT_RELATIVE_X_CENTER | RELATIVE_Y_POS ); return TRUE; }
static Client MCinitClientRecord(Client c, oid user, bstream *fin, stream *fout) { const char *prompt; c->user = user; c->username = 0; c->scenario = NULL; c->oldscenario = NULL; c->srcFile = NULL; c->blkmode = 0; c->fdin = fin ? fin : bstream_create(GDKin, 0); if ( c->fdin == NULL){ MT_lock_set(&mal_contextLock); c->mode = FREECLIENT; MT_lock_unset(&mal_contextLock); showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL); return NULL; } c->yycur = 0; c->bak = NULL; c->listing = 0; c->fdout = fout ? fout : GDKstdout; c->mdb = 0; c->history = 0; c->curprg = c->backup = 0; c->glb = 0; /* remove garbage from previous connection * be aware, a user can introduce several modules * that should be freed to avoid memory leaks */ c->usermodule = c->curmodule = 0; c->father = NULL; c->login = c->lastcmd = time(0); //c->active = 0; c->session = GDKusec(); c->qtimeout = 0; c->stimeout = 0; c->itrace = 0; c->flags = 0; c->errbuf = 0; prompt = !fin ? GDKgetenv("monet_prompt") : PROMPT1; c->prompt = GDKstrdup(prompt); if ( c->prompt == NULL){ if (fin == NULL) { c->fdin->s = NULL; bstream_destroy(c->fdin); MT_lock_set(&mal_contextLock); c->mode = FREECLIENT; MT_lock_unset(&mal_contextLock); } showException(GDKout, MAL, "initClientRecord", MAL_MALLOC_FAIL); return NULL; } c->promptlength = strlen(prompt); c->actions = 0; c->exception_buf_initialized = 0; c->error_row = c->error_fld = c->error_msg = c->error_input = NULL; c->wlc_kind = 0; c->wlc = NULL; #ifndef HAVE_EMBEDDED /* no authentication in embedded mode */ { str msg = AUTHgetUsername(&c->username, c); if (msg) /* shouldn't happen */ freeException(msg); } #endif c->blocksize = BLOCK; c->protocol = PROTOCOL_9; c->filetrans = false; c->query = NULL; char name[16]; snprintf(name, sizeof(name), "Client%d->s", (int) (c - mal_clients)); MT_sema_init(&c->s, 0, name); return c; }
/* * This is a phtread started function. Here we start the client. We * need to initialize and allocate space for the global variables. * Thereafter it is up to the scenario interpreter to process input. */ void MSserveClient(void *dummy) { MalBlkPtr mb; Client c = (Client) dummy; str msg = 0; if (!isAdministrator(c) && MCinitClientThread(c) < 0) { MCcloseClient(c); return; } /* * A stack frame is initialized to keep track of global variables. * The scenarios are run until we finally close the last one. */ mb = c->curprg->def; if (c->glb == NULL) c->glb = newGlobalStack(MAXGLOBALS + mb->vsize); if (c->glb == NULL) { showException(c->fdout, MAL, "serveClient", MAL_MALLOC_FAIL); c->mode = FINISHCLIENT + 1; /* == RUNCLIENT */ } else { c->glb->stktop = mb->vtop; c->glb->blk = mb; } if (c->scenario == 0) msg = defaultScenario(c); if (msg) { showException(c->fdout, MAL, "serveClient", "could not initialize default scenario"); c->mode = FINISHCLIENT + 1; /* == RUNCLIENT */ GDKfree(msg); } else { do { do { runScenario(c); if (c->mode == FINISHCLIENT) break; resetScenario(c); } while (c->scenario && !GDKexiting()); } while (c->scenario && c->mode != FINISHCLIENT && !GDKexiting()); } /* pre announce our exiting: cleaning up may take a while and we * don't want to get killed during that time for fear of * deadlocks */ MT_exiting_thread(); /* * At this stage we should clean out the MAL block */ freeMalBlk(c->curprg->def); c->curprg->def = 0; if (c->mode > FINISHCLIENT) { if (isAdministrator(c) /* && moreClients(0)==0 */) { if (c->scenario) { exitScenario(c); } } } if (!isAdministrator(c)) MCcloseClient(c); }
bool NutcrackerApp::OnInit() { gParameters = std::make_unique<cz::Parameters>(); gParameters->set(argc, argv); // call the base class initialization method, currently it only parses a // few common command-line options but it could be do more in the future // NOTE: Not calling it, as it will show an error message because the I try to use my own command lines // if ( !wxApp::OnInit() ) // return false; #if wxUSE_XPM wxImage::AddHandler(new wxXPMHandler); #endif #if wxUSE_LIBPNG wxImage::AddHandler(new wxPNGHandler); #endif #if wxUSE_LIBJPEG wxImage::AddHandler(new wxJPEGHandler); #endif #if wxUSE_GIF wxImage::AddHandler(new wxGIFHandler); #endif // // Initialize image lists // for (int i = 0; i < SMALLIMG_IDX_MAX; i++) gImageListSmall.Add(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE, wxART_OTHER, wxSize(16, 16))); gImageListSmall.Replace(SMALLIMG_IDX_FOLDER, wxArtProvider::GetBitmap(wxART_FOLDER, wxART_OTHER, wxSize(16, 16))); gImageListSmall.Replace(SMALLIMG_IDX_FILE_OTHER, wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16, 16))); gImageListSmall.Replace(SMALLIMG_IDX_FILE_NUT, wxBITMAP_PNG(APP_IMG_16x16_FILE_NUT)); gImageListSmall.Replace(SMALLIMG_IDX_REFRESH, wxBITMAP_PNG(APP_IMG_16x16_REFRESH)); gImageListSmall.Replace(SMALLIMG_IDX_FOLDER_ADD, wxBITMAP_PNG(APP_IMG_16x16_FOLDER_ADD)); gImageListSmall.Replace(SMALLIMG_IDX_NUT, wxBITMAP_PNG(APP_IMG_16x16_NUT)); gImageListSmall.Replace(SMALLIMG_IDX_CALLSTACK_CURRENT, wxBITMAP_PNG(APP_IMG_16x16_CALLSTACK_CURRENT)); for (int i = 0; i < BIGIMG_IDX_NUT; i++) gImageList32x32.Add(wxArtProvider::GetBitmap(wxART_MISSING_IMAGE, wxART_OTHER, wxSize(32, 32))); gImageList32x32.Replace(BIGIMG_IDX_NUT, wxBITMAP_PNG(APP_IMG_32x32_NUT)); gWorkspace = std::make_shared<Workspace>(); // create the main application window MainWnd *mainWnd = new MainWnd(); mainWnd->Show(true); if (gParameters->has("workspace")) { try { gWorkspace->load(gParameters->get("workspace")); } catch (std::exception& e) { showException(e); } } /* postAppLambdaEvent([]() { fireAppEvent(AppEventID::OpenWorkspace); }); */ std::shared_ptr<std::function<void()>> func; // // Test project handling // // success: wxApp::OnRun() will be called which will enter the main message // loop and the application will run. If we returned false here, the // application would exit immediately. return true; }
void FindResultsWnd::find(const wxString& what, LookWhere lookWhere, bool matchCase, bool matchWholeWord) { if (!gWorkspace || wxString(what).Trim()=="") return; gWorkspace->clearFindResults(); // // Determine in what files we want to look // std::vector<std::shared_ptr<const File>> files; switch(lookWhere) { case kLook_Workspace: gWorkspace->iterateFiles([&](const std::shared_ptr<const File>& file) { files.push_back(file); return true; }); break; case kLook_CurrentFile: { auto& currentfile = gFileEditorGroupWnd->getCurrentFile(); if (!currentfile) throw std::runtime_error("No file currently open."); files.push_back(currentfile); } break; default: return; } int searchFlags = 0; if (matchCase) searchFlags |= wxSTC_FIND_MATCHCASE; if (matchWholeWord) searchFlags |= wxSTC_FIND_WHOLEWORD; // // I'm creating a temporary File editor window, to search in files not open at the moment // wxStyledTextCtrl* tmptxtctrl = new wxStyledTextCtrl( this ); tmptxtctrl->Hide(); try { for (auto& f : files) { FileEditorWnd* feditorwnd = gFileEditorGroupWnd->findFileWnd(f, nullptr); if (feditorwnd) { tmptxtctrl->SetText(feditorwnd->m_textCtrl->GetText()); } else { tmptxtctrl->LoadFile(f->fullpath.widen()); } tmptxtctrl->SetSearchFlags(searchFlags); int pos=0; tmptxtctrl->SetTargetStart(0); tmptxtctrl->SetTargetEnd(tmptxtctrl->GetLength()-1); while((pos=tmptxtctrl->SearchInTarget(what))!=-1) { tmptxtctrl->GotoPos(pos); // GetCurrentLine returns the line text with the newline characters, which causes the grid rows to grow, // so we need to remove the newline characters at the end gWorkspace->addFindResult(wxString(tmptxtctrl->GetLine(tmptxtctrl->GetCurrentLine())).Trim(), f, tmptxtctrl->GetCurrentLine()+1, tmptxtctrl->GetColumn(pos)); tmptxtctrl->SetTargetStart(pos+1); tmptxtctrl->SetTargetEnd(tmptxtctrl->GetLength()-1); } } } catch(std::exception& e) { showException(e); } tmptxtctrl->Destroy(); }