home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
MAXMAILP.ZIP
/
MAXLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-02
|
6KB
|
283 lines
/****************************************************************************/
/* */
/* Maxlib.c :Miscellaneous Maximus routines for MaxMail */
/* */
/****************************************************************************/
#if defined OS2
#define INCL_DOS
#define INCL_DOSDATETIME
#include <os2.h>
extern int hangup;
#endif
#include "MaxMail.h"
/* Load in the MAXimus PARM file into our global structure */
int read_prm(char *pname)
{
int prmfile,x;
offsets=NULL;
if ((prmfile=sopen(pname,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD))==-1)
return(-1);
x=read(prmfile,(char *)&prm,sizeof(struct m_pointers));
if (prm.id != 'M' || prm.version != CTL_VER)
{
printf("\a\a");
aborterror(FILEOPEN,"Bad PARM file");
}
x=(int)(fsize(pname)-((int)tell(prmfile)));
offsets=(char *)malloc(x+10);
x=read(prmfile,offsets,x);
close(prmfile);
return TRUE;
}
/* Quick simple method to return size of file without
opening it */
#if defined OS2
long fsize(char *fname)
{
FILEFINDBUF find;
USHORT HANDLE;
unsigned count;
HANDLE = 0xffff;
count = 1;
if (DosFindFirst((char far *) fname, (USHORT far *) &HANDLE,
0x0, (FILEFINDBUF far *) &find, sizeof(find),
(unsigned far *) &count,0L) ){
DosFindClose(HANDLE);
return(0L); /* An error occured */
} else {
DosFindClose(HANDLE);
return(find.cbFile);
}
}
#else
long fsize(char *fname)
{
struct find_t find;
if(_dos_findfirst(fname,0xffff,&find))
return(0L); /* An error occured */
else return(find.size);
}
#endif
void get_currents()
{
unsigned x;
/* dos_getdrive not available in OS/2 */
#if !defined OS2
_dos_getdrive(&x);
sprintf(sdrive,"%c:",'A' + x - 1);
#endif
getcwd(temp,_MAX_DIR - 1);
strcpy(sdir,temp+2);
strcat(sdir,"\\");
}
/* Switch to drive,dir specified */
int switch_dir(char *dname)
{
unsigned x,y;
char tt[65];
strcpy(tt,dname);
x = strlen(tt);
tt[x-1] = 0; /* Nullify trailing \ */
/* dos_setdrive not available in OS/2 */
#if !defined OS2
x = dname[0] - 'A' + 1;
_dos_setdrive(x,&y); /*ignore 2nd parm */
#endif
return(chdir(tt));
}
#if !defined OS2
/* Video stuff */
void strout(char *outmsg)
{
if (!ReDirect)
printf(outmsg);
if (!IsLocal) {
check_carrier();
fos_txstrw(outmsg);
check_carrier();
}
}
void strin(char *inmsg)
{
unsigned ch;
int key,minutes;
char *p;
p = inmsg;
cflush();
if (!IsLocal) { /* Simulate GETS function for fossil */
minutes = timeon(); /* Establish a counter */
while (1) {
while ((ch = fos_inkeych()) == 0xFFFF) {
check_carrier();
if (timeon() > minutes + IDLETIME) /* User is idle too long */
aborterror(USERIDLE,NULL);
}
key = ch & 0xff;
if (key == '\r') { /* Carraige return */
break;
}
if (key == '\b') { /* Backspace */
if (p > inmsg) {
fos_txcw((byte) key);
putchar(key);
fos_txcw((byte) ' ');
putchar(' ');
fos_txcw((byte) key);
putchar(key);
p--;
}
*p = 0; /* Terminate */
continue;
}
else {
(*p) = key;
p++;
}
fos_txcw((byte) key);
putchar(key);
}
*p = 0; /* Terminate */
*(p+1) = 0;
}
else gets(inmsg);
}
int chrin(void)
{
unsigned ch;
int key;
int minutes;
cflush();
if (IsLocal)
return(getch());
else {
minutes = timeon(); /* Establish a counter */
while ((ch = fos_inkeych()) == 0xFFFF) {
check_carrier();
if (timeon() > minutes + IDLETIME) { /* User is idle too long */
aborterror(USERIDLE,NULL);
}
}
return(ch & 0xff);
}
}
#endif
void cflush(void)
{
if (IsLocal)
return;
#if defined OS2
com_clear_in();
#else
fos_purge_ibuf();
#endif
}
#if defined OS2
int check_carrier(void)
{
checkhangup();
if (hangup) { /* Look at DCD(carrier bit) */
fclose(outfile);
aborterror(DROPCARRIER,NULL);
}
return(FALSE);
}
#else
int check_carrier(void)
{
unsigned status;
status = fos_modem_stat();
if ((status & 0x80) == 0) { /* Look at DCD(carrier bit) */
fclose(outfile);
aborterror(DROPCARRIER,NULL);
}
return(FALSE);
}
#endif
void logit(char *strng,char flag)
{
FILE *log;
char ttemp[40];
char *ttemp1;
char *month;
char *day;
if (LogMode == FALSE)
return;
ttemp1 = (char *) malloc(101);
if (ttemp1 == NULL) {
LogMode = FALSE;
aborterror(BADALLOC,NULL);
}
strcpy(ttemp, timestring());
strtok(ttemp," "); /* Strip Day of week */
month = strtok(NULL," ");
day = strtok(NULL," ");
tm = strtok(NULL," ");
if (Task)
sprintf(ttemp1,"%c %s %s %s MaxMail{%d} %s\n",flag,day,month,tm,Task,strng);
else sprintf(ttemp1,"%c %s %s %s MaxMail %s\n",flag,day,month,tm,strng);
if ((log = _fsopen(LogFile,"a",SH_DENYWR)) == NULL) {
printf("\a\aError opening log file!\n");
LogMode = FALSE;
free(ttemp1);
return;
}
fputs(ttemp1,log);
free(ttemp1);
fclose(log);
}
char *timestring(void)
{
time_t aclock;
struct tm *newtime;
time(&aclock);
newtime = localtime(&aclock);
return(asctime(newtime));
}
void find_class(void)
{
int x;
for (x=0;x < MAXCLASS;x++)
{
if (LastUser.priv==prm.class[x].priv) {
UserClass=x;
break;
}
}
}