示例#1
0
文件: respk.cpp 项目: preet/respk
bool GenerateDataOutputFromFile(std::string const &res_name,
                                std::string const &json_file_path,
                                std::string const &res_file_path,
                                std::string &output)
{
    // Try a relative path first
    std::string const json_fpath_only = GetFilePathOnly(json_file_path);

    std::ifstream res_file(
                json_fpath_only+res_file_path,
                std::ios_base::in | std::ios_base::binary);

    if(!res_file) {
        // Couldn't find the resource file. Try the
        // given file path directly
        res_file.close();
        res_file.open(res_file_path,
                      std::ios_base::in | std::ios_base::binary);

        if(!res_file) {
            std::cout << "respk: ERROR: Could not open resource file: " << std::endl;
            std::cout << "Tried: " << std::endl;
            std::cout << res_file_path << " and " << std::endl;
            std::cout << (json_fpath_only+res_file_path) << std::endl;
            return false;
        }
    }

    std::istreambuf_iterator<char> res_file_it(res_file);
    std::istreambuf_iterator<char> res_file_eos;
    std::vector<char> list_bytes(res_file_it,res_file_eos);

    output.clear();
    output.append("\n");
    output.append("// ============================================================= // \n\n");
    output.append("extern std::vector<unsigned char> const ");
    output.append(res_name);
    output.append(" =\n");
    output.append("{\n    ");

    unsigned char* list_ubytes =
            reinterpret_cast<unsigned char*>(&(list_bytes[0]));

    // output all the bytes
    for(size_t i=0; i < list_bytes.size()-1; i++) {
        output.append(g_lut_ubyte_to_hex[list_ubytes[i]] + ",");
        if((i+1)%16==0) {
            output.append("\n    ");
        }
    }
    // last byte
    output.append(g_lut_ubyte_to_hex[list_ubytes[list_bytes.size()-1]]);
    output.append("\n};\n");

    return true;
}
示例#2
0
int DeviceSettings::writeDnsList()
{
    QFile res_file( RESOLV_CONF ); // resolv.conf

    if (  !res_file.exists() || !res_file.open(  IO_WriteOnly|IO_Truncate ) )
        return -1;

    QTextStream str( &res_file );
    unsigned int num = dnsListBox->count();
    for ( unsigned int row = 0; row < num; ++row ) {
        QString line = "nameserver " + dnsListBox->text( row );
        str << "nameserver " + dnsListBox->text( row ) + "\n";
    }

    res_file.close();

    return 0;
}
示例#3
0
void benchmark(const bopt_params& par, const std::string& name)
{
    auto t1 = std::chrono::steady_clock::now();
    Benchmark<Function> benchmark(par);
    vectord result(Function::dim_in);
    benchmark.optimize(result);
    auto time_running = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - t1).count();
    std::cout.precision(17);
    std::cout << std::endl;
    auto best = benchmark.evaluateSample(result);
    double accuracy = benchmark.accuracy(best);

    std::cout << name << std::endl;
    std::cout << "Result: " << std::fixed << result << " -> " << best << std::endl;
    std::cout << "Smallest difference: " << accuracy << std::endl;
    std::cout << "Time running: " << time_running << "ms" << std::endl
              << std::endl;

    std::ofstream res_file(name + ".dat", std::ios_base::out | std::ios_base::app);
    res_file.precision(17);
    res_file << std::fixed << accuracy << " " << time_running << std::endl;
}
示例#4
0
QStringList DeviceSettings::getDnsList()
{
    QStringList dnsList;
    QFile res_file( RESOLV_CONF ); // resolv.conf
    QString line;

    if (  !res_file.exists() || !res_file.open(  IO_ReadOnly ) )
        return QStringList();

    while ( -1 != res_file.readLine( line, 1024 ) ) {
        line = line.stripWhiteSpace();
        if ( line.startsWith( "nameserver" ) ) {
            int index = rx->search( line );
            if ( index >= 0 ) {
                dnsList.append( rx->cap() );
            }
        }
    }

    res_file.close();
    return dnsList;
}
示例#5
0
文件: GENER.c 项目: doniexun/OrangeC
void valx(void) {
    int i;
    FILE *fp;
    char *c0 = "C0DOS.OBJ";
    char *c0d= "C0DOSD.OBJ";
    char *cl = "CLDOS.LIB";
    char *ci = NULL;
    char *dosx = NULL;
   char *lnk_op = "/NCI /32";


    if ( ( obj_file_cnt() + lib_file_cnt() ) > 0 ) {
        int sys = get_dosex();
        switch ( sys ) {
            case OPT_W32CON:
                c0d = c0 = "C0xwin.obj"; cl = "CLWIN.LIB"; ci = "CLIMP.LIB"; 
                lnk_op = "/NCI /PE";
                break;
            case OPT_W32GUI:
                c0d = c0 = "C0win.obj"; cl = "CLWIN.LIB"; ci = "CLIMP.LIB"; 
                lnk_op = "/NCI /PE /WIN";
                break;
            case OPT_W32DLL: 
                c0d = c0 = "C0dwin.obj"; cl = "CLWIN.LIB"; ci = "CLIMP.LIB";
                lnk_op = "/NCI /PE /BDL";
                break;
         case OPT_DOS32A:
            c0d = "c0doswd.obj" ;
            c0 = "c0dosw.obj" ;
            lnk_op = "/NCI /LE" ;
            dosx = "stub32a.exe" ;
            break ;
            case OPT_PMODEW:
                c0d = "c0doswd.obj" ;
                c0 = "c0dosw.obj" ;
                lnk_op = "/NCI /LE" ;
                dosx = "pmodew.exe"; 
                break;
            case OPT_DOS4G:	
                c0d = "c0doswd.obj" ;
                c0 = "c0dosw.obj" ;
                lnk_op = "/NCI /LE" ;
                dosx = "4gstub.exe"; 
                break;
            case OPT_WDOSX:	
                c0d = "c0doswd.obj" ;
                c0 = "c0dosw.obj" ;
                lnk_op = "/NCI /LE" ;
                dosx = "wdosxle.exe"; 
                break;
            case OPT_ZRDX:	
                c0d = "c0doswd.obj" ;
                c0 = "c0dosw.obj" ;
                lnk_op = "/NCI /LE" ;
                dosx = "zrdx.exe"; 
                break;
            case OPT_CAUSEWAY:	
                c0d = "c0doswd.obj" ;
                c0 = "c0dosw.obj" ;
                lnk_op = "/NCI /LE" ;
                dosx = "cwstub.exe"; 
                break;
            case OPT_HXDOS:
                c0d = c0 = "C0xwin.obj"; 
                cl = "CLWIN.LIB"; 
                ci = "CLIMP.LIB"; 
                lnk_op = "/NCI /PE";
                dosx = "dpmist32.bin";
                break;
            case OPT_WHXDOS:
                c0d = c0 = "C0doswhx.obj"; 
                lnk_op = "/NCI /PE";
                dosx = "hdld32.bin";
                break;
            case OPT_D3X:
                c0d = "c0doswd.obj";
                c0 = "c0dos.obj";
                lnk_op = "/NCI /LE" ;
                dosx = "d3xw.exe"; 
                break;
            default:
                fprintf( stderr, "VALX use only with PMODE!\n" );
            case OPT_PMODE:
                break;
        }
        fp = response( RESPONSE );
        fprintf( fp, "-NOCA -USE32 %s ",
            get_option(OPT_MAPFILE) ? "-MAP" : "-NOMAP" );	
        if ( lnk_op )
            fprintf( fp, "%s ", lnk_op);
        if (dosx)
            fprintf(fp, "-STB:(%s\\%s) ", get_syslib_path(), dosx);
        if (! get_option(OPT_NODEFLIB) ) {
            if ( get_option(OPT_DEBUG) )
            fprintf(fp,"\"%s\\%s\"", get_syslib_path(), c0d );
            else
            fprintf(fp,"\"%s\\%s\"", get_syslib_path(), c0 );
        }
        for ( i = 0; i < obj_file_cnt(); i++ )
            fprintf( fp, " %s", obj_file(i) );
        fprintf( fp, ",%s,%s,",  
            get_exe_name(),
            get_option( OPT_MAPFILE) ? get_exe_name() : "NUL"
        );
        if (! get_option(OPT_NODEFLIB) )
         fprintf(fp,"\"%s\\%s\"", get_syslib_path(), cl );
        if (ci)
         fprintf(fp," \"%s\\%s\"", get_syslib_path(), ci );
        for ( i = 0; i < lib_file_cnt(); i++ )
            fprintf( fp, " %s", lib_file(i) );
        fprintf( fp, "\n" );
        for ( i = 0; i < res_file_cnt(); i++ )
            fprintf( fp, " %s", res_file(i) );
        fprintf( fp, "\n\n" );
        fclose(fp);
        exec("VALX", "@" RESPONSE );
        if (! get_option(OPT_KEEPRSP) )
            unlink( RESPONSE );
          if ( !get_option(OPT_KEEPGEN) )
        {
            del_res_tmpfiles();
        }
        if (sys == OPT_WHXDOS)
        {
            exec("PATCHPE", get_exe_name());
        }
    }
}
示例#6
0
文件: GENER.c 项目: doniexun/OrangeC
void olink(void) {
    int i;
    FILE *fp;
    char *c0 = "c0pm.o";
    char *c0d= "c0pmd.o";
    char *cl = "cldos.l";
    char *ci = NULL;
   char *lnk_op = "/T:PM";


    if ( ( obj_file_cnt() + lib_file_cnt() ) > 0 ) {
        int sys = get_dosex();
        switch ( sys ) {
            case OPT_W32CON:
                c0d = c0 = "c0xpe.o"; cl = "clwin.l"; ci = "climp.l"; 
                lnk_op = "/T:CON32";
                break;
            case OPT_W32GUI:
                c0d = c0 = "c0pe.o"; cl = "clwin.l"; ci = "climp.l"; 
                lnk_op = "/T:GUI32";
                break;
            case OPT_W32DLL: 
                c0d = c0 = "c0dpe.o"; cl = "clwin.l"; ci = "climp.l";
                lnk_op = "/T:DLL32";
                break;
         case OPT_DOS32A:
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;sstub32a.exe" ;
            break ;
            case OPT_PMODEW:
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;spmodew.exe" ;
                break;
            case OPT_DOS4G:	
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;s4gstub.exe" ;
                break;
            case OPT_WDOSX:	
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;swdosxle.exe" ;
                break;
            case OPT_ZRDX:	
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;szrdx.exe" ;
                break;
            case OPT_CAUSEWAY:	
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;scwstub.exe" ;
                break;
            case OPT_HXDOS:
                c0d = c0 = "c0xpe.o"; 
                cl = "CLWIN.L"; 
                ci = "CLIMP.L"; 
                lnk_op = "/T:CON32;sdpmist32.bin";
                break;
            case OPT_WHXDOS:
                c0d = "c0hxd.o";
                c0 = "c0hx.o"; 
                lnk_op = "/T:CON32;shdld32.bin /DOBJECTALIGN=10000";
                break;
            case OPT_D3X:
            c0d = "c0watd.o" ;
            c0 = "c0wat.o" ;
            lnk_op = "/T:DOS32;sd3xw.exe" ;
                break;
            default:
                fprintf( stderr, "VALX use only with PMODE!\n" );
            case OPT_PMODE:
                break;
        }
        fp = response( RESPONSE );
        fprintf( fp, "-c%s",
            get_option(OPT_MAPFILE) ? " -m" : "" );	
        fprintf( fp, " -o%s%s", get_exe_name(),	get_option( OPT_MAPFILE) ? get_exe_name() : "");
        if ( lnk_op )
        {
            fprintf( fp, " %s", lnk_op);
        }
        if (! get_option(OPT_NODEFLIB) ) {
            if ( get_option(OPT_DEBUG) )
            fprintf(fp," \"%s\\%s\"", get_syslib_path(), c0d );
            else
            fprintf(fp," \"%s\\%s\"", get_syslib_path(), c0 );
        }
        for ( i = 0; i < obj_file_cnt(); i++ )
            fprintf( fp, " %s", obj_file(i) );
        for ( i = 0; i < lib_file_cnt(); i++ )
            fprintf( fp, " %s", lib_file(i) );
        if (! get_option(OPT_NODEFLIB) )
        {
            if (cl)
            {
                 fprintf(fp," \"%s\\%s\"", get_syslib_path(), cl );
            }
            if (ci)
            {
                 fprintf(fp," \"%s\\%s\"", get_syslib_path(), ci );
            }
        }
        for ( i = 0; i < res_file_cnt(); i++ )
            fprintf( fp, " %s", res_file(i) );
        fclose(fp);
        exec("olink", "@" RESPONSE );
        if (! get_option(OPT_KEEPRSP) )
            unlink( RESPONSE );
          if ( !get_option(OPT_KEEPGEN) )
        {
            del_res_tmpfiles();
        }
        if (sys == OPT_WHXDOS)
        {
            exec("PATCHPE", get_exe_name());
        }
    }
}