Example #1
0
NLM_EXTERN MonitorPtr LIBCALL Nlm_MonitorIntNewEx (Nlm_CharPtr title, Nlm_Int4 n1, Nlm_Int4 n2, Nlm_Boolean hasCancelBtn)
{
	AppMsgInfo *info = GetAppMsgInfo();
	Monitor *pMon = (Monitor*) MemNew(sizeof(Monitor));

	if (pMon != NULL)
	{
		MON_SET_MAGIC(pMon);
		pMon->type = MonType_Int;
		pMon->strTitle = title ? StrSave(title) : 0;
		pMon->num1 = n1;
		pMon->num2 = n2;
		pMon->cancel = FALSE;
		pMon->hasCancelBtn = (int) hasCancelBtn;
		if (!(*info->hookMonitor)(pMon,MonCode_Create))
		{
		    MonitorFree(pMon);
		    /* only post an information message here; it is expected
		    	that the hook function would report the real reason
		    	that the monitor creation failed. */
			ErrPostEx(SEV_INFO,0,0,"Unable to create monitor");
			return NULL;
		}
	}
	return pMon;
}
Example #2
0
/* returns an accession from Bioseq; allocates memory! */
CharPtr LIBCALL Misc_GetAccession(BioseqPtr pbs)
{
     SeqIdPtr psi = NULL;
     SeqIdPtr psiThis = NULL;
     TextSeqIdPtr ptsi = NULL;
     CharPtr pacc = NULL;

    /* SK: NULL ptr check */
    if (pbs == NULL)
    {
        ErrPostEx(SEV_ERROR,0,0, "Misc_GetAccession: NULL pbs.");
        return NULL;
    }

      psi = pbs->id;
      if (psi == NULL)
       {
         ErrPostEx(SEV_ERROR,0,0, "Misc_GetAccession: NULL Seq-id pointer.");
         return NULL;
       }
      psiThis = psi;
      while (psiThis != NULL)
       {
         if ((psiThis->choice == SEQID_GENBANK) ||
	 (psiThis->choice == SEQID_EMBL) ||
	 (psiThis->choice == SEQID_PIR) ||
	 (psiThis->choice == SEQID_SWISSPROT) ||
	 (psiThis->choice == SEQID_OTHER) ||
	 (psiThis->choice == SEQID_DDBJ) ||
	 (psiThis->choice == SEQID_PRF))
          {
            ptsi = psiThis->data.ptrvalue;
            if (ptsi == NULL)
            {
               ErrPostEx(SEV_ERROR,0,0, "Misc_GetAccession: NULL TextSeq-id pointer.");
               return FALSE;
            }
            if (ptsi->accession != NULL)
            {
              pacc = StrSave(ptsi->accession);
              return pacc;
            }
            else
            {
              ErrPostEx(SEV_ERROR,0,0, "Misc_GetAccession: NULL pointer to accession.");
              return NULL;
            }
          }
         psiThis = psiThis->next;
       }
       return NULL;
}
Example #3
0
NLM_EXTERN MonitorPtr LIBCALL Nlm_MonitorStrNewEx (Nlm_CharPtr title, Nlm_Int2 len, Nlm_Boolean hasCancelBtn)
{
	AppMsgInfo *info = GetAppMsgInfo();
	Monitor *pMon = (Monitor*) MemNew(sizeof(Monitor));

	if (pMon != NULL)
	{
		MON_SET_MAGIC(pMon);
		pMon->type = MonType_Str;
		pMon->strTitle = title ? StrSave(title) : 0;
		pMon->num1 = MAX(0,MIN(len,72));
		pMon->cancel = FALSE;
		pMon->hasCancelBtn = (int) hasCancelBtn;
		(*info->hookMonitor)(pMon,MonCode_Create);
	}
	return pMon;
}
Example #4
0
/** Add a new symbol in the symbol table. */
Symbol AddSym (int tbl_id, char *name, int type)
{
  int index;
  SymTbl tbl = TBL + tbl_id;
  Symbol sym;
  if ((tbl_id < 0) || (tbl_id > next_tbl))
    error ("symbol: in FindSym: illegal tbl_id");
  index = Hash (tbl, name, type);
  sym = tbl->array + index;
  /* create a new symbol if necessary */
  if (sym->type == INVALID_SYMBOL)
    {
      sym->name = StrSave (name);
      sym->type = type;
      sym->value = 0;
      sym->ptr = 0;
    }
  return sym;
}
Example #5
0
NLM_EXTERN Nlm_Boolean LIBCALL Nlm_MonitorStrValue (MonitorPtr pMon, Nlm_CharPtr sval)
{
	AppMsgInfo *info = GetAppMsgInfo();
	if ( ! MON_IS_VALID(pMon) )
	{
		ErrPostEx(SEV_WARNING,0,0,"MonitorStrValue: %s",_invalid_mon);
		return FALSE;
	}
	if (pMon->type != MonType_Str)
	{
		ErrPostEx(SEV_WARNING,0,0,"MonitorStrValue: %s",_invalid_type);
		return (Nlm_Boolean)(!pMon->cancel);
	}

	if (pMon->strValue) MemFree((void*)pMon->strValue);
	pMon->strValue = sval ? StrSave(sval) : 0;
	(*info->hookMonitor)(pMon,MonCode_StrValue);
	return (Nlm_Boolean)(!pMon->cancel);
}
Example #6
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;
    }
}
Example #7
0
/* Build the list of games in the open file f.
 * Returns 0 for success or error number.
 */
