Example #1
0
/* [AS] Replaced by "dynamic" tag selection below */
char *
GameListLineOld (int number, GameInfo *gameInfo)
{
    char *event = (gameInfo->event && strcmp(gameInfo->event, "?") != 0) ?
		     gameInfo->event : gameInfo->site ? gameInfo->site : "?";
    char *white = gameInfo->white ? gameInfo->white : "?";
    char *black = gameInfo->black ? gameInfo->black : "?";
    char *date = gameInfo->date ? gameInfo->date : "?";
    int len = 10 + strlen(event) + 2 + strlen(white) + 1 +
      strlen(black) + 11 + strlen(date) + 1;
    char *ret = (char *) malloc(len);
    sprintf(ret, "%d. %s, %s-%s, %s, %s",
	    number, event, white, black, PGNResult(gameInfo->result), date);
    return ret;
}
Example #2
0
/* Return a non-static buffer with a games info.
 */
char *
PGNTags (GameInfo *gameInfo)
{
    size_t len;
    char *buf;
    char *p;

    // First calculate the needed buffer size.
    // Then we don't have to check the buffer size later.
    len = 12 + 11 + 11 + 12 + 12 + 12 + 25 + 1; // The first 7 tags
    if (gameInfo->event) len += strlen(gameInfo->event);
    if (gameInfo->site)  len += strlen(gameInfo->site);
    if (gameInfo->date)  len += strlen(gameInfo->date);
    if (gameInfo->round) len += strlen(gameInfo->round);
    if (gameInfo->white) len += strlen(gameInfo->white);
    if (gameInfo->black) len += strlen(gameInfo->black);
    if (gameInfo->whiteRating >= 0) len += 40;
    if (gameInfo->blackRating >= 0) len += 40;
    if (gameInfo->timeControl) len += strlen(gameInfo->timeControl) + 20;
    if (gameInfo->variant != VariantNormal) len += 50;
    if (gameInfo->extraTags) len += strlen(gameInfo->extraTags);

    buf = malloc(len);
    if (!buf)
	return 0;

    p = buf;
    p += sprintf(p, "[Event \"%s\"]\n", gameInfo->event ? gameInfo->event : "?");
    p += sprintf(p, "[Site \"%s\"]\n", gameInfo->site ? gameInfo->site : "?");
    p += sprintf(p, "[Date \"%s\"]\n", gameInfo->date ? gameInfo->date : "?");
    p += sprintf(p, "[Round \"%s\"]\n", gameInfo->round ? gameInfo->round : "-");
    p += sprintf(p, "[White \"%s\"]\n", gameInfo->white ? gameInfo->white : "?");
    p += sprintf(p, "[Black \"%s\"]\n", gameInfo->black ? gameInfo->black : "?");
    p += sprintf(p, "[Result \"%s\"]\n", PGNResult(gameInfo->result));
    if (gameInfo->whiteRating >= 0)
	p += sprintf(p, "[WhiteElo \"%d\"]\n", gameInfo->whiteRating);
    if (gameInfo->blackRating >= 0)
	p += sprintf(p, "[BlackElo \"%d\"]\n", gameInfo->blackRating);
    if (gameInfo->timeControl)
	p += sprintf(p, "[TimeControl \"%s\"]\n", gameInfo->timeControl);
    if (gameInfo->variant != VariantNormal)
        p += sprintf(p, "[Variant \"%s\"]\n", VariantName(gameInfo->variant));
    if (gameInfo->extraTags)
	strcpy(p, gameInfo->extraTags);
    return buf;
}
Example #3
0
char *
GameListLineFull (int number, GameInfo * gameInfo)
{
    char * event = gameInfo->event ? gameInfo->event : "?";
    char * site = gameInfo->site ? gameInfo->site : "?";
    char * white = gameInfo->white ? gameInfo->white : "?";
    char * black = gameInfo->black ? gameInfo->black : "?";
    char * round = gameInfo->round ? gameInfo->round : "?";
    char * date = gameInfo->date ? gameInfo->date : "?";
    char * oob = gameInfo->outOfBook ? gameInfo->outOfBook : "";
    char * reason = gameInfo->resultDetails ? gameInfo->resultDetails : "";

    int len = 64 + strlen(event) + strlen(site) + strlen(white) + strlen(black) + strlen(date) + strlen(oob) + strlen(reason);

    char *ret = (char *) malloc(len);

    sprintf(ret, "%d, \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"",
	number, event, site, round, white, black, PGNResult(gameInfo->result), reason, date, oob );

    return ret;
}
Example #4
0
/* Print game info */
void
PrintPGNTags (FILE *fp, GameInfo *gameInfo)
{
    char *p;
    fprintf(fp, "[Event \"%s\"]\n", gameInfo->event ? gameInfo->event : "?");
    fprintf(fp, "[Site \"%s\"]\n", gameInfo->site ? gameInfo->site : "?");
    fprintf(fp, "[Date \"%s\"]\n", gameInfo->date ? gameInfo->date : "?");
    fprintf(fp, "[Round \"%s\"]\n", gameInfo->round ? gameInfo->round : "-");
    fprintf(fp, "[White \"%s\"]\n", gameInfo->white ? gameInfo->white : "?");
    fprintf(fp, "[Black \"%s\"]\n", gameInfo->black ? gameInfo->black : "?");
    fprintf(fp, "[Result \"%s\"]\n", PGNResult(gameInfo->result));
    if (gameInfo->whiteRating >= 0)
	fprintf(fp, "[WhiteElo \"%d\"]\n", gameInfo->whiteRating);
    if (gameInfo->blackRating >= 0)
	fprintf(fp, "[BlackElo \"%d\"]\n", gameInfo->blackRating);
    if (gameInfo->timeControl)
	fprintf(fp, "[TimeControl \"%s\"]\n", gameInfo->timeControl);
    if (gameInfo->variant != VariantNormal)
        fprintf(fp, "[Variant \"%s\"]\n", VariantName(gameInfo->variant));
    if (*(p = CollectPieceDescriptors()))
        fprintf(fp, "[VariantMen \"%s\"]\n", p);
    if (gameInfo->extraTags)
	fputs(gameInfo->extraTags, fp);
}
Example #5
0
char *
GameListLine (int number, GameInfo * gameInfo)
{
    char buffer[2*MSG_SIZ];
    char * buf = buffer;
    char * glt = appData.gameListTags;

    buf += sprintf( buffer, "%d.", number );

    while( *glt != '\0' ) {
        *buf++ = ' ';

        switch( *glt ) {
        case GLT_EVENT:
            strncpy( buf, gameInfo->event ? gameInfo->event : "?", MAX_FIELD_LEN );
            break;
        case GLT_SITE:
            strncpy( buf, gameInfo->site ? gameInfo->site : "?", MAX_FIELD_LEN );
            break;
        case GLT_DATE:
            strncpy( buf, gameInfo->date ? gameInfo->date : "?", MAX_FIELD_LEN );
            break;
        case GLT_ROUND:
            strncpy( buf, gameInfo->round ? gameInfo->round : "?", MAX_FIELD_LEN );
            break;
        case GLT_PLAYERS:
            strncpy( buf, gameInfo->white ? gameInfo->white : "?", MAX_FIELD_LEN );
            buf[ MAX_FIELD_LEN-1 ] = '\0';
            buf += strlen( buf );
            *buf++ = '-';
            strncpy( buf, gameInfo->black ? gameInfo->black : "?", MAX_FIELD_LEN );
            break;
        case GLT_RESULT:
	    safeStrCpy( buf, PGNResult(gameInfo->result), 2*MSG_SIZ );
            break;
        case GLT_WHITE_ELO:
            if( gameInfo->whiteRating > 0 )
	      sprintf( buf,  "%d", gameInfo->whiteRating );
            else
	      safeStrCpy( buf, "?" , 2*MSG_SIZ);
            break;
        case GLT_BLACK_ELO:
            if( gameInfo->blackRating > 0 )
                sprintf( buf, "%d", gameInfo->blackRating );
            else
	      safeStrCpy( buf, "?" , 2*MSG_SIZ);
            break;
        case GLT_TIME_CONTROL:
            strncpy( buf, gameInfo->timeControl ? gameInfo->timeControl : "?", MAX_FIELD_LEN );
            break;
        case GLT_VARIANT:
            strncpy( buf, gameInfo->variantName ? gameInfo->variantName : VariantName(gameInfo->variant), MAX_FIELD_LEN );
//            strncpy( buf, VariantName(gameInfo->variant), MAX_FIELD_LEN );
            break;
        case GLT_OUT_OF_BOOK:
            strncpy( buf, gameInfo->outOfBook ? gameInfo->outOfBook : "?", MAX_FIELD_LEN );
            break;
        case GLT_RESULT_COMMENT:
            strncpy( buf, gameInfo->resultDetails ? gameInfo->resultDetails : "res?", MAX_FIELD_LEN );
            break;
        default:
            break;
        }

        buf[MAX_FIELD_LEN-1] = '\0';

        buf += strlen( buf );

        glt++;

        if( *glt != '\0' ) {
            *buf++ = ',';
        }
    }

    *buf = '\0';

    return strdup( buffer );
}