Changeset 98

Show
Ignore:
Timestamp:
03/23/06 01:35:12 (3 years ago)
Author:
krobillard
Message:

Time is now stored as double. Removed OTime.

Location:
trunk/orca
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/orca/op.c

    r65 r98  
    144144        if( orIs(b, OT_TIME) ) 
    145145        { 
    146             OTime time; 
    147             OValue* res; 
    148  
    149             time.sec  = a->time.sec + b->time.sec; 
    150             time.usec = a->time.usec + b->time.usec; 
    151             if( time.usec > 1000000 ) 
    152             { 
    153                 time.sec  += 1; 
    154                 time.usec -= 1000000; 
    155             } 
    156  
    157             res = orRESULT; 
    158             orSetTF( res, OT_TIME ); 
    159             res->time = time; 
     146            orSeconds(a) += orSeconds(b); 
    160147            return; 
    161148        } 
     
    283270        if( orIs(b, OT_TIME) ) 
    284271        { 
    285             OTime btime; 
    286             OValue* res; 
    287  
    288             // http://www.dusek.ch/manual/glibc/libc_21.html 
    289  
    290             btime = b->time; 
    291             if( a->time.usec < btime.usec ) 
    292             { 
    293                 int nsec = (btime.usec - a->time.usec) / 1000000 + 1; 
    294                 btime.usec -= 1000000 * nsec; 
    295                 btime.sec  += nsec; 
    296             } 
    297             if( a->time.usec - btime.usec > 1000000 ) 
    298             { 
    299                 int nsec = (a->time.usec - btime.usec) / 1000000; 
    300                 btime.usec += 1000000 * nsec; 
    301                 btime.sec  -= nsec; 
    302             } 
    303  
    304             res = orRESULT; 
    305             orSetTF( res, OT_TIME ); 
    306             /* usec will always be positive. */ 
    307             res->time.sec  = a->time.sec - btime.sec; 
    308             res->time.usec = a->time.usec - btime.usec; 
    309             /* 
    310             if( a->time.sec < time.sec ) 
    311                 res->time.sec = - res->time.sec; 
    312             */ 
     272            orSeconds(a) -= orSeconds(b); 
    313273            return; 
    314274        } 
  • trunk/orca/ovalue.h

    r86 r98  
    169169 
    170170 
    171 typedef struct 
    172 { 
    173     int32_t     sec; 
    174     int32_t     usec; 
    175 } 
    176 OTime; 
    177  
    178  
    179171typedef void (*ONativeFunc)(void*); 
    180172 
     
    204196        OWordRef    word; 
    205197        OContext    ctx; 
    206         OTime       time; 
    207198        struct { 
    208199            OIndex      n; 
     
    494485#define orLogic(val)    (val)->integer 
    495486#define orDecimal(val)  (val)->num.decimal 
     487#define orSeconds(val)  (val)->num.decimal 
    496488#define orTupleLen(val) (val)->argc 
    497489 
  • trunk/orca/print.c

    r96 r98  
    202202    int yc; 
    203203 
    204     tt = val->time.sec; 
     204    tt = (time_t) orSeconds(val); 
    205205    st = localtime( &tt ); 
    206206 
     
    241241 
    242242 
     243static void moldTime( OString* out, const OValue* val ) 
     244{ 
     245    char* cp; 
     246 
     247    orArrayReserve( out, 1, out->used + 32 ); 
     248 
     249    cp = out->charArray + out->used; 
     250    strPrint( cp, "%f", orSeconds(val) ); 
     251    while( *cp != '\0' ) 
     252        ++cp; 
     253    out->used = cp - out->charArray; 
     254} 
     255 
     256 
    243257static void formList( OString* out, const OValue* val ) 
    244258{ 
     
    578592                            break; 
    579593 
    580         case OT_TIME:       { 
    581                             double d; 
    582                             char* cp; 
    583                             d = ((double) val->time.sec) + 
    584                                 ((double) val->time.usec * 0.000001); 
    585                             orArrayReserve( out, 1, out->used + 32 ); 
    586                             cp = out->charArray + out->used; 
    587                             strPrint( cp, "%f", d ); 
    588                             while( *cp != '\0' ) 
    589                                 ++cp; 
    590                             out->used = cp - out->charArray; 
    591                             } 
     594        case OT_TIME:       moldTime( out, val ); 
    592595                            break; 
    593596 
     
    890893                            break; 
    891894 
    892         case OT_TIME:       { 
    893                             double d; 
    894                             char* cp; 
    895                             d = ((double) val->time.sec) + 
    896                                 ((double) val->time.usec * 0.000001); 
    897                             orArrayReserve( out, 1, out->used + 32 ); 
    898                             cp = out->charArray + out->used; 
    899                             strPrint( cp, "%f", d ); 
    900                             while( *cp != '\0' ) 
    901                                 ++cp; 
    902                             out->used = cp - out->charArray; 
    903                             } 
     895        case OT_TIME:       moldTime( out, val ); 
    904896                            break; 
    905897 
  • trunk/orca/unix/os.c

    r71 r98  
    7575 
    7676    orSetTF( res, OT_TIME ); 
    77     res->time.sec  = buf.st_mtime; 
    78     res->time.usec = 0; 
     77    orSeconds(res) = buf.st_mtime; 
    7978    return 0; 
    8079} 
     
    156155        orSetTF( res, OT_DATE ); 
    157156 
    158     res->time.sec  = tp.tv_sec; 
    159     res->time.usec = tp.tv_usec; 
     157    orSeconds(res) = tp.tv_sec + (tp.tv_usec * 0.000001); 
    160158} 
    161159 
  • trunk/orca/win32/os.c

    r85 r98  
    173173    else 
    174174        orSetTF( res, OT_DATE ); 
    175     res->time.sec  = tb.time; 
    176     res->time.usec = tb.millitm * 1000; 
     175    orSeconds(res) = tb.time + (tb.millitm * 0.001); 
    177176} 
    178177