1: 
   2: /* webCpp 0.6
   3:  * Copyright (C) 2001, 2002 Jeffrey Bakker
   4:  *
   5:  * This program is free software; you can redistribute it and/or modify
   6:  * it under the terms of the GNU General Public License as published by
   7:  * the Free Software Foundation; either version 2 of the License, or
   8:  * (at your option) any later version.
   9:  *
  10:  * This program is distributed in the hope that it will be useful,
  11:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13:  * GNU General Public License for more details.
  14:  *
  15:  * You should have received a copy of the GNU General Public License
  16:  * along with this program; if not, write to the Free Software
  17:  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18:  */
  19: 
  20: 
  21: #ifdef HAVE_CONFIG_H 
  22: #include <config.h> 
  23: #endif 
  24: 
  25: #include <iostream> 
  26: #include <fstream> 
  27: #include <string> 
  28: #include <cctype> 
  29: #include "dupe.h" 
  30: #include "help.h" 
  31: #include "bangbanger.h" 
  32: #include "gangbanger.h" 
  33: #include "hashbanger.h" 
  34: #include "headbanger.h" 
  35: using namespace std;
  36: 
  37: /******************************** MAIN FUNCTION ******************************/
  38: int main(int argc, char **argv)
  39: {
  40:  Help help;
  41:  if (argc < 3) {help.helpme();}
  42: 
  43:  string type;
  44:  type = argv[1];
  45:  // default filetype is the extension of the input file
  46:  // needs to check if the filetype will be forced by the user
  47:  if(argc > 3) {
  48:   string ar;
  49:   for(int a=3; a < argc; a++) {
  50:    ar = argv[a];
  51:    if (ar.substr(0,3) == "-t=") {type = "." + ar.substr(3);}
  52:    if (ar == "--backup" || ar == "-b") {
  53:     string backup = argv[2];
  54:     backup += ".old";
  55:     Dupe::duplicate(argv[2], backup);
  56:    }
  57:   }
  58:  }
  59: 
  60:  Style* Source;  // make a Style Pointer
  61:                 // and determine the language style
  62:  switch(Style::getExtension(type)) {
  63:   case (0):
  64:   case (1):
  65:   case (2):
  66:   case (3): Source = new HeadBanger; break;
  67:   case (4):
  68:   case (5):
  69:   case (6): Source = new HashBanger; break;
  70:   case (7): Source = new GangBanger; break;
  71:   case (8): Source = new BangBanger; break;
  72:   default : Source = new HeadBanger; break;
  73:  }
  74: 
  75:  int percent;
  76:  string imode, omode;
  77:  // checking whether the input or ouput mode sould be redirected --------------
  78:  imode = argv[1];
  79:  omode = argv[2];
  80:  percent = 0;
  81: 
  82:  if (imode == "--pipe" || imode == "-") {
  83:   Source->toggleIswitch();
  84:  } else { 
  85:   ifstream Count;
  86:   string tmp;
  87: 
  88:   Count.open(imode.data());
  89:   if(!Count) {
  90:    cerr << imode << " cannot be found.\n";
  91:    exit(0);
  92:   }
  93: 
  94:   while (Count) {
  95:    getline(Count,tmp);
  96:    percent++;
  97:   }
  98:   percent--;
  99:   Count.close();
 100: //  Count.seekg(ios::beg);
 101:   if(!Source->fIO.openR(imode)) {exit(0);}
 102:  }
 103: 
 104:  if (omode == "--pipe" || omode == "-") {
 105:   Source->toggleOswitch();
 106:  } else {
 107:   if(Source->isIstd()) {Source->fIO.ofile.open(omode.data());}
 108:   else if(!Source->fIO.openW(omode)) {exit(0);}
 109:  }
 110: 
 111:  //----------------------------------------------------------------------------
 112:  // optional arguments --------------------------------------------------------
 113:  if (argv[3] != NULL) {
 114:   string arg;
 115:   for(int i=3; i < argc; i++) {
 116: 
 117:    arg = argv[i];
 118:    if (arg == "--dupe" || arg == "-d") {
 119:     if(Dupe::duplicate(argv[1], argv[2])) return 0;
 120:     else exit(1);
 121:    } else if (arg.substr(0,3) == "-t=") {
 122:       cerr << Source->checkExtension("." + arg.substr(3)) << " detected.\n";
 123:    } else if (arg.substr(0,3) == "-c=") {
 124:       Source->ColourOf.schemeIt(arg.substr(3));
 125:    } else if (arg.substr(0,3) == "-C=") {
 126:       Source->toggleCSSSwitch();
 127:       Source->setCSSfile(arg.substr(3));
 128:    } else if (arg.substr(0,3) == "-p=") {
 129:       Source->setBGPicture(arg.substr(3));
 130:    } else if (arg.substr(0,3) == "-w=") {
 131:       Source->ColourOf.schemeIt(arg.substr(3));
 132:       Source->toggleMargin();
 133:       Source->toggleHyperSwitch();
 134:       Source->toggleMadewithSwitch();
 135:    } else if (arg == "--backup"       || arg == "-b") {
 136:    } else if (arg == "--made-with"    || arg == "-m") {
 137:       Source->toggleMadewithSwitch();
 138:    } else if (arg == "--hyperlink"    || arg == "-h") {
 139:       Source->toggleHyperSwitch();
 140:    } else if (arg == "--set-colours"  || arg == "-s") {
 141:       Source->ColourOf.setAllColours();
 142:    } else if (arg == "--line-numbers" || arg == "-l") {
 143:       Source->toggleMargin();
 144:    } else help.helpme();
 145:   }
 146:  }
 147:  //----------------------------------------------------------------------------
 148:  if(!Source->isIstd()) {
 149:   cerr << Source->checkExtension(argv[1]) << " detected.\n";
 150:  }
 151:  //----------------------------------------------------------------------------
 152:  Source->openhtml(argv[1]);
 153:  Source->Colourizer();
 154: 
 155:  // process each line and display the progress
 156:  while(Source->fIO.ifile && cin) {
 157:   Source->Colourizer();
 158:   if(!Source->isIstd() && ((Source->getLineCount() * 100) / percent) < 101) {
 159:    cerr << "\r"
 160:         << ((Source->getLineCount() * 100) / percent)
 161:         << "% Complete ";
 162:   }
 163:  }
 164: 
 165:  Source->closehtml();
 166:  Source->fIO.close();
 167:  cerr << endl;
 168:  return 0;
 169: } // END MAIN -----------------------------------------------------------------
 170: 
 171: 

w e b c p p
web c plus plus