/* $Header: /fpfilter.wor/RCS/dp.h,v 2.5 1994/11/29 23:42:51 root Exp $ */
#ifndef DEEPEE_H
#define DEEPEE_H
/* Copyright Milan Technology Inc., 1991, 1992 */

/* @(#)dp.h	2.5 10/16/99 */
/* support 3200 */
/* support HP and Adobe postscript binary 6/18/97 */
/* support parallel4 and OS that do not allow line wrap 10/16/99 */

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>

#include <signal.h>

#include <fcntl.h>
#ifdef LINUX
/* #include <bsd/sgtty.h> */
#include </usr/include/sgtty.h>
#else
#include <sgtty.h>
#endif
#include <sys/file.h>
#include <sys/socket.h>

#ifdef LPD
#include <sys/un.h>
#endif

#ifdef ATT
#include <sys/in.h>

#else
#include <netinet/in.h>
#endif

#include <netdb.h>

#ifdef INTERACTIVE
#include <net/errno.h>
#endif
#include <errno.h>

extern int errno;
#include <sys/time.h>
#include <syslog.h>

/* #ifdef SCO */
/* #include <poll.h> */
/* #endif */

#ifdef AIX
#include <sys/select.h>
#endif

#if defined (SEQUENT) || defined (SOLARIS)
#define bcopy(a, b, c) memcpy(b, a, c)
#define rindex(a, b)   strrchr(a, b)
#define bzero(a, c) memset(a, (char)0, c)
#endif

#ifdef HPOLD
#define strcasecmp strcmp
#endif

#ifdef INTERACTIVE
#define rindex(a, b)   strrchr(a, b)
#endif

#define SERIAL    2001
#define PARALLEL  2000

/* The following are additional ports defined for 3800 */
#define SERIAL1   2020
#define SERIAL2   2021
#define PARALLEL1 2010
#define PARALLEL2 2011
#define PARALLEL3 2012
#define PARALLEL4 2013

#define PARALLEL_CHAN_TYPE  0
#define SERIAL_CHAN_TYPE    1

/* HP postscript binary and Adobe postscript binary file type */
#define NO_BINARY     0
#define ADOBE_BINARY  1
#define TEK_BINARY    1
#define HP_BINARY     2


#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

#ifndef STDOUT_FILENO
#define STDOUT_FILENO 1
#endif

#define MAX_MAGIC_HEADER 100
#define LINGERVAL 1000
#define ASCII 0
#define POSTSCRIPT 1
#define CAT 2
#define MAX_BUFFER 2000
#define MAXFILELEN 1024
#define MAXSTRNGLEN 800
#define MAXNAMELEN  256
#define MAXLINELEN  256
#define APPEND 0
#define PREPEND 1

#define TRUE  1
#define FALSE 0

#define CTRL_A    0x01
#define CTRL_C    0x03
#define CTRL_D    0x04
#define CTRL_E    0x05
#define CTRL_Q    0x11
#define CTRL_S    0x13
#define CTRL_T    0x14
#define ESC       0x1B
#define CTRL_BKSL 0x1C

#define readEnd 0
#define writeEnd 1

/* hsw == Host SoftWare */
typedef struct hsw_CONFIG {
   char ptr_nam[MAXNAMELEN];
   char hostname[MAXNAMELEN];
   int port_type;
   int port_index;
   int dataport; /* used for printer classes */
   struct hsw_CONFIG  *next_printer;
} hsw_PCONFIG;

typedef struct file_obj {
   char file_name[MAXNAMELEN];
   struct file_obj *next;
} file_obj_t, *file_obj_ptr;


/* Structure used for notification purposes */

typedef struct notification {
   int mail;                  /* notify thru mail ? */
   int file;                  /* notify thru file ? */
   int syslog;                /* notify thru syslog file ? */
   int program;               /* notify thru execing a prog */
   char user[MAXNAMELEN];     /* User name to send mail to   */
   char filename[MAXNAMELEN]; /* Name of such a file */
   char prog_name[MAXNAMELEN];/* name of prog to exec */
} s_notification;

