Changeset 53


Ignore:
Timestamp:
01/17/06 22:51:03 (6 years ago)
Author:
gnue
Message:
  • cleaned up a warning
  • the symbols for seek are now seek_set, seek_cur and seek_end since end conflicted with end keyword
  • got seek to actually work (replaced == with NewtRefEqual, removed quotes for the symbols)
  • added getc, putc and write (write writes a binary just like read reads a binary)
  • added a sample code for NSOF I/O.

contribute patch by Paul Guyot

Location:
NEWT0/trunk
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • NEWT0/trunk/ext/protoFILE/protoFILE.c

    r1 r53  
    102102        return NewtThrow(kNErrNotASymbol, whence); 
    103103 
    104     if (whence == NSSYM("set")) 
     104    if (NewtRefEqual(whence, NSSYM(seek_set))) 
    105105        wh = SEEK_SET; 
    106     else if (whence == NSSYM("curr")) 
     106    else if (NewtRefEqual(whence, NSSYM(seek_cur))) 
    107107        wh = SEEK_CUR; 
    108     else if (whence == NSSYM("end")) 
     108    else if (NewtRefEqual(whence, NSSYM(seek_end))) 
    109109        wh = SEEK_END; 
    110110    else 
     
    395395} 
    396396 
     397newtRef MyGetc(newtRefArg rcvr) 
     398{ 
     399    newtRefVar stream; 
     400    FILE* theFile; 
     401    int theResult; 
     402     
     403    stream = NcGetSlot(rcvr, NSSYM(_stream)); 
     404    if (NewtRefIsNIL(stream)) 
     405        return kNewtRefUnbind; 
     406 
     407    theFile = NewtRefToFILE(stream); 
     408    theResult = fgetc(theFile); 
     409    return NewtMakeInteger(theResult); 
     410} 
     411 
     412newtRef MyPutc(newtRefArg rcvr, newtRefArg byte) 
     413{ 
     414    newtRefVar stream; 
     415    FILE* theFile; 
     416    char theByte; 
     417    int theResult; 
     418     
     419    stream = NcGetSlot(rcvr, NSSYM(_stream)); 
     420    if (NewtRefIsNIL(stream)) 
     421        return kNewtRefUnbind; 
     422 
     423    theFile = NewtRefToFILE(stream); 
     424    theByte = NewtRefToInteger(byte); 
     425    theResult = fputc(theByte, theFile); 
     426    return NewtMakeInteger(theResult); 
     427} 
     428 
     429newtRef MyWrite(newtRefArg rcvr, newtRefArg binary) 
     430{ 
     431    newtRefVar stream; 
     432    FILE* theFile; 
     433    void* data; 
     434    int len; 
     435    int theResult; 
     436     
     437    stream = NcGetSlot(rcvr, NSSYM(_stream)); 
     438    if (NewtRefIsNIL(stream)) 
     439        return kNewtRefUnbind; 
     440 
     441    theFile = NewtRefToFILE(stream); 
     442    data = NewtRefToBinary(binary); 
     443    len = NewtBinaryLength(binary); 
     444    theResult = fwrite(data, len, 1, theFile); 
     445 
     446    return NewtMakeInteger(theResult); 
     447} 
    397448 
    398449/*------------------------------------------------------------------------*/ 
     
    427478    NcSetSlot(r, NSSYM(Print),      NewtMakeNativeFunc(MyPrint,     1, "Print(str)")); 
    428479    NcSetSlot(r, NSSYM(Gets),       NewtMakeNativeFunc(MyGets,      0, "Gets()")); 
     480    NcSetSlot(r, NSSYM(Getc),       NewtMakeNativeFunc(MyGetc,      0, "Getc()")); 
     481    NcSetSlot(r, NSSYM(Putc),       NewtMakeNativeFunc(MyPutc,      1, "Putc(byte)")); 
     482    NcSetSlot(r, NSSYM(Write),      NewtMakeNativeFunc(MyWrite,     1, "Write(binary)")); 
    429483 
    430484    NcSetSlot(r, NSSYM(_stream),    kNewtRefNIL); 
  • NEWT0/trunk/src/newt_core/NewtIconv.c

    r36 r53  
    4242        if (dst) 
    4343        { 
    44             char *  inbuf_p = src; 
     44            const char *    inbuf_p = src; 
    4545            char *  outbuf_p = dst; 
    4646            size_t  inbytesleft = srclen; 
Note: See TracChangeset for help on using the changeset viewer.