/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : nest2.c Component : main Fonctionality : main procedure ******************************************************************/ #include #include #include #include #include #include #include #include #include "graphical.h" #include "algo.h" #include "MainInt.h" #include "TitleInt.h" #include "file.h" #include "nest2.h" /* declaration of global variables */ DIR* homeD; FileDatas* fileDatas; /* file data structure for simulations */ FileDatas* geneticFileDatas; /* file data structure for genetic simulations */ char homeDirectory[256]; char shareDirectory[256]; char rulesPath[256]; char geneticPath[256]; char nest2Server[256]; char nest2ConfigFile[256]; char shareNetconfig[256]; char buf[4096]; int fd, sfd, l; MainInterface *the_main_interface = NULL; void manage_genetic_alarm (int sig) { if (sig == SIGALRM) the_main_interface->manageGeneticAlarm (); } main(int argc, char* argv[]) { TitleInterface* titleInterface; Display* display; int screenNum; int w, h; time_t currentTime; struct passwd *pw_code; currentTime = time (0); srand ((int)currentTime); pw_code = getpwuid ( geteuid () ); strcat (homeDirectory, pw_code->pw_dir); strcat (homeDirectory, "/nest"); strcat (rulesPath, homeDirectory); strcat (rulesPath, "/rules"); strcat (geneticPath, homeDirectory); strcat (geneticPath, "/genetic"); strcat (nest2ConfigFile, homeDirectory); strcat (nest2ConfigFile, "/netconfig"); strcat (shareDirectory, DATAPATH); strcat (shareNetconfig, DATAPATH); strcat (shareNetconfig, "/netconfig"); strcat (nest2Server, BINPATH); strcat (nest2Server, "/nestserver"); printf ("%s\n", VERSION); printf ("3D Wasp nest simulator, Copyright (C) 1997 Sylvain GUERIN\n"); printf ("LIASC, ENST Bretagne & Santa Fe Institute\n"); printf ("%s comes with ABSOLUTELY NO WARRANTY. This is free software,\n", VERSION); printf ("and you are welcome to redistribute it under certain conditions.\n"); printf ("For details, see GNU General Public License (COPYING file).\n"); printf ("Please send bug reports to Sylvain.Guerin@liasc.enst-bretagne.fr\n"); /* is X-server OK ? */ if ( (display = XOpenDisplay (NULL)) == NULL ) { printf ("Unable to connect X Server %s\n", XDisplayName (NULL)); printf ("Exiting %s ... \n", VERSION); exit (-1); } else { /* X-server OK */ screenNum = DefaultScreen (display); w = DisplayWidth (display, screenNum); h = DisplayHeight (display, screenNum); XCloseDisplay (display); } /* on cree le repertoire ~login/nest s'il n'existe pas deja */ if ( (homeD = opendir (homeDirectory)) == NULL ) { printf ("\n It seems this is your first time... Welcome to Nest !\n"); printf (" A nest tree will be created in your home directory.\n\n"); mkdir (homeDirectory, 00755); mkdir (rulesPath, 00755); mkdir (geneticPath, 00755); fd = open (nest2ConfigFile, O_RDWR | O_CREAT); sfd = open (shareNetconfig, O_RDONLY); l = 4096; while (l == 4096) { l = read (sfd, buf, 4096); if (l == -1) break; write (fd, buf, l); } close (sfd); fchmod (fd, 00644); close (fd); } else closedir(homeD); /* avant toutes choses, on se fend d'un titre (un joli) */ titleInterface = new TitleInterface (w, h); titleInterface->manageWindow (); delete titleInterface; /* et c'est parti pour nest2... */ geneticFileDatas = new FileDatas (pw_code->pw_dir, pw_code->pw_name, geneticPath); fileDatas = new FileDatas (pw_code->pw_dir, pw_code->pw_name, rulesPath); the_main_interface = new MainInterface (10, 10); the_main_interface->manageWindow (); delete fileDatas; delete geneticFileDatas; printf ("Exiting %s ... \n", VERSION); }