Bug #283 ยป dm.diff
| games/dm/Makefile 5 Aug 2006 17:16:03 -0000 | ||
|---|---|---|
|
MAN= dm.8 dm.conf.5
|
||
|
BINGRP= games
|
||
|
BINMODE=2555
|
||
|
WARNS?= 6
|
||
|
.include <bsd.prog.mk>
|
||
| games/dm/dm.c 5 Aug 2006 17:15:21 -0000 | ||
|---|---|---|
|
static char *game, /* requested game */
|
||
|
*gametty; /* from tty? */
|
||
|
void c_day (char *, char *, char *);
|
||
|
void c_tty (char *);
|
||
|
void c_game (char *, char *, char *, char *);
|
||
|
void hour (int);
|
||
|
double load (void);
|
||
|
void nogamefile (void);
|
||
|
void play (char **);
|
||
|
void read_config (void);
|
||
|
int users (void);
|
||
|
static void c_day(char *, char *, char *);
|
||
|
static void c_tty(char *);
|
||
|
static void c_game(char *, char *, char *, char *);
|
||
|
static void hour(int);
|
||
|
static double load(void);
|
||
|
static void nogamefile(void);
|
||
|
static void play(char **);
|
||
|
static void read_config(void);
|
||
|
static int users(void);
|
||
|
#ifdef LOG
|
||
|
static void logfile(void);
|
||
|
#endif
|
||
|
int
|
||
|
main(argc, argv)
|
||
|
int argc;
|
||
|
char *argv[];
|
||
|
main(__unused int argc, char *argv[])
|
||
|
{
|
||
|
char *cp;
|
||
| ... | ... | |
|
* play --
|
||
|
* play the game
|
||
|
*/
|
||
|
void
|
||
|
play(args)
|
||
|
char **args;
|
||
|
static void
|
||
|
play(char **args)
|
||
|
{
|
||
|
char pbuf[MAXPATHLEN];
|
||
| ... | ... | |
|
* read_config --
|
||
|
* read through config file, looking for key words.
|
||
|
*/
|
||
|
void
|
||
|
read_config()
|
||
|
static void
|
||
|
read_config(void)
|
||
|
{
|
||
|
FILE *cfp;
|
||
|
char lbuf[BUFSIZ], f1[40], f2[40], f3[40], f4[40], f5[40];
|
||
| ... | ... | |
|
* c_day --
|
||
|
* if day is today, see if okay to play
|
||
|
*/
|
||
|
void
|
||
|
c_day(s_day, s_start, s_stop)
|
||
|
char *s_day, *s_start, *s_stop;
|
||
|
static void
|
||
|
c_day(char *s_day, char *s_start, char *s_stop)
|
||
|
{
|
||
|
static const char *days[] = {
|
||
|
"sunday", "monday", "tuesday", "wednesday",
|
||
| ... | ... | |
|
* c_tty --
|
||
|
* decide if this tty can be used for games.
|
||
|
*/
|
||
|
void
|
||
|
c_tty(tty)
|
||
|
char *tty;
|
||
|
static void
|
||
|
c_tty(char *tty)
|
||
|
{
|
||
|
static int first = 1;
|
||
|
static char *p_tty;
|
||
| ... | ... | |
|
* c_game --
|
||
|
* see if game can be played now.
|
||
|
*/
|
||
|
void
|
||
|
c_game(s_game, s_load, s_users, s_priority)
|
||
|
char *s_game, *s_load, *s_users, *s_priority;
|
||
|
static void
|
||
|
c_game(char *s_game, char *s_load, char *s_users, char *s_priority)
|
||
|
{
|
||
|
static int found;
|
||
| ... | ... | |
|
* load --
|
||
|
* return 15 minute load average
|
||
|
*/
|
||
|
double
|
||
|
load()
|
||
|
static double
|
||
|
load(void)
|
||
|
{
|
||
|
double avenrun[3];
|
||
| ... | ... | |
|
* todo: check idle time; if idle more than X minutes, don't
|
||
|
* count them.
|
||
|
*/
|
||
|
int
|
||
|
users()
|
||
|
static int
|
||
|
users(void)
|
||
|
{
|
||
|
int nusers, utmp;
|
||
| ... | ... | |
|
return(nusers);
|
||
|
}
|
||
|
void
|
||
|
nogamefile()
|
||
|
static void
|
||
|
nogamefile(void)
|
||
|
{
|
||
|
int fd, n;
|
||
|
char buf[BUFSIZ];
|
||
| ... | ... | |
|
* hour --
|
||
|
* print out the hour in human form
|
||
|
*/
|
||
|
void
|
||
|
hour(h)
|
||
|
int h;
|
||
|
static void
|
||
|
hour(int h)
|
||
|
{
|
||
|
switch(h) {
|
||
|
case 0:
|
||
| ... | ... | |
|
* logfile --
|
||
|
* log play of game
|
||
|
*/
|
||
|
logfile()
|
||
|
static void
|
||
|
logfile(void)
|
||
|
{
|
||
|
struct passwd *pw;
|
||
|
FILE *lp;
|
||