PUTC

Started by Robert, October 17, 2024, 11:45:44 PM

Previous topic - Next topic

MrBcx

Small update:  PUTC enclosing parentheses are optional.  Feels more BASIC-like ...


OPEN "test.txt" FOR OUTPUT AS #1
FOR CHAR i = 65 TO 70
    PUTC #1, i
NEXT
PUTC #1, 13  ' 13 = Carriage Return
PUTC #1, 10  ' 10 = Line Feed
FLUSH #1     ' optional but always a good idea to FLUSH when you're done :-)
CLOSE #1

Robert

Thank you MrBcx.

PUTC will be handy for popping in a 13 or a 10 or both when the compiler spits out " No new-line at end of file ! "

Oh, yes, one more thing ... PUTC will also do exotic 21,  30, 118 and 155 if you are editing a file for, respectively, an IBM MainFrame Z/OS, a Lamborghini QNX, the Z80 Sinclair, or an 8-bit Atari.

Details here: https://en.wikipedia.org/wiki/Newline


MrBcx

Thanks for the suggestion Robert.  Below is the entry into Revisions.txt for the next version of BCX:

Robert Wishlaw : Added PUTC (byte_expression, FilePtr) to the BCX lexicon as a complement to GETC(FP#)
                 PUTC will accept QBASIC style file pointers.  Here is a compilable example:
               
                         OPEN "test.txt" FOR OUTPUT AS #1
                         FOR CHAR i = 65 TO 70      ' The letters ABCDEF
                             PUTC (#1, i)
                         NEXT
                         PUTC (#1, 10 + 1 + 1 + 1)  ' 13 = Carriage Return  ( I used this line to test the parser )
                         PUTC (#1, 10)              ' 10 = Line Feed
                         FLUSH(#1)                  ' optional but always a good idea to FLUSH when you're done :-)
                         CLOSE #1 


The StdC call is putc (byte, FP);

but I wanted to rearrange the arguments, so that a byte expression could be more easily parsed, when needed.

Hence this crazy looking test line:  PUTC (#1, 10 + 1 + 1 + 1)  ' 13 = Carriage Return

The internal BCX processor for the new PUTC command is:



                CASE "putc"                                  ' MrBcx 819 (New)
                Stk$[Tmp] = "putc"                           ' MrBcx 819 (New)
                REMOVE "#" FROM Stk$[Tmp+2]                  ' MrBcx 819 (New)
                IF DataType(Stk$[Tmp+2]) = vt_NUMBER THEN    ' MrBcx 819 (New)
                    Stk$[Tmp+2] = "FP" + Stk$[Tmp+2]         ' MrBcx 819 (New)
                END IF                                       ' MrBcx 819 (New)
                '                                            ' MrBcx 819 (New)  Rearrange: putc ( fp# ,  byte-expreession )
                '                                            ' MrBcx 819 (New)         to: putc ( byte-expression, fp# )
                DIM fp$                                      ' MrBcx 819 (New)
                fp$ = Stk$[Tmp+2]                            ' MrBcx 819 (New)
                LShiftStk(Tmp+2)                             ' MrBcx 819 (New)
                LShiftStk(Tmp+2)                             ' MrBcx 819 (New)
                Stk$[Ndx] = ","                              ' MrBcx 819 (New)
                INCR Ndx                                     ' MrBcx 819 (New)
                Stk$[Ndx] = fp$                              ' MrBcx 819 (New)
                INCR Ndx                                     ' MrBcx 819 (New)
                Stk$[Ndx] = ")"                              ' MrBcx 819 (New)



It is working as it should and will be included in 8.1.9

Thanks ...



Robert

Perhaps a PUTC to go with the  GETC new in BCX 8.1.7?