aboutsummaryrefslogtreecommitdiff
path: root/ksiders/atrextr.c
blob: 2aeb898b1c04ebdf1833f208868959891dc0bfe3 (plain)
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
/* Copyright 1997 Ken Siders */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "atr.h"
#include "atdos.h"

int main( int argc, char **argv) {
	AtrFilePtr atr;
	int stat = 0, ret = 0;
	char *file = "*.*";
	char *path = NULL;

	printf("AtrExtr Version 0.9u (c)1997 Ken Siders\n");
	printf("Ported and modified by B. Watson, 2007\n");
	printf("This program may be freely distributed\n\n");

	if(argc < 2 || argc > 4) {
		printf("usage: atrextr atrname.atr [file] [dir]\n"
				"Wildcards may be used for file (default: *.*)\n"
				"dir will be created, if it does not exist\n");
		exit(-1);
	}

	atr = OpenAtr(argv[1]);
	if(atr == 0) {
		printf("Error reading ATR file: %s\n", argv[1]);
		CloseAtr(atr);
		exit(2);
	}

	CloseAtr(atr);

	if(argc >= 3 && argv[2][0])
		file = argv[2];

	if(argc == 4) {
		path = argv[3];
		mkdir(path, 0777); /* ignore errors (ExtractAtariFile() will fail instead) */
	}

	while ( !stat ) {
		SetVerbose(1);
		stat = ExtractAtariFile( argv[1], file, path );
		SetVerbose(0);
	}

	if( stat < 0 ) {
		printf("\nError encountered when extracting file(s)\n");
		printf("some files may have been extracted incorrectly\n");
		stat = -stat;
		ret = 1;
	}

	printf("\n%d file(s) extracted\n", stat);

	exit(ret);
}