• Page principale
  • Pages associées
  • Modules
  • Classes
  • Fichiers

/tmp/galet/src/galet.cpp

Aller à la documentation de ce fichier.
00001 // vim:syntax=cpp.doxygen tw=3 sw=3
00002 /***************************************************************************
00003  *   Copyright (C) 2008 by Brice Boyer                                     *
00004  *   brice.boyer@ens-lyon.org                                              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU General Public License as published by  *
00008  *   the Free Software Foundation; either version 2 of the License, or     *
00009  *   (at your option) any later version.                                   *
00010  *                                                                         *
00011  *   This program is distributed in the hope that it will be useful,       *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU General Public License for more details.                          *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU General Public License     *
00017  *   along with this program; if not, write to the                         *
00018  *   Free Software Foundation, Inc.,                                       *
00019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00020  ***************************************************************************/
00021 
00029 #ifdef HAVE_CONFIG_H
00030 #include <config.h>
00031 #endif
00032 
00033 #include <iostream>
00034 #include <cstdlib>
00035 
00036 #include "type_base.h"
00037 #include "explore.h"
00038 #include "graphe.h"
00039 #include "parseur.h"
00040 
00055 using namespace std;
00056 
00064 //int GN_ = 0 ;
00065 
00066 /* init static */
00067 
00068 entier_type       GRAPHE::_NombreImpr = 0  ;
00069 entier_type       GRAPHE::_NombreCree  = 0  ;
00070 entier_type       GRAPHE::_MaTaille = 0  ;
00071 noms_type         GRAPHE::_NomsNoeuds ;
00072 bool              GRAPHE::_AReussi = false;
00073 bool              GRAPHE::_CopieOk = false;                    // par défaut, on n'a pas droit à la copie.
00074 noms_type         GRAPHE::_NomsOpers  ;
00075 //relatif_matrix  GRAPHE::opers_incid ;
00076 relatif_vect      GRAPHE::_OpersProp  ;
00077 relatif_matrix    GRAPHE::_OpersOrdre ;
00078 oper_vect         GRAPHE::_Operations  ;
00079 entier_type       GRAPHE::_GaletMax   ;
00080 
00081 /* MAIN */
00082 
00083 void aide (const etiquette & nomprog) {
00084    cout << _ok << "Usage :\n";
00085    cout << '\t' << nomprog << "-opt1 toto [-opt_opt2 titi] --choix1 --choix2 ... fichier\n";
00086    cout << _ok << "Options :\n";
00087    cout << "-g x \t: on peut utiliser x galets. Par défaut le nombre d'initiaux.\n";
00088    cout << _ok << "Options optionnelles :\n";
00089    cout << "-o y \t: la sortie est y; (NE PAS JOUER AVEC ÇA)\n";
00090    cout << "-h\t : cette aide !\n";
00091    cout << _ok << "Choix :\n";
00092    cout << "--toutes-sols \t: on veut toutes les solutions (PAS TOUT À FAIT IMPLÉMENTÉ) ;\n";
00093    cout << "--avec-copie  \t: on autorise le copiage.\n";
00094    cout << "--cherche-sol \t : on cherche le nombre minimum de galets (PAS TESTÉ, NE PAS UTILISER).\n";
00095    cout << _ok << "Par défaut:\n";
00096    cout << "On n'utilise pas le copiage et on veut savoir s'il y a une solution pour le nombre mini de galet possible.\n";
00097    cout << "Le nom de fichier est par défaut ./arbre/arbre.dat\n\n";
00098    cout << _ok << "Pour modifier le niveau de débogage, aller regarder dans src/type_base.h la macro NIVEAU_DEBUG.\n\n";
00099    cout << _ok << "exemple d'utilisation : ./galet -g 14 --avec-copie ./arbre/Wino.dat \n";
00100    cout << "La syntaxe des arbres est documentée quelque part\n\n";
00101    return;
00102 }
00103 
00104 int main ( int argc, char *argv[] ) {
00105 
00106    string entree_default = "./arbre/arbre.dat"; // fichier d'entrée par défaut.
00107    /*** on parse ***/
00108 
00109    string nomprog    = argv[0];
00110    bool on_copie     = false;                                           // par défaut, on ne copie pas
00111    bool toutes_sols  = false;                                           // on cherche si galéisable
00112    bool cherche_min  = false;                                           // et on ne cherche pas la meilleur sol.
00113    unsigned nb_galets = 0;                                              // par défaut on ne sais pas combien de galet on cherche.
00114    ostringstream sortie ;                                               // inutile.
00115    ostringstream entree ;
00116    if ( argc == 1 ) {
00117       cout << "on utilise les options par défaut.\n";
00118    }
00119    else {
00120       unsigned i = 1 ;
00121       while ( i < (unsigned) argc  ) {                                  /*{{{*/
00122          if ( argv[i][0] == '-' ) {                                     /*{{{*/
00123             switch (argv[i][1]) {
00124                case 'g' : {                                             // galets
00125                   nb_galets = atoi(argv[i+1]);
00126                   if ( nb_galets < 1 || nb_galets > 90 ) {
00127                      cout << _erreur << "Dans la fonction " << nomprog << ", l'argument " << argv[i][2] << " de " << argv[i] << " est incorrect.\n";
00128                      aide ( nomprog );
00129                      return ( EXIT_FAILURE );
00130                   }
00131                   i += 2;
00132                }
00133                break;
00134                case 'o' : {
00135                   sortie << argv[i+1] ;                                 // faut être tordu pour dire -o toto -o titi non ?
00136                   i += 2;
00137                }
00138                case '?' :
00139                case 'h' : {
00140                   aide( nomprog );
00141                   return (EXIT_SUCCESS);
00142                }
00143                break;
00144                case '-' : {
00145                   switch (argv[i][2]) {
00146                      case 't' : {
00147                         toutes_sols = true;
00148                      }
00149                      break;
00150                      case 'a' : {
00151                         on_copie = true;
00152                      }
00153                      break;
00154                      default : {
00155                         cout << _erreur << "fonction " << nomprog << " : argument de " << argv[i] << " incorrect.\n";
00156                         aide ( nomprog ) ;
00157                         return ( EXIT_FAILURE ) ;
00158                      }
00159                      case 'h' : {
00160                         aide(nomprog);
00161                         return (EXIT_SUCCESS);
00162                      }
00163                   }
00164                   ++i;
00165                }
00166                break;
00167                default :  {
00168                   cout << _erreur << "fonction " << nomprog << " : argument de " << argv[i] << " incorrect.\n";
00169                   aide ( nomprog );
00170                   return ( EXIT_FAILURE );
00171                }
00172             }
00173          }                                                              // fin '-'/*}}}*/
00174          else {/*{{{*/
00175             entree << argv[i];                                          // c'est qui qui lancerait prog -a x toto -b y toto -a t toto ???
00176             entree_default = entree.str();
00177             ++i;
00178          }                                                              // fin dernier/*}}}*/
00179       }                                                                 // fin/*}}}*/
00180    }                                                                    // argc != 1
00181 
00182    /*** on a fini de parser !! ***/
00183    cout << "On a lu :\n";
00184    cout << "-g \t"            << nb_galets     << endl ;
00185    cout << "-o \t"            << sortie.str()  << endl ;
00186    cout << "--toutes-sols\t"  << LaReponse(toutes_sols)   << endl ;
00187    cout << "--avec-copie\t"   << LaReponse(on_copie)      << endl ;
00188    cout << "entrée : \t"      << entree.str()  << endl ;
00189 
00190