Exemple #1
0
void
EngineOutputPopUp ()
{
    static int  needInit = TRUE;
    static char *title = N_("Engine output");

    if (GenericPopUp(engoutOptions, _(title), EngOutDlg, BoardWindow, NONMODAL, appData.topLevel)) {
	if(engoutOptions[STRIDE-1].type != Break)
	    DisplayFatalError(_("Mismatch of STRIDE in nengineoutput.c\nChange and recompile!"), 0, 2);
	AddHandler(&engoutOptions[MEMO], EngOutDlg, 6);
	AddHandler(&engoutOptions[MEMO+STRIDE], EngOutDlg, 6);
	if( needInit ) {
	    InitEngineOutput(&engoutOptions[0], &engoutOptions[MEMO]); // make icon bitmaps
	    needInit = FALSE;
	}
        SetEngineColorIcon( 0 );
        SetEngineColorIcon( 1 );
        SetEngineState( 0, STATE_IDLE, "" );
        SetEngineState( 1, STATE_IDLE, "" );
    } else {
	SetIconName(EngOutDlg, _(title));
	SetDialogTitle(EngOutDlg, _(title));
    }

    MarkMenu("View.EngineOutput", EngOutDlg);

    ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
}
Exemple #2
0
void
Colorize (ColorClass cc, int continuation)
{
    char buf[MSG_SIZ];
    int count, outCount, error;

    if (textColors[(int)cc].bg > 0) {
	if (textColors[(int)cc].fg > 0) {
	  snprintf(buf, MSG_SIZ, "\033[0;%d;%d;%dm", textColors[(int)cc].attr,
		   textColors[(int)cc].fg, textColors[(int)cc].bg);
	} else {
	  snprintf(buf, MSG_SIZ, "\033[0;%d;%dm", textColors[(int)cc].attr,
		   textColors[(int)cc].bg);
	}
    } else {
	if (textColors[(int)cc].fg > 0) {
	  snprintf(buf, MSG_SIZ, "\033[0;%d;%dm", textColors[(int)cc].attr,
		    textColors[(int)cc].fg);
	} else {
	  snprintf(buf, MSG_SIZ, "\033[0;%dm", textColors[(int)cc].attr);
	}
    }
    count = strlen(buf);
    outCount = OutputToProcess(NoProc, buf, count, &error);
    if (outCount < count) {
	DisplayFatalError(_("Error writing to display"), error, 1);
    }

    if (continuation) return;
    PlaySoundForColor(cc);
}
Exemple #3
0
int
OpenTCP (char *host, char *port, ProcRef *pr)
{
#if OMIT_SOCKETS
    DisplayFatalError(_("Socket support is not configured in"), 0, 2);
#else  /* !OMIT_SOCKETS */
    struct addrinfo hints;
    struct addrinfo *ais, *ai;
    int error;
    int s=0;
    ChildProc *cp;

    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;

    error = getaddrinfo(host, port, &hints, &ais);
    if (error != 0) {
      /* a getaddrinfo error is not an errno, so can't return it */
      fprintf(debugFP, "getaddrinfo(%s, %s): %s\n",
	      host, port, gai_strerror(error));
      return ENOENT;
    }

    for (ai = ais; ai != NULL; ai = ai->ai_next) {
      if ((s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) < 0) {
	error = errno;
	continue;
      }
      if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) {
	error = errno;
	continue;
      }
      error = 0;
      break;
    }
    freeaddrinfo(ais);

    if (error != 0) {
      return error;
    }

    cp = (ChildProc *) calloc(1, sizeof(ChildProc));
    cp->kind = CPSock;
    cp->pid = 0;
    cp->fdFrom = s;
    cp->fdTo = s;
    *pr = (ProcRef) cp;
#endif /* !OMIT_SOCKETS */

    return 0;
}
Exemple #4
0
int
SetUpChildIO (int to_prog[2], int from_prog[2])
{
    char pty_name[MSG_SIZ];

    if ((to_prog[1] = PseudoTTY(pty_name)) == -1) {
	DisplayFatalError("Can't open pseudo-tty", errno, 1);
	ExitEvent(1);
    }
    from_prog[0] = to_prog[1];
    to_prog[0] = from_prog[1] = open(pty_name, O_RDWR, 0);

#if HAVE_STROPTS_H /* do we really need this??  pipe-like behavior is fine */
    if (ioctl (to_prog[0], I_PUSH, "ptem") == -1 ||
	ioctl (to_prog[0], I_PUSH, "ldterm") == -1 ||
	ioctl (to_prog[0], I_PUSH, "ttcompat") == -1) {
# ifdef NOTDEF /* seems some systems don't have or need ptem and ttcompat */
	DisplayFatalError("Can't ioctl pseudo-tty", errno, 1);
	ExitEvent(1);
# endif /*NOTDEF*/
    }
#endif /* HAVE_STROPTS_H */

}
Exemple #5
0
void InitEngineUCI( const char * iniDir, ChessProgramState * cps )
{   // replace engine command line by adapter command with expanded meta-symbols
    if( cps->isUCI ) {
        char *p, *q;
        char polyglotCommand[MSG_SIZ];

        p = appData.adapterCommand;
        q = polyglotCommand;
        while(*p) {
          if(*p == '\\') p++; else
          if(*p == '%') { // substitute marker
            char argName[MSG_SIZ], buf[MSG_SIZ], *s = buf;
            if(*++p == '%') { // second %, expand as f or s in option name (e.g. %%cp -> fcp)
              *s++ = cps == &first ? 'f' : 's';
              p++;
            }
            while(*p >= '0' && *p) *s++ = *p++; // copy option name
            *s = NULLCHAR;
            if(cps == &second) { // change options for first into those for second engine
              if(strstr(buf, "first") == buf) sprintf(argName, "second%s", buf+5); else
              if(buf[0] == 'f') sprintf(argName, "s%s", buf+1); else
		safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
            } else safeStrCpy(argName, buf, sizeof(argName)/sizeof(argName[0]));
            if(GetArgValue(argName)) { // look up value of option with this name
              s = argName;
              while(*s) *q++ = *s++;
            } else DisplayFatalError("Bad adapter command", 0, 1);
            continue;
          }
          if(*p) *q++ = *p++;
        }
        *q = NULLCHAR;
        cps->program = StrSave(polyglotCommand);
        cps->dir = appData.polyglotDir;
    }
}
Exemple #6
0
int
OpenRcmd (char *host, char *user, char *cmd, ProcRef *pr)
{
    DisplayFatalError(_("internal rcmd not implemented for Unix"), 0, 1);
    return -1;
}