tStartup stuff tidied up; some Win32 fixes - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 85f5b158176c66547a12b83d986e8e1a43af6252
 (DIR) parent 17873cad3510a8303b4cba796f0dc070515a0f4f
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Wed, 25 Apr 2001 00:21:30 +0000
       
       Startup stuff tidied up; some Win32 fixes
       
       
       Diffstat:
         M src/curses_client.c                 |       4 ----
         M src/dopeos.c                        |       4 ++--
         M src/dopewars.c                      |      20 +++++++++++++++-----
         M src/dopewars.h                      |       1 +
         M src/gtk_client.c                    |       3 ---
         M src/serverside.c                    |      15 +++++++--------
         M src/serverside.h                    |       2 +-
         M src/winmain.c                       |      15 ++++-----------
       
       8 files changed, 30 insertions(+), 34 deletions(-)
       ---
 (DIR) diff --git a/src/curses_client.c b/src/curses_client.c
       t@@ -1824,8 +1824,6 @@ void CursesLoop() {
           start_curses();
           Width=COLS; Depth=LINES;
        
       -   InitHighScoreFile();
       -
        /* Set up message handlers */
           ClientMessageHandlerPt = HandleClientMessage;
           SocketWriteTestPt = NULL;
       t@@ -1851,8 +1849,6 @@ void CursesLoop() {
           }
           g_free(Name);
           end_curses();
       -
       -   CloseHighScoreFile();
        }
        
        #else
 (DIR) diff --git a/src/dopeos.c b/src/dopeos.c
       t@@ -79,8 +79,8 @@ SCREEN *newterm(void *a,void *b,void *c) {
           Width=80; Depth=25; CurAttr=TextAttr; CurX=0; CurY=0;
           for (i=0;i<10;i++)
              Attr[i]=FOREGROUND_RED|FOREGROUND_BLUE|FOREGROUND_GREEN;
       -   hOut=GetStdHandle(STD_OUTPUT_HANDLE);
       -   hIn=GetStdHandle(STD_INPUT_HANDLE);
       +   hOut=GetConHandle("CONOUT$");
       +   hIn=GetConHandle("CONIN$");
           SetConsoleMode(hIn,0);
        /* SetConsoleScreenBufferSize(hOut,coord);*/
        /* clear_screen();*/
 (DIR) diff --git a/src/dopewars.c b/src/dopewars.c
       t@@ -1664,6 +1664,19 @@ void HandleCmdLine(int argc,char *argv[]) {
           }
        }
        
       +int GeneralStartup(int argc,char *argv[]) {
       +/* Does general startup stuff (config. files, command line, and high */
       +/* score init.) - Returns 0 if OK, -1 if something failed.           */
       +   SetupParameters();
       +   HandleCmdLine(argc,argv);
       +   if (WantVersion || WantHelp) {
       +      HandleHelpTexts();
       +   } else if (!AIPlayer) {
       +      return InitHighScoreFile();
       +   }
       +   return 0;
       +}
       +
        #ifndef CYGWIN
        
        /* Standard program entry - Win32 uses WinMain() instead, in winmain.c */
       t@@ -1673,11 +1686,7 @@ int main(int argc,char *argv[]) {
           bindtextdomain(PACKAGE,LOCALEDIR);
           textdomain(PACKAGE);
        #endif
       -   SetupParameters();
       -   HandleCmdLine(argc,argv);
       -   if (WantVersion || WantHelp) {
       -      HandleHelpTexts();
       -   } else {
       +   if (GeneralStartup(argc,argv)==0 && !WantVersion && !WantHelp) {
              StartNetworking();
              if (Server) {
                 ServerLoop();
       t@@ -1694,6 +1703,7 @@ int main(int argc,char *argv[]) {
              }
              StopNetworking();
           }
       +   CloseHighScoreFile();
           g_free(PidFile);
           return 0;
        }
 (DIR) diff --git a/src/dopewars.h b/src/dopewars.h
       t@@ -396,6 +396,7 @@ void SetPlayerName(Player *Play,char *Name);
        void HandleCmdLine(int argc,char *argv[]);
        void SetupParameters();
        void HandleHelpTexts();
       +int GeneralStartup(int argc,char *argv[]);
        void ReadConfigFile(char *FileName);
        gboolean ParseNextConfig(GScanner *scanner);
        int GetGlobalIndex(gchar *ID1,gchar *ID2);
 (DIR) diff --git a/src/gtk_client.c b/src/gtk_client.c
       t@@ -1618,8 +1618,6 @@ char GtkLoop(int *argc,char **argv[],char ReturnOnFail) {
           GtkAdjustment *adj;
           gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
        
       -   InitHighScoreFile();
       -
        #ifdef CYGWIN
           win32_init(hInstance,hPrevInstance);
        #else
       t@@ -1712,7 +1710,6 @@ char GtkLoop(int *argc,char **argv[],char ReturnOnFail) {
        
           gtk_main();
        
       -   CloseHighScoreFile();
           return TRUE;
        }
        
 (DIR) diff --git a/src/serverside.c b/src/serverside.c
       t@@ -739,8 +739,6 @@ void ServerLoop() {
           GString *LineBuf;
           gboolean EndOfLine;
        
       -   InitHighScoreFile();
       -
           StartServer();
        
           LineBuf=g_string_new("");
       t@@ -826,8 +824,6 @@ void ServerLoop() {
           }
           StopServer();
           g_string_free(LineBuf,TRUE);
       -
       -   CloseHighScoreFile();
        }
        #endif /* NETWORKING */
        
       t@@ -879,23 +875,26 @@ void CloseHighScoreFile() {
           if (ScoreFP) fclose(ScoreFP);
        }
        
       -void InitHighScoreFile() {
       +int InitHighScoreFile() {
        /* Opens the high score file for later use, and then drops privileges.      */
       -/* If the high score file cannot be found, exits the program with an error. */
       +/* If the high score file cannot be found, returns -1 (0=success)           */
        
       -   if (ScoreFP) return;  /* If already opened, then we're done */
       +   if (ScoreFP) return 0;  /* If already opened, then we're done */
        
           ScoreFP=fopen(HiScoreFile,"a+");
        
       +#ifndef CYGWIN
           if (setregid(getgid(),getgid())!=0) perror("setregid");
       +#endif
        
           if (!ScoreFP) {
              g_warning(_("Cannot open high score file %s.\n"
                        "Either ensure you have permissions to access this file and "
                        "directory, or\nspecify an alternate high score file with "
                        "the -f command line option."),HiScoreFile);
       -      exit(1);
       +      return -1;
           }
       +   return 0;
        }
        
        int HighScoreRead(struct HISCORE *MultiScore,struct HISCORE *AntiqueScore) {
 (DIR) diff --git a/src/serverside.h b/src/serverside.h
       t@@ -65,7 +65,7 @@ void SetFightTimeout(Player *Play);
        void ClearFightTimeout(Player *Play);
        int GetMinimumTimeout(GSList *First);
        GSList *HandleTimeouts(GSList *First);
       -void InitHighScoreFile();
       +int InitHighScoreFile();
        void CloseHighScoreFile();
        int HighScoreRead(struct HISCORE *MultiScore,struct HISCORE *AntiqueScore);
        void CopsAttackPlayer(Player *Play);
 (DIR) diff --git a/src/winmain.c b/src/winmain.c
       t@@ -28,11 +28,11 @@
        #include <commctrl.h>
        #include <glib.h>
        #include <stdlib.h>
       -#include "dopeid.h"
        
        #include "dopeos.h"
        #include "dopewars.h"
        #include "tstring.h"
       +#include "AIPlayer.h"
        #include "curses_client.h"
        #include "gtk_client.h"
        #include "message.h"
       t@@ -68,16 +68,7 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
           split=g_strsplit(lpszCmdParam," ",0);
           argc=0;
           while (split[argc] && split[argc][0]) argc++;
       -   HandleCmdLine(argc,split);
       -   g_strfreev(split);
       -   if (WantVersion || WantHelp) {
       -      AllocConsole();
       -      g_set_print_handler(Win32PrintFunc);
       -      HandleHelpTexts();
       -      newterm(NULL,NULL,NULL);
       -      g_print(_("Press any key..."));
       -      bgetch();
       -   } else {
       +   if (GeneralStartup(argc,split)==0 && !WantVersion && !WantHelp) {
              StartNetworking();
              if (Server) {
                 AllocConsole();
       t@@ -104,6 +95,8 @@ int APIENTRY WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
              }
              StopNetworking();
           }
       +   g_strfreev(split);
       +   CloseHighScoreFile();
           if (PidFile) g_free(PidFile);
           return 0;
        }