Exemple #1
0
static void cellToQString( const UCell* val, QString& str )
{
    switch( ur_type(val) )
    {
        case UT_NONE:
            str.clear();
            break;

        case UT_CHAR:
            str = QChar( ur_int(val) );
            break;

        case UT_INT:
            str.setNum( ur_int(val) );
            break;

        case UT_DECIMAL:
            str.setNum( ur_decimal(val) );
            break;

        case UT_BIGNUM:
            str.setNum( bignum_l(val) );
            break;

        case UT_STRING:
        case UT_FILE:
        {
            USeriesIter si;
            int len;
            ur_seriesSlice( UT, &si, val );
            len = si.end - si.it;
            switch( si.buf->form )
            {
                case UR_ENC_LATIN1:
                    str = QString::fromLatin1( si.buf->ptr.c + si.it, len );
                    break;
                case UR_ENC_UTF8:
                    str = QString::fromUtf8( si.buf->ptr.c + si.it, len );
                    break;
                case UR_ENC_UCS2:
                    str = QString::fromUtf16( si.buf->ptr.u16 + si.it, len );
                    break;
            }
        }
            break;

        default:
        {
            UBuffer buf;
            ur_strInit( &buf, UR_ENC_LATIN1, 0 );
            ur_toStr( UT, val, &buf, 0 );
            str = QString::fromLatin1( buf.ptr.c, buf.used );
            ur_strFree( &buf );
        }
            break;
    }
}
Exemple #2
0
int main( int argc, char** argv )
{
    char cmd[ 2048 ];
    BoronApp app( argc, argv );
    UThread* ut;
    UBuffer rstr;
    int fileN = 0;
    int ret = 0;


    {
    UEnvParameters param;
    ut = boron_makeEnv( boron_envParam(&param) );
    }
    if( ! ut )
    {
        printf( "boron_makeEnv failed\n" );
        return -1;
    }

    ur_freezeEnv( ut );
    boron_initQt( ut );


    if( argc > 1 )
    {
        int i;
        char* arg;

        for( i = 1; i < argc; ++i )
        {
            arg = argv[i];
            if( arg[0] == '-' )
            {
                switch( arg[1] )
                {
                    case 's':
                        //ur_disable( env, UR_ENV_SECURE );
                        break;

                    case 'h':
                        usage( argv[0] );
                        return 0;
                }
            }
            else
            {
                fileN = i;
                break;
            }
        }
    }

    ur_strInit( &rstr, UR_ENC_UTF8, 0 );

#ifdef _WIN32
    {
    WORD wsver;
    WSADATA wsdata;
    wsver = MAKEWORD( 2, 2 );
    WSAStartup( wsver, &wsdata );
    }
#endif

    if( fileN )
    {
        char* pos;

        pos = cmd;
        cmd[ sizeof(cmd) - 1 ] = -1;

        // Create args block for any command line parameters.
        if( (argc - fileN) > 1 )
        {
            int i;
            pos = str_copy( pos, "args: [" );
            for( i = fileN + 1; i < argc; ++i )
            {
                *pos++ = '"';
                pos = str_copy( pos, argv[i] );
                *pos++ = '"';
                *pos++ = ' ';
            }
            *pos++ = ']';
        }
        else
        {
            pos = str_copy( pos, "args: none " );
        }

        pos = str_copy( pos, "do load {" );
        pos = str_copy( pos, argv[fileN] );
        *pos++ = '}';

        assert( cmd[ sizeof(cmd) - 1 ] == -1 && "cmd buffer overflow" );

        if( ! boron_evalUtf8( ut, cmd, pos - cmd ) )
        {
            UCell* ex = ur_exception( ut );
            if( ur_is(ex, UT_ERROR) )
            {
                OPEN_CONSOLE
                reportError( ut, ex, &rstr );
                goto prompt;
            }
            else if( ur_is(ex, UT_WORD) )
            {
                switch( ur_atom(ex) ) 
                {
                    case UR_ATOM_QUIT:
                        goto quit;

                    case UR_ATOM_HALT:
                        goto prompt;
                        break;
                }
            }
        }
    }
    else
    {
        OPEN_CONSOLE
        printf( APPNAME " %s (%s)\n", UR_VERSION_STR, __DATE__ );

prompt:

        while( 1 )
        {
            printf( ")> " );
            fflush( stdout );   /* Required on Windows. */
            fgets( cmd, sizeof(cmd), stdin ); 
#if 0
            {
                char* cp = cmd;
                while( *cp != '\n' )
                    printf( " %d", (int) *cp++ );
                printf( "\n" );
            }
#endif

            if( cmd[0] == ESC )
            {
                // Up   27 91 65
                // Down 27 91 66
                printf( "\n" );
            }
            else if( cmd[0] != '\n' )
            {
#if 0
                if( cmd[0] == 'q' )
                    goto quit;
#endif
                UCell* val = boron_evalUtf8( ut, cmd, -1 );
                if( val )
                {
                    if( ur_is(val, UT_UNSET) ||
                        ur_is(val, UT_CONTEXT) )
                        goto prompt;

                    rstr.used = 0;
                    ur_toStr( ut, val, &rstr, 0 );
                    if( rstr.ptr.c )
                    {
                        ur_strTermNull( &rstr );
                        if( rstr.used > PRINT_MAX )
                        {
                            char* cp = str_copy( rstr.ptr.c + PRINT_MAX - 4,
                                                 "..." );
                            *cp = '\0';
                        }
                        printf( "== %s\n", rstr.ptr.c );
                    }
                }
                else
                {
                    UCell* ex = ur_exception( ut );
                    if( ur_is(ex, UT_ERROR) )
                    {
                        reportError( ut, ex, &rstr );
                    }
                    else if( ur_is(ex, UT_WORD) )
                    {
                        switch( ur_atom(ex) ) 
                        {
                            case UR_ATOM_QUIT:
                                goto quit;

                            case UR_ATOM_HALT:
                                printf( "**halt\n" );
                                break;

                            default:
                                printf( "**unhandled excepetion %s\n",
                                        ur_atomCStr(ut,ur_atom(ex)) );
                                break;
                        }
                    }
                    boron_reset( ut );
                }
            }
        }
    }

quit:

    ur_strFree( &rstr );
    boron_freeQt();
    boron_freeEnv( ut );

#ifdef _WIN32
    WSACleanup();
#endif

    return ret;
}
Exemple #3
0
static void itemview_layout( GWidget* wp )
{
    UCell* rc;
    /*
    UCell* it;
    UBuffer* blk;
    int row, rowCount;
    int col, colCount;
    int itemY;
    */
    UCell* style = glEnv.guiStyle;
    UThread* ut  = glEnv.guiUT;
    //UIndex strN = 0;
    EX_PTR;
    /*
    DPCompiler* save;
    DPCompiler dpc;
    */


#ifdef ITEM_HEADER
    if( ep->headerBlkN <= 0 )
        return;
#endif
    if( ep->dataBlkN <= 0 )
        return;

    itemview_calcItemHeight( ut, ep );

    //itemY = wp->area.y + wp->area.h - ep->itemHeight;

    if( ep->use_color == -1 )
    {
        rc = style + CI_STYLE_WIDGET_SH;
        if( ur_is(rc, UT_CONTEXT) )
        {
            const Shader* shad = shaderContext( ut, rc, 0 );
            if( shad )
            {
                ep->use_color = glGetUniformLocation( shad->program,
                                                      "use_color" );
                //printf( "KR use_color %d\n", ep->use_color );
            }
        }
    }


#if 0
    // Compile draw list for visible items.

    save = ur_beginDP( &dpc );
    if( save )
        dpc.shaderProg = save->shaderProg;


    // Header

    blk = ur_buffer( ep->headerBlkN );
    it  = blk->ptr.cell;
    colCount = ep->colCount = blk->used;

    for( col = 0; col < colCount; ++col, ++it )
    {
        rc = style + CI_STYLE_LABEL;
        if( ur_is(it, UT_STRING) )
        {
            *rc = *it;
        }

        rc = style + CI_STYLE_AREA;
        rc->coord.len = 4;
        rc->coord.n[0] = wp->area.x + (col * MIN_COLW);
        rc->coord.n[1] = itemY;
        rc->coord.n[2] = MIN_COLW;
        rc->coord.n[3] = ep->itemHeight;

        rc = style + CI_STYLE_LIST_HEADER;
        if( ur_is(rc, UT_BLOCK) )
            ur_compileDP( ut, rc, 1 );
    }
    itemY -= ep->itemHeight;


    // Items

    blk = ur_buffer( ep->dataBlkN );
    it  = blk->ptr.cell;
    rowCount = blk->used / colCount;

    for( row = 0; row < rowCount; ++row )
    {
        for( col = 0; col < colCount; ++col, ++it )
        {
            rc = style + CI_STYLE_LABEL;
            if( ur_is(it, UT_STRING) )
            {
                *rc = *it;
            }
            else
            {
                UBuffer* str;

                if( ! strN )
                    strN = ur_makeString( ut, UR_ENC_LATIN1, 32 );

                ur_initSeries( rc, UT_STRING, strN );

                str = ur_buffer( strN );
                str->used = 0;
                ur_toStr( ut, it, str, 0 );
            }

            rc = style + CI_STYLE_AREA;
            rc->coord.len = 4;
            rc->coord.n[0] = wp->area.x + (col * MIN_COLW);
            rc->coord.n[1] = itemY;
            rc->coord.n[2] = MIN_COLW;
            rc->coord.n[3] = ep->itemHeight;

            rc = style + ((row == ep->selRow) ?
                                CI_STYLE_LIST_ITEM_SELECTED :
                                CI_STYLE_LIST_ITEM);
            if( ur_is(rc, UT_BLOCK) )
                ur_compileDP( ut, rc, 1 );
        }
        itemY -= ep->itemHeight;
    }

    ur_endDP( ut, ur_buffer(ep->dp[0]), save );
#endif
}
Exemple #4
0
int main( int argc, char** argv )
{
    UThread* ut;
    char cmd[ 2048 ];
    double result;
    (void) argc;
    (void) argv;


    printf( "Urlan Calculator Example %s (%s)\n", UR_VERSION_STR, __DATE__ );

    ut = ur_makeEnv( 256, 0, 0, 0, 0 );
    if( ! ut )
    {
        printf( "ur_makeEnv failed\n" );
        return 255;
    }

    defineWords( ut );

    while( 1 )
    {
        printf( ")> " );
        fflush( stdout );   /* Required on Windows. */
        fgets( cmd, sizeof(cmd), stdin );

        if( cmd[0] < ' ' )
        {
            printf( "\n" );
        }
        else if( cmd[0] == 'q' )
        {
            break;
        }
        else
        {
            if( calc_evalCStr( ut, cmd, &result ) )
            {
                printf( "= %f\n", result );
            }
            else
            {
                UBuffer* blk = ur_errorBlock(ut);
                if( blk->used )
                {
                    UBuffer str;

                    ur_strInit( &str, UR_ENC_UTF8, 0 );
                    ur_toStr( ut, blk->ptr.cell, &str, 0 );
                    ur_strTermNull( &str );
                    printf( "%s\n", str.ptr.c );
                    ur_strFree( &str );

                    blk->used = 0;
                }
                else
                    break;
            }
        }
    }

    ur_freeEnv( ut );
    return 0;
}