The BUFFER module

The BUFFER is the basic component of a TEXTFILE but is is very useful for many string manupulations.

Code

program run_buffer

   use TYPES
   use SYSTEM
   use STR
   use BUFFER
   use TEXTFILE

#include "macros"

   implicit none

   BUFFER :: b
   STR :: word 
   REAL :: real
   INT :: int

   tonto.initialize

   stdout.create_stdout
   stdout.open
  
   stdout.text("I am creating a buffer below ...")
   stdout.flush

   b.set(" this is a buffer string, 0.1 0.2 10 ! comment","!")

   stdout.show("buffer string =",b.string)
   stdout.show("item start    =",b.item_start)
   stdout.show("item end      =",b.item_end)
   stdout.show("item index    =",b.item_index)
   stdout.show("n_items       =",b.n_items)
   stdout.show("analysed      =",b.analysed)
   stdout.show("comment_chars =",b.comment_chars)

   stdout.flush
   stdout.text("Now I am extracting from this buffer ...")
   stdout.flush

   b.get(word)  
   stdout.show("1st word =",word)

   b.get(word)  
   stdout.show("2nd word =",word)

   b.get(word)  
   stdout.show("3rd word =",word)

   b.get(word)  
   stdout.show("4th word =",word)

   b.get(word)  
   stdout.show("5th word =",word)

   b.get(word)  
   stdout.show("6th word =",word)

   b.get(real)  
   stdout.show("7th real  =",real)

   b.get(int)  
   stdout.show("8th int  =",int)

   stdout.flush
   stdout.text("Now move back to the 2nd item and get it ...")
   stdout.flush

   b.move_to_item(2)  
   b.get(word)  
   stdout.show("2nd word =",word)

   stdout.flush
   stdout.text("Now I will print out a cursor to the current position")
   stdout.flush

   stdout.flush
   stdout.show("buffer string =", b.string)
   stdout.text("Cursor---------"//b.cursor_pointer.align_left.trim)

   stdout.flush
   stdout.text('The last item I processed was "'// b.previous_item.trim //'"')

end 

Results

I am creating a buffer below ...

buffer string = this is a buffer string, 0.1 0.2 10 ! comment
item start    =        0
item end      =        0
item index    =        0
n_items       =        8
analysed      =        T
comment_chars =                   !

Now I am extracting from this buffer ...

1st word =                this
2nd word =                  is
3rd word =                   a
4th word =              buffer
5th word =             string,
6th word =                 0.1
7th real  =         0.200000000
8th int  =       10

Now move back to the 2nd item and get it ...

2nd word =                  is

Now I will print out a cursor to the current position


buffer string = this is a buffer string, 0.1 0.2 10 ! comment
Cursor----------------^

The last item I processed was "is"