Esempio n. 1
0
string Sam::cigar_seq2cigar() {

	string cigar;
	if ( _cigar_seq.empty() ) return "*";

//cerr << "_cigar_seq : " << _cigar_seq << endl;
	int num(0);
	char type;
	for ( size_t i(0); i < _cigar_seq.length(); ++i ){
		
		if ( num > 0 ) {

			if ( type == _cigar_seq[i] ) {
				++num;
			} else {
				cigar += itoa( num ) + char2str( type );
//cerr << "*cigar : " << cigar << endl;
				type   = _cigar_seq[i];
				num    = 1;
			}
		} else {
			++num;
			type = _cigar_seq[i];
		}
	}
	cigar += itoa( num ) + char2str( type );
//cerr << "*cigar : " << cigar << endl;
//cerr << "Test cigar_seq2cigar: \ncigar_seq: " << _cigar_seq << "\ncigar    : " << cigar << endl; exit(1);
	return cigar;
}
Esempio n. 2
0
std::string HalfMove::san_from(const Board& board) const {
    Piece::Letter letter = board.letter(from());
    if (letter == Piece::PAWN && board.test_takes(*this)) {
        return char2str(from().file_char());
    }
    bool alt = false, alt_file = false, alt_rank = false;
    THECHESS_SQUARE_FOREACH (square) {
        HalfMove alt_move(square, to(), board);
        if (board.letter(square) == letter && square != from() &&
                board.test_move(alt_move) && !board.test_castling(alt_move)) {
            alt = true;
            if (square.file() == from().file()) {
                alt_file = true;
            }
            if (square.rank() == from().rank()) {
                alt_rank = true;
            }
        }
    }
    if (alt_file && alt_rank) {
        return from().str();
    } else if (alt_file) {
        return char2str(from().rank_char());
    } else if (alt) {
        return char2str(from().file_char());
    }
    return "";
}
Esempio n. 3
0
string join ( const char *delim, list<char> &goven ){

	string strLine;
    strLine.clear();

    if ( goven.empty() ) return strLine;
	list< char >::iterator iter = goven.begin();
    strLine = char2str( *iter );
	for ( ++iter; iter != goven.end(); ++iter ) strLine += ( delim + char2str( *iter ) );

    return strLine;
}
Esempio n. 4
0
string join ( const char *delim, deque<char> &goven ) {

	string strLine;
    strLine.clear();

    if ( goven.empty() ) return strLine;
    strLine.append( char2str(goven[0]) );
    for ( size_t i(1); i < goven.size(); ++i ) {

        strLine.append ( delim + char2str( goven[i] ) );
    }

    return strLine;
}
Esempio n. 5
0
int Command::getHeader()
{
	// Max Number of headers

	
	char buf[512];
	std::vector<std::string> bufList;
	
	for (int i = 0; i < 32; i++)
	{

		fgets(buf, 512, this->in);

		if (!strcmp(buf, "\n")) {
			//end of header
			break;
		}

#ifdef DEBUG
		std::cout << buf << std::endl;
#endif
		
		
		bufList.push_back(char2str(buf));
	}

	
	
	this->header = this->parseHeader(bufList);
	
	return 0;
	
}
Esempio n. 6
0
BOOL file_listnext(FLISTH hdl, FLINFO *fli) {

	FLHDL		flhdl;
	ItemCount	count;
	OSStatus	r;
	UTCDateTime	*dt;

	flhdl = (FLHDL)hdl;
	if ((flhdl == NULL) || (flhdl->eoff)) {
		goto ffn_err;
	}
	r = FSGetCatalogInfoBulk(flhdl->fsi, 1, &count, NULL,
						kFSCatInfoNodeFlags | kFSCatInfoDataSizes |
						kFSCatInfoAllDates,
						&flhdl->fsci, NULL, NULL, &flhdl->name);
	if (r != noErr) {
		flhdl->eoff = TRUE;
		if (r != errFSNoMoreItems) {
			goto ffn_err;
		}
	}
	if (count != 1) {
		flhdl->eoff = TRUE;
		goto ffn_err;
	}
	if (fli) {
		fli->caps = FLICAPS_SIZE | FLICAPS_ATTR | FLICAPS_DATE | FLICAPS_TIME;
		if (flhdl->fsci.nodeFlags & kFSNodeIsDirectoryMask) {
			fli->attr = FILEATTR_DIRECTORY;
			fli->size = 0;
			dt = &flhdl->fsci.createDate;
		}
		else {
			fli->attr = FILEATTR_ARCHIVE;
			fli->size = (UINT32)flhdl->fsci.dataLogicalSize;
			dt = &flhdl->fsci.contentModDate;
		}
		if (flhdl->fsci.nodeFlags & kFSNodeLockedMask) {
			fli->attr |= FILEATTR_READONLY;
		}
		cnvdatetime(dt, &fli->date, &fli->time);
		char2str(fli->path, sizeof(fli->path),
								flhdl->name.unicode, flhdl->name.length);
	}
	return(SUCCESS);

ffn_err:
	return(FAILURE);
}
Esempio n. 7
0
BOOL getLongFileName(char *dst, const char *path) {

	FSSpec			fss;
	Str255			fname;
	FSRef			fref;
	HFSUniStr255	name;

	if (*path == '\0') {
		return(false);
	}
	mkstr255(fname, path);
	FSMakeFSSpec(0, 0, fname, &fss);
	FSpMakeFSRef(&fss, &fref);
	if (FSGetCatalogInfo(&fref, kFSCatInfoNone, NULL, &name, NULL, NULL)
																!= noErr) {
		return(false);
	}
	char2str(dst, 512, name.unicode, name.length);
	if (!dst) {
		return(false);
	}
	return(true);
}
Esempio n. 8
0
static void check_char(int ch, int exp) {
    char s0[16], s1[16];
    if (exp == ch) return;
    str_fmt_exception(ERR_JSON_SYNTAX, "Expected %s, got %s",
        char2str(exp, s0), char2str(ch, s1));
}