rfxswf cleanups: added prefixes and altered structure name conventions
[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 }
31 int args_callback_longoption(char*name,char*val)
32 {
33     return args_long2shortoption(options, name, val);
34 }
35 void args_callback_usage(char*name)
36 {    
37     printf("\nreflex SWF Text Scan Utility\n(w) 2000 by Rainer Boehme <rb@reflex-studio.de>\n\nUsage: %s filename.swf\n", name);
38     exit(0);
39 }
40 int args_callback_command(char*name,char*val)
41 {
42     if(filename) {
43         fprintf(stderr, "Only one file allowed. You supplied at least two. (%s and %s)\n",
44                  filename, name);
45     }
46     filename = name;
47     return 0;
48 }
49
50 SWF swf;
51   
52 void fontcallback(U16 id,U8 * name)
53 { LPSWFFONT font;
54   LPTAG t;
55   
56   swf_FontExtract(&swf,id,&font);
57   printf("#< %s %s %s>\n",name,swf_FontIsBold(font)?"bold":"",swf_FontIsItalic(font)?"italic":"");
58
59   t = swf.firstTag;
60
61   while (t)
62   { swf_TextPrintDefineText(t,font);
63     t = swf_NextTag(t);
64   }
65   
66   swf_FontFree(font);
67 }
68
69 int main (int argc,char ** argv)
70 { int f;
71
72   processargs(argc, argv);
73   if(!filename)
74       exit(0);
75
76   f = open(filename,O_RDONLY);
77   if (f>=0)
78   { if FAILED(swf_ReadSWF(f,&swf))
79     { fprintf(stderr,"%s is not a valid SWF file or contains errors.\n",filename);
80       close(f);
81     }
82     else
83     { close(f);
84       swf_FontEnumerate(&swf,&fontcallback);
85       swf_FreeTags(&swf);
86     }
87   } else {
88       fprintf(stderr,"File not found: %s\n",argv[1]);
89   }
90   
91   return 0;
92 }
93