implemented --framerate.
[swftools.git] / src / swfstrings.c
1 /* swfstrings.c
2    Scans a swf file for strings
3
4    Part of the swftools package.
5    
6    Copyright (c) 2000,2001 Rainer Böhme <rfxswf@reflex-studio.de>
7
8    This file is distributed under the GPL, see file COPYING for details */
9
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include "../lib/rfxswf.h"
13 #include "../lib/args.h"
14
15 char * filename = 0;
16
17 struct options_t options[] =
18 {
19  {"v","verbose"},
20  {"V","version"},
21  {0,0}
22 };
23
24 int args_callback_option(char*name,char*val)
25 {
26     if(!strcmp(name, "V")) {
27         printf("swfstrings - part of %s %s\n", PACKAGE, VERSION);
28         exit(0);
29     }
30     return 0;
31 }
32 int args_callback_longoption(char*name,char*val)
33 {
34     return args_long2shortoption(options, name, val);
35 }
36 void args_callback_usage(char*name)
37 {    
38     printf("\nreflex SWF Text Scan Utility\n(w) 2000 by Rainer Boehme <rb@reflex-studio.de>\n\nUsage: %s filename.swf\n", name);
39     exit(0);
40 }
41 int args_callback_command(char*name,char*val)
42 {
43     if(filename) {
44         fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
45                  filename, name);
46     }
47     filename = name;
48     return 0;
49 }
50
51 SWF swf;
52   
53 void fontcallback(U16 id,U8 * name)
54 { LPSWFFONT font;
55   LPTAG t;
56   
57   swf_FontExtract(&swf,id,&font);
58   printf("#< %s %s %s>\n",name,swf_FontIsBold(font)?"bold":"",swf_FontIsItalic(font)?"italic":"");
59
60   t = swf.firstTag;
61
62   while (t)
63   { swf_TextPrintDefineText(t,font);
64     t = swf_NextTag(t);
65   }
66   
67   swf_FontFree(font);
68 }
69
70 int main (int argc,char ** argv)
71 { int f;
72
73   processargs(argc, argv);
74   if(!filename)
75       exit(0);
76
77   f = open(filename,O_RDONLY);
78   if (f>=0)
79   { if FAILED(swf_ReadSWF(f,&swf))
80     { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",filename);
81       close(f);
82     }
83     else
84     { close(f);
85       swf_FontEnumerate(&swf,&fontcallback);
86       swf_FreeTags(&swf);
87     }
88   } else {
89       fprintf(stderr,"File not found: %s\n",argv[1]);
90   }
91   
92   return 0;
93 }
94