#include	"install.h"

#define STATUS_FAIL(msg, status) { \
	if (!((status & STS$M_SUCCESS) >> STS$V_SUCCESS)) { \
		lib$signal(status); \
		lowcase(msg); \
		fprintf(stderr, " \\%s\\\r\n", msg); \
		sys$exit(SS$_NORMAL); \
	} \
}	

#define	FILE_FAIL(msg, status) { \
	if (status == NULL || status == -1) { \
		lowcase(msg); \
	    	fprintf(stderr, "Fail to open/create/access %s\r\n", msg); \
		sys$exit(SS$_NORMAL); \
	} \
}

/*
 * Messages.
 */

#define	MSG1		"\007Backup past top of buffer"
#define	MSG2		"\007Advance past bottom of buffer"
#define MSG3		"\007Undefined key, type '?' for help"
#define MSG4		"\007No previous marked bulletin message"
#define MSG5		"\007Can't queue to sys$print"
#define MSG6		"\007Can't write to this file"
#define MSG7		"\007Can't write to"

/*
 * Commands.
 */

#define	LEGND1		\
"Command: Down, Up, <CR>, <DEL>, <SPACE>, F, M, N, P, X, Ctrl-W, Ctrl-Z, PF2, ?"

#define	LEGND2		\
"Command: <CR>, <SPACE>, F, N, P, S, U, 1-9, Ctrl-W, Ctrl-Z, PF2, ?"

#define LEGND3		\
"Command: <CR>, <SPACE>, B, F, N, P, S, U, Ctrl-W, Ctrl-Z, PF2, ?"

/*
 * Constants.
 */

#define	TOP_ROW			1	/* Start row of screen */
#define	END_ROW			20	/* End row of screen */
#define	BRD_LEN			24	/* Pasteboard length */
#define	BRD_WID			80	/* Pasteboard width */
#define	LEGND_LEN		1	/* Legend virtual display length */
#define	LEGND_POS		1	/* Legend virtual display position */
#define	BULL_LEN		1	/* Bulletin virtual display length */
#define	BULL_POS		2	/* Bulletin virtual display position */
#define	TXT_LEN			20	/* Text virtual display length */
#define TXT_POS			3	/* Text virtual display position */
#define	BOT1_LEN		1	/* Bottom1 virtual display length */
#define BOT1_POS		23	/* Bottom1 virtual display position */
#define	BOT2_LEN		1	/* Bottom2 virtual display length */
#define BOT2_POS		24	/* Bottom2 virtual display position */

#define	LIMIT			9000000	/* Threshold */
#define	QUAL_LEN		255	/* Max length */
#define MAX_BULL		20	/* Max number of bulletins open */

#define	BULL_PARAM		"BULLETIN"	/* Bulletin parameter */
#define	ADD_QUAL		"ADD"	/* ADD qualifier */
#define	ALL_QUAL		"ALL"	/* ALL qualifier */
#define CONFRM_QUAL		"CONFIRM"	/* CONFIRM qualifier */
#define TITLE_QUAL		"TITLE"		/* TITLE qualifier */
#define EXPDATE_QUAL		"EXPIRY_DATE"	/* EXPIRY_DATE qualifier */
#define	FILE_QUAL		"FILE"	/* FILE qualifier */
#define	BRIEF_QUAL		"BRIEF"	/* BRIEF qualifier */
#define	DEL_QUAL		"DELETE"	/* DELETE qualifier */
#define	EDT_QUAL		"EDIT"	/* EDIT qualifier */
#define	EXP_QUAL		"EXPIRE"	/* EXPIRE qualifier */
#define	HELP_QUAL		"HELP"	/* HELP qualifier */
#define	NEW_QUAL		"NEW"	/* NEW qualifier */
#define	READ_QUAL		"READ"	/* READ qualifier */
#define	SRCH_QUAL		"SEARCH"	/* SEARCH qualifier */
#define REVRS_QUAL		"REVERSE"	/* REVERSE qualifier */
#define	DEFAULT			"DEFAULT"	/* DEFAULT qualifier */
#define	BATCH_QUAL		"BATCH"	/* BATCH qualifier */

#define	TITLE_LEN		65	/* Size of message title */
#define	INDX_LEN		101	/* Size of index record */

#define	FILENAM_LEN		128	/* Size of file spec */
#define	BULLNAM_LEN		16	/* Size of bulletin name */
#define	CTRLSTR_LEN		240	/* Size of control string */
#define	SEARCHKEY_LEN		80	/* Size of search string */
#define	ASCTIM_LEN		23	/* Size of ASCII time string */
#define	ASCDAT_LEN		11	/* Size of ASCII date string */
#define POSTER_LEN		11	/* Size of Poster */

#define	DAT_LEN			BULLNAM_LEN + CTRLSTR_LEN
                
#define	USER_HELPSTR		"BULLETIN"	
#define	MAINT_HELPSTR		"BULLMAINT"	
#define	BULLUPD			"SYS$LOGIN:BULLETIN.DAT" 
#define	DEF_LIBNAM		"BULLETIN.BLB"	
#define	DEF_EXT			".BUL"	

#define	MSG_LEN			512	
#define	KEY_LEN			10	
#define	KEY_PREFX		"B"	
#define	MARK			'X'
#define	UNMARK			' '
#define	READ			'R'
#define	NEVER			'N'
#define	DELETE			'D'
#define	YES			'Y'
#define	NO			'N'

#define	INCR			'i'
#define	DECR			'd'
#define	ALL			'a'
#define	NEW			'n'
#define	LIB			'l'

#define TRUE			1
#define	FALSE			0

#define PF2			257
#define	UP			274
#define DOWN			275
#define CTRL_U			21
#define	CTRL_W			23
#define CTRL_Z			26
#define DEL			127
#define RETURN			13
#define ESCAPE			27

struct	indx_file_struct {
	long	msg_id;
	char	status;
	char	title[TITLE_LEN];
	unsigned 	date[2];
	unsigned 	exp_date[2];
	long	lin_cnt;
	char	poster[POSTER_LEN];
};

struct	data_file_struct {
	char	bull_nam[BULLNAM_LEN];
	char	upd_lst[CTRLSTR_LEN];
};

struct	lnk_lst_struct {
	long	msg_id;	
	char	*title;	
	unsigned 	date[2];	
	unsigned 	exp_date[2];
	long	lin_cnt; 
	char	poster[POSTER_LEN];
	char	marker;	
	char	flag;	
	char	read;	
	long	presnt_lib; 
	char	*bck;
	char	*fwd;
	char	*up;
	char	*dwn;
};

struct	bull_lst_struct {
	long	file;
	long	last_bull;
	long	lst_pos[MAX_BULL];
	char	bull_lib[MAX_BULL][FILENAM_LEN];
	char	bull_indx[MAX_BULL][FILENAM_LEN];
	char	bull_nam[MAX_BULL][BULLNAM_LEN];
};

struct	exit_blk_struct {
	long	nxt;
	long	(*exit_rtn)();
	long	num_arg;
	long	*stat_addr;
	long	arg;
};

extern	long	pstbrd_id, 
		keybrd_id, 
		term, 
		legnd_id, 
		bull_id, 
		txt_id, 
		bot1_id, 
		bot2_id, 
		mssg_id;

globalvalue	
	long	BULL_TOOMANY, 		
		BULL_NOTFND, 
		BULL_NOMORE, 
		BULL_NOTITLE, 
		BULL_NOFILE,
		BULL_TOOLONG, 
		BULL_CANTUPD,
		BULL_UPDOVRFLW;
