MIME-Version: 1.0
Return-Path: bluepeak.westend.com!popeye
Return-Path: <popeye@bluepeak.westend.com>
Received: from popeye.bluepeak.westend.com by bluepeak  with smtp
	(Smail3.2 #1) id m11UMyQ-00027eC; Fri, 24 Sep 1999 06:28:42 +0200 (MEST)
Received: from genesis for a.kupries
 with Cubic Circle's cucipop (v1.10 1996/09/06) Fri Sep 24 06:23:20 1999
Received: from mail_srv.novadigm.com (novadigm.com [208.244.225.99])
	by genesis.westend.com (8.8.6/8.8.6) with ESMTP id EAA10829
	for <a.kupries@westend.com>; Fri, 24 Sep 1999 04:42:14 +0200 (MET DST)
Received: from LAPCAT ([208.244.230.179]) by mail_srv.novadigm.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2448.0)
	id TNC6Q75K; Thu, 23 Sep 1999 22:35:38 -0400
X-From_: matt@novadigm.com  Fri Sep 24 04:42:15 1999
Message-ID: <002601bf0636$5e641080$b3e6f4d0@lapcat>
Reply-To: "Matt Newman" <matt@novadigm.com>
From: "Matt Newman" <matt@novadigm.com>
To: "Matt Newman" <matt@sensus.org>, "Andreas Kupries" <a.kupries@westend.com>
Cc: "Jean-Claude Wippler" <jcw@equi4.com>
Subject: Re: [trf1.8] Support for Seek on FD
Date: Thu, 23 Sep 1999 22:41:53 -0400
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 4.72.2106.4
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Content-Type: multipart/mixed;
              boundary="----=_NextPart_000_0023_01BF0614.D50DB0A0"

------=_NextPart_000_0023_01BF0614.D50DB0A0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
              charset="iso-8859-1"

I have attached some patches to registry.c - they return the running
position in the stream and also have the side effect of disabling anything
other than Tcl_Seek(ch, 0, SEEK_CUR)

Let me know your thoughts on this.

Matt Newman
-----Original Message-----
From: Matt Newman <matt@sensus.org>
To: Andreas Kupries <a.kupries@westend.com>
Cc: Jean-Claude Wippler <jcw@equi4.com>
Date: Thursday, September 23, 1999 10:15 PM
Subject: [trf1.8] Support for Seek on FD


>I have been grapping with a problem using the zip compression method and
>wanted to share my thoughts.
>
>A normal Tcl paradigm is to do
>
>set fd [open foo w]
>puts $fd data
>close $fd
>set size [file size foo]
>
>But in the case of any form of transformation it is quite often nice to
know
>the pre-transformation size - i.e. in the case of zip the uncompressed
size.
>Now you can normally tell howmuch data has been written to a channel by
>doing
>
>set fd [open foo w]
>puts $fd data
>flush $fd
>set size [tell $fd]
>close $fd
>
>(If the channel supports seeks)
>
>However when you do this with the Trf channels two problems raise their
ugly
>heads....
>
>1) Calling [tell] before the flush seems to brake the channel in some way
>(try it out - reverse the flush & tell)
>
>2) The registry.c SeekProc calls the underlying channel's SeekProc.
>
>The later is not correct under almost all non 1-1 transformations, since
>offsets (sizes) may be different on each side of the transformation.
>
>This also has the side effect that [tell] on a transformed FD returns the
>underlying offset, not the pre-transform offset.
>
>It occured to me that the Seek support may need to be different for
>different types of transform, instead of the single generic one in
>registry.c
>
>One simple situtation I could propose would be that the registry.c code
>maintain a byte-count and only support Tcl_Seek(ch, 0, SEEK_CUR) which is
>what [tell] uses - and throws an error in all other cases - at least for
>writing this would give me a very simple way of getting the pre-transform
>byte-count.
>
>What do you think?
>
>Matt Newman
>
>PS. My "real" need is to know the pre and post compression sizes - but this
>need would hold true for all other transforms too.
>

------=_NextPart_000_0023_01BF0614.D50DB0A0
Content-Disposition: attachment;
	filename="registry.c.diff"
Content-Transfer-Encoding: quoted-printable
Content-Type: application/octet-stream;
              name="registry.c.diff"

Index: registry.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/tcl/trf/generic/registry.c,v
retrieving revision 1.5
diff -c -r1.5 registry.c
*** registry.c	1999/09/22 20:57:25	1.5
--- registry.c	1999/09/24 02:39:42
***************
*** 121,126 ****
--- 121,127 ----
    Tcl_TimerToken timer;
  #endif
 =20
+   int	position;	/* Keep track of the upstream logical file position */
  } TrfTransformationInstance;
 =20
 =20
***************
*** 1190,1195 ****
--- 1191,1197 ----
  	gotBytes    +=3D toRead;
  	toRead =3D 0;
 =20
+ 	trans->position +=3D gotBytes;
  	return gotBytes;
 =20
        } else {
***************
*** 1242,1247 ****
--- 1244,1250 ----
  	  *errorCodePtr =3D EWOULDBLOCK;
  	  return -1;
  	} else {
+ 	  trans->position +=3D gotBytes;
  	  return gotBytes;
  	}
        } else {
***************
*** 1256,1261 ****
--- 1259,1265 ----
  					    trans->clientData);
  	if (trans->result.used =3D=3D 0) {
  	  /* we had nothing to flush */
+ 	  trans->position +=3D gotBytes;
  	  return gotBytes;
  	}
  	continue; /* at: while (toRead > 0) */
***************
*** 1287,1292 ****
--- 1291,1297 ----
      }
    } /* while toRead > 0 */
 =20
+   trans->position +=3D gotBytes;
    return gotBytes;
  }
  =0C
***************
*** 1349,1354 ****
--- 1354,1360 ----
      return -1;
    }
 =20
+   trans->position +=3D toWrite;
    return toWrite;
  }
  =0C
***************
*** 1410,1418 ****
      trans->readIsFlushed =3D 0;
    }
 =20
!   result =3D Tcl_Seek (parent, offset, mode);
!   *errorCodePtr =3D (result =3D=3D -1) ? Tcl_GetErrno ():0;
!   return result;
  }
  =0C
  /*
--- 1416,1427 ----
      trans->readIsFlushed =3D 0;
    }
 =20
!   if (mode !=3D SEEK_CUR || offset !=3D 0) {
!     *errorCodePtr =3D EFAULT;
!     return -1;
!   } else {
!     return trans->position;
!   }
  }
  =0C
  /*
***************
*** 1846,1851 ****
--- 1855,1861 ----
 =20
    trans->mode             =3D Tcl_GetChannelMode (attach);
    trans->timer            =3D (Tcl_TimerToken) NULL;
+   trans->position	  =3D 0;
 =20
    if (ENCODE_REQUEST (entry, optInfo)) {
      /* ENCODE on write

------=_NextPart_000_0023_01BF0614.D50DB0A0--
