home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 13 / 13.iso / s / s001 / 1.ddi / TS / SRC / ONSHIFT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-08  |  2.0 KB  |  85 lines

  1.                 /******************************************
  2.            *            ONSHIFT.C             *
  3.                * Copyright TimeSlice, Inc. 1985, 86, 87. *
  4.                ******************************************/
  5.  
  6. #include <ts.h>
  7.  
  8. SHIFT *_shfrnt;             /*head of shift structs list*/
  9.  
  10. extern void kbd_isr();
  11.  
  12. /***
  13. * ONSHIFT( STATUS, FUNCPTR )
  14. * This function attaches an isr to interrupt # 9. The isr executes a user
  15. * function if the keyboard shift status is equal to a trigger value (hot key).
  16. * It returns a pointer to the SHIFT structure allocated for that shift. This
  17. * is the pointer that should be passed to rmvshift.
  18. ***/
  19. SHIFT *onshift( status , func )
  20. int  status ;            /* hot key value */
  21. void (*func)() ;            /* user function to execute if hot key pressed */
  22. {
  23.   SHIFT    *sp;
  24.   char *malloc();
  25.   int cpuflags;
  26.   static installed;
  27.  
  28.   critstart( DOS_CRCLASS );
  29.  
  30.   /*if called for the first time, install kbd_isr*/
  31.   if( !installed ) {
  32.     intatt( 0x09, 0x300, kbd_isr, REPLACE ) ;
  33.     installed = 1;
  34.   }
  35.  
  36.   /*search for existing SHIFT with same status*/
  37.   for( sp = _shfrnt ; sp && sp->status!=status ; sp = sp->nxt );
  38.  
  39.   /*if not found, allocate a new SHIFT and put it in front of _shfrnt list*/
  40.   if( !sp ) {
  41. #if defined(TURBOC)
  42.     sp = (SHIFT *)_ts_malloc( sizeof( SHIFT ) );
  43. #else
  44.     sp = (SHIFT *)malloc( sizeof( SHIFT ) );
  45. #endif
  46.     cpuflags = cli();
  47.     sp->nxt = _shfrnt;
  48.     _shfrnt = sp;
  49.     putf( cpuflags );
  50.     sp->status = status;
  51.   }
  52.   sp->infunc = 0;            /*always reset when onkey called*/
  53.   sp->func = func;
  54.   critend( DOS_CRCLASS );
  55.  
  56.   return sp;
  57. }
  58.  
  59.  
  60. /***
  61. * RMVSHIFT( SP )
  62. * Remove SHIFT structure *SP from SHIFT list.
  63. ***/
  64. void rmvshift( sp )
  65. SHIFT *sp;
  66. {
  67.   SHIFT *sp2;
  68.   int cpuflags;
  69.  
  70.   cpuflags = cli();
  71.   for( sp2 = (SHIFT *)&_shfrnt ; sp2->nxt ; sp2 = sp2->nxt )
  72.     if( sp2->nxt == sp ) {
  73.       sp2->nxt = sp->nxt;
  74.       critstart( DOS_CRCLASS );
  75. #if defined(TURBOC)
  76.       _ts_free( sp );
  77. #else
  78.       free( sp );
  79. #endif
  80.       critend( DOS_CRCLASS );
  81.       break;
  82.     }
  83.   putf( cpuflags );
  84. }
  85.