gui2023: a new GUI with ZIP file support
[trut64.git] / gui / gui2023 / utils / contap.c
blobdaa550a97dd17f8940e57914cc53b1beac89e819
1 /*
2 * Copyright (C) 2023 Anton Blad
3 * Copyright (C) 2023 Fredrik Kuivinen
4 * Copyright (C) 2023 Jakob Rosén
6 * This file is licensed under GPL v2.
7 */
9 // Just a simple tool used for testing the TRUT64 GUI
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include "tap.h"
15 int main(int argc, char** argv)
17 printf("Contap. Concatenates two TAP files and saves the result.\n");
18 if (argc < 4)
20 printf("Usage: contap <source1> <source2> <destination> [<padding>]\n");
21 return -1;
24 char* source1_name=argv[1];
25 char* source2_name=argv[2];
26 char* destination_name=argv[3];
27 int padding=0;
28 if (argc==5)
30 sscanf(argv[4], "%d", &padding);
32 printf("Padding %d seconds between tap files\n", padding);
34 struct tape_data* tap1;
35 struct tape_data* tap2;
36 tap1=load_tap_file(source1_name);
37 tap2=load_tap_file(source2_name);
39 struct tape_data* result;
40 result=malloc(sizeof(struct tape_data));
41 result->length=tap1->length+tap2->length+padding;
42 result->data=(int*)malloc(result->length*sizeof(int));
43 int pos=0;
44 int i;
45 for (i=0; i<tap1->length; i++)
47 result->data[pos++]=tap1->data[i];
49 for (i=0; i<padding; i++)
51 result->data[pos++]=985248;
53 for (i=0; i<tap2->length; i++)
55 result->data[pos++]=tap2->data[i];
58 free_tap(tap1);
59 free_tap(tap2);
61 FILE* f;
62 f = fopen(destination_name, "rb");
63 if(f) {
64 printf("File '%s' already exist! Please delete it first.\n", destination_name);
65 return -1;
67 fclose(f);
68 f = fopen(destination_name, "wb");
69 save_tap(f, result);
70 free_tap(result);
71 printf("All done!\n");
73 return 0;