home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 164.lha / ARexx / WB_ARexx_v1.1 / wbrexx.c < prev    next >
C/C++ Source or Header  |  1988-04-28  |  5KB  |  183 lines

  1. /** WBRexx.c
  2. *
  3. *                                WBRexx 1.1
  4. *                                ==========
  5. *
  6. *                     Copyright 1988, W.G.J. Langeveld
  7. *                           All Rights Reserved
  8. *                           Freely Distributable
  9. *
  10. *   This program can be used to execute REXX scripts or REXX command strings
  11. *   from the workbench. This can be accomplished either by double clicking on
  12. *   a WBRexx project icon, where the default tool points to this program, or
  13. *   by extended-selecting a number of such icons and double-clicking on the 
  14. *   WBRexx tool icon.
  15. *
  16. *   WINDOW tooltype support added by Steve Berry.
  17. *
  18. **/
  19. #include "exec/exec.h"
  20. #include "libraries/dos.h"
  21. #include "libraries/dosextens.h"
  22. #include "libraries/arpbase.h"
  23. #include "intuition/intuition.h"
  24. #include "workbench/startup.h"
  25. #include "workbench/workbench.h"
  26. #include "functions.h"
  27. #include "stdio.h"
  28. #include "arpfunctions.h"
  29.  
  30. static char *ExpandArg(), *rindex();
  31.  
  32. /**
  33. *
  34. *   Main function. This one handles the Workbench message and all that stuff.
  35. *
  36. **/
  37. void WBRexx(WB_msg)
  38. struct WBStartup *WB_msg;
  39. {
  40.    struct DiskObject *ARIcon = NULL;
  41.    int i, isrxstr = 0, debug = 0;
  42.    char buffer[80], *result1 = NULL, *result2 = NULL, *win = NULL, *SendREXXMsg();
  43.    struct FileLock *olddir = NULL;
  44. /*
  45. *  Handle the WorkBench message.
  46. */
  47.    if (WB_msg) {
  48.       for (i = 0; i < (int) WB_msg->sm_NumArgs; i++) {
  49.          if (debug) {
  50.             strcpy(buffer, "Argument is ");
  51.             strncat(buffer, WB_msg->sm_ArgList[i].wa_Name, 58);
  52.             AReqBool(NULL, buffer, NULL, "Okay");
  53.          }
  54.          result1 = ExpandArg(&WB_msg->sm_ArgList[i], NULL);
  55. /*
  56. *   If this is an inline rexx function (tooltype RX), it will have no file
  57. *   associated with it. Therefore, get the name of the info file.
  58. */
  59.          isrxstr = (strlen(result1) > 0) ? 0 : 1;
  60.          if (isrxstr) result1 = ExpandArg(&WB_msg->sm_ArgList[i], ".info");
  61.  
  62.          if (debug) {
  63.             strcpy(buffer, "Expands to ");
  64.             strncat(buffer, result1, 59);
  65.             AReqBool(NULL, buffer, NULL, "Okay");
  66.          }
  67. /*
  68. *   If the name string is still zero, ignore this one.
  69. */
  70.          if (strlen(result1) > 0) {
  71. /*
  72. *   Else, open the icon.
  73. */
  74.             ARIcon = GetDiskObject(result1);
  75.             if (ARIcon != NULL) {
  76. /*
  77. *   Only do project Icons, of course.
  78. */
  79.                if (ARIcon->do_Type == WBPROJECT) {
  80. /*
  81. *   See if this one has a WINDOW tooltype
  82. */
  83.                   win = FindToolType(ARIcon->do_ToolTypes, "WINDOW");
  84. /*
  85. *   Check the RX tooltype if this is an inline string command. If it is,
  86. *   get the string from the ToolType RX.
  87. */
  88.                   if (isrxstr) result1 = FindToolType(ARIcon->do_ToolTypes, "RX");
  89.                   if (result1) {
  90.                      if (debug) {
  91.                         strcpy(buffer, "REXX gets ");
  92.                         strncat(buffer, result1, 60);
  93.                         AReqBool(NULL, buffer, NULL, "Okay");
  94.                      }
  95. /*
  96. *   Change to the icon's directory.
  97. */
  98.                      if (WB_msg->sm_ArgList[i].wa_Lock) 
  99.                         olddir = CurrentDir(WB_msg->sm_ArgList[i].wa_Lock);
  100. /*
  101. *   Send the command to Rexx. If there's an error, post an autorequest
  102. */
  103.                      result2 = SendREXXMsg(result1, isrxstr, win);
  104.                      if (result2) AReqBool(NULL, result2, NULL, "Okay");
  105. /*
  106. *   Change back to the previous directory
  107. */
  108.                      if (WB_msg->sm_ArgList[i].wa_Lock) CurrentDir(olddir);
  109.                   }
  110.                }
  111. /*
  112. *   If this is the tool icon, see if DEBUG is set.
  113. */
  114.                else if (ARIcon->do_Type == WBTOOL) {
  115.                   result1 = FindToolType(ARIcon->do_ToolTypes, "DEBUG");
  116.                   if (result1) {
  117.                      if (MatchToolValue(result1, "ON")) debug = TRUE;
  118.                   }
  119.                }
  120. /*
  121. *   Free the icon.
  122. */
  123.                FreeDiskObject(ARIcon);
  124.             }
  125.          }
  126.       }
  127.    }  
  128.  
  129.    return;
  130. }
  131.  
  132. /**
  133. *
  134. *   This function expands a WBArg filename to include the full pathname and
  135. *   if given, the extension "extens".
  136. *
  137. **/
  138. char *ExpandArg(arg, extens)
  139. struct WBArg *arg;
  140. char *extens;
  141. {
  142.    struct FileLock *olddir, *lock;
  143.    static char iconname[255];
  144.    static char buff[80], *rind;
  145.    long len;
  146.  
  147.    iconname[0] = '\0';
  148. /*
  149. *   See if this type can be locked. If not, it must be a device, return.
  150. */
  151.    if (arg->wa_Lock == NULL) return(iconname);
  152. /*
  153. *   Change directory to the tools directory.
  154. */
  155.    olddir = CurrentDir(arg->wa_Lock);
  156. /*
  157. *   Get the current path
  158. */
  159.    strcpy(buff, arg->wa_Name);
  160. /*
  161. *   If present, append the file extension.
  162. */
  163.    if (extens) strcat(buff, extens);
  164.  
  165.    lock = Lock(buff, ACCESS_READ);
  166.    if (lock) {
  167.       len = PathName(lock, iconname, 1);
  168.       UnLock(lock);
  169.       if (extens) {
  170.          rind = rindex(iconname, '.');
  171.          if (rind) *rind = '\0';
  172.       }
  173.    }
  174. /*
  175. *   Set directory back
  176. */
  177.    CurrentDir(olddir);
  178.  
  179.    return(iconname);
  180. }
  181.  
  182.  
  183.