1 /*****************************************************************/
2 /* Main program for parsing XLS files */
4 /* This file is part of catdoc project */
5 /* (c) David Rysdam 1998 */
6 /* (c) Victor Wagner 1998-2003, (c) Alex Ott 2003 */
7 /*****************************************************************/
25 #define strcasecmp(a,b) strcmpi(a,b)
27 extern char *forced_date_format;
28 extern char number_format[];
29 extern char *sheet_separator;
30 /************************************************************************/
31 /* Displays help message */
32 /************************************************************************/
34 printf("Usage:\n xls2csv [-xlV] [-g number] [-f date-format] [-b string] [-s charset] [-d charset] [-c char] [ -q number] files\n");
36 /* Defines unicode chars which should be
37 replaced by strings before UNICODE->target chatset
38 mappigs are applied i.e. TeX special chars like %
40 char *input_buffer, *output_buffer;
41 int main(int argc, char *argv[])
44 FILE *new_file, *ole_file;
46 short int *tmp_charset;
50 read_config_file(SYSTEMRC);
52 tempname=find_file(strdup(USERRC),getenv("HOME"));
54 read_config_file(tempname);
62 check_charset(&dest_csname,dest_csname);
64 while ((c=getopt(argc,argv,"Vlf:s:d:xq:c:b:g:p:"))!=-1) {
67 list_charsets(); exit(0);
69 unknown_as_hex = 1; break;
71 check_charset(&source_csname,optarg);
72 source_charset=read_charset(source_csname);
75 sheet_separator= strdup(optarg);
78 check_charset(&dest_csname,optarg);
82 quote_mode = strtol(optarg,&errptr,0);
83 if ((errptr && *errptr)||quote_mode<0||quote_mode>3) {
85 "argument of -q should be number from 0 to 3\n");
91 cell_separator = optarg[0];
94 forced_date_format = strdup(optarg);
98 int digits = strtol(optarg,&strend,0);
99 if (*strend||digits<0||digits>DBL_DIG) {
100 fprintf(stderr,"value of -g option should be numbe between 0 and %d, not '%s'\n", DBL_DIG, optarg);
103 sprintf(number_format,"%%.%dg",digits);
106 case 'V': printf("Catdoc Version %s\n",CATDOC_VERSION);
113 /* If we are using system strftime, we need to set LC_TIME locale
114 * category unless choosen charset is not same as system locale
116 #if defined(HAVE_LANGINFO) && defined(HAVE_STRFTIME) && !defined(__TURB0C__)
119 /* charset conversion init*/
120 input_buffer=malloc(FILE_BUFFER);
121 if (strcmp(dest_csname,"utf-8")) {
122 tmp_charset=read_charset(dest_csname);
124 fprintf(stderr,"Cannot load target charset %s\n",dest_csname);
127 target_charset=make_reverse_map(tmp_charset);
132 spec_chars=read_substmap(stradd("ascii",SPEC_EXT));
134 fprintf(stderr,"Cannod read substitution map ascii%s\n",
138 replacements=read_substmap(stradd("ascii",REPL_EXT));
140 fprintf(stderr,"Cannod read substitution map ascii%s\n",
145 if (isatty(fileno(stdin))) {
149 do_table(stdin,"STDIN");
152 for (i=optind;i<argc;i++) {
154 input=fopen(filename,"rb");
159 if ((new_file=ole_init(input, NULL, 0)) != NULL) {
161 while((ole_file=ole_readdir(new_file)) != NULL) {
162 int res=ole_open(ole_file);
163 /* fprintf(stderr, "name = %s\n", ((oleEntry*)ole_file)->name); */
165 if (strcasecmp(((oleEntry*)ole_file)->name , "Workbook") == 0
166 || strcasecmp(((oleEntry*)ole_file)->name,"Book") == 0) {
167 do_table(ole_file,filename);
176 fprintf(stderr, "%s is not OLE file or Error\n", filename);