Changeset 71 for trunk/orca

Show
Ignore:
Timestamp:
03/03/06 19:14:39 (3 years ago)
Author:
krobillard
Message:

Added make-dir native.
Minor cleanup in file.c.

Location:
trunk/orca
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/ChangeLog

    r63 r71  
    44V0.0.24 - ?? March 2006 
    55 
    6     *  
     6    * Added make-dir. 
     7    * Bugfixes. 
    78 
    89 
  • trunk/orca/boot.c

    r63 r71  
    301301  "    /wait\n" 
    302302  "]\n" 
    303   "change-dir: native [\n" 
    304   "    value\n" 
    305   "]\n" 
     303  "change-dir: native [value]\n" 
    306304  "what-dir: native []\n" 
     305  "make-dir: native [path [file!]]\n" 
    307306  "clean-path: native [path [file!]]\n" 
    308307  "recycle: native [/off /on]\n" 
     
    381380  "orca: true\n" 
    382381  "system: context [\n" 
    383   "    version: 0.0.24\n" 
     382  "    version: 0.0.23\n" 
    384383  "    os: none\n" 
    385384  "    error: context [\n" 
  • trunk/orca/boot.r

    r3 r71  
    410410    ] 
    411411 
    412     change-dir: native [ 
    413         value 
    414     ] 
    415  
     412    change-dir: native [value] 
    416413    what-dir: native [] 
     414    make-dir: native [path [file!]]     ; url! 
    417415 
    418416    clean-path: native [path [file!]]   ; url! 
  • trunk/orca/files.c

    r42 r71  
    3131extern void orChangeDirNative( OValue* a1 ); 
    3232extern void orWhatDirNative(); 
     33extern void orMakeDirNative( OValue* a1 ); 
    3334extern void orRenameNative( OValue* a1 ); 
    3435extern void orDeleteNative( OValue* a1 ); 
     
    594595    orNative( orChangeDirNative,  "change-dir" ); 
    595596    orNative( orWhatDirNative,    "what-dir"   ); 
     597    orNative( orMakeDirNative,    "make-dir"   ); 
    596598    orNative( orNowNative,        "now"        ); 
    597599    orNative( orGetenvNative,     "getenv"     ); 
  • trunk/orca/unix/os.c

    r42 r71  
    2323#include <sys/time.h> 
    2424#include <sys/stat.h> 
     25#include <errno.h> 
    2526#include <dirent.h> 
    2627#include <unistd.h> 
     
    4041 
    4142 
     43/** 
     44  Returns -1 if not present. 
     45*/ 
     46int orFileSize( const char* path ) 
     47{ 
     48    struct stat buf; 
     49    if( stat( path, &buf ) == -1 ) 
     50        return -1; 
     51    return buf.st_size; 
     52} 
     53 
     54 
     55/** 
     56  Returns 1 if directory, 0 if file or -1 if error. 
     57*/ 
     58int orIsDir( const char* path ) 
     59{ 
     60    struct stat buf; 
     61    if( stat( path, &buf ) == -1 ) 
     62        return -1; 
     63    return S_ISDIR(buf.st_mode) ? 1 : 0; 
     64} 
     65 
     66 
     67/** 
     68  Returns 0 if result set to file modification time or -1 if error. 
     69*/ 
     70int orFileModified( const char* path, OValue* res ) 
     71{ 
     72    struct stat buf; 
     73    if( stat( path, &buf ) == -1 ) 
     74        return -1; 
     75 
     76    orSetTF( res, OT_TIME ); 
     77    res->time.sec  = buf.st_mtime; 
     78    res->time.usec = 0; 
     79    return 0; 
     80} 
     81 
     82 
    4283/* 
    4384   change-dir 
     
    4687{ 
    4788    int logic = 0; 
    48     OString* str = orSTRINGS + a1->index; 
     89    OString* str = orSTRING(a1); 
     90    orTermCStr(str); 
    4991    if( chdir( str->charArray ) == 0 ) 
    5092        logic = 1; 
     
    69111            str->used = len; 
    70112            memCpy( str->charArray, orTmp, len ); 
    71             orResultFILE( str - orSTRINGS ); 
     113            orResultFILE( orStringN(str) ); 
    72114            return; 
    73115        } 
     
    78120 
    79121/** 
    80   Returns -1 if not present. 
    81 */ 
    82 int orFileSize( const char* path ) 
    83 { 
    84     struct stat buf; 
    85     if( stat( path, &buf ) == -1 ) 
    86         return -1; 
    87     return buf.st_size; 
    88 } 
    89  
    90  
    91 /** 
    92   Returns 1 if directory, 0 if file or -1 if error. 
    93 */ 
    94 int orIsDir( const char* path ) 
    95 { 
    96     struct stat buf; 
    97     if( stat( path, &buf ) == -1 ) 
    98         return -1; 
    99     return S_ISDIR(buf.st_mode) ? 1 : 0; 
    100 } 
    101  
    102  
    103 /** 
    104   Returns 0 if result set to file modification time or -1 if error. 
    105 */ 
    106 int orFileModified( const char* path, OValue* res ) 
    107 { 
    108     struct stat buf; 
    109     if( stat( path, &buf ) == -1 ) 
    110         return -1; 
    111  
    112     orSetTF( res, OT_TIME ); 
    113     res->time.sec  = buf.st_mtime; 
    114     res->time.usec = 0; 
    115     return 0; 
     122  No error if directory exists. 
     123*/ 
     124void orMakeDirNative( OValue* a1 ) 
     125{ 
     126    int err; 
     127    OString* str = orSTRING(a1); 
     128    orTermCStr(str); 
     129    err = mkdir( str->charArray, 0755 ); 
     130    if( err ) 
     131    { 
     132        if( (errno != EEXIST) || (orIsDir(str->charArray) != 1) ) 
     133        { 
     134            orErrorT( OR_ERROR_ACCESS, strerror/*_r*/(errno) ); 
     135        } 
     136    } 
    116137} 
    117138 
     
    229250        // What is the overhead of creating the arg list between fork/exec? 
    230251        char* argv[10]; 
    231         argumentList( orSTRINGS + a1->index, a1->series.it, argv, 9 ); 
     252        argumentList( orSTRING(a1), a1->series.it, argv, 9 ); 
    232253 
    233254        close( pfd[0] ); 
     
    306327        // What is the overhead of creating the arg list between fork/exec? 
    307328        char* argv[10]; 
    308         argumentList( orSTRINGS + a1->index, a1->series.it, argv, 9 ); 
     329        argumentList( orSTRING(a1), a1->series.it, argv, 9 ); 
    309330 
    310331        if( execvp( argv[0], argv ) == -1 ) 
  • trunk/orca/win32/os.c

    r42 r71  
    3434    seed += clock(); 
    3535    return seed; 
    36 } 
    37  
    38  
    39 /* 
    40    change-dir 
    41 */ 
    42 void orChangeDirNative( OValue* a1 ) 
    43 { 
    44     int logic = 0; 
    45     OString* str = orSTRINGS + a1->index; 
    46     if( _chdir( str->charArray ) == 0 ) 
    47         logic = 1; 
    48     orResult( OT_LOGIC, logic ); 
    49 } 
    50  
    51  
    52 /* 
    53    what-dir 
    54 */ 
    55 void orWhatDirNative() 
    56 { 
    57     if( _getcwd( orTmp, OR_TMP_SIZE ) ) 
    58     { 
    59         int len; 
    60         OString* str; 
    61         
    62         len = strLen( orTmp ); 
    63         if( len > 0 ) 
    64         { 
    65             str = orMakeString( len + OR_CTERM_LEN ); 
    66             str->used = len; 
    67             memCpy( str->charArray, orTmp, len ); 
    68             orResultFILE( str - orSTRINGS ); 
    69             return; 
    70         } 
    71     } 
    72     orResultFALSE; 
    7336} 
    7437 
     
    12386    return 0; 
    12487    */ 
     88} 
     89 
     90 
     91/* 
     92   change-dir 
     93*/ 
     94void orChangeDirNative( OValue* a1 ) 
     95{ 
     96    int logic = 0; 
     97    OString* str = orSTRING(a1); 
     98    orTermCStr(str); 
     99    if( _chdir( str->charArray ) == 0 ) 
     100        logic = 1; 
     101    orResult( OT_LOGIC, logic ); 
     102} 
     103 
     104 
     105/* 
     106   what-dir 
     107*/ 
     108void orWhatDirNative() 
     109{ 
     110    if( _getcwd( orTmp, OR_TMP_SIZE ) ) 
     111    { 
     112        int len; 
     113        OString* str; 
     114        
     115        len = strLen( orTmp ); 
     116        if( len > 0 ) 
     117        { 
     118            str = orMakeString( len + OR_CTERM_LEN ); 
     119            str->used = len; 
     120            memCpy( str->charArray, orTmp, len ); 
     121            orResultFILE( orStringN(str) ); 
     122            return; 
     123        } 
     124    } 
     125    orResultFALSE; 
     126} 
     127 
     128 
     129/* 
     130  No error if directory exists. 
     131*/ 
     132void orMakeDirNative( OValue* a1 ) 
     133{ 
     134    int err; 
     135    OString* str = orSTRING(a1); 
     136    orTermCStr(str); 
     137 
     138#if 0 
     139    if( ! CreateDirectory( str->charArray, NULL ) ) 
     140    { 
     141    } 
     142#else 
     143    err = _mkdir( str->charArray ); 
     144    if( err ) 
     145    { 
     146        if( (errno != EEXIST) || (orIsDir(str->charArray) != 1) ) 
     147        { 
     148            orErrorT( OR_ACCESS_ERR, strerror/*_r*/(errno) ); 
     149        } 
     150    } 
     151#endif 
    125152} 
    126153