Пример #1
0
static void openFiles( void )
{
    int objhdl;

    objhdl = open( ObjFileName, O_RDONLY | O_BINARY );
    if( objhdl != -1 ) {
        if( ListFileName != NULL ) {
            OutputDest = open( ListFileName, O_WRONLY | O_CREAT | O_TRUNC, PMODE_RW );
            if( OutputDest == -1 )
                openError( ListFileName );
            ChangePrintDest( OutputDest );
        }
        objFileLen = filelength( objhdl );
        if( objFileLen == 0 ) {
            LeaveProgram( RC_OKAY, WHERE_OBJ_ZERO_LEN );
        }
        objFileBuf = MemAlloc( objFileLen );
        objFilePos = 0;
        if( posix_read( objhdl, objFileBuf, objFileLen ) == -1 ) {
            openError( ObjFileName );
        }
        close( objhdl );
    } else {
        openError( ObjFileName );
    }
}
Пример #2
0
MStatus dagPoseInfo::parseArgs( const MArgList& args )
//
// There is one mandatory flag: -f/-file <filename>
//
{
    MStatus     	stat;
    MString     	arg;
    MString			fileName;
    const MString	fileFlag			("-f");
    const MString	fileFlagLong		("-file");

    // Parse the arguments.
    for ( unsigned int i = 0; i < args.length(); i++ ) {
        arg = args.asString( i, &stat );
        if (!stat)
            continue;

        if ( arg == fileFlag || arg == fileFlagLong ) {
            // get the file name
            //
            if (i == args.length()-1) {
                arg += ": must specify a file name";
                displayError(arg);
                return MS::kFailure;
            }
            i++;
            args.get(i, fileName);
        }
        else {
            arg += ": unknown argument";
            displayError(arg);
            return MS::kFailure;
        }
    }

    file = fopen(fileName.asChar(),"wb");
    if (!file) {
        MString openError("Could not open: ");
        openError += fileName;
        displayError(openError);
        stat = MS::kFailure;
    }

    return stat;
}
Пример #3
0
void SQLThread::run()
{
    bool haveError = false;
    int tryCnt = 3;
    while(true)
    {
        while(rarelyUsed.empty() && frequentUsed.empty())
        {
            usedSemaphore.acquire();
            if(exitFlag)
            {
                rarelyUsed.clear();
                frequentUsed.clear();
                return;
            }
        }

        if(!rarelyUsed.empty())
        {
            //连接数据库
            if( rarelyUsed.front().task == ConnectDb)
            {
                 sql.setDb("test", rarelyUsed.front().user,
                           rarelyUsed.front().passwd);
                 if(!sql.openDb())
                 {
                    emit openError("Can not open the MYSQL database, please cheack...");
                    if(++tryCnt <= 3)
                    {
                        connectDb("test", rarelyUsed.front().user,
                                  rarelyUsed.front().passwd);
                    }
                    else
                        haveError = true;
                    break;
                 }

                 if(!sql.createDb(rarelyUsed.front().name))
                 {
                    emit openError("Create database failure....");
                    break;
                 }

                 if(!sql.changeDb(rarelyUsed.front().name))
                 {
                     emit openError("Change database failure....");
                     break;
                 }

            }
            else if( rarelyUsed.front().task == CreatTable)
            {
                if(! sql.createTable(rarelyUsed.front().name))
                {
                    emit openError("Create table failure....");
                    break;
                }
            }
             else if( rarelyUsed.front().task == SelectData)
            {

                emit getResult(sql.selectTable(rarelyUsed.front().name, cnt), cnt);
            }
            rarelyUsed.pop_front();
            freeSemaphore.release();
            continue;
        }
        //处理第二队列
        if(!frequentUsed.empty())
        {
            sql.insertData(frequentUsed.front().table,
                           frequentUsed.front().id, frequentUsed.front().data);
            frequentUsed.pop_front();
            freeSemaphore.release();
        }
    }
}