home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / Amiga_Mail_Vol2 / Archives / Plain / mj91 / ASL / FileHook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-12  |  3.9 KB  |  129 lines

  1. ;/* filehook.c - Execute me to compile me with Lattice 5.10
  2. LC -b1 -cfistq -v -y -j73 filehook.c
  3. Blink FROM LIB:c.o,filehook.o TO filehook LIBRARY LIB:LC.lib,LIB:Amiga.lib
  4. quit
  5. */
  6.  
  7. /*(c)  Copyright 1991 Commodore-Amiga, Inc.   All rights reserved.
  8. The information contained herein is subject to change without notice,
  9. and is provided "as is" without warranty of any kind, either expressed
  10. or implied.  The entire risk as to the use of this information is
  11. assumed by the user.
  12. */
  13.  
  14.  
  15. #include <clib/asl_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/dos_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/alib_stdio_protos.h>
  20. #include <dos/dosasl.h>
  21. #include <intuition/intuition.h>
  22. #include <exec/libraries.h>
  23.  
  24. #ifdef LATTICE
  25. int CXBRK(void) { return(0); }  /* Disable Lattice CTRL/C handling */
  26. int chkabort(void) { return(0); }  /* really */
  27. #endif
  28.  
  29. #define DESTPATLENGTH 20
  30.  
  31. UBYTE *vers = "\0$VER: filehook 1.0";
  32.  
  33. void main(void);
  34.  
  35. struct Library *AslBase;
  36. struct IntuitionBase *IntuitionBase;
  37. struct Window *window;
  38.  
  39. CPTR HookFunc();
  40.  
  41. /* this is the pattern matching string that the hook function uses */
  42. UBYTE *sourcepattern = "(#?.info)";
  43. UBYTE pat[DESTPATLENGTH];
  44.  
  45.  
  46. void main()
  47. {
  48.  
  49.     struct FileRequester *fr;
  50.  
  51.     /* This is a dos.library function that turns a pattern matching
  52.     ** string into something the DOS pattern matching functions
  53.     ** can understand.
  54.     */
  55.     ParsePattern(sourcepattern, pat, DESTPATLENGTH);
  56.  
  57.     if (AslBase = OpenLibrary("asl.library", 36L))
  58.     {
  59.         if (IntuitionBase = (struct IntuitionBase *)
  60.                     OpenLibrary("intuition.library", 36L))
  61.         {
  62.             /* open a window that gets ACTIVEWINDOW events */
  63.             if (window = (struct Window *)OpenWindowTags(NULL, 
  64.                     WA_Title, "ASL Hook Function Example", 
  65.                     WA_IDCMP, IDCMP_ACTIVEWINDOW,
  66.                     WA_Flags, WINDOWDEPTH,
  67.                     TAG_END))
  68.             {
  69.                 if (fr = AllocFileRequest())
  70.                 {
  71.                     /* application body here... */
  72.                     
  73.                     
  74.                     if (AslRequestTags(fr, 
  75.                         ASL_Window, window,
  76.                         ASL_TopEdge, 0L,
  77.                         ASL_Height, 200L,
  78.                         ASL_Hail, (ULONG)"Pick an icon to save",
  79.                         ASL_HookFunc, (ULONG)HookFunc,
  80.                         ASL_FuncFlags, FILF_DOWILDFUNC | FILF_DOMSGFUNC | FILF_SAVE,
  81.                         ASL_OKText, (ULONG)"Save",
  82.                         TAG_DONE))
  83.                     {
  84.                         printf("You picked %s%s\n", fr->rf_Dir, fr->rf_File);
  85.                     }
  86.                     
  87.                     /* more application body here */
  88.                     
  89.                     FreeFileRequest(fr);
  90.                 }
  91.                 CloseWindow(window);
  92.             }
  93.             CloseLibrary(IntuitionBase);
  94.         }
  95.         CloseLibrary(AslBase);
  96.     }
  97. }
  98.  
  99.  
  100. CPTR HookFunc(LONG type, CPTR obj, struct FileRequester *fr)
  101. {
  102.     static BOOL returnvalue;
  103.     switch(type)
  104.     {
  105.         case FILF_DOMSGFUNC:
  106.         /* We got a message meant for the window */
  107.             printf("You activated the window\n");
  108.             return(obj);
  109.             break;
  110.         case FILF_DOWILDFUNC:
  111.         /* We got an AnchorPath structure, should
  112.         ** the requester display this file? */
  113.         
  114.             /* MatchPattern() is a dos.library function that 
  115.             ** compares a matching pattern (parsed by the
  116.             ** ParsePattern() DOS function) to a string and
  117.             ** returns true if they match. */
  118.             returnvalue = MatchPattern(pat, 
  119.                     ((struct AnchorPath *)obj)->ap_Info.fib_FileName);
  120.             
  121.             /* we have to negate MatchPattern()'s return value 
  122.             ** because the file requester expects a zero for 
  123.             ** a match not a TRUE value */
  124.             return( (CPTR)(! returnvalue) );
  125.             break;
  126.     }
  127. }
  128.  
  129.