home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / BURKS / SOFTWARE / LIBS / PCL4C43.ZIP / LOGIN.C (.txt) < prev    next >
Text File  |  1995-04-06  |  5KB  |  198 lines

  1. /*
  2. **  login.c (3/3/95)
  3. **
  4. **  Logs onto MarshallSoft BBS as 'GUEST GUEST'
  5. */
  6.  
  7.  
  8. #define RTS_CTS_CONTROL 1
  9.  
  10. /************************/
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <malloc.h>
  15. #include <dos.h>
  16. #include <string.h>
  17. #include "modem_io.h"
  18. #include "pcl4c.h"
  19.  
  20. #define FALSE 0
  21. #define TRUE !FALSE
  22. #define CTLZ 0x1a
  23.  
  24. /*** Global Variables ***/
  25.  
  26. int Port;                 /* COM Port */
  27. int CharPace = 3;         /* inter-char delay in tics */
  28. int BaudCode;             /* baud rate code ( index into BaudRate[] ) */
  29. char *BaudRate[10] =  {"300","600","1200","2400","4800","9600",
  30.                        "19200","38400","57600","115200"};
  31. char *ModelText[4] =  {"Small","Compact","Medium","Large"};
  32.  
  33. /*** local prototypes ***/
  34.  
  35. int BaudMatch(char *);
  36. int PutGet(char *,char *,int);
  37. void ErrorCheck(int);
  38. void MyExit(char *);
  39.  
  40. /*** main ***/
  41.  
  42. #define ONE_SEC 18
  43.  
  44. void main(int argc, char *argv[])
  45. {char c;
  46.  int  i, rc;
  47.  char far *Ptr;
  48.  int  Seg;
  49.  int  Code;
  50.  int  Version;
  51.  char Temp[80];
  52.  if(argc!=3)
  53.    {printf("Usage: LOGIN <port> <baud>\n");
  54.     exit(1);
  55.    }
  56.  /* get port number from command line */
  57.  Port = atoi(argv[1]) - 1;
  58.  if((Port<COM1) || (Port>COM20))
  59.    {printf("Port must be COM1 to COM20n");
  60.     exit(1);
  61.    }
  62.  /* get baud rate from command line */
  63.  BaudCode = BaudMatch(argv[2]);
  64.  if(BaudCode<0)
  65.    {printf("Cannot recognize baud rate = %s\n",argv[2]);
  66.     exit(1);
  67.    }
  68.  /* setup 512 byte receive buffer */
  69.  Ptr = (char far *) _fmalloc(512+16);
  70.  Seg = FP_SEG(Ptr) + ((FP_OFF(Ptr)+15)>>4);
  71.  SioRxBuf(Port,Seg,Size512);
  72.  /* set port parmameters */
  73.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  74.  /* reset the port */
  75.  ErrorCheck( SioReset(Port,BaudCode) );
  76.  /* set DTR and RTS */
  77.  ErrorCheck( SioDTR(Port,'S') );
  78.  ErrorCheck( SioRTS(Port,'S') );
  79.  /* display some info */
  80.  printf(" -- LOGIN (3/5/95) --\n");
  81.  Version = SioInfo('V');
  82.  sprintf(Temp,"      Library: %d.%d\n",Version>>4,0x0f&Version);
  83.  printf(Temp);
  84.  sprintf(Temp," Memory Model: %s\n",ModelText[3&SioInfo('M')] );
  85.  printf(Temp);
  86.  strcpy(Temp,"TX Interrupts: ");
  87.  if(SioInfo('I')) strcat(Temp,"YES\n");
  88.  else strcat(Temp,"NO\n");
  89.  printf(Temp);
  90. #if RTS_CTS_CONTROL
  91.  SioFlow(Port,10*ONE_SEC);
  92.  printf(" Flow Control: YES\n");
  93. #else
  94.  printf(" Flow Control: NO\n");
  95. #endif
  96.  /* Set FIFO level */
  97.  printf("   16550 UART: ");
  98.  if( SioFIFO(Port,LEVEL_14) ) printf("YES\n");
  99.  else printf("NO\n");
  100.  /* clear PCL4C receive buffer */
  101.  ErrorCheck( SioRxFlush(Port) );
  102.  printf("\n");
  103.  /* wait for Modem to say its ready */
  104.  printf("  <<Waiting for Modem DSR>>\n");
  105.  while( !SioDSR(Port) )
  106.    {if(SioKeyPress()||SioBrkKey()) MyExit("Aborted by user");
  107.     printf(".");
  108.     SioDelay(ONE_SEC);
  109.    }
  110.  printf("  <<DSR on>>\n");
  111.  
  112. #if RTS_CTS_CONTROL
  113.  printf("  <<Waiting for Modem CTS>>\n");
  114.  while( !SioCTS(Port) )
  115.    {if(SioKeyPress()||SioBrkKey()) MyExit("Aborted by user");
  116.     printf(".");
  117.     SioDelay(ONE_SEC);
  118.    }
  119.  printf("  <<CTS on>>\n");
  120. #endif
  121.  /* initialize (Hayes compatible) modem */
  122.  Code = PutGet("!AT!","OK",ONE_SEC);
  123.  if(Code) Code = PutGet("AT E1 S7=60 S11=60 V1 X1 Q0!","OK",5*ONE_SEC);
  124.  if(Code)
  125.    {printf("  <<Modem ready. Logging on...>>\n");
  126.     /* log onto MarshallSoft BBS as GUEST */
  127.     Code = PutGet("!ATDT880,9748!","CONNECT",45*ONE_SEC);
  128.     if(Code) Code = PutGet("!","graphics (y/N)?|LAST name:",30*ONE_SEC);
  129.     if(Code=='0') Code = PutGet("!","LAST name:",10*ONE_SEC);
  130.     if(Code) Code = PutGet("GUEST GUEST!","password:",10*ONE_SEC);
  131.     if(Code) Code = PutGet("GUEST!",NULL,10*ONE_SEC);
  132.    }
  133.  else printf("\n  <<WARNING: Expected OK not received>>\n");
  134.  /* user now has control */
  135.  printf("Enter terminal loop ( Type ^Z to exit )\n");
  136.  /* enter terminal loop */
  137.  while(TRUE)
  138.      {/* was key pressed ? */
  139.       if(SioKeyPress())
  140.           {i = SioKeyRead();
  141.            if((char)i==CTLZ)
  142.               {printf("\n*** Hanging up modem\n");
  143.                ModemHangup(Port);
  144.                /* restore COM port status & exit */
  145.                SioDone(Port);
  146.                exit(1);
  147.               }
  148.            else SioPutc(Port,(char)i);
  149.           } /* end if */
  150.       /* any incoming over serial port ? */
  151.       i = SioGetc(Port,0);
  152.       if(i>-1) SioCrtWrite((char)i);
  153.      } /* end while */
  154. } /* end main */
  155.  
  156. /*** check return code ***/
  157.  
  158. void ErrorCheck(int Code)
  159. {/* trap PCL error codes */
  160.  if(Code<0)
  161.      {SioError(Code);
  162.       SioDone(Port);
  163.       exit(1);
  164.      }
  165. } /* end ErrorCheck */
  166.  
  167. /*** find baud rate index ***/
  168.  
  169. int BaudMatch(char *P)
  170. {int i;
  171.  /* find baud rate in table */
  172.  for(i=0;i<10;i++) if(strcmp(BaudRate[i],P)==0) return(i);
  173.  return(-1);
  174. }
  175.  
  176. /*** send string & expect reply ***/
  177.  
  178. int PutGet(char *Send,char *Expect,int Tics)
  179. {int rc;
  180.  printf("\n*** Sending '%s' ",Send);
  181.  if(Expect) printf(" & awaiting '%s'",Expect);
  182.  printf("\n");
  183.  rc = ModemSendTo(Port, CharPace, Send);
  184.  if(Expect)
  185.    {rc = ModemWaitFor(Port,Tics,FALSE,Expect);
  186.     if(rc<=0) printf("\nERROR: '%s' sent but '%s' not received\n",Send,Expect);
  187.    }
  188.  return rc;
  189. }
  190.  
  191. /*** common exit ***/
  192.  
  193. void MyExit(char *S)
  194. {printf("%s\n",S);
  195.  SioDone(Port);
  196.  exit(0);
  197. }
  198.