-
Notifications
You must be signed in to change notification settings - Fork 3
/
combine.c
71 lines (70 loc) · 1.62 KB
/
combine.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
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
int
main (int argc, char **argv)
{
int aflag = 0;
int bflag = 0;
char *cvalue = NULL;
int index;
int c;
int verbosity=0;
int dst_address;
int src_address=0;
char output_filename [256];
FILE * in, * out;
unsigned char src_buffer[16384];
unsigned char dst_buffer[262144];
opterr = 0;
while ((c = getopt (argc, argv, "vh:l:uf:o:")) != -1)
switch (c)
{
case 'o':
strcpy(output_filename,optarg);
case 'v':
verbosity++;
printf ("Verbosity: %d\n", verbosity);
break;
case 'h':
printf ("High index: %d\n", atoi(optarg));
dst_address = atoi(optarg)*8192;
break;
case 'l':
printf ("Low index: %d\n", atoi(optarg));
dst_address = atoi(optarg)*8192+131072;
break;
case 'u':
printf ("Read from upper 8k\n");
src_address=8192;
break;
case 'f':
printf ("Read from file %s\n", optarg);
in = fopen(optarg, "rb");
if (in!=NULL) {
fread(src_buffer, 16384,1, in);
}
memcpy(dst_buffer+dst_address, src_buffer+src_address,8192);
src_address=0;
break;
case '?':
if (optopt == 'c')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr,
"Unknown option character `\\x%x'.\n",
optopt);
return 1;
default:
abort ();
}
out = fopen (output_filename, "wb");
if (out != NULL) {
fwrite(dst_buffer, 262144,1,out);
}
return 0;
}