Пример #1
0
static int
ThreadedReadConsole(const char *prompt, char *buf, int len, int addtohistory)
{
    sighandler_t oldint,oldbreak;
    /*
     *   SIGINT/SIGBREAK when ESS is waiting for output are a real pain:
     *   they get processed after user hit <return>.
     *   The '^C\n' in raw Rterm is nice. But, do we really need it ?
     */
    oldint = signal(SIGINT, SIG_IGN);
    oldbreak = signal(SIGBREAK, SIG_IGN);
    mainThreadId = GetCurrentThreadId();
    lineavailable = 0;
    tprompt = prompt;
    tbuf = buf;
    tlen = len;
    thist = addtohistory;
    SetEvent(EhiWakeUp);
    while (1) {
	if (!peekevent()) WaitMessage();
	if (lineavailable) break;
	doevent();
	if(R_Tcl_do) R_Tcl_do();
    }
    lineavailable = 0;
    /* restore handler  */
    signal(SIGINT, oldint);
    signal(SIGBREAK, oldbreak);
    return tlen;
}
Пример #2
0
int Menu::umenurelease1(int key,int state,int x,int y,Time time,Widget *org)
  {
  /*  printf("Menu release %d,%d greedy=%d\n",x,y,greedy); */
  greedygrab(1);
  stfocus((Widget *)nth(0));
  if(x>=0 && x<gtw() && y>=0 && y<gth())
    {
    ev.type=ButtonPress;
    calcpointer();
    doevent(gtmain(),&ev);
    calcpointer();
    ev.type=ButtonRelease;
    doevent(gtmain(),&ev);
    }
  return 0;
  }
Пример #3
0
void R_ProcessEvents(void)
{
    while (peekevent()) doevent();
    if (cpuLimit > 0.0 || elapsedLimit > 0.0) {
	double cpu, data[5];
	R_getProcTime(data);
	cpu = data[0] + data[1];  /* children? */
	if (elapsedLimit > 0.0 && data[2] > elapsedLimit) {
	    cpuLimit = elapsedLimit = -1;
	    if (elapsedLimit2 > 0.0 && data[2] > elapsedLimit2) {
		elapsedLimit2 = -1.0;
		error(_("reached session elapsed time limit"));
	    } else
		error(_("reached elapsed time limit"));
	}
	if (cpuLimit > 0.0 && cpu > cpuLimit) {
	    cpuLimit = elapsedLimit = -1;
	    if (cpuLimit2 > 0.0 && cpu > cpuLimit2) {
		cpuLimit2 = -1.0;
		error(_("reached session CPU time limit"));
	    } else
		error(_("reached CPU time limit"));
	}
    }
    if (UserBreak) {
	UserBreak = FALSE;
	onintr();
    }
    R_CallBackHook();
    if(R_Tcl_do) R_Tcl_do();
}
Пример #4
0
Файл: run.c Проект: kmillar/rho
int
rpipeGetc(rpipe * r)
{
    DWORD a, b;
    char  c;

    if (!r)
	return NOLAUNCH;
    while (PeekNamedPipe(r->read, NULL, 0, NULL, &a, NULL)) {
	if (!a && !r->active) {
	    /* I got a case in which process terminated after Peek.. */
	    PeekNamedPipe(r->read, NULL, 0, NULL, &a, NULL);
	    if (!a) return NOLAUNCH;/* end of pipe */
	}
	if (a) {
	    if (ReadFile(r->read, &c, 1, &b, NULL) == TRUE)
		return c;
	    else
		return NOLAUNCH;/* error but...treated as eof */
	}
	/* we want to look for user break here */
	while (peekevent()) doevent();
	if (UserBreak) {
	    rpipeTerminate(r);
	    break;
	}
	R_ProcessEvents();
	Sleep(100);
    }
    return NOLAUNCH;		/* again.. */
}
Пример #5
0
wchar_t *askfilenamesW(const wchar_t *title, const wchar_t *default_name,
		       int multi,
		       const wchar_t *filters, int filterindex,
		       const wchar_t *dir)
{
    int i;
    OPENFILENAMEW ofn;
    char cwd[MAX_PATH];
    wchar_t wcod[MAX_PATH];
    HWND prev = GetFocus();

    if (!default_name) default_name = L"";
    memset(wcsbuf, 0, sizeof(wcsbuf));
    wcscpy(wcsbuf, default_name);
    GetCurrentDirectory(MAX_PATH, cwd);
    if (!strcmp(cod, "")) {
	if (!dir) GetCurrentDirectoryW(MAX_PATH, wcod); else wcscpy(wcod, dir);
    } else
	mbstowcs(wcod, cod, MAX_PATH);

    ofn.lStructSize     = sizeof(OPENFILENAME);
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
    ofn.hInstance       = 0;
    ofn.lpstrFilter     = filters;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter  = 0;
    ofn.nFilterIndex    = filterindex;
    ofn.lpstrFile       = wcsbuf;
    ofn.nMaxFile        = 65520; /* precaution against overflow */
    ofn.lpstrFileTitle  = NULL;
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
    ofn.lpstrInitialDir = wcod;
    ofn.lpstrTitle      = title;
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
    ofn.nFileOffset     = 0;
    ofn.nFileExtension  = 0;
    ofn.lpstrDefExt     = L"*";
    ofn.lCustData       = 0L;
    ofn.lpfnHook        = NULL;
    ofn.lpTemplateName  = NULL;

    if (GetOpenFileNameW(&ofn) == 0) {
	/* This could fail if the Unicode name is not a native name */
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
	if(res) strcpy(cod, cwd);
	SetCurrentDirectory(cwd);
	wcsbuf[0] = 0;
	wcsbuf[1] = 0;
    } else {
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
	if(res) strcpy(cod, cwd);
	SetCurrentDirectory(cwd);
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
    }
    SetFocus(prev);
    return wcsbuf;
}
Пример #6
0
int Wind::configurenotify(XEvent *ev)
  {
  int rtn;
  // Give it to the widget, otherwise give it to our kids
  if (target && target->gtouter() == this && (rtn = target->configurenotify(ev)) != -1)
    return rtn;
  doevent(this,ev);
  return 0;
  }
