| | 393 | newtRef MyGetc(newtRefArg rcvr) |
| | 394 | { |
| | 395 | newtRefVar stream; |
| | 396 | FILE* theFile; |
| | 397 | int theResult; |
| | 398 | |
| | 399 | stream = NcGetSlot(rcvr, NSSYM(_stream)); |
| | 400 | if (NewtRefIsNIL(stream)) |
| | 401 | return kNewtRefUnbind; |
| | 402 | |
| | 403 | theFile = NewtRefToFILE(stream); |
| | 404 | theResult = fgetc(theFile); |
| | 405 | return NewtMakeInteger(theResult); |
| | 406 | } |
| | 407 | |
| | 408 | newtRef MyPutc(newtRefArg rcvr, newtRefArg byte) |
| | 409 | { |
| | 410 | newtRefVar stream; |
| | 411 | FILE* theFile; |
| | 412 | char theByte; |
| | 413 | int theResult; |
| | 414 | |
| | 415 | stream = NcGetSlot(rcvr, NSSYM(_stream)); |
| | 416 | if (NewtRefIsNIL(stream)) |
| | 417 | return kNewtRefUnbind; |
| | 418 | |
| | 419 | theFile = NewtRefToFILE(stream); |
| | 420 | theByte = NewtRefToInteger(byte); |
| | 421 | theResult = fputc(theByte, theFile); |
| | 422 | return NewtMakeInteger(theResult); |
| | 423 | } |
| | 424 | |
| | 425 | newtRef MyWrite(newtRefArg rcvr, newtRefArg binary) |
| | 426 | { |
| | 427 | newtRefVar stream; |
| | 428 | FILE* theFile; |
| | 429 | void* data; |
| | 430 | int len; |
| | 431 | int theResult; |
| | 432 | |
| | 433 | stream = NcGetSlot(rcvr, NSSYM(_stream)); |
| | 434 | if (NewtRefIsNIL(stream)) |
| | 435 | return kNewtRefUnbind; |
| | 436 | |
| | 437 | theFile = NewtRefToFILE(stream); |
| | 438 | data = NewtRefToBinary(binary); |
| | 439 | len = NewtBinaryLength(binary); |
| | 440 | theResult = fwrite(data, len, 1, theFile); |
| | 441 | |
| | 442 | return NewtMakeInteger(theResult); |
| | 443 | } |
| | 476 | NcSetSlot(r, NSSYM(Getc), NewtMakeNativeFunc(MyGetc, 0, "Getc()")); |
| | 477 | NcSetSlot(r, NSSYM(Putc), NewtMakeNativeFunc(MyPutc, 1, "Putc(byte)")); |
| | 478 | NcSetSlot(r, NSSYM(Write), NewtMakeNativeFunc(MyWrite, 1, "Write(binary)")); |