/*************************************************
*                      Smailmon                  *
*************************************************/

/* Copyright (c) University of Cambridge 1995. */

/* P. Hazel, February 1995*/
/* Last Modified: March 1995 */

/* This is the general header file for all the modules that comprise
the smailmon program */

/* System compilation parameters */

#define queue_index_size  10      /* Size of index into queue */
#define queue_buffer_size 10240   /* Big buffer for header handling */


/* ANSI C includes */

#include <ctype.h>
#include <setjmp.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/* Not-fully-ANSI systems (e.g. SunOS4 are missing some things) */

#ifndef SEEK_SET
#define SEEK_SET 0
#define SEEK_CUR 1
#define SEEK_END 2
#endif

#ifdef MEMMOVE_IS_BCOPY
#define memmove(a, b, c) bcopy(b, a, c)
#endif

/* Unix includes */

#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>

/* The sys/resource.h header on SunOS 4 causes trouble with the gcc
compiler. Just stuff the bit we want in here; pragmatic easy way out. */

#ifdef NO_SYS_RESOURCE
#define RLIMIT_NOFILE   6               /* maximum descriptor index + 1 */
struct rlimit {
        int     rlim_cur;               /* current (soft) limit */
        int     rlim_max;               /* maximum value for rlim_cur */
};
#else
#include <sys/resource.h>
#endif
   

/* Regular expression include */

#include "regexp/regexp.h"

/* X11 includes */

#include <X11/Xlib.h>
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/cursorfont.h>
#include <X11/Shell.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Command.h>
#include <X11/Xaw/Form.h>
#include <X11/Xaw/Dialog.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/SimpleMenu.h>
#include <X11/Xaw/SmeBSB.h>
#include <X11/Xaw/SmeLine.h>
#include <X11/Xaw/TextSrc.h>
#include <X11/Xaw/TextSink.h>

/* These are required because smailmon has its own munged
version of the stripchart widget. */

#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/XawInit.h>
#include <X11/Xaw/StripCharP.h>

extern WidgetClass mystripChartWidgetClass;



/*************************************************
*               Enumerations                     *
*************************************************/

/* Operations on the in-store message queue */

enum { queue_noop, queue_add };

/* Operations on the destinations queue */

enum { dest_noop, dest_add, dest_remove };


/*************************************************
*          Structure for destinations            *
*************************************************/

typedef struct dest_item {
  struct dest_item *next;
  char address[1];
} dest_item;     



/*************************************************
*           Structure for queue items            *
*************************************************/

typedef struct queue_item {
  struct queue_item *next;
  struct queue_item *prev; 
  struct dest_item  *destinations; 
  int  input_time; 
  int  msglog_time; 
  char *sender; 
  char name[15];
  char seen;
} queue_item;     



/*************************************************
*                Global variables                *
*************************************************/

extern Display *X_display;         /* Current display */
extern XtAppContext X_appcon;      /* Application context */

extern FILE  *DEBUG;
extern FILE  *LOG;

extern char  *input_dir;           /* name of smail input directory */

extern int    log_buffer_size;     /* size of log buffer */
extern int    log_depth;           /* depth of log tail window */
extern char  *log_display_buffer;  /* to hold display text */
extern char  *log_file;            /* name of smail log file */
extern char  *log_font;            /* font for log display */
extern ino_t  log_inode;           /* the inode of the log file */
extern long int log_position;      /* position in log file */
extern Widget log_widget;          /* widget for tail display */
extern int    log_width;           /* width of log tail window */

extern char * queue_buffer;        /* large buffer for header handling */
extern int    queue_depth;         /* depth of queue window */
extern char * queue_font;          /* font for queue display */
extern int    queue_max_addresses; /* limit on per-message list */
extern int    queue_update;        /* update interval */
extern Widget queue_widget;        /* widget for queue display */
extern int    queue_width;         /* width of queue window */

extern char  *regexp_compiling;    /* string being compiled (for error) */

extern int    smailmon_initialized;/* TRUE when initialized */
extern char  *smailmon_name;       /* name of smailmon program */

extern int    stripchart_height;   /* height of stripcharts */
extern int    stripchart_number;   /* number of stripcharts */
extern regexp **stripchart_regexp; /* vector of regexps */
extern char **stripchart_title;    /* vector of titles */
extern int   *stripchart_total;    /* vector of accumulating values */
extern int    stripchart_update;   /* update interval */
extern int    stripchart_width;    /* width of stripcharts */

extern XtTranslations queue_trans; /* translation table for queue text widget */
extern XtTranslations text_trans;  /* translation table for other text widgets */

extern Widget toplevel_widget;

extern char  *version_date;        /* date of compilation */
extern char  *version_string;      /* version number */
extern char  *visible_name;        /* the domain's visible name */

extern char  *window_title;        /* title of the smailmon window */


/*************************************************
*                Global functions                *
*************************************************/

extern char *copystring(char *);
extern void  create_stripchart(Widget, char *);
extern void  debug(char *, ...);
extern dest_item *find_dest(queue_item *, char *, int);
extern queue_item *find_queue(char *, int);
extern void  init(int, char **);
extern void  menu_create(Widget, XEvent *, String *, Cardinal *);
extern void  queue_display(void);
extern void  read_log(void);
extern int   read_spool(char *);
extern int   read_spool_init(char *);
extern void  read_spool_tidy(void);
extern int   repaint_window(StripChartWidget, int, int);
extern void  scan_spool_input(int);
extern int   strncmpic(char *, char *, int);
extern char *strstric(char *, char *, int);
extern void  str_remove(char *, char *, char *);
extern char *str_subfield(char *, char *, int);
extern char *substr(char *, int, int);
extern void  substr_init(void);
extern void  text_empty(Widget);
extern void  text_show(Widget, char *, ...);
extern void  text_position(Widget, int);
extern void  xs_SetValues(Widget, Cardinal, ...);

/* End of smailmon.h */
