home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / network / telnet.lzh / consolefun.c next >
C/C++ Source or Header  |  1991-09-02  |  2KB  |  93 lines

  1. #include <intuition/intuition.h>
  2. #include <devices/console.h>
  3. #include <functions.h>
  4.  
  5. #include "consolefun.h"
  6.  
  7. long OpenConsole(writereq, readreq, window)
  8.     struct IOStdReq *writereq;
  9.     struct IOStdReq *readreq;
  10.     struct Window *window;
  11. {
  12.     long error;
  13.  
  14.     writereq->io_Data = (APTR) window;
  15.     writereq->io_Length = sizeof(struct Window);
  16.     error = OpenDevice("console.device",0,(struct IORequest*)writereq,0);
  17.     readreq->io_Device = writereq->io_Device;
  18.     readreq->io_Unit = writereq->io_Unit;
  19.     return error;
  20. }
  21.  
  22. void CloseConsole(writereq)
  23.     struct IOStdReq *writereq;
  24. {
  25.     CloseDevice((struct IORequest*)writereq);
  26. }
  27.  
  28. /* Output a single character to a specified console */
  29. void ConPutChar(struct IOStdReq *writereq, char character)
  30.     {
  31.     writereq->io_Command = CMD_WRITE;
  32.     writereq->io_Data = (APTR)&character;
  33.     writereq->io_Length = 1;
  34.     DoIO((struct IORequest*)writereq);
  35.     }
  36.  
  37. /* Output a stream of known length to a console */
  38. void ConWrite(struct IOStdReq *writereq, char *string, long length)
  39.     {
  40.     writereq->io_Command = CMD_WRITE;
  41.     writereq->io_Data = (APTR)string;
  42.     writereq->io_Length = length;
  43.     DoIO((struct IORequest*)writereq);
  44.     }
  45.  
  46. /* output a NULL-terminated string of characters to a console */
  47. void ConPuts(struct IOStdReq *writereq, char *string)
  48.     {
  49.     writereq->io_Command = CMD_WRITE;
  50.     writereq->io_Data = (APTR)string;
  51.     writereq->io_Length = -1;    /* this means print till terminator null */
  52.     DoIO((struct IORequest*)writereq);
  53.     }
  54.  
  55.  
  56. /* Queue up a read request to console, passing it pointer
  57.  * to a buffer into which it can read the character
  58.  */
  59. void QueueRead(struct IOStdReq *readreq, char *whereto)
  60.     {
  61.     readreq->io_Command = CMD_READ;
  62.     readreq->io_Data = (APTR)whereto;
  63.     readreq->io_Length = 1;
  64.     SendIO((struct IORequest*)readreq);
  65.     }
  66.  
  67. /* check if a character has been received
  68.  * if none, return -1
  69.  */
  70. long ConMayGetChar(struct MsgPort *msgport, char *whereto)
  71.     {
  72.     register temp;
  73.     struct IOStdReq *readreq;
  74.  
  75.     if(!(readreq = (struct IOStdReq *)GetMsg(msgport))) return -1;
  76.     temp = *whereto;
  77.     QueueRead(readreq, whereto);
  78.     return temp;
  79.     }
  80.  
  81. /* wait for a character */
  82. char ConGetChar(struct MsgPort *msgport, char *whereto)
  83.     {
  84.     register temp;
  85.     struct IOStdReq *readreq;
  86.  
  87.     WaitPort(msgport);
  88.     readreq = (struct IOStdReq *)GetMsg(msgport);
  89.     temp = *whereto;
  90.     QueueRead(readreq, whereto);
  91.     return temp;
  92.     }
  93.