the read from standard in bug

Sadhunathan Nadesan sadhu at castandcrew.com
Sat Mar 15 13:35:01 EST 2003


Problem:  read from stdin clips off input

Scott, I request your help please.  As you may recall I am running
an older 2.4 version of the MC interpreter on my 2.2.16 (kernel) Linux
machine and newer versions won't compile due to library incompatibilities.
I think you said you were going to fix this bug after you got a faster
machine and ran into it yourself, but I don't have that fix.

So I am looking for a work around.

In the case of cgi scripts, to replace the "read from stdin until empty"
you suggested to check the content length and I currently use this,
which works great:

     if ($REQUEST_METHOD = "POST") then
       put empty into buffer
       repeat until (length(buffer) >= $CONTENT_LENGTH)
         read from stdin until empty
         put it after buffer
       end repeat
     else
       read from stdin until empty
       put it into buffer
     end if


Except, I am also running into the clipping problem on non cgi use, ie,
when there is no content length variable to check.  For example I have
this script that I use as a replacement tool, and use it by piping text
straight into it with cat or redirect

#!/usr/local/bin/mc
#*************************************************************************
#
#     Program name:     replace.mt
#     Version number:   1.0
#     Author:           SN
#     Date:             9/22/01
#     Description:      Replace argument one with argument two, a filter
#
#****************************************************************************

on startup
  read from stdin until empty
  replace $1 with $2 in it
  put it
end startup


What happens is that the output from this filter is chopped off, the trailing
part of the file is missing .. but only sometimes.

Of course I could rewrite this with sed and make it a shell script or
use Perl or whatever but one cool thing about MC is that it is not line
oriented like Unix filters so when I get those files from Mac guys that
are just one huge line, everything still works.  I am strongly resisting
going to another language although that would be easy enough because I
really want MC to be a useable scripting language for me.

In any case, can you suggest a work around for the clipping problem that
would work on 2.4 or even 2.3?



More information about the metacard mailing list