Tuesday Mar 27 17:35:19 +0000 2001 Tom Oehser <[EMAIL PROTECTED]> wrote:
>
> As an example of the advantages of lua, the old unrpm-- in awk was:
>
> #!/bin/sh
> awk 'BEGIN{
> RS=" "
> "filesize '$1'"|getline SZ
> for(SK=-1;SK<SZ;SK++){
> LR=TR
> "tomshexd -r<'$1'"|getline TR
> if(LR TR=="1f8b"){
> CK=system("dd if='$1' bs=1 skip="SK" 2>/dev/null|gzip -t")
> if(CK==0){
> system("dd if='$1' bs=1 skip="SK" 2>/dev/null|gzip -d|cpio -iuvmd")
> break
> }}}}'
>
> In lua it is:
>
> #!/usr/bin/lua -f
> if getargs()[3] then readfrom(getargs()[3]) end
> while 1 do
> b=read(1)
> if not b then break end
> if b=="\31" then
> b=read(1)
> if not b or b=="\139" then break end
> end
> end
> if not b then
> _ALERT("ERROR\n")
> exit(-1)
> end
> writeto("|gzip -d|cpio -iuvmd")
> write("\31\139")
> buf = read(8192)
> while buf do
> write(buf)
> buf = read(8192)
> end
>
> granted, it has gone from 297 bytes to 351 bytes, but at a 120x
> performance boost!
Have you made size comparisons when these files are gzipped w/ thousands of
kilobytes of other ascii text files ;)
>
> -Tom
>
Tomi