Пример #7
0
void R_ProcessEvents(void)
{
    while (peekevent()) doevent();
    if (UserBreak) {
	UserBreak = FALSE;
	onintr();
    }
    R_CallBackHook();
    if(R_tcldo) R_tcldo();
}
Пример #8
0
char *askfilesavewithdir(const char *title, const char *default_name,
			 const char *dir)
{
    int i;
    OPENFILENAME ofn;
    char cwd[MAX_PATH], *defext = NULL;

    if (!default_name) default_name = "";
    else if(default_name[0] == '|') {
	defext = (char *)default_name + 2;
	default_name = "";
    }
    strcpy(strbuf, default_name);

    ofn.lStructSize     = sizeof(OPENFILENAME);
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
    ofn.hInstance       = 0;
    ofn.lpstrFilter     = userfilter?userfilter:filter[0];
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter  = 0;
    ofn.nFilterIndex    = 0;
    ofn.lpstrFile       = strbuf;
    ofn.nMaxFile        = BUFSIZE;
    ofn.lpstrFileTitle  = NULL;
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
    if(dir && strlen(dir) > 0) {
	strcpy(cwd, dir);
	/* This should have been set to use backslashes in the caller */
	ofn.lpstrInitialDir = cwd;
    } else {
	if (GetCurrentDirectory(MAX_PATH, cwd))
	    ofn.lpstrInitialDir = cwd;
	else
	    ofn.lpstrInitialDir = NULL;
    }
    ofn.lpstrTitle      = title;
    ofn.Flags           = OFN_OVERWRITEPROMPT |
	OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
    ofn.nFileOffset     = 0;
    ofn.nFileExtension  = 0;
    ofn.lpstrDefExt     = defext;
    ofn.lCustData       = 0L;
    ofn.lpfnHook        = NULL;
    ofn.lpTemplateName  = NULL;

    if (GetSaveFileName(&ofn) == 0)
	return NULL;
    else {
	for (i = 0; i < 10; i++) if (peekevent()) doevent();
	return strbuf;
    }
}
Пример #9
0
int Menu::umenupress1(int key,int state,int x,int y,Time time,Widget *org)
  {
  if(x<0 || x>=gtwidth() || y<0 || y>=gtheight())
    { /* Mouse press is out of our window */
    popgrab();
    }
  else
    { /* Mouse press is in our window */
    calcpointer();
    /* Event is for one of our kids maybe */
    doevent(gtmain(),&ev);
    }
  return 0;
  }
