-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsplitape.c
73 lines (70 loc) · 2.02 KB
/
splitape.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*** M2000: Portable P2000 emulator *****************************************/
/*** ***/
/*** splitape.c ***/
/*** ***/
/*** This program splits a tape image to several tape images all ***/
/*** containing only one file ***/
/*** ***/
/*** Copyright (C) Marcel de Kogel 1996,1997 ***/
/*** You are not allowed to distribute this software commercially ***/
/*** Please, notify me, if you make any changes to this file ***/
/****************************************************************************/
#include <stdio.h>
#include <ctype.h>
int main (int argc, char *argv[])
{
static unsigned char buffer[1024+256];
FILE *infile;
FILE *outfile;
char filename[13];
int filecount=0;
int i,j;
printf ("splitape: Tape image splitter\n"
"Copyright (C) Marcel de Kogel 1996\n");
if (argc!=2)
{
printf ("Usage: splitape <tape image>\n");
return 1;
}
infile=fopen (argv[1],"rb");
if (!infile)
{
printf ("Can't open %s\n",argv[1]);
return 1;
}
while (fread(buffer,1024+256,1,infile))
{
for (i=0;i<8;++i)
{
j=buffer[0x36+i];
if (!isprint(j) || j==' ' || j=='?' || j=='*')
j='_';
filename[i]=j;
}
filename[8]='.';
filename[9]=(filecount/100)%10+'0';
filename[10]=(filecount/10)%10+'0';
filename[11]=(filecount)%10+'0';
filename[12]='\0';
i=buffer[0x4F];
if (!i) i=256;
outfile=fopen (filename,"wb");
if (outfile)
printf ("Writing %s - %d blocks\n",filename,i);
else
{
printf ("Can't open %s\n",filename);
return 1;
}
fwrite (buffer,1024+256,1,outfile);
for (--i;i;--i)
{
fread (buffer,1024+256,1,infile);
fwrite (buffer,1024+256,1,outfile);
}
fclose (outfile);
filecount++;
}
fclose (infile);
return 0;
}