Advertisement
Guest User

Spellcheck Program w/ Problems

a guest
Apr 19th, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.26 KB | None | 0 0
  1. #include "spellcheck.h"
  2.  
  3. using namespace std;
  4.  
  5. /*
  6.     SPELLCHECK Main Program Code
  7.     Copyright (C) 2013  Ian Duncan
  8.  
  9.     This program is free software: you can redistribute it and/or modify
  10.     it under the terms of the GNU General Public License as published by
  11.     the Free Software Foundation, either version 2 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21. */
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.     string yn;
  26.    
  27.     char *dictionary = "/usr/etc/english.dict"; //Default Dictionary
  28.     spelling s; //Spelling class instance
  29.     bool doAdd = false; //Should we add a word to the dictionary
  30.     bool customDict = false;
  31.    
  32.    
  33.    
  34.    
  35.     //Check if we have the right number of arguments
  36.  
  37.     if(argc < 2)
  38.     {
  39.         do_help_msg(argv[0]);
  40.         exit(1);
  41.     }
  42.  
  43.     //Check for arguments about license and about
  44.     if(string(argv[1]) == "-add")
  45.     {
  46.         doAdd = true;
  47.     }
  48.     if(string(argv[1]) == "-version")
  49.     {
  50.         do_about_msg();
  51.         exit(0);
  52.     }
  53.     if(string(argv[1]) == "-license")
  54.     {
  55.         do_license_msg();
  56.         exit(0);
  57.     }
  58.     if(string(argv[1]) == "-help")
  59.     {
  60.         do_help_msg(argv[0]);
  61.         exit(0);
  62.     }
  63.  
  64.     try
  65.     {
  66.         if(string(argv[2]) == "-dict")
  67.         {
  68.             dictionary = argv[3];
  69.             customDict = true;
  70.         }
  71.  
  72.         if(string(argv[3]) == "-dict")
  73.         {
  74.             dictionary = argv[4];
  75.             customDict = true;
  76.         }
  77.     }
  78.     catch(...)
  79.     {
  80.         dictionary = "/usr/etc/english.dict";
  81.     }
  82.  
  83.    
  84.  
  85.     if(doAdd == true)
  86.     {
  87.         try
  88.         {
  89.            
  90.            
  91.             add_word(dictionary, argv[2]);
  92.  
  93.             if(customDict == true)
  94.             {
  95.                 cout << "Added word \'" << argv[2] << "\' to the dictionary \'" << dictionary << "\'" << endl;
  96.             }
  97.             else
  98.             {
  99.                 cout << "Added word \'" << argv[2] << "\' to the default dictionary (english.dict)" << endl;
  100.             }
  101.         }
  102.         catch(int n)
  103.         {
  104.             if(n == 1)
  105.             {
  106.                 cout << "Specified dictionary doesn't exist!" << endl;
  107.             }
  108.         }
  109.     }
  110.     else
  111.     {
  112.        
  113.        
  114.    
  115.  
  116.     //Now its time to do the spell check
  117.     try
  118.     {
  119.         std::string wordsToCheck(argv[1]);
  120.  
  121.         s = check_spelling_string(dictionary, wordsToCheck, "\n");
  122.  
  123.         if(s.badWords == 0)
  124.         {
  125.             cout << "All words spelled correctly!" << endl;
  126.         }
  127.         else
  128.         {
  129.  
  130.             if(s.badWords == 1)
  131.             {
  132.                 cout << s.badWords << " word was spelled incorrectly." << endl << endl;
  133.             }
  134.             else
  135.             {
  136.                 cout << s.badWords << " words were spelled incorrectly." << endl << endl;
  137.             }
  138.             cout << "The following words were misspelled:" << endl << endl;
  139.             cout << s.badList;
  140.             cout << endl;
  141.             cout << "If you would like to add the words above, use:" << endl << endl;
  142.             cout << argv[0] << " -add [word you'd like to add] (Adds a word to the default dictionary english.dict)" << endl;
  143.             cout << argv[0] << " -add [word you'd like to add] -dict [dictionary file] (Adds a word to the dictionary file specified)" << endl;
  144.             cout << endl;
  145.         }
  146.        
  147.    
  148.     }
  149.     catch(int n)
  150.     {
  151.         if(n == 1)
  152.         {
  153.             cout << "Specified dictionary doesn't exist!" << endl;
  154.         }
  155.     }
  156. }
  157.  
  158.     return 0;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement