コード例 #1
0
ファイル: SamFile.cpp プロジェクト: rtchen/gotcloud
void SamFile::init(const char* filename, OpenType mode, SamFileHeader* header)
{
    init();
        
    resetFile();

    bool openStatus = true;
    if(mode == READ)
    {
        // open the file for read.
        openStatus = OpenForRead(filename, header);
    }
    else
    {
        // open the file for write.
        openStatus = OpenForWrite(filename, header);
    }
    if(!openStatus)
    {
        // Failed to open the file - print error and abort.
        fprintf(stderr, "%s\n", GetStatusMessage());
        std::cerr << "FAILURE - EXITING!!!" << std::endl;
        exit(-1);
    }
}
コード例 #2
0
ファイル: mitab_tabseamless.cpp プロジェクト: 0004c/node-gdal
/**********************************************************************
 *                   TABSeamless::Open()
 *
 * Open a seamless .TAB dataset and initialize the structures to be ready
 * to read features from it.
 *
 * Seamless .TAB files are composed of a main .TAB file in which each 
 * feature is the MBR of a base table.
 *
 * Set bTestOpenNoError=TRUE to silently return -1 with no error message
 * if the file cannot be opened.  This is intended to be used in the
 * context of a TestOpen() function.  The default value is FALSE which
 * means that an error is reported if the file cannot be opened.
 *
 * Returns 0 on success, -1 on error.
 **********************************************************************/
