File: main.c

package info (click to toggle)
xdemineur 2.1.1-21
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 436 kB
  • sloc: ansic: 1,314; makefile: 8
file content (145 lines) | stat: -rw-r--r-- 3,700 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright  1993-1999 Marc Baudoin <babafou@babafou.eu.org>
 *
 * Permission to use, copy, modify, and distribute this software and
 * its documentation for any purpose and without fee is hereby
 * granted, provided that the above copyright notice appear in all
 * copies and that both that copyright notice and this permission
 * notice appear in supporting documentation.  The author makes no
 * representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied
 * warranty.
 *
 */

static char *const cvsid = "$Id: main.c,v 1.3.2.2 1999/08/01 20:57:46 babafou Exp $" ;

#include <sys/types.h>

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <time.h>

#include "demineur.h"
#include "xdemineur.h"

/* ------------------------------------------------------------------------- */

void sigalrm ( int sig ) ;

/* ------------------------------------------------------------------------- */

extern volatile time_t   elapsed ;
extern state_t           state ;
int                      option_mines = 0 ;

/* ------------------------------------------------------------------------- */

int main ( int argc , char **argv )
{
   int                i ;
   char               *display_name = NULL , *geometry = NULL ;
   struct sigaction   act ;

   /* command line arguments */

   for ( i = 1 ; i < argc ; i ++ )
   {
      if ( strcmp ( argv[i] , "-v" ) == 0 )
      {
         unsigned char *message = "\
xdmineur 2.1.1\n\
\n\
Copyright  1993-1999 Marc Baudoin <babafou@babafou.eu.org>\n\
\n\
Permission to use, copy, modify, and distribute this software and\n\
its documentation for any purpose and without fee is hereby\n\
granted, provided that the above copyright notice appear in all\n\
copies and that both that copyright notice and this permission\n\
notice appear in supporting documentation.  The author makes no\n\
representations about the suitability of this software for any\n\
purpose.  It is provided \"as is\" without express or implied\n\
warranty.\n" ;

         printf ( "%s" , message ) ;

         exit ( EX_OK ) ;
      }
      else if ( strcmp ( argv[i] , "-display" ) == 0 )
      {
         i ++ ;
         if ( i < argc )
         {
            display_name = argv[i] ;
            continue ;
         }
         i -- ;
      }
      else if ( strcmp ( argv[i] , "-geometry" ) == 0 )
      {
         i ++ ;
         if ( i < argc )
         {
            geometry = argv[i] ;
            continue ;
         }
         i -- ;
      }
      else if ( strcmp ( argv[i] , "-m" ) == 0 )
      {
         i ++ ;
         if ( i < argc )
         {
            option_mines = atoi ( argv[i] ) ;
            continue ;
         }
         i -- ;
      }

      fprintf ( stderr , "bad command line option \"%s\"\n" , argv[i] ) ;
      fprintf ( stderr ,
        "usage: %s [-v] [-display displayname] [-geometry geom] [-m mines]\n" ,
                argv[0] ) ;
      exit ( EX_USAGE ) ;
   }

   /* initialization */

   xdemineur_initialize ( argc , argv , display_name , geometry ) ;

   srand ( time ( NULL ) ) ;

   demineur_initialize ( option_mines ) ;

   act.sa_handler = sigalrm ;
   sigemptyset ( &act.sa_mask ) ;
#ifdef SA_RESTART
   act.sa_flags = SA_RESTART ;
#else
   act.sa_flags = 0 ;
#endif
   if ( sigaction ( SIGALRM , &act , NULL ) == -1 )
   {
      perror ( "sigaction" ) ;
      exit ( EX_OSERR ) ;
   }

   /* event loop */

   xdemineur_event_loop ( ) ;

   /* the end */

   demineur_end ( ) ;

   exit ( EX_OK ) ;
}

/* ------------------------------------------------------------------------- */

void sigalrm ( int sig )
{
   elapsed ++ ;
}