home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 562.lha / EZQ / EZQ.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-25  |  4.7 KB  |  152 lines

  1. /* EZQ.c    v1.0ß © 1991 Arnie Cachelin
  2.    Run DOS operations on files dropped onto Workbench 2.0 App Icon.
  3.    DOS commands specified in the EZQ icon's ToolTypes will be filled
  4.    with the path and name of incoming icons replacing alternate '%s's
  5.    then Execute()'d.  (Sorry, no console I/O provided)  */
  6. /* 24 Sep 1991 At 22:21:11 */
  7.  
  8. #include <intuition/intuition.h>
  9. #include <proto/intuition.h>
  10. #include <proto/exec.h>
  11. #include <proto/dos.h>
  12. #include <workbench/startup.h>
  13. #include <workbench/workbench.h>
  14. #include <proto/wb.h>
  15. #include <workbench/icon.h>
  16. #include <proto/icon.h>
  17. #define YES_ANSWER    "  YES  "
  18. #define NO_ANSWER     "  NO  "
  19. #include "AskUser.h"  /* The YES_ANSWER defines override 'Continue','cancel' */
  20. #include "EZQIcon.h"  /*  Output from my 'Icon' utility works nicely here!  */
  21. #define DIRLEN 34
  22. #define VERSION  "EZQ v1.0 © 1991 Arnie Cachelin"
  23. #define INTUITIONNAME    "intuition.library"
  24. #define WORKBENCHNAME    "workbench.library"
  25. #define ICONNAME    "icon.library"
  26.  
  27. struct IntuitionBase *IntuitionBase = NULL;
  28. struct WorkbenchBase *WorkbenchBase = NULL;
  29. struct Library *IconBase = NULL;
  30. struct Library *OpenLibrary();
  31. struct MsgPort *CreatePort();
  32. struct Message *GetMsg();
  33. struct AppIcon *AddAppIcon();
  34. struct MsgPort *msgport = NULL;
  35. struct AppIcon *ai = NULL;
  36. struct IntuiMessage *imsg;
  37. struct AppMessage *amsg;
  38. struct DiskObject *dob=NULL;
  39. int imagememsize = 0;
  40. extern struct   WBStartup     *WBenchMsg;
  41.  
  42. #ifdef BLAB
  43. void ShowMsg(char *title,struct AppMessage *amsg)
  44. {
  45.     struct WBArg *argptr;
  46.   int i,n;
  47.   char dirname[DIRLEN+1];
  48.  
  49.     argptr = amsg->am_ArgList;
  50.   printf("%s: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n",title, amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  51.   for (i=0; i<amsg->am_NumArgs; i++)
  52.   {
  53.    if(argptr->wa_Lock)  /* AppIcons have wa_Lock=0... get "SYS:" as dir */
  54.      if (NameFromLock(argptr->wa_Lock,dirname,DIRLEN))
  55.       if( (n=strlen(dirname)) && ((char)dirname[n-1]!=':') ) strcat(dirname,"/");
  56.          printf("\targ(%ld): Name='%s%s', Lock=%lx\n",i, dirname,argptr->wa_Name, argptr->wa_Lock);
  57.     strcpy(dirname,"");
  58.       argptr++;
  59.     }
  60. }
  61. #endif
  62.  
  63. void Terminate(char *text)
  64. {
  65.   if (ai) RemoveAppIcon(ai);
  66.     if (msgport) DeletePort(msgport);
  67.   if(IconBase) CloseLibrary(IconBase);
  68.   if(WorkbenchBase) CloseLibrary(IntuitionBase);
  69.   if(IntuitionBase) CloseLibrary(IntuitionBase);
  70. #ifdef BLAB
  71.   printf("Terminating: %s\n",text);
  72. #endif
  73.   exit(0L);
  74. }
  75.  
  76. void Initialize(char *text)
  77. {
  78.   ULONG userdata = 0,id = 1;
  79.  
  80. #ifdef BLAB
  81.   printf("Initializing: %s\n",text);
  82. #endif
  83.   if (!(IntuitionBase = OpenLibrary(INTUITIONNAME, 0)))
  84.     Terminate("Could not open intuition\n");
  85.     if (!(WorkbenchBase = OpenLibrary(WORKBENCHNAME, 36)))
  86.     Terminate("Could not open workbench\n");
  87.   if (!(IconBase = OpenLibrary(ICONNAME, 36)))
  88.     Terminate("Could not open icon library\n");
  89.     if (!(msgport = CreatePort("appwindow", 0)))
  90.     Terminate("Could not createport\n");
  91.     if (!(ai = AddAppIcon(id, userdata, text, msgport, NULL, &DOB, NULL)))
  92.         Terminate("Could not addappicon()\n"); /* It would be even easier to just use the prog. icon 'dob'  */
  93. }                          /*  But that could get confusing, with identical icons floatin around  */
  94.  
  95. #define MESLEN 15
  96. main(argc, argv)
  97. int argc;
  98. char **argv;
  99. {
  100.     struct Message *GetMsg();
  101.      char dir[DIRLEN+1]="",Command[255],*file;
  102.   struct WBArg *argptr;
  103.   int i,n,t;
  104.     BOOL done = FALSE;
  105.   ULONG Sigs;
  106.   char MesText[MESLEN+2*DIRLEN]="Really Quit ",ProgName[2*DIRLEN];
  107.  
  108.   if(argc) strcpy(ProgName,argv[0]);
  109.   else strcpy(ProgName,WBenchMsg->sm_ArgList->wa_Name);
  110.   strncat(MesText,ProgName,2*DIRLEN);
  111.   Initialize(ProgName);
  112.   Sigs= (1 << msgport->mp_SigBit);
  113.   if((dob = (struct  DiskObject *)GetDiskObject(ProgName) ))
  114.   {
  115.       do
  116.     {
  117.       Wait(Sigs);
  118.       while (amsg =(struct AppMessage *) GetMsg(msgport))
  119.       {
  120. #ifdef BLAB
  121.         ShowMsg("APP ",amsg);
  122. #endif
  123.         if (amsg->am_NumArgs==0)  /* Just a double-click  */
  124.         {
  125.           ReplyMsg((struct Message *)amsg);
  126.           done = AskUser(NULL,MesText);
  127.         }
  128.         else
  129.         {
  130.           argptr = amsg->am_ArgList;
  131.           for (i=0; i<amsg->am_NumArgs; i++,argptr++)
  132.             if(argptr->wa_Lock)
  133.             {
  134.               NameFromLock(argptr->wa_Lock,dir,DIRLEN);
  135.               if( (n=strlen(dir)) && ((char)dir[n-1]!=':') ) strcat(dir,"/");
  136.               file=argptr->wa_Name;
  137.               for(t=0;strlen(dob->do_ToolTypes[t]);t++)
  138.               {
  139.                 sprintf(Command,dob->do_ToolTypes[t],dir,file,dir,file,dir,file);
  140.                 Execute(Command,NULL,NULL);
  141.               }
  142.             }
  143.           ReplyMsg((struct Message *)amsg);
  144.         }
  145.       }
  146.       } while (!done);
  147.     FreeDiskObject(dob);
  148.   }
  149.   else Terminate("Program Has No Icon!!");
  150.   Terminate("All OK.");
  151. }
  152.