Changeset 432 for branches/thune
- Timestamp:
- 07/16/07 03:30:31 (17 months ago)
- Location:
- branches/thune/thread_safe
- Files:
-
- 2 added
- 5 modified
-
doc/UserManual (modified) (3 diffs)
-
files.c (modified) (2 diffs)
-
tests/Makefile (modified) (1 diff)
-
tests/local (added)
-
tests/local/file.t (added)
-
unix/os.c (modified) (2 diffs)
-
win32/os.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/doc/UserManual
r430 r432 481 481 appen (ser val -- ) Append and drop. 482 482 map (ser comb -- ) Transform each element of a series. 483 split-path (full -- path file) Split full path into path & file.484 dirize (str -- str) Ensure trailing slash is present.485 483 replace.all (ser old new -- ser) Find & Replace 486 484 =========== ====================== ================= … … 567 565 seek (port pos -- port) Set port stream position. 568 566 getenv (name -- var) Get environment variable. 567 full-path (path -- full) Makes a relative directory path absolute. 569 568 system.run (cmd -- status) Execute program. 570 569 to-hex (int -- int) Flag integer to display in hexadecimal. … … 572 571 checksum (bin type -- digest) Compute 'crc16 or 'sha1 checksum. 573 572 =========== ====================== ====================== 573 574 575 Input/Output Helpers 576 ~~~~~~~~~~~~~~~~~~~~ 577 578 ========== ====================== ================= 579 Word Stack Usage Function 580 ========== ====================== ================= 581 split-path (full -- path file) Split full path into path & file. 582 dirize (str -- str) Ensure trailing slash is present. 583 ========== ====================== ================= 574 584 575 585 -
branches/thune/thread_safe/files.c
r417 r432 545 545 546 546 547 char* ur_cleanPath( const char* src, const char* end, char* clean ) 548 { 549 char* dst = clean; 550 while( src != end ) 551 { 552 if( *src == '\\' || *src == '/' ) 553 { 554 int len = end - src; 555 if( (len > 2) && (src[1] == '.') && (src[2] == '.') ) 556 { 557 src += 3; 558 while( dst != clean ) 547 #define IS_SLASH(c) (((c) == '/') || ((c) == '\\')) 548 549 static char* upDir( char* start, char* it ) 550 { 551 char* oit = it; 552 if( it != start ) 553 { 554 if( IS_SLASH(*it) ) 555 --it; 556 while( it != start ) 557 { 558 if( IS_SLASH(*it) ) 559 { 560 if( it != oit ) 561 ++it; 562 break; 563 } 564 --it; 565 } 566 } 567 return it; 568 } 569 570 571 /* 572 (path -- absolute) 573 */ 574 UR_CALL( uc_fullPath ) 575 { 576 char* cpA; 577 char* cpB; 578 579 if( ur_stringSlice(ut, tos, &cpA, &cpB) ) 580 { 581 #ifdef _WIN32 582 if( ((cpB - cpA) > 1) && (cpA[1] == ':') ) 583 return; 584 #endif 585 if( (*cpA != '/') && (*cpA != '\\') ) 586 { 587 uc_whatDir( ut, tos ); 588 UR_S_NIP; 589 590 if( cpA != cpB ) 591 { 592 UString* str; 593 char* dst; 594 int len; 595 596 str = ur_bin( tos ); 597 ur_arrayReserve( str, 1, str->used + (cpB - cpA) ); 598 dst = str->ptr.c + str->used; 599 600 #define INC_A ++cpA; if(cpA == cpB) break; 601 602 while( cpA != cpB ) 559 603 { 560 --dst; 561 if( *dst == '/' ) 562 break; 604 if( *cpA == '.' ) 605 { 606 len = cpB - cpA; 607 if( len > 1 ) 608 { 609 if( IS_SLASH(cpA[1]) ) 610 { 611 cpA += 2; 612 continue; 613 } 614 else if( (len > 2) && 615 (cpA[1] == '.') && 616 IS_SLASH(cpA[2]) ) 617 { 618 cpA += 3; 619 dst = upDir( str->ptr.c, dst - 1 ); 620 continue; 621 } 622 } 623 } 624 else if( IS_SLASH(*cpA) ) 625 { 626 if( IS_SLASH(dst[-1]) ) 627 { 628 ++cpA; 629 continue; 630 } 631 } 632 *dst++ = *cpA++; 563 633 } 564 } 565 else 566 { 567 ++src; 568 *dst++ = '/'; 569 } 570 } 571 else 572 { 573 *dst++ = *src++; 574 } 575 } 576 return dst; 577 } 578 579 580 // (filename -- filename) 581 UR_CALL( uc_cleanPath ) 582 { 583 UString* str; 584 UString* clean; 585 UIndex binN; 586 char* dst; 587 588 UR_CALL_UNUSED_TH 589 590 if( ur_is(tos, UT_STRING) ) 591 { 592 str = ur_bin(tos); 593 594 binN = ur_makeBinary( str->used - tos->series.it ); 595 clean = ur_binPtr( binN ); 596 597 dst = ur_cleanPath( str->ptr.c + tos->series.it, 598 str->ptr.c + str->used, clean->ptr.c ); 599 clean->used = dst - clean->ptr.c; 600 601 ur_setSeries( tos, binN, 0 ); 634 635 str->used = dst - str->ptr.c; 636 } 637 } 638 } 639 else 640 { 641 ur_throwErr( UR_ERR_DATATYPE, "full-path expected string!" ); 602 642 } 603 643 } … … 1231 1271 { uc_file_info, "file-info" }, 1232 1272 { uc_getenv, "getenv" }, 1233 { uc_ cleanPath, "clean-path" },1273 { uc_fullPath, "full-path" }, 1234 1274 { uc_checksum, "checksum" }, 1235 1275 #ifdef UR_CONFIG_BZIP2 -
branches/thune/thread_safe/tests/Makefile
r168 r432 1 1 # Makefile 2 2 3 .PHONY: grind clean3 .PHONY: local grind clean 4 4 5 5 test: 6 6 @./run_test working/*.t 7 7 8 local: 9 @./run_test local/*.t 10 8 11 grind: 9 @./grind working/*.t 12 @./grind working/*.t local/*.t 10 13 11 14 clean: -
branches/thune/thread_safe/unix/os.c
r418 r432 64 64 char tmp[ 512 ]; 65 65 66 UR_S_GROW;67 tos = UR_TOS;68 69 66 if( getcwd( tmp, sizeof(tmp) ) ) 70 67 { … … 74 71 75 72 len = strLen( tmp ); 76 if( len > 0 ) 77 { 78 binN = ur_makeBinary( len + 1 ); 79 str = ur_binPtr( binN ); 80 str->used = len; 81 memCpy( str->ptr.c, tmp, len ); 82 83 if( tmp[ len - 1 ] != '/' ) 84 { 85 str->ptr.c[ len ] = '/'; 86 ++str->used; 87 } 88 89 ur_initType( tos, UT_STRING /*UT_FILE*/ ); 90 ur_setSeries( tos, binN, 0 ); 91 return; 92 } 93 } 94 ur_setFalse( tos ); 73 assert( len > 0 ); 74 75 binN = ur_makeBinary( len + 1 ); 76 str = ur_binPtr( binN ); 77 str->used = len; 78 memCpy( str->ptr.c, tmp, len ); 79 80 if( tmp[ len - 1 ] != '/' ) 81 { 82 str->ptr.c[ len ] = '/'; 83 ++str->used; 84 } 85 86 UR_S_GROW; 87 tos = UR_TOS; 88 ur_initString( tos, binN, 0 ); // UT_FILE 89 } 90 else 91 { 92 ur_throwErr( UR_ERR_ACCESS, strerror(errno) ); 93 } 95 94 } 96 95 -
branches/thune/thread_safe/win32/os.c
r387 r432 59 59 char tmp[ 512 ]; 60 60 61 UR_S_GROW;62 tos = UR_TOS;63 64 61 if( _getcwd( tmp, sizeof(tmp) ) ) 65 62 { … … 69 66 70 67 len = strLen( tmp ); 71 if( len > 0 ) 72 { 73 binN = ur_makeBinary( len + 1 ); 74 str = ur_binPtr( binN ); 75 str->used = len; 76 memCpy( str->ptr.c, tmp, len ); 77 78 if( tmp[ len - 1 ] != '\\' ) 79 { 80 str->ptr.c[ len ] = '\\'; 81 ++str->used; 82 } 83 84 ur_initType( tos, UT_STRING /*UT_FILE*/ ); 85 ur_setSeries( tos, binN, 0 ); 86 return; 87 } 88 } 89 ur_setFalse( tos ); 68 assert( len > 0 ); 69 70 binN = ur_makeBinary( len + 1 ); 71 str = ur_binPtr( binN ); 72 str->used = len; 73 memCpy( str->ptr.c, tmp, len ); 74 75 if( tmp[ len - 1 ] != '\\' ) 76 { 77 str->ptr.c[ len ] = '\\'; 78 ++str->used; 79 } 80 81 UR_S_GROW; 82 tos = UR_TOS; 83 ur_initString( tos, binN, 0 ); // UT_FILE 84 } 85 else 86 { 87 ur_throwErr( UR_ERR_ACCESS, strerror(errno) ); 88 } 90 89 } 91 90 … … 220 219 if( fh == INVALID_HANDLE_VALUE ) 221 220 { 222 ur_throwErr( ur_thread, UR_EX_ACCESS, "FindFirstFile" );221 ur_throwErr( UR_ERR_ACCESS, "FindFirstFile" ); 223 222 return; 224 223 } … … 264 263 if( (err != ERROR_FILE_EXISTS) || (ur_isDir(str->ptr.c) != 1) ) 265 264 { 266 ur_throwErr( ur_thread, UR_EX_ACCESS, 267 "CreateDirectory error (%d)", err ); 265 ur_throwErr( UR_ERR_ACCESS, "CreateDirectory error (%d)", err ); 268 266 return; 269 267 } … … 275 273 if( (errno != EEXIST) || (orIsDir(str->ptr.c) != 1) ) 276 274 { 277 ur_throwErr( ur_thread, UR_EX_ACCESS, strerror/*_r*/(errno) );275 ur_throwErr( UR_ERR_ACCESS, strerror/*_r*/(errno) ); 278 276 return; 279 277 }
