source: trunk/src/netlabs/bin/run.erx@ 2417

Last change on this file since 2417 was 2417, checked in by Andreas Schnellbacher, 14 years ago
  • Added svn keywords.
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 5.1 KB
RevLine 
[1281]1/****************************** Module Header *******************************
2*
3* Module Name: run.erx
4*
[1859]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*
[1281]38* Copyright (c) Netlabs EPM Distribution Project 2002
39*
[2417]40* $Id: run.erx 2417 2011-05-15 23:32:51Z aschn $
[1281]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
[2273]55rc = Init()
56if (rc <> 0) then
57 exit( rc)
[1281]58
59/* Determine action from mode or extension */
[1859]60Msg = ''
61Action = ''
[1281]62select
63
64 /* CMD and REXX files */
65 when Mode = 'CMD' | UPExt = 'CMD' then
[1859]66 /*Action = 'os2 /k /f 'filename.2*/
67 Action = 'Shell 'Filename.2
[1281]68
[1859]69 /* EPM macro files */
[1281]70 when UpExt = 'E' then
[1859]71 Action = 'Postme RecompileNew'
[1281]72
73 /* TeX source files */
74 when wordpos( UpExt, 'TEX TEXI TEXINFO') > 0 then
[1859]75 Action = 'Shell vlatex.cmd 'Filename.3
[1281]76
77 /* LaTeX macro documentation source files */
78 when wordpos( UpExt, 'DRV DTX FDD') > 0 then
[1859]79 Action = 'Shell vlatex.cmd 'Filename.3
[1281]80
81 /* C files */
82 when UpExt = 'C' then
[1859]83 /*Action = 'os2 /k /f wcc386 'Filename.1*/
84 /*Action = 'os2 /k /f gcc 'Filename.1*/
[2313]85 Action = 'Shell nmake /nologo all'
[1281]86
[1859]87 /* EPM REXX files */
[1281]88 when Mode = 'REXX' & UpExt = 'ERX' then
[1859]89 Action = 'Postme Rx 'Filename.2
[1281]90
[1725]91 /* HTML files */
92 when Mode = 'HTML' then
[1859]93 Action = 'StartBrowser 'Filename.2
[1725]94
[1281]95 otherwise
96 do
[1859]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
[1281]100 end
101
102end /* select */
103
104/* Execute action */
[1859]105if Msg <> '' then
106 'sayerror 'Msg
[1281]107else
[1859]108 'sayerror RUN.ERX: Executing 'Action
109Action
[1281]110
[2332]111/*
[1281]112/* Restore directory */
113call directory '\'
[1859]114call directory SavedDir
[2332]115*/
[1281]116
[1859]117exit
[1281]118
119
120/*-------------------------------------------------------------------------*/
[1859]121Init:
122
[2273]123 rc = 0
[2332]124 rcx = setlocal()
[2273]125
[1859]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
[2273]135 do
136 'Save'
137 if rc <> 0 then
138 return( rc)
139 'Refresh' /* refresh the bars before further actions */
140 end
[1859]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
[2273]183 return( 0)
[1859]184
185/*-------------------------------------------------------------------------*/
[1281]186GetMode: procedure
[1887]187 'SaveUserstring'
188 'FileAVar2Userstring mode'
[1281]189 'extract /userstring'
190 Mode = userstring.1
[1887]191 'RestoreUserstring'
[1281]192 return Mode
193
194
Note: See TracBrowser for help on using the repository browser.