forked from teamQPM/qpm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
us_run.prg
375 lines (331 loc) · 10.8 KB
/
us_run.prg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* QPM - QAC based Project Manager
*
* Copyright 2011-2021 Fernando Yurisich <[email protected]>
* https://teamqpm.github.io/
*
* Based on QAC - Project Manager for (x)Harbour
* Copyright 2006-2011 Carozo de Quilmes <[email protected]>
* http://www.CarozoDeQuilmes.com.ar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "minigui.ch"
#include "fileio.ch"
// For error codes see: http://msdn2.microsoft.com/en-us/library/ms681382(VS.85).aspx
#define VERSION "01.04"
MEMVAR cQPMDir
PROCEDURE MAIN( ... )
LOCAL aParams := hb_aParams()
LOCAL n, bList := .F., bOk := .F., nLineSize := 1024, cParam, MemoAux := "", i, cLineaAux := ""
PRIVATE cCMD := "", cControlFile := "", cDefaultPath := "", cCurrentPath, cMode := "NORMAL", cQPMDir := ""
cParam := ""
FOR n := 1 TO Len( aParams )
cParam += ( aParams[ n ] + " " )
NEXT n
cParam := AllTrim( cParam )
IF Upper( US_Word( cParam, 1 ) ) == "-VER" .or. Upper( US_Word( cParam, 1 ) ) == "-VERSION"
hb_MemoWrit( "US_Run.version", VERSION )
RETURN
ENDIF
IF Upper( US_Word( cParam, 1 ) ) != "QPM"
__Run( "ECHO " + "US_Res 001E: Running Outside System" )
RETURN
ENDIF
cParam := US_WordDel( cParam, 1 )
IF Upper( SubStr( cParam, 1, 5 ) ) == "-LIST"
bList := .T.
cQPMDir := SubStr( US_Word( cParam, 1), 6 )
IF ! Right( cQPMDir, 1 ) == "\"
cQPMDir += "\"
ENDIF
cParam := AllTrim( SubStr( cParam, US_WordInd( cParam, 2 ) ) )
ENDIF
IF bList
QPM_Log( "------------ " + "US_Run.version " + VERSION )
ENDIF
IF Empty( cParam )
IF bList
QPM_Log( "US_Run 002E: Missing Parameters" )
ENDIF
RETURN
ENDIF
IF ! File( cParam )
IF bList
QPM_Log( "US_Run 003E: Parameters File Not Found: " + cParam )
ENDIF
RETURN
ENDIF
MemoAux := MemoRead( cParam )
FOR i := 1 TO MLCount( MemoAux, nLineSize )
cLineaAux := AllTrim( MemoLine( MemoAux, nLineSize, i ) )
IF Upper( US_Word( cLineaAux, 1 ) ) == "COMMAND"
cCMD := US_WordSubStr( cLineaAux, 2 )
ENDIF
IF Upper( US_Word( cLineaAux, 1 ) ) == "CONTROL"
cControlFile := US_WordSubStr( cLineaAux, 2 )
ENDIF
IF Upper( US_Word( cLineaAux, 1 ) ) == "DEFAULTPATH"
cDefaultPath := US_WordSubStr( cLineaAux, 2 )
ENDIF
IF Upper( US_Word( cLineaAux, 1 ) ) == "MODE"
cMode := US_WordSubStr( cLineaAux, 2 )
ENDIF
NEXT i
FErase( cParam )
IF bList
QPM_Log( "US_Run 004I: COMMAND = " + cCMD )
QPM_Log( "US_Run 005I: CONTROL = " + cControlFile )
QPM_Log( "US_Run 006I: DEFPATH = " + cDefaultPath )
QPM_Log( "US_Run 007I: RUNMODE = " + cMode )
ENDIF
DEFINE WINDOW VentanaMain ;
AT 0, 0 ;
WIDTH GetDesktopWidth() ;
HEIGHT GetDesktopHeight() ;
TITLE '' ;
MAIN ;
ICON "DOS" ;
NOSHOW ;
ON INIT ( bok := US_RunInit( bList ) )
END WINDOW
ACTIVATE WINDOW VentanaMain
IF bOk
IF bList
QPM_Log( "US_Run 008I: Ended OK" )
ENDIF
ELSE
IF bList
QPM_Log( "US_Run 009E: Ended with ERROR" )
ENDIF
ENDIF
RETURN
//========================================================================
FUNCTION US_RunInit( bList )
LOCAL Reto, nHandle, bOk := .T.
DO EVENTS
nHandle := FOpen( cControlFile, FO_WRITE + FO_EXCLUSIVE )
IF FError() == 0
IF ! Empty( cDefaultPath )
cCurrentPath := GetCurrentFolder()
SetCurrentFolder( cDefaultPath )
ENDIF
IF bList
QPM_Log( "US_Run 010I: current folder is " + GetCurrentFolder() )
ENDIF
DO EVENTS
DO CASE
CASE cMode == "HIDE"
Reto := WaitRun( cCMD, 0 ) // EXECUTE FILE ( cCMD ) WAIT HIDE
CASE cMode == "MINIMIZE"
Reto := WaitRun( cCMD, 6 ) // EXECUTE FILE ( cCMD ) WAIT MINIMIZE
CASE cMode == "MAXIMIZE"
Reto := WaitRun( cCMD, 3 ) // EXECUTE FILE ( cCMD ) WAIT MAXIMIZE
OTHERWISE
Reto := WaitRun( cCMD, 5 ) // EXECUTE FILE ( cCMD ) WAIT
ENDCASE
IF bList
QPM_Log( "US_Run 011I: WaitRun returned " + US_VarToStr( Reto ) )
ENDIF
IF ! Empty( cDefaultPath )
SetCurrentFolder( cCurrentPath )
ENDIF
DO EVENTS
IF Reto > 8
IF bList
QPM_Log( "US_Run 012E: Error Running: " + cCMD + HB_OsNewLine() + "Code: " + US_VarToStr( Reto ) )
ENDIF
bOk := .F.
ENDIF
FClose( nHandle )
ELSE
IF bList
QPM_Log( "US_Run 013E: error opening control file." )
ENDIF
bOk := .F.
ENDIF
FErase( cControlFile )
DO EVENTS
VentanaMain.Release()
RETURN bOk
//========================================================================
// FUNCION PARA EXTRAER UNA PALABRA DE UN ESTRING
//========================================================================
FUNCTION US_WORD(ESTRING, POSICION)
LOCAL CONT := 1
IF Posicion == NIL
Posicion := 1
ENDIF
ESTRING := AllTrim( ESTRING )
DO WHILE .T.
IF At( " ", ESTRING ) != 0
IF CONT == POSICION
RETURN SubStr( ESTRING, 1, At( " ", ESTRING ) - 1 )
ELSE
ESTRING := AllTrim( SubStr( ESTRING, At( " ", ESTRING ) + 1 ) )
CONT ++
ENDIF
ELSE
IF POSICION == CONT
RETURN ESTRING
ELSE
EXIT
ENDIF
ENDIF
ENDDO
RETURN ""
//========================================================================
// FUNCION PARA ELIMINAR UNA PALABRA DE UN STRING
//========================================================================
FUNCTION US_WordDel( ESTRING, POSICION )
LOCAL cRet
IF POSICION > 0
cRet := AllTrim( SubStr( ESTRING, 1, US_WordInd( ESTRING, POSICION ) - 1 ) + ;
StrTran( SubStr( ESTRING, US_WordInd( ESTRING, POSICION ) ), US_Word( ESTRING, POSICION ), " ", 1, 1 ) )
ELSE
cRet := ESTRING
ENDIF
RETURN cRet
//========================================================================
// FUNCION PARA SABER LA POSICION DE LA PALABRA NUMERO ....
// ESTA FUNCION RETORNA EL BYTE DONDE EMPIEZA LA PALABRA
//========================================================================
FUNCTION US_WordInd( ESTRING, POSICION )
LOCAL CONT, ESTR, ESTR2
IF ESTRING == NIL
ESTRING := ""
ENDIF
IF US_Words( Estring ) < Posicion
RETURN ( Len( Estring ) + 1 )
ENDIF
CONT := 1
ESTR := ESTRING
ESTR2 := RTrim( ESTRING )
ESTRING := AllTrim( ESTRING )
DO WHILE .T.
IF At(" ",ESTRING) != 0
IF CONT == POSICION
RETURN ( Len( ESTR ) - ( Len( ESTRING ) + ( Len( ESTR ) - Len( ESTR2 ) ) ) + 1 )
ELSE
ESTRING := AllTrim( SubStr( ESTRING, At( " ", ESTRING ) + 1 ) )
CONT ++
ENDIF
ELSE
IF POSICION == CONT
RETURN ( Len( ESTR ) - ( Len( ESTRING ) + ( Len( ESTR ) - Len( ESTR2 ) ) ) + 1 )
ELSE
RETURN 0
ENDIF
ENDIF
ENDDO
RETURN 0
//========================================================================
// FUNCION PARA retornar un substr a partir de la posicion de una palabra
//========================================================================
FUNCTION US_WordSubstr( estring, pos )
IF Estring == NIL
Estring := ""
ENDIF
RETURN SubStr( estring, US_WordInd( estring, pos ) )
//========================================================================
// FUNCION PARA CONTAR LAS PALABRAS EN UN ESTRING
//========================================================================
FUNCTION US_WORDS( ESTRING )
LOCAL CONT := 0
IF Estring == NIL
Estring := ""
ENDIF
ESTRING := AllTrim( ESTRING )
DO WHILE .T.
IF At( " ", ESTRING ) != 0
ESTRING := AllTrim( SubStr( ESTRING, At( " ", ESTRING ) + 1 ) )
CONT++
ELSE
IF Len( ESTRING ) > 0
RETURN CONT + 1
ELSE
RETURN CONT
ENDIF
ENDIF
ENDDO
RETURN 0
//========================================================================
FUNCTION US_VarToStr(X)
LOCAL T, StringAux:="", i
IF X == NIL
X := "*NIL*"
ENDIF
T := ValType( X )
DO CASE
CASE T = 'C'
RETURN X
CASE T = 'O'
RETURN "*OBJ*"
CASE T = 'U'
RETURN "*UND*"
CASE T = 'M'
RETURN X
CASE T = 'D'
StringAux=DToS(X)
RETURN StringAux
CASE T = 'N'
StringAux := US_STRCERO( X )
RETURN StringAux
CASE T = 'L'
StringAux := iif( X, '.T.', '.F.' )
RETURN StringAux
CASE T = 'A'
FOR i := 1 TO Len( X ) - 1
StringAux := StringAux + US_VarToStr( X[ i ] ) + hb_osNewLine()
NEXT
IF Len( X ) > 0
StringAux := StringAux + US_VarToStr( X[ Len( X ) ] )
ENDIF
RETURN StringAux
ENDCASE
RETURN ""
//========================================================================
FUNCTION US_StrCero(NUM,LONG,DEC)
LOCAL INDICIO
IF DEC=NIL
IF LONG=NIL
NUM=STR(NUM)
ELSE
NUM=STR(NUM,LONG)
ENDIF
ELSE
NUM=STR(NUM,LONG,DEC)
ENDIF
LONG=Len(NUM)
FOR INDICIO := 1 TO LONG
IF SubStr( NUM, INDICIO, 1 ) == " "
NUM := Stuff( NUM, INDICIO, 1, "0" )
ENDIF
NEXT
RETURN NUM
//========================================================================
// ESCRIBE EN EL LOG
//========================================================================
STATIC FUNCTION QPM_Log( string )
LOCAL LogArchi := cQPMDir + "QPM.LOG"
LOCAL msg := DToS( Date() ) + " " + Time() + " US_RUN " + ProcName( 1 ) + "(" + Str( ProcLine( 1 ), 3, 0 ) + ")" + " " + string
SET CONSOLE OFF
SET ALTERNATE TO ( LogArchi ) ADDITIVE
SET ALTERNATE ON
? msg
SET ALTERNATE OFF
SET ALTERNATE TO
SET CONSOLE ON
RETURN .T.
/* eof */