added ratio to put commands
[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 program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
21
22 #include <stdio.h>
23 #include <fcntl.h>
24 #include "../lib/rfxswf.h"
25 #include "../lib/args.h"
26
27 char * filename = 0;
28
29 struct options_t options[] =
30 {
31  {"v","verbose"},
32  {"V","version"},
33  {0,0}
34 };
35
36 int args_callback_option(char*name,char*val)
37 {
38     if(!strcmp(name, "V")) {
39         printf("swfstrings - part of %s %s\n", PACKAGE, VERSION);
40         exit(0);
41     }
42     return 0;
43 }
44 int args_callback_longoption(char*name,char*val)
45 {
46     return args_long2shortoption(options, name, val);
47 }
48 void args_callback_usage(char*name)
49 {    
50     printf("\nreflex SWF Text Scan Utility\n(w) 2000 by Rainer Boehme <rb@reflex-studio.de>\n\nUsage: %s filename.swf\n", name);
51     exit(0);
52 }
53 int args_callback_command(char*name,char*val)
54 {
55     if(filename) {
56         fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
57                  filename, name);
58     }
59     filename = name;
60     return 0;
61 }
62
63 SWF swf;
64   
65 void fontcallback(U16 id,U8 * name)
66 { LPSWFFONT font;
67   LPTAG t;
68   
69   swf_FontExtract(&swf,id,&font);
70   printf("#< %s %s %s>\n",name,swf_FontIsBold(font)?"bold":"",swf_FontIsItalic(font)?"italic":"");
71
72   t = swf.firstTag;
73
74   while (t)
75   { swf_TextPrintDefineText(t,font);
76     t = swf_NextTag(t);
77   }
78   
79   swf_FontFree(font);
80 }
81
82 int main (int argc,char ** argv)
83 { int f;
84
85   processargs(argc, argv);
86   if(!filename)
87       exit(0);
88
89   f = open(filename,O_RDONLY|O_BINARY);
90   if (f>=0)
91   { if FAILED(swf_ReadSWF(f,&swf))
92     { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",filename);
93       close(f);
94     }
95     else
96     { close(f);
97       swf_FontEnumerate(&swf,&fontcallback);
98       swf_FreeTags(&swf);
99     }
100   } else {
101       fprintf(stderr,"File not found: %s\n",argv[1]);
102   }
103   
104   return 0;
105 }
106