home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / BBS_IO.C < prev    next >
Text File  |  1992-01-27  |  2KB  |  126 lines

  1. /*** bbs_io.c ***/
  2.  
  3. #include <stdio.h>
  4. #include "pcl4c.h"
  5. #include "ascii.h"
  6. #include "bbs.h"
  7.  
  8. extern int TransferFlag;
  9. extern int EchoFlag;
  10.  
  11. /*** output to serial port ***/
  12.  
  13. int PutChar(Port,ch)
  14. int Port;
  15. char ch;
  16. {int Code;
  17.  /* output character */
  18.  Code = SioPutc(Port,ch);
  19.  if(Code<0)
  20.      {printf("COM%d Error: ",1+Port);
  21.       SioError(Code);
  22.       exit(1);
  23.      }
  24.  if(!TransferFlag) SioCrtWrite(ch);
  25.  return(Code);
  26.  }
  27.  
  28. /*** receive from serial port ***/
  29.  
  30. int GetChar(Port,Timeout)
  31. int Port;
  32. int Timeout;
  33. {int Code;
  34.  /* input character */
  35.  Code = SioGetc(Port,Timeout);
  36.  if(Code<-1)
  37.      {printf("COM%d Error: ",1+Port);
  38.       SioError(Code);
  39.       exit(1);
  40.      }
  41.  if(!TransferFlag) if(Code!=-1) SioCrtWrite(Code);
  42.  return(Code);
  43. }
  44.  
  45. /*** output carriage return and line feed ***/
  46.  
  47. int PutCRLF(Port)
  48. {
  49.  PutChar(Port,CR);
  50.  PutChar(Port,LF);
  51. }
  52.  
  53. /*** output text string ***/
  54.  
  55. int PutString(Port,String)
  56. int Port;
  57. char *String;
  58. {int i;
  59.  PutCRLF(Port);
  60.  for(i=0;i<strlen(String);i++)
  61.     {/* write character to port */
  62.      PutChar(Port,String[i]);
  63.      /*SioDelay(1);*/
  64.     }
  65. } /* end PutString */
  66.  
  67. /*** receive text string ***/
  68.  
  69. int GetString(Port,Buffer,MaxLen)
  70. int Port;
  71. char *Buffer;
  72. int MaxLen;
  73. {int i = 0;
  74.  int Code;
  75.  int Wait = 60;
  76.  printf("\n");
  77.  while(1)
  78.    {/* fetch next character from port */
  79.     Code = GetChar(Port,Wait*SECONDS);
  80.     if(Code==-1) return(Code);
  81.     if(Code<0) MyExit(Code,"Error ");
  82.     /* echo it back ? */
  83.     if(EchoFlag) SioPutc(Port,Code);
  84.     else SioPutc(Port,'.');
  85.     /* carriage return ? */
  86.     if((char)Code==CR)
  87.        {Buffer[i] = '\0';
  88.         return(0);
  89.        }
  90.     /* backspace ? */
  91.     if((char)Code==BS)
  92.       {if(i==0) continue;
  93.        else i--;
  94.       }
  95.     else  /* stuff in string buffer */
  96.       {Buffer[i++] = (char)Code;
  97.        Wait = 10;
  98.        if(i>MaxLen) return(1);
  99.       }
  100.    } /* end while */
  101. } /* end GetString */
  102.  
  103. /*** display error text ***/
  104.  
  105. int SayError(Port,Msg)
  106. int Port;
  107. char *Msg;
  108. {char Temp[80];
  109.  sprintf(Temp,"ERROR: COM%d - %s",1+Port,Msg);
  110.  PutString(Port,Temp);
  111. } /* end SayError */
  112.  
  113. /*** display message at bottom of screen ***/
  114.  
  115. int DisplayLine(Msg,Ptr,Len)
  116. char *Msg;
  117. char *Ptr; /* not used */
  118. int Len;   /* not used */
  119. {
  120.  printf("[%s]\n",Msg);
  121. } /* end DisplayLine */
  122. /*** test for break condition ***/
  123.  
  124. int TestBreak()
  125. {if(SioBrkKey()) MyExit(0,"User pressed Ctrl-BREAK");
  126. }