Click to See Complete Forum and Search --> : It works!


f'lar
02-25-2001, 04:02 AM
I have an old laptop that I'm trying to get up and going: no cdrom, no network capabilities, but it does have at least 256 colors on the display, and a serial port. I have tiny linux on it, but I could only get command line w/out the network on it because some of the packages are too big for a floppy. I just wrote a program to split files into floppy sized pieces, and another to reassemble the pieces into one. I think I just got all the bugs worked out, all the remains now it to add some polish (input using argv instead of prompting, usage statements, etc) and port it to linux (shouldn't be hard, I wrote to port it. I would have written it native linux, but I wrote most of the code while chatting over icq with a friend, and I still haven't found an icq client for linux that authenticates through a https firewall :mad: ).

This is pretty cool for me, because I've written plenty of harder stuff, but always for an assignment. It's the first time I've seen a need that I had and written my own program to fill it. BTW, if anyone wants it, I may as well make it available via GPL when it's ready, though it's usefullness would be mostly limited to older machines.

[ 25 February 2001: Message edited by: f'lar ]

jemfinch
02-25-2001, 05:41 AM
I'm really happy you got to write something to help you do something you really wanted to do. That's awesome.

It's also pretty spiffy that you're using your laptop to its full ability.

Just as a note, though, there's a program "split" in the GNU textutils package that does what you need :)

I'm not trying to rain on your parade -- practically everything I write has been written better and earlier. Yet I still write it. :)

Jeremy

f'lar
02-25-2001, 05:56 AM
What's the recombiner?

[edit]
Nevermind: figured it out. I don't think I have it, so I'll have to download, but no biggy. I'll have to get the source, too, and do some comparisons.

[ 25 February 2001: Message edited by: f'lar ]

andrzej
02-25-2001, 05:58 AM
Funny thing: I've written the same thing some time ago. Slow, because it reads/writes byte by byte. Easy to fix, but I don't care. Good news is that it compiles and works both on windows and linux.

No comments on code quality, please. It was an urgent need. :o

split.cpp

#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

void increment(char *arg)
{
arg[6]++;
if (arg[6]>'9') {
arg[6]='0';
arg[5]++;
if (arg[5]>'9') {
arg[5]='0';
arg[4]++;
if (arg[4]>'9') {
arg[4]='0';
arg[3]++;
}
}
}
}

int main(int argc, char **argv)
{
unsigned long size, count;
int ff=0;
char *outname="out0000.spl";
unsigned char ch;
size=strtoul(argv[1],NULL,10);
assert(size>0);
FILE *fin, *fout;
if (argc==3) {
fin=fopen(argv[2],"rb");
while (!feof(fin)) {
fout=fopen(outname,"wb");
increment(outname);
count=0;
while ((++count<=size)&&!feof(fin)) {
if (ff) fputc(0xFF,fout);
ch=fgetc(fin);
if (ch==0xFF) ff=1;
else {
ff=0;
fputc(ch,fout);
}
}
fclose(fout);
}
fclose(fin);
}
else printf("arg1: size; arg2: source;\n");
return 0;
}



join.cpp


#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

void increment(char *arg)
{
arg[6]++;
if (arg[6]>'9') {
arg[6]='0';
arg[5]++;
if (arg[5]>'9') {
arg[5]='0';
arg[4]++;
if (arg[4]>'9') {
arg[4]='0';
arg[3]++;
}
}
}
}

int main(int argc, char **argv)
{
char *inname="out0000.spl";
int ff;
unsigned char ch;
FILE *fin, *fout;
if (argc==2) {
fout=fopen(argv[1],"wb");
while ((fin=fopen(inname,"rb"))!=NULL) {
ff=0;
while (!feof(fin)) {
if (ff) fputc(0xFF,fout);
ch=fgetc(fin);
if (ch==0xFF) ff=1;
else {
ff=0;
fputc(ch,fout);
}
}
fclose(fin);
increment(inname);
}
fclose(fout);
}
else printf("arg1: dest;\n");
return 0;
}

Strike
02-25-2001, 02:07 PM
the recombiner is join

jemfinch
02-25-2001, 02:27 PM
Originally posted by Strike:
the recombiner is join

Actually, no. The recombiner is cat. Join is for something else entirely.

Jeremy

f'lar
02-25-2001, 05:00 PM
I think tar might work, too, except that it adds a header.

I think I'm going to use the one I wrote, because diskspace is really an issue and this has exactly the functionality I need with none that I don't, plus I may as well use it after I spent the effort to write it. I also think I will make the two programs into one, and you tell it what you're doing via command line switch.

[ 26 February 2001: Message edited by: f'lar ]

f'lar
02-26-2001, 02:40 AM
Well, it doesn't quite work, at least on the laptop. The laptop's only a 486, and I have an older slackware 4 on there (tiny linux) which still uses the old libraries, so it won't run unless I can compile it for an i386 machine. I tried just changing the setting in kdevelop, but it won't build now, says g++ can't create executables. How do I fix this. I think I just need to download support for building generic i386 type executables. Where do I look for that (and don't tell me the gnu gcc page: i need something more specific). I don't have gcc on the laptop yet, because you need larger files to get it there first, or I'd just transfer the source and compile it there, so it's a chicken/egg problem.

Salmon
02-26-2001, 10:49 AM
Originally posted by jemfinch:
. . . -- practically everything I write has been written better and earlier. Yet I still write it. :)


Yeah, there's always something really satisfying about using something that you've written yourself, even if something a little better might already exist.

f'lar
02-26-2001, 06:23 PM
Now it really works, becuase I changed my split program so it doesn't write the file name as a header in the first file anymore, so I can just use cat to put them back together. In the meantime, before I finally put linux on the laptop for (hopefully) the last time, I'm installing a copy of OS/2 Warp 3.0 I came across: should be interesting. BTW, anyone know if there's a free c++ compiler for os2, or if, since it's dos compatible, I could use the free borland one?

andy4us1
02-26-2001, 06:29 PM
:cool:

I've been using tiny linux for several months on my firewall, I really like the distro. Plus it's really Slack. Anyway, if you've got a serial port, it may be eaiser to use something like minicom to transfer files over the serial port. Or if you install the network package, which is 3 floppy's, then you might be able to get SLIP working and network over serial ports. It's all kinda slow, but a lot easier than splitting over floppys !

Andy

PS Well done anyway, it's fun to do stuff like that !