359 if (_isSmallInteger(ioctlNumber)) { |
373 if (_isSmallInteger(ioctlNumber)) { |
360 ioNum = _intVal(ioctlNumber); |
374 ioNum = _intVal(ioctlNumber); |
361 f = MKFD(_INST(filePointer)); |
375 f = MKFD(_INST(filePointer)); |
362 savInt = _immediateInterrupt; |
376 savInt = _immediateInterrupt; |
363 _immediateInterrupt = 1; |
377 _immediateInterrupt = 1; |
364 do { |
378 do { |
365 ret = ioctl(fileno(f), ioNum); |
379 ret = ioctl(fileno(f), ioNum); |
366 } while ((ret < 0) && (errno == EINTR)); |
380 } while ((ret < 0) && (errno == EINTR)); |
367 _immediateInterrupt = savInt; |
381 _immediateInterrupt = savInt; |
368 if (ret >= 0) { |
382 if (ret >= 0) { |
369 RETURN ( _MKSMALLINT(ret) ); |
383 RETURN ( _MKSMALLINT(ret) ); |
370 } |
384 } |
371 ErrorNumber = _MKSMALLINT(errno); |
385 ErrorNumber = _MKSMALLINT(errno); |
401 && (_isSmallInteger(arg) || (isStructure == true))) { |
415 && (_isSmallInteger(arg) || (isStructure == true))) { |
402 f = MKFD(_INST(filePointer)); |
416 f = MKFD(_INST(filePointer)); |
403 ioNum = _intVal(ioctlNumber); |
417 ioNum = _intVal(ioctlNumber); |
404 savInt = _immediateInterrupt; |
418 savInt = _immediateInterrupt; |
405 _immediateInterrupt = 1; |
419 _immediateInterrupt = 1; |
406 do { |
420 do { |
407 if (isStructure == true) { |
421 if (isStructure == true) { |
408 ret = ioctl(fileno(f), ioNum, _ByteArrayInstPtr(arg)->ba_element); |
422 ret = ioctl(fileno(f), ioNum, _ByteArrayInstPtr(arg)->ba_element); |
409 } else { |
423 } else { |
410 ret = ioctl(fileno(f), ioNum, _intVal(arg)); |
424 ret = ioctl(fileno(f), ioNum, _intVal(arg)); |
411 } |
425 } |
412 } while ((ret < 0) && (errno == EINTR)); |
426 } while ((ret < 0) && (errno == EINTR)); |
413 _immediateInterrupt = savInt; |
427 _immediateInterrupt = savInt; |
414 if (ret >= 0) { |
428 if (ret >= 0) { |
415 RETURN ( _MKSMALLINT(ret) ); |
429 RETURN ( _MKSMALLINT(ret) ); |
416 } |
430 } |
417 ErrorNumber = _MKSMALLINT(errno); |
431 ErrorNumber = _MKSMALLINT(errno); |
437 int cnt, savInt; |
451 int cnt, savInt; |
438 extern OBJ ErrorNumber; |
452 extern OBJ ErrorNumber; |
439 extern errno; |
453 extern errno; |
440 extern int _immediateInterrupt; |
454 extern int _immediateInterrupt; |
441 |
455 |
442 if (_INST(filePointer) != nil) { |
456 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
443 if (_INST(mode) != _writeonly) { |
457 f = MKFD(_INST(filePointer)); |
444 f = MKFD(_INST(filePointer)); |
458 savInt = _immediateInterrupt; |
445 savInt = _immediateInterrupt; |
459 _immediateInterrupt = 1; |
446 _immediateInterrupt = 1; |
460 do { |
447 do { |
461 if (_INST(buffered) == false) { |
448 if (_INST(buffered) == false) { |
462 cnt = read(fileno(f), &byte, 1); |
449 cnt = read(fileno(f), &byte, 1); |
463 } else { |
450 } else { |
464 if (_INST(mode) == _readwrite) |
451 if (_INST(mode) == _readwrite) |
465 fseek(f, 0L, 1); /* needed in stdio */ |
452 fseek(f, 0L, 1); /* needed in stdio */ |
466 cnt = fread(&byte, 1, 1, f); |
453 cnt = fread(&byte, 1, 1, f); |
467 } |
454 } |
468 } while ((cnt < 0) && (errno == EINTR)); |
455 } while ((cnt < 0) && (errno == EINTR)); |
469 _immediateInterrupt = savInt; |
456 _immediateInterrupt = savInt; |
470 if (cnt == 1) { |
457 if (cnt == 1) { |
471 if (_INST(position) != nil) |
458 if (_INST(position) != nil) |
472 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
459 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
473 RETURN ( _MKSMALLINT(byte) ); |
460 RETURN ( _MKSMALLINT(byte) ); |
474 } |
461 } |
475 if (cnt < 0) { |
462 if (cnt < 0) { |
476 ErrorNumber = _MKSMALLINT(errno); |
463 ErrorNumber = _MKSMALLINT(errno); |
477 } |
464 } |
478 RETURN ( nil ); |
465 RETURN ( nil ); |
|
466 } |
|
467 } |
479 } |
468 %} |
480 %} |
469 . |
481 . |
470 filePointer isNil ifTrue:[^ self errorNotOpen]. |
482 filePointer isNil ifTrue:[^ self errorNotOpen]. |
471 self errorWriteOnly |
483 self errorWriteOnly |
495 extern OBJ ErrorNumber; |
507 extern OBJ ErrorNumber; |
496 extern errno; |
508 extern errno; |
497 OBJ pos; |
509 OBJ pos; |
498 extern int _immediateInterrupt; |
510 extern int _immediateInterrupt; |
499 |
511 |
500 if (_INST(filePointer) != nil) { |
512 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
501 if (_INST(mode) != _writeonly) { |
513 if (_isSmallInteger(count) && _isSmallInteger(start)) { |
502 if (_isSmallInteger(count) && _isSmallInteger(start)) { |
514 cnt = _intVal(count); |
503 cnt = _intVal(count); |
515 offs = _intVal(start) - 1; |
504 offs = _intVal(start) - 1; |
516 f = MKFD(_INST(filePointer)); |
505 f = MKFD(_INST(filePointer)); |
517 objSize = _Size(anObject) - OHDR_SIZE; |
506 objSize = _Size(anObject) - OHDR_SIZE; |
518 if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
507 if ((offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs))) { |
519 cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs; |
508 cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs; |
520 savInt = _immediateInterrupt; |
509 savInt = _immediateInterrupt; |
521 _immediateInterrupt = 1; |
510 _immediateInterrupt = 1; |
522 do { |
511 do { |
523 if (_INST(buffered) == false) { |
512 if (_INST(buffered) == false) { |
524 cnt = read(fileno(f), cp, cnt); |
513 cnt = read(fileno(f), cp, cnt); |
525 } else { |
514 } else { |
526 if (_INST(mode) == _readwrite) |
515 if (_INST(mode) == _readwrite) |
527 fseek(f, 0L, 1); /* needed in stdio */ |
516 fseek(f, 0L, 1); /* needed in stdio */ |
528 cnt = fread(cp, 1, cnt, f); |
517 cnt = fread(cp, 1, cnt, f); |
529 } |
518 } |
530 } while ((cnt < 0) && (errno == EINTR)); |
519 } while ((cnt < 0) && (errno == EINTR)); |
531 _immediateInterrupt = savInt; |
520 _immediateInterrupt = savInt; |
532 if (cnt >= 0) { |
521 if (cnt >= 0) { |
533 pos = _INST(position); |
522 pos = _INST(position); |
534 if (pos != nil) |
523 if (pos != nil) |
535 _INST(position) = _MKSMALLINT(_intVal(pos) + cnt); |
524 _INST(position) = _MKSMALLINT(_intVal(pos) + cnt); |
536 RETURN ( _MKSMALLINT(cnt) ); |
525 RETURN ( _MKSMALLINT(cnt) ); |
537 } |
526 } |
538 ErrorNumber = _MKSMALLINT(errno); |
527 ErrorNumber = _MKSMALLINT(errno); |
539 RETURN ( nil ); |
528 RETURN ( nil ); |
|
529 } |
|
530 } |
540 } |
531 } |
541 } |
532 } |
542 } |
533 %} |
543 %} |
534 . |
544 . |
548 %{ /* NOCONTEXT */ |
558 %{ /* NOCONTEXT */ |
549 extern int _immediateInterrupt; |
559 extern int _immediateInterrupt; |
550 int savInt; |
560 int savInt; |
551 |
561 |
552 if (_INST(binary) == true) { |
562 if (_INST(binary) == true) { |
553 if (_INST(filePointer) != nil) { |
563 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
554 if (_INST(mode) != _writeonly) { |
564 FILE *f; |
555 FILE *f; |
565 unsigned char hi, low; |
556 unsigned char hi, low; |
566 int cnt; |
557 int cnt; |
567 |
558 |
568 savInt = _immediateInterrupt; |
559 savInt = _immediateInterrupt; |
569 _immediateInterrupt = 1; |
560 _immediateInterrupt = 1; |
570 f = MKFD(_INST(filePointer)); |
561 f = MKFD(_INST(filePointer)); |
571 do { |
562 do { |
572 if (_INST(buffered) == false) { |
563 if (_INST(buffered) == false) { |
573 cnt = read(fileno(f), &hi, 1); |
564 cnt = read(fileno(f), &hi, 1); |
574 } else { |
565 } else { |
575 if (_INST(mode) == _readwrite) |
566 if (_INST(mode) == _readwrite) |
576 fseek(f, 0L, 1); /* needed in stdio */ |
567 fseek(f, 0L, 1); /* needed in stdio */ |
577 cnt = fread(&hi, 1, 1, f); |
568 cnt = fread(&hi, 1, 1, f); |
578 } |
569 } |
579 } while ((cnt < 0) && (errno == EINTR)); |
570 } while ((cnt < 0) && (errno == EINTR)); |
580 |
571 |
581 if (cnt < 0) { |
572 if (cnt < 0) { |
|
573 _immediateInterrupt = savInt; |
|
574 RETURN ( nil ); |
|
575 } |
|
576 do { |
|
577 if (_INST(buffered) == false) { |
|
578 cnt = read(fileno(f), &low, 1); |
|
579 } else { |
|
580 if (_INST(mode) == _readwrite) |
|
581 fseek(f, 0L, 1); /* needed in stdio */ |
|
582 cnt = fread(&low, 1, 1, f); |
|
583 } |
|
584 } while ((cnt < 0) && (errno == EINTR)); |
|
585 |
|
586 _immediateInterrupt = savInt; |
582 _immediateInterrupt = savInt; |
587 if (cnt < 0) { |
583 RETURN ( nil ); |
588 if (_INST(position) != nil) { |
584 } |
589 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
585 do { |
590 } |
586 if (_INST(buffered) == false) { |
591 RETURN ( _MKSMALLINT(hi & 0xFF) ); |
587 cnt = read(fileno(f), &low, 1); |
592 } |
588 } else { |
|
589 if (_INST(mode) == _readwrite) |
|
590 fseek(f, 0L, 1); /* needed in stdio */ |
|
591 cnt = fread(&low, 1, 1, f); |
|
592 } |
|
593 } while ((cnt < 0) && (errno == EINTR)); |
|
594 |
|
595 _immediateInterrupt = savInt; |
|
596 if (cnt < 0) { |
593 if (_INST(position) != nil) { |
597 if (_INST(position) != nil) { |
594 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
598 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
595 } |
599 } |
596 RETURN ( _MKSMALLINT(((hi & 0xFF)<<8) | (low & 0xFF)) ); |
600 RETURN ( _MKSMALLINT(hi & 0xFF) ); |
597 } |
601 } |
598 } |
602 if (_INST(position) != nil) { |
599 } |
603 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
600 %} |
604 } |
601 . |
605 RETURN ( _MKSMALLINT(((hi & 0xFF)<<8) | (low & 0xFF)) ); |
602 %{ |
606 } |
|
607 } |
|
608 %} |
|
609 . |
|
610 %{ /* STACK: 2000 */ |
603 FILE *f; |
611 FILE *f; |
604 int len; |
612 int len; |
605 char buffer[1024]; |
613 char buffer[1024]; |
606 int ch, savInt; |
614 int ch, savInt; |
607 int cnt = 0; |
615 int cnt = 0; |
608 extern int _immediateInterrupt; |
616 extern int _immediateInterrupt; |
609 |
617 |
610 if (_INST(filePointer) != nil) { |
618 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
611 if (_INST(mode) != _writeonly) { |
619 f = MKFD(_INST(filePointer)); |
612 f = MKFD(_INST(filePointer)); |
620 savInt = _immediateInterrupt; |
613 savInt = _immediateInterrupt; |
621 _immediateInterrupt = 1; |
614 _immediateInterrupt = 1; |
622 |
615 |
623 /* text-mode */ |
616 /* text-mode */ |
624 for (;;) { |
617 for (;;) { |
625 ch = getc(f); |
618 ch = getc(f); |
626 cnt++; |
619 cnt++; |
627 |
620 |
628 if (ch >= ' ') break; |
621 if (ch >= ' ') break; |
629 if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
622 if ((ch != ' ') && (ch != '\t') && (ch != '\r') |
630 && (ch != '\n') && (ch != 0x0b)) break; |
623 && (ch != '\n') && (ch != 0x0b)) break; |
631 } |
624 } |
632 ungetc(ch, f); |
625 ungetc(ch, f); |
633 cnt--; |
626 cnt--; |
634 |
627 |
635 len = 0; |
628 len = 0; |
636 for (;;) { |
629 for (;;) { |
637 ch = getc(f); |
630 ch = getc(f); |
638 if (ch == EOF) |
631 if (ch == EOF) |
639 break; |
632 break; |
640 ch &= 0xFF; |
633 ch &= 0xFF; |
641 if (! (((ch >= 'a') && (ch <= 'z')) || |
634 if (! (((ch >= 'a') && (ch <= 'z')) || |
642 ((ch >= 'A') && (ch <= 'Z')) || |
635 ((ch >= 'A') && (ch <= 'Z')) || |
643 ((ch >= '0') && (ch <= '9')))) { |
636 ((ch >= '0') && (ch <= '9')))) { |
644 ungetc(ch, f); |
637 ungetc(ch, f); |
645 break; |
638 break; |
646 } |
639 } |
647 cnt++; |
640 cnt++; |
648 buffer[len++] = ch; |
641 buffer[len++] = ch; |
649 if (len >= sizeof(buffer)-1) { |
642 if (len >= sizeof(buffer)-1) { |
650 /* emergency */ |
643 /* emergency */ |
651 break; |
644 break; |
652 } |
645 } |
653 } |
646 } |
654 _immediateInterrupt = savInt; |
647 _immediateInterrupt = savInt; |
655 |
648 |
656 if (_INST(position) != nil) { |
649 if (_INST(position) != nil) { |
657 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + cnt); |
650 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + cnt); |
658 } |
651 } |
659 buffer[len] = '\0'; |
652 buffer[len] = '\0'; |
660 if (len != 0) { |
653 if (len != 0) { |
661 RETURN ( _MKSTRING(buffer COMMA_CON) ); |
654 RETURN ( _MKSTRING(buffer COMMA_CON) ); |
662 } |
655 } |
663 RETURN ( nil ); |
656 RETURN ( nil ); |
|
657 } |
|
658 } |
664 } |
659 %} |
665 %} |
660 . |
666 . |
661 filePointer isNil ifTrue:[^ self errorNotOpen]. |
667 filePointer isNil ifTrue:[^ self errorNotOpen]. |
662 self errorWriteOnly |
668 self errorWriteOnly |
672 %{ /* NOCONTEXT */ |
678 %{ /* NOCONTEXT */ |
673 int savInt; |
679 int savInt; |
674 extern int _immediateInterrupt; |
680 extern int _immediateInterrupt; |
675 |
681 |
676 if (_INST(binary) == true) { |
682 if (_INST(binary) == true) { |
677 if (_INST(filePointer) != nil) { |
683 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
678 if (_INST(mode) != _writeonly) { |
684 FILE *f; |
679 FILE *f; |
685 int first, second; |
680 int first, second; |
686 short value; |
681 short value; |
687 |
682 |
688 savInt = _immediateInterrupt; |
683 savInt = _immediateInterrupt; |
689 _immediateInterrupt = 1; |
684 _immediateInterrupt = 1; |
690 |
685 |
691 f = MKFD(_INST(filePointer)); |
686 f = MKFD(_INST(filePointer)); |
692 first = getc(f); |
687 first = getc(f); |
693 if (first == EOF) { |
688 if (first == EOF) { |
|
689 _immediateInterrupt = savInt; |
|
690 RETURN ( nil ); |
|
691 } |
|
692 second = getc(f); |
|
693 _immediateInterrupt = savInt; |
694 _immediateInterrupt = savInt; |
694 |
695 RETURN ( nil ); |
695 if (second == EOF) { |
696 } |
696 RETURN ( nil ); |
697 second = getc(f); |
697 } |
698 _immediateInterrupt = savInt; |
698 if (_INST(position) != nil) { |
699 |
699 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
700 if (second == EOF) { |
700 } |
701 RETURN ( nil ); |
701 if (msbFlag == true) { |
702 } |
702 RETURN ( _MKSMALLINT(((first & 0xFF)<<8) | (second & 0xFF)) ); |
703 if (_INST(position) != nil) { |
703 } |
704 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
704 RETURN ( _MKSMALLINT(((second & 0xFF)<<8) | (first & 0xFF)) ); |
705 } |
705 } |
706 if (msbFlag == true) { |
|
707 RETURN ( _MKSMALLINT(((first & 0xFF)<<8) | (second & 0xFF)) ); |
|
708 } |
|
709 RETURN ( _MKSMALLINT(((second & 0xFF)<<8) | (first & 0xFF)) ); |
706 } |
710 } |
707 } |
711 } |
708 %} |
712 %} |
709 . |
713 . |
710 filePointer isNil ifTrue:[^ self errorNotOpen]. |
714 filePointer isNil ifTrue:[^ self errorNotOpen]. |
723 %{ /* NOCONTEXT */ |
727 %{ /* NOCONTEXT */ |
724 int savInt; |
728 int savInt; |
725 extern int _immediateInterrupt; |
729 extern int _immediateInterrupt; |
726 |
730 |
727 if (_INST(binary) == true) { |
731 if (_INST(binary) == true) { |
728 if (_INST(filePointer) != nil) { |
732 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
729 if (_INST(mode) != _writeonly) { |
733 FILE *f; |
730 FILE *f; |
734 int first, second; |
731 int first, second; |
735 |
732 |
736 savInt = _immediateInterrupt; |
733 savInt = _immediateInterrupt; |
737 _immediateInterrupt = 1; |
734 _immediateInterrupt = 1; |
738 f = MKFD(_INST(filePointer)); |
735 f = MKFD(_INST(filePointer)); |
739 first = getc(f); |
736 first = getc(f); |
740 if (first == EOF) { |
737 if (first == EOF) { |
|
738 _immediateInterrupt = savInt; |
|
739 RETURN ( nil ); |
|
740 } |
|
741 second = getc(f); |
|
742 _immediateInterrupt = savInt; |
741 _immediateInterrupt = savInt; |
743 |
742 RETURN ( nil ); |
744 if (second == EOF) { |
743 } |
745 RETURN ( nil ); |
744 second = getc(f); |
746 } |
745 _immediateInterrupt = savInt; |
747 if (_INST(position) != nil) { |
746 |
748 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
747 if (second == EOF) { |
749 } |
748 RETURN ( nil ); |
750 if (msbFlag == true) { |
749 } |
751 RETURN ( _MKSMALLINT(((first & 0xFF)<<8) | (second & 0xFF)) ); |
750 if (_INST(position) != nil) { |
752 } |
751 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
753 RETURN ( _MKSMALLINT(((second & 0xFF)<<8) | (first & 0xFF)) ); |
752 } |
754 } |
753 if (msbFlag == true) { |
|
754 RETURN ( _MKSMALLINT(((first & 0xFF)<<8) | (second & 0xFF)) ); |
|
755 } |
|
756 RETURN ( _MKSMALLINT(((second & 0xFF)<<8) | (first & 0xFF)) ); |
755 } |
757 } |
756 } |
758 } |
757 %} |
759 %} |
758 . |
760 . |
759 filePointer isNil ifTrue:[^ self errorNotOpen]. |
761 filePointer isNil ifTrue:[^ self errorNotOpen]. |
773 %{ /* NOCONTEXT */ |
775 %{ /* NOCONTEXT */ |
774 int savInt; |
776 int savInt; |
775 extern int _immediateInterrupt; |
777 extern int _immediateInterrupt; |
776 |
778 |
777 if (_INST(binary) == true) { |
779 if (_INST(binary) == true) { |
778 if (_INST(filePointer) != nil) { |
780 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
779 if (_INST(mode) != _writeonly) { |
781 FILE *f; |
780 FILE *f; |
782 int first, second, third, fourth; |
781 int first, second, third, fourth; |
783 int value; |
782 int value; |
784 |
783 |
785 savInt = _immediateInterrupt; |
784 savInt = _immediateInterrupt; |
786 _immediateInterrupt = 1; |
785 _immediateInterrupt = 1; |
787 f = MKFD(_INST(filePointer)); |
786 f = MKFD(_INST(filePointer)); |
788 first = getc(f); |
787 first = getc(f); |
789 if (first == EOF) { |
788 if (first == EOF) { |
|
789 _immediateInterrupt = savInt; |
|
790 RETURN ( nil ); |
|
791 } |
|
792 second = getc(f); |
|
793 if (second == EOF) { |
|
794 _immediateInterrupt = savInt; |
|
795 RETURN ( nil ); |
|
796 } |
|
797 third = getc(f); |
|
798 if (third == EOF) { |
|
799 _immediateInterrupt = savInt; |
|
800 RETURN ( nil ); |
|
801 } |
|
802 fourth = getc(f); |
|
803 _immediateInterrupt = savInt; |
790 _immediateInterrupt = savInt; |
804 if (fourth == EOF) { |
791 RETURN ( nil ); |
805 RETURN ( nil ); |
792 } |
806 } |
793 second = getc(f); |
807 if (_INST(position) != nil) { |
794 if (second == EOF) { |
808 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
795 _immediateInterrupt = savInt; |
809 } |
796 RETURN ( nil ); |
810 if (msbFlag == true) { |
797 } |
811 value = ((first & 0xFF) << 24) |
798 third = getc(f); |
812 | ((second & 0xFF) << 16) |
799 if (third == EOF) { |
813 | ((third & 0xFF) << 8) |
800 _immediateInterrupt = savInt; |
814 | (fourth & 0xFF); |
801 RETURN ( nil ); |
815 } else { |
802 } |
816 value = ((fourth & 0xFF) << 24) |
803 fourth = getc(f); |
817 | ((third & 0xFF) << 16) |
804 _immediateInterrupt = savInt; |
818 | ((second & 0xFF) << 8) |
805 if (fourth == EOF) { |
819 | (first & 0xFF); |
806 RETURN ( nil ); |
820 } |
807 } |
821 if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
808 if (_INST(position) != nil) { |
822 RETURN ( _MKSMALLINT(value)); |
809 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
823 } |
810 } |
824 RETURN ( _makeLarge(value) ); |
811 if (msbFlag == true) { |
825 } |
812 value = ((first & 0xFF) << 24) |
|
813 | ((second & 0xFF) << 16) |
|
814 | ((third & 0xFF) << 8) |
|
815 | (fourth & 0xFF); |
|
816 } else { |
|
817 value = ((fourth & 0xFF) << 24) |
|
818 | ((third & 0xFF) << 16) |
|
819 | ((second & 0xFF) << 8) |
|
820 | (first & 0xFF); |
|
821 } |
|
822 if ((value >= _MIN_INT) && (value <= _MAX_INT)) { |
|
823 RETURN ( _MKSMALLINT(value)); |
|
824 } |
|
825 RETURN ( _makeLarge(value) ); |
826 } |
826 } |
827 } |
827 } |
828 %} |
828 %} |
829 . |
829 . |
830 filePointer isNil ifTrue:[^ self errorNotOpen]. |
830 filePointer isNil ifTrue:[^ self errorNotOpen]. |
845 int savInt; |
845 int savInt; |
846 extern int _immediateInterrupt; |
846 extern int _immediateInterrupt; |
847 extern OBJ _makeULarge(); |
847 extern OBJ _makeULarge(); |
848 |
848 |
849 if (_INST(binary) == true) { |
849 if (_INST(binary) == true) { |
850 if (_INST(filePointer) != nil) { |
850 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
851 if (_INST(mode) != _writeonly) { |
851 FILE *f; |
852 FILE *f; |
852 int first, second, third, fourth; |
853 int first, second, third, fourth; |
853 unsigned int value; |
854 unsigned int value; |
854 |
855 |
855 savInt = _immediateInterrupt; |
856 savInt = _immediateInterrupt; |
856 _immediateInterrupt = 1; |
857 _immediateInterrupt = 1; |
857 f = MKFD(_INST(filePointer)); |
858 f = MKFD(_INST(filePointer)); |
858 first = getc(f); |
859 first = getc(f); |
859 if (first == EOF) { |
860 if (first == EOF) { |
|
861 _immediateInterrupt = savInt; |
|
862 RETURN ( nil ); |
|
863 } |
|
864 second = getc(f); |
|
865 if (second == EOF) { |
|
866 _immediateInterrupt = savInt; |
|
867 RETURN ( nil ); |
|
868 } |
|
869 third = getc(f); |
|
870 if (third == EOF) { |
|
871 _immediateInterrupt = savInt; |
|
872 RETURN ( nil ); |
|
873 } |
|
874 fourth = getc(f); |
|
875 _immediateInterrupt = savInt; |
860 _immediateInterrupt = savInt; |
876 if (fourth == EOF) { |
861 RETURN ( nil ); |
877 RETURN ( nil ); |
862 } |
878 } |
863 second = getc(f); |
879 if (_INST(position) != nil) { |
864 if (second == EOF) { |
880 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
865 _immediateInterrupt = savInt; |
881 } |
866 RETURN ( nil ); |
882 if (msbFlag == true) { |
867 } |
883 value = ((first & 0xFF) << 24) |
868 third = getc(f); |
884 | ((second & 0xFF) << 16) |
869 if (third == EOF) { |
885 | ((third & 0xFF) << 8) |
870 _immediateInterrupt = savInt; |
886 | (fourth & 0xFF); |
871 RETURN ( nil ); |
887 } else { |
872 } |
888 value = ((fourth & 0xFF) << 24) |
873 fourth = getc(f); |
889 | ((third & 0xFF) << 16) |
874 _immediateInterrupt = savInt; |
890 | ((second & 0xFF) << 8) |
875 if (fourth == EOF) { |
891 | (first & 0xFF); |
876 RETURN ( nil ); |
892 } |
877 } |
893 if (value <= _MAX_INT) { |
878 if (_INST(position) != nil) { |
894 RETURN ( _MKSMALLINT(value)); |
879 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
895 } |
880 } |
896 RETURN ( _makeULarge(value) ); |
881 if (msbFlag == true) { |
897 } |
882 value = ((first & 0xFF) << 24) |
|
883 | ((second & 0xFF) << 16) |
|
884 | ((third & 0xFF) << 8) |
|
885 | (fourth & 0xFF); |
|
886 } else { |
|
887 value = ((fourth & 0xFF) << 24) |
|
888 | ((third & 0xFF) << 16) |
|
889 | ((second & 0xFF) << 8) |
|
890 | (first & 0xFF); |
|
891 } |
|
892 if (value <= _MAX_INT) { |
|
893 RETURN ( _MKSMALLINT(value)); |
|
894 } |
|
895 RETURN ( _makeULarge(value) ); |
898 } |
896 } |
899 } |
897 } |
900 %} |
898 %} |
901 . |
899 . |
902 filePointer isNil ifTrue:[^ self errorNotOpen]. |
900 filePointer isNil ifTrue:[^ self errorNotOpen]. |
927 extern errno; |
925 extern errno; |
928 OBJ pos; |
926 OBJ pos; |
929 int cnt, savInt; |
927 int cnt, savInt; |
930 extern int _immediateInterrupt; |
928 extern int _immediateInterrupt; |
931 |
929 |
932 if (_INST(filePointer) != nil) { |
930 if ((_INST(filePointer) != nil) && (_INST(mode) != _readonly)) { |
933 if (_INST(mode) != _readonly) { |
931 if (_isSmallInteger(aByteValue)) { |
934 if (_isSmallInteger(aByteValue)) { |
932 c = _intVal(aByteValue); |
935 c = _intVal(aByteValue); |
933 f = MKFD(_INST(filePointer)); |
936 f = MKFD(_INST(filePointer)); |
934 savInt = _immediateInterrupt; |
937 savInt = _immediateInterrupt; |
935 _immediateInterrupt = 1; |
938 _immediateInterrupt = 1; |
936 #ifdef OLD |
|
937 if (_INST(buffered) == false) { |
|
938 cnt = write(fileno(f), &c, 1); |
|
939 } else |
|
940 #endif |
|
941 { |
|
942 if (_INST(mode) == _readwrite) |
|
943 fseek(f, 0L, 1); /* needed in stdio */ |
|
944 cnt = fwrite(&c, 1, 1, f); |
|
945 #ifndef OLD |
939 if (_INST(buffered) == false) { |
946 if (_INST(buffered) == false) { |
940 cnt = write(fileno(f), &c, 1); |
947 fflush(f); |
941 } else { |
948 } |
942 if (_INST(mode) == _readwrite) |
949 #endif |
943 fseek(f, 0L, 1); /* needed in stdio */ |
950 } |
944 cnt = fwrite(&c, 1, 1, f); |
951 _immediateInterrupt = savInt; |
945 } |
952 if (cnt == 1) { |
946 _immediateInterrupt = savInt; |
953 pos = _INST(position); |
947 if (cnt == 1) { |
954 if (pos != nil) |
948 pos = _INST(position); |
955 _INST(position) = _MKSMALLINT(_intVal(pos) + 1); |
949 if (pos != nil) |
956 RETURN ( self ); |
950 _INST(position) = _MKSMALLINT(_intVal(pos) + 1); |
957 } |
951 RETURN ( self ); |
958 ErrorNumber = _MKSMALLINT(errno); |
952 } |
959 RETURN (nil); |
953 ErrorNumber = _MKSMALLINT(errno); |
|
954 RETURN (nil); |
|
955 } |
|
956 } |
960 } |
957 } |
961 } |
958 %} |
962 %} |
959 . |
963 . |
960 filePointer isNil ifTrue:[^ self errorNotOpen]. |
964 filePointer isNil ifTrue:[^ self errorNotOpen]. |
997 objSize = _Size(anObject) - OHDR_SIZE; |
1001 objSize = _Size(anObject) - OHDR_SIZE; |
998 if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
1002 if ( (offs >= 0) && (cnt >= 0) && (objSize >= (cnt + offs)) ) { |
999 cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs; |
1003 cp = (char *)_InstPtr(anObject) + OHDR_SIZE + offs; |
1000 savInt = _immediateInterrupt; |
1004 savInt = _immediateInterrupt; |
1001 _immediateInterrupt = 1; |
1005 _immediateInterrupt = 1; |
|
1006 #ifdef OLD |
1002 if (_INST(buffered) == false) { |
1007 if (_INST(buffered) == false) { |
1003 cnt = write(fileno(f), cp, cnt); |
1008 cnt = write(fileno(f), cp, cnt); |
1004 } else { |
1009 } else |
|
1010 #endif |
|
1011 { |
1005 if (_INST(mode) == _readwrite) |
1012 if (_INST(mode) == _readwrite) |
1006 fseek(f, 0L, 1); /* needed in stdio */ |
1013 fseek(f, 0L, 1); /* needed in stdio */ |
1007 cnt = fwrite(cp, 1, cnt, f); |
1014 cnt = fwrite(cp, 1, cnt, f); |
1008 } |
1015 } |
|
1016 #ifndef OLD |
|
1017 if (_INST(buffered) == false) { |
|
1018 fflush(f); |
|
1019 } |
|
1020 #endif |
1009 _immediateInterrupt = savInt; |
1021 _immediateInterrupt = savInt; |
1010 if (cnt >= 0) { |
1022 if (cnt >= 0) { |
1011 pos = _INST(position); |
1023 pos = _INST(position); |
1012 if (pos != nil) |
1024 if (pos != nil) |
1013 _INST(position) = _MKSMALLINT(_intVal(pos) + cnt); |
1025 _INST(position) = _MKSMALLINT(_intVal(pos) + cnt); |
1065 } |
1077 } |
1066 |
1078 |
1067 f = MKFD(_INST(filePointer)); |
1079 f = MKFD(_INST(filePointer)); |
1068 savInt = _immediateInterrupt; |
1080 savInt = _immediateInterrupt; |
1069 _immediateInterrupt = 1; |
1081 _immediateInterrupt = 1; |
|
1082 #ifdef OLD |
1070 if (_INST(buffered) == false) { |
1083 if (_INST(buffered) == false) { |
1071 cnt = write(fileno(f), bytes, 2); |
1084 cnt = write(fileno(f), bytes, 2); |
1072 } else { |
1085 } else |
|
1086 #endif |
|
1087 { |
1073 if (_INST(mode) == _readwrite) |
1088 if (_INST(mode) == _readwrite) |
1074 fseek(f, 0L, 1); /* needed in stdio */ |
1089 fseek(f, 0L, 1); /* needed in stdio */ |
1075 cnt = fwrite(bytes, 1, 2, f); |
1090 cnt = fwrite(bytes, 1, 2, f); |
1076 } |
1091 } |
|
1092 #ifndef OLD |
|
1093 if (_INST(buffered) == false) { |
|
1094 fflush(f); |
|
1095 } |
|
1096 #endif |
1077 _immediateInterrupt = savInt; |
1097 _immediateInterrupt = savInt; |
1078 if (cnt == 2) { |
1098 if (cnt == 2) { |
1079 if (_INST(position) != nil) { |
1099 if (_INST(position) != nil) { |
1080 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
1100 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 2); |
1081 } |
1101 } |
1129 } |
1149 } |
1130 |
1150 |
1131 f = MKFD(_INST(filePointer)); |
1151 f = MKFD(_INST(filePointer)); |
1132 savInt = _immediateInterrupt; |
1152 savInt = _immediateInterrupt; |
1133 _immediateInterrupt = 1; |
1153 _immediateInterrupt = 1; |
|
1154 #ifdef OLD |
1134 if (_INST(buffered) == false) { |
1155 if (_INST(buffered) == false) { |
1135 cnt = write(fileno(f), bytes, 4); |
1156 cnt = write(fileno(f), bytes, 4); |
1136 } else { |
1157 } else |
|
1158 #endif |
|
1159 { |
1137 cnt = fwrite(bytes, 1, 4, f); |
1160 cnt = fwrite(bytes, 1, 4, f); |
1138 } |
1161 } |
|
1162 #ifndef OLD |
|
1163 if (_INST(buffered) == false) { |
|
1164 fflush(f); |
|
1165 } |
|
1166 #endif |
1139 _immediateInterrupt = savInt; |
1167 _immediateInterrupt = savInt; |
1140 if (cnt == 4) { |
1168 if (cnt == 4) { |
1141 if (_INST(position) != nil) { |
1169 if (_INST(position) != nil) { |
1142 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
1170 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 4); |
1143 } |
1171 } |
1221 if (_INST(filePointer) != nil) { |
1252 if (_INST(filePointer) != nil) { |
1222 if (_INST(mode) != _writeonly) { |
1253 if (_INST(mode) != _writeonly) { |
1223 f = MKFD(_INST(filePointer)); |
1254 f = MKFD(_INST(filePointer)); |
1224 savInt = _immediateInterrupt; |
1255 savInt = _immediateInterrupt; |
1225 _immediateInterrupt = 1; |
1256 _immediateInterrupt = 1; |
1226 do { |
1257 do { |
|
1258 #ifdef OLD |
1227 if (_INST(buffered) == false) { |
1259 if (_INST(buffered) == false) { |
1228 if (read(fileno(f), &ch, 1) != 1) |
1260 if (read(fileno(f), &ch, 1) != 1) |
1229 c = EOF; |
1261 c = EOF; |
1230 else |
1262 else |
1231 c = ch; |
1263 c = ch; |
1232 } else { |
1264 } else |
|
1265 #endif |
|
1266 { |
1233 if (_INST(mode) == _readwrite) |
1267 if (_INST(mode) == _readwrite) |
1234 fseek(f, 0L, 1); /* needed in stdio */ |
1268 fseek(f, 0L, 1); /* needed in stdio */ |
1235 c = getc(f); |
1269 c = getc(f); |
1236 } |
1270 } |
1237 } while ((c < 0) && (errno == EINTR)); |
1271 } while ((c < 0) && (errno == EINTR)); |
1238 |
1272 |
1239 _immediateInterrupt = savInt; |
1273 _immediateInterrupt = savInt; |
1240 if (c != EOF) { |
1274 if (c != EOF) { |
1241 pos = _INST(position); |
1275 pos = _INST(position); |
1242 if (_isSmallInteger(pos)) { |
1276 if (_isSmallInteger(pos)) { |
1317 doWrite: |
1349 doWrite: |
1318 f = MKFD(_INST(filePointer)); |
1350 f = MKFD(_INST(filePointer)); |
1319 |
1351 |
1320 savInt = _immediateInterrupt; |
1352 savInt = _immediateInterrupt; |
1321 _immediateInterrupt = 1; |
1353 _immediateInterrupt = 1; |
|
1354 #ifdef OLD |
1322 if (_INST(buffered) == false) { |
1355 if (_INST(buffered) == false) { |
1323 cnt = write(fileno(f), &c, 1); |
1356 cnt = write(fileno(f), &c, 1); |
1324 } else { |
1357 } else |
|
1358 #endif |
|
1359 { |
1325 if (_INST(mode) == _readwrite) |
1360 if (_INST(mode) == _readwrite) |
1326 fseek(f, 0L, 1); /* needed in stdio */ |
1361 fseek(f, 0L, 1); /* needed in stdio */ |
1327 cnt = fwrite(&c, 1, 1, f); |
1362 cnt = fwrite(&c, 1, 1, f); |
1328 } |
1363 } |
|
1364 #ifndef OLD |
|
1365 if (_INST(buffered) == false) { |
|
1366 fflush(f); |
|
1367 } |
|
1368 #endif |
1329 _immediateInterrupt = savInt; |
1369 _immediateInterrupt = savInt; |
1330 if (cnt == 1) { |
1370 if (cnt == 1) { |
1331 pos = _INST(position); |
1371 pos = _INST(position); |
1332 if (pos != nil) { |
1372 if (pos != nil) { |
1333 _INST(position) = _MKSMALLINT(_intVal(pos) + 1); |
1373 _INST(position) = _MKSMALLINT(_intVal(pos) + 1); |
1383 if (cp != NULL) { |
1423 if (cp != NULL) { |
1384 f = MKFD(_INST(filePointer)); |
1424 f = MKFD(_INST(filePointer)); |
1385 |
1425 |
1386 savInt = _immediateInterrupt; |
1426 savInt = _immediateInterrupt; |
1387 _immediateInterrupt = 1; |
1427 _immediateInterrupt = 1; |
|
1428 #ifdef OLD |
1388 if (_INST(buffered) == false) { |
1429 if (_INST(buffered) == false) { |
1389 cnt = write(fileno(f), cp, len); |
1430 cnt = write(fileno(f), cp, len); |
1390 } else { |
1431 } else |
|
1432 #endif |
|
1433 { |
1391 if (_INST(mode) == _readwrite) |
1434 if (_INST(mode) == _readwrite) |
1392 fseek(f, 0L, 1); /* needed in stdio */ |
1435 fseek(f, 0L, 1); /* needed in stdio */ |
1393 cnt = fwrite(cp, 1, len, f); |
1436 cnt = fwrite(cp, 1, len, f); |
1394 } |
1437 } |
|
1438 #ifndef OLD |
|
1439 if (_INST(buffered) == false) { |
|
1440 fflush(f); |
|
1441 } |
|
1442 #endif |
1395 _immediateInterrupt = savInt; |
1443 _immediateInterrupt = savInt; |
1396 if (cnt == len) { |
1444 if (cnt == len) { |
1397 pos = _INST(position); |
1445 pos = _INST(position); |
1398 if (pos != nil) { |
1446 if (pos != nil) { |
1399 _INST(position) = _MKSMALLINT(_intVal(pos) + len); |
1447 _INST(position) = _MKSMALLINT(_intVal(pos) + len); |
1452 index2 = len; |
1500 index2 = len; |
1453 |
1501 |
1454 savInt = _immediateInterrupt; |
1502 savInt = _immediateInterrupt; |
1455 _immediateInterrupt = 1; |
1503 _immediateInterrupt = 1; |
1456 len = index2 - index1 + 1; |
1504 len = index2 - index1 + 1; |
|
1505 #ifdef OLD |
1457 if (_INST(buffered) == false) { |
1506 if (_INST(buffered) == false) { |
1458 cnt = write(fileno(f), cp + index1 - 1, len); |
1507 cnt = write(fileno(f), cp + index1 - 1, len); |
1459 } else { |
1508 } else |
|
1509 #endif |
|
1510 { |
1460 if (_INST(mode) == _readwrite) |
1511 if (_INST(mode) == _readwrite) |
1461 fseek(f, 0L, 1); /* needed in stdio */ |
1512 fseek(f, 0L, 1); /* needed in stdio */ |
1462 cnt = fwrite(cp + index1 - 1, 1, len, f); |
1513 cnt = fwrite(cp + index1 - 1, 1, len, f); |
1463 } |
1514 } |
|
1515 #ifndef OLD |
|
1516 if (_INST(buffered) == false) { |
|
1517 fflush(f); |
|
1518 } |
|
1519 #endif |
1464 _immediateInterrupt = savInt; |
1520 _immediateInterrupt = savInt; |
1465 if (cnt == len) { |
1521 if (cnt == len) { |
1466 if (_INST(position) != nil) { |
1522 if (_INST(position) != nil) { |
1467 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + len); |
1523 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + len); |
1468 } |
1524 } |
1498 if (_INST(binary) != true) { |
1554 if (_INST(binary) != true) { |
1499 f = MKFD(_INST(filePointer)); |
1555 f = MKFD(_INST(filePointer)); |
1500 |
1556 |
1501 savInt = _immediateInterrupt; |
1557 savInt = _immediateInterrupt; |
1502 _immediateInterrupt = 1; |
1558 _immediateInterrupt = 1; |
|
1559 #ifdef OLD |
1503 if (_INST(buffered) == false) { |
1560 if (_INST(buffered) == false) { |
1504 cnt = write(fileno(f), "\n", 1); |
1561 cnt = write(fileno(f), "\n", 1); |
1505 } else { |
1562 } else |
|
1563 #endif |
|
1564 { |
1506 if (_INST(mode) == _readwrite) |
1565 if (_INST(mode) == _readwrite) |
1507 fseek(f, 0L, 1); /* needed in stdio */ |
1566 fseek(f, 0L, 1); /* needed in stdio */ |
1508 cnt = fwrite("\n", 1, 1, f); |
1567 cnt = fwrite("\n", 1, 1, f); |
1509 } |
1568 } |
|
1569 #ifndef OLD |
|
1570 if (_INST(buffered) == false) { |
|
1571 fflush(f); |
|
1572 } |
|
1573 #endif |
1510 _immediateInterrupt = savInt; |
1574 _immediateInterrupt = savInt; |
1511 if (cnt == 1) { |
1575 if (cnt == 1) { |
1512 if (_INST(position) != nil) { |
1576 if (_INST(position) != nil) { |
1513 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
1577 _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + 1); |
1514 } |
1578 } |
1531 "read the next line (characters up to newline). |
1595 "read the next line (characters up to newline). |
1532 Return a string containing those characters excluding the newline. |
1596 Return a string containing those characters excluding the newline. |
1533 If the previous-to-last character is a cr, this is also removed, |
1597 If the previous-to-last character is a cr, this is also removed, |
1534 so its possible to read alien (i.e. ms-dos) text as well." |
1598 so its possible to read alien (i.e. ms-dos) text as well." |
1535 |
1599 |
1536 %{ /* NOCONTEXT */ |
1600 %{ /* STACK:2000 */ |
1537 |
1601 |
1538 FILE *f; |
1602 FILE *f; |
1539 int len; |
1603 int len; |
1540 char buffer[1024*8]; |
1604 char buffer[1024]; |
1541 extern int _immediateInterrupt; |
1605 extern int _immediateInterrupt; |
1542 int savInt; |
1606 int savInt; |
1543 char *rslt; |
1607 char *rslt; |
1544 extern errno; |
1608 extern errno; |
1545 |
1609 int fd; |
1546 if ((_INST(filePointer) != nil) && (_INST(filePointer) != _writeonly)) { |
1610 |
|
1611 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
1547 if (_INST(binary) != true) { |
1612 if (_INST(binary) != true) { |
1548 f = MKFD(_INST(filePointer)); |
1613 f = MKFD(_INST(filePointer)); |
1549 savInt = _immediateInterrupt; |
1614 savInt = _immediateInterrupt; |
1550 _immediateInterrupt = 1; |
1615 _immediateInterrupt = 1; |
1551 buffer[0] = 0; |
1616 buffer[0] = 0; |
|
1617 |
|
1618 #ifndef OLD |
|
1619 if (_INST(mode) == _readwrite) |
|
1620 fseek(f, 0L, 1); /* needed in stdio */ |
|
1621 #endif |
|
1622 #ifdef OLD |
1552 if (_INST(buffered) == true) { |
1623 if (_INST(buffered) == true) { |
1553 do { |
1624 #endif |
|
1625 do { |
1554 rslt = fgets(buffer, sizeof(buffer), f); |
1626 rslt = fgets(buffer, sizeof(buffer), f); |
1555 } while ((rslt == NULL) && (errno == EINTR)); |
1627 } while ((rslt == NULL) && (errno == EINTR)); |
|
1628 #ifdef OLD |
1556 } else { |
1629 } else { |
1557 rslt = buffer; |
1630 rslt = buffer; |
|
1631 fd = fileno(f); |
1558 for (;;) { |
1632 for (;;) { |
1559 do { |
1633 do { |
1560 len = read(fileno(f), rslt, 1); |
1634 len = read(fd, rslt, 1); |
1561 } while ((len < 0) && (errno == EINTR)); |
1635 } while ((len < 0) && (errno == EINTR)); |
1562 if (len <= 0) { |
1636 if (len <= 0) { |
1563 if (rslt == buffer) { |
1637 if (rslt == buffer) { |
1564 rslt = NULL; |
1638 rslt = NULL; |
1565 } else { |
1639 } else { |
1566 *rslt = '\0'; |
1640 *rslt = '\0'; |
1624 s = (char *) _stringVal(aString); |
1699 s = (char *) _stringVal(aString); |
1625 len = _stringSize(aString); |
1700 len = _stringSize(aString); |
1626 |
1701 |
1627 savInt = _immediateInterrupt; |
1702 savInt = _immediateInterrupt; |
1628 _immediateInterrupt = 1; |
1703 _immediateInterrupt = 1; |
|
1704 #ifdef OLD |
1629 if (_INST(buffered) == false) { |
1705 if (_INST(buffered) == false) { |
1630 cnt = write(fileno(f), s, len); |
1706 cnt = write(fileno(f), s, len); |
1631 } else { |
1707 } else |
|
1708 #endif |
|
1709 { |
1632 if (_INST(mode) == _readwrite) |
1710 if (_INST(mode) == _readwrite) |
1633 fseek(f, 0L, 1); /* needed in stdio */ |
1711 fseek(f, 0L, 1); /* needed in stdio */ |
1634 cnt = fwrite(s, 1, len, f); |
1712 cnt = fwrite(s, 1, len, f); |
1635 } |
1713 } |
1636 if (cnt == len) { |
1714 if (cnt == len) { |
|
1715 #ifdef OLD |
1637 if (_INST(buffered) == false) { |
1716 if (_INST(buffered) == false) { |
1638 cnt = write(fileno(f), "\n", 1); |
1717 cnt = write(fileno(f), "\n", 1); |
1639 } else { |
1718 } else |
|
1719 #endif |
|
1720 { |
1640 cnt = fwrite("\n", 1, 1, f); |
1721 cnt = fwrite("\n", 1, 1, f); |
1641 } |
1722 } |
|
1723 #ifndef OLD |
|
1724 if (_INST(buffered) == false) { |
|
1725 fflush(f); |
|
1726 } |
|
1727 #endif |
1642 if (cnt == 1) { |
1728 if (cnt == 1) { |
1643 pos = _INST(position); |
1729 pos = _INST(position); |
1644 if (pos != nil) { |
1730 if (pos != nil) { |
1645 _INST(position) = _MKSMALLINT(_intVal(pos)+len+1); |
1731 _INST(position) = _MKSMALLINT(_intVal(pos)+len+1); |
1646 } |
1732 } |
1672 |
1758 |
1673 (mode == #readonly) ifTrue:[^ self errorReadOnly]. |
1759 (mode == #readonly) ifTrue:[^ self errorReadOnly]. |
1674 filePointer isNil ifTrue:[^ self errorNotOpen]. |
1760 filePointer isNil ifTrue:[^ self errorNotOpen]. |
1675 srcFilePointer := aStream filePointer. |
1761 srcFilePointer := aStream filePointer. |
1676 srcFilePointer isNil ifTrue:[^ aStream errorNotOpen]. |
1762 srcFilePointer isNil ifTrue:[^ aStream errorNotOpen]. |
1677 %{ |
1763 |
|
1764 %{ /* STACK:2000 */ |
1678 FILE *dst, *src; |
1765 FILE *dst, *src; |
1679 char *matchString; |
1766 char *matchString; |
1680 int matchLen = 0; |
1767 int matchLen = 0; |
1681 char buffer[1024*8]; |
1768 char buffer[1024]; |
1682 extern int _immediateInterrupt; |
1769 extern int _immediateInterrupt; |
1683 int savInt; |
1770 int savInt; |
1684 |
1771 |
1685 if (_isSmallInteger(srcFilePointer) && (_INST(buffered) == true)) { |
1772 if (_isSmallInteger(srcFilePointer) |
|
1773 #ifdef OLD |
|
1774 && (_INST(buffered) == true) |
|
1775 #endif |
|
1776 ) { |
1686 if ((aStringOrNil == nil) || _isString(aStringOrNil)) { |
1777 if ((aStringOrNil == nil) || _isString(aStringOrNil)) { |
1687 if (aStringOrNil != nil) { |
1778 if (aStringOrNil != nil) { |
1688 matchString = (char *) _stringVal(aStringOrNil); |
1779 matchString = (char *) _stringVal(aStringOrNil); |
1689 matchLen = _stringSize(aStringOrNil); |
1780 matchLen = _stringSize(aStringOrNil); |
1690 } |
1781 } |
1734 l = _stringSize(aString); |
1831 l = _stringSize(aString); |
1735 |
1832 |
1736 f = MKFD(_INST(filePointer)); |
1833 f = MKFD(_INST(filePointer)); |
1737 firstpos = ftell(f); |
1834 firstpos = ftell(f); |
1738 for (;;) { |
1835 for (;;) { |
|
1836 if (_INST(mode) == _readwrite) |
|
1837 fseek(f, 0L, 1); /* needed in stdio */ |
1739 lastpos = ftell(f); |
1838 lastpos = ftell(f); |
1740 savInt = _immediateInterrupt; |
1839 savInt = _immediateInterrupt; |
1741 _immediateInterrupt = 1; |
1840 _immediateInterrupt = 1; |
1742 do { |
1841 do { |
1743 cp = fgets(buffer, sizeof(buffer), f); |
1842 cp = fgets(buffer, sizeof(buffer), f); |
1744 } while ((cp == NULL) && (errno == EINTR)); |
1843 } while ((cp == NULL) && (errno == EINTR)); |
1745 _immediateInterrupt = savInt; |
1844 _immediateInterrupt = savInt; |
1746 if (cp == NULL) { |
1845 if (cp == NULL) { |
1747 fseek(f, firstpos, 0); |
1846 fseek(f, firstpos, 0); |
1748 RETURN ( nil ); |
1847 RETURN ( nil ); |
1749 } |
1848 } |
1942 |
2045 |
1943 skipLine |
2046 skipLine |
1944 "read the next line (characters up to newline) skip only; |
2047 "read the next line (characters up to newline) skip only; |
1945 return nil if EOF reached. Not allowed in binary mode." |
2048 return nil if EOF reached. Not allowed in binary mode." |
1946 |
2049 |
1947 %{ /* NOCONTEXT */ |
2050 %{ /* STACK:2000 */ |
1948 |
2051 |
1949 FILE *f; |
2052 FILE *f; |
1950 char buffer[1024*8]; |
2053 char buffer[1024]; |
1951 extern int _immediateInterrupt; |
2054 extern int _immediateInterrupt; |
1952 int savInt; |
2055 int savInt; |
1953 |
2056 |
1954 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
2057 if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) { |
1955 if (_INST(binary) != true) { |
2058 if (_INST(binary) != true) { |
1956 f = MKFD(_INST(filePointer)); |
2059 f = MKFD(_INST(filePointer)); |
1957 savInt = _immediateInterrupt; |
2060 savInt = _immediateInterrupt; |
1958 _immediateInterrupt = 1; |
2061 _immediateInterrupt = 1; |
|
2062 if (_INST(mode) == _readwrite) |
|
2063 fseek(f, 0L, 1); /* needed in stdio */ |
1959 if (fgets(buffer, sizeof(buffer), f) != NULL) { |
2064 if (fgets(buffer, sizeof(buffer), f) != NULL) { |
1960 _immediateInterrupt = savInt; |
2065 _immediateInterrupt = savInt; |
1961 RETURN ( self ); |
2066 RETURN ( self ); |
1962 } |
2067 } |
1963 _immediateInterrupt = savInt; |
2068 _immediateInterrupt = savInt; |