]> www.wagner.pp.ru Git - oss/catdoc.git/blob - src/catppt.c
Recreated CVS repository from working copy
[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.1 2006-02-24 17:44:06 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 ppt2text [-lV] [-b string] [-s charset] [-d charset] files\n");
38 }
39
40
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:p:"))!=-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 'V': printf("Catdoc Version %s\n",CATDOC_VERSION);
85                         exit(0);
86                 default:
87                         help();
88                         exit(1);
89                 }       
90         }
91         /* If we are using system strftime, we need to  set LC_TIME locale
92          * category unless choosen charset is not same as system locale
93          */ 
94 #if defined(HAVE_LANGINFO) && defined(HAVE_STRFTIME) && !defined(__TURB0C__)
95         set_time_locale();
96 #endif  
97         /* charset conversion init*/
98         input_buffer=malloc(FILE_BUFFER);
99         if (strcmp(dest_csname,"utf-8")) {
100                 tmp_charset=read_charset(dest_csname);
101                 if (!tmp_charset) {
102                         fprintf(stderr,"Cannot load target charset %s\n",dest_csname);
103                         exit(1);
104                 }       
105                 target_charset=make_reverse_map(tmp_charset);
106                 free(tmp_charset);
107         } else { 
108                 target_charset=NULL;
109         } 
110         spec_chars=read_substmap(stradd("ascii",SPEC_EXT));
111         if (!spec_chars) {
112                 fprintf(stderr,"Cannod read substitution map ascii%s\n",
113                                                 SPEC_EXT);
114                 exit(1);
115         }  
116         replacements=read_substmap(stradd("ascii",REPL_EXT));
117         if (!replacements) {
118                 fprintf(stderr,"Cannod read substitution map ascii%s\n",
119                                                 REPL_EXT);
120                 exit(1);
121         }  
122         if (optind>=argc) {
123                 if (isatty(fileno(stdin))) {
124                         help();
125                         exit(0);
126                 }    
127                 do_ppt(stdin,"STDIN");
128                 exit (0);
129         }       
130         for (i=optind;i<argc;i++) {
131                 filename = argv[i];
132                 input=fopen(filename,"rb");
133                 if (!input) {
134                         perror(filename);
135                         exit(1);
136                 }
137                 if ((new_file=ole_init(input, NULL, 0)) != NULL) {
138                         set_ole_func();
139                         while((ole_file=ole_readdir(new_file)) != NULL) {
140                                 int res=ole_open(ole_file);
141 /*                              fprintf(stderr, "name = %s\n", ((oleEntry*)ole_file)->name); */
142                                 if (res >= 0) {
143                                         if (strcasecmp(((oleEntry*)ole_file)->name , "PowerPoint Document") == 0) {
144                                                 do_ppt(ole_file,filename);
145                                         }
146                                 } 
147                                 ole_close(ole_file);
148                         }
149                         set_std_func();
150                         ole_finish();
151                         fclose(new_file);
152                 } else {
153                         fprintf(stderr, "%s is not OLE file or Error\n", filename);
154                 }
155         }
156         return 0;
157 }