typedef struct Adobe {
   char *prog;
   char *pname;
   char *name;
   char *host;
   char *accountingfile;
   int banner_first, banner_last, verbose_log;
} s_Adobe;

/* Struct to hold options and other "global" values */
typedef struct options {
   int use_control_d;
   int hostname ;
   int mapflg;
   int ff_flag;
   int dobanner;
   int binary_type;
   int chk_ps;
   int dataport;         /* TCP/IP port number of the target */
   int port_type;        /* port type (parallel or serial) of the target */
   int port_index;       /* port index (0..NPPORT or NSPORT) of the target */
   char port_id_string[20];
   int send_startfile;
   int send_endfile;
   int real_filter;
   int closewait  ;
   int use_printer_classes;
   char *current_dir;
   char *start_string;
   char *end_string;
   char *psbinary_start;
   char *psbinary_end;
   char *asciifilter;
   char asciiname[MAXNAMELEN];
   char start_file[MAXFILELEN];
   char end_file[MAXFILELEN];
   char *printer_str;
   int checkserial ;
   int checkparallel ;
   file_obj_ptr file_list;

   s_Adobe adobe;
   s_notification notify_type;
   /* List of serial and parallel ports */
   hsw_PCONFIG *prt_list;
   int acctg;
   int paracctg ;
} s_options;

/* Function prototypes */

#if defined(__cplusplus)
#define EXTERNAL_FUNCTION( funName, params ) extern "C" { funName params; }
#else
#if defined(ANSI) || defined(__STDC__)
#define EXTERNAL_FUNCTION( funName, params ) funName params
#else
#define EXTERNAL_FUNCTION( funName, params ) funName()
#endif
#endif


EXTERNAL_FUNCTION(void systemNoWait, (char* cmd));
EXTERNAL_FUNCTION(void sig_child, ());
EXTERNAL_FUNCTION(int parseCommandLineArgs, (int argc, char **argv));
EXTERNAL_FUNCTION(void expand_char, ());
EXTERNAL_FUNCTION(void get_printername, (char *printer));
EXTERNAL_FUNCTION(void err_notify, (int err_no, char* message));
EXTERNAL_FUNCTION(void error_protect, (int err_no)); 
EXTERNAL_FUNCTION(hsw_PCONFIG* form_printer_list, 
		  (char* string, hsw_PCONFIG *ptr_ptr, int ptype, int where));
EXTERNAL_FUNCTION(hsw_PCONFIG* process_class_pair, 
		  (char* string, hsw_PCONFIG *ptr_ptr, int where));
EXTERNAL_FUNCTION(char* parse_string, (char* str)); 
EXTERNAL_FUNCTION(void add_file, (file_obj_ptr *flist, char *fil_add)); 
EXTERNAL_FUNCTION(int sendfile, 
	  (int sock, char *fil_send, int outp_d, int chk_ps, char *printer));
EXTERNAL_FUNCTION(void check_input, (int sock, int outp_d, int timeout));
EXTERNAL_FUNCTION(void send_control_d, (int sock));
EXTERNAL_FUNCTION(void check_alarm, ());
EXTERNAL_FUNCTION(char *expand_buffer, (char *, int, int *));
EXTERNAL_FUNCTION(char *expand_ps_bin,
		  (int binary_type, char *data, int length, int *retlength));
EXTERNAL_FUNCTION(void send_banner, ());
EXTERNAL_FUNCTION(char *expand_binary,(char *,int,int));
EXTERNAL_FUNCTION(void update_status_file,(char *message,int status_num,int style));
EXTERNAL_FUNCTION(void write_buf,(int sock, char *buffer, int length,char *ptr_nam,int outp_d));

EXTERNAL_FUNCTION(void check_write,(int sock));
EXTERNAL_FUNCTION(void do_acctg,());
EXTERNAL_FUNCTION(void setPostscriptBinary, (int binary_type));

#endif /* DEEPEE_H */

#define APPEND 0
#define CREATE 1

extern s_options g_opt;
