filters

applixwordimport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2000 Enno Bartels <ebartels@nwn.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <config.h>
21
22#ifdef HAVE_UNISTD_H
23#include <unistd.h>
24#endif
25
26#include <tqmessagebox.h>
27#include <tqptrlist.h>
28#include <applixwordimport.h>
29#include <applixwordimport.moc>
30#include <kdebug.h>
31#include <KoFilterChain.h>
32#include <kgenericfactory.h>
33
34typedef KGenericFactory<APPLIXWORDImport, KoFilter> APPLIXWORDImportFactory;
35K_EXPORT_COMPONENT_FACTORY( libapplixwordimport, APPLIXWORDImportFactory( "kofficefilters" ) )
36
37
38/******************************************************************************
39 * class: APPLIXWORDImport function: APPLIXWORDImport *
40 ******************************************************************************
41 * *
42 * Short description : Constructor *
43 * *
44 * *
45 ******************************************************************************/
46APPLIXWORDImport::APPLIXWORDImport (KoFilter *, const char *, const TQStringList& ) :
47 KoFilter()
48{
49}
50
51/******************************************************************************
52 * class: APPLIXWORDImport function: nextLine *
53 ******************************************************************************
54 * *
55 * Short description : Readline and update progressbar *
56 * *
57 * *
58 ******************************************************************************/
59TQString
60APPLIXWORDImport::nextLine (TQTextStream & stream)
61{
62 TQString s;
63
64 // Read one Line
65 s = stream.readLine();
66
67 m_instep += s.length();
68 if (m_instep > m_stepsize)
69 {
70 m_instep = 0;
71 m_progress += 2;
72 emit sigProgress (m_progress) ;
73 }
74
75 return s;
76}
77
78
79
80/******************************************************************************
81 * class: APPLIXWORDImport function: filter *
82 ******************************************************************************
83 * *
84 * Short description : *
85 * *
86 * *
87 ******************************************************************************/
88KoFilter::ConversionStatus APPLIXWORDImport::convert( const TQCString& from, const TQCString& to )
89{
90
91 if (to!="application/x-kword" || from!="application/x-applixword")
92 return KoFilter::NotImplemented;
93
94 TQFile in(m_chain->inputFile());
95 if (!in.open (IO_ReadOnly))
96 {
97 kdError(30517) << "Unable to open input file!" << endl;
98 in.close();
99 return KoFilter::FileNotFound;
100 }
101
102
103 TQString str;
104
105 str += "<?xml version=\"1.0\"?>\n";
106 str += "<DOC author=\"Reginald Stadlbauer and Torben Weis\" email=\"reggie@kde.org and weis@kde.org\" editor=\"KWord\" mime=\"application/x-kword\">\n";
107 str += " <PAPER format=\"1\" ptWidth=\"595\" ptHeight=\"841\" mmWidth =\"210\" mmHeight=\"297\" inchWidth =\"8.26772\" inchHeight=\"11.6929\" orientation=\"0\" columns=\"1\" ptColumnspc=\"2\" mmColumnspc=\"1\" inchColumnspc=\"0.0393701\" hType=\"0\" fType=\"0\" ptHeadBody=\"9\" ptFootBody=\"9\" mmHeadBody=\"3.5\" mmFootBody=\"3.5\" inchHeadBody=\"0.137795\" inchFootBody=\"0.137795\">\n";
108 str += " <PAPERBORDERS mmLeft=\"10\" mmTop=\"15\" mmRight=\"10\" mmBottom=\"15\" ptLeft=\"28\" ptTop=\"42\" ptRight=\"28\" ptBottom=\"42\" inchLeft=\"0.393701\" inchTop=\"0.590551\" inchRight=\"0.393701\" inchBottom=\"0.590551\"/>\n";
109 str += " </PAPER>\n";
110 str += " <ATTRIBUTES processing=\"0\" standardpage=\"1\" hasHeader=\"0\" hasFooter=\"0\" />\n";
111 str += " <FRAMESETS>\n";
112 str += " <FRAMESET frameType=\"1\" autoCreateNewFrame=\"1\" frameInfo=\"0\" removeable=\"0\">\n";
113 str += " <FRAME left=\"28\" top=\"42\" right=\"566\" bottom=\"798\" runaround=\"1\" runaGapPT=\"2\" runaGapMM=\"1\" runaGapINCH=\"0.0393701\" lWidth=\"1\" lRed=\"255\" lGreen=\"255\" lBlue=\"255\" lStyle=\"0\" rWidth=\"1\" rRed=\"255\" rGreen=\"255\" rBlue=\"255\" rStyle=\"0\" tWidth=\"1\" tRed=\"255\" tGreen=\"255\" tBlue=\"255\" tStyle=\"0\" bWidth=\"1\" bRed=\"255\" bGreen=\"255\" bBlue=\"255\" bStyle=\"0\" bkRed=\"255\" bkGreen=\"255\" bkBlue=\"255\" bleftpt=\"0\" bleftmm=\"0\" bleftinch=\"0\" brightpt=\"0\" brightmm=\"0\" brightinch=\"0\" btoppt=\"0\" btopmm=\"0\" btopinch=\"0\" bbottompt=\"0\" bbottommm=\"0\" bbottominch=\"0\"/>\n";
114
115
116 TQTextStream stream (&in);
117
118 m_stepsize = in.size()/50;
119 m_instep = 0;
120 m_progress = 0;
121
122 int rueck;
123 int pos, ok;
124 char stylename[100];
125 TQString mystr, textstr;
126 TQPtrList<t_mycolor> mcol;
127 TQStringList mcoltxt;
128
129 /**************************************************************************
130 * Read header *
131 **************************************************************************/
132 if (! readHeader (stream, in)) return KoFilter::StupidError;
133
134
135 while (!stream.atEnd())
136 {
137 // Read one line
138 mystr = readTagLine (stream, in);
139 ok = true;
140
141 /**********************************************************************
142 * jump over start_styles if it exists *
143 **********************************************************************/
144 if (mystr == "<start_styles>")
145 {
146 printf ("Start styles\n");
147 t_mycolor *col = new t_mycolor; // delete is in place
148 TQString coltxt ;
149 int zaehler = 0; // Note: "zaehler" means "counter" in English
150 do
151 {
152 mystr = readTagLine (stream, in);
153 if (mystr == "<end_styles>")
154 {
155 ok = false;
156 kdDebug(30517)<<"End styles\n\n";
157 }
158 else
159 {
160 if (mystr.startsWith ("<color "))
161 {
162 mystr.remove (0, 8);
163 pos = mystr.find ("\"");
164 coltxt = mystr.left (pos);
165 mystr.remove (0,pos+1);
166 rueck = sscanf ((const char *) mystr.latin1() ,
167 ":%d:%d:%d:%d>",
168 &col->c, &col->m, &col->y, &col->k);
169 kdDebug(30517)<<" Color " << zaehler<<" : "<<col->c << " " << col->m<< " "<< col->y<<" "<< col->k<<" "<<coltxt<<" "<<endl;
170 zaehler ++;
171
172 // Color transformation cmyk -> rgb
173 col->r = 255 - (col->c + col->k);
174 if (col->r < 0) col->r = 0;
175
176 col->g = 255 - (col->m + col->k);
177 if (col->g < 0) col->g = 0;
178
179 col->b = 255 - (col->y + col->k);
180 if (col->b < 0) col->b = 0;
181
182 mcol.append (col);
183 mcoltxt.append (coltxt);
184 } //end if ...<col...
185 } //end else
186 } // end while
187 while (ok == true);
188 delete col;
189 } // end if ...<start_styles>...
190 /***********************************************************************
191 * jump over embedded Applix docs *
192 ***********************************************************************/
193 else if (mystr == "<start_data Applix>")
194 {
195 kdDebug(30517)<<"\nEmbedded Applix object starts:\n";
196 do
197 {
198 mystr = readTagLine (stream, in);
199 if (mystr == "<end_data>") ok = false;
200 else
201 {
202 kdDebug(30517)<<" "<<mystr<<endl;
203 }
204 }
205 while (ok == true);
206 kdDebug(30517)<<"Embedded Applix object ends\n\n";
207
208 }
209 /**********************************************************************
210 * jump over header footer *
211 **********************************************************************/
212 else if (mystr.startsWith ("<start_hdrftr "))
213 {
214 kdDebug(30517)<<"\nHeader/Footer starts:\n";
215 do
216 {
217 mystr = readTagLine (stream, in);
218 if (mystr == "<end_hdrftr>") ok = false;
219 else
220 {
221 kdDebug(30517)<<" "<<mystr<<endl;
222 }
223 }
224 while (ok == true);
225 kdDebug(30517)<<"\nHeader/Footer ends\n";
226 }
227 /**********************************************************************
228 * found a paragraph string *
229 **********************************************************************/
230 else if (mystr.startsWith ("<P "))
231 {
232 sscanf ( (const char *) mystr.latin1(), "<P \"%99s\"", stylename);
233 mystr.remove (0, 5+strlen(stylename));
234 kdDebug(30517)<<" Para Name: "<< stylename<<endl;
235 kdDebug(30517)<<" Rest: "<<mystr<<endl;
236 }
237 /**********************************************************************
238 * found a textstring *
239 **********************************************************************/
240 else if (mystr.startsWith ("<T "))
241 {
242 TQString colname;
243
244 // Remove starting tab info
245 mystr.remove (0, 4);
246
247 // Remove ending >
248 mystr.remove (mystr.length()-1, 1);
249
250 // Separate textstring "
251 ok = true;
252 int y=0;
253 do
254 {
255 pos = mystr.find ("\"", y);
256 kdDebug(30517)<<"POS:"<<pos<<" length:"<< mystr.length()<<" y:"<<y <<endl;
257
258 kdDebug(30517)<<"< "<<mystr<<" >\n";
259 if( (pos-1 > -1) && (mystr[pos-1] == '\\'))
260 {
261 kdDebug(30517)<<" No string end - but Gänsefüsschen\n";
262 y=pos+1;
263 }
264 else
265 {
266 kdDebug(30517)<<" String end //\n";
267 ok = false;
268 }
269 }
270 while (ok == true);
271
272 textstr = mystr.left (pos);
273 mystr.remove (0, pos+1);
274 mystr.stripWhiteSpace();
275 kdDebug(30517) <<"Text:<" <<textstr <<" > "<< pos<<" Rest:<"<< mystr<<"> \n";
276
277 // split format
278 TQStringList typeList;
279 typeList = TQStringList::split (' ', mystr);
280
281 int fontsize=12, bold=0, italic=0, underline=0, colpos=-1;
282 TQString fontname;
283 int nn=0;
284 for (TQStringList::Iterator it = typeList.begin(); it != typeList.end(); ++it )
285 {
286 kdDebug(30517) <<" No: "<< nn<< " > "<< (*it)<< "< = \n";
287
288 // Looking for bold
289 if ((*it) == "bold")
290 {
291 bold = 1;
292 kdDebug(30517)<<"bold\n";
293 }
294 else if ((*it) == "no-bold")
295 {
296 bold = 0;
297 kdDebug(30517)<<"no bold\n";
298 }
299 else if ((*it) == "italic")
300 {
301 italic = 1;
302 kdDebug(30517)<<"italic\n";
303 }
304 else if ((*it) == "no-italic")
305 {
306 italic = 0;
307 kdDebug(30517) <<"no italic\n";
308 }
309 else if ((*it) == "underline")
310 {
311 underline = 1;
312 kdDebug(30517)<<"underline\n";
313 }
314 else if ((*it) == "no-underline")
315 {
316 underline = 0;
317 kdDebug(30517) <<"no underline\n";
318 }
319 else if ((*it).startsWith ("size"))
320 {
321 (*it).remove (0, 5);
322 sscanf ( (const char *) (*it).latin1(), "%d", &fontsize);
323 kdDebug(30517)<<"fontsize: "<< fontsize<<endl;
324 }
325 else if ((*it).startsWith ("face"))
326 {
327 (*it).remove (0, 6);
328 (*it).remove ((*it).length()-1, 1);
329 fontname = *it;
330 kdDebug(30517)<<"fontname: "<<fontname<<endl;
331 }
332 else if ((*it).startsWith ("color:"))
333 {
334 (*it).remove (0, 7);
335 (*it).remove ((*it).length()-1, 1);
336 colname = *it;
337 colpos = mcoltxt.findIndex (colname);
338 kdDebug(30517) <<" Color: "<< colname<<" "<< colpos <<" \n";
339 }
340 else
341 {
342 kdDebug(30517)<<" "<< (*it)<<endl;
343 }
344
345
346 }
347 kdDebug(30517) <<"\n";
348
349 // Replaces Part for & <>, applixwear special characters and qouts
350 replaceSpecial (textstr);
351
352
353 // add text inside
354 str += " <PARAGRAPH>\n";
355 str += " <TEXT>";
356 str += textstr;
357 str += "</TEXT>\n";
358
359 if (bold == 1 || underline == 1 || italic == 1 || fontsize != 12 ||
360 colpos != -1 || !fontname.isEmpty())
361 {
362 str += " <LAYOUT>\n";
363 str += " <FORMAT>\n";
364 if (!fontname.isEmpty())
365 {
366 str += " <FONT name=\"";
367 str += fontname;
368 str += "\" />\n";
369 }
370
371 if (fontsize != 1)
372 {
373 str += " <SIZE value=\"";
374 str += TQString::number (fontsize);
375 str += "\" />\n";
376 }
377
378 if (italic == 1)
379 {
380 str += " <ITALIC value=\"1\" />\n";
381 }
382
383 if (bold == 1)
384 {
385 str += " <WEIGHT value=\"75\" />\n";
386 }
387
388 if (underline == 1)
389 {
390 str += " <UNDERLINE value=\"1\" />\n";
391 }
392
393 if (colpos != -1)
394 {
395 t_mycolor *mc = new t_mycolor; // delete is in place
396 mc = mcol.at(colpos);
397 str += " <COLOR red=\"";
398
399 str += TQString::number (mc->r);
400 str += "\" green=\"";
401 str += TQString::number (mc->g);
402 str += "\" blue=\"";
403 str += TQString::number (mc->b);
404 str += "\" />\n";
405 delete mc;
406 }
407
408 str += " </FORMAT>\n";
409 str += " </LAYOUT>\n";
410 }
411 str += " </PARAGRAPH>\n";
412 }
413
414 }
415 emit sigProgress(100);
416
417 str += " </FRAMESET>\n";
418 str += " </FRAMESETS>\n";
419 str += "</DOC>\n";
420 kdDebug(30517)<<"Text "<< str <<endl;
421
422 KoStoreDevice* out = m_chain->storageFile( "root", KoStore::Write );
423 if (!out)
424 {
425 kdError(30517) << "Unable to open output file!" << endl;
426 in.close ();
427 return KoFilter::StorageCreationError;
428 }
429
430 TQCString cstring = str.utf8 ();
431
432 out->writeBlock ((const char*) cstring, cstring.length());
433
434 in.close ();
435 return KoFilter::OK;
436}
437
438
439/******************************************************************************
440 * function: specCharfind *
441 ******************************************************************************/
442TQChar
443APPLIXWORDImport::specCharfind (TQChar a, TQChar b)
444{
445 TQChar chr;
446
447 if ( (a == 'n') && (b == 'p') ) chr = 'ß';
448
449
450 else if ( (a == 'n') && (b == 'c') ) chr = 'Ò';
451 else if ( (a == 'p') && (b == 'c') ) chr = 'ò';
452
453 else if ( (a == 'n') && (b == 'd') ) chr = 'Ó';
454 else if ( (a == 'p') && (b == 'd') ) chr = 'ó';
455
456 else if ( (a == 'n') && (b == 'e') ) chr = 'Ô';
457 else if ( (a == 'p') && (b == 'e') ) chr = 'ô';
458
459 else if ( (a == 'n') && (b == 'f') ) chr = 'Õ';
460 else if ( (a == 'p') && (b == 'f') ) chr = 'õ';
461
462 else if ( (a == 'p') && (b == 'g') ) chr = 'ö';
463 else if ( (a == 'n') && (b == 'g') ) chr = 'Ö';
464
465
466
467 else if ( (a == 'n') && (b == 'j') ) chr = 'Ù';
468 else if ( (a == 'p') && (b == 'j') ) chr = 'ù';
469
470 else if ( (a == 'n') && (b == 'k') ) chr = 'Ú';
471 else if ( (a == 'p') && (b == 'k') ) chr = 'ú';
472
473 else if ( (a == 'n') && (b == 'l') ) chr = 'Û';
474 else if ( (a == 'p') && (b == 'l') ) chr = 'û';
475
476 else if ( (a == 'p') && (b == 'm') ) chr = 'ü';
477 else if ( (a == 'n') && (b == 'm') ) chr = 'Ü';
478
479
480
481 else if ( (a == 'm') && (b == 'a') ) chr = 'À';
482 else if ( (a == 'o') && (b == 'a') ) chr = 'à';
483
484 else if ( (a == 'm') && (b == 'b') ) chr = 'Á';
485 else if ( (a == 'o') && (b == 'b') ) chr = 'á';
486
487 else if ( (a == 'm') && (b == 'c') ) chr = 'Â';
488 else if ( (a == 'o') && (b == 'c') ) chr = 'â';
489
490 else if ( (a == 'm') && (b == 'd') ) chr = 'Ã';
491 else if ( (a == 'o') && (b == 'd') ) chr = 'ã';
492
493 else if ( (a == 'm') && (b == 'e') ) chr = 'Ä';
494 else if ( (a == 'o') && (b == 'e') ) chr = 'ä';
495
496 else if ( (a == 'm') && (b == 'f') ) chr = 'Å';
497 else if ( (a == 'o') && (b == 'f') ) chr = 'å';
498
499 else if ( (a == 'm') && (b == 'g') ) chr = 'Æ';
500 else if ( (a == 'o') && (b == 'g') ) chr = 'æ';
501
502
503
504 else if ( (a == 'm') && (b == 'i') ) chr = 'È';
505 else if ( (a == 'o') && (b == 'i') ) chr = 'è';
506
507 else if ( (a == 'm') && (b == 'j') ) chr = 'É';
508 else if ( (a == 'o') && (b == 'j') ) chr = 'é';
509
510 else if ( (a == 'm') && (b == 'k') ) chr = 'Ê';
511 else if ( (a == 'o') && (b == 'k') ) chr = 'ê';
512
513 else if ( (a == 'm') && (b == 'l') ) chr = 'Ë';
514 else if ( (a == 'o') && (b == 'l') ) chr = 'ë';
515
516
517
518
519
520
521 else if ( (a == 'm') && (b == 'm') ) chr = 'Ì';
522 else if ( (a == 'o') && (b == 'm') ) chr = 'ì';
523
524 else if ( (a == 'm') && (b == 'n') ) chr = 'Í';
525 else if ( (a == 'o') && (b == 'n') ) chr = 'í';
526
527 else if ( (a == 'm') && (b == 'o') ) chr = 'Î';
528 else if ( (a == 'o') && (b == 'o') ) chr = 'î';
529
530 else if ( (a == 'm') && (b == 'p') ) chr = 'Ï';
531 else if ( (a == 'o') && (b == 'p') ) chr = 'ï';
532
533
534 else if ( (a == 'n') && (b == 'b') ) chr = 'Ñ';
535 else if ( (a == 'p') && (b == 'b') ) chr = 'ñ';
536
537
538 else if ( (a == 'k') && (b == 'c') ) chr = '¢';
539 else if ( (a == 'k') && (b == 'j') ) chr = '©';
540 else if ( (a == 'l') && (b == 'f') ) chr = 'µ';
541 else if ( (a == 'n') && (b == 'i') ) chr = 'Ø';
542 else if ( (a == 'p') && (b == 'i') ) chr = 'ø';
543
544 else if ( (a == 'l') && (b == 'j') ) chr = '¹';
545 else if ( (a == 'l') && (b == 'c') ) chr = '²';
546 else if ( (a == 'l') && (b == 'd') ) chr = '³';
547
548 else if ( (a == 'l') && (b == 'm') ) chr = '¼';
549 else if ( (a == 'l') && (b == 'n') ) chr = '½';
550 else if ( (a == 'l') && (b == 'o') ) chr = '¾';
551
552 else if ( (a == 'l') && (b == 'a') ) chr = '°';
553
554 else if ( (a == 'k') && (b == 'o') ) chr = '®';
555 else if ( (a == 'k') && (b == 'h') ) chr = '§';
556 else if ( (a == 'k') && (b == 'd') ) chr = '£';
557
558 else if ( (a == 'p') && (b == 'a') ) chr = 'ð';
559 else if ( (a == 'n') && (b == 'a') ) chr = 'Ð';
560
561 else if ( (a == 'l') && (b == 'l') ) chr = '»';
562 else if ( (a == 'k') && (b == 'l') ) chr = '«';
563
564 else if ( (a == 'l') && (b == 'k') ) chr = 'º';
565
566 else if ( (a == 'l') && (b == 'h') ) chr = '·';
567
568 else if ( (a == 'k') && (b == 'b') ) chr = '¡';
569
570 else if ( (a == 'k') && (b == 'e') ) chr = '¤';
571
572 else if ( (a == 'l') && (b == 'b') ) chr = '±';
573
574 else if ( (a == 'l') && (b == 'p') ) chr = '¿';
575
576 else if ( (a == 'k') && (b == 'f') ) chr = '¥';
577
578 else if ( (a == 'p') && (b == 'o') ) chr = 'þ';
579 else if ( (a == 'n') && (b == 'o') ) chr = 'Þ';
580
581 else if ( (a == 'n') && (b == 'n') ) chr = 'Ý';
582 else if ( (a == 'p') && (b == 'n') ) chr = 'ý';
583 else if ( (a == 'p') && (b == 'p') ) chr = 'ÿ';
584
585 else if ( (a == 'k') && (b == 'k') ) chr = 'ª';
586
587 else if ( (a == 'k') && (b == 'm') ) chr = '¬';
588 else if ( (a == 'p') && (b == 'h') ) chr = '÷';
589
590 else if ( (a == 'k') && (b == 'g') ) chr = '|';
591
592 else if ( (a == 'l') && (b == 'e') ) chr = '\'';
593
594 else if ( (a == 'k') && (b == 'i') ) chr = '¨';
595
596 else if ( (a == 'k') && (b == 'n') ) chr = '­';
597
598 else if ( (a == 'k') && (b == 'p') ) chr = '¯';
599
600 else if ( (a == 'l') && (b == 'g') ) chr = '¶';
601
602 else if ( (a == 'l') && (b == 'i') ) chr = '¸';
603
604 else if ( (a == 'm') && (b == 'h') ) chr = 'Ç';
605 else if ( (a == 'o') && (b == 'h') ) chr = 'ç';
606
607 else if ( (a == 'n') && (b == 'h') ) chr = '×';
608
609 else if ( (a == 'k') && (b == 'a') ) chr = ' ';
610
611 else if ( (a == 'a') && (b == 'j') ) chr = '!';
612
613 else chr = '#';
614
615 return chr;
616}
617
618
619
620/******************************************************************************
621 * class: APPLIXWORDImport function: readTagLine *
622 ******************************************************************************
623 * *
624 * Short description : *
625 * *
626 * *
627 ******************************************************************************/
628TQString
629APPLIXWORDImport::readTagLine (TQTextStream &stream, TQFile &in)
630{
631 TQString mystrn, mystr;
632 int ok, pos;
633
634 // Read one line
635 mystr = nextLine (stream);
636
637 // Delete whitespaces
638 mystr.stripWhiteSpace();
639
640 // Look if the tag continues on the next line
641 if ((mystr.length() == 80) && (mystr[mystr.length()-1] == '\\') )
642 {
643 ok = true;
644 do
645 {
646 // Get the actual position in the file
647 pos = in.at ();
648
649 // Read next line
650 mystrn = nextLine (stream);
651
652 // Is the new line a new tag line
653 if (mystrn[0] == ' ')
654 {
655 // remove the whitespace at the start of the new line
656 mystrn.remove (0, 1);
657
658 // remove the '/' at the end of the old line
659 mystr.remove (mystr.length()-1, 1);
660
661 // append the new line
662 mystr += mystrn;
663 }
664 else
665 {
666 // was the newline a newtaglien the jump back
667 in.at (pos);
668 ok = false;
669 }
670 }
671 while (ok == true);
672 }
673
674 return mystr;
675}
676
677
678
679
680/******************************************************************************
681 * class: APPLIXWORDImport function: replaceSpecial *
682 ******************************************************************************
683 * *
684 * Short description : *
685 * *
686 * *
687 ******************************************************************************/
688void
689APPLIXWORDImport::replaceSpecial (TQString &textstr)
690{
691 int ok, pos;
692
693 // 1. Replace Part for this characters: <, >, &
694 textstr.replace ('&', "&amp;");
695 textstr.replace ('<', "&lt;");
696 textstr.replace ('>', "&gt;");
697
698
699 // 2. Replace part for this characters: applixwear qoutes
700 ok = true;
701 pos = 0;
702 do
703 {
704 // Searching for an quote
705 pos = textstr.find ('\"', pos);
706
707 // Is it an textqoute ?
708 if ((pos > -1) && (textstr[pos-1] == '\\'))
709 {
710 textstr.replace (pos-1, 2,"\"");
711 }
712 else
713 {
714 ok = false;
715 }
716 }
717 while (ok == true);
718
719
720
721 // 3. Replace part for Applix Characters
722 int foundSpecialCharakter;
723 TQChar newchar;
724
725 do
726 {
727 // initialize
728 foundSpecialCharakter = false;
729
730 pos = textstr.find ("^");
731
732 // is there a special character ?
733 if (pos > -1 )
734 {
735 // i have found a special character !
736 foundSpecialCharakter = true;
737
738 // translate the applix special character
739 newchar = specCharfind (textstr[pos+1], textstr[pos+2]);
740
741 // replace the character
742 textstr.replace (pos, 3, newchar);
743 }
744 }
745 while (foundSpecialCharakter == true);
746}
747
748
749
750/******************************************************************************
751 * class: APPLIXWORDImport function: readHeader *
752 ******************************************************************************
753 * *
754 * Short description : *
755 * *
756 * *
757 ******************************************************************************/
758int
759APPLIXWORDImport::readHeader (TQTextStream &stream, TQFile &in)
760{
761 TQString mystr;
762 int rueck;
763 int vers[3] = { 0, 0, 0 };
764
765 // Read Headline
766 mystr = readTagLine (stream, in);
767
768 // mystr = stream.readLine ();
769 rueck = sscanf ((const char *) mystr.latin1() ,
770 "*BEGIN WORDS VERSION=%d/%d ENCODING=%dBIT",
771 &vers[0], &vers[1], &vers[2]);
772 printf ("Versions info: %d %d %d\n", vers[0], vers[1], vers[2]);
773
774 // Check the headline
775 if (rueck <= 0)
776 {
777 printf ("Header not correkt - May be it is not an applixword file\n");
778 printf ("Headerline: <%s>\n", (const char *) mystr.latin1());
779
780 TQMessageBox::critical (0L, "Applixword header problem",
781 TQString ("The Applixword header is not correct. "
782 "May be it is not an applixword file! <BR>"
783 "This is the header line I did read:<BR><B>%1</B>").arg(mystr.latin1()),
784 "Okay");
785
786 // i18n( "What is the separator used in this file ? First line is \n%1" ).arg(firstLine),
787 return false;
788 }
789 else return true;
790}