#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xos.h>
#include <stdio.h>

/*
 * $Source: /mit/sipb/src/src/xscreensaver/RCS/xsaver.h,v $
 * $Author: ghudson $
 * $Header: /mit/sipb/src/src/xscreensaver/RCS/xsaver.h,v 1.3 96/01/28 01:53:21 ghudson Exp $
 *
 * This file is part of xscreensaver.  It contains the general header
 * stuff for the screensaver.
 *
 * Author: Jonathan Kamens, MIT Project Athena and
 *                          MIT Student Information Processing Board
 *
 * Copyright (c) 1989 by Jonathan Kamens.  This code may be
 * distributed freely as long as this notice is kept intact in its
 * entirety and every effort is made to send all corrections and
 * improvements to the code back to the author.  Also, don't try to
 * make any money off of it or pretend that you wrote it.
 */


 /* If you change anything here that will affect the way things appear */
 /* to the user (e.g. you install a maximum timeout and/or default     */
 /* timeout, or you change the default menu button), you might want to */
 /* consider editing the man page to reflect your changes.	       */


 /* Length of a valid encrypted password in the /etc/passwd file */
#define PASSWDLENGTH 		13

 /* Maximun length of a user name */
#define MAXUSERNAME		15

 /* Maximum length of a (plaintext) password.  I know that such a      */
 /* limit is artificial since Unix allows arbitrarily long passwords   */
 /* (to some extent), but I've got to stop somewhere.  You should      */
 /* probably leave it defined at 20, and then compile it with a higher */
 /* limit if somebody complains that they can't type their password    */
 /* (why would anyone want a password longer than 20 characters?       */
#define MAXPASSWORD		20

 /* Default timeout, in minutes, in a string (e.g. "30").  If this is */
 /* set to "0", then either there is no default timeout.  If          */
 /* MAXTIMEOUT is defined, then this MUST be set to something 	      */
 /* non-zero, or you'll get spurious error messages from the program. */
#define TIMEOUT			"0"

 /* Maximum timeout.  The user cannot set xscreensaver to timeout in  */
 /* a greater time period than this.  Note that this should be set to */
 /* a number, NOT a string.					      */
/* #define MAXTIMEOUT		480 */

 /* This supposedly defines the centimeters per minute that the        */
 /* bouncing icon travels.  I'm not sure how well it does that, but it */
 /* does give some measure of the speed of the icon.  Define as a      */
 /* string. 							       */
#define CMPERMINUTE 		"40"

 /* Some people don't like the middle button to be the menu button,    */
 /* especially if the mouse only has two buttons and both of them have */
 /* to be pressed to simulate pressing the middle button.  If you have */
 /* a mouse with only two buttons, or if for some other reason you     */
 /* don't think the middle button should be the default, change this.  */
 /* Once again, define it as a string.				       */
#define MENUBUTTON		"2"

 /* If you define TIMEOUT_LOGOUT, then a user will be logged out if    */
 /* his xscreensaver times out.  Note that the method I use to log the */
 /* user out (in the procedure do_timeout) is, I think, somewhat of a  */
 /* BSD-ism -- I send a kill signal to the process "-1," which should  */
 /* make it go to all the user's processes.  If this won't work for    */
 /* you, you might not want to define this symbol.                     */
#define TIMEOUT_LOGOUT

 /* If your C library uses "putenv" instead of "setenv," you need to   */
 /* define setenv to putenv, because my library uses setenv.  If you   */
 /* have neither setenv nor putenv, take a look at the file setenv.c   */
 /* and decide if you want to use it (i.e. if it will compile on your  */
 /* architecture, and if you do, define the symbol COMPILE_SETENV.     */
/* #define setenv putenv */
/* #define COMPILE_SETENV */

 /* If your system uses the kill system call with a negative process */
 /* id instead of the killpg system call, define the symbol   	     */
 /* NO_KILLPG							     */
#ifdef __svr4__
#define NO_KILLPG
#endif

 /* If your system lacks bzero but has memset, define the symbol     */
 /* USE_MEMSET							     */
#ifdef __svr4__
#define USE_MEMSET
#endif

 /* If your C library does not have srandom and random, define the   */
 /* symbol NO_RANDOM						     */
#if defined(__svr4__) || defined(__hpux)
#define NO_RANDOM
#endif

 /* If defined, xsaver will listen on port number PASSWORD_PORT for  */
 /* tcp connections while the screen is locked.  If it receives a    */
 /* connection, it will read a line of input from the port (or time  */
 /* out in a short amount of time) and see if that input is the      */
 /* correct password.  If it is, the screen is unlocked.	     */  
 /*								     */
 /* The purpose of this is to get around a mysterious bug I have been */
 /* unable to solve in xscreensaver -- occasionally, the program will */
 /* fail to accept any input from the keyboard when the screen is     */
 /* locked, even though I have grabbed the keyboard.		      */
 /* 								      */
 /* Also, there are resources and command-line options to set the port */
 /* to which xsaver will listen.				       */
 /*								       */
 /* I have this enclosed in an #ifndef here so that it can be 	      */
 /* redefined in the makefile.  If you don't want to use it at all,   */
 /* then comment out these three lines.  You'll probably also have to */
 /* do this if your system doesn't have BSD style sockets, because I  */
 /* wrote it for BSD style sockets and don't know much about other    */
 /* types (if you make it work on another architecture, send the      */
 /* changes to me!).			       			      */
#ifndef PASSWORD_PORT
#define PASSWORD_PORT 32253 /* a semi-random number -- I just made it up */
#endif


/*
 *  DO NOT MODIFY ANYTHING BELOW THIS POINT, UNLESS YOU REALLY KNOW
 * WHAT YOU ARE DOING.
 */

#ifdef USE_MEMSET
#define bzero(p,l) memset((p), 0, (l))
#endif

#ifdef NO_RANDOM
#define	srandom			srand48
#define	random			lrand48
#endif

typedef struct {
     int velocity, timeout, menu_button;
     Boolean timeout_exit;
     Boolean use_background, auto_lock, use_passwd, transparent, no_fork;
     Boolean d_time, d_elapsed, d_timeout, leave_close, start_locked;
     Boolean disable_x_screensaver, debug, display_icon;
#ifdef PASSWORD_PORT
     int password_port;
     Boolean require_port;
#endif
     String key, ekey, lock_message;
     String lock_command, unlock_command;
     String startup_message;
#ifdef _IBMR2
     Boolean disable_hotkey, require_hotkey;
#endif
     int logout_button_timeout;
     String logout_command;
} Defaults;


#define TIME_FORMAT 		"Time: %d:%02d"
#define ELAPSED_FORMAT 		"Elapsed: %d:%02d"
#define TIMEOUT_FORMAT 		"Timeout: %d %s, %d %s"
#define TIMELEFT_FORMAT		"Time Left: %d %s, %d %s"
#define USER_FORMAT		"User: %s"
#define PASS_PROMPT1		"Enter password:     "
#define PASS_PROMPT2		"Enter it again:     "
#define CAPS_LOCK_PROMPT        "Check the caps lock key!"

 /* State machine states */

#define DOING_NOTHING 0
#define GETTING_FIRST_INITIAL_PASSWORD 1
#define GETTING_SECOND_INITIAL_PASSWORD 2
#define GETTING_LOCKED_PASSWORD 3
#define SHOWING_CAPSLOCK_WARNING 4


typedef enum {
     Force,
     NoForce
} ForceType;


typedef struct {
     time_t start, current;
} Times;

#ifdef SIGNALRETURNSINT
#define SIGTYPE int
#else
#define SIGTYPE void
#endif

/*  signal() that works right */
int csignal();
