home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / telecomm / busybud.lzh / busybud.c < prev    next >
C/C++ Source or Header  |  1987-04-22  |  9KB  |  327 lines

  1.  
  2. /******************************/
  3. /* Busy Buddy accessory       */
  4. /* Copyright 1988 by ST-Log   */
  5. /* Rat*Ware by                */
  6. /* Matthew J. W. Ratcliff     */
  7. /* AKA Mat*Rat, All Rights    */
  8. /* Reserved.                  */
  9. /******************************/
  10.  
  11. /**********************/
  12. /* EXTERNALS          */
  13. /**********************/
  14.  
  15. extern int gl_apid;
  16.  
  17.  
  18. /*****************/
  19. /* Include files */
  20. /*****************/
  21.  
  22. #include <stdio.h>
  23. #include <osbind.h>
  24.  
  25. /********************/
  26. /* Global variables */
  27. /********************/
  28.  
  29. char Back_Type[]=
  30. "[2][ Busy Buddy by Mat*Rat| | Backspace select, ASCII? ][ 8| 126| 127]";
  31.  
  32. char Buzzoff[]=
  33.  "[1][ | Busy Buddy is now OFF | ][ OK ]";
  34.  
  35. char Busy_Time[]=
  36. "[2][ Busy Buddy Maximum | Time Limit? | | Minutes ][  5 | 15 | 60 ]";
  37.  
  38. char Busy_Tout[]=
  39. "[2][ Busy Buddy TIMEOUT | | Shall I ? ][ Exit | Restart ]";
  40.  
  41. char Buddy_Byte, Backup;
  42. int Time_Limit;
  43.  
  44. /*************/
  45. /* Constants */
  46. /*************/
  47.  
  48. #define EVNT_MSG        0x0010
  49. #define EVNT_TIM        0x0020
  50. #define TIME_H        (int)0
  51. #define TIME_L        (int)2000
  52. #define AC_OPEN         40      /* Startup accessory cmd*/
  53. #define ASCII_8         1
  54. #define ASCII_126       2
  55. #define ASCII_127       3
  56. #define BS              8       /* Backspace character  */
  57. #define XE_DEL         126      /* Delete character-XE  */
  58. #define ST_DEL         127      /* Delete char-ST       */
  59. #define SPACE           32      /* Space character      */
  60. #define PRT             0       /* Standard IO devices  */
  61. #define AUX             1
  62. #define CON             2
  63. #define MIDI            3
  64. #define KBD             4
  65. #define FIVE_MIN        (int)150
  66. #define FIFTEEN_MIN     (int)450
  67. #define SIXTY_MIN       (int)1800
  68. #define SEL_FIVE        1
  69. #define SEL_FIFTEEN     2
  70. #define SEL_SIXTY       3
  71. #define BELL            7
  72.  
  73.  
  74. /********************************************************/
  75. /* Program: Busy Buddy                                  */
  76. /* Type:    Desk accessory                              */
  77. /* Purpose: Busy Buddy, when activated, initiates       */
  78. /* a   2 second timed interval for sending alternating  */
  79. /* space and backspace characters over the modem.       */
  80. /* This feature will keep the system at the other       */
  81. /* end BUSY. This will prevent most BBS and             */
  82. /* telecommunication systems from TIMING OUT            */
  83. /* on you, so you have time for a Budweiser break.      */
  84. /********************************************************/
  85.  
  86. main()
  87.  
  88. { /* Get busy BUDDY! */
  89.  
  90. int menu_id;
  91. int mgin[8];
  92. int dum,event,flag;
  93. int forever;
  94.  
  95. /**********************/
  96. /* Install accessory: */
  97. /**********************/
  98.  
  99. appl_init();
  100. menu_id = menu_register(gl_apid,"  Busy Buddy");
  101.  
  102. /******************************************************/
  103. /* Event message only, until activated the first time */
  104. /******************************************************/
  105.  
  106. flag    = EVNT_MSG;
  107. forever = 1;
  108.  
  109. while (forever)
  110.   { /* loop forever */
  111.  
  112.   dum   = 0;
  113.   event = evnt_multi( flag, -1, -1, -1,
  114.                       dum, dum, dum, dum, dum, /* de-daaa */
  115.                       dum, dum, dum, dum, dum, /* de-dooo */
  116.                       mgin, TIME_L, TIME_H,
  117.                       &dum, &dum, &dum, &dum, &dum, &dum);
  118.   if (event & EVNT_MSG)
  119.     if (mgin[0] == AC_OPEN && mgin[4] == menu_id)
  120.           if (flag & EVNT_TIM)
  121.             {
  122.             flag = EVNT_MSG;
  123.             Buddy_Off();
  124.             event = 0;
  125.             }
  126.           else
  127.             {
  128.             flag = EVNT_TIM | EVNT_MSG;
  129.             Buddy_On();
  130.             event = 0;
  131.             }
  132.  
  133.   if (event & EVNT_TIM)
  134.     if (flag & EVNT_TIM)
  135.       {
  136.       Buddy();
  137.       if (Time_Limit <= 0)
  138.         flag = Buddy_Toff();
  139.       }
  140.  
  141.  
  142.   } /* end loop forever */
  143.  
  144. } /* end main() */
  145.  
  146. /*************************************************************/
  147. /* Function:    Buddy_On()                                   */
  148. /* Description: Initialize Busy Buddy. Allow user to select  */
  149. /* backspace or delete type of backup. Initialize Backup     */
  150. /* variable and send first SPACE character to begin process. */
  151. /*************************************************************/
  152.  
  153. Buddy_On()
  154.  
  155. { /* begin Buddy_On() */
  156.  
  157. int bsel;
  158.  
  159. bsel = form_alert(1, Back_Type);        /* Get backspace or delete type */
  160.  
  161. switch (bsel)
  162.   { /* begin switch */
  163.   case (ASCII_8):
  164.     Backup = BS;
  165.     break;
  166.  
  167.   case (ASCII_126):
  168.     Backup = XE_DEL;
  169.     break;
  170.  
  171.   case (ASCII_127):
  172.     Backup = ST_DEL;
  173.     break;
  174.  
  175.   default:
  176.     break;
  177.  
  178.   } /* end switch */
  179.  
  180. Get_Limit();                            /* Set time limit               */
  181. Send_Byte( SPACE );                     /* Start the busy signal        */
  182. Buddy_Byte = Backup;                    /* setup for backspace next time*/
  183.  
  184. } /* end Buddy_On() */
  185.  
  186.  
  187.  
  188. /*************************************************************/
  189. /* Function:    Buddy_Off()                                  */
  190. /* Description: Make certain that a backup character was the */
  191. /* last thing sent (spaces must be matched with backups),    */
  192. /* then inform the user that Busy Buddy is dormant.          */
  193. /*************************************************************/
  194.  
  195. Buddy_Off ()
  196.  
  197. { /* begin Buddy_Off() */
  198.  
  199. if (Buddy_Byte == Backup)               /* Make certain that backup was */
  200.   Send_Byte( Buddy_Byte );              /* last character sent          */
  201.  
  202. form_alert(1, Buzzoff );                /* Tell user busy is off now    */
  203.  
  204. } /* end Buddy_Off() */
  205.  
  206.  
  207. /*************************************************************/
  208. /* Function:    Buddy()                                      */
  209. /* Description: Send the current character from Buddy_Byte.  */
  210. /* Then toggle from SPACE to BACKUP, or BACKUP to SPACE for  */
  211. /* next 2 second interrupt.                                  */
  212. /*************************************************************/
  213.  
  214. Buddy()
  215.  
  216. { /* begin Buddy() */
  217.  
  218. Send_Byte( Buddy_Byte );                /* Send current space or backup */
  219.  
  220. if (Buddy_Byte == SPACE)                /* If space just sent, backup   */
  221.   Buddy_Byte = Backup;                  /* next time.                   */
  222. else
  223.   Buddy_Byte = SPACE;                   /* If backup just sent, then    */
  224.                                         /* send space next time.        */
  225. Time_Limit--;
  226.  
  227. } /* end Buddy() */
  228.  
  229.  
  230. /*************************************************************/
  231. /* Function:    Send_Byte( char )                            */
  232. /* Description: Send the character received to the AUX, RS232*/
  233. /* port, using the Bconout function.                         */
  234. /*************************************************************/
  235.  
  236. Send_Byte( dude )
  237. char dude;
  238.  
  239. { /* begin Send_Byte( char ) */
  240.  
  241. /***************************************************/
  242. /* Send the caracter passed to the AUX, RS232 Port */
  243. /***************************************************/
  244.  
  245. Bconout ( AUX, dude );
  246.  
  247. } /* end Send_Byte( char ) */
  248.  
  249.  
  250.  
  251. /*************************************************************/
  252. /* Function:    Buddy_Toff()    returns ( INT )              */
  253. /* Description: Make certain that a backup character was the */
  254. /* last thing sent (spaces must be matched with backups),    */
  255. /* then inform the user that Busy Buddy is timed out.        */
  256. /* Return flag status for next event multi.                  */
  257. /*************************************************************/
  258.  
  259. Buddy_Toff ()
  260.  
  261. { /* begin Buddy_Toff() */
  262.  
  263. #define BEXIT     1
  264. #define BRESTART  2
  265.  
  266. int sel, bflag;
  267.  
  268. if (Buddy_Byte == Backup)               /* Make certain that backup was */
  269.   Send_Byte( Buddy_Byte );              /* last character sent          */
  270.  
  271. Bconout( CON, BELL);                    /* WAKE UP CALL!                */
  272.  
  273. sel = form_alert(1, Busy_Tout );        /* Tell user busy timed out     */
  274.  
  275. if (sel == BEXIT)
  276.   {
  277.   bflag = EVNT_MSG;
  278.   form_alert(1, Buzzoff);
  279.   }
  280. else
  281.   {
  282.   bflag = EVNT_MSG | EVNT_TIM;
  283.   Get_Limit();
  284.   }
  285.  
  286. return ( bflag );
  287.  
  288.  
  289. } /* end Buddy_Toff() */
  290.  
  291.  
  292. /*************************************************************/
  293. /* Function:    Get_Limit()                                  */
  294. /* Description: Get maximum time limit for Busy Buddy to run */
  295. /* unattended.                                               */
  296. /*************************************************************/
  297.  
  298. Get_Limit()
  299.  
  300. { /* begin Get_Limit */
  301.  
  302. int bsel;
  303.  
  304. bsel = form_alert (3, Busy_Time );
  305.  
  306. switch ( bsel )
  307.   { /* begin switch */
  308.   case (SEL_FIVE):
  309.     Time_Limit = FIVE_MIN;
  310.     break;
  311.  
  312.   case (SEL_FIFTEEN):
  313.     Time_Limit = FIFTEEN_MIN;
  314.     break;
  315.  
  316.   case (SEL_SIXTY):
  317.     Time_Limit = SIXTY_MIN;
  318.     break;
  319.  
  320.   default:
  321.     break;
  322.   } /* end switch */
  323.  
  324. } /* end Get_Limit */
  325.  
  326.  
  327.