if page range is given and % filename syntax is used, name files according to page...
[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(void*self,U16 id,U8 * name)
66 { SWFFONT* font;
67   TAG* t;
68   
69   swf_FontExtract(&swf,id,&font);
70   printf("#<font %d \"%s\"%s%s>\n",id, name,swf_FontIsBold(font)?" bold":"",swf_FontIsItalic(font)?" italic":"");
71
72   t = swf.firstTag;
73
74   while (t)
75   { 
76     if(swf_isTextTag(t))
77         swf_TextPrintDefineText(t,font);
78     t = swf_NextTag(t);
79   }
80   
81   swf_FontFree(font);
82 }
83
84 int main (int argc,char ** argv)
85 { int f;
86
87   processargs(argc, argv);
88   if(!filename)
89       exit(0);
90
91   f = open(filename,O_RDONLY|O_BINARY);
92   if (f>=0)
93   { if FAILED(swf_ReadSWF(f,&swf))
94     { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",filename);
95       close(f);
96     }
97     else
98     { close(f);
99       swf_FontEnumerate(&swf,&fontcallback,0);
100       swf_FreeTags(&swf);
101     }
102   } else {
103       fprintf(stderr,"File not found: %s\n",argv[1]);
104   }
105   
106   return 0;
107 }
108