Subversion Repositories SvarDOS

Rev

Rev 349 | Rev 432 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
349 mateuszvis 1
/*
2
 * translates a binary file to a C include.
3
 * used by the SvarCOM build process to embedd rcom inside COMMAND.COM
4
 *
5
 * Copyright (C) 2021 Mateusz Viste
6
 */
7
 
8
#include <stdio.h>
9
 
10
int main(int argc, char **argv) {
11
  FILE *fdin, *fdout;
12
  unsigned long len;
13
  int c;
14
 
15
  if (argc != 4) {
16
    puts("usage: file2c infile.dat outfile.c varname");
17
    return(1);
18
  }
19
 
20
  fdin = fopen(argv[1], "rb");
21
  if (fdin == NULL) {
22
    puts("ERROR: failed to open input file");
23
    return(1);
24
  }
25
 
26
  fdout = fopen(argv[2], "wb");
27
  if (fdout == NULL) {
28
    fclose(fdin);
29
    puts("ERROR: failed to open output file");
30
    return(1);
31
  }
32
 
33
  fprintf(fdout, "const char %s[] = {", argv[3]);
34
  for (len = 0;; len++) {
35
    c = getc(fdin);
36
    if (c == EOF) break;
37
    if (len > 0) fprintf(fdout, ",");
38
    if ((len & 15) == 0) fprintf(fdout, "\r\n");
39
    fprintf(fdout, "%3u", c);
40
  }
41
  fprintf(fdout, "};\r\n");
42
  fprintf(fdout, "#define %s_len %lu\r\n", argv[3], len);
43
 
44
  fclose(fdin);
45
  fclose(fdout);
46
  return(0);
47
}