File: dataToHeader.c

package info (click to toggle)
gnustep-base 1.24.7-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 24,176 kB
  • ctags: 5,535
  • sloc: objc: 966,973; ansic: 31,274; makefile: 317; cpp: 110; sh: 102; xml: 28
file content (55 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (6)
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
/*
 * A trivial C program to read characterset data files and produce a C
 * header file to be included into NSCharacterSet.m
 * Pass it the names of the data files as arguments.
 */
#include	<stdio.h>
#include	<string.h>

int
main(int argc, char **argv)
{
  int	i;
  int	c;
  FILE	*o;

  if (argc < 2)
    {
      fprintf(stderr, "Expecting names of data files to convert\n");
      return 1;
    }
  o = fopen("NSCharacterSetData.h", "w");
  for (i = 1; i < argc; i++)
    {
      FILE	*f;
      char	name[BUFSIZ];
      int	j;
      int	sep = '{';

      strcpy(name, argv[i]);
      j = strlen(name) - 4;
      if (j < 0 || strcmp(&name[j], ".dat") != 0)
	{
	  fprintf(stderr, "Bad file name '%s'\n", name);
	  return 1;
	}
      f = fopen(name, "r");
      if (f == NULL)
	{
	  fprintf(stderr, "Unable to read '%s'\n", name);
	  return 1;
	}
      name[j] = '\0';
      fprintf(o, "static unsigned char %s[8192] = ", name);
      while ((c = fgetc(f)) != EOF)
	{
	  fprintf(o, "%c\n'\\x%02x'", sep, c);
	  sep = ',';
	}
      fprintf(o,"};\n");
      fclose(f);
    }
  fclose(o);
  return 0;
}