home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / filehook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  3.8 KB  |  118 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. ** The following example illustrates the use of a hook function for
  7. ** both _DOWILDFUNC and _DOMSGFUNC.
  8. **
  9. */
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <dos/dosasl.h>
  13. #include <libraries/asl.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17. #include <clib/asl_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <stdio.h>
  20.  
  21. #ifdef LATTICE
  22. int CXBRK(void)     { return(0); }  /* Disable Lattice CTRL/C handling */
  23. void chkabort(void) { return; }     /* really */
  24. #endif
  25.  
  26. #define DESTPATLENGTH 20
  27.  
  28. UBYTE *vers = "$VER: filehook 37.0";
  29.  
  30. CPTR HookFunc();
  31.  
  32. struct Library *AslBase = NULL;
  33. struct Library *IntuitionBase = NULL;
  34. struct Window  *window = NULL;
  35.  
  36. /* this is the pattern matching string that the hook function uses */
  37. UBYTE *sourcepattern = "(#?.info)";
  38. UBYTE pat[DESTPATLENGTH];
  39.  
  40. void main(int argc, char **argv)
  41. {
  42.     struct FileRequester *fr;
  43.  
  44.     if (AslBase = OpenLibrary("asl.library", 37L))
  45.     {
  46.         if (IntuitionBase = (struct IntuitionBase *)
  47.                     OpenLibrary("intuition.library", 37L))
  48.         {
  49.             /* This is a V37 dos.library function that turns a pattern matching
  50.             ** string into something the DOS pattern matching functions can
  51.             ** understand.
  52.             */
  53.             ParsePattern(sourcepattern, pat, DESTPATLENGTH);
  54.  
  55.             /* open a window that gets ACTIVEWINDOW events */
  56.             if (window = (struct Window *)OpenWindowTags(NULL,
  57.                     WA_Title, "ASL Hook Function Example",
  58.                     WA_IDCMP, IDCMP_ACTIVEWINDOW,
  59.                     WA_Flags, WFLG_DEPTHGADGET,
  60.                     TAG_END))
  61.             {
  62.                 if (fr = AllocFileRequest())
  63.                 {
  64.                     if (AslRequestTags(fr,
  65.                         ASL_Dir, (ULONG)"SYS:Utilities",
  66.                         ASL_Window, window,
  67.                         ASL_TopEdge, 0L,
  68.                         ASL_Height, 200L,
  69.                         ASL_Hail, (ULONG)"Pick an icon, select save",
  70.                         ASL_HookFunc, (ULONG)HookFunc,
  71.                         ASL_FuncFlags, FILF_DOWILDFUNC | FILF_DOMSGFUNC | FILF_SAVE,
  72.                         ASL_OKText, (ULONG)"Save",
  73.                         TAG_DONE))
  74.                     {
  75.                         printf("PATH=%s FILE=%s\n", fr->rf_Dir, fr->rf_File);
  76.                         printf("To combine the path and filename, copy the path\n");
  77.                         printf("to a buffer, add the filename with Dos AddPart().\n");
  78.                     }
  79.                     FreeFileRequest(fr);
  80.                 }
  81.                 CloseWindow(window);
  82.             }
  83.             CloseLibrary(IntuitionBase);
  84.         }
  85.         CloseLibrary(AslBase);
  86.     }
  87. }
  88.  
  89.  
  90. CPTR HookFunc(LONG type, CPTR obj, struct FileRequester *fr)
  91. {
  92.     static BOOL returnvalue;
  93.     switch(type)
  94.     {
  95.         case FILF_DOMSGFUNC:
  96.         /* We got a message meant for the window */
  97.             printf("You activated the window\n");
  98.             return(obj);
  99.             break;
  100.         case FILF_DOWILDFUNC:
  101.         /* We got an AnchorPath structure, should
  102.         ** the requester display this file? */
  103.  
  104.             /* MatchPattern() is a dos.library function that
  105.             ** compares a matching pattern (parsed by the
  106.             ** ParsePattern() DOS function) to a string and
  107.             ** returns true if they match. */
  108.             returnvalue = MatchPattern(pat,
  109.                     ((struct AnchorPath *)obj)->ap_Info.fib_FileName);
  110.  
  111.             /* we have to negate MatchPattern()'s return value
  112.             ** because the file requester expects a zero for
  113.             ** a match not a TRUE value */
  114.             return( (CPTR)(! returnvalue) );
  115.             break;
  116.     }
  117. }
  118.