[metapost] scantokens

Walt Burkhard burkhard at cs.ucsd.edu
Sat Apr 22 01:13:35 CEST 2017


Hello Fellow MetaPosters,

I am using the scantokens command and have observed some rather weird
standard output remarks. ---

Here is my program ---

string aa ;
numeric n[] , i , j , len ;
numeric wide ;
%%  mydata contains one sequence of numbers " 12 34 45 1 0  234"

vardef mydigits ( expr nn ) =
  numeric w ;
  if (nn > 99) and (nn < 1000) :
    w := 3 ;
    w
  elseif (nn > 9) and (nn < 100) :
    w := 2 ;
    w
  else :
    w := 1 ;
    w
  fi
enddef ;

aa := readfrom ( "mydata" ) ;
message ("aa "&aa ) ;

for i = 0 upto 5 :
  len := length aa ;
  spaces := 0 ;
  for j = 0 upto len :
    if substring (j,j+1) of aa = " " :  spaces := spaces+1 ; else : fi
exitif true ; fi ;
  endfor ;
  aa := substring (spaces,len) of aa ;
  n[i] := scantokens aa ;
  wide :=  mydigits ( n[i] ) ;
  len := length aa ;
  aa := substring (wide,len) of aa ;
endfor ;

for i = 0 upto 5 :
  message ( "n["&decimal i&"] "&decimal n[i] ) ;
endfor ;

end


AND here is the mydata file ---

 12 34 45 1 0  234

The scantokens commands seem to want to indicate that there is more to read
than just the next number!

Here is a portion of the output I obtain ---

This is MetaPost, version 1.9991 (TeX Live 2016) (kpathsea version 6.2.2)
(/usr/local/texlive/2016/texmf-dist/metapost/base/mpost.mp
(/usr/local/texlive/2016/texmf-dist/metapost/base/plain.mp
Preloading the plain mem file, version 1.005) ) (./mytest.mp
aa  12 34 45 1 0  234
! Extra tokens will be flushed.
<to be read again>
                   34
<scantokens> 12 34
                   45 1 0  234
<to be read again>
                   ;
<for(0)> ...s,len)of.aa;n[(EXPR0)]:=scantokens.aa;

wide:=mydigits(n[(EXPR0)])...
l.34 endfor
            ;

MetaPost interrupts the processing at this point, but if an "r" is entered
from the keyboard, MetaPost continues
with much more similar output and then finally ---

n[0] 12
n[1] 34
n[2] 45
n[3] 1
n[4] 0
n[5] 234 )

Is there a way to avoid these extra standard output remarks?


Many thanks in advance.

Walt
ps    The zipped file jkljkl.zip contains both mytest.mp and mydata.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20170421/10bcfd71/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: jkljkl.zip
Type: application/zip
Size: 874 bytes
Desc: not available
URL: <http://tug.org/pipermail/metapost/attachments/20170421/10bcfd71/attachment.zip>


More information about the metapost mailing list