home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.forth      Forth programmers eat a lot of Bratwurst      117,927 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 117,762 of 117,927   
   albert@spenarnc.xs4all.nl to the.beez.speaks@gmail.com   
   Re: Idiomatic way to read a word of text   
   22 Nov 25 09:25:35   
   
   In article ,   
   Hans Bezemer   wrote:   
   >On 18-11-2025 00:25, Paul Rubin wrote:   
   >> I'm playing with the idea of writing a Roff-like text formatter in   
   >> Forth.  The input is lines of text "blah blech, and this that the   
   >> other...".  The text lines can be arbitrarily long so I don't want to   
   >> read the entire line into a memory buffer using something like REFILL.   
   >>   
   >> Let's say I don't have to worry about individual words overflowing   
   >> memory though (segfault is not allowed, but it's ok to panic and quit).   
   >> So the main loop will be to copy an input word to the output buffer and   
   >> maybe flush the output buffer.  The output buffer can be of fixed size.   
   >>   
   >> Also, some input lines will be formatting commands like ".i\n" (change   
   >> font to italic).  Those lines should be given to the Forth text   
   >> interpreter.   
   >>   
   >> I guess I could use the FILE word set to write something like getc()   
   >> with its own buffering, but that seems messy.  I'm wondering if this is   
   >> a common situation and there's an idiomatic solution.   
   >   
   >I don't know if it's "idiomatic", but it works. In essence, it reads the   
   >file binary. If there is something left at the end of the buffer, it   
   >copies that to the start, adjusts the buffer address and size and   
   >continues. It doesn't return a word per call, you open the file and it   
   >applies a quotation to each word parsed (a n --).   
      
   That is exactly how it works in ciforth too for file redirection.   
   (Reading from the console just fills the TIB.)   
      
   >   
   >No, it's not beautiful, but it works. BTW, if you happen to be German   
   >and your prose contains words that exceed 256 characters, you're on your   
   >own.   
      
   Not beautiful?   
   >   
   >Hans Bezemer   
      
   Groetjes Albert   
   --   
   The Chinese government is satisfied with its military superiority over USA.   
   The next 5 year plan has as primary goal to advance life expectancy   
   over 80 years, like Western Europe.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca