Subversion Repositories SvarDOS

Rev

Rev 432 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 432 Rev 477
Line 10... Line 10...
10
 
10
 
11
static void help(void) {
11
static void help(void) {
12
  puts("usage: file2c [/c] [/lxxx] infile.dat outfile.c varname");
12
  puts("usage: file2c [/c] [/lxxx] infile.dat outfile.c varname");
13
  puts("");
13
  puts("");
14
  puts("/c    - define the output array as CONST");
14
  puts("/c    - define the output array as CONST");
-
 
15
  puts("/s    - define the output array as STATIC");
15
  puts("/lxxx - enforces the output array to be xxx bytes big");
16
  puts("/lxxx - enforces the output array to be xxx bytes big");
16
}
17
}
17
 
18
 
18
 
19
 
19
int main(int argc, char **argv) {
20
int main(int argc, char **argv) {
20
  char *fnamein = NULL, *fnameout = NULL, *varname = NULL;
21
  char *fnamein = NULL, *fnameout = NULL, *varname = NULL;
21
  char flag_c = 0;
22
  char stortype = 0; /* 'c' = const ; 's' = static */
22
  char *flag_l = "";
23
  char *flag_l = "";
23
  FILE *fdin, *fdout;
24
  FILE *fdin, *fdout;
24
  unsigned long len;
25
  unsigned long len;
25
  int c;
26
  int c;
26
 
27
 
Line 28... Line 29...
28
    if ((argv[c][0] == '/') && (argv[c][1] == 'l')) {
29
    if ((argv[c][0] == '/') && (argv[c][1] == 'l')) {
29
      flag_l = argv[c] + 2;
30
      flag_l = argv[c] + 2;
30
      continue;
31
      continue;
31
    }
32
    }
32
    if ((argv[c][0] == '/') && (argv[c][1] == 'c')) {
33
    if ((argv[c][0] == '/') && (argv[c][1] == 'c')) {
33
      flag_c = 1;
34
      stortype = 'c';
-
 
35
      continue;
-
 
36
    }
-
 
37
    if ((argv[c][0] == '/') && (argv[c][1] == 's')) {
-
 
38
      stortype = 's';
34
      continue;
39
      continue;
35
    }
40
    }
36
    if (argv[c][0] == '/') {
41
    if (argv[c][0] == '/') {
37
      help();
42
      help();
38
      return(1);
43
      return(1);
Line 66... Line 71...
66
    fclose(fdin);
71
    fclose(fdin);
67
    puts("ERROR: failed to open output file");
72
    puts("ERROR: failed to open output file");
68
    return(1);
73
    return(1);
69
  }
74
  }
70
 
75
 
71
  if (flag_c) fprintf(fdout, "const ");
76
  if (stortype == 'c') fprintf(fdout, "const ");
-
 
77
  if (stortype == 's') fprintf(fdout, "static ");
72
  fprintf(fdout, "char %s[%s] = {", varname, flag_l);
78
  fprintf(fdout, "char %s[%s] = {", varname, flag_l);
73
 
79
 
74
  for (len = 0;; len++) {
80
  for (len = 0;; len++) {
75
    c = getc(fdin);
81
    c = getc(fdin);
76
    if (c == EOF) break;
82
    if (c == EOF) break;