Changeset 432 for branches/thune

Show
Ignore:
Timestamp:
07/16/07 03:30:31 (17 months ago)
Author:
krobillard
Message:

Replaced clean-path with full-path. Improved uc_whatDir().

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

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/doc/UserManual

    r430 r432  
    481481appen        (ser val -- )           Append and drop. 
    482482map          (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. 
    485483replace.all  (ser old new -- ser)    Find & Replace  
    486484===========  ======================  ================= 
     
    567565seek         (port pos -- port)      Set port stream position. 
    568566getenv       (name -- var)           Get environment variable. 
     567full-path    (path -- full)          Makes a relative directory path absolute. 
    569568system.run   (cmd -- status)         Execute program. 
    570569to-hex       (int -- int)            Flag integer to display in hexadecimal. 
     
    572571checksum     (bin type -- digest)    Compute 'crc16 or 'sha1 checksum. 
    573572===========  ======================  ====================== 
     573 
     574 
     575Input/Output Helpers 
     576~~~~~~~~~~~~~~~~~~~~ 
     577 
     578==========   ======================  ================= 
     579Word         Stack Usage             Function 
     580==========   ======================  ================= 
     581split-path   (full -- path file)     Split full path into path & file. 
     582dirize       (str -- str)            Ensure trailing slash is present. 
     583==========   ======================  ================= 
    574584 
    575585 
  • branches/thune/thread_safe/files.c

    r417 r432  
    545545 
    546546 
    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 
     549static 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*/ 
     574UR_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 ) 
    559603                { 
    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++; 
    563633                } 
    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!" ); 
    602642    } 
    603643} 
     
    12311271    { uc_file_info,  "file-info" }, 
    12321272    { uc_getenv,     "getenv" }, 
    1233     { uc_cleanPath,  "clean-path" }, 
     1273    { uc_fullPath,   "full-path" }, 
    12341274    { uc_checksum,   "checksum" }, 
    12351275#ifdef UR_CONFIG_BZIP2 
  • branches/thune/thread_safe/tests/Makefile

    r168 r432  
    11# Makefile  
    22 
    3 .PHONY: grind clean 
     3.PHONY: local grind clean 
    44 
    55test: 
    66        @./run_test working/*.t 
    77 
     8local: 
     9        @./run_test local/*.t 
     10 
    811grind: 
    9         @./grind working/*.t 
     12        @./grind working/*.t local/*.t 
    1013 
    1114clean: 
  • branches/thune/thread_safe/unix/os.c

    r418 r432  
    6464    char tmp[ 512 ]; 
    6565 
    66     UR_S_GROW; 
    67     tos = UR_TOS; 
    68  
    6966    if( getcwd( tmp, sizeof(tmp) ) ) 
    7067    { 
     
    7471        
    7572        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    } 
    9594} 
    9695 
  • branches/thune/thread_safe/win32/os.c

    r387 r432  
    5959    char tmp[ 512 ]; 
    6060 
    61     UR_S_GROW; 
    62     tos = UR_TOS; 
    63  
    6461    if( _getcwd( tmp, sizeof(tmp) ) ) 
    6562    { 
     
    6966        
    7067        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    } 
    9089} 
    9190 
     
    220219        if( fh == INVALID_HANDLE_VALUE ) 
    221220        { 
    222             ur_throwErr( ur_thread, UR_EX_ACCESS, "FindFirstFile" ); 
     221            ur_throwErr( UR_ERR_ACCESS, "FindFirstFile" ); 
    223222            return; 
    224223        } 
     
    264263        if( (err != ERROR_FILE_EXISTS) || (ur_isDir(str->ptr.c) != 1) ) 
    265264        { 
    266             ur_throwErr( ur_thread, UR_EX_ACCESS, 
    267                          "CreateDirectory error (%d)", err ); 
     265            ur_throwErr( UR_ERR_ACCESS, "CreateDirectory error (%d)", err ); 
    268266            return; 
    269267        } 
     
    275273        if( (errno != EEXIST) || (orIsDir(str->ptr.c) != 1) ) 
    276274        { 
    277             ur_throwErr( ur_thread, UR_EX_ACCESS, strerror/*_r*/(errno) ); 
     275            ur_throwErr( UR_ERR_ACCESS, strerror/*_r*/(errno) ); 
    278276            return; 
    279277        }