Changeset 453
- Timestamp:
- 08/25/07 22:49:09 (13 months ago)
- Location:
- branches/thune/thread_safe
- Files:
-
- 2 added
- 14 modified
-
config.t (modified) (1 diff)
-
doc/UserManual (modified) (3 diffs)
-
encoding.c (modified) (5 diffs)
-
gl/gx.c (modified) (1 diff)
-
gl/joystick.c (modified) (1 diff)
-
make.c (modified) (9 diffs)
-
print.c (modified) (4 diffs)
-
series.c (modified) (1 diff)
-
stdio.c (modified) (2 diffs)
-
tests/working/utf8.good (added)
-
tests/working/utf8.t (added)
-
tokenize.c (modified) (2 diffs)
-
unix/os.c (modified) (2 diffs)
-
urlan.c (modified) (2 diffs)
-
urlan.h (modified) (2 diffs)
-
win32/os.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/config.t
r431 r453 12 12 [ ] emh "Debugger Hooks" 13 13 [ ] 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] 16 17 17 18 ;eof -
branches/thune/thread_safe/doc/UserManual
r450 r453 19 19 * Garbage collected datatype system with prototype based objects. 20 20 * 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. 23 22 24 23 .. Evaluation 25 24 ---------- 26 25 Thune uses postfix notation 26 27 28 About This Document 29 ------------------- 30 31 This manual is largely incomplete. It can only serve as a quick function 32 reference at this point. 33 27 34 28 35 … … 278 285 279 286 *Connect* also accepts components as arguments. This is short-hand for 280 refer ing to the first input or output.287 referring to the first input or output. 281 288 The following call makes the same connection as the example above:: 282 289 … … 466 473 find.last (ser pat -- ser) Find pattern in series starting from end. 467 474 match_ (ser pat -- end) Move position to end of matching pattern. 468 trim (str -- str) Remove white space from start and end.475 trim (str -- str) Remove white space from start and end. 469 476 ========== ====================== ================= 470 477 -
branches/thune/thread_safe/encoding.c
r447 r453 1 1 /*============================================================================ 2 2 Urlan Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 31 31 Returns number of characters copied. 32 32 */ 33 int copyUtf16ToAscii( char* dest, const uint16_t* src, int len ) 33 int 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 67 int copyUcs2ToAscii( char* dest, const uint16_t* src, int len ) 34 68 { 35 69 const uint16_t* end; … … 47 81 return len; 48 82 } 83 #endif 49 84 50 85 51 #ifndef UR_CONFIG_UDS52 86 /* 53 87 Returns number of characters copied. … … 87 121 case UR_ENC_UTF16: 88 122 count >>= 1; 89 strN = ur_makeBinary( count , &bin );90 bin->used = copyU tf16ToAscii( 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 ); 92 126 enc = UR_ENC_ASCII; 93 127 goto set_result; … … 156 190 } 157 191 } 158 #endif159 192 160 193 -
branches/thune/thread_safe/gl/gx.c
r442 r453 1345 1345 { 1346 1346 const GLubyte* str; 1347 UIndex binN;1348 1347 1349 1348 UR_CALL_UNUSED_TH 1349 UR_CALL_UNUSED_TOS 1350 1350 1351 1351 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 ); 1355 1353 UR_S_GROW; 1356 tos = UR_TOS;1357 ur_initType(tos, UT_STRING);1358 ur_setSeries(tos, binN, 0 );1359 1354 } 1360 1355 -
branches/thune/thread_safe/gl/joystick.c
r390 r453 83 83 84 84 ++val; // JV_NAME 85 n = ur_makeString( name, -1 ); 86 ur_initString( val, n, 0 ); 85 ur_makeString( val, name, -1 ); 87 86 88 87 ++val; // JV_AXIS_COUNT -
branches/thune/thread_safe/make.c
r452 r453 1 1 /*============================================================================ 2 2 Thune Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 335 335 336 336 337 #ifndef UR_CONFIG_UDS338 337 /* 339 338 Create context from initializer block. … … 458 457 } 459 458 } 460 #endif461 459 462 460 … … 614 612 615 613 614 /* 615 Convert UTF-8 to UCS-2 616 */ 617 static 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 616 666 /** 617 667 If len is less than zero then the length is automatically determined. 618 668 Special characters are translated. 619 669 */ 620 UIndex ur_makeStringT( UThread* ut, const char* txt, int len )670 UIndex ur_makeStringT( UThread* ut, UCell* res, const char* txt, int len ) 621 671 { 622 672 UIndex strN; … … 625 675 const char* end; 626 676 char* out; 677 int ch; 627 678 628 679 if( len == 0 ) 629 680 { 630 return ur_makeBinary( 0, 0 ); 681 strN = ur_makeBinary( 0, 0 ); 682 goto init; 631 683 } 632 684 … … 653 705 else 654 706 { 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; 656 716 } 657 717 } 658 718 659 719 str->used = out - str->ptr.c; 660 661 720 str->ptr.c[ str->used ] = '\0'; 721 722 init: 723 724 ur_initString( res, strN, 0 ); 662 725 return strN; 663 726 } … … 1326 1389 1327 1390 1328 #ifndef UR_CONFIG_UDS1329 1391 /* 1330 1392 (datatype! proto -- value) … … 1720 1782 { 1721 1783 if( spA ) 1722 binN = ur_makeString( spA, spB - spA ); 1784 { 1785 binN = ur_makeString( res, spA, spB - spA ); 1786 } 1723 1787 else 1788 { 1724 1789 binN = ur_makeBinary( 0, 0 ); 1725 1790 init_str: 1726 ur_initString( res, binN, 0 ); 1791 ur_initString( res, binN, 0 ); 1792 } 1727 1793 } 1728 1794 } … … 1871 1937 ur_throwErr( UR_ERR_DATATYPE, "Invalid make values" ); 1872 1938 } 1873 #endif1874 1939 1875 1940 -
branches/thune/thread_safe/print.c
r452 r453 31 31 32 32 33 extern int copyU tf16ToAscii( char* dest, const uint16_t* src, int len );33 extern int copyUcs2ToUtf8( char* dest, const uint16_t* src, int len ); 34 34 35 35 … … 43 43 44 44 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 ); 45 void 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 ); 50 49 } 51 50 … … 78 77 79 78 case UR_ENC_UTF16: 80 ur_strCatU tf16( out, str2->ptr.u16 + si, used );79 ur_strCatUcs2( out, str2->ptr.u16 + si, used ); 81 80 break; 82 81 } … … 271 270 #define APP_STR_FUNC _appendStringUtf16 272 271 #define APP_STR_T uint16_t 273 #define APP_STR_COPY ur_strCatU tf16272 #define APP_STR_COPY ur_strCatUcs2 274 273 #include "print_string.c" 275 274 -
branches/thune/thread_safe/series.c
r450 r453 1 1 /*============================================================================ 2 2 Thune Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or -
branches/thune/thread_safe/stdio.c
r387 r453 1 1 /*============================================================================ 2 2 Urlan Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 145 145 if( cp ) 146 146 { 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 ); 151 148 return; 152 149 } -
branches/thune/thread_safe/tokenize.c
r452 r453 492 492 #endif 493 493 break; 494 495 default: 496 syntaxError( "Unprintable/Non-ASCII Input" ); 494 497 } 495 498 } … … 1050 1053 string_end: 1051 1054 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 1053 1058 ++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 ); 1058 1060 1059 1061 ++it; -
branches/thune/thread_safe/unix/os.c
r447 r453 1 1 /*============================================================================ 2 2 Urlan Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 258 258 continue; 259 259 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 ); 262 263 } 263 264 -
branches/thune/thread_safe/urlan.c
r450 r453 432 432 //extern ULanguage _parseLanguage; 433 433 extern void ur_rebuildAtomHash( UArray* ); 434 #ifndef UR_CONFIG_UDS435 434 extern void ur_makeCallsEval( UThread* ); 436 435 extern void ur_makeCallsSeries( UThread* ); … … 440 439 #ifdef UR_CONFIG_NET 441 440 extern UPortDevice _netPortDevice; 442 #endif443 441 #endif 444 442 #ifdef LANG_RUNE -
branches/thune/thread_safe/urlan.h
r450 r453 551 551 UIndex ur_makeBinaryT( UThread*, int size, UBinary** ptr ); 552 552 UIndex ur_makeBinaryFrom( UThread*, const UCell* ); 553 UIndex ur_makeStringT( UThread*, const char* txt, int len );553 UIndex ur_makeStringT( UThread*, UCell*, const char* txt, int len ); 554 554 UIndex ur_makeVectorT( UThread*, int size, UArray** ptr ); 555 555 UIndex ur_makeResourceT( UThread*, int dataType, int size, UResource** ); … … 617 617 #define ur_makeBlock(size) ur_makeBlockT(ut,size,0) 618 618 #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) 620 620 #define ur_makeVector(size,ptr) ur_makeVectorT(ut,size,ptr) 621 621 #define ur_makeResource(dt,size,rp) ur_makeResourceT(ut,dt,size,rp) -
branches/thune/thread_safe/win32/os.c
r447 r453 1 1 /*============================================================================ 2 2 Thune Interpreter 3 Copyright (C) 2005-200 6Karl Robillard3 Copyright (C) 2005-2007 Karl Robillard 4 4 5 5 This library is free software; you can redistribute it and/or … … 326 326 continue; 327 327 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 ); 330 331 } 331 332 while( _findnext( handle, &fileinfo ) != -1 );
