home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
MAXMAILP.ZIP
/
MAXMAILP.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-04
|
10KB
|
300 lines
/****************************************************************************/
/* */
/* Maxmail : By Craig Derouen */
/* October 10,1990 */
/* Maximus ARCHIVE Mail Xfer Utility */
/* */
/* Version 1.0 */
/* */
/* Maxmailp : OS/2 Module Only. Ported by Steve Lesner. */
/* This module is for the OS/2 compile only. You must use this module */
/* to create an OS/2 system. For Dos, this files counterpart is maxmail.*/
/* This module draws upon my GateKeeper (GATE.LIB) routines to init the */
/* Com port and other various routines used under OS/2 only. */
/* */
/* There are a few things that are different in this version of Maxmail for */
/* OS/2. Most importantly, the command line parameters. Here is a summary:*/
/*
/? Will display the DOS and OS/2 allowable parameters.
/Bx Is a Gate Command. If present, the modem is passed the (x) baud rate.
/Hx Is a Gate Command. If present, the modem is passed the (x) com handle.
/Vx Is a Gate Command. If present, it tells the Gate what kind of
screen (x) is being used (7 for mono, no ansi, 15 for color with ansi).
/S1 Is a Gate Command. If present, it tells the Gate that a high speed,
MNP type modem (over 2400) is being used. /S0 or nothing denotes normal
modem type.
/W1 Is a Gate Command. If present, it tells the Gate that the high
speed modem is locked and is using flow control. /W0 or nithing denotes
no flow control.
*/
/* Please see the README.OS2 file for an example of how to call maxmailp */
/****************************************************************************/
#define MAIN 1
#include "MaxMail.h"
#define INCL_DOS
#define INCL_DOSDEVICES
#define INCL_DOSDATETIME
#define INCL_SUB
#include <os2.h>
#include <io.h>
HFILE hfComHandle = -1;
char spawned = 0, ansi = 0;
int high_speed,flow_control,crttype;
int hangup,modem_active,modem_ok;
char fname[81],lname[81],curspeed[81];
unsigned int modem_speed,com_speed;
void main(int argc,char **argv)
{
int x;
unsigned y;
unsigned long count;
int newuser = FALSE;
struct stat fbuf;
double timediff;
struct packer_st *pack1;
char s[81];
unsigned int ui,ei;
spawned=0;
modem_ok=1;
/* Parse out the drive and dir where maxmail is located */
_splitpath(argv[0],hdrive,hdir,temp,temp1); /* Ignore name and extension */
IsLocal = TRUE;
TimeAdjust = FALSE;
msg_update = TRUE;
packer_del = TRUE;
Hangup = FALSE;
MaxMsgs = 400; /* Maximum number of messages to parse */
Task = 0; /* If > 0, Multiuser mode */
strcpy(MCfgFile,"MaxMail.cfg");
strcpy(LastUse,"Lastuser.bbs");
strcpy(PrmFile,"Max.Prm");
strcpy(TxtFile,"MaxMsgs.txt");
strcpy(CfgFile,"MaxMail.usr");
strcpy(StatName,"MsgStats");
strcpy(SumFile,"Summary");
for (x = 1; x < argc; x++) { /* Parse out command line */
strcpy(s,argv[x]);
if (argv[x][0] == '-' || argv[x][0] == '/') {
y = toupper(argv[x][1]); /* Argument switch */
switch (y) {
case 'P': /* Command file */
strcpy(PrmFile,argv[x]+2);
break;
case 'C': /* MaxMail configfile */
strcpy(CfgFile,argv[x]+2);
break;
case 'T': /* Task number */
Task = argv[x][2] - '0';
sprintf(LastUse,"Lastus%02d.bbs",Task);
break;
case 'L': /* Force Local mode */
IsLocal = 2;
modem_ok=0;
break;
case 'U': /* Turn off lastread update */
msg_update = FALSE;
break;
case 'N': /* Don't delete packed file */
packer_del = FALSE;
break;
case 'A': /* Adjust time online */
TimeAdjust = TRUE;
break;
/* Start of Gate Parameters */
case 'B':
ui=(unsigned int) atol(&(s[2]));
if ((ui==300) || (ui==1200) || (ui==2400) || (ui==9600) || (ui==19200) ||
(ui==38400) || (ui==57600)) {
itoa(ui,curspeed,10);
spawned=1;
}
break;
case 'H':
hfComHandle=atoi(&(s[2]));
spawned=1;
break;
case 'S':
high_speed=atoi(&(s[2]));
break;
case 'V':
crttype=atoi(&(s[2]));
switch (crttype) {
case 7 : ansi = 0;break;
case 15 : ansi = 1;break;
}
break;
case 'W':
flow_control=atoi(&(s[2]));
break;
case '?': /* Show parms */
show_opts();
break;
}
}
else { /* Only non-switch argument specifies the Maxmail config file */
strcpy(MCfgFile,argv[x]);
}
}
initgate(1);
if (spawned)
modemcall();
else
localcall();
if (!hangup) {
logon();
showglogo();
}
init();
/* Open the last userfile. Without it, we can't do a thing! */
x = sopen(LastUse,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD);
if (x == -1)
aborterror(FILEOPEN,"Missing Lastuse file");
y = read(x,&LastUser,sizeof(struct _usr));
user_slen = (LastUser.struct_len ? LastUser.struct_len * 20 : 180);
lseek(x,0L,SEEK_SET);
y = read(x,&LastUser,user_slen);
if (y < user_slen) { /* Humm couldnt read all of file! */
close(x);
aborterror(FILEOPEN,"Error reading LastUse file");
}
close(x); /* We only need the file for the structure info */
strcpy(UserName,LastUser.name);
if (IsLocal < 2)
/* IsLocal = LastUser.flag == 0 ? TRUE : FALSE; */
IsLocal = FALSE;
/* Now Compute the maximum messages caller can have for this run
based upon time remaining and baud rate. This is really a
ROUGH guess and I will polish it in time! */
count = get_kminute(); /* Fetch # of Kilobytes per minute at current baud */
count *= LastUser.timeremaining; /* Total # of Kbytes we can download */
/* Assume message is average of 500 bytes when packed */
count /= 500;
MaxMsgs = ((MaxMsgs > count) && LastUser.flag) ? count : MaxMsgs;
UserCfgnum = 0; /* Startup */
if(stat(CfgFile,&fbuf) == 0 ) /* Does file exist? */
x = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
else x = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IWRITE);
if (x == -1)
aborterror(FILEOPEN,"Error opening/creating User config file");
UserCfgnum = find_config(x,LastUser.name,&USERCFG);
if (UserCfgnum < 0) { /* Couldn't be found */
newuser_help(); /* Display a file to the new user */
newuser = TRUE;
memset(&USERCFG,0,sizeof(struct user_cfg));
USERCFG.flags |= USRCFG_UPD; /* Force the user to update his configuration */
memcpy(USERCFG.name,LastUser.name,36);
UserCfgnum = find_blconfig(x); /* Look for an empty slot */
if (UserCfgnum < 0) /* Couldn't be found */
UserCfgnum = new_user(x);
}
close(x); /* We only need the file for the structure info */
update |= USERCFG.flags;
afile = _fsopen(PRM(adat_name),"rb",SH_DENYNO);
if (afile == NULL)
aborterror(FILEOPEN,"Missing AREA.DAT file");
fread(&AREA,sizeof(struct _area),1,afile);
astrlen = AREA.struct_len;
if(fidomsg_init()) {
fclose(afile);
aborterror(BADALLOC,NULL);
}
if (!(update & USRCFG_UPD)) {
if (USERCFG.protocol > totprotocols)
update |= USRCFG_FUPD;
if (USERCFG.packer > totpackers)
update |= USRCFG_FUPD;
}
signon(); /* Sign on message */
sprintf(temp,"Begin, v%2.2f",Version);
logit(temp,'+');
if (!newuser)
sprintf(temp1,"User: %s logging on",UserName);
else sprintf(temp1,"New User: %s logging on",UserName);
logit(temp1,':');
if ((update & USRCFG_UPD) || (update & USRCFG_FUPD))
getconfig();
else {
strout("\r\nScanning your message areas. Hang on....");
y = build_areas();
if (USERCFG.totareas == 0)
USERCFG.totareas = y;
else if (y != USERCFG.totareas) {
update |= USRCFG_FUPD;
getconfig();
}
}
pack1 = get_curpacklnk();
menu();
strout("\r\n\r\n");
if (*SignOff) {
strout(SignOff);
strout("\r\n");
}
if (!Hangup && !IsLocal) {
strout("Heading back to Maximus. Please wait a sec....\r\n");
}
if (totmsgs) /* Update the lastread pointers */
update_msgs();
if (!IsLocal) {
delay_s(3);
com_clear_out();
}
if (Hangup) {
logit("User requested hangup",'#');
dtr(FALSE);
delay_s(4);
dtr(TRUE);
deinit(5);
}
deinit(0);
logoff(1);
cleanup();
outlocal("\x0c");
end_gate(1);
}