home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / MAXMAILP.ZIP / MAXMAILP.C < prev    next >
C/C++ Source or Header  |  1991-01-04  |  10KB  |  300 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*    Maxmail     : By Craig Derouen                                        */
  4. /*                   October 10,1990                                        */
  5. /*                   Maximus ARCHIVE Mail Xfer Utility                      */
  6. /*                                                                          */
  7. /*           Version 1.0                            */
  8. /*                                        */
  9. /*    Maxmailp      : OS/2 Module Only.  Ported by Steve Lesner.            */
  10. /*    This module is for the OS/2 compile only.  You must use this module   */
  11. /*    to create an OS/2 system.  For Dos, this files counterpart is maxmail.*/
  12. /*    This module draws upon my GateKeeper (GATE.LIB) routines to init the  */
  13. /*    Com port and other various routines used under OS/2 only.            */
  14. /*                                                                          */
  15. /* There are a few things that are different in this version of Maxmail for */
  16. /* OS/2.  Most importantly, the command line parameters.  Here is a summary:*/
  17. /*
  18.    /?  Will display the DOS and OS/2 allowable parameters.
  19.    /Bx Is a Gate Command.  If present, the modem is passed the (x) baud rate.
  20.    /Hx Is a Gate Command.  If present, the modem is passed the (x) com handle.
  21.    /Vx Is a Gate Command.  If present, it tells the Gate what kind of
  22.        screen (x) is being used (7 for mono, no ansi, 15 for color with ansi).
  23.    /S1 Is a Gate Command.  If present, it tells the Gate that a high speed,
  24.        MNP type modem (over 2400) is being used. /S0 or nothing denotes normal
  25.        modem type.
  26.    /W1 Is a Gate Command.  If present, it tells the Gate that the high
  27.        speed modem is locked and is using flow control. /W0 or nithing denotes
  28.        no flow control.
  29. */
  30. /* Please see the README.OS2 file for an example of how to call maxmailp    */
  31. /****************************************************************************/
  32.  
  33.  
  34. #define  MAIN  1
  35.  
  36. #include "MaxMail.h"
  37.  
  38. #define INCL_DOS
  39. #define INCL_DOSDEVICES
  40. #define INCL_DOSDATETIME
  41. #define INCL_SUB
  42.  
  43. #include <os2.h>
  44. #include <io.h>
  45.  
  46. HFILE        hfComHandle = -1;
  47. char         spawned = 0, ansi = 0;
  48. int          high_speed,flow_control,crttype;
  49. int          hangup,modem_active,modem_ok;
  50. char         fname[81],lname[81],curspeed[81];
  51. unsigned int modem_speed,com_speed;
  52.  
  53.  
  54. void main(int argc,char **argv)
  55. {
  56.    int x;
  57.    unsigned y;
  58.    unsigned long count;
  59.    int newuser = FALSE;
  60.    struct stat fbuf;
  61.    double timediff;
  62.    struct packer_st *pack1;
  63.  
  64.    char s[81];
  65.    unsigned int ui,ei;
  66.  
  67.    spawned=0;
  68.    modem_ok=1;
  69.  
  70. /* Parse out the drive and dir where maxmail is located */
  71.    _splitpath(argv[0],hdrive,hdir,temp,temp1);        /* Ignore name and extension */
  72.  
  73.    IsLocal = TRUE;
  74.    TimeAdjust = FALSE;
  75.    msg_update = TRUE;
  76.    packer_del = TRUE;
  77.    Hangup = FALSE;
  78.    MaxMsgs = 400;        /* Maximum number of messages to parse */
  79.    Task = 0;        /* If > 0, Multiuser mode */
  80.    strcpy(MCfgFile,"MaxMail.cfg");
  81.    strcpy(LastUse,"Lastuser.bbs");
  82.    strcpy(PrmFile,"Max.Prm");
  83.    strcpy(TxtFile,"MaxMsgs.txt");
  84.    strcpy(CfgFile,"MaxMail.usr");
  85.    strcpy(StatName,"MsgStats");
  86.    strcpy(SumFile,"Summary");
  87.  
  88.    for (x = 1; x < argc; x++) {        /* Parse out command line */
  89.       strcpy(s,argv[x]);
  90.       if (argv[x][0] == '-' || argv[x][0] == '/') {
  91.          y = toupper(argv[x][1]);        /* Argument switch */
  92.          switch (y) {
  93.             case 'P':        /* Command file */
  94.                strcpy(PrmFile,argv[x]+2);
  95.                break;
  96.  
  97.             case 'C':        /* MaxMail configfile */
  98.                strcpy(CfgFile,argv[x]+2);
  99.                break;
  100.  
  101.             case 'T':        /* Task number */
  102.                Task = argv[x][2] - '0';
  103.                sprintf(LastUse,"Lastus%02d.bbs",Task);
  104.                break;
  105.  
  106.             case 'L':        /* Force Local mode */
  107.                IsLocal = 2;
  108.                modem_ok=0;
  109.                break;
  110.  
  111.             case 'U':        /* Turn off lastread update */
  112.                msg_update = FALSE;
  113.                break;
  114.  
  115.             case 'N':        /* Don't delete packed file */
  116.                packer_del = FALSE;
  117.                break;
  118.  
  119.             case 'A':        /* Adjust time online */
  120.                TimeAdjust = TRUE;
  121.                break;
  122.                                 /* Start of Gate Parameters */
  123.             case 'B':
  124.               ui=(unsigned int) atol(&(s[2]));
  125.               if ((ui==300) || (ui==1200) || (ui==2400) || (ui==9600) || (ui==19200) ||
  126.                   (ui==38400) || (ui==57600)) {
  127.                 itoa(ui,curspeed,10);
  128.                 spawned=1;
  129.               }
  130.               break;
  131.  
  132.             case 'H':
  133.               hfComHandle=atoi(&(s[2]));
  134.               spawned=1;
  135.           break;
  136.  
  137.             case 'S':
  138.               high_speed=atoi(&(s[2]));
  139.               break;
  140.  
  141.             case 'V':
  142.               crttype=atoi(&(s[2]));
  143.               switch (crttype) {
  144.                 case 7  : ansi = 0;break;
  145.                 case 15 : ansi = 1;break;
  146.               }
  147.               break;
  148.  
  149.             case 'W':
  150.               flow_control=atoi(&(s[2]));
  151.               break;
  152.  
  153.             case '?':        /* Show parms */
  154.                show_opts();
  155.                break;
  156.          }
  157.       }
  158.       else {        /* Only non-switch argument specifies the Maxmail config file */
  159.          strcpy(MCfgFile,argv[x]);
  160.       }
  161.    }
  162.  
  163.   initgate(1);
  164.   if (spawned)
  165.     modemcall();
  166.   else
  167.     localcall();
  168.   if (!hangup) {
  169.     logon();
  170.     showglogo();
  171.   }
  172.    init();
  173.  
  174. /* Open the last userfile.  Without it, we can't do a thing! */
  175.  
  176.    x = sopen(LastUse,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD); 
  177.    if (x == -1) 
  178.       aborterror(FILEOPEN,"Missing Lastuse file");
  179.  
  180.    y = read(x,&LastUser,sizeof(struct _usr));
  181.    user_slen = (LastUser.struct_len ? LastUser.struct_len * 20 : 180);
  182.    lseek(x,0L,SEEK_SET);
  183.    y = read(x,&LastUser,user_slen);
  184.    if (y < user_slen) {        /* Humm couldnt read all of file! */
  185.       close(x);
  186.       aborterror(FILEOPEN,"Error reading LastUse file");
  187.    }
  188.    close(x);        /* We only need the file for the structure info */
  189.  
  190.    strcpy(UserName,LastUser.name);
  191.  
  192.    if (IsLocal < 2)
  193.       /* IsLocal = LastUser.flag == 0 ? TRUE : FALSE; */
  194.       IsLocal = FALSE;
  195.  
  196. /* Now Compute the maximum messages caller can have for this run
  197.    based upon time remaining and baud rate. This is really a 
  198.    ROUGH guess and I will polish it in time! */
  199.  
  200.    count = get_kminute(); /* Fetch # of Kilobytes per minute at current baud */
  201.    count *= LastUser.timeremaining;        /* Total # of Kbytes we can download */
  202.  
  203. /* Assume message is average of 500 bytes when packed */
  204.    count /= 500;
  205.  
  206.    MaxMsgs = ((MaxMsgs > count) && LastUser.flag) ? count : MaxMsgs;
  207.  
  208.    UserCfgnum = 0;        /* Startup */
  209.    if(stat(CfgFile,&fbuf) == 0 )         /* Does file exist? */
  210.       x = sopen(CfgFile,O_RDWR | O_BINARY,SH_DENYNO,S_IREAD);
  211.    else x = sopen(CfgFile,O_RDWR | O_BINARY | O_CREAT,SH_DENYNO,S_IWRITE);
  212.    if (x == -1)
  213.       aborterror(FILEOPEN,"Error opening/creating User config file");
  214.    UserCfgnum = find_config(x,LastUser.name,&USERCFG);
  215.    if (UserCfgnum < 0) {        /* Couldn't be found */
  216.       newuser_help();        /* Display a file to the new user */
  217.       newuser = TRUE;
  218.       memset(&USERCFG,0,sizeof(struct user_cfg));
  219.       USERCFG.flags |= USRCFG_UPD;        /* Force the user to update his configuration */
  220.       memcpy(USERCFG.name,LastUser.name,36);
  221.       UserCfgnum = find_blconfig(x);        /* Look for an empty slot */
  222.       if (UserCfgnum < 0)  /* Couldn't be found */
  223.          UserCfgnum = new_user(x);
  224.    }
  225.    close(x);        /* We only need the file for the structure info */
  226.  
  227.    update |= USERCFG.flags;
  228.  
  229.    afile = _fsopen(PRM(adat_name),"rb",SH_DENYNO); 
  230.    if (afile == NULL)
  231.       aborterror(FILEOPEN,"Missing AREA.DAT file");
  232.    fread(&AREA,sizeof(struct _area),1,afile);
  233.    astrlen = AREA.struct_len;
  234.  
  235.  
  236.    if(fidomsg_init()) {
  237.       fclose(afile);
  238.       aborterror(BADALLOC,NULL);
  239.    }
  240.  
  241.    if (!(update & USRCFG_UPD)) {
  242.       if (USERCFG.protocol > totprotocols)
  243.          update |= USRCFG_FUPD;
  244.  
  245.       if (USERCFG.packer > totpackers)
  246.          update |= USRCFG_FUPD;
  247.    }
  248.  
  249.    signon();        /* Sign on message */
  250.    sprintf(temp,"Begin, v%2.2f",Version);
  251.    logit(temp,'+');
  252.    if (!newuser) 
  253.       sprintf(temp1,"User: %s logging on",UserName);
  254.    else sprintf(temp1,"New User: %s logging on",UserName);
  255.    logit(temp1,':');
  256.  
  257.    if ((update & USRCFG_UPD)  || (update & USRCFG_FUPD)) 
  258.       getconfig();
  259.    else {
  260.       strout("\r\nScanning your message areas. Hang on....");
  261.       y = build_areas();
  262.       if (USERCFG.totareas == 0)
  263.          USERCFG.totareas = y;
  264.       else if (y != USERCFG.totareas) {
  265.          update |= USRCFG_FUPD;
  266.          getconfig();
  267.       }
  268.    }
  269.  
  270.    pack1 = get_curpacklnk();
  271.  
  272.    menu();
  273.    strout("\r\n\r\n");
  274.    if (*SignOff) {
  275.       strout(SignOff);
  276.       strout("\r\n");
  277.    }
  278.    if (!Hangup && !IsLocal) {
  279.       strout("Heading back to Maximus. Please wait a sec....\r\n");
  280.    }
  281.    if (totmsgs)      /* Update the lastread pointers */
  282.       update_msgs();
  283.    if (!IsLocal) {
  284.       delay_s(3);
  285.       com_clear_out();
  286.    }
  287.    if (Hangup) {
  288.       logit("User requested hangup",'#');
  289.       dtr(FALSE);
  290.       delay_s(4);
  291.       dtr(TRUE);
  292.       deinit(5);
  293.    }
  294.    deinit(0);
  295.    logoff(1);
  296.    cleanup();
  297.    outlocal("\x0c");
  298.    end_gate(1);
  299. }
  300.