[metapost] scantokens

Daniel H. Luecking luecking at uark.edu
Mon Apr 24 19:33:41 CEST 2017


Walt:


After expansion,

  n[i] := scantokens aa;

becomes

  n[i] := 12 34 45 1 0  234;

which is invalid.


You should arrange to either (1) split off the numbers in

aa one at a time, or (2) create mydata with a separate line

for each number and read it one line at a time.


Cheers,

Daniel H. Luecking [luecking at uark.edu]
Department of Mathematical Sciences
1 University of Arkansas
Fayetteville, AR, USA 72701-1201


________________________________
From: metapost <metapost-bounces at tug.org> on behalf of Walt Burkhard <burkhard at cs.ucsd.edu>
Sent: Friday, April 21, 2017 6:13 PM
To: Metapost List
Subject: [metapost] scantokens

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<https://urldefense.proofpoint.com/v2/url?u=http-3A__mpost.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=qWEXXzhF1oqlzQC88L7WnGB_k10FjyBQUf-ed2VmV4E&e=>
(/usr/local/texlive/2016/texmf-dist/metapost/base/plain.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__plain.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=bzeG1FO7B6JSDFzqFBYQxs6AvZwpxA97bwS3Y5zQlk4&e=>
Preloading the plain mem file, version 1.005) ) (./mytest.mp<https://urldefense.proofpoint.com/v2/url?u=http-3A__mytest.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=-O3lzwAypZSOmpyVVf1gSe5NMlTV6xkuFZdrBrN7-yY&e=>
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<https://urldefense.proofpoint.com/v2/url?u=http-3A__mytest.mp&d=DwMFaQ&c=7ypwAowFJ8v-mw8AB-SdSueVQgSDL4HiiSaLK01W8HA&r=TC6doj34eEZMeTCOMVYeIK4ttwYpTurqDpMOi43sP18&m=abeM8ifl3acGToYAZzBoTJxhOKzeHVPINt2QhoStkYU&s=-O3lzwAypZSOmpyVVf1gSe5NMlTV6xkuFZdrBrN7-yY&e=> and mydata.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/metapost/attachments/20170424/7f941cc3/attachment.html>


More information about the metapost mailing list