Página principal | Lista alfabética | Lista de componentes | Lista de archivos | Miembros de las clases | Archivos de los miembros | Páginas relacionadas

mud.cpp

Ir a la documentación de este archivo.
00001 
00006 /*
00007    MUnDoCAAD MUD Engine
00008    Copyright (C) 2002-2005 José Manuel Ferrer Ortiz
00009 
00010    *****************************************************************************
00011    *                                                                           *
00012    *  This program is free software; you can redistribute it and/or modify it  *
00013    *  under the terms of the GNU General Public License version 2, as          *
00014    *  published by the Free Software Foundation.                               *
00015    *                                                                           *
00016    *  This program is distributed in the hope that it will be useful, but      *
00017    *  WITHOUT ANY WARRANTY; without even the implied warranty of               *
00018    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU         *
00019    *  General Public License version 2 for more details.                       *
00020    *                                                                           *
00021    *  You should have received a copy of the GNU General Public License        *
00022    *  version 2 along with this program; if not, write to the Free Software    *
00023    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA  *
00024    *                                                                           *
00025    *****************************************************************************
00026 */
00027 
00028 
00029 #include <cstdlib>  // Para strtoul
00030 #include <cstring>  // Para strcmp
00031 #include <csignal>  // Para signal
00032 
00033 #include <QCoreApplication>
00034 #include <QDir>
00035 
00036 #include "Archivero.hpp"
00037 #include "Ejecutor.hpp"
00038 #include "Guardian.hpp"
00039 #include "Log.hpp"
00040 #include "Mensajero.hpp"
00041 #include "Servidor.hpp"
00042 
00043 
00044 QDir       dir_datos (".");
00045 Archivero *miArchiv;
00046 Ejecutor  *miEjecut;
00047 Guardian  *miGuard;
00048 Mensajero *miMensaj;
00049 Servidor  *miServer;
00050 
00051 
00053 void CompruebaDirDatos ()
00054 {
00055   // Buscamos el fichero "entidad.dtd" sin distinguir mayúsculas de minúsculas
00056   QStringList lista (dir_datos.entryList (QDir::Files | QDir::Readable).filter
00057       ("entidad.dtd", Qt::CaseInsensitive));
00058 
00059   QStringList::iterator iter (lista.begin());
00060 
00061   for ( ; iter != lista.end(); ++iter)
00062     if ((*iter).length() == 11)  // 11 es la longitud de "entidad.dtd"
00063       break;  // Hemos encontrado el fichero
00064 
00065   if (iter == lista.end())  // No encontrado
00066     qFatal ("Directorio de datos \"%s\" incorrecto.",
00067             dir_datos.absolutePath().toLatin1().constData());
00068 }
00069 
00071 void GestionaSenyal (int num)
00072 {
00073   QString numstr;
00074   numstr.setNum (num);
00075 
00076   Log (8, "Señal recibida");
00077   Log (7, " (número de señal: " + numstr + ")");
00078   Log (8, ", cerrando el MUD.\n");
00079 
00080   delete miMensaj;
00081   delete miServer;
00082   delete miEjecut;
00083   delete miArchiv;
00084   delete miGuard;
00085 
00086   exit (0);
00087 }
00088 
00090 void LeeOpciones (const int argc, char **argv)
00091 {
00092   for (unsigned short s = 1; s < argc; s++)
00093   {
00094     if (!strcmp (argv[s], "--help"))
00095     {
00096       Log (10, "MUnDoCAAD MUD Engine\n"
00097            "Copyright (C) 2002-2005 José Manuel Ferrer Ortiz\n\n"
00098            "Este programa es software libre; puedes redistribuirlo y/o "
00099              "modificarlo bajo los\ntérminos de la GNU General Public License "
00100              "versión 2, como ha sido publicada por\nla Free Software "
00101              "Foundation.\n\n"
00102            "Este programa se distribuye con la esperanza de que sea útil, pero "
00103              "SIN NINGUNA\nGARANTÍA. Vea la GNU General Public License versión "
00104              "2 para más detalles.\n\n"
00105            "Modo de empleo:\n" +
00106              QString (argv[0]) + " [-p prolijidad] [-d directorio de datos] "
00107              "[-f fichero de registro] [--help]\n");
00108       exit (0);
00109     }
00110     if (!strcmp (argv[s], "-p"))
00111     {
00112       s++;  // Pasamos al siguiente parámetro
00113       if (s >= argc)  // Si no hay más parámetros
00114         qFatal ("Faltan parámetros.");
00115       prolijidad = (unsigned char) strtoul (argv[s], NULL, 10);
00116     }
00117     else if (!strcmp (argv[s], "-d"))
00118     {
00119       s++;  // Pasamos al siguiente parámetro
00120       if (s >= argc)  // Si no hay más parámetros
00121         qFatal ("Faltan parámetros.");
00122       dir_datos = QDir::cleanPath (argv[s]);
00123     }
00124     else if (!strcmp (argv[s], "-f"))
00125     {
00126       s++;  // Pasamos al siguiente parámetro
00127       if (s >= argc)  // Si no hay más parámetros
00128         qFatal ("Faltan parámetros.");
00129       if ((fichero_log = fopen (argv[s], "a")) == NULL)
00130       {
00131         perror ("fopen()");
00132         exit (-1);
00133       }
00134     }
00135     else  // Parámetro no reconocido
00136       qFatal ("Parámetro en la posición %d (\"%s\") inesperado.", s + 1,
00137               argv[s]);
00138   }
00139 }
00140 
00141 int main (int argc, char **argv)
00142 {
00143   qInstallMsgHandler          (ManejadorMensajes);
00144   QCoreApplication aplicacion (argc, argv);
00145 
00146   LeeOpciones (argc, argv);
00147 
00148   // Información del programa
00149   Log (9, "MUnDoCAAD MUD Engine\n"
00150        "Copyright (C) 2002-2005 José Manuel Ferrer Ortiz\n\n");
00151 
00152   CompruebaDirDatos();
00153   Log (5, "Directorio de datos del MUD: " + dir_datos.absolutePath() + "\n");
00154 
00155   // Procuraremos gestionar las señales
00156   signal (SIGINT,  GestionaSenyal);
00157   signal (SIGTERM, GestionaSenyal);
00158 
00159   miArchiv = new Archivero;
00160   miEjecut = new Ejecutor;
00161   miGuard  = new Guardian;
00162   miMensaj = new Mensajero;
00163   miServer = new Servidor;
00164 
00165   return (aplicacion.exec());
00166 }

Generado el Tue Nov 29 01:04:33 2005 para MUnDoCAAD MUD Engine por  doxygen 1.4.4