int TABSeamless::Open(const char *pszFname, const char *pszAccess,
                      GBool bTestOpenNoError /*= FALSE*/ )
{
    char nStatus = 0;
   
    if (m_poIndexTable)
    {
        CPLError(CE_Failure, CPLE_AssertionFailed,
                 "Open() failed: object already contains an open file");
        return -1;
    }

    /*-----------------------------------------------------------------
     * Validate access mode and call the right open method
     *----------------------------------------------------------------*/
    if (EQUALN(pszAccess, "r", 1))
    {
        m_eAccessMode = TABRead;
        nStatus = (char)OpenForRead(pszFname, bTestOpenNoError);
    }
    else
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                 "Open() failed: access mode \"%s\" not supported", pszAccess);
        return -1;
    }

    return nStatus;
}
コード例 #3
0
ファイル: settings.cpp プロジェクト: GunioRobot/LoopDub
SettingsFile::SettingsFile(char *filename)
{
    m_file = 0;
	m_bWrite = false;
    m_strSection[0] = 0;
    m_strParam[0] = 0;
    m_strSubParam[0] = 0;
    m_strValue[0] = 0;
	OpenForRead(filename);
}
コード例 #4
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
void ListBranches()
{
    assert (EditBoard != NULL);
    Edit_DrawBoard (*EditBoard);

    MoveList ml;
    EditBoard->GenMoves (ml);
    if ( ml.num == 0 || EditBoard->IsDefiniteDraw() )
    {
        printf ( ">>> At end of game.\n" );
        return;
    }

    LearnTree tree;
    if ( !OpenForRead(tree) )
        return;

    LearnBranch branch;
    int ordinal = 0;
    for ( INT32 offset = EditOffset[EditPly]; offset >= 0; ++ordinal )
    {
        printf ( "%3d.  ", ordinal );
        if ( !tree.read(offset,branch) )
        {
            printf ( "<!!! error reading branch at offset=%ld !!!>\n", long(offset) );
            break;
        }

        char temp [256];
        if ( ml.IsLegal(branch.move) )
            FormatChessMove ( *EditBoard, branch.move, temp );
        else
            IllegalMoveFormat ( branch.move, temp );

        if ( branch.move.source == 0 )
        {
            printf ( "[deleted]     %09ld\n", long(offset) );
        }
        else
        {
            printf ( "%c %-10s  %09ld: s=%-6d t=%-5.1lf WL=%-5d e=%-8ld a=%-4ld\n",
                     (branch.child == -1) ? ' ' : '*',
                     temp,
                     long(offset),
                     int(branch.move.score),
                     double(branch.timeAnalyzed) / 100.0,
                     long(branch.winsAndLosses),
                     long(branch.nodesEvaluated),
                     long(branch.numAccesses) );
        }

        offset = branch.sibling;
    }
}
コード例 #5
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_delete ( int argc, const char *argv[] )
{
    if ( argc != 2 )
    {
        printf ( "Missing ordinal argument.\n" );
        return 0;
    }

    int ord = 0;
    if ( sscanf(argv[1],"%d",&ord) != 1 || ord < 0 )
    {
        printf ( "Invalid ordinal '%s'\n", argv[1] );
        return 0;
    }

    LearnTree tree;
    if ( !OpenForRead(tree) )
        return 1;

    LearnBranch branch;

    int ordinal = 0;
    for ( INT32 offset = EditOffset[EditPly]; offset >= 0; ++ordinal )
    {
        if ( !tree.read(offset,branch) )
        {
            printf ( ">>> Error reading offset %ld !!!\n", long(offset) );
            return 0;
        }

        if ( ordinal == ord )
        {
            INT32 saveSibling = branch.sibling;
            memset ( &branch, 0, sizeof(LearnBranch) );
            branch.sibling = saveSibling;
            branch.child = -1;

            if ( !tree.write(offset,branch) )
                printf ( ">>> Error writing branch back to offset %ld.\n", long(offset) );
            else
                printf ( "*** Deleted ordinal=%d, offset=%ld.\n", ordinal, long(offset) );

            return 0;
        }

        offset = branch.sibling;
    }

    printf ( ">>> Error finding ordinal %d.\n", ord );
    return 0;
}
コード例 #6
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_jump ( int argc, const char *argv[] )
{
    assert ( EditBoard != NULL );

    if ( argc != 2 )
    {
        printf ( "Error: Missing offset argument\n" );
        return 0;
    }

    LearnTree tree;
    if ( !OpenForRead(tree) )
        return 1;

    long scanofs = 0;
    if ( sscanf(argv[1],"%ld",&scanofs) != 1 || scanofs < 0 )
    {
        printf ( "Invalid offset '%s'\n", argv[1] );
        return 0;
    }

    EditPly = 0;
    EditBoard->Init();

    int found = 0;

    try
    {
        found = FindPathToOffset (tree, 0, INT32(scanofs));
    }
    catch ( const char *message )
    {
        printf ( ">>> %s\n", message );
    }

    if ( found )
    {
        printf ( "Successfully found offset %ld\n", scanofs );
        ListBranches();
    }
    else
    {
        printf ( ">>> Could not find path to offset %ld\n", scanofs );
        printf ( ">>> Returned to root of tree.\n" );
    }

    return 0;
}
コード例 #7
0
ファイル: AudioFile.cpp プロジェクト: joshlong/libcd
DWORD CWAV::StartNormalizeAudioFile(CUString strFileName)
{
	m_pTmpWav = new CWAV();
	
	if (CDEX_OK != OpenForRead( strFileName + _W( ".wav" ) ) )
		return 0;
	

	if (CDEX_OK != m_pTmpWav->OpenForWrite(strFileName + AUDIO_FILE_NRMFILEEXT,
		m_wfInfo.samplerate,
		m_wBitsPerSample,
		m_wfInfo.channels))
		return 0;
	
	// everything ok, return number of bytes to convert
	return m_dwDataSize;
}
コード例 #8
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_parents ( int argc, const char *argv[] )
{
    assert ( EditBoard != NULL );

    if ( argc != 2 )
    {
        printf ( "Missing offset parameter\n" );
        return 0;
    }

    long scanTarget = 0;
    if ( sscanf(argv[1],"%ld",&scanTarget) != 1 || scanTarget < 0 )
    {
        printf ( "Invalid target offset %ld\n", scanTarget );
        return 0;
    }

    INT32 target = INT32(scanTarget);

    LearnTree tree;
    if ( !OpenForRead(tree) )
        return 1;

    int numMatches = 0;
    LearnBranch branch;
    INT32 numNodes = tree.numNodes();
    for ( INT32 offset = 0; offset < numNodes; ++offset )
    {
        if ( !tree.read(offset,branch) )
        {
            printf ( ">>> Error reading offset %ld\n", long(offset) );
            return 0;
        }

        if ( branch.child == target )
            printf ( "#%d:  parent  offset = %ld\n", ++numMatches, long(offset) );

        if ( branch.sibling == target )
            printf ( "#%d:  sibling offset = %ld\n", ++numMatches, long(offset) );
    }

    return 0;
}
コード例 #9
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_integrity ( int argc, const char *argv[] )
{
    LearnTree tree;
    if ( !OpenForRead(tree) )
        return 1;

    lprintf ( ">>> Starting depth-first integrity check at offset %ld...\n",
              long(EditOffset[EditPly]) );

    PerformIntegrityCheck ( tree, EditOffset[EditPly] );

    lprintf ( ">>> Second pass: linear check...\n" );
    INT32 numNodes = tree.numNodes();
    LearnBranch branch;
    for ( INT32 offset = 0; offset < numNodes; ++offset )
    {
        if ( !tree.read(offset,branch) )
        {
            lprintf ( ">>> Error reading offset %ld\n", long(offset) );
            return 0;
        }

        if ( branch.reserved[0] > 0 )
        {
            if ( branch.reserved[0] > 1 )
            {
                lprintf ( ">>> Branch at offset %ld has %ld referents!\n",
                          long(offset),
                          long(branch.reserved[0]) );
            }

            branch.reserved[0] = 0;
            if ( !tree.write(offset,branch) )
            {
                lprintf ( ">>> Error writing back branch %ld\n", long(offset) );
                return 0;
            }
        }
    }

    return 0;
}
コード例 #10
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_move ( int argc, const char *argv[] )
{
    assert (EditBoard != NULL);
    assert (UnmoveTable != NULL);

    int ply = EditBoard->GetCurrentPlyNumber();
    assert ( ply == EditPly );

    MoveList ml;
    EditBoard->GenMoves (ml);
    if ( ml.num == 0 || EditBoard->IsDefiniteDraw() )
    {
        printf ( ">>> At end of game.\n" );
        return 0;
    }

    if ( argc != 2 )
    {
        fprintf ( stderr, "Use:  move Ordinal\n" );
        return 0;
    }

    int seekord = 0;
    if ( sscanf(argv[1],"%d",&seekord) != 1 || seekord < 0 )
    {
        fprintf ( stderr, "Invalid integer argument '%s'\n", argv[1] );
        return 0;
    }

    if ( EditOffset[EditPly] == -1 )
    {
        printf ( ">>> At leaf of experience tree.\n" );
        return 0;
    }

    LearnTree tree;
    if ( !OpenForRead(tree) )
        return 1;

    LearnBranch branch;

    int ordinal = 0;
    for ( INT32 offset = EditOffset[EditPly]; offset >= 0; ++ordinal )
    {
        if ( !tree.read(offset,branch) )
        {
            fprintf ( stderr, "!!! Error reading offset %ld !!!\n", long(offset) );
            return 0;
        }

        if ( seekord == ordinal )
        {
            if ( ml.IsLegal(branch.move) )
            {
                MoveTable[EditPly] = branch.move;
                EditBoard->MakeMove ( branch.move, UnmoveTable[EditPly] );
                EditOffset[++EditPly] = branch.child;
                ListBranches();
            }
            else
            {
                char temp [64];
                IllegalMoveFormat ( branch.move, temp );
                fprintf ( stderr, "!!! Error: illegal move %s at offset %ld\n",
                          temp,
                          long(offset) );
            }
            break;
        }

        offset = branch.sibling;
    }

    return 0;
}
コード例 #11
0
ファイル: edittree.cpp プロジェクト: cosinekitty/chenard
int ETEC_import ( int argc, const char *argv[] )
{
    if (argc != 2)
    {
        printf("Missing filespec parameter.\n");
        return 1;
    }

    LearnTree tree;
    if ( OpenForRead(tree) )       // actually, this opens existing file for modification
    {
        try
        {
            char            dir [512];
            char            fullpath [512];
            int             numfiles = 0;
            _finddata_t     finfo;

            if (ExtractDir (dir, sizeof(dir), argv[1]))
            {
                intptr_t handle = _findfirst (argv[1], &finfo);
                if (handle != -1)
                {
                    do
                    {
                        if (!(finfo.attrib & _A_SUBDIR))
                        {
                            if (bscat (fullpath, sizeof(fullpath), dir, finfo.name))
                            {
                                if (ImportGameFile (tree, fullpath))
                                {
                                    ++numfiles;
                                }
                            }
                            else
                            {
                                printf("!!! ERROR forming full path !!!\n");
                                break;
                            }
                        }
                    }
                    while (0 == _findnext(handle,&finfo));
                    _findclose (handle);
                }

                if (numfiles == 0)
                {
                    printf ("!!! ERROR importing files using '%s' as filespec.\n", argv[1]);
                }
                else
                {
                    printf ("Imported %d game files.\n", numfiles);
                }
            }
            else
            {
                printf("!!! ERROR extracting dir from filespec.\n");
            }
        }
        catch (const char *message)
        {
            printf (">>> %s\n", message);
        }
    }

    return 0;
}