File: tap2spt.c

package info (click to toggle)
spectemu 0.94a-18
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd
  • size: 1,300 kB
  • ctags: 3,206
  • sloc: ansic: 15,421; asm: 5,160; sh: 1,533; cpp: 377; makefile: 175
file content (82 lines) | stat: -rw-r--r-- 1,316 bytes parent folder | download | duplicates (12)
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
73
74
75
76
77
78
79
80
81
82
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>


#define MAXLEN 256

int main(int argc, char *argv[])
{
  char filename[MAXLEN];

  FILE *tap, *spt, *blk;
  int i, len, n, c;

  if(argc < 2) {
    fprintf(stderr, "usage: %s basename\n", argv[0]);
    exit(1);
  }

  strcpy(filename, argv[1]);
  strcat(filename, ".tap");
  
  tap = fopen(filename, "rb");
  
  if(tap == NULL) {
    fprintf(stderr, "Could not open file %s. %s\n", 
	    filename, strerror(errno));
    exit(1);
  }

  strcpy(filename, argv[1]);
  strcat(filename, ".spt");
  
  spt = fopen(filename, "wt");

  if(spt == NULL) {
    fprintf(stderr, "Could not open file %s. %s\n", 
	    filename, strerror(errno));
    exit(1);
  }
  

  for(i = 0;; i++) {
    c = getc(tap);
    if(c == EOF) break;
    
    len = c + (getc(tap) << 8);
    
    sprintf(filename, "%s.%03i", argv[1], i);

  
    blk = fopen(filename, "wb");

    if(blk == NULL) {
      fprintf(stderr, "Could not open file %s. %s\n", 
	      filename, strerror(errno));
      exit(1);
    }

    fprintf(spt, "%03i %02X %5i OK   Generated by tap2spt\n", 
	    i, getc(tap), len - 2);

    for(n = 0; n < len - 2; n++) {
      putc(getc(tap), blk);
    }
    
    getc(tap);
    
    fclose(blk);
  }

  fclose(tap);
  fclose(spt);

  return 0;
}