home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / dos / prg / sphinx / examples / tsr / complete.c__ < prev    next >
Encoding:
Text File  |  1994-04-24  |  6.1 KB  |  223 lines

  1. /*
  2.     NAME:  COMPLETE.C--
  3.     SPHINX C-- Example File
  4.     DESCRIPTION:  C-- TSR program to add command line file and directory name
  5.                   completion to DOS.  The hot key is <SCROLL LOCK>.
  6. */
  7.  
  8. ?resize TRUE   // resize program memory
  9. ?assumeDSSS FALSE
  10.  
  11. ?include "WRITE.H--"
  12. ?include "DOS.H--"
  13. ?include "KEYCODES.H--"
  14. ?include "SYSTEM.H--"
  15. ?include "FILE.H--"
  16. ?include "TSR.H--"
  17.  
  18.  
  19. word old_idle_handle[2]={};    /* address holder for old int 0x28 handle */
  20. word oldkeyboardhandle[2]={};  /* address holder for old INT 0x9 handle */
  21.  
  22. ?define DEFAULT_DTA  0x80  // offset address in program segment of DTA
  23.  
  24. byte scrolllockcount = 0;
  25. word oldDTAsegment=0,oldDTAoffset=0;
  26. byte cursorx = 0,cursory = 0;
  27. byte xcount = 0;
  28. byte done = FALSE;
  29. byte displaypage = 0;
  30.  
  31. ?define SEARCHSTRLEN 80
  32. byte search_ext_flag = FALSE;
  33. word skip_count = 0;
  34. byte searchstr[SEARCHSTRLEN] = 0;
  35. word search_attributes = FA_NORMAL + FA_READONLY + FA_HIDDEN + FA_SYSTEM
  36.                          + FA_DIRECTORY + FA_ARCHIVE;
  37. ?define FILENAMELEN 8+4+1
  38. byte foundstr[FILENAMELEN] = 0;
  39.  
  40. ?define INTNUMBER 0x28
  41.  
  42. @ setDTA ();  /* place setDTA procedure here in code, to make sure it is
  43.                  before the TSR cut off point, which is #main +1 */
  44.  
  45.  
  46. interrupt idle_handle ()
  47. /*
  48.     This handle chains onto the INT 0x28 vector.
  49. */
  50. {
  51. $ PUSHA
  52. $ PUSH DS
  53. $ PUSH ES
  54. DS = CS;
  55.  
  56. if( scrolllockcount > 0 )
  57.     {scrolllockcount = 0;
  58.  
  59.     AH = 0xF;
  60.     $ INT 0x10  // get current video mode BH will equal active page
  61.  
  62.     AH = 0x3;
  63.     $ INT 0x10  // get cursor location DH,DL= row,column
  64.     cursorx = DL;
  65.     cursory = DH;    
  66.     displaypage = BH;
  67.  
  68.     xcount = cursorx;
  69.     IF( xcount >= 1 )
  70.         {do {
  71.             xcount--;
  72.             IF( xcount >= 1 )
  73.                 done = TRUE;
  74.             @ GOTOXYZ(byte xcount,byte cursory,byte displaypage);
  75.             AH = 0x8;
  76.             BH = displaypage;
  77.             $INT 0x10  // READ ATTRIBUTES/CHARACTER AT CURSOR POSITION
  78.             IF( AL != ' ' )
  79.                 IF( AL != '<' )
  80.                     IF( AL != '>' )
  81.                         IF( AL != '|' )
  82.                             IF( AL != '\t' )
  83.                                 done = FALSE;
  84.             } while( done == FALSE );
  85.         }
  86.  
  87.     DI = 0;
  88.     xcount++;
  89.     search_ext_flag = FALSE;
  90.     skip_count = 0;
  91.     IF( xcount < cursorx )
  92.         {done = FALSE;
  93.         do {
  94.             skip_count++;
  95.             @ GOTOXYZ(byte xcount,byte cursory,byte displaypage);
  96.  
  97.             AH = 0x8;
  98.             BH = displaypage;
  99.             $INT 0x10  // READ ATTRIBUTES/CHARACTER AT CURSOR POSITION
  100.  
  101.             searchstr[DI] = AL;
  102.             IF( AL == '\\' )
  103.                 {search_ext_flag = FALSE;
  104.                 skip_count = 0;
  105.                 }
  106.             ELSE IF( AL == ':' )
  107.                 {search_ext_flag = FALSE;
  108.                 skip_count = 0;
  109.                 }
  110.             ELSE IF( AL == '.' )
  111.                 search_ext_flag = TRUE;
  112.             DI++;
  113.  
  114.             xcount++;
  115.             } while( xcount < cursorx );
  116.         }
  117.  
  118.     @ GOTOXYZ(byte cursorx,byte cursory,byte displaypage);
  119.  
  120.     if( DI > 0 )
  121.         {IF( search_ext_flag == FALSE )
  122.             {searchstr[DI] = '*';
  123.             DI++;
  124.             searchstr[DI] = '.';
  125.             DI++;
  126.             }
  127.         searchstr[DI] = '*';
  128.         DI++;
  129.         searchstr[DI] = 0;
  130.         @ GETDTA();
  131.         oldDTAoffset = BX;
  132.         oldDTAsegment = ES;
  133.         setDTA(DS,DEFAULT_DTA);
  134.  
  135.         IF( @ FINDFIRSTFILE( , ,search_attributes,#searchstr) == 0 )
  136.             {
  137.             DI = 0;
  138.             do {
  139.                 foundstr[DI] = DSBYTE[DI+DEFAULT_DTA+0x1E];
  140.                 DI++;
  141.                 } while( foundstr[DI-1] != 0 );
  142.  
  143.             AX = @ FINDNEXTFILE();
  144.             IF( AX == 0 )
  145.                 {do {
  146.                      DI = 0;
  147.                      do {
  148.                          BL = TRUE;
  149.                          IF( foundstr[DI] != DSBYTE[DI+DEFAULT_DTA+0x1E] )
  150.                              BL = FALSE;
  151.                          IF( foundstr[DI] == 0 )
  152.                              BL = FALSE;
  153.                          IF( DSBYTE[DI+DEFAULT_DTA+0x1E] == 0 )
  154.                              BL = FALSE;
  155.                          DI++;
  156.                          } while( BL == TRUE );
  157.                      DI--;
  158.                      foundstr[DI] = 0;
  159.                      } while( @ FINDNEXTFILE() == 0 );
  160.                 } 
  161.  
  162.             SI = 0;
  163.             do {
  164.                 IF( SI >= skip_count )
  165.                     @ BIOSPUSHKEY( foundstr[SI] );
  166.                 SI++;
  167.                 } while( foundstr[SI] != 0 );
  168.             }
  169.         ELSE @BEEP();
  170.         setDTA(oldDTAoffset,oldDTAoffset);
  171.         }
  172.     ELSE @BEEP();
  173.     }
  174.  
  175. $ POP ES
  176. $ POP DS
  177. $ POPA
  178. $ CS:
  179. $ JMP FAR old_idle_handle;   /* chain to old interrupt handle */
  180. }
  181.  
  182.  
  183. interrupt keyboardhandle ()   
  184. /* this is called every time a key is pressed or released */
  185. {
  186. $ PUSH AX
  187.  
  188. $ IN AL,KEYBOARD_PORT 
  189. IF( AL == s_scrolllock )
  190.     {CSBYTE[#scrolllockcount]++;
  191.     @ EATKEY();      
  192.     @ EOI();  
  193.     $ POP AX
  194.     return();
  195.     }
  196.  
  197. $ POP AX
  198.  
  199. $ CS:
  200. $ JMP FAR oldkeyboardhandle;   /* chain to old interrupt handle */
  201. }
  202.  
  203.  
  204. void main ()
  205. {GETINTVECT(#old_idle_handle,INTNUMBER); /* get old keyboard interrupt handle */
  206. SETINTVECT( ,INTNUMBER,CS,#idle_handle); /* attach to keyboard interrupt */
  207. GETINTVECT(#oldkeyboardhandle,0x9);    /* get old keyboard interrupt handle */
  208. SETINTVECT( ,0x9,CS,#keyboardhandle);  /* attach to keyboard interrupt */
  209.  
  210. WRITESTR("\nCOMPLETE.COM  ---  Version 1.1\n");
  211. WRITESTR("The DOS command line filename completion INSTALLED.\n\n");
  212. WRITESTR("Created By SPHINX Programming 1994.\n");
  213. WRITESTR("COMPLETE.COM was compiled with ");
  214. WRITESTR(__COMPILER__);
  215. WRITESTR(".\n\n");
  216. WRITESTR("Press <SCROLL LOCK> at the command line prompt to complete a partially\n");
  217. WRITESTR("entered file or directory name.  A beep will sound if no match is found,\n");
  218. WRITESTR("otherwise the first match will be supplied.\n");
  219.  
  220. @ KEEP( , , ,#main+1);   /* TSR, memory saved up to start of main() */
  221. }
  222.  
  223. /* end of COMPLETE.C-- */