Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

monwwrd.cpp

Go to the documentation of this file.
00001 //**********************************************************************
00002 //                                                                     *
00003 //    Filename:      monwwrd.cpp                                       *
00004 //    Date:          16 Feb 2002                                       *
00005 //    File Version:  1                                                 *
00006 //                                                                     *
00007 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00008 //    Company:       Monitor Computing Services Ltd.                   *
00009 //                                                                     *
00010 //**********************************************************************
00011 //                                                                     *
00012 //    Copyright (C) 2002  Monitor Computing Services Ltd.              *
00013 //                                                                     *
00014 //    This program is free software; you can redistribute it and/or    *
00015 //    modify it under the terms of the GNU General Public License      *
00016 //    as published by the Free Software Foundation; either version 2   *
00017 //    of the License, or any later version.                            *
00018 //                                                                     *
00019 //    This program is distributed in the hope that it will be useful,  *
00020 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00021 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00022 //    GNU General Public License for more details.                     *
00023 //                                                                     *
00024 //    You should have received a copy of the GNU General Public        *
00025 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00026 //    program; if not, write to:                                       *
00027 //       The Free Software Foundation Inc.,                            *
00028 //       59 Temple Place - Suite 330,                                  *
00029 //       Boston, MA  02111-1307,                                       *
00030 //       USA.                                                          *
00031 //                                                                     *
00032 //**********************************************************************
00033 //                                                                     *
00034 //    Notes:                                                           *
00035 //                                                                     *
00036 //**********************************************************************
00037 
00038 #include  <ctype.h>
00039 #include  <fstream.h>
00040 #include  <stdio.h>
00041 
00042 #include "monwwrd.h"
00043 #include "mondocwr.h"
00044 
00045 
00046 MonWordWiseReader::MonWordWiseReader(
00047                                      ifstream      *source,
00048                                      MonDocWriter  *writer,
00049                                      void          *traceObj,
00050                                      void          (*traceFunc)(void*, const char*))  :
00051     MonDocReader(source, writer, traceObj, traceFunc),
00052     poundSign(''), hashChar('#'), printerTab(0xDD), padChar('|'),
00053     linesPerInch(6.0), charactersPerInch(10.0),
00054     pageWidth(8.19), pageLength(11.583), leftMargin(0.0)
00055 {
00056 }
00057 
00058 
00059 void
00060 MonWordWiseReader::convert()
00061 {
00062     writer->Begin();
00063 
00064 
00065     int    inputInt = EOF;
00066 
00067 
00068     while (EOF != (inputInt = source->get()))
00069     {
00070         char    inputChar = (inputInt & 0xFF);
00071 
00072         if (!iscntrl(inputChar))
00073         {
00074             if (padChar == inputChar)
00075             {
00076                 writer->writeHardSpace();
00077                 traceAdd(' ');
00078             }
00079             else if (hashChar == inputChar)
00080             {
00081                 writer->write(poundSign);
00082                 traceAdd(poundSign);
00083             }
00084             else if (printerTab == inputChar)
00085             {
00086                 writer->write('\t');
00087                 traceAdd('\t');
00088             }
00089             else
00090             {
00091                 writer->write(inputChar);
00092                 traceAdd(inputChar);
00093             }
00094         }
00095         else
00096         {
00097             switch (inputChar)
00098             {
00099             case 0x0D:
00100                 writer->endParagraph();
00101                 traceWrite();
00102                 break;
00103             case 0x02:
00104                 convertCommand();
00105                 break;
00106             default:
00107                 traceAdd(inputChar);
00108                 break;
00109             }
00110         }
00111     }
00112     traceWrite();
00113 
00114     writer->End();
00115 }
00116 
00117 
00118 void
00119 MonWordWiseReader::convertCommand()
00120 {
00121     int   inputInt = EOF;
00122 
00123     while ((EOF != (inputInt = source->get())) &&
00124            (0x0D != inputInt) && (0x07 != inputInt))
00125     {
00126         switch ((char)inputInt)
00127         {
00128         case 'B':
00129             switch((char)source->get())
00130             {
00131             case 'P':
00132                 traceWrite("BP == Begin new Page");
00133                 writer->endPage();
00134                 break;
00135             case 'S':
00136                 {
00137                     traceWrite("BS == Bottom Space");
00138                     float  marginLines = (float)convertInteger();
00139                     writer->bottomMargin(marginLines / linesPerInch);
00140                     break;
00141                 }
00142             }
00143             break;
00144         case 'C':
00145             switch((char)source->get())
00146             {
00147             case 'I':
00148                 traceWrite("CI == Cancel all Indents");
00149                 writer->leftIndent(0.0);
00150                 break;
00151             case 'O':
00152                 traceWrite("CO == Continuous Output (no paging), ignored");
00153                 break;
00154             }
00155             break;
00156         case 'D':
00157             switch((char)source->get())
00158             {
00159             case 'F':
00160                 traceWrite("DF == Define footing, ignored");
00161                 break;
00162             case 'H':
00163                 traceWrite("DH == Define heading, ignored");
00164                 break;
00165             case 'M':
00166                 traceWrite("DM == Disable Paper Message, ignored");
00167                 break;
00168             }
00169             break;
00170         case 'E':
00171             switch((char)source->get())
00172             {
00173             case 'M':
00174                 traceWrite("EM == Enable Paper Message, ignored");
00175                 break;
00176             case 'P':
00177                 traceWrite("EP == Enable Paging, ignored");
00178                 break;
00179             }
00180             break;
00181         case 'F':
00182             switch((char)source->get())
00183             {
00184             case 'P':
00185                 traceWrite("FP == Footing position, ignored");
00186                 break;
00187             }
00188             break;
00189         case 'G':
00190             switch((char)source->get())
00191             {
00192             case 'F':
00193                 traceWrite("GF == Get file, ignored");
00194                 break;
00195             }
00196             break;
00197         case 'H':
00198             switch((char)source->get())
00199             {
00200             case 'P':
00201                 traceWrite("HP == Heading position, ignored");
00202                 break;
00203             }
00204             break;
00205         case 'I':
00206             switch((char)source->get())
00207             {
00208             case 'N':
00209                 {
00210                     traceWrite("IN == Indent");
00211                     float  indentSpaces = (float)convertInteger();
00212                     writer->leftIndent(indentSpaces / charactersPerInch);
00213                     break;
00214                 }
00215             }
00216             break;
00217         case 'J':
00218             switch((char)source->get())
00219             {
00220             case 'O':
00221                 traceWrite("JO == Justification On");
00222                 writer->justify();
00223                 break;
00224             }
00225             break;
00226         case 'L':
00227             switch((char)source->get())
00228             {
00229             case 'M':
00230                 traceWrite("LM == Left Margin");
00231                 leftMargin = ((float)convertInteger()) / charactersPerInch;
00232                 writer->leftMargin(leftMargin);
00233                 break;
00234             case 'L':
00235                 {
00236                     traceWrite("LL == Line Length");
00237                     float  lineLength = (float)convertInteger();
00238                     writer->rightMargin(pageWidth -
00239                                         (leftMargin + (lineLength / charactersPerInch)));
00240                     break;
00241                 }
00242             case 'LS':
00243                 traceWrite("LS == Line spacing, ignored");
00244                 break;
00245             }
00246             break;
00247         case 'N':
00248             switch((char)source->get())
00249             {
00250             case 'J':
00251                 traceWrite("NJ == No Justification");
00252                 writer->leftJustify();
00253                 break;
00254             }
00255             break;
00256         case 'O':
00257             switch((char)source->get())
00258             {
00259             case 'C':
00260                 traceWrite("OC == Output Control Code(s), ignored");
00261                 break;
00262             }
00263             break;
00264         case 'P':
00265             switch((char)source->get())
00266             {
00267             case 'C':
00268                 traceWrite("PC == Define Pad Character");
00269                 padChar = (char)source->get();
00270                 break;
00271             case 'L':
00272                 traceWrite("PL == Page Length, ignored");
00273                 break;
00274             case 'N':
00275                 traceWrite("PN == Set page number, ignored");
00276                 break;
00277             case 'P':
00278                 traceWrite("PP == Print page number, ignored");
00279                 break;
00280             }
00281             break;
00282         case 'S':
00283             switch((char)source->get())
00284             {
00285             case 'S':
00286                 traceWrite("SS == Single Spacing, ignored");
00287                 break;
00288             case 'P':
00289                 {
00290                     traceWrite("SP == Space with blank lines");
00291                     int  blankLines = convertInteger();
00292                     while (blankLines > 0)
00293                     {
00294                         writer->endParagraph();
00295                         blankLines--;
00296                     }
00297                     break;
00298                 }
00299             }
00300             break;
00301         case 'T':
00302             switch((char)source->get())
00303             {
00304             case 'I':
00305                 {
00306                     traceWrite("TI == Temporary indent");
00307                     float  indentSpaces = (float)convertInteger();
00308                     writer->firstLineIndent(indentSpaces / charactersPerInch);
00309                     break;
00310                 }
00311             case 'S':
00312                 {
00313                     traceWrite("TS == Top Space");
00314                     float  marginLines = (float)convertInteger();
00315                     writer->topMargin(marginLines / linesPerInch);
00316                     break;
00317                 }
00318             }
00319             break;
00320         }  // End of switch ((char)inputInt)
00321     }  // End of while ((EOF != (inputInt = source->get())) &&
00322 }

Generated on Sun Jul 20 02:35:50 2003 for WordWise to RTF, Win32 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002