home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 144.lha / WB_Rexx / wbrexx.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  4.2 KB  |  160 lines

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