home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / modem / byepc300.arc / BYECHAT.ARC / CHAT.C < prev    next >
Text File  |  1987-10-24  |  4KB  |  201 lines

  1. /*
  2. **  Program:        <chat.c>
  3. **
  4. **  Purpose:        CHAT program for BYE-PC
  5. **
  6. **  Author:        R.E. Starr, Jr.
  7. **
  8. **  Requirements:   <byexface.obj>
  9. */
  10.  
  11. #include    <stdio.h>
  12. #include    <stdlib.h>
  13. #include    <conio.h>
  14. #include    <process.h>
  15. #include    <ctype.h>
  16. #include    <string.h>
  17. #include    "byexface.h"
  18.  
  19. void wink();
  20. void chat_loop();
  21. int alert_sysop();
  22.  
  23. #define ON  1
  24. #define OFF 0
  25.  
  26. #define BYE_VER 3    /* minimum version# required */
  27. #define BYE_REV 0    /* minimum revision# required */
  28.  
  29. #define VER 1        /* chat version# */
  30. #define REV 1        /* chat revision# */
  31.  
  32. #define ESC    27    /* escape */
  33. #define CTRL_X    24    /* ctrl_x */
  34. #define K_HOME    71    /* home key */
  35. #define K_END    79    /* end key */
  36.  
  37.  
  38. main(argc, argv)
  39.  
  40.  int argc;
  41.  char *argv[];
  42.     {
  43.     int rtn;
  44.  
  45.     if (rtn = _bye_check(BYE_VER, BYE_REV))
  46.     {
  47.     printf("\nERROR: BYE-PC ");
  48.     switch(rtn)
  49.         {
  50.         case 1:
  51.         printf("is not loaded!\n");
  52.         break;
  53.         case 2:
  54.         printf("loaded is the wrong Version!\n");
  55.         break;
  56.         case 3:
  57.         printf("loaded is the wrong Revision!\n");
  58.         break;
  59.         default:
  60.         printf("returned invalid error code!\n");
  61.         break;
  62.         }
  63.     exit(1);
  64.     }
  65.     _bye_rxflush();        /* reset the rx queue  */
  66.     printf("\nCHAT Version %1d.%-2.2d for BYE-PC\n", VER, REV);
  67.     printf("[Use CTRL-X to Exit]\n\n");
  68.  
  69.     if (strcmpi("-S", argv[1]))
  70.     if (!alert_sysop())
  71.         goto end;
  72.     chat_loop();
  73.     printf("\n[CHAT End]\n\n");
  74.  
  75.  end:
  76.     _bye_rxflush();        /* reset the receive queue */
  77.     exit(0);
  78.     }
  79.  
  80.  
  81. /*
  82. **  Function:    void chat_loop()
  83. **
  84. **  Paramters:    void
  85. **
  86. **  Purpose:    Keyboard char loop that echos chars to remote.
  87. **
  88. **  Return:    void
  89. */
  90.  
  91. void chat_loop()
  92.  {
  93.  int c;
  94.  
  95.  while(1)
  96.     {
  97.     if ((c = getch()) == NULL)        /* scan code key? */
  98.     c = getch();            /* get scan code  */
  99.     switch(c)
  100.     {
  101.     case ESC:
  102.     case CTRL_X:        /* exit from chat keys */
  103.         return;
  104.     case '\r':        /* do a cr/lf */
  105.         printf("\n");
  106.         break;
  107.     case '\b':        /* do a backspace */
  108.         printf("\b \b");
  109.         break;
  110.     default:        /* print the character */
  111.         printf("%c", (char)c);
  112.     }
  113.     }
  114.  }
  115.  
  116.  
  117. /*
  118. **  Function:    void alert_sysop()
  119. **
  120. **  Paramters:    void
  121. **
  122. **  Purpose:    Rings the bell on local console to signal sys op.
  123. **
  124. **  Return:    1 = Sys/op on line
  125. **        0 = No answer from sys/op
  126. */
  127.  
  128. int alert_sysop()
  129.  {
  130.  char name[65];
  131.  int c, i, d, r;
  132.  
  133.  _bye_getname(name);
  134.  printf("Operator page from %s: ", name);
  135.  wink();
  136.  for (i=0; i < 10; i++)
  137.     {
  138.     printf("\a");            /* ring the bell */
  139.     for (d = 0; d < 4096; d++)
  140.     {
  141.     if (!r)
  142.         wink();
  143.     if (++r >= 64)            /* rotation rate */
  144.         r = 0;
  145.     if (kbhit())            /* any keys pressed? */
  146.         {
  147.         if ((c = getch()) == NULL)        /* scan code key? */
  148.         c = getch();            /* get scan code  */
  149.         switch(c)
  150.         {
  151.         case K_END:
  152.         case K_HOME:
  153.             printf(".\n\n[Sys/Op on Line]: ");
  154.             return(1);
  155.         case CTRL_X:
  156.             printf(".\n\n[CHAT Cancelled]\n");
  157.             return(0);
  158.         }
  159.         }
  160.     }
  161.     printf(".");
  162.     }
  163.  printf("\n\nSorry, No Answer...\n");
  164.  return(0);
  165.  }
  166.  
  167.  
  168. /*
  169. **  Function:    void wink()
  170. **
  171. **  Paramters:    void
  172. **
  173. **  Purpose:    Simulates a rotating cursor.
  174. **
  175. **  Return:    void
  176. */
  177.  
  178. void wink()
  179.  {
  180.  static int state = 0;
  181.  
  182.  switch(state)
  183.     {
  184.     case 0:
  185.     printf("|");
  186.     break;
  187.     case 1:
  188.     printf("/");
  189.     break;
  190.     case 2:
  191.     printf("-");
  192.     break;
  193.     default:
  194.     state = 0;
  195.     printf("\\");
  196.     }
  197.  state++;
  198.  printf("\b");
  199.  }
  200.  
  201.