1 /* $Id: pushback.c,v 1.2 2000/12/14 18:45:35 ghazi Exp $
4 Revision 1.2 2000/12/14 18:45:35 ghazi
7 * compress.c: Include stdlib.h and compress.h.
9 (report_str_error): Make static.
10 (ez_inflate_str): Delete unused variable. Add parens in if-stmt.
11 (hrd_inflate_str): Likewise.
13 * compress.h (init_compression, end_compression, init_inflation,
14 end_inflation): Prototype void arguments.
16 * dostime.c (rcsid): Delete.
18 * jargrep.c: Include ctype.h, stdlib.h, zlib.h and compress.h.
19 Make functions static. Cast ctype function argument to `unsigned
20 char'. Add parens in if-stmts. Constify.
21 (Usage): Change into a macro.
22 (jargrep): Remove unused parameter.
24 * jartool.c: Constify. Add parens in if-stmts. Align
25 signed/unsigned char pointers in functions calls using casts.
27 (list_jar): Fix printf format specifier.
28 (usage): Chop long string into bits. Reformat.
30 * pushback.c (rcsid): Delete.
32 Revision 1.1 2000/12/09 03:08:23 apbianco
33 2000-12-08 Alexandre Petit-Bianco <apbianco@cygnus.com>
37 Revision 1.2 2000/08/23 19:42:17 cory
38 Added support for more Unix platforms. The following code has been hacked
39 to work on AIX, Solaris, True 64, and HP-UX.
40 Added bigendian check. Probably works on most big and little endian platforms
43 Revision 1.1.1.1 1999/12/06 03:09:13 toast
48 Revision 1.1 1999/05/10 08:32:37 burnsbr
54 pushback.c - code for a pushback buffer to handle file I/O
55 Copyright (C) 1999 Bryan Burns
57 This program is free software; you can redistribute it and/or
58 modify it under the terms of the GNU General Public License
59 as published by the Free Software Foundation; either version 2
60 of the License, or (at your option) any later version.
62 This program is distributed in the hope that it will be useful,
63 but WITHOUT ANY WARRANTY; without even the implied warranty of
64 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65 GNU General Public License for more details.
67 You should have received a copy of the GNU General Public License
68 along with this program; if not, write to the Free Software
69 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
79 void pb_init(pb_file
*pbf
, int fd
){
81 pbf
->next
= pbf
->pb_buff
;
85 int pb_push(pb_file
*pbf
, void *buff
, int amt
){
90 printf("%d bytes being pushed back to the buffer\n", amt
);
93 /* determine how much we can take */
94 if((int)(RDSZ
- pbf
->buff_amt
) < amt
)
95 in_amt
= RDSZ
- pbf
->buff_amt
;
102 /* figure out if we need to wrap around, and if so, by how much */
103 if(((pbf
->pb_buff
+ RDSZ
) - pbf
->next
) < in_amt
)
104 wrap
= in_amt
- ((pbf
->pb_buff
+ RDSZ
) - pbf
->next
);
106 /* write everything up til the end of the buffer */
107 memcpy(pbf
->next
, buff
, (in_amt
- wrap
));
109 /* finish writing what's wrapped around */
110 memcpy(pbf
->pb_buff
, ((char *)buff
+ (in_amt
- wrap
)), wrap
);
112 /* update the buff_amt field */
113 pbf
->buff_amt
+= in_amt
;
116 printf("%d bytes we can't accept\n", (amt
- in_amt
));
123 int pb_read(pb_file
*pbf
, void *buff
, int amt
){
130 printf("%d bytes requested from us\n", amt
);
132 while(out_amt
< amt
){
133 /* if our push-back buffer contains some data */
134 if(pbf
->buff_amt
> 0){
137 printf("giving data from buffer\n");
140 /* calculate how much we can actually give the caller */
141 if( (amt
- out_amt
) < (int)pbf
->buff_amt
)
142 tmp
= (amt
- out_amt
);
146 /* Determine if we're going to need to wrap around the buffer */
147 if(tmp
> ((pbf
->pb_buff
+ RDSZ
) - pbf
->next
))
148 wrap
= tmp
- ((pbf
->pb_buff
+ RDSZ
) - pbf
->next
);
150 memcpy(bp
, pbf
->next
, (tmp
- wrap
));
151 bp
= &(((char *)bp
)[tmp
- wrap
]);
153 /* If we need to wrap, read from the start of the buffer */
155 memcpy(bp
, pbf
->pb_buff
, wrap
);
156 bp
= &(((char *)bp
)[wrap
]);
159 /* update the buff_amt field */
160 pbf
->buff_amt
-= tmp
;
164 printf("%d bytes remaining in buffer\n", pbf
->buff_amt
);
167 /* if the buffer is empty, reset the next header to the front of the
168 buffer so subsequent pushbacks/reads won't have to wrap */
169 if(pbf
->buff_amt
== 0)
170 pbf
->next
= pbf
->pb_buff
;
176 printf("Reading from file..\n");
179 /* The pushback buffer was empty, so we just need to read from the file */
180 tmp
= read(pbf
->fd
, bp
, (amt
- out_amt
));
186 bp
= &(((char *)bp
)[tmp
]);
191 printf("managed to read %d bytes\n", out_amt
);