int
GameListBuild (FILE *f)
{
    ChessMove cm, lastStart;
    int gameNumber;
    ListGame *currentListGame = NULL;
    int error, scratch=100, plyNr=0, fromX, fromY, toX, toY;
    int offset;
    char lastComment[MSG_SIZ], buf[MSG_SIZ];
    TimeMark t, t2;

    GetTimeMark(&t);
    GameListFree(&gameList);
    yynewfile(f);
    gameNumber = 0;
    movePtr = 0;

    lastStart = (ChessMove) 0;
    yyskipmoves = FALSE;
    do {
        yyboardindex = scratch;
	offset = yyoffset();
	quickFlag = plyNr + 1;
	cm = (ChessMove) Myylex();
	switch (cm) {
	  case GNUChessGame:
	    if ((error = GameListNewGame(&currentListGame))) {
		rewind(f);
		yyskipmoves = FALSE;
		return(error);
	    }
	    currentListGame->number = ++gameNumber;
	    currentListGame->offset = offset;
	    if(1) { CopyBoard(boards[scratch], initialPosition); plyNr = 0; currentListGame->moves = PackGame(boards[scratch]); }
	    if (currentListGame->gameInfo.event != NULL) {
		free(currentListGame->gameInfo.event);
	    }
	    currentListGame->gameInfo.event = StrSave(yy_text);
	    lastStart = cm;
	    break;
	  case XBoardGame:
	    lastStart = cm;
	    break;
	  case MoveNumberOne:
	    switch (lastStart) {
	      case GNUChessGame:
		break;		/*  ignore  */
	      case PGNTag:
		lastStart = cm;
		break;		/*  Already started */
	      case (ChessMove) 0:
	      case MoveNumberOne:
	      case XBoardGame:
		if ((error = GameListNewGame(&currentListGame))) {
		    rewind(f);
		    yyskipmoves = FALSE;
		    return(error);
		}
		currentListGame->number = ++gameNumber;
		currentListGame->offset = offset;
		if(1) { CopyBoard(boards[scratch], initialPosition); plyNr = 0; currentListGame->moves = PackGame(boards[scratch]); }
		lastStart = cm;
		break;
	      default:
		break;		/*  impossible  */
	    }
	    break;
	  case PGNTag:
	    lastStart = cm;
	    if ((error = GameListNewGame(&currentListGame))) {
		rewind(f);
		yyskipmoves = FALSE;
		return(error);
	    }
	    currentListGame->number = ++gameNumber;
	    currentListGame->offset = offset;
	    ParsePGNTag(yy_text, &currentListGame->gameInfo);
	    do {
		yyboardindex = 1;
		offset = yyoffset();
		cm = (ChessMove) Myylex();
		if (cm == PGNTag) {
		    ParsePGNTag(yy_text, &currentListGame->gameInfo);
		}
	    } while (cm == PGNTag || cm == Comment);
	    if(1) {
		int btm=0;
		if(currentListGame->gameInfo.fen) ParseFEN(boards[scratch], &btm, currentListGame->gameInfo.fen, FALSE);
		else CopyBoard(boards[scratch], initialPosition);
		plyNr = (btm != 0);
		currentListGame->moves = PackGame(boards[scratch]);
	    }
	    if(cm != NormalMove) break;
	  case IllegalMove:
		if(appData.testLegality) break;
	  case NormalMove:
	    /* Allow the first game to start with an unnumbered move */
	    yyskipmoves = FALSE;
	    if (lastStart == (ChessMove) 0) {
	      if ((error = GameListNewGame(&currentListGame))) {
		rewind(f);
		yyskipmoves = FALSE;
		return(error);
	      }
	      currentListGame->number = ++gameNumber;
	      currentListGame->offset = offset;
	      if(1) { CopyBoard(boards[scratch], initialPosition); plyNr = 0; currentListGame->moves = PackGame(boards[scratch]); }
	      lastStart = MoveNumberOne;
	    }
	  case WhiteCapturesEnPassant:
	  case BlackCapturesEnPassant:
	  case WhitePromotion:
	  case BlackPromotion:
	  case WhiteNonPromotion:
	  case BlackNonPromotion:
	  case WhiteKingSideCastle:
	  case WhiteQueenSideCastle:
	  case BlackKingSideCastle:
	  case BlackQueenSideCastle:
	  case WhiteKingSideCastleWild:
	  case WhiteQueenSideCastleWild:
	  case BlackKingSideCastleWild:
	  case BlackQueenSideCastleWild:
	  case WhiteHSideCastleFR:
	  case WhiteASideCastleFR:
	  case BlackHSideCastleFR:
	  case BlackASideCastleFR:
		fromX = currentMoveString[0] - AAA;
		fromY = currentMoveString[1] - ONE;
		toX = currentMoveString[2] - AAA;
		toY = currentMoveString[3] - ONE;
		plyNr++;
		ApplyMove(fromX, fromY, toX, toY, currentMoveString[4], boards[scratch]);
		if(currentListGame && currentListGame->moves) PackMove(fromX, fromY, toX, toY, boards[scratch][toY][toX]);
	    break;
        case WhiteWins: // [HGM] rescom: save last comment as result details
        case BlackWins:
        case GameIsDrawn:
        case GameUnfinished:
	    if(!currentListGame) break;
	    if(currentListGame->gameInfo.result == GameUnfinished)
		currentListGame->gameInfo.result = cm; // correct result tag with actual result
	    if (currentListGame->gameInfo.resultDetails != NULL) {
		free(currentListGame->gameInfo.resultDetails);
	    }
	    if(yy_text[0] == '{') {
		char *p;
		safeStrCpy(lastComment, yy_text+1, sizeof(lastComment)/sizeof(lastComment[0]));
		if((p = strchr(lastComment, '}'))) *p = 0;
		currentListGame->gameInfo.resultDetails = StrSave(lastComment);
	    }
	    break;
	  default:
	    break;
	}
	if(gameNumber % 1000 == 0) {
	    snprintf(buf, MSG_SIZ, _("Reading game file (%d)"), gameNumber);
	    DisplayTitle(buf); DoEvents();
	}
    }
    while (cm != (ChessMove) 0);

 if(currentListGame) {
    if(!currentListGame->moves) DisplayError("Game cache overflowed\nPosition-searching might not work properly", 0);

    if (appData.debugMode) {
	for (currentListGame = (ListGame *) gameList.head;
	     currentListGame->node.succ;
	     currentListGame = (ListGame *) currentListGame->node.succ) {

	    fprintf(debugFP, "Parsed game number %d, offset %ld:\n",
		    currentListGame->number, currentListGame->offset);
	    PrintPGNTags(debugFP, &currentListGame->gameInfo);
	}
    }
  }
    if(appData.debugMode) { GetTimeMark(&t2);printf("GameListBuild %ld msec\n", SubtractTimeMarks(&t2,&t)); }
    quickFlag = 0;
    PackGame(boards[scratch]); // for appending end-of-game marker.
    DisplayTitle("WinBoard");
    rewind(f);
    yyskipmoves = FALSE;
    return 0;
}