]> www.wagner.pp.ru Git - oss/catdoc.git/blob - src/catppt.c
Added all the history to NEWS file
[oss/catdoc.git] / src / catppt.c
1 /**
2  * @file   ppt2text.c
3  * @author Alex Ott <alexott@gmail.com>
4  * @date   23 äÅË 2004
5  * Version: $Id: catppt.c,v 1.2 2006-10-17 19:11:29 vitus Exp $
6  * Copyright: Alex Ott 
7  * 
8  * @brief  main module for text extracting from .ppt
9  * 
10  * 
11  */
12
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 #include <stdio.h>
17 #include <time.h>
18 #include <math.h>
19 #include <ctype.h>
20 #include <string.h>
21 #include <unistd.h>
22 #include "ppt.h"
23 #include "catdoc.h"
24 #include <stdlib.h>
25 #include "catdoc.h"
26 #include "float.h"
27
28 #ifdef __TURBOC__
29 #define strcasecmp(a,b) strcmpi(a,b)
30 #endif
31
32 /** 
33  * Displays  help message
34  * 
35  */
36 void help (void) {
37         printf("Usage:\n catppt [-lV] [-b string] [-s charset] [-d charset] files\n");
38 }
39
40 extern char *slide_separator;
41 char *input_buffer, *output_buffer;
42
43 /** 
44  * 
45  * 
46  * @param argc 
47  * @param argv 
48  * 
49  * @return 
50  */
51 int main(int argc, char *argv[]) {
52         FILE *input;
53         FILE *new_file, *ole_file;
54         char *filename =NULL;
55         short int *tmp_charset;
56         int c;
57         int i;
58         char *tempname;
59         read_config_file(SYSTEMRC);
60 #ifdef USERRC
61         tempname=find_file(strdup(USERRC),getenv("HOME"));
62         if (tempname) {
63                 read_config_file(tempname);
64                 free(tempname);
65         }
66 #endif
67 #ifdef HAVE_LANGINFO
68         get_locale_charset();
69 #endif
70         
71         check_charset(&dest_csname,dest_csname); 
72
73         while ((c=getopt(argc,argv,"Vls:d:b:"))!=-1) {
74                 switch(c)  {
75                 case 'l':
76                         list_charsets(); exit(0);
77                 case 's':
78                         check_charset(&source_csname,optarg);
79                         source_charset=read_charset(source_csname);
80                         break;
81                 case 'd':
82                         check_charset(&dest_csname,optarg);
83                         break;
84                 case 'b':
85                         slide_separator = strdup(optarg);
86                         break;
87                 case 'V': printf("Catdoc Version %s\n",CATDOC_VERSION);
88                         exit(0);
89                 default:
90                         help();
91                         exit(1);
92                 }       
93         }
94         /* If we are using system strftime, we need to  set LC_TIME locale
95          * category unless choosen charset is not same as system locale
96          */ 
97 #if defined(HAVE_LANGINFO) && defined(HAVE_STRFTIME) && !defined(__TURB0C__)
98         set_time_locale();
99 #endif  
100         /* charset conversion init*/
101         input_buffer=malloc(FILE_BUFFER);
102         if (strcmp(dest_csname,"utf-8")) {
103                 tmp_charset=read_charset(dest_csname);
104                 if (!tmp_charset) {
105                         fprintf(stderr,"Cannot load target charset %s\n",dest_csname);
106                         exit(1);
107                 }       
108                 target_charset=make_reverse_map(tmp_charset);
109                 free(tmp_charset);
110         } else { 
111                 target_charset=NULL;
112         } 
113         spec_chars=read_substmap(stradd("ascii",SPEC_EXT));
114         if (!spec_chars) {
115                 fprintf(stderr,"Cannod read substitution map ascii%s\n",
116                                                 SPEC_EXT);
117                 exit(1);
118         }  
119         replacements=read_substmap(stradd("ascii",REPL_EXT));
120         if (!replacements) {
121                 fprintf(stderr,"Cannod read substitution map ascii%s\n",
122                                                 REPL_EXT);
123                 exit(1);
124         }  
125         if (optind>=argc) {
126                 if (isatty(fileno(stdin))) {
127                         help();
128                         exit(0);
129                 }    
130                 do_ppt(stdin,"STDIN");
131                 exit (0);
132         }       
133         for (i=optind;i<argc;i++) {
134                 filename = argv[i];
135                 input=fopen(filename,"rb");
136                 if (!input) {
137                         perror(filename);
138                         exit(1);
139                 }
140                 if ((new_file=ole_init(input, NULL, 0)) != NULL) {
141                         set_ole_func();
142                         while((ole_file=ole_readdir(new_file)) != NULL) {
143                                 int res=ole_open(ole_file);
144 /*                              fprintf(stderr, "name = %s\n", ((oleEntry*)ole_file)->name); */
145                                 if (res >= 0) {
146                                         if (strcasecmp(((oleEntry*)ole_file)->name , "PowerPoint Document") == 0) {
147                                                 do_ppt(ole_file,filename);
148                                         }
149                                 } 
150                                 ole_close(ole_file);
151                         }
152                         set_std_func();
153                         ole_finish();
154                         fclose(new_file);
155                 } else {
156                         fprintf(stderr, "%s is not OLE file or Error\n", filename);
157                 }
158         }
159         return 0;
160 }