Changeset 453 for branches/thune

Show
Ignore:
Timestamp:
08/25/07 22:49:09 (15 months ago)
Author:
krobillard
Message:

UTF-8 strings can now be read.
ur_makeString() now takes UCell argument.

Location:
branches/thune/thread_safe
Files:
2 added
14 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/config.t

    r431 r453  
    1212[ ] emh      "Debugger Hooks" 
    1313[ ] dt-code  "Include 'code datatype" 
    14 [ ] uds      "Library with datatype & gc system only - no eval" 
    15              disable [bzip2 trig math3d dt-code] 
     14 
     15;[ ] uds      "Library with datatype & gc system only - no eval" 
     16;             disable [bzip2 trig math3d dt-code] 
    1617 
    1718;eof 
  • branches/thune/thread_safe/doc/UserManual

    r450 r453  
    1919   * Garbage collected datatype system with prototype based objects. 
    2020   * Written in C to work well as an embedded scripting language. 
    21    * Small (but not tiny) binary & run-time enviroment. 
    22  
     21   * Small (but not tiny) binary & run-time environment. 
    2322 
    2423.. Evaluation 
    2524   ---------- 
    2625   Thune uses postfix notation 
     26 
     27 
     28About This Document 
     29------------------- 
     30 
     31This manual is largely incomplete.  It can only serve as a quick function 
     32reference at this point. 
     33 
    2734 
    2835 
     
    278285 
    279286*Connect* also accepts components as arguments.  This is short-hand for 
    280 refering to the first input or output. 
     287referring to the first input or output. 
    281288The following call makes the same connection as the example above:: 
    282289 
     
    466473find.last   (ser pat -- ser)        Find pattern in series starting from end. 
    467474match_      (ser pat -- end)        Move position to end of matching pattern. 
    468 trim        (str -- str)            Remove whitespace from start and end. 
     475trim        (str -- str)            Remove white space from start and end. 
    469476==========  ======================  ================= 
    470477 
  • branches/thune/thread_safe/encoding.c

    r447 r453  
    11/*============================================================================ 
    22    Urlan Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    3131   Returns number of characters copied. 
    3232*/ 
    33 int copyUtf16ToAscii( char* dest, const uint16_t* src, int len ) 
     33int copyUcs2ToUtf8( char* dest, const uint16_t* src, int len ) 
     34{ 
     35    // TODO: Prevent overflow of dest. 
     36    const char* start; 
     37    const uint16_t* end; 
     38    uint16_t c; 
     39 
     40    start = dest; 
     41    end = src + len; 
     42 
     43    while( src != end ) 
     44    { 
     45        c = *src++; 
     46        if( c > 127 ) 
     47        { 
     48            if( c > 0x07ff ) 
     49            { 
     50                *dest++ = 0xE0 | (c >> 12); 
     51                *dest++ = 0x80 | ((c >> 6) & 0x3f); 
     52                c = 0x80 | (c & 0x3f); 
     53            } 
     54            else 
     55            { 
     56                *dest++ = 0xC0 | (c >> 6); 
     57                c = 0x80 | (c & 0x3f); 
     58            } 
     59        } 
     60        *dest++ = (char) c; 
     61    } 
     62    return dest - start; 
     63} 
     64 
     65 
     66#if 0 
     67int copyUcs2ToAscii( char* dest, const uint16_t* src, int len ) 
    3468{ 
    3569    const uint16_t* end; 
     
    4781    return len; 
    4882} 
     83#endif 
    4984 
    5085 
    51 #ifndef UR_CONFIG_UDS 
    5286/* 
    5387   Returns number of characters copied. 
     
    87121                    case UR_ENC_UTF16: 
    88122                        count >>= 1; 
    89                         strN = ur_makeBinary( count, &bin );  
    90                         bin->used = copyUtf16ToAscii( bin->ptr.c, 
    91                                                       (uint16_t*) cpA, count ); 
     123                        strN = ur_makeBinary( count * 2, &bin );  
     124                        bin->used = copyUcs2ToUtf8( bin->ptr.c, 
     125                                                    (uint16_t*) cpA, count ); 
    92126                        enc = UR_ENC_ASCII; 
    93127                        goto set_result; 
     
    156190    } 
    157191} 
    158 #endif 
    159192 
    160193 
  • branches/thune/thread_safe/gl/gx.c

    r442 r453  
    13451345{ 
    13461346    const GLubyte* str; 
    1347     UIndex binN; 
    13481347 
    13491348    UR_CALL_UNUSED_TH 
     1349    UR_CALL_UNUSED_TOS 
    13501350 
    13511351    str = glGetString( GL_EXTENSIONS ); 
    1352     binN = ur_makeString( (const char*) str, -1 ); 
    1353  
    1354  
     1352    ur_makeString( ur_s_next(UR_TOS), (const char*) str, -1 ); 
    13551353    UR_S_GROW; 
    1356     tos = UR_TOS; 
    1357     ur_initType(tos, UT_STRING); 
    1358     ur_setSeries(tos, binN, 0 ); 
    13591354} 
    13601355 
  • branches/thune/thread_safe/gl/joystick.c

    r390 r453  
    8383 
    8484            ++val;                          // JV_NAME 
    85             n = ur_makeString( name, -1 ); 
    86             ur_initString( val, n, 0 ); 
     85            ur_makeString( val, name, -1 ); 
    8786 
    8887            ++val;                          // JV_AXIS_COUNT 
  • branches/thune/thread_safe/make.c

    r452 r453  
    11/*============================================================================ 
    22    Thune Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    335335 
    336336 
    337 #ifndef UR_CONFIG_UDS 
    338337/* 
    339338   Create context from initializer block. 
     
    458457    } 
    459458} 
    460 #endif 
    461459 
    462460 
     
    614612 
    615613 
     614/* 
     615   Convert UTF-8 to UCS-2 
     616*/ 
     617static void _makeString16( UBinary* str, const uint8_t* cp, int len ) 
     618{ 
     619    uint16_t  ch; 
     620    uint16_t* out; 
     621    const uint8_t* end; 
     622 
     623    ur_arrayReserve( str, 1, len * sizeof(uint16_t) ); 
     624    out = str->ptr.u16; 
     625 
     626    end = cp + len; 
     627    while( cp != end ) 
     628    { 
     629        ch = *cp++; 
     630 
     631        if( ch <= 0x7f ) 
     632        { 
     633            *out++ = ch; 
     634        } 
     635        else if( ch >= 0xc2 && ch <= 0xdf ) 
     636        { 
     637            if( cp != end ) 
     638            { 
     639                *out++ = ((ch & 0x1f) << 6) | (*cp & 0x3f); 
     640                ++cp; 
     641            } 
     642        } 
     643        else if( ch >= 0xe0 && ch <= 0xef ) 
     644        { 
     645            if( (end - cp) < 2 ) 
     646                break; 
     647            *out++ = ((ch    & 0x0f) << 12) | 
     648                     ((cp[0] & 0x3f) <<  6) | 
     649                      (cp[1] & 0x3f); 
     650            cp += 2; 
     651        } 
     652        else if( ch >= 0xf0 && ch <= 0xf3 ) 
     653        { 
     654            if( (end - cp) < 3 ) 
     655                break; 
     656            *out++ = 0;     // Only handle UCS-2 
     657            cp += 3; 
     658        } 
     659    } 
     660 
     661    str->avail /= 2; 
     662    str->used = out - str->ptr.u16; 
     663} 
     664 
     665 
    616666/** 
    617667  If len is less than zero then the length is automatically determined. 
    618668  Special characters are translated. 
    619669*/ 
    620 UIndex ur_makeStringT( UThread* ut, const char* txt, int len ) 
     670UIndex ur_makeStringT( UThread* ut, UCell* res, const char* txt, int len ) 
    621671{ 
    622672    UIndex strN; 
     
    625675    const char* end; 
    626676    char* out; 
     677    int ch; 
    627678 
    628679    if( len == 0 ) 
    629680    { 
    630         return ur_makeBinary( 0, 0 ); 
     681        strN = ur_makeBinary( 0, 0 ); 
     682        goto init; 
    631683    } 
    632684 
     
    653705        else 
    654706        { 
    655             *out++ = *cp++; 
     707            ch = *cp++; 
     708            if( ((unsigned int) ch) > 0x7f ) 
     709            { 
     710                _makeString16( str, (const uint8_t*) txt, len ); 
     711                ur_initString( res, strN, 0 ); 
     712                ur_setEncoding( res, UR_ENC_UTF16 ); 
     713                return strN; 
     714            } 
     715            *out++ = ch; 
    656716        } 
    657717    } 
    658718 
    659719    str->used = out - str->ptr.c; 
    660  
    661720    str->ptr.c[ str->used ] = '\0'; 
     721 
     722init: 
     723 
     724    ur_initString( res, strN, 0 ); 
    662725    return strN; 
    663726} 
     
    13261389 
    13271390 
    1328 #ifndef UR_CONFIG_UDS 
    13291391/* 
    13301392  (datatype! proto -- value) 
     
    17201782            { 
    17211783                if( spA ) 
    1722                     binN = ur_makeString( spA, spB - spA ); 
     1784                { 
     1785                    binN = ur_makeString( res, spA, spB - spA ); 
     1786                } 
    17231787                else 
     1788                { 
    17241789                    binN = ur_makeBinary( 0, 0 ); 
    17251790init_str: 
    1726                 ur_initString( res, binN, 0 ); 
     1791                    ur_initString( res, binN, 0 ); 
     1792                } 
    17271793            } 
    17281794        } 
     
    18711937    ur_throwErr( UR_ERR_DATATYPE, "Invalid make values" ); 
    18721938} 
    1873 #endif 
    18741939 
    18751940 
  • branches/thune/thread_safe/print.c

    r452 r453  
    3131 
    3232 
    33 extern int copyUtf16ToAscii( char* dest, const uint16_t* src, int len ); 
     33extern int copyUcs2ToUtf8( char* dest, const uint16_t* src, int len ); 
    3434 
    3535 
     
    4343 
    4444 
    45 void ur_strCatUtf16( UString* str, const uint16_t* cp, int len ) 
    46 { 
    47     if( (str->used + len) > str->avail ) 
    48         EXPAND( str, len ); 
    49     str->used += copyUtf16ToAscii( str->ptr.c + str->used, cp, len ); 
     45void ur_strCatUcs2( UString* str, const uint16_t* cp, int len ) 
     46{ 
     47    EXPAND( str, len * 2 ); 
     48    str->used += copyUcs2ToUtf8( str->ptr.c + str->used, cp, len ); 
    5049} 
    5150 
     
    7877 
    7978                case UR_ENC_UTF16: 
    80                     ur_strCatUtf16( out, str2->ptr.u16 + si, used ); 
     79                    ur_strCatUcs2( out, str2->ptr.u16 + si, used ); 
    8180                    break; 
    8281            } 
     
    271270#define APP_STR_FUNC    _appendStringUtf16 
    272271#define APP_STR_T       uint16_t 
    273 #define APP_STR_COPY    ur_strCatUtf16 
     272#define APP_STR_COPY    ur_strCatUcs2 
    274273#include "print_string.c" 
    275274 
  • branches/thune/thread_safe/series.c

    r450 r453  
    11/*============================================================================ 
    22    Thune Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
  • branches/thune/thread_safe/stdio.c

    r387 r453  
    11/*============================================================================ 
    22    Urlan Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    145145        if( cp ) 
    146146        { 
    147             UIndex strN = ur_makeString( cp, -1 ); 
    148  
    149             ur_initType( tos, UT_STRING ); 
    150             ur_setSeries( tos, strN, 0 ); 
     147            ur_makeString( tos, cp, -1 ); 
    151148            return; 
    152149        } 
  • branches/thune/thread_safe/tokenize.c

    r452 r453  
    492492#endif 
    493493                    break; 
     494 
     495                default: 
     496                    syntaxError( "Unprintable/Non-ASCII Input" ); 
    494497                } 
    495498            } 
     
    10501053string_end: 
    10511054 
    1052     // Make string before appending cell (in case GC is called). 
     1055    // Mark cell as unset in case GC is called by ur_makeString. 
     1056    cell = ur_appendCell( BLOCK, UT_UNSET ); 
     1057 
    10531058    ++token; 
    1054     tn = ur_makeString( token, it - token ); 
    1055  
    1056     cell = ur_appendCell( BLOCK, UT_STRING ); 
    1057     ur_setSeries( cell, tn, 0 ); 
     1059    ur_makeString( cell, token, it - token ); 
    10581060 
    10591061    ++it; 
  • branches/thune/thread_safe/unix/os.c

    r447 r453  
    11/*============================================================================ 
    22    Urlan Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    258258                continue; 
    259259 
    260             cell = ur_appendCell( blk, UT_STRING /*UT_FILE*/ ); 
    261             ur_setSeries( cell, ur_makeString(cp, -1), 0 ); 
     260            // Mark cell as unset in case GC is called by ur_makeString. 
     261            cell = ur_appendCell( blk, UT_UNSET ); 
     262            ur_makeString( cell, cp, -1 ); 
    262263        } 
    263264 
  • branches/thune/thread_safe/urlan.c

    r450 r453  
    432432//extern ULanguage _parseLanguage; 
    433433extern void ur_rebuildAtomHash( UArray* ); 
    434 #ifndef UR_CONFIG_UDS 
    435434extern void ur_makeCallsEval( UThread* ); 
    436435extern void ur_makeCallsSeries( UThread* ); 
     
    440439#ifdef UR_CONFIG_NET 
    441440extern UPortDevice _netPortDevice; 
    442 #endif 
    443441#endif 
    444442#ifdef LANG_RUNE 
  • branches/thune/thread_safe/urlan.h

    r450 r453  
    551551UIndex  ur_makeBinaryT( UThread*, int size, UBinary** ptr ); 
    552552UIndex  ur_makeBinaryFrom( UThread*, const UCell* ); 
    553 UIndex  ur_makeStringT( UThread*, const char* txt, int len ); 
     553UIndex  ur_makeStringT( UThread*, UCell*, const char* txt, int len ); 
    554554UIndex  ur_makeVectorT( UThread*, int size, UArray** ptr ); 
    555555UIndex  ur_makeResourceT( UThread*, int dataType, int size, UResource** ); 
     
    617617#define ur_makeBlock(size)              ur_makeBlockT(ut,size,0)     
    618618#define ur_makeBinary(size,ptr)         ur_makeBinaryT(ut,size,ptr) 
    619 #define ur_makeString(txt,len)          ur_makeStringT(ut,txt,len) 
     619#define ur_makeString(cell,txt,len)     ur_makeStringT(ut,cell,txt,len) 
    620620#define ur_makeVector(size,ptr)         ur_makeVectorT(ut,size,ptr) 
    621621#define ur_makeResource(dt,size,rp)     ur_makeResourceT(ut,dt,size,rp) 
  • branches/thune/thread_safe/win32/os.c

    r447 r453  
    11/*============================================================================ 
    22    Thune Interpreter 
    3     Copyright (C) 2005-2006  Karl Robillard 
     3    Copyright (C) 2005-2007  Karl Robillard 
    44 
    55    This library is free software; you can redistribute it and/or 
     
    326326                continue; 
    327327 
    328             cell = ur_appendCell( blk, UT_STRING /*UT_FILE*/ ); 
    329             ur_setSeries( cell, ur_makeString(fileinfo.name, -1), 0 ); 
     328            // Mark cell as unset in case GC is called by ur_makeString. 
     329            cell = ur_appendCell( blk, UT_UNSET ); 
     330            ur_makeString( cell, fileinfo.name, -1 ); 
    330331        } 
    331332        while( _findnext( handle, &fileinfo ) != -1 );