ExtStream.st
changeset 12 8e03bd717355
parent 10 4f1f9a91e406
child 22 847106305963
equal deleted inserted replaced
11:6bf3080856be 12:8e03bd717355
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 ReadWriteStream subclass:#ExternalStream
    13 ReadWriteStream subclass:#ExternalStream
    14        instanceVariableNames:'filePointer mode buffered binary'
    14        instanceVariableNames:'filePointer mode buffered binary useCRLF'
    15        classVariableNames:'lobby'
    15        classVariableNames:'lobby'
    16        poolDictionaries:''
    16        poolDictionaries:''
    17        category:'Streams-External'
    17        category:'Streams-External'
    18 !
    18 !
    19 
    19 
    27 ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
    27 ExternalStream is abstract; concrete classes are FileStream, PipeStream etc.
    28 ExternalStreams can be in two modes: text (the default) and binary.
    28 ExternalStreams can be in two modes: text (the default) and binary.
    29 In text-mode, the elements read/written are characters; while in binary-mode the basic
    29 In text-mode, the elements read/written are characters; while in binary-mode the basic
    30 elements are bytes which read/write as SmallIntegers in the range 0..255.
    30 elements are bytes which read/write as SmallIntegers in the range 0..255.
    31 
    31 
    32 $Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.5 1993-11-08 02:30:14 claus Exp $
    32 $Header: /cvs/stx/stx/libbasic/Attic/ExtStream.st,v 1.6 1993-12-11 00:46:55 claus Exp $
    33 
    33 
    34 written 88 by claus
    34 written 88 by claus
    35 '!
    35 '!
    36 
    36 
    37 %{
    37 %{
    71 
    71 
    72 new
    72 new
    73     |newStream|
    73     |newStream|
    74 
    74 
    75     newStream := self basicNew.
    75     newStream := self basicNew.
    76     newStream text.
    76     newStream text; buffered:true; useCRLF:false.
    77     ^ newStream
    77     ^ newStream
    78 ! !
    78 ! !
    79 
    79 
    80 !ExternalStream methodsFor:'instance release'!
    80 !ExternalStream methodsFor:'instance release'!
    81 
    81 
    88 closeFile
    88 closeFile
    89     "low level close - may be redefined in subclasses"
    89     "low level close - may be redefined in subclasses"
    90 
    90 
    91 %{  /* NOCONTEXT */
    91 %{  /* NOCONTEXT */
    92 
    92 
    93     fclose(MKFD(_INST(filePointer)));
    93     if (_INST(filePointer) != nil) {
       
    94         int savInt;
       
    95         extern int _immediateInterrupt;
       
    96 
       
    97         savInt = _immediateInterrupt;
       
    98         _immediateInterrupt = 1;
       
    99         fclose(MKFD(_INST(filePointer)));
       
   100         _immediateInterrupt = savInt;
       
   101     }
    94 %}
   102 %}
    95 ! !
   103 ! !
    96 
   104 
    97 !ExternalStream methodsFor:'private'!
   105 !ExternalStream methodsFor:'private'!
    98 
   106 
   210 
   218 
   211 buffered:aBoolean
   219 buffered:aBoolean
   212     "turn buffering on or off - default is on"
   220     "turn buffering on or off - default is on"
   213 
   221 
   214     buffered := aBoolean
   222     buffered := aBoolean
       
   223 !
       
   224 
       
   225 useCRLF:aBoolean
       
   226     "turn on or off CRLF sending (instead of LF only) - default is off"
       
   227 
       
   228     useCRLF := aBoolean
   215 !
   229 !
   216 
   230 
   217 binary
   231 binary
   218     "switch to binary mode - default is text"
   232     "switch to binary mode - default is text"
   219 
   233 
   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                         }
  1153 .
  1181 .
  1154     filePointer isNil ifTrue:[^ self errorNotOpen].
  1182     filePointer isNil ifTrue:[^ self errorNotOpen].
  1155     (mode == #readonly) ifTrue:[^ self errorReadOnly].
  1183     (mode == #readonly) ifTrue:[^ self errorReadOnly].
  1156     binary ifFalse:[^ self errorNotBinary].
  1184     binary ifFalse:[^ self errorNotBinary].
  1157 
  1185 
  1158     (aNumber isKindOf:Integer) ifTrue:[
  1186     aNumber isInteger ifTrue:[
  1159         (self nextShortPut:(aNumber // 16r10000) MSB:msbFlag) isNil ifTrue:[^ nil].
  1187         (self nextShortPut:(aNumber // 16r10000) MSB:msbFlag) isNil ifTrue:[^ nil].
  1160         ^ self nextShortPut:(aNumber \\ 16r10000) MSB:msbFlag.
  1188         ^ self nextShortPut:(aNumber \\ 16r10000) MSB:msbFlag.
  1161     ].
  1189     ].
  1162     self argumentMustBeInteger
  1190     self argumentMustBeInteger
  1163 ! !
  1191 ! !
  1177     int savInt;
  1205     int savInt;
  1178     extern int _immediateInterrupt;
  1206     extern int _immediateInterrupt;
  1179 
  1207 
  1180     if (_INST(filePointer) != nil) {
  1208     if (_INST(filePointer) != nil) {
  1181         if (_INST(mode) != _writeonly) {
  1209         if (_INST(mode) != _writeonly) {
  1182             if (_INST(buffered) == true) {
  1210 #ifdef OLD
       
  1211             if (_INST(buffered) == true) 
       
  1212 #endif
       
  1213             {
  1183                 f = MKFD(_INST(filePointer));
  1214                 f = MKFD(_INST(filePointer));
  1184                 savInt = _immediateInterrupt;
  1215                 savInt = _immediateInterrupt;
  1185                 _immediateInterrupt = 1;
  1216                 _immediateInterrupt = 1;
  1186                 c = getc(f);
  1217                 c = getc(f);
  1187                 _immediateInterrupt = savInt;
  1218                 _immediateInterrupt = savInt;
  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)) {
  1281 synchronizeOutput
  1315 synchronizeOutput
  1282     "write all buffered data - for buffered mode only"
  1316     "write all buffered data - for buffered mode only"
  1283 
  1317 
  1284 %{  /* NOCONTEXT */
  1318 %{  /* NOCONTEXT */
  1285 
  1319 
  1286     FILE *f;
       
  1287 
       
  1288     if (_INST(filePointer) != nil) {
  1320     if (_INST(filePointer) != nil) {
  1289         if (_INST(mode) != _readonly) {
  1321         if (_INST(mode) != _readonly) {
  1290             if (_INST(buffered) == true) {
  1322             if (_INST(buffered) == true) {
  1291                 fflush(f);
  1323                 fflush( MKFD(_INST(filePointer)) );
  1292             }
  1324             }
  1293         }
  1325         }
  1294     }
  1326     }
  1295 %}
  1327 %}
  1296 !
  1328 !
  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';
  1576                         *rslt = '\0';
  1650                         *rslt = '\0';
  1577                         break;
  1651                         break;
  1578                     }
  1652                     }
  1579                 }
  1653                 }
  1580             }
  1654             }
       
  1655 #endif
  1581             _immediateInterrupt = savInt;
  1656             _immediateInterrupt = savInt;
  1582             if (rslt != NULL) {
  1657             if (rslt != NULL) {
  1583                 len = strlen(buffer);
  1658                 len = strlen(buffer);
  1584                 if (_INST(position) != nil) {
  1659                 if (_INST(position) != nil) {
  1585                     _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + len);
  1660                     _INST(position) = _MKSMALLINT(_intVal(_INST(position)) + len);
  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             }
  1693             savInt = _immediateInterrupt;
  1784             savInt = _immediateInterrupt;
  1694             _immediateInterrupt = 1;
  1785             _immediateInterrupt = 1;
  1695             for (;;) {
  1786             for (;;) {
  1696                 if (fgets(buffer, sizeof(buffer), src) == NULL) break;
  1787                 if (fgets(buffer, sizeof(buffer), src) == NULL) break;
  1697                 if (fputs(buffer, dst) == EOF) break;
  1788                 if (fputs(buffer, dst) == EOF) break;
       
  1789 #ifndef OLD
       
  1790                     if (_INST(buffered) == false) {
       
  1791                         fflush(dst);
       
  1792                     }
       
  1793 #endif
  1698                 if (matchLen) {
  1794                 if (matchLen) {
  1699                     if (strncmp(matchString, buffer, matchLen) == 0) 
  1795                     if (strncmp(matchString, buffer, matchLen) == 0) 
  1700                         break;
  1796                         break;
  1701                 }
  1797                 }
  1702             }
  1798             }
  1717      do not advance position i.e. nextLine will reread this line"
  1813      do not advance position i.e. nextLine will reread this line"
  1718 
  1814 
  1719     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
  1815     (mode == #writeonly) ifTrue:[^ self errorWriteOnly].
  1720     filePointer isNil ifTrue:[^ self errorNotOpen].
  1816     filePointer isNil ifTrue:[^ self errorNotOpen].
  1721     binary ifTrue:[^ self errorBinary].
  1817     binary ifTrue:[^ self errorBinary].
  1722 %{
  1818 
       
  1819 %{  /* STACK: 2000 */
  1723     FILE *f;
  1820     FILE *f;
  1724     int l;
  1821     int l;
  1725     char buffer[1024*8];
  1822     char buffer[1024];
  1726     char *cp;
  1823     char *cp;
  1727     char *matchString;
  1824     char *matchString;
  1728     int  firstpos, lastpos;
  1825     int  firstpos, lastpos;
  1729     extern int _immediateInterrupt;
  1826     extern int _immediateInterrupt;
  1730     int savInt;
  1827     int savInt;
  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             }
  1822 
  1921 
  1823     fd := self fileDescriptor.
  1922     fd := self fileDescriptor.
  1824     sema := Semaphore new.
  1923     sema := Semaphore new.
  1825 
  1924 
  1826     [OperatingSystem readCheck:fd] whileFalse:[
  1925     [OperatingSystem readCheck:fd] whileFalse:[
  1827         Processor enableIOSemaphore:sema on:fd.
  1926         Processor enableSemaphore:sema onInput:fd.
       
  1927         Processor currentProcess state:#ioWait.
  1828         sema wait.
  1928         sema wait.
  1829         Processor disableIOSemaphore:sema
  1929         Processor disableSemaphore:sema
  1830     ]
  1930     ]
  1831 !
  1931 !
  1832 
  1932 
  1833 writeWait
  1933 writeWait
  1834     "suspend the current process, until the receiver
  1934     "suspend the current process, until the receiver
  1840 
  1940 
  1841     fd := self fileDescriptor.
  1941     fd := self fileDescriptor.
  1842     sema := Semaphore new.
  1942     sema := Semaphore new.
  1843 
  1943 
  1844     [OperatingSystem writeCheck:fd] whileFalse:[
  1944     [OperatingSystem writeCheck:fd] whileFalse:[
  1845         Processor enableIOSemaphore:sema on:fd.
  1945         Processor enableSemaphore:sema onOutput:fd.
       
  1946         Processor currentProcess state:#ioWait.
  1846         sema wait.
  1947         sema wait.
  1847         Processor disableIOSemaphore:sema
  1948         Processor disableSemaphore:sema
  1848     ]
  1949     ]
  1849 ! !
  1950 ! !
  1850      
  1951      
  1851 !ExternalStream methodsFor:'reimplemented for speed'!
  1952 !ExternalStream methodsFor:'reimplemented for speed'!
  1852 
  1953 
  1917             if (_INST(mode) != _writeonly) {
  2018             if (_INST(mode) != _writeonly) {
  1918                 f = MKFD(_INST(filePointer));
  2019                 f = MKFD(_INST(filePointer));
  1919                 savInt = _immediateInterrupt;
  2020                 savInt = _immediateInterrupt;
  1920                 _immediateInterrupt = 1;
  2021                 _immediateInterrupt = 1;
  1921                 _INST(position) = nil;
  2022                 _INST(position) = nil;
       
  2023                 if (_INST(mode) == _readwrite)
       
  2024                     fseek(f, 0L, 1); /* needed in stdio */
  1922                 for (;;) {
  2025                 for (;;) {
  1923                     c = getc(f);
  2026                     c = getc(f);
  1924                     if (c == EOF) {
  2027                     if (c == EOF) {
  1925                         _immediateInterrupt = savInt;
  2028                         _immediateInterrupt = savInt;
  1926                         RETURN (nil);
  2029                         RETURN (nil);
  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;
  2014     int savInt;
  2119     int savInt;
  2015 
  2120 
  2016     if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) {
  2121     if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) {
  2017         if (_INST(binary) != true) {
  2122         if (_INST(binary) != true) {
  2018             f = MKFD(_INST(filePointer));
  2123             f = MKFD(_INST(filePointer));
       
  2124             if (_INST(mode) == _readwrite)
       
  2125                 fseek(f, 0L, 1); /* needed in stdio */
  2019             while (1) {
  2126             while (1) {
  2020                 if (feof(f)) {
  2127                 if (feof(f)) {
  2021                     RETURN ( nil );
  2128                     RETURN ( nil );
  2022                 }
  2129                 }
  2023                 savInt = _immediateInterrupt;
  2130                 savInt = _immediateInterrupt;
  2064 
  2171 
  2065     if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) {
  2172     if ((_INST(filePointer) != nil) && (_INST(mode) != _writeonly)) {
  2066         if (_INST(binary) != true) {
  2173         if (_INST(binary) != true) {
  2067             f = MKFD(_INST(filePointer));
  2174             f = MKFD(_INST(filePointer));
  2068             while (1) {
  2175             while (1) {
       
  2176                 if (_INST(mode) == _readwrite)
       
  2177                     fseek(f, 0L, 1); /* needed in stdio */
  2069                 if (feof(f)) {
  2178                 if (feof(f)) {
  2070                     RETURN ( nil );
  2179                     RETURN ( nil );
  2071                 }
  2180                 }
  2072                 savInt = _immediateInterrupt;
  2181                 savInt = _immediateInterrupt;
  2073                 _immediateInterrupt = 1;
  2182                 _immediateInterrupt = 1;
  2118     int inComment, inString, inPrimitive = 0;
  2227     int inComment, inString, inPrimitive = 0;
  2119     extern int _immediateInterrupt;
  2228     extern int _immediateInterrupt;
  2120     int savInt;
  2229     int savInt;
  2121 
  2230 
  2122     f = MKFD(_INST(filePointer));
  2231     f = MKFD(_INST(filePointer));
       
  2232     if (_INST(mode) == _readwrite)
       
  2233         fseek(f, 0L, 1); /* needed in stdio */
  2123     /*
  2234     /*
  2124      * skip spaces
  2235      * skip spaces
  2125      */
  2236      */
  2126     savInt = _immediateInterrupt;
  2237     savInt = _immediateInterrupt;
  2127     _immediateInterrupt = 1;
  2238     _immediateInterrupt = 1;
  2128     while (! done) {
  2239     while (! done) {
  2129         if (feof(f)) {
  2240         if (feof(f)) {
  2130             _immediateInterrupt = savInt;
  2241             _immediateInterrupt = savInt;
  2131             RETURN ( nil );
  2242             RETURN ( nil );
  2132         }
  2243         }
  2133 	do {
  2244         do {
  2134             c = getc(f);
  2245             c = getc(f);
  2135 	} while ((c < 0) && (errno == EINTR));
  2246         } while ((c < 0) && (errno == EINTR));
  2136         switch (c) {
  2247         switch (c) {
  2137             case ' ':
  2248             case ' ':
  2138             case '\t':
  2249             case '\t':
  2139             case '\n':
  2250             case '\n':
  2140             case '\r':
  2251             case '\r':
  2166             bcopy(buffer, newBuffer, index);
  2277             bcopy(buffer, newBuffer, index);
  2167             free(buffer);
  2278             free(buffer);
  2168             buffer = newBuffer;
  2279             buffer = newBuffer;
  2169             currSize = currSize * 2;
  2280             currSize = currSize * 2;
  2170         }
  2281         }
  2171 	do {
  2282         do {
  2172             c = getc(f);
  2283             c = getc(f);
  2173 	} while (c < 0 && (errno == EINTR));
  2284         } while (c < 0 && (errno == EINTR));
  2174         if (c == '%') {
  2285         if (c == '%') {
  2175             peekC = getc(f);
  2286             peekC = getc(f);
  2176             ungetc(peekC, f);
  2287             ungetc(peekC, f);
  2177             if (peekC == '{') {
  2288             if (peekC == '{') {
  2178                 inPrimitive++;
  2289                 inPrimitive++;