-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvfpscm.PRG
232 lines (212 loc) · 5.68 KB
/
vfpscm.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
*
* class to convert vfp forms into xmls and viceverza
*
* some methods taked from
* http://vfpx.codeplex.com/wikipage?title=Alternate%20SCCText
*
*
define class vfpscm as custom
*
* creates an xml representation from a form
*
function scx2xml(cFileScx, cFileXml)
* crear una copia de la forma, en el cursor llamado scxrecord
use (cFileScx) in 0 shared alias thetable
if select('thetable')==0
return
endif
select * from thetable into cursor record readwrite
select thetable
use
select record
* limpiar codigo compilado y ordenar propiedades y metodos
replace ;
objcode with '',;
ole with iif(empty(ole),'',strconv(ole, 13)),;
properties with this.sortproperties(properties) ,;
methods with this.sortmethods(methods), ;
reserved3 with this.sortproperties(reserved3) ;
all
*index on this.sortScx() tag x
cursorToXml('',cFileXml,1,512+48)
use
return
*
* creates a form since an xml representation
*
function xml2scx(cFileXml, cFileScx)
this.createNewForm()
xmlToCursor( cFileXml, 'newform', 512+8192)
select newForm
replace ;
ole with iif(empty(ole),'',strconv(ole, 14)),;
properties with this.sortproperties(properties) ,;
methods with this.sortmethods(methods) ,;
reserved3 with this.sortproperties(reserved3) ;
all
*index on this.sortScx() tag x
copy to (cFileScx)
use
if '.vcx' $ lower(cFileScx)
compile classlib(cFileScx)
endif
if '.scx' $ lower(cFileScx)
compile form (cFileScx)
endif
return
*
* creates the table for a new form
*
function createNewForm
create cursor newform ( ;
platform c(8),;
uniqueid c(10),;
timestamp n(10),;
class m(4),;
classloc m(4),;
baseclass m(4),;
objname m(4),;
parent m(4),;
properties m(4),;
protected m(4),;
methods m(4),;
objcode m(4),;
ole m(4),;
ole2 m(4),;
reserved1 m(4),;
reserved2 m(4),;
reserved3 m(4),;
reserved4 m(4),;
reserved5 m(4),;
reserved6 m(4),;
reserved7 m(4),;
reserved8 m(4),;
user m(4);
)
return
*
* sortProperties
*
* sort properties in aphabetical order, because vfp change order
*
function sortProperties(cProp)
local cRetVal,nTotLin,nLin
* Si properties es vacio, regresar vacio
if empty(cProp)
return cProp
endif
* Es un grid, dejarlo tal cual
lIsGrid = at('Column1.Name',cProp)>0
lIsPageFrame = at('PageCount',cProp)>0
nTotLin = ALines(aProp,cProp)
* Asegurarme que todas las lineas terminen en CrLf
for nLin=1 to nTotLin
if right(aProp[nLin],2)<>chr(13)+chr(10)
aProp[nLin] = aProp[nLin]+chr(13)+chr(10)
endif
next
if lIsGrid or lIsPageFrame
* No ordenar propiedades cuando el objeto sea el grid
else
* Ordenar las propiedades en orden alfabetico
* aSort(aProp)
endif
* Volver a crear el memo
cRetVal = ''
for nLin=1 to nTotLin
cRetVal = cRetVal + aProp[nLin]
next
return cRetVal
*
* sortMethods
*
* sort methods in aphabetical order
*
function sortMethods(cMethods)
local i,cRetVal,nTotMethods,nLine,nTotLines
nTotMethods = 0
nTotLines = alines(aText,cMethods)
* Recorrer todas las lineas
* Formar el arreglo aMethods con TODO el codigo de cada methodo
* Crear un nuevo elemento del arreglo, cada vez que cambia de metodo
for nLine=1 to nTotLines
if left(aText[nLine],10)=='PROCEDURE '
nTotMethods = nTotMethods + 1
dimension aMethods[nTotMethods]
aMethods[nTotMethods] = ''
endif
if nTotMethods>0
aMethods[nTotMethods] = aMethods[nTotMethods] + allt(aText[nLine]) + chr(13)+chr(10)
endif
next
cRetVal = ''
if nTotMethods>0
asort(aMethods)
for i=1 to nTotMethods
cRetVal = cRetVal + aMethods[i]
next
endif
return cRetVal
*
* Ordena los registros de un scx
* Los primeros 2 son reservados, siempre deben ir al inicio
* El ultimo, siempre es reservado, siempre debe ir al final
* Los demas los ordena en base al nombre. A Excepcion de los encabezados de los grids, los pone antes
*
function sortscx
cRetVal = ''
do case
case allt(UNIQUEID)=='Screen' or allt(UNIQUEID)=='Class'
cRetVal = '1'
case allt(BASECLASS)=='dataenviroment'
cretval = '2'
case empty(OBJNAME)
cRetVal = 'zzzzz'
case not empty(PARENT)
cRetVal = LOWER(TRIM(PARENT) + IIF(EMPTY(PARENT),"",".") + IIF(LOWER(BASECLASS)="header","0","")+LOWER(objname))
case allt(platform)=='COMMENT'
cRetVal = alltrim(OBJNAME) + '.zzzzz'
otherwise
cRetVal = alltrim(OBJNAME)
endcase
return PADR( cRetVal , 100)
* regresa el timestamp mayor de todos los registros del archivo xml
* lo regresa en formato numerico
function getModXml(cFileXml)
local nModXml, cXml, nPos, cTimeStamp
nModXml = 0
if file(cFileXml)
cXml = filetostr(cFileXml)
* obtener mayor timestamp de todos los registros
do while .t.
nPos = at('<timestamp>',cXml)
if nPos==0
exit
endif
cTimeStamp = substr(cXml, nPos+11, 20)
cTimeStamp = substr(cTimeStamp, 1, at('<', cTimeStamp)-1)
nModXml = max(nModXml, val(cTimeStamp))
cXml = substr(cXml, nPos + 11)
enddo
endif
return nModXml
* regresa la fecha de creacion y modificacion del scx
function getModScx (cFileScx, nCreated, nModified)
nCreated = 0
nModified = 0
if file(cFileScx)
use (cFileScx) shared alias theform in 0
select theform
scan
if theform.timestamp>0
if nCreated=0
nCreated = theform.timestamp
endif
nCreated = min(nCreated, theform.timestamp)
endif
nModified = max(nModified, theform.timestamp)
endscan
use
endif
return
enddefine