"Fossies" - the Fresh Open Source Software Archive

Member "wp2latex-3.82/sources.cc/pass1_4.cc" (4 Aug 2018, 27827 Bytes) of package /linux/misc/wp2latex-3.82.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "pass1_4.cc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 3.77_vs_3.78.

    1 /******************************************************************************
    2  * program:     wp2latex                                                      *
    3  * function:    convert WordPerfect files into LaTeX                          *
    4  * modul:       pass1_4.cc                                                    *
    5  * description: This is conversion module for parsing WP 4.x binary files.    *
    6  *              Encrypted WP4.x files are handled by pass1c45 module.         *
    7  * licency:     GPL                                                   *
    8  ******************************************************************************/
    9 #include <string.h>
   10 #include <stdio.h>
   11 #include <stdlib.h>
   12 #include <ctype.h>
   13 
   14 #include <sets.h>
   15 #include <strings.h>
   16 #include <lists.h>
   17 #include "wp2latex.h"
   18 
   19 #include "cp_lib/cptran.h"
   20 
   21 
   22 int set0_40[]={0 ___ 0xFF};     //Everything
   23 int set1_40[]={0 ___ 0xBF,0xC0,0xC3,0xC4,0xD1,0xD2,0xD4 ___ 0xFF}; //Header, Footer, Minipage Text
   24 int set2_40[]={0x20 ___ 0x7F,0xE1};  //Characters Only
   25 
   26 //0 - object must be handled specialy, size is not defined
   27 extern BYTE ObjWP4SizesC0[];
   28 
   29 
   30 class TconvertedPass1_WP4: public TconvertedPass1
   31      {
   32 public:char UnderlineType;
   33      char SubSup;
   34      SBYTE DefColumns;
   35      char LogLevel;
   36 
   37      virtual int Convert_first_pass(void);
   38 
   39 protected:
   40      set filter[4];
   41 
   42      void Comment4(DWORD & NewPos, WORD & w);
   43      void Character4(void);
   44      void ColDef4(void);
   45      bool CheckConzistency4(long NewPos);
   46      void DefMarkedText4(DWORD & NewPos);
   47      void FootEndNote(DWORD & NewPos, WORD & w);
   48      void FootNoteObsolette(DWORD & NewPos, WORD & w);
   49      void Header_Footer4(DWORD & NewPos, WORD & w);
   50      void InitFilter4(void);
   51      void InvisibleChars4(DWORD & NewPos, WORD & w);
   52      void MakeIndex4(DWORD & NewPos);
   53      void Overstrike4(DWORD & NewPos, WORD & w);
   54      void ProcessKey4(void);     
   55      void TableOfAuthorities4(DWORD & NewPos);
   56      void Tabset4(void);
   57      void UnderlineMode4(void);
   58      };
   59 
   60 
   61 #ifndef FINAL
   62 void CrackObject(TconvertedPass1 *cq, DWORD end_of_code);
   63 #endif
   64 
   65 /*Register translators here*/
   66 TconvertedPass1 *Factory_WP4(void) {return new TconvertedPass1_WP4;}
   67 FFormatTranslator FormatWP4("WP4.x",Factory_WP4);
   68 
   69 
   70 //Converting wp4.2 units to wp5.x units
   71 #define u2w(x) (120*x)
   72 
   73 
   74 /// Convert a simple character in WP4
   75 void TconvertedPass1_WP4::Character4(void)
   76 {
   77 #ifdef DEBUG
   78   fprintf(log,"\n#Character4() ");fflush(log);
   79 #endif
   80 
   81   fread(&subby, 1, 1, wpd);
   82 
   83   CharacterStr(this,Ext_chr_str(subby,this,ConvertCpg));
   84 
   85   sprintf(ObjType, ":%u",(unsigned)subby);
   86 }
   87 
   88 
   89 void TconvertedPass1_WP4::ColDef4(void)
   90 {
   91 #ifdef DEBUG
   92   fprintf(log,"\n#ColDef4() ");fflush(log);
   93 #endif
   94 
   95   fseek(wpd, 49L, SEEK_CUR);
   96   fread(&DefColumns, 1, 1, wpd);   /* new number of columns */
   97 
   98   sprintf(ObjType, "ColDef:%d",(int)DefColumns);
   99   if(Columns==0 && DefColumns>2) DefColumns=2;
  100 }
  101 
  102 
  103 
  104 void TconvertedPass1_WP4::Comment4(DWORD & NewPos, WORD & w)
  105 {
  106 #ifdef DEBUG
  107   fprintf(log,"\n#Comment4() ");fflush(log);
  108 #endif
  109   signed char Old_char_on_line;
  110   unsigned char OldFlag;
  111   attribute OldAttr;
  112 
  113 
  114   OldFlag = flag;
  115   OldAttr = attr;
  116   Old_char_on_line = char_on_line;
  117   flag = CharsOnly;
  118   recursion++;
  119   InitAttr(attr);       //Turn all attributes in the comment off
  120 
  121   fseek(wpd, 4, SEEK_CUR);
  122 
  123   fputc('%',strip);
  124   NewPos = ActualPos = ftell(wpd);
  125   while (!feof(wpd))
  126        {
  127        fread(&by, 1, 1, wpd);
  128        if(by==0)    //End of comment text
  129             {
  130                 while (!feof(wpd) && !(by==0xF2))
  131                     fread(&by, 1, 1, wpd);
  132                 }
  133        if(by==0xF2) break;
  134        if(by==0xA || by==0xD)   //New comment line
  135             {
  136                 line_term = 's';        //Soft return
  137         Make_tableentry_envir_extra_end(this);
  138         fprintf(strip, "\n");
  139         rownum++;
  140         Make_tableentry_attr(this);
  141 
  142                 fputc('%',strip);
  143                 }
  144 
  145        ProcessKey4();
  146        continue;
  147        }
  148   ActualPos = ftell(wpd);
  149   w = ActualPos-NewPos+5;
  150   NewPos = ActualPos;
  151 
  152   line_term = 's';      //Soft return
  153   Make_tableentry_envir_extra_end(this);
  154   fprintf(strip, "\n");
  155   rownum++;
  156   Make_tableentry_attr(this);
  157 
  158 
  159   recursion--;
  160   strcpy(ObjType, "Comment");
  161   attr = OldAttr;
  162   flag = OldFlag;
  163   if(Old_char_on_line==true || Old_char_on_line==-1) char_on_line = -1;
  164     else char_on_line = false;
  165 }
  166 
  167 
  168 void TconvertedPass1_WP4::FootEndNote(DWORD & NewPos, WORD & w)
  169 {
  170 #ifdef DEBUG
  171   fprintf(log,"\n#FootEndNote() ");fflush(log);
  172 #endif
  173   unsigned char OldFlag;
  174   attribute OldAttr;
  175   unsigned char NoteType;
  176 
  177 
  178   OldFlag = flag;
  179   OldAttr = attr;
  180   flag = HeaderText;
  181   recursion++;
  182   InitAttr(attr);       //Turn all attributes in the note off
  183 
  184   NewPos = ftell(wpd);
  185   fread(&NoteType, 1, 1, wpd);
  186   if(NoteType == 2) {
  187           if(!EndNotes) EndNotes=true;      /* set up endnotes */
  188           if(EndNotes<0) goto FootNote;     /* endnotes are disabled */
  189           fprintf(strip, "\\endnote{");
  190           }
  191         else {
  192 FootNote:    fprintf(strip, "\\footnote{");
  193          }
  194 
  195 
  196   while (!feof(wpd))    // Skip everything to the mark 0xFF
  197     {
  198     if(fread(&by, 1, 1, wpd)!=1) goto EmptyNote;
  199     if(by==0xE2) goto EmptyNote;
  200     if(by==0xFF) break; // real start of the note text
  201     }
  202   fseek(wpd, 2l, SEEK_CUR);     /* margins */
  203 
  204 
  205   ActualPos = ftell(wpd);
  206   while (!feof(wpd))
  207        {
  208        if(fread(&by, 1, 1, wpd)!=1) break;
  209 
  210        if(by==0xE2) break;
  211        if(by==0) {ActualPos++;continue;}
  212 
  213        ProcessKey4();
  214        }
  215 
  216 EmptyNote:
  217   ActualPos = ftell(wpd);
  218   w = ActualPos-NewPos+1;
  219   NewPos = ActualPos;
  220 
  221   fputc('}',strip);
  222 
  223   recursion--;
  224   strcpy(ObjType, NoteType==2?"Endnote":"Footnote");
  225   attr = OldAttr;
  226   flag = OldFlag;
  227   char_on_line = true;
  228 }
  229 
  230 
  231 void TconvertedPass1_WP4::FootNoteObsolette(DWORD & NewPos, WORD & w)
  232 {
  233 #ifdef DEBUG
  234   fprintf(log,"\n#FootNote() ");fflush(log);
  235 #endif
  236   unsigned char OldFlag;
  237   attribute OldAttr;
  238 
  239 
  240   OldFlag = flag;
  241   OldAttr = attr;
  242   flag = CharsOnly;
  243   recursion++;
  244   InitAttr(attr);       //Turn all attributes in the note off
  245 
  246   fseek(wpd, 5L, SEEK_CUR);
  247   fprintf(strip, "\\footnote{");
  248 
  249   ActualPos = ftell(wpd);
  250   while (!feof(wpd))
  251        {
  252        fread(&by, 1, 1, wpd);
  253 
  254        if(by==0xD2) break;
  255 
  256        ProcessKey4();
  257        }
  258 
  259   ActualPos = ftell(wpd);
  260   w = ActualPos-NewPos+1;
  261   NewPos = ActualPos;
  262 
  263   fputc('}',strip);
  264 
  265   recursion--;
  266   strcpy(ObjType, "Footnote");
  267   attr = OldAttr;
  268   flag = OldFlag;
  269   char_on_line = true;
  270 }
  271 
  272 
  273 void TconvertedPass1_WP4::Header_Footer4(DWORD & NewPos, WORD & w)
  274 {
  275 #ifdef DEBUG
  276   fprintf(log,"\n#Header_Footer4() ");fflush(log);
  277 #endif
  278   unsigned char OldFlag,OldEnvir;
  279   attribute OldAttr;
  280   unsigned char HFtype,HFtype2;
  281   long PosX;
  282   char SaveLLevel=LogLevel;
  283 
  284   OldFlag = flag;
  285   OldAttr = attr;
  286   OldEnvir= envir;
  287 
  288 
  289   PosX = ftell(wpd) + 6;
  290   fread(&HFtype, 1, 1, wpd);
  291 
  292   fseek(wpd, PosX, SEEK_SET);
  293   ActualPos = PosX;
  294   flag = Nothing;
  295   LogLevel = 0;     //do not log dummy scan
  296   while (!feof(wpd))    //This loop scans the header only
  297        {
  298        fread(&by, 1, 1, wpd);
  299 
  300        if(by==0xFF)
  301             {
  302                 fread(&subby, 1, 1, wpd);
  303                 fread(&HFtype2, 1, 1, wpd);
  304                 fread(&by, 1, 1, wpd);
  305         if(by!=0xD1) goto EndHeaderFooter; //This object is corrupted
  306                 NewPos = ftell(wpd);
  307         break;
  308                 }
  309        if(by==0xD1)
  310             {
  311                 HFtype2=HFtype | 4;
  312                 ActualPos = ftell(wpd);
  313                 break;
  314                 }
  315 
  316        ProcessKey4();
  317        }
  318   if(feof(wpd)) goto EndHeaderFooter; //This object is corrupted
  319   w=ActualPos-PosX+6;
  320 
  321 // Start a conversion of a Header or Footer
  322   LogLevel = SaveLLevel;
  323   InitAttr(attr);       //Turn all attributes in the header/footer off
  324   recursion++;
  325 
  326   line_term = 's';      //Soft return
  327   if(char_on_line == -20)    /* Left one enpty line for new enviroment */
  328       {
  329       fputc('%', table);
  330       fputc('%', strip);
  331       NewLine(this);
  332       }
  333   if(char_on_line==true)
  334       {
  335       NewLine(this);
  336       }
  337 
  338 //               (HFtype2 & 3) <= 1 ? "\\headtext":"\\foottext"
  339   InitHeaderFooter(this, HFtype2 & 3, HFtype2 >> 2);
  340 
  341   envir='!';        //Ignore enviroments after header/footer
  342   NewLine(this);
  343 
  344   fseek(wpd, PosX, SEEK_SET);
  345   ActualPos = PosX;
  346   envir = ' ';
  347   flag = HeaderText;
  348   char_on_line = -10;
  349   while (!feof(wpd))
  350        {
  351        fread(&by, 1, 1, wpd);
  352 
  353        if(by==0xFF || by==0xD1) break;
  354 
  355        ProcessKey4();
  356        }
  357 
  358   Close_All_Attr(attr,strip);
  359   if(char_on_line==true)
  360      {
  361      line_term = 's';       //Soft return
  362      NewLine(this);
  363      }
  364   putc('}', strip);
  365 
  366   line_term = 's';      //Soft return
  367   envir='^';        //Ignore enviroments after header/footer
  368   NewLine(this);
  369 
  370   recursion--;
  371 
  372   attr = OldAttr;
  373   flag = OldFlag;
  374   envir= OldEnvir;
  375   char_on_line = -10;
  376 
  377 EndHeaderFooter:
  378   LogLevel=SaveLLevel;
  379   strcpy(ObjType, ((HFtype & 3) <= 1)?"Header":"Footer");
  380 }
  381 
  382 
  383 /* LineSpacing is called whenever we hit a line-spacing-change command.
  384  * The argument is the desired line spacing, multiplied by two.
  385  * So single spacing gets a 2, 1.5 spacing gets a 3, etc.  */
  386 static void LineSpacing4(TconvertedPass1 *cq)
  387 {
  388 #ifdef DEBUG
  389   fprintf(cq->log,"\n#LineSpacing4() ");fflush(cq->log);
  390 #endif
  391 WORD CurrentSpacing;
  392 char b;
  393 
  394   b = (WORD)fgetc(cq->wpd) * 64;           //LastSpacing
  395   CurrentSpacing=(WORD)fgetc(cq->wpd) * 64;
  396 
  397   b = 'l';
  398   fwrite(&b, 1, 1, cq->table);
  399   Wr_word(cq->table,CurrentSpacing);
  400 
  401   sprintf(cq->ObjType, "Line Spacing %2.2f",float(CurrentSpacing)/128);
  402 }
  403 
  404 
  405 static void LineUpDown(TconvertedPass1_WP4 *cq, float offset)
  406 {
  407 #ifdef DEBUG
  408   fprintf(cq->log,"\n#LineUpDown(%f) ",offset);fflush(cq->log);
  409 #endif
  410 
  411   fprintf(cq->strip, "\\vspace*{%2.2fex}", offset);
  412 
  413   sprintf(cq->ObjType, "Advance Up/Down %2.2f",offset);
  414 }
  415 
  416 
  417 void TconvertedPass1_WP4::MakeIndex4(DWORD & NewPos)
  418 {
  419 #ifdef DEBUG
  420   fprintf(log,"\n#MakeIndex4() ");fflush(log);
  421 #endif
  422   signed char Old_char_on_line;
  423   unsigned char OldFlag;
  424   attribute OldAttr;
  425 
  426 
  427   OldFlag = flag;
  428   OldAttr = attr;
  429   Old_char_on_line = char_on_line;
  430   flag = CharsOnly;
  431   recursion++;
  432   InitAttr(attr);       //Turn all attributes in the index off
  433 
  434 
  435   fprintf(strip, " \\index{");
  436 
  437   NewPos = ActualPos = ftell(wpd);
  438   while (!feof(wpd))
  439        {
  440        fread(&by, 1, 1, wpd);
  441        if(by==0)    //End of index text
  442         {
  443                 while (!feof(wpd) && !(by==0xEA))
  444                     fread(&by, 1, 1, wpd);
  445                 }
  446        if(by==0xEA) break;
  447        if(by==0xE1)     //Extended char ?
  448         {
  449         fseek(wpd, 2, SEEK_CUR);
  450         continue;
  451         }
  452        if(by==0xA || by==0xD)   //New line -- ignore
  453             {
  454                 fprintf(strip,"_nl");
  455                 continue;
  456                 }
  457        if(by=='\\') {fputs("_bsl", strip); continue;}
  458        if(by=='$')  {fputs("_dol", strip); continue;}
  459        if(by=='{')  {fputs("_opb", strip); continue;}
  460        if(by=='}')  {fputs("_clb", strip); continue;}
  461        if(by=='_')  {fputs("_und", strip); continue;}
  462 
  463        ProcessKey4();
  464        }
  465 
  466   ActualPos = ftell(wpd);
  467 //w = ActualPos-NewPos+5;
  468   NewPos = ActualPos;
  469 
  470   fputc('}',strip);
  471   Index=true;
  472 
  473   recursion--;
  474   strcpy(ObjType, "Index");
  475   attr = OldAttr;
  476   flag = OldFlag;
  477   char_on_line = Old_char_on_line;
  478   char_on_line = true;
  479 }
  480 
  481 
  482 void TconvertedPass1_WP4::Overstrike4(DWORD & NewPos, WORD & w)
  483 {
  484 #ifdef DEBUG
  485   fprintf(log,"\n#Overstrike4() ");fflush(log);
  486 #endif
  487   char OldSubSup,OldMathDepth;
  488 
  489   if(char_on_line<=0)
  490     {
  491     strcpy(ObjType, "!Overstrike");
  492     return;
  493     }
  494 
  495   ActualPos = ftell(wpd);
  496 
  497   by=fgetc(wpd);
  498   while( (by>=0x90 && by<=0x97)||(by>=0xB2 && by<=0xBD)) //attributes
  499     {
  500     ProcessKey4();
  501     by=fgetc(wpd);
  502     }
  503 
  504   if((by>=0x20 && by< 0x80) || by==0xE1)
  505     {
  506     Open_All_Attr(attr, strip);
  507     OldMathDepth=attr.Math_Depth;
  508     if(attr.Math_Depth>0) attr.Math_Depth=0;//Math might be nested inside \llap
  509     OldSubSup=SubSup;SubSup=0;
  510     fprintf(strip, "\\llap{");
  511     ProcessKey4();
  512     fputc('}',strip);
  513     NewPos = ActualPos = ftell(wpd);
  514     w++;
  515 
  516     attr.Math_Depth=OldMathDepth;
  517     if(OldSubSup)
  518           {
  519           AttrOff(this,5);
  520           AttrOff(this,6);
  521           }
  522     }
  523     else fseek(wpd,ActualPos,SEEK_SET); //Overstrike rejected
  524 
  525 
  526   char_on_line = true;
  527   sprintf(ObjType, "Overstrike %c", by);
  528 }
  529 
  530 
  531 void TconvertedPass1_WP4::InvisibleChars4(DWORD & NewPos, WORD & w)
  532 {
  533 #ifdef DEBUG
  534   fprintf(log,"\n#InvisibleChars4() ");fflush(log);
  535 #endif
  536 signed char OldCharOnLine;
  537 DWORD OldActualPos;
  538 
  539   OldCharOnLine=char_on_line;
  540   AttrOn(attr,Hidden_Text);
  541   recursion++;
  542 
  543   OldActualPos = ActualPos = ftell(wpd);
  544   by=fgetc(wpd);
  545 
  546   while (!feof(wpd))
  547        {
  548        fread(&by, 1, 1, wpd);
  549 
  550        if(by==0xDF) break;
  551 
  552        ProcessKey4();
  553        }
  554 
  555   NewPos = ActualPos = ftell(wpd);
  556   w+= ActualPos -OldActualPos;
  557 
  558   recursion--;
  559   AttrOff(this,Hidden_Text);
  560 
  561   char_on_line = OldCharOnLine;
  562   strcpy(ObjType, "Ptr Cmnd");
  563 }
  564 
  565 
  566 void TconvertedPass1_WP4::TableOfAuthorities4(DWORD & NewPos)
  567 {
  568 #ifdef DEBUG
  569   fprintf(log,"\n#TableOfAuthorities4() ");fflush(log);
  570 #endif
  571 BYTE SectionNumber;
  572 string ShortForm,FullForm;
  573 
  574   SectionNumber = fgetc(wpd);
  575   by=fgetc(wpd);
  576 
  577   NewPos = ActualPos = ftell(wpd);
  578 
  579   if(by!=0xED)
  580     while(!feof(wpd))
  581        {
  582        by=fgetc(wpd);
  583        if(by==0) break;
  584        if(by==0xED) break;
  585        if(by==0xE1)     //Extended char ?
  586         {
  587         fseek(wpd, 2, SEEK_CUR);
  588         continue;
  589         }
  590        else ShortForm+=by;
  591        }
  592   if(by!=0xED)
  593     while(!feof(wpd))
  594        {
  595        by=fgetc(wpd);
  596        if(by==0) break;
  597        if(by==0xED) break;
  598        if(by==0xE1)     //Extended char ?
  599         {
  600         fseek(wpd, 2, SEEK_CUR);
  601         continue;
  602         }
  603        else FullForm+=by;
  604        }
  605   if(by!=0xED) by=fgetc(wpd);
  606 
  607   ActualPos = ftell(wpd);
  608   NewPos = ActualPos;
  609 
  610   if(length(ShortForm)>sizeof(ObjType)-5)
  611     ShortForm=copy(ShortForm,0,sizeof(ObjType)-5);
  612   sprintf(ObjType, "!ToA:%s",ShortForm());  /*not supported yet*/
  613 }
  614 
  615 
  616 void TconvertedPass1_WP4::DefMarkedText4(DWORD & NewPos)
  617 {
  618 #ifdef DEBUG
  619   fprintf(log,"\n#DefMarkedText4() ");fflush(log);
  620 #endif
  621 
  622   TableOfContents(this,4);  /*1 byte contains list type as usual for all WP releases*/
  623   fseek(wpd,5,SEEK_CUR);    /*skip 5 bytes with definition*/
  624 
  625   while(!feof(wpd))
  626        {
  627        fread(&by, 1, 1, wpd);
  628        if(by==0xE9) break;
  629        }
  630   NewPos = ActualPos = ftell(wpd);
  631 }
  632 
  633 
  634 
  635 void TconvertedPass1_WP4::Tabset4(void)
  636 {
  637 #ifdef DEBUG
  638   fprintf(log,"\n#Tabset4() ");fflush(log);
  639 #endif
  640   int tabpos;
  641   char ch;
  642   long pos;
  643 
  644 
  645   pos = ftell(wpd);
  646   fseek(wpd, pos+32l+20l, SEEK_SET);   /* Ga naar TAB-info */
  647 
  648   num_of_tabs = 0;
  649   ch=0;     //????
  650   for(tabpos=0;tabpos<256;tabpos++)
  651     {
  652     ch <<= 1;
  653     if(!(tabpos & 7))
  654         fread(&ch, 1, 1, wpd);
  655 
  656     if(ch & 0x80)
  657         {
  658         this->tabpos[num_of_tabs] = u2w(tabpos);
  659         if(++num_of_tabs > 40) break;
  660         }
  661     }
  662 
  663 
  664   tabpos=num_of_tabs;
  665   while(tabpos < 40)
  666     {
  667     this->tabpos[tabpos++] = 0xFFFF;
  668     }
  669 
  670   Make_tableentry_tabset(this);
  671   sprintf(ObjType, "TabSet");
  672 }
  673 
  674 
  675 void TconvertedPass1_WP4::UnderlineMode4(void)
  676 {
  677 #ifdef DEBUG
  678   fprintf(log,"\n#UnderlineMode4() ");fflush(log);
  679 #endif
  680 
  681  fseek(wpd, 1l, SEEK_CUR);
  682  UnderlineType=fgetc(wpd); /* second byte is a bit field.
  683             *       1 = double-underline (default single),
  684             *       2 = underline spaces (default don't)  */
  685 
  686  strcpy(ObjType, "Und Opt");
  687 }
  688 
  689 
  690 bool TconvertedPass1_WP4::CheckConzistency4(long NewPos)
  691 {
  692 #ifdef DEBUG
  693   fprintf(log,"\n#CheckConzistency() ");fflush(log);
  694 #endif
  695 
  696   bool Result = true;
  697   unsigned char TestedBy;
  698   long Pos;
  699 
  700   Pos = ftell(wpd);
  701 
  702   fseek(wpd, NewPos-1 , 0);
  703   fread(&TestedBy, 1, 1, wpd);
  704   if (TestedBy != by)
  705     {
  706         if (err != NULL)
  707       {
  708       perc.Hide();
  709           fprintf(err,
  710           _("\nError: Object %lX:%X consistency check failed. Trying to ignore."),Pos,(int)by);
  711           }
  712         CorruptedObjects++;
  713         Result = false;
  714     /* asm int 3; end;*/
  715     }
  716 
  717   fseek(wpd, Pos, 0);
  718   return Result;
  719 }
  720 
  721 
  722 /** This is main procedure for processing one key. It is recursivelly called. */
  723 void TconvertedPass1_WP4::ProcessKey4(void)
  724 {
  725 #ifdef DEBUG
  726   fprintf(log,"\n#ProcessKey4() ");fflush(log);
  727 #endif
  728   WORD w;
  729   DWORD NewPos = 0;
  730   unsigned char by, subby;
  731 
  732   if(this->by == 0)
  733     fread(&this->by, 1, 1, wpd);
  734 
  735   *ObjType = '\0';
  736   w = 1;
  737   this->subby = 0;
  738 
  739 
  740   /*Guessing end position of the object*/
  741 
  742   if(this->by >= 0xC0)
  743       {
  744       w=ObjWP4SizesC0[this->by-0xC0];
  745       if(w>0) NewPos = ActualPos + w;
  746 
  747       switch(this->by)
  748     {
  749     case 0xC4:fread(&this->subby, 1, 1, wpd);  break;
  750 //  case 0xD1:  //header & footer must be analyzed specially
  751 //              verify(0xFF); verify(0xFF);/* separator */ gobble(2);                       /* left and right margin */
  752 //  case 0xDF: gobble_until(0xDF);              /* invisible characters */
  753 //  case 0xE2:  handle note
  754     }
  755       }
  756       
  757     // Create backup of command and subcommand for the case of recursion.
  758   by = this->by;
  759   subby = this->subby;
  760 
  761   if(ExtendedCheck && NewPos != 0)
  762     if(!CheckConzistency4(NewPos))
  763       {
  764       NewPos = 0;
  765       strcpy(ObjType, "Corrupted!!");
  766       goto _LObjectError;
  767       }
  768 
  769   if(filter[flag][by])
  770      {
  771      switch(by)
  772     {
  773     case 0x02:PageNumber(this); break;          /* Page number */
  774 
  775     case 0x09:strcpy(ObjType, "!Tab");
  776           putc(' ', strip);   break;    /*tabulator (ignored)*/
  777     case 0x0a:HardReturn(this);break;           // Hard return
  778     case 0x0b:Terminate_Line(this,'p');strcpy(ObjType, "SRt SoftPg");break;/* Soft page break after a SRt */
  779     case 0x0c:strcpy(ObjType, "HPg");Terminate_Line(this,'P');break;    // Hard page
  780     case 0x0d:SoftReturn(this);break;           /* Soft return */
  781 
  782     case 0x20:putc(' ', strip);   break;    /* Soft space ' '*/
  783 
  784 
  785     case 0x80:strcpy(ObjType, "NOP");       break;  /* NOP */
  786     case 0x81:Justification(this, 1 | 0x80);    break;  /* Full justification */
  787     case 0x82:Justification(this, 0 | 0x80);    break;  /* Left justification - Ragged right */
  788     case 0x83:if(envir=='c')                /* End centering */
  789              Justification(this, 1 + 0x80);
  790           strcpy(ObjType, "Center End");    break;
  791 //  case 0x84: leave_environment(0); break;             /* End aligned text */
  792 //  case 0x85: process0(MathCalc); break;               /* Begin math calc */
  793     case 0x86:CenterPage(this);         break;  /* Center page vertically */
  794     case 0x87:Column(this,DefColumns);          break;  /* Begin column mode */
  795     case 0x88:Column(this,1);           break;  /* End column mode */
  796 //  case 0x89: process0(Tab);    break;         /* Tab after right margin */
  797     case 0x8A:WidowOrphan(this,3);          break;  /* Widow/orphan protection */
  798     case 0x8B:WidowOrphan(this,0);          break;  /* Allow widows/orphans */
  799     case 0x8C:if(char_on_line>=0) Terminate_Line(this,'h'); /* Soft page break after a HRt */
  800                      else Terminate_Line(this,'s');     // hard return mustn't occur here, fix it
  801           strcpy(ObjType, "HRt-SPg");   break;
  802 //      case 0x8D:process0(note_status == eFn ? FNoteNum : ENoteNum);/* Footnote/Endnote number */
  803     case 0x90:Attr_ON(this,10);         break;  /* Begin redline */
  804     case 0x91:Attr_OFF(this,10);            break;  /* End redline */
  805     case 0x92:Attr_ON(this,13);         break;  /* Begin strikeout */
  806     case 0x93:Attr_OFF(this,13);            break;  /* End strikeout */
  807     case 0x94:if(UnderlineType & 1) Attr_ON(this,11);   /* Dbl Begin underlining */
  808                        else Attr_ON(this,14); /* Normal */
  809           strcpy(ObjType, "Underline"); break;
  810     case 0x95:AttrOff(this,14);             /* End underlining */
  811           AttrOff(this,11);
  812           strcpy(ObjType, "underline"); break;
  813     case 0x96:Attr_ON(this,17);         break;  /* Begin reverse video */
  814     case 0x97:Attr_OFF(this,17);            break;  /* End reverse video */
  815 //  case 0x98:   break;                 /* Table of contents placeholder */
  816     case 0x99:Overstrike4(NewPos,w);        break;  /* Overstrike */
  817     case 0x9A:CancelHyph(this);         break;
  818     case 0x9B:strcpy(ObjType,"!End Gener Text");break;  /* End of generated text */
  819     case 0x9C:Attr_OFF(this,12);            break;  /* End boldface */
  820     case 0x9D:Attr_ON(this,12);         break;  /* Begin boldface */
  821     case 0x9E:Hyphenation(this, false);     break;  /* Forbid hyphenation */
  822     case 0x9F:Hyphenation(this, true);      break;  /* Allow hyphenation */
  823     case 0xA0:fputc('~', strip);strcpy(ObjType, " ");
  824           break;                        /* Hard space */
  825 //  case 0xA1: process0(SubTtl); break;                   /* Do subtotal */
  826 //  case 0xA2: process0(IsSubTtl); break;              /* Subtotal entry */
  827 //  case 0xA3: process0(Ttl); break;                         /* Do total */
  828 //  case 0xA4: process0(IsTtl); break;                    /* Total entry */
  829 //  case 0xA5: process0(GrandTtl); break;              /* Do grand total */
  830 //  case 0xA6: process0(MathCalcColumn); break;      /* Math calc column */
  831 //  case 0xA7: process0(Math); break;                 /* Begin math mode */
  832 //  case 0xA8: process0(eMath); break;                  /* End math mode */
  833     case 0xA9:                                  /* Normal breakable hyphen */
  834     case 0xAA:                                      /* Hyphen at end of line */
  835     case 0xAB:HardHyphen(this);break;               /* Hyphen at end of page */
  836     case 0xAC:SoftHyphen(this);         break;  /* Discretionary hyphen */
  837     case 0xAD:SoftHyphen(this);         break;  /* Discretionary hyphen at EOLn */
  838     case 0xAE:SoftHyphen(this);         break;  /* Discretionary hyphen at EOPg */
  839     case 0xAF:Column(this,false);           break;  /* EOT columns and EOLn */
  840     case 0xB0:Column(this,false);           break;  /* EOT columns and EOPg */
  841 //  case 0xB1: process0(NegateTotal); break;     /* Negate current total */
  842     case 0xB2:Attr_ON(this,8);          break;  /* Italic On */
  843     case 0xB3:Attr_OFF(this,8);         break;  /* Italic Off */
  844     case 0xB4:Attr_ON(this,9);          break;  /* Shadow On */
  845     case 0xB5:Attr_OFF(this,9);         break;  /* Shadow Off */
  846     case 0xB6:Attr_ON(this,7);          break;  /* Outline On */
  847     case 0xB7:Attr_OFF(this,7);         break;  /* Outline Off */
  848 
  849     case 0xBC:AttrOn(attr,5);SubSup|=0x82;      /* Superscript */
  850           strcpy(ObjType, "SupScript");
  851           break;
  852     case 0xBD:AttrOn(attr,6);SubSup|=0x81;      /* Subscript */
  853           strcpy(ObjType, "SubScript");
  854           break;
  855     case 0xBE:LineUpDown(this, 0.5);            break;  /* Advance 1/2 line up */
  856     case 0xBF:LineUpDown(this, -0.5);           break;  /* Advance 1/2 line down */
  857     case 0xC0:strcpy(ObjType, "!Margin Reset"); break;  /* Margin change */
  858     case 0xC1:LineSpacing4(this);           break;  /* Line spacing */
  859     case 0xC2:strcpy(ObjType, "!Left Mar Relese");break;/* Margin release */
  860     case 0xC3:Center(this);             break;  /* Center text */
  861     case 0xC4:if((subby & 0x7F)==0xA || (subby & 0x7F)==0xC)/* Align or Flush Right */
  862              {
  863              Flush_right(this, (subby & 0x80)?1:0);
  864              }
  865           else
  866             sprintf(ObjType, "!Align(%d)", (int)subby);
  867           break;
  868 //  case 0xC5: gobble(2); c = igetc();               /* Hyphenation zone */
  869 //              process2(HZone, c, igetc()); verify(0xC5); break;
  870     case 0xC6:Page_number_position(this,4);     break;  /* Page number position */
  871     case 0xC7:SetPgNum(this,4);         break;  /* New page number */
  872 //  case 0xC8: gobble(3);                      /* Set Page number column */
  873 //  case 0xC9: gobble(20);                                  /* Set tabs */
  874     case 0xCA:strcpy(ObjType, "!Cond EOP");     break;  /* Conditional end of page */
  875     case 0xCB:SetFontSize(this,4);          break;  /* Set pitch or font */
  876     case 0xCC:Indent(this,4);           break;  /* Indented paragraph */
  877     case 0xCD:Indent(this,0x14);            break;  /* Indented paragraph (obsolete) */
  878     case 0xCE:strcpy(ObjType, "!Top Margin");   break;  /* Set top margin */
  879     case 0xCF:Suppress(this,4);         break;  /* Suppress headers/footers for this page */
  880     case 0xD0:strcpy(ObjType, "!Form Len");     break;  /* old form length */       /* Set page length */
  881     case 0xD1:Header_Footer4(NewPos,w);     break;  /* header/footer */
  882     case 0xD2:FootNoteObsolette(NewPos,w);      break;  /* obsolete footnote */
  883     case 0xD3:SetFootnoteNum(this, -4);     break;  /* obsolete `set footnote number' */
  884 //  case 0xD4:                            /* Advance to half line number */
  885 //  case 0xD5: gobble(1); process1(LPI, igetc());    /* Set LPI (6 or 8) */
  886 //  case 0xD6:                                      /* set extended tabs */
  887           /* next 4 bytes are <old start><old increment>
  888                   <new start><new increment> */
  889     case 0xD7:strcpy(ObjType, "!Math Cols");   break;  /* Define math columns */
  890 //  case 0xD8: gobble(1); process1(AlignChar, igetc());        verify(0xD8); break;           /* Set alignment character */
  891 //  case 0xD9: gobble(2);                     /* obsolete margin release */
  892     case 0xDA:UnderlineMode4();         break;  /* Set underline mode */
  893 //  case 0xDB:                                   /* Set sheet feeder bin */
  894 //  case 0xDC: gobble(7); verify(0xDC); break;      /* End-of-page codes */
  895 //  case 0xDD: gobble(22);                             /* define columns */
  896     case 0xDE:End_of_indent(this);          break;  /* End indented paragraph */
  897     case 0xDF:InvisibleChars4(NewPos,w);        break;  /* invisible characters - commands for printer */
  898 //  case 0xE0:                              /* Doubly-indented paragraph */
  899     case 0xE1:Character4();         break;  /* IBM character */
  900     case 0xE2:FootEndNote(NewPos, w);       break;  /* footnote or endnote */
  901 //  case 0xE3: gobble(74+74);                     /* footnote attributes */
  902     case 0xE4:SetFootnoteNum(this,4);           break;  /* set footnote number */
  903 //  case 0xE5:                              /* paragraph numbering style */
  904 //  case 0xE6:                                       /* paragraph number */
  905     case 0xE7:StartSection(this,4);         break;
  906     case 0xE8:EndSection(this,4);           break;
  907     case 0xE9:DefMarkedText4(NewPos);       break;  /* begin marked text */
  908     case 0xEA:MakeIndex4(NewPos);           break;  /* end marked text */
  909     case 0xEB:DateCode(this);               break;  /* define marked text */
  910 //  case 0xEC:          break;  /* define index mark */
  911     case 0xED:TableOfAuthorities4(NewPos);      break;  /* Table of authorities */
  912     case 0xEE:strcpy(ObjType, "!ParNumDef");    break;  /* paragraph number def */
  913     case 0xEF:ParagraphNumber(this);            break;  /* paragraph number */
  914 //  case 0xF0:                  /*  Line Numbering */
  915     case 0xF1:Tabset4();                break;  /* Tab settings */
  916         case 0xF2:Comment4(NewPos, w);          break;
  917     case 0xF3:ColDef4();                break;
  918 //  case 0xF4:                  /*Point size*/
  919 
  920 
  921     default:if(by>=0x01 && by<=0x7f)
  922              {
  923              RequiredFont = FONT_NORMAL;
  924              CharacterStr(this, Ext_chr_str(by,this,NULL));
  925                      if(attr.Closed_Depth>0)
  926             {
  927             if(SubSup)
  928               {
  929               AttrOff(this,5);
  930               AttrOff(this,6);
  931               }
  932             SubSup=0;
  933             }
  934                      }
  935                 break;
  936         }
  937   }
  938 
  939 _LObjectError:
  940   if (log != NULL && LogLevel>=1)
  941     {   /**/
  942     if ((by >= 0x80)||(*ObjType != '\0'))
  943         {
  944     fprintf(log, _("\n%*sObject type:%3Xh subtype:%3d length:%4u"),
  945                         recursion * 2, "", by, subby, w);
  946     if (*ObjType != '\0')
  947               fprintf(log, " [%s] ", ObjType);
  948              else fprintf(log, "    ");
  949         if(*ObjType==0) UnknownObjects++;
  950 
  951         fflush(log);
  952         }
  953     else if (by >= ' ' && by <= 'z')
  954              putc(by, log);
  955     }
  956 
  957 
  958   if (NewPos == 0)
  959     {
  960     if(by<0xC0) ActualPos++;    //Only one byte read - simple guess of new position
  961            else ActualPos = ftell(wpd);
  962     return;
  963     }
  964   ActualPos = ftell(wpd);
  965   if (NewPos == ActualPos) return;
  966   fseek(wpd, NewPos, SEEK_SET);
  967   ActualPos = NewPos;
  968   NewPos = 0;
  969 
  970   /*these functions has fixed size - see table SizesC0*/
  971 }
  972 
  973 
  974 void TconvertedPass1_WP4::InitFilter4(void)
  975 {
  976  filter[0]=set(set0_40,sizeof(set0_40)/sizeof(int));
  977  filter[1]=set(set1_40,sizeof(set1_40)/sizeof(int));
  978  filter[2]=set(set2_40,sizeof(set2_40)/sizeof(int));
  979  filter[3]=set();
  980 }
  981 
  982 
  983 /***************************************/
  984 /* This procedure provides all needed processing for the first pass*/
  985 int TconvertedPass1_WP4::Convert_first_pass(void)
  986 {
  987 #ifdef DEBUG
  988   fprintf(log,"\n#TconvertedPass1_WP4::Convert_first_pass() ");fflush(log);
  989 #endif
  990 DWORD fsize;
  991 
  992   LogLevel=1;
  993   InitFilter4();
  994 
  995   ConvertCpg = GetTranslator("wp4aTOinternal");
  996   DefColumns=2;
  997 
  998   UnderlineType = 0;
  999   SubSup = 0;
 1000 
 1001   DocumentStart=ftell(wpd);
 1002 
 1003   fsize=filesize(wpd);
 1004   perc.Init(ftell(wpd), fsize,_("First pass WP 4.x:"));
 1005 
 1006   ActualPos = ftell(wpd);
 1007   while (ActualPos < fsize)
 1008       {
 1009       if(Verbosing >= 1)        //actualise a procentage counter
 1010           perc.Actualise(ActualPos);
 1011 
 1012       by = 0;
 1013       ProcessKey4();
 1014       }
 1015 
 1016   Finalise_Conversion(this);
 1017   return(1);
 1018 }
 1019 
 1020 /*--------------------End of PASS1_4------------------*/
 1021