File: makefdb.c

package info (click to toggle)
libming 0.2a.cvs20020110-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 2,204 kB
  • ctags: 4,173
  • sloc: ansic: 19,467; yacc: 2,149; cpp: 1,518; java: 1,253; ruby: 516; perl: 462; python: 436; makefile: 295; sh: 4
file content (153 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>

#include "blocktypes.h"
#include "read.h"

void readRect(FILE *f)
{
  int nBits = readBits(f, 5);
  readBits(f, nBits);
  readBits(f, nBits);
  readBits(f, nBits);
  readBits(f, nBits);
}

#define FONTINFO2_HASLAYOUT		(1<<7)
#define FONTINFO2_SHIFTJIS		(1<<6)
#define FONTINFO2_UNICODE		(1<<5)
#define FONTINFO2_ANSI			(1<<4)
#define FONTINFO2_WIDEOFFSETS	(1<<3)
#define FONTINFO2_WIDECODES		(1<<2)
#define FONTINFO2_ITALIC		(1<<1)
#define FONTINFO2_BOLD			(1<<0)

void printDefineFont2(FILE *f, int length)
{
  int flags, namelen, i, reserved;
  char name[264];
  FILE *out;
  int wide = 0;

  readUInt16(f); /* font id */

  flags = readUInt8(f);

  if(flags & FONTINFO2_WIDECODES) {
#if 1
    wide = 1;
    warning("Sorry, wide code fonts not supported.");
#else
    error("Sorry, wide code fonts not supported.");
#endif
  }

  if(!(flags & FONTINFO2_HASLAYOUT))
    error("Hrm.  I was expecting some layout info."); 

  reserved = readUInt8(f); /* "reserved" */

  namelen = readUInt8(f);

  for(i=0; i<namelen; ++i)
    name[i] = (unsigned char)readUInt8(f);

  if(flags & FONTINFO2_BOLD)
  {
    name[i++] = '-';
    name[i++] = 'B';
  }
  if(flags & FONTINFO2_ITALIC)
  {
    name[i++] = '-';
    name[i++] = 'I';
  }

  name[i++] = '.';
  name[i++] = 'f';
  name[i++] = 'd';
  name[i++] = 'b';
  name[i] = '\0';

  printf("Writing %s, %i bytes\n", name, length+2);

  if((out=fopen(name,"wb"))==NULL)
    error("Couldn't open output file!");

  fputc('f', out);
  fputc('d', out);
  fputc('b', out);
  fputc('0', out);

  fputc(flags, out);
  fputc(reserved, out);
  fputc(namelen, out);

  for(i=0; i<namelen; ++i)
    fputc(name[i], out);

  length -= namelen + 5;

  for(; length>0; --length)
    fputc(fgetc(f), out); /* prolly faster buffered, eh? */

  fclose(out);

  if(wide==2)
  {
    printf("Removing %s\n", name);
    unlink(name);
  }
}

int main(int argc, char *argv[])
{
  FILE *f;
  int size, offset, block, type, length, i;

  if(argc<2)
    error("Give me a filename.\n");

  if(!(f = fopen(argv[1],"rb")))
    error("Sorry, can't seem to read that file.\n");

  if(!(readUInt8(f)=='F' && readUInt8(f)=='W' && readUInt8(f)=='S'))
    error("Doesn't look like a flash file to me..\n");

  readUInt8(f); /* version */
  size = readUInt32(f);
  readRect(f); /* bounds */
  readUInt16(f); /* frame rate */
  readUInt16(f); /* total frames */

  for(;;)
  {
    block = readUInt16(f);
    type = block>>6;
	offset = fileOffset;

    length = block & ((1<<6)-1);

    if(length == 63) /* it's a long block. */
      length = readUInt32(f);

    if(type == 0 || fileOffset > size)
      break;

    switch(type)
    {
      case DEFINEFONT2:
	    printf("Found DefineFont2 block at offset %i\n", offset);
	    printf("Block length: %i\n", length);
      	printDefineFont2(f, length);
      	break;

      default:
      	for(i=length; i>0; --i) readUInt8(f);
      	break;
    }
  }

  return 0;
}