Mail Archives: djgpp/2001/01/02/09:21:35.2
In article <Pine DOT SUN DOT 3 DOT 91 DOT 1010102113516 DOT 18307I-100000 AT is>,
djgpp AT delorie DOT com wrote:
>
> On Tue, 2 Jan 2001, Tom St Denis wrote:
>
> > Anyways... My code only finds the first file then findnext() returns
> > 1... ALWAYS!
> >
> > I don't want to flood the group, so if anyone has two mins to spare
> > email me at tomstdenis AT yahoo DOT com and I will send you the source to
look
> > at.
>
> My advice would be to write the shortest program you can come up with
> which uses findfirst and findnext, and still exhibits the problem, and
> then post that code here as plain text.
>
> Experience shows that, while working on the short program, either
> (1) you will find the problem in your code; or (2) the resulting
> program will be simple enough for someone to spot the problem in
> no time.
Here is the entire program (minus the bzip lib of course) (one huge
main file... the way programs of this caliber should be written...
hehehehe)
--bz.c--
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <dir.h>
#include <dos.h>
#include <ctype.h>
#include "bzlib.h"
int main(int argc, char **argv)
{
struct ffblk fb;
unsigned long f, x, y;
unsigned char buf[4096];
if (argc == 1) {
printf("%s: [e|d] archive [files]\nE\tEncode files into
archive\nD\tDecode files out of archive.\n", argv[0]);
return 0; }
if (toupper(argv[1][0]) == 'E') {
FILE *input;
BZFILE *output;
/* encode */
output = BZ2_bzopen(argv[2], "wb9");
memset(&fb, 0, sizeof(fb));
f = findfirst(argv[3], &fb,
FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_ARCH);
while (!f) {
/* write the file name and then it's size */
input = fopen(fb.ff_name, "rb");
if (!input) {
printf("Can't open: %s\n", fb.ff_name);
return -1;
}
printf("%s\n", fb.ff_name);
fseek(input, 0, SEEK_END);
x = ftell(input);
fseek(input, 0, SEEK_SET);
BZ2_bzwrite(output, fb.ff_name, sizeof(fb.ff_name));
BZ2_bzwrite(output, &x, sizeof(x));
do {
y = fread(buf, 1, sizeof(buf), input);
BZ2_bzwrite(output, buf, y);
} while (y == sizeof(buf));
fclose(input);
f = findnext(&fb);
}
BZ2_bzclose(output);
} else {
/* decode */
BZFILE *input;
FILE *output;
/* open archive */
input = BZ2_bzopen(argv[2], "rb");
while (BZ2_bzread(input, fb.ff_name, sizeof(fb.ff_name))) {
output = fopen(fb.ff_name, "wb");
printf("%s\n", fb.ff_name);
BZ2_bzread(input, &x, sizeof(x));
while (x) {
/* read at most sizeof(buf) bytes */
y = (x>sizeof(buf))?sizeof(buf):x;
x -= y;
/* read/write */
BZ2_bzread(input, buf, y);
fwrite(buf, 1, y, output);
}
fclose(output);
}
BZ2_bzclose(input);
}
return 0;
}
--bz.c--
>
Sent via Deja.com
http://www.deja.com/
- Raw text -