1 | /****************************** Module Header *******************************
|
---|
2 | *
|
---|
3 | * Module Name: run.erx
|
---|
4 | *
|
---|
5 | * EPM REXX
|
---|
6 | * Execute an action for the current file in EPM, depending on its mode
|
---|
7 | * or extension.
|
---|
8 | *
|
---|
9 | * This REXX command is called when the menu item "Run -> Run current file"
|
---|
10 | * or the toolbar button "Run" was pressed.
|
---|
11 | *
|
---|
12 | * This is coded in REXX to let users adjust it to their needs easily:
|
---|
13 | *
|
---|
14 | * o Copy this file to your %NEPMD_USERDIR%\bin directory.
|
---|
15 | * o Change or extend the "select" expression below.
|
---|
16 | * o In your "when" block, set the var "Action" to the command that
|
---|
17 | * shall be executed.
|
---|
18 | * o In your "when" block, set the var "Msg" to override the default
|
---|
19 | * message.
|
---|
20 | *
|
---|
21 | * Available vars:
|
---|
22 | *
|
---|
23 | * Filename.1 current filename
|
---|
24 | * Filename.2 like Filename.1, but enclosed in doublequotes if it
|
---|
25 | * contains spaces
|
---|
26 | * Filename.3 like Filename.1, but without path
|
---|
27 | * Path path of Filename.1, including the trailing backslash
|
---|
28 | * Basename like Filename.3, but without extension
|
---|
29 | * Ext extension, without the dot
|
---|
30 | * UpExt extension in uppercase
|
---|
31 | * Mode mode for Filename.1
|
---|
32 | *
|
---|
33 | * Notes:
|
---|
34 | *
|
---|
35 | * o Temporary files, starting with a dot, are ignored.
|
---|
36 | * o If current file is modified, it will be saved first.
|
---|
37 | *
|
---|
38 | * Copyright (c) Netlabs EPM Distribution Project 2002
|
---|
39 | *
|
---|
40 | * $Id: run.erx 2417 2011-05-15 23:32:51Z aschn $
|
---|
41 | *
|
---|
42 | * ===========================================================================
|
---|
43 | *
|
---|
44 | * This file is part of the Netlabs EPM Distribution package and is free
|
---|
45 | * software. You can redistribute it and/or modify it under the terms of the
|
---|
46 | * GNU General Public License as published by the Free Software
|
---|
47 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
48 | * Netlabs EPM Distribution. This library is distributed in the hope that it
|
---|
49 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
---|
50 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
51 | * General Public License for more details.
|
---|
52 | *
|
---|
53 | ****************************************************************************/
|
---|
54 |
|
---|
55 | rc = Init()
|
---|
56 | if (rc <> 0) then
|
---|
57 | exit( rc)
|
---|
58 |
|
---|
59 | /* Determine action from mode or extension */
|
---|
60 | Msg = ''
|
---|
61 | Action = ''
|
---|
62 | select
|
---|
63 |
|
---|
64 | /* CMD and REXX files */
|
---|
65 | when Mode = 'CMD' | UPExt = 'CMD' then
|
---|
66 | /*Action = 'os2 /k /f 'filename.2*/
|
---|
67 | Action = 'Shell 'Filename.2
|
---|
68 |
|
---|
69 | /* EPM macro files */
|
---|
70 | when UpExt = 'E' then
|
---|
71 | Action = 'Postme RecompileNew'
|
---|
72 |
|
---|
73 | /* TeX source files */
|
---|
74 | when wordpos( UpExt, 'TEX TEXI TEXINFO') > 0 then
|
---|
75 | Action = 'Shell vlatex.cmd 'Filename.3
|
---|
76 |
|
---|
77 | /* LaTeX macro documentation source files */
|
---|
78 | when wordpos( UpExt, 'DRV DTX FDD') > 0 then
|
---|
79 | Action = 'Shell vlatex.cmd 'Filename.3
|
---|
80 |
|
---|
81 | /* C files */
|
---|
82 | when UpExt = 'C' then
|
---|
83 | /*Action = 'os2 /k /f wcc386 'Filename.1*/
|
---|
84 | /*Action = 'os2 /k /f gcc 'Filename.1*/
|
---|
85 | Action = 'Shell nmake /nologo all'
|
---|
86 |
|
---|
87 | /* EPM REXX files */
|
---|
88 | when Mode = 'REXX' & UpExt = 'ERX' then
|
---|
89 | Action = 'Postme Rx 'Filename.2
|
---|
90 |
|
---|
91 | /* HTML files */
|
---|
92 | when Mode = 'HTML' then
|
---|
93 | Action = 'StartBrowser 'Filename.2
|
---|
94 |
|
---|
95 | otherwise
|
---|
96 | do
|
---|
97 | Msg = 'RUN.ERX: No action defined for this mode. Executing OPEN.ERX...'
|
---|
98 | /* "call open" to call open.erx doesn't work (reliable?) in EPM-REXX */
|
---|
99 | Action = 'rx open' Filename.2
|
---|
100 | end
|
---|
101 |
|
---|
102 | end /* select */
|
---|
103 |
|
---|
104 | /* Execute action */
|
---|
105 | if Msg <> '' then
|
---|
106 | 'sayerror 'Msg
|
---|
107 | else
|
---|
108 | 'sayerror RUN.ERX: Executing 'Action
|
---|
109 | Action
|
---|
110 |
|
---|
111 | /*
|
---|
112 | /* Restore directory */
|
---|
113 | call directory '\'
|
---|
114 | call directory SavedDir
|
---|
115 | */
|
---|
116 |
|
---|
117 | exit
|
---|
118 |
|
---|
119 |
|
---|
120 | /*-------------------------------------------------------------------------*/
|
---|
121 | Init:
|
---|
122 |
|
---|
123 | rc = 0
|
---|
124 | rcx = setlocal()
|
---|
125 |
|
---|
126 | /* Get .filename and .modify fields */
|
---|
127 | 'Extract /filename/modify'
|
---|
128 |
|
---|
129 | /* Don't act on temp files */
|
---|
130 | if left( Filename.1, 1) = '.' then
|
---|
131 | exit
|
---|
132 |
|
---|
133 | /* Save current file if modified */
|
---|
134 | if modify.1 > 0 then
|
---|
135 | do
|
---|
136 | 'Save'
|
---|
137 | if rc <> 0 then
|
---|
138 | return( rc)
|
---|
139 | 'Refresh' /* refresh the bars before further actions */
|
---|
140 | end
|
---|
141 |
|
---|
142 | /* Get current .erx file */
|
---|
143 | parse source . . ThisFile
|
---|
144 | /* Avoid endless loop when ThisFile executes itself */
|
---|
145 | if translate(ThisFile) = translate(Filename.1) then
|
---|
146 | exit
|
---|
147 |
|
---|
148 | /* Get mode array field */
|
---|
149 | Mode = GetMode()
|
---|
150 |
|
---|
151 | /* Change to dir of current file */
|
---|
152 | SavedDir = directory()
|
---|
153 | call directory '\'
|
---|
154 | call directory Filename.1'\..'
|
---|
155 |
|
---|
156 | /* Filename.2: add ".." for spaces in Filename.1 */
|
---|
157 | if pos( ' ', Filename.1) > 0 then
|
---|
158 | Filename.2 = '"'Filename.1'"'
|
---|
159 | else
|
---|
160 | Filename.2 = Filename.1
|
---|
161 |
|
---|
162 | /* Filename.3: strip Path, use name only */
|
---|
163 | lp = lastpos( '\', Filename.1)
|
---|
164 | Filename.3 = substr( Filename.1, lp + 1)
|
---|
165 | Path = substr( Filename.1, 1, lp)
|
---|
166 |
|
---|
167 | /* Ext and Basename */
|
---|
168 | p = pos( '.', Filename.3)
|
---|
169 | if p > 1 then
|
---|
170 | do
|
---|
171 | Ext = substr( Filename.3, p + 1)
|
---|
172 | Basename = substr( Filename.3, 1, p - 1)
|
---|
173 | end
|
---|
174 | else
|
---|
175 | do
|
---|
176 | Ext = ''
|
---|
177 | Basename = Filename.3
|
---|
178 | end
|
---|
179 | UpExt = translate( Ext)
|
---|
180 |
|
---|
181 | /*'sayerror Mode for "'Filename.1'" = "'Mode'", UpExt = "'UpExt'"'*/
|
---|
182 |
|
---|
183 | return( 0)
|
---|
184 |
|
---|
185 | /*-------------------------------------------------------------------------*/
|
---|
186 | GetMode: procedure
|
---|
187 | 'SaveUserstring'
|
---|
188 | 'FileAVar2Userstring mode'
|
---|
189 | 'extract /userstring'
|
---|
190 | Mode = userstring.1
|
---|
191 | 'RestoreUserstring'
|
---|
192 | return Mode
|
---|
193 |
|
---|
194 |
|
---|