source: svn/trunk/newcon3bcm2_21bu/dta/tools/bin2c.c @ 5

Last change on this file since 5 was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 2.3 KB
Line 
1/***************************************************************
2**
3** Broadcom Corp. Confidential
4** Copyright 2002 Broadcom Corp. All Rights Reserved.
5**
6** THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED
7** SOFTWARE LICENSE AGREEMENT BETWEEN THE USER AND BROADCOM.
8** YOU HAVE NO RIGHT TO USE OR EXPLOIT THIS MATERIAL EXCEPT
9** SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
10**
11** Description: Create SGIL bitmap fonts from freetype fonts.
12**
13** Created: 8/22/2002 by Jeffrey P. Fisher
14**
15**
16**
17****************************************************************/
18
19#include <stdio.h>
20
21void print_usage(char *argv[])
22{
23        printf("Usage:  %s [options] <filename>\n",argv[0]);
24        printf("  Create a C data array from the binary contents of the file.\n");
25        printf("  An output file is created with \".c\" appended to the filename.\n");
26        printf("  -h            Usage information.\n");
27}
28
29/****************************************************************
30* INPUTS:               arc - argument count
31*                           argv - array of arguments
32* OUTPUTS:              none
33* RETURNS:              non-zero on failure
34* DESCRIPTION:  Main entry point convert fonts to raw bitmap.
35*
36****************************************************************/
37int main(int argc, char *argv[])
38{
39        int i,len;
40        FILE* fin,*fout;
41        char *dot_ptr;
42        unsigned char *ptr;
43        static char out_name[1024];;
44
45        if (argc != 2 )
46        {
47                print_usage(argv);
48                return 0;
49        }
50
51        fin = fopen(argv[1],"rb");
52
53        /* Parse arguments */
54        for (i = 1; i < argc; ++i)
55        {
56                if ((strcmp(argv[i],"-h") == 0) || (strcmp(argv[i],"-H") == 0))
57                {
58                        print_usage(argv);
59                        return 0;
60                }
61
62        }
63       
64        dot_ptr = strstr(argv[1],".");
65
66        if (!dot_ptr)
67        {
68                sprintf(out_name,"%s.c",argv[1]);
69        }
70        else
71        {
72                strcpy(out_name,argv[1]);
73                dot_ptr[0] = 0;
74                sprintf(out_name,"%s.c",argv[1]);
75        }
76
77        printf("Creating file %s...\n",out_name);
78        fout = fopen(out_name,"w+");
79        if (!fin || !fout)
80        {
81                return -1;
82        }
83
84        fseek(fin,0,SEEK_END);
85        len = ftell(fin);
86        fseek(fin,0,SEEK_SET);
87        ptr = (unsigned char*)malloc(len);
88        if (fread(ptr,1,len,fin) != len)
89        {
90                return -1;
91        }
92
93        fprintf(fout,"const unsigned char g_%s[] = \n{\n\t",argv[1]);
94        for (i = 0; i < len; i++)
95        {
96                if (i % 8 == 0)
97                {
98                        fprintf(fout,"\n\t");
99                }
100                fprintf(fout,"0x%02x, ",ptr[i]);
101        }
102
103        fprintf(fout,"\n};\nunsigned int g_%s_size = %d;\n",argv[1],len);
104       
105        fclose(fin);
106        fclose(fout);
107        free(ptr);
108        return 0;
109}
110
111
Note: See TracBrowser for help on using the repository browser.