home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LW5VT09.LHA / Toaster / Arexx_examples / PlugIns / LoadMacros.lwm < prev    next >
Encoding:
Text File  |  1996-06-10  |  11.0 KB  |  342 lines

  1. /* CMD: ½LoadMacros                                                     */
  2. /* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
  3.     MacrosName = "LoadMacros"
  4. /* Macro Type:                                                          */
  5. /* SPECIAL     * REMEMBERS                                              */
  6. /* Description:                                                         */
  7.  
  8. Info1A = "!Load Macros ©                 Information 1 of 2"
  9. Info1B = ""
  10. Info1C = "@This macro allows for easier adding of macros.  "
  11. Info1D = "@After options are chosen a file requester will  "
  12. Info1E = "@appear; for ONLY a path OR a path and one file. "
  13. Info1F = ""
  14. Info1G = "@þ Number of Macros                              "
  15. Info1H = "¤ INDIVIDUAL FILE: adds one selected macro;     "
  16. Info1I = "¤ ENTIRE DIR.: adds all macros within directory."
  17. Info1J = ""
  18. Info1K = "@þ Names for Added Macros                        "
  19. Info1L = "¤ NAME ...FILENAME: Macro's name = File's name. "
  20. Info1M = "¤ ENCODED...: Macros have names encoded within. "
  21. Info1N = "¤ ...USER: The name is asked from the user.     "
  22.  
  23. Info2A = "!Load Macros ©                 Information 2 of 2"
  24. Info2B = "@               Plug-Ins and Go! ©               "
  25. Info2C = "                           Hester and associates"
  26. Info2D = "                           13032 Copenhill Road "
  27. Info2E = "                           Dallas, Texas 75240  "
  28. Info2F = "@Special Thanks to:                              "
  29. Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
  30. Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
  31. Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
  32. Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
  33. Info2K = ""
  34. Info2L = "@This macro represents a lot of time & hard work."
  35. Info2M = "@Encourage people to create new ones and not kill"
  36. Info2N = "@that possibility by stealing those that are out."
  37.  
  38. /* -------------------------------------------------------------------- */
  39.                                      /* Start Error Detection (See End) */
  40. SIGNAL ON ERROR
  41. SIGNAL ON SYNTAX
  42.                                                    /* Address LightWave */
  43. VT3DLib = ADDLIB("LWModelerARexx.port",0)
  44. ADDRESS "LWModelerARexx.port"
  45.                                                /* Add Support Functions */
  46. SupportLib = "rexxsupport.library"
  47. IF POS(SupportLib , SHOW('L')) = 0 THEN
  48.     IF ~ADDLIB(SupportLib , 0 , -30 , 0) THEN DO
  49.         CALL Notify(1,"!Can't find "SupportLib)
  50.         IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  51.         EXIT
  52.     END
  53.  
  54. /* -------------------------------------------------------------------- */
  55.                                     /* Reading Global Macro Preferences */
  56. BEHDefaultFilePath = "Sys:"
  57. BEHSettingsSavedTo = "T:"
  58. BEHSpeechAndSound = "1"
  59.  
  60. IF (EXISTS("S:PlugInPrefs")) THEN DO
  61.     IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
  62.     IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
  63.     BEHDefaultFilePath = READLN(PlugInPrefs)
  64.     BEHSettingsSavedTo = READLN(PlugInPrefs)
  65.     BEHSpeechAndSound = READLN(PlugInPrefs)
  66.     CALL CLOSE PlugInPrefs
  67. END
  68.  
  69. /* -------------------------------------------------------------------- */
  70.                                             /* Recalling Macro Settings */
  71. ReqAdd = "1"
  72. ReqName = "3"
  73. FilePath = "/Arexx_Examples/lwm"
  74. FileName = ""
  75.  
  76. PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
  77.  
  78. IF (EXISTS(PrefsFileName)) THEN DO
  79.     IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
  80.     IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
  81.  
  82.     ReqAdd = READLN(PrefsFile)
  83.     ReqName = READLN(PrefsFile)
  84.     FilePath = READLN(PrefsFile)
  85.     FileName = READLN(PrefsFile)
  86.  
  87.     CALL CLOSE PrefsFile
  88. END
  89.  
  90. /* -------------------------------------------------------------------- */
  91.                                                    /* Main Body Of Code */
  92. CALL MenuRequester
  93. CALL FileRequester
  94.  
  95. DO FOREVER
  96.     IF ReqAdd = 3 THEN CALL ScanDirectory
  97.  
  98.     CALL VerifyFile
  99.     IF Verified = 0 THEN DO
  100.         IF ReqAdd ~= 3 THEN CALL Sorry
  101.     END
  102.     IF Verified = 1 THEN DO
  103.         CALL ReadFile
  104.         IF ReqName = 1 THEN TheName = BaseName
  105.         IF ReqName = 2 THEN TheName = EncodedName
  106.         IF ReqName = 3 THEN CALL UseProvidedName
  107.         CALL FinalStage
  108.     END
  109.                                                   /* Starting Next Loop */
  110.     IF ReqAdd = 1 THEN CALL Exiting
  111.     IF ReqAdd = 2 THEN CALL FileRequester
  112. END
  113.  
  114. CALL Exiting
  115.  
  116. /* -------------------------------------------------------------------- */
  117.                                                       /* User Interface */
  118. MenuRequester:
  119.  
  120.     CALL Req_Begin("Load Macros ©          ")
  121.  
  122.     CALL Req_AddControl("",'T', "        by Brett Hester ")
  123.     CALL Req_AddControl("",'T', "")
  124.     CALL Req_AddControl("",'T', "Number of Macros")
  125.     ReqA = Req_AddControl("",'CV', "Individual File       Multiple Files        Entire Directory     ")
  126.     CALL Req_AddControl("",'T', "")
  127.     CALL Req_AddControl("",'T', "Names for Added Macros")
  128.     ReqB = Req_AddControl("",'CV', "Based Off Filename(s) Encoded In File(s)    Provided By User     ")
  129.     CALL Req_AddControl("",'T', "")
  130.     ReqC = Req_AddControl("",'CV', "Information")
  131.  
  132.     CALL Req_SetVal(ReqA, ReqAdd)
  133.     CALL Req_SetVal(ReqB, ReqName)
  134.     CALL Req_SetVal(ReqC, 0)
  135.  
  136.     OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting
  137.  
  138.     ReqAdd = Req_GetVal(ReqA)
  139.     ReqName = Req_GetVal(ReqB)
  140.     BEHInfo = Req_GetVal(ReqC)
  141.  
  142.     CALL Req_End()
  143.  
  144.     IF BEHInfo = 1 THEN CALL InformationWindows
  145.  
  146. RETURN
  147.  
  148. /* -------------------------------------------------------------------- */
  149.                                                       /* File Requester */
  150. FileRequester:
  151.  
  152.     FileReq = GetFileName("-- Select Macro(s) --", FilePath, FileName)
  153.     IF FileReq = "" THEN CALL Exiting
  154.     IF FileReq = "(none)" THEN CALL Exiting
  155.                                        /* Extracting File Name and Path */
  156.     FileReqLength = LENGTH(FileReq)
  157.     FileDivider = LASTPOS("/",FileReq)
  158.     IF FileDivider = 0 THEN FileDivider = LASTPOS(":",FileReq)
  159.     FileNameLength = FileReqLength - FileDivider
  160.  
  161.     FilePath = STRIP(LEFT(FileReq, FileDivider),"T","/")
  162.     FileName = RIGHT(FileReq, FileNameLength)
  163.                                              /* Verify Directory Exists */
  164.     IF EXISTS(FilePath) = 0 THEN DO
  165.         CALL Notify(1,"!Sorry!",'@Directory "'||FilePath||'" not found.')
  166.         CALL Exiting
  167.     END
  168.                                          /* If ENTIRE DIR. is selected: */
  169.     IF ReqAdd = 3 THEN DO
  170.         FileList = SHOWDIR(FilePath,"F",";")
  171.         FilePathPlus = FilePath
  172.         IF RIGHT(FilePath,1) ~= ":" THEN FilePathPlus = FilePath||"/"
  173.     END
  174.  
  175.     CALL SaveSettings
  176.  
  177. RETURN
  178.  
  179. /* -------------------------------------------------------------------- */
  180.                                      /* Striping Filename from FileList */
  181. ScanDirectory:
  182.  
  183.     PARSE var FileList FileName";"FileList
  184.     IF FileName = "" THEN CALL Exiting
  185.     FileReq = FilePathPlus||FileName
  186.  
  187. RETURN
  188.  
  189. /* -------------------------------------------------------------------- */
  190.                                                          /* Verify File */
  191. VerifyFile:
  192.                                              /* Verify File Ends ".lwm" */
  193.     Verified = 0
  194.     FileSuffix = UPPER(RIGHT(FileReq, 4))
  195.     IF FileSuffix = ".LWM" THEN Verified = 1
  196.     BaseName = LEFT(FileName,((LENGTH(FileName))-4))
  197.  
  198. RETURN
  199.  
  200. /* -------------------------------------------------------------------- */
  201.                                                 /* Reading Encoded Name */
  202. ReadFile:
  203.  
  204.     IF (OPEN(TheFile, FileReq, 'R')) THEN DO
  205.         EncodedName = READLN(TheFile)
  206.         CALL CLOSE(TheFile)
  207.         EncodedName = STRIP(COMPRESS(EncodedName,"*/    "))
  208.         Remove = POS("CMD:",UPPER(EncodedName))
  209.         IF Remove ~= 0 THEN EncodedName = STRIP(DELSTR(EncodedName,Remove,4))
  210.     END
  211.  
  212. RETURN
  213.  
  214. /* -------------------------------------------------------------------- */
  215.                                                       /* User Interface */
  216. UseProvidedName:
  217.  
  218.     CALL Req_Begin("Load Macros ©")
  219.  
  220.     CALL Req_AddControl("File Name   ",'T',BaseName)
  221.     CALL Req_AddControl("Encoded Name",'T',EncodedName)
  222.     ReqC = Req_AddControl("Macro Name  ",'S', 20)
  223.  
  224.     CALL Req_SetVal(ReqC, BaseName)
  225.  
  226.     OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting
  227.  
  228.     TheName = Req_GetVal(ReqC)
  229.  
  230.     CALL Req_End()
  231.  
  232. RETURN
  233.  
  234. /* -------------------------------------------------------------------- */
  235.                                                         /* Adding Macro */
  236. FinalStage:
  237.  
  238.     IF POS(" ",FileReq) ~= 0 THEN DO
  239.         IF ReqAdd ~= 3 THEN CALL Sorry
  240.     END
  241.  
  242.     IF POS(" ",FileReq) = 0 THEN DO
  243.         IF TheName = "" THEN TheName = "Unnamed"
  244.         OKorCancel = RxCmd_Add(TheName, FileReq)
  245.     END
  246.  
  247.     IF ReqAdd ~= 3 THEN DO
  248.         IF OKorCancel = 0 THEN CALL Sorry
  249.     END
  250.  
  251. RETURN
  252.  
  253. /* -------------------------------------------------------------------- */
  254.                                             /* Recording Macro Settings */
  255. SaveSettings:
  256.  
  257.     IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
  258.         CALL WRITELN(PrefsFile, MacrosName)
  259.  
  260.         CALL WRITELN(PrefsFile, ReqAdd)
  261.         CALL WRITELN(PrefsFile, ReqName)
  262.         CALL WRITELN(PrefsFile, FilePath)
  263.         CALL WRITELN(PrefsFile, FileName)
  264.  
  265.         CALL CLOSE PrefsFile
  266.     END
  267.  
  268. RETURN
  269.  
  270. /* -------------------------------------------------------------------- */
  271.                                                               /* Ending */
  272. Exiting:
  273.  
  274.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  275.     EXIT
  276.  
  277. RETURN
  278.  
  279. /* -------------------------------------------------------------------- */
  280.  
  281. Sorry:
  282.  
  283.     ReqA = "!Sorry!"
  284.     ReqB = ""
  285.     ReqC = '@"'||FileReq||'"'
  286.     ReqD = ""
  287.     ReqE = "þ Macro already listed.       - or -"
  288.     ReqF = "þ File format unknown.        - or -"
  289.     ReqG = "þ File name contains spaces.  - or -"
  290.     ReqH = 'þ File name does not end with ".lwm"'
  291.     CALL Notify(1,ReqA,ReqB,ReqC,ReqD,ReqE,ReqF,ReqG,ReqH)
  292.  
  293. RETURN
  294.  
  295. /* -------------------------------------------------------------------- */
  296.                                                  /* Information Windows */
  297. InformationWindows:
  298.  
  299.     OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
  300.     IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
  301.     CALL MenuRequester
  302.  
  303. RETURN
  304.  
  305. /* -------------------------------------------------------------------- */
  306.                                                       /* Error Handling */
  307. SYNTAX:
  308. ERROR:
  309.  
  310.     ErrCode = RC
  311.     ErrLine = SIGL
  312.     ErrInfo = ERRORTEXT(ErrCode)
  313.  
  314.     Err1 = "!Sorry!"
  315.     Err2 = "An Error has been detected"
  316.     Err3 = "@þ Macro -            "
  317.     Err4 = "@þ Line Number -      "
  318.     Err5 = "@þ Error Code -       "
  319.     Err6 = "@þ Error Description -"
  320.     Err7 = "@¤ Please Inform -    "
  321.     Err8 = '  "Error Notice"     '
  322.     Err9 = "  13032 Copenhill Rd."
  323.     Err10 = "  Dallas, TX. 75240  "
  324.  
  325.     Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
  326.  
  327. /* -------------------------------------------------------------------- */
  328.                                              /* Advanced Error Handling */
  329.     CALL SETCLIP("ErrorMacro",MacrosName)
  330.     CALL SETCLIP("ErrorLine",ErrLine)
  331.     CALL SETCLIP("ErrorCode",ErrCode)
  332.     CALL SETCLIP("ErrorDesc",ErrInfo)
  333.  
  334.     PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
  335.  
  336.     CALL SETCLIP("ErrorFile",ErrFile)
  337.  
  338. /* -------------------------------------------------------------------- */
  339.  
  340.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  341.     EXIT
  342.