-
Notifications
You must be signed in to change notification settings - Fork 6
/
us_slash.prg
353 lines (312 loc) · 11.7 KB
/
us_slash.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
/*
* 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/>.
*/
#define DBLQT '"'
#define SNGQT "'"
#define CRLF hb_osNewLine()
#define VERSION "01.08"
MEMVAR cQPMDIR
// Parameters: 1 -> cParam (multiple words), 2 -> cFileIn (one word), 3 -> cFileOut (one word)
PROCEDURE MAIN( ... )
LOCAL aParams := hb_AParams(), n, cLib, cSearch := "", cGroup := "", bDoubleSlash, bUseAt
LOCAL bLoop := .T., cLine, cFines := { Chr(13) + Chr(10), Chr(10) }, hParam, cKey
LOCAL cFileOut, cFileIn, cParam, gcc_call, cmdbatch, bList := .F., cPath := ""
LOCAL fgccbat := US_FileTmp( NIL, ".bat" )
LOCAL fstatus := US_FileTmp( NIL, ".res" )
LOCAL fparams := US_FileTmp( NIL, ".par" )
PRIVATE 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_Slash.version", VERSION )
RETURN
ENDIF
IF Upper( US_Word( cParam, 1 ) ) != "QPM"
__Run( "ECHO " + "US_Slash 001E: Running Outside System" )
RETURN
ENDIF
cParam := US_WordDel( cParam, 1 )
IF Upper( US_Word( cParam, 1 ) ) == "SSLASH"
bDoubleSlash := .F.
cParam := US_WordDel( cParam, 1 )
ELSE
bDoubleSlash := .T.
ENDIF
IF Upper( US_Word( cParam, 1 ) ) == "NOAT"
bUseAt := .F.
cParam := US_WordDel( cParam, 1 )
ELSE
bUseAt := .T.
ENDIF
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
cFileIn := US_Word( cParam, US_Words( cParam ) - 1 )
cFileOut := US_Word( cParam, US_Words( cParam ) )
cFileOut := SubStr( cFileOut, 3 )
cParam := AllTrim( SubStr( cParam, 1, US_WordInd( cParam, US_Words( cParam ) - 1 ) - 1 ) )
IF bList
QPM_Log( "------------ " + "US_Slash.version " + VERSION )
QPM_Log( "US_Slash 002I: Log into: " + cQPMDir + "QPM.log" )
QPM_Log( "US_Slash 003I: FileIn: " + cFileIn )
QPM_Log( "US_Slash 004I: FileOut: " + cFileOut )
QPM_Log( "US_Slash 005I: Param: " + cParam )
ENDIF
IF Upper( Right( cFileIn, 9 ) ) == 'SCRIPT.LD'
hParam := FOpen( cFileIn )
IF FError() = 0
cFileIn := ""
cSearch := ""
cGroup := "-Wl,--start-group "
DO WHILE bLoop
IF hb_FReadLine( hParam, @cLine, cFines ) != 0
bLoop := .F.
ENDIF
cKey := US_Word( cLine, 1 )
IF ! Empty( cKey )
IF bList
QPM_Log( "US_Slash 006I: Script " + cLine )
ENDIF
IF cKey == "INPUT("
cFileIn += US_Word( cLine, 2 ) + " "
ELSEIF cKey == "SEARCH_DIR("
cSearch += "-L" + US_Word( cLine, 2 ) + " "
ELSEIF cKey == "GROUP("
n := 2
DO WHILE .T.
cLib := US_Word( cLine, n )
IF Left( cLib, 2 ) # "-l"
EXIT
ENDIF
cGroup += cLib + " "
n ++
ENDDO
ELSEIF cKey == "PATH("
cPath := US_Word( cLine, 2 )
ELSEIF bList
QPM_Log( "US_Slash 007E: Bad key: " + cKey )
ENDIF
ENDIF
ENDDO
FClose( hParam )
cGroup += "-Wl,--end-group -static-libgcc "
ELSE
IF bList
QPM_Log( "US_Slash 008E: Open error: " + cFileIn )
ENDIF
RETURN
ENDIF
ENDIF
cLine := cFileIn + ' -o ' + cFileOut + ' ' + cSearch + cGroup + cParam + hb_osNewLine()
IF bDoubleSlash
cLine := StrTran( cLine, "\", "\\" )
ENDIF
hb_MemoWrit( fparams, cLine )
IF bUseAt
gcc_call := 'GCC.EXE @' + fparams
ELSE
gcc_call := 'GCC.EXE ' + cLine
ENDIF
IF bList
QPM_Log( "US_Slash 009I: cFileIn: " + cFileIn )
QPM_Log( "US_Slash 010I: cFileOut: " + cFileOut )
QPM_Log( "US_Slash 011I: cSearch: " + cSearch )
QPM_Log( "US_Slash 012I: cGroup: " + cGroup )
QPM_Log( "US_Slash 013I: cParam: " + cParam )
QPM_Log( "US_Slash 014I: cPath: " + cPath )
QPM_Log( "US_Slash 015I: gcc_call: " + gcc_call )
QPM_Log( "US_Slash 016I: cLine: " + cLine )
ENDIF
cmdbatch := hb_osNewLine() + ;
"@echo off" + hb_osNewLine() + ;
iif( empty( cPath ), "", "set PATH=" + cPath + hb_osNewLine() ) + ;
gcc_call + hb_osNewLine() + ;
"if errorlevel 1 goto bad" + hb_osNewLine() + ;
"echo OK > " + fstatus + hb_osNewLine() + ;
"goto exit" + hb_osNewLine() + ;
":bad" + hb_osNewLine() + ;
"echo ERROR > " + fstatus + hb_osNewLine() + ;
":exit" + hb_osNewLine()
hb_MemoWrit( fgccbat, cmdbatch )
IF bList
QPM_Log( "US_Slash 017I: INI Batch" )
QPM_LOG( Left( cmdbatch, Len( cmdbatch ) - 2 ) )
QPM_Log( "US_Slash 018I: END Batch" )
QPM_Log( "US_Slash 019I: INI Param" )
QPM_LOG( Left( cLine, Len( cLine ) - 2 ) )
QPM_Log( "US_Slash 020I: END Param" )
ENDIF
__Run( fgccbat )
IF MemoLine( MemoRead( fstatus ), 254, 1 ) = "ERROR"
IF bList
QPM_Log( "US_Slash 021I: Status: ERROR" )
QPM_Log( "------------" + CRLF )
ENDIF
ELSE
IF bList
QPM_Log( "US_Slash 022I: Status: OK" )
QPM_Log( "------------" + CRLF )
ENDIF
ENDIF
FErase( fgccbat )
FErase( fparams )
FErase( fstatus )
RETURN
//========================================================================
// RETORNA EL NOMBRE DE UN ARCHIVO INEXISTENTE
//========================================================================
FUNCTION US_FileTmp( prefix, suffix )
LOCAL cFile
IF Empty( prefix )
prefix := "_temp"
ENDIF
IF Empty( suffix )
suffix := ".tmp"
ENDIF
IF ! Left( suffix, 1 ) == "."
suffix := "." + suffix
ENDIF
DO WHILE .T.
cFile := prefix + US_NameRandom() + suffix
IF ! File( cFile )
EXIT
ENDIF
ENDDO
RETURN cFile
//========================================================================
// RETORNA UN STRING A PARTIR DEL NÚMERO DE SEGUNDOS TRANSCURRIDOS
//========================================================================
FUNCTION US_NameRandom()
RETURN AllTrim( StrTran( StrTran( Str( Seconds() ), ".", AllTrim( Str( US_Rand( Seconds() ) ) ) ), "-", "M" ) )
//========================================================================
// RETORNA UN STRING A PARTIR DEL NÚMERO DE SEGUNDOS TRANSCURRIDOS
//========================================================================
FUNCTION US_Rand( random )
LOCAL negative, ttx, ttj, tty, ttk, ttl, ttz, tts, ttt, rett
negative := ( random < 0 )
IF random == 0
RETURN 0
ENDIF
random := Abs( random )
ttx := Seconds() / 100
ttj := ( ttx - Int( ttx ) ) * 100
tty := Log( Sqrt( Seconds() / 100 ) )
ttk := ( tty - Int( tty ) ) * 100
ttl := ttj * ttk
ttz := ttl - Int( ttl )
tts := random * ttz
ttt := Round( tts, 2 )
rett := Int( ttt ) + iif( Int( ttt ) + 1 < random + 1, 1, 0 )
RETURN ( rett * iif( negative, -1, 1 ) )
//========================================================================
// EXTRAE UNA PALABRA DE UN STRING
//========================================================================
FUNCTION US_Word( estring, posicion )
LOCAL cont := 1
IF posicion == NIL
posicion := 1
ENDIF
estring := AllTrim( estring )
DO WHILE .T.
IF AT( " ", estring ) == 0
RETURN iif( posicion == cont, estring, "" )
ELSEIF cont == posicion
RETURN SubStr( estring, 1, At( " ", estring ) - 1 )
ENDIF
estring := AllTrim( SubStr( estring, At( " ", estring ) + 1 ) )
cont ++
ENDDO
RETURN ""
//========================================================================
// ELIMINAR UNA PALABRA DE UN STRING
//========================================================================
FUNCTION US_WordDel( estring, posicion )
RETURN iif( posicion > 0, ;
AllTrim( SubStr( estring, 1, US_WordInd( estring, posicion ) - 1 ) + ;
StrTran( SubStr( estring, US_WordInd( estring, posicion ) ), US_Word( estring, posicion ), " ", 1, 1 ) ), ;
estring )
//========================================================================
// RETORNA LA POSICION DONDE EMPIEZA LA PALABRA numero
//========================================================================
FUNCTION US_WordInd( estring, numero )
LOCAL cont, estr, estr2
IF estring == NIL
estring := ""
ENDIF
IF US_Words( estring ) < numero
RETURN ( Len( estring ) + 1 )
ENDIF
cont := 1
estr := estring
estr2 := RTrim( estring )
estring := AllTrim( estring )
DO WHILE .T.
IF At( " ", estring ) == 0
RETURN iif( numero == cont, Len( estr ) - ( Len( estring ) + ( Len( estr ) - Len( estr2 ) ) ) + 1, 0 )
ELSEIF cont == numero
RETURN ( Len( estr ) - ( Len( estring ) + ( Len( estr ) - Len( estr2 ) ) ) + 1 )
ENDIF
estring := AllTrim( SubStr( estring, At( " ", estring ) + 1 ) )
cont ++
ENDDO
RETURN 0
//========================================================================
// CUENTA LAS PALABRAS EN UN STRING
//========================================================================
FUNCTION US_Words( estring )
LOCAL cont := 0
IF estring == NIL
estring := ""
ENDIF
estring := AllTrim( estring)
DO WHILE .T.
IF At( " ", estring ) == 0
RETURN iif( Len( estring ) > 0, cont + 1, cont )
ENDIF
estring := AllTrim( SubStr( estring, At( " ", estring ) + 1 ) )
cont ++
ENDDO
RETURN 0
//========================================================================
// ESCRIBE EN EL LOG
//========================================================================
STATIC FUNCTION QPM_Log( string )
LOCAL LogArchi := cQPMDir + "QPM.LOG"
LOCAL msg := DToS( Date() ) + " " + Time() + " US_SLASH " + 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 */