Пример #10
0
char *askfilenames(const char *title, const char *default_name, int multi,
		   const char *filters, int filterindex,
		   char *strbuf, int bufsize,
		   const char *dir)
{
    int i;
    OPENFILENAME ofn;
    char cwd[MAX_PATH] = "";
    HWND prev = GetFocus();

    if (!default_name) default_name = "";
    strcpy(strbuf, default_name);
    GetCurrentDirectory(MAX_PATH, cwd);
    if (!cod[0]) strcpy(cod, cwd);

    ofn.lStructSize     = sizeof(OPENFILENAME);
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
    ofn.hInstance       = 0;
    ofn.lpstrFilter     = filters;
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter  = 0;
    ofn.nFilterIndex    = filterindex;
    ofn.lpstrFile       = strbuf;
    ofn.nMaxFile        = bufsize;
    ofn.lpstrFileTitle  = NULL;
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
    ofn.lpstrInitialDir = dir ? dir : cod;
    ofn.lpstrTitle      = title;
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
    ofn.nFileOffset     = 0;
    ofn.nFileExtension  = 0;
    ofn.lpstrDefExt     = "*";
    ofn.lCustData       = 0L;
    ofn.lpfnHook        = NULL;
    ofn.lpTemplateName  = NULL;

    if (GetOpenFileName(&ofn) == 0) {
	if(!dir) GetCurrentDirectory(MAX_PATH, cod);
	SetCurrentDirectory(cwd);
	strbuf[0] = 0;
	strbuf[1] = 0;
    } else {
	if(!dir) GetCurrentDirectory(MAX_PATH, cod);
	SetCurrentDirectory(cwd);
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
    }
    SetFocus(prev);
    return strbuf;
}
Пример #11
0
uint eventlist::operator++(int){
    currtime++;
    // put all the things that should be done EACH TURN in here.
    doevent();
    // update halucination
    // movemonsters
    // generate new monsters
    // display messages
    // heal hero
    // use food
    // get rid of old corpses


    return currtime;
}
Пример #12
0
/*
 *  Handle the events from a message dialog, hide the window afterwards.
 */
static int handle_message_dialog(window w)
{
    window old;
    dialog_data *d = data(w);

    old = currentdrawing();
    d->hit = NOT_CHOSEN_YET;

    show(w);
    while (d->hit == NOT_CHOSEN_YET) {
	waitevent();
	doevent();
    }
    hide(w);

    if (old) drawto(old);

    return d->hit;
}
Пример #13
0
wchar_t *askfilesaveW(const char *title, const char *default_name) 
{
    int i;
    OPENFILENAMEW ofn;
    wchar_t cwd[MAX_PATH], wdef_name[MAX_PATH], wtitle[1000];

    if (!default_name) wcscpy(wdef_name, L"");
    else mbstowcs(wdef_name, default_name, MAX_PATH);
    wcscpy(wcsbuf, wdef_name);
    mbstowcs(wtitle, title, 1000);

    ofn.lStructSize     = sizeof(OPENFILENAME);
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
    ofn.hInstance       = 0;
    ofn.lpstrFilter     = userfilterW ? userfilterW : wfilter[0];
    ofn.lpstrCustomFilter = NULL;
    ofn.nMaxCustFilter  = 0;
    ofn.nFilterIndex    = 0;
    ofn.lpstrFile       = wcsbuf;
    ofn.nMaxFile        = BUFSIZE;
    ofn.lpstrFileTitle  = NULL;
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
    if (GetCurrentDirectoryW(MAX_PATH, cwd))
	ofn.lpstrInitialDir = cwd;
    else
	ofn.lpstrInitialDir = NULL;
    ofn.lpstrTitle      = wtitle;
    ofn.Flags           = OFN_OVERWRITEPROMPT |
	OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
    ofn.nFileOffset     = 0;
    ofn.nFileExtension  = 0;
    ofn.lpstrDefExt     = NULL;
    ofn.lCustData       = 0L;
    ofn.lpfnHook        = NULL;
    ofn.lpTemplateName  = NULL;

    if (GetSaveFileNameW(&ofn) == 0)
	return NULL;
    else {
	for (i = 0; i < 10; i++) if (peekevent()) doevent();
	return wcsbuf;
    }
}
Пример #14
0
int main(int argc, char **argv)
{
	struct event *ev;

	nproc = 128;
	ncycmax = 10;
	dtc = 0.01;
	dts = 0.0;
	alpha = 0.1;

	init();

	while ((ev = nextevent()) != NULL) {
		doevent(ev);
	}

	term();
	tst_resm(TPASS, "PASS");
	tst_exit();
}