/*                        COPYRIGHT (c) 1990 BY                             *
 *                 MITECH CORPORATION, CONCORD, MASSACHUSETTS.              *
 *			   ALL RIGHTS RESERVED                              *

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of MITECH Corporation
not be used in advertising or publicity pertaining to distribution of
the software without specific, written prior permission.

MITECH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
MITECH BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.

*/

#include <stdio.h>
#include <descrip.h>
#include <ssdef.h>
#include <string.h>
#include <errno.h>

void err_exit(x)
     int x;
{exit(x);}

FILE *open_xtek_mail_box(mbx_name)
     char *mbx_name;
{char tmp[512];
 int j,n;
 FILE *f;
 n = strlen(mbx_name);
 for(j=0;j<n;++j) tmp[j] = toupper(mbx_name[j]);
 tmp[n] = 0;
 create_mbx(tmp);
 if (!(f = fopen(tmp,"rb"))) err_exit(vaxc$errno);
 return(f);}
 
#define mailbox_size (512)
#define mailbox_byte_quota (3*mailbox_size)
#define mailbox_protection_mask (0x0000F000)

 struct dsc$descriptor *
set_dsc_cst(x,buff)
 struct dsc$descriptor *x;
 char *buff;
{(*x).dsc$w_length = strlen(buff);
 (*x).dsc$a_pointer = buff;
 (*x).dsc$b_class = DSC$K_CLASS_S;
 (*x).dsc$b_dtype = DSC$K_DTYPE_T;
 return(x);}

int create_mbx(name)
  char *name;
{short chan;
 int prmflg,maxmsg,bufquo,promsk,acmode,iflag,retval;
 struct dsc$descriptor lognam;
 prmflg = 0;
 maxmsg = mailbox_size;
 bufquo = mailbox_byte_quota;
 promsk = mailbox_protection_mask;
 acmode = 0;
 set_dsc_cst(&lognam,name);
 retval = sys$crembx(prmflg,&chan,maxmsg,bufquo,promsk,acmode,&lognam);
 if (retval != SS$_NORMAL) err_exit(retval);
 return(chan);}




