/* * Do a special thing (beep, flush, etc) */ static errr Term_xtra_emx(int n, int v) { void *instance=((termWindow*)Term)->instance; switch (n) { case TERM_XTRA_SHAPE: if (v) { emx_showcursor(instance); } else { emx_hidecursor(instance); } return (0); case TERM_XTRA_NOISE: DosBeep(440, 50); return (0); case TERM_XTRA_FLUSH: while (!CheckEvents(TRUE)); return 0; case TERM_XTRA_EVENT: return (CheckEvents(!v)); case TERM_XTRA_DELAY: if (v > 0) _sleep2(v); return (0); } return (1); }
void itimerthread(void* dummy) { if (outlevel >= O_VERBOSE) report(stderr, GT_("fetchmail: thread sleeping for %d sec.\n"), poll_interval); while(1) { _sleep2(poll_interval*1000); kill((getpid()), SIGALRM); } }
/* * a thread-safe usecond sleep */ void xine_usec_sleep(unsigned usec) { #if HAVE_NANOSLEEP /* nanosleep is prefered on solaris, because it's mt-safe */ struct timespec ts; ts.tv_sec = usec / 1000000; ts.tv_nsec = (usec % 1000000) * 1000; nanosleep(&ts, NULL); #else #ifdef __EMX__ _sleep2(usec / 1000); #else usleep(usec); #endif }
int main(int argc, char **argv) { int c, end = 0, lines = 25; int x, y, h, n, v; FILE *in=NULL; char a; char buf[160]; HPIPE pipe; APIRET rc; char *target; /* Check command line */ if (argc!=2 && argc!=3) { printf("Usage: %s Mirror|Recall|Choice|Term-4|...|Term-7 [number of lines]\n" "Start this before angband.exe\n", argv[0]); exit(1); } if (argc==3) lines = atoi(argv[2]); if (lines <= 0) lines = 25; printf("Looking for Angband... press ^C to abort\n"); target=strdup(argv[1]); for (c=0; c<strlen(target); c++) target[c]=tolower(target[c]); strnfmt(buf, 160, "\\pipe\\angband\\%s", target); do { rc=DosCreateNPipe((PSZ)buf, /* Create pipe */ &pipe, NP_ACCESS_INBOUND, NP_WAIT|NP_TYPE_BYTE|NP_READMODE_BYTE|1, 1, /* No output buffer */ 1, /* No input buffer */ -1); if (rc) /* Pipe not created */ { printf("DosCreateNPipe: rc=%ld, pipe=%ld\n", (long)rc, (long)pipe); break; } do { rc=DosConnectNPipe(pipe); /* Wait for angband to connect */ if (!rc) break; _sleep2(500); /* Sleep for 0.5s */ } while (_read_kbd(0, 0, 0)==-1); /* Until key pressed */ if (rc) break; h=_imphandle(pipe); /* Register handle with io */ setmode(h, O_BINARY); /* Make it binary */ in=fdopen(h, "rb"); /* Register handle with stdio */ } while (0); /* We don't need no stinking exception handling <g> */ if (!in) { printf("Sorry, the pipe connection to Angband could not be established.\n"); exit(1); } printf("Connected.\n"); strnfmt(buf, 160, "mode co80,%d", lines); system(buf); /* Infinite loop */ while (!end) { /* Get command */ c = fgetc(in); switch (c) { case PIP_XTRA: if (!fread(&n, sizeof(x), 1, in) || !fread(&v, sizeof(y), 1, in)) abort(); /* This hack prevents another hack */ printf("Sorry, angband.exe and aclient.exe don't fit together.\n"); exit(1); break; case PIP_CURS: if (!fread(&x, sizeof(x), 1, in) || !fread(&y, sizeof(y), 1, in)) abort(); Term_curs_emx(x, y); break; case PIP_WIPE: if (!fread(&x, sizeof(x), 1, in) || !fread(&y, sizeof(y), 1, in) || !fread(&n, sizeof(n), 1, in)) abort(); Term_wipe_emx(x, y, n); break; case PIP_TEXT: if (!fread(&x, sizeof(x), 1, in) || !fread(&y, sizeof(y), 1, in) || !fread(&n, sizeof(n), 1, in) || !fread(&a, sizeof(a), 1, in) || (n > 160) || !fread(buf, n, 1, in)) abort(); Term_text_emx(x, y, n, a, buf); break; case PIP_INIT: Term_init_emx(NULL); break; case PIP_NUKE: case EOF: default: Term_nuke_emx(NULL); end=1; break; } } return 0; }