-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoxrefengine.prg
4252 lines (3555 loc) · 107 KB
/
foxrefengine.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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
* Abstract...:
* Primary class for Code References application.
*
* Changes....:
*
#include "foxpro.h"
#include "foxref.h"
DEFINE CLASS FoxRef AS Session
PROTECTED lIgnoreErrors AS Boolean
PROTECTED lRefreshMode
PROTECTED cProgressForm
PROTECTED lCancel
PROTECTED tTimeStamp
PROTECTED lIgnoreErrors
Name = "FoxRef"
* search match engines
MatchClass = "MatchDefault"
MatchClassLib = "foxmatch.prg"
WildMatchClass = "MatchWildcard"
WildMatchClassLib = "foxmatch.prg"
* default search engine for Open Window
FindWindowClass = "RefSearchWindow"
FindWindowClassLib = "FoxRefSearch_Window.prg"
oSearchEngine = .NULL.
oWindowEngine = .NULL.
WindowHandle = -1
WindowFilename = ''
WindowLineNo = 0
Comments = COMMENTS_INCLUDE
MatchCase = .F.
WholeWordsOnly = .F.
ProjectHomeDir = .F. && True to search only files in Project's Home Directory or below
SubFolders = .F.
Wildcards = .F.
Quiet = .F. && quiet mode -- don't display search progress
ShowProgress = .T. && show a progress form
Errors = .NULL.
FileTypes = ''
ReportFile = REPORT_FILE
XSLTemplate = "foxref.xsl"
* MRU array lists
DIMENSION aLookForMRU[10]
DIMENSION aReplaceMRU[10]
DIMENSION aFolderMRU[10]
DIMENSION aFileTypesMRU[10]
DIMENSION aDefaultFileTypes[1]
aLookForMRU = ''
aReplaceMRU = ''
aFolderMRU = ''
aFileTypesMRU = ''
Pattern = ''
OverwritePrior = .T.
ConfirmReplace = .T. && confirm each replacement
BackupOnReplace = .T. && false to not backup when doing global replace
DisplayReplaceLog = .T. && create activity log for replacements
PreserveCase = .F. && preserve case during a Replace operation
FoxRefDirectory = ''
RefTable = ''
DefTable = ''
FileTable = ''
AddInTable = ''
ProjectFile = ''
FileDirectory = ''
ActivityLog = ''
* The following are set by the Options dialog
* There should be a corresponding entry in FoxRefOption.DBF
* (except for BackupStyle & FontString)
IncludeDefTable = .T. && create Definition table when searching
CodeOnly = .F. && search only source code & expressions (not names and other none-code items)
FormProperties = .T. && search form/class property names & values
AutoProjectHomeDir = .F. && True to search only files in Project's Home Directory or below when doing definitions automatically
ShowRefsPerLine = .F. && display a column in search results that depicts number of references found on the line
ShowFileTypeHistory = .F. && True to keep filetype history in addition to showing common filetypes in search dialog
ShowDistinctMethodLine = .F. && True to show columns for method/line apart from Class
SortMostRecentFirst = .F.
BackupStyle = 1 && 1 = "filename.ext.bak" 2 = "Backup of filename.ext"
FontString = FONT_DEFAULT
* XML Export Options
XMLFormat = XMLFORMAT_ELEMENTS
XMLSchema = .T.
* This is the SetID for the last Replacement Log after it's saved
ReplaceLogSetID = ''
* properties used internally
cSetID = ''
lRefreshMode = .F.
lIgnoreErrors = .F.
oProgressForm = .NULL.
lCancel = .F.
tTimeStamp = .NULL.
lDefinitionsOnly = .F.
* collection of files we've backed up in this session
oBackupCollection = .NULL.
oFileCollection = .NULL.
oSearchCollection = .NULL.
oProcessedCollection = .NULL.
oEngineCollection = .NULL.
oReportCollection = .NULL.
oFileTypeCollection = .NULL.
cTalk = ''
nLangOpt = 0
cEscapeState = ''
cSYS3054 = ''
cSaveUDFParms = ''
cSaveLib = ''
cExclusive = ''
cCompatible = ''
oOptions = .NULL.
lInitError = .F.
oProjectFileRef = .NULL.
PROCEDURE Init(lRestorePrefs)
LOCAL nSelect
LOCAL oException
LOCAL cAddInType
LOCAL nMemoWidth
THIS.cTalk = SET("TALK")
SET TALK OFF
SET DELETED ON
THIS.cCompatible = SET("COMPATIBLE")
SET COMPATIBLE OFF
THIS.cExclusive = SET("EXCLUSIVE")
SET EXCLUSIVE OFF
THIS.nLangOpt = _VFP.LanguageOptions
_VFP.LanguageOptions = 0
THIS.cEscapeState = SET("ESCAPE")
SET ESCAPE OFF
THIS.cSYS3054 = SYS(3054)
SYS(3054,0)
THIS.cSaveLib = SET("LIBRARY")
THIS.cSaveUDFParms = SET("UDFPARMS")
SET UDFPARMS TO VALUE
SET EXACT OFF
* Changed on 02/14/2002 06:13:18 PM by Ryan - moved to FoxRefStart.prg
* THIS.RestorePrefs()
* collection of errors
THIS.Errors = NEWOBJECT("CFoxRefCollection", "FoxRefCollection.prg")
* create a collection that contains the files we've backup up
THIS.oBackupCollection = NEWOBJECT("CFoxRefCollection", "FoxRefCollection.prg")
THIS.oFileCollection = NEWOBJECT("CFoxRefCollection", "FoxRefCollection.prg")
THIS.oSearchCollection = NEWOBJECT("CFoxRefCollection", "FoxRefCollection.prg")
THIS.oProcessedCollection = CREATEOBJECT("Collection")
THIS.oEngineCollection = CREATEOBJECT("Collection")
THIS.oReportCollection = CREATEOBJECT("Collection")
THIS.oFileTypeCollection = CREATEOBJECT("Collection") && default filetypes from FoxRefAddin
THIS.oOptions = NEWOBJECT("FoxResource", "FoxResource.prg")
IF m.lRestorePrefs
THIS.RestorePrefs()
ENDIF
THIS.FoxRefDirectory = THIS.FoxRefDirectory
ENDFUNC
PROCEDURE Destroy()
LOCAL cCompatible
THIS.CloseProgress()
IF THIS.cEscapeState = "ON"
SET ESCAPE ON
ENDIF
IF THIS.cTalk = "ON"
SET TALK ON
ENDIF
IF THIS.cExclusive = "ON"
SET EXCLUSIVE ON
ENDIF
SYS(3054,INT(VAL(THIS.cSYS3054)))
_VFP.LanguageOptions = THIS.nLangOpt
IF THIS.cSaveUDFParms = "REFERENCE"
SET UDFPARMS TO REFERENCE
ENDIF
m.cCompatible = THIS.cCompatible
SET COMPATIBLE &cCompatible
ENDFUNC
FUNCTION FoxRefDirectory_Assign(cFoxRefDirectory)
m.cFoxRefDirectory = ADDBS(m.cFoxRefDirectory)
IF EMPTY(m.cFoxRefDirectory) OR !DIRECTORY(m.cFoxRefDirectory)
m.cFoxRefDirectory = ADDBS(HOME(7))
IF !DIRECTORY(m.cFoxRefDirectory)
m.cFoxRefDirectory = ADDBS(HOME())
ENDIF
ENDIF
THIS.FoxRefDirectory = m.cFoxRefDirectory
THIS.DefTable = THIS.FoxRefDirectory + DEF_TABLE
THIS.FileTable = THIS.FoxRefDirectory + FILE_TABLE
THIS.AddInTable = THIS.FoxRefDirectory + ADDIN_TABLE
THIS.InitAddIns()
THIS.OpenTables()
ENDFUNC
* Open the Add In table which contains our filetypes to process
FUNCTION InitAddIns(lExclusive)
LOCAL nSelect
LOCAL nMemoWidth
LOCAL cAddInType
m.nSelect = SELECT()
* if we don't find the AddIn table on disk, then copy out
* our project version of it
IF !FILE(FORCEEXT(THIS.AddInTable, "DBF"))
TRY
USE FoxRefAddin IN 0 SHARED AGAIN
SELECT FoxRefAddIn
COPY TO (THIS.AddInTable) WITH PRODUCTION
CATCH
FINALLY
IF USED("FoxRefAddin")
USE IN FoxRefAddIn
ENDIF
ENDTRY
ENDIF
TRY
IF m.lExclusive
USE (THIS.AddInTable) ALIAS AddInCursor IN 0 EXCLUSIVE
ELSE
USE (THIS.AddInTable) ALIAS AddInCursor IN 0 SHARED AGAIN
ENDIF
CATCH
ENDTRY
IF !USED("AddInCursor")
* we didn't find the Add-In table on disk, so use our built-in version
TRY
USE FoxRefAddIn ALIAS AddInCursor IN 0 SHARED AGAIN
CATCH
ENDTRY
ENDIF
* process AddIn table
THIS.oEngineCollection = CREATEOBJECT("Collection")
THIS.oReportCollection = CREATEOBJECT("Collection")
THIS.oFileTypeCollection = CREATEOBJECT("Collection") && default filetypes from FoxRefAddin
THIS.AddFileType("*.*", FILETYPE_CLASS_DEFAULT, FILETYPE_LIBRARY_DEFAULT)
IF USED("AddInCursor")
m.nMemoWidth = SET("MEMOWIDTH")
SET MEMOWIDTH TO 1000
* setup file types
SELECT AddInCursor
SCAN ALL
m.cAddInType = RTRIM(AddInCursor.Type)
DO CASE
CASE m.cAddInType == ADDINTYPE_FINDFILE
THIS.AddFileType(AddInCursor.Data, AddInCursor.ClassName, AddInCursor.ClassLib)
CASE m.cAddInType == ADDINTYPE_IGNOREFILE
THIS.AddFileType(AddInCursor.Data)
CASE m.cAddInType == ADDINTYPE_FINDWINDOW
IF !EMPTY(AddInCursor.ClassName)
THIS.FindWindowClass = AddInCursor.ClassName
THIS.FindWindowClassLib = AddInCursor.ClassLib
ENDIF
CASE m.cAddInType == ADDINTYPE_MATCH
IF !EMPTY(AddInCursor.ClassName)
THIS.MatchClass = AddInCursor.ClassName
THIS.MatchClassLib = AddInCursor.ClassLib
ENDIF
CASE m.cAddInType == ADDINTYPE_WILDMATCH
IF !EMPTY(AddInCursor.ClassName)
THIS.WildMatchClass = AddInCursor.ClassName
THIS.WildMatchClassLib = AddInCursor.ClassLib
ENDIF
CASE m.cAddInType == ADDINTYPE_REPORT
THIS.AddReport(AddInCursor.Data, AddInCursor.ClassLib, AddInCursor.ClassName, AddInCursor.Method, AddInCursor.Filename)
CASE m.cAddInType == ADDINTYPE_FILETYPE
THIS.oFileTypeCollection.Add(AddInCursor.Data)
ENDCASE
ENDSCAN
SET MEMOWIDTH TO (m.nMemoWidth)
ENDIF
SELECT (m.nSelect)
ENDFUNC
PROCEDURE FontString_Access
IF EMPTY(THIS.FontString)
RETURN FONT_DEFAULT
ELSE
RETURN THIS.FontString
ENDIF
ENDPROC
* Add another file to process definitions for
* These are files that aren't in our normal
* scope processing, but are discovered along the
* way, such as #include
FUNCTION AddFileToProcess(cFilename)
IF FILE(m.cFilename)
THIS.oFileCollection.AddNoDupe(LOWER(FULLPATH(m.cFilename)))
ENDIF
ENDFUNC
* Add a file to search -- these are files that aren't
* in our normal scope processing, but we search anyhow,
* such as a Table within a DBC when searching a project
FUNCTION AddFileToSearch(cFilename)
IF FILE(m.cFilename)
THIS.oSearchCollection.AddNoDupe(LOWER(FULLPATH(m.cFilename)))
ENDIF
ENDFUNC
* Add a report from the Add-Ins
FUNCTION AddReport(cReportName, cClassLib, cClassName, cMethod, cFilename)
LOCAL oReportAddIn
oReportAddIn = NEWOBJECT("ReportAddIn")
oReportAddIn.ReportName = m.cReportName
oReportAddIn.RptClassLibrary = m.cClassLib
oReportAddIn.RptClassName = m.cClassName
oReportAddIn.RptMethod = m.cMethod
oReportAddIn.RptFilename = m.cFilename
TRY
THIS.oReportCollection.Add(oReportAddIn, m.cReportName)
CATCH
ENDTRY
ENDFUNC
* Add a filetype search
FUNCTION AddFileType(cFileSkeleton, cClassName, cClassLibrary)
LOCAL nIndex
LOCAL lSuccess
LOCAL oEngine
IF VARTYPE(m.cClassName) <> 'C'
m.cClassName = ''
ENDIF
m.cFileSkeleton = UPPER(ALLTRIM(m.cFileSkeleton))
IF EMPTY(m.cFileSkeleton)
m.cFileSkeleton = "*.*"
ENDIF
FOR m.i = 1 TO THIS.oEngineCollection.Count
IF THIS.oEngineCollection.GetKey(m.i) == m.cFileSkeleton
THIS.oEngineCollection.Remove(m.i)
EXIT
ENDIF
ENDFOR
IF EMPTY(m.cClassName)
THIS.oEngineCollection.Add(.NULL., m.cFileSkeleton)
ELSE
TRY
m.oEngine = NEWOBJECT(m.cClassName, m.cClassLibrary)
CATCH
m.oEngine = .NULL.
FINALLY
ENDTRY
IF !ISNULL(oEngine)
IF m.cFileSkeleton = "*.*" AND THIS.oEngineCollection.Count > 0
THIS.oEngineCollection.Add(m.oEngine, m.cFileSkeleton, 1)
ELSE
THIS.oEngineCollection.Add(m.oEngine, m.cFileSkeleton)
ENDIF
ENDIF
ENDIF
RETURN m.lSuccess
ENDFUNC
* Initialize all of the search engines
* with our search options
PROCEDURE SearchInit()
LOCAL i
LOCAL oException
LOCAL nSelect
LOCAL lSuccess
nSelect = SELECT()
THIS.ClearErrors()
m.oException = .NULL.
m.lSuccess = .T.
THIS.oProcessedCollection.Remove(-1)
TRY
IF THIS.Wildcards
THIS.oSearchEngine = NEWOBJECT(THIS.WildMatchClass, THIS.WildMatchClassLib)
ELSE
THIS.oSearchEngine = NEWOBJECT(THIS.MatchClass, THIS.MatchClassLib)
ENDIF
m.lSuccess = THIS.oSearchEngine.InitEngine()
CATCH TO oException
m.lSuccess = .F.
MessageBox(m.oException.Message, MB_ICONEXCLAMATION, APPNAME_LOC)
ENDTRY
IF m.lSuccess
THIS.oSearchEngine.MatchCase = THIS.MatchCase
THIS.oSearchEngine.WholeWordsOnly = THIS.WholeWordsOnly
IF THIS.oSearchEngine.SetPattern(THIS.Pattern)
* IF THIS.WindowHandle >= 0
* this create the engine for searching open windows
TRY
THIS.oWindowEngine = NEWOBJECT(THIS.FindWindowClass, THIS.FindWindowClassLib)
CATCH TO oException
MessageBox(m.oException.Message + CHR(10) + CHR(10) + THIS.FindWindowClass + " (" + THIS.FindWindowClassLib + ")", MB_ICONSTOP, APPNAME_LOC)
ENDTRY
IF VARTYPE(THIS.oWindowEngine) == 'O'
WITH THIS.oWindowEngine
.SetID = THIS.cSetID
.oSearchEngine = THIS.oSearchEngine
.Pattern = THIS.Pattern
.Comments = THIS.Comments
.IncludeDefTable = THIS.IncludeDefTable
.FormProperties = THIS.FormProperties
.CodeOnly = THIS.CodeOnly
.PreserveCase = THIS.PreserveCase
ENDWITH
ENDIF
* ENDIF
* collection of engines for various filetypes
FOR m.i = 1 TO THIS.oEngineCollection.Count
IF VARTYPE(THIS.oEngineCollection.Item(m.i)) == 'O'
WITH THIS.oEngineCollection.Item(m.i)
.SetID = ''
.oSearchEngine = THIS.oSearchEngine
.Pattern = THIS.Pattern
.Comments = THIS.Comments
.IncludeDefTable = THIS.IncludeDefTable
.FormProperties = THIS.FormProperties
.CodeOnly = THIS.CodeOnly
.PreserveCase = THIS.PreserveCase
ENDWITH
ENDIF
ENDFOR
ELSE
m.lSuccess = .F.
MessageBox(ERROR_PATTERN_LOC, MB_ICONEXCLAMATION, APPNAME_LOC)
ENDIF
ENDIF
RETURN m.lSuccess
ENDPROC
* Global Replace on all checked files in current RefTable
FUNCTION GlobalReplace(cReplaceText)
LOCAL nSelect
LOCAL i
LOCAL j
LOCAL nReplaceCnt
LOCAL nRefCnt
LOCAL nFileCnt
LOCAL cDescription
LOCAL cOriginalText
LOCAL cModifiedText
LOCAL cOriginalHTML
LOCAL cModifiedHTML
LOCAL nUpdateCnt
LOCAL cFilename
LOCAL nSaveSYS3099
LOCAL nReplaceIndex
LOCAL nLastPos
LOCAL ARRAY aReplaceFiles[1]
LOCAL ARRAY aRefList[1]
LOCAL ARRAY aReplaceList[1]
m.nSelect = SELECT()
THIS.ClearErrors()
THIS.ActivityLog = ''
m.nUpdateCnt = 0
* we must replace in reverse order
* for example, by line # descending, then by column descending
IF !USED("RefFile")
USE (THIS.FileTable) ALIAS RefFile IN 0 SHARED AGAIN
ENDIF
* process by file so we can check to make sure
* the file hasn't changed between when we did
* our search and now
SELECT DISTINCT ;
RefTable.FileID, ;
RefTable.TimeStamp, ;
FileTable.UniqueID, ;
PADR(FileTable.Folder, 240) AS SortFolder, ;
FileTable.Filename ;
FROM (THIS.RefTable) RefTable INNER JOIN (THIS.FileTable) FileTable ON RefTable.FileID == FileTable.UniqueID ;
WHERE Checked AND !Inactive ;
ORDER BY SortFolder, Filename ;
INTO ARRAY aReplaceFiles
m.nFileCnt = _TALLY
FOR m.i = 1 TO nFileCnt
IF SEEK(aReplaceFiles[m.i, 3], "RefFile", "UniqueID")
m.cFilename = ADDBS(RTRIM(RefFile.Folder)) + RTRIM(RefFile.Filename)
IF FILE(m.cFilename)
IF FDATE(m.cFilename, 1) == aReplaceFiles[m.i, 2] && check timestamp on file
* this groups replacements into ones that occur on the same line
m.nSaveSYS3099 = SYS(3099)
SYS(3099, 70)
SELECT RefID ;
FROM (THIS.RefTable) ;
WHERE FileID == aReplaceFiles[m.i, 1] AND Checked AND !Inactive ;
GROUP BY RefID ;
ORDER BY ColPos DESCEND ;
INTO ARRAY aRefList
m.nRefCnt = _TALLY
SYS(3099, m.nSaveSYS3099)
FOR m.j = 1 TO m.nRefCnt
SELECT UniqueID, Abstract, ColPos, MatchLen, ClassName, ProcName, ProcLineNo, FindType ;
FROM (THIS.RefTable) ;
WHERE RefID == aRefList[m.j, 1] ;
ORDER BY ColPos DESCEND ;
INTO ARRAY aReplaceList
m.nReplaceCnt = _TALLY
IF m.nReplaceCnt > 0
* get the original and the modified text so we
* can show it in our confirmation dialog
m.cOriginalText = aReplaceList[1, 2]
m.cModifiedText = m.cOriginalText
m.cOriginalHTML = m.cOriginalText
m.cModifiedHTML = m.cModifiedText
FOR m.nReplaceIndex = 1 TO m.nReplaceCnt
m.nLastPos = aReplaceList[m.nReplaceIndex, 3] + aReplaceList[m.nReplaceIndex, 4]
m.cOriginalHTML = LEFTC(m.cOriginalHTML, aReplaceList[m.nReplaceIndex, 3] - 1) + [<font color="blue">] + SUBSTRC(m.cOriginalHTML, aReplaceList[m.nReplaceIndex, 3], aReplaceList[m.nReplaceIndex, 4]) + [</font>] + ;
IIF(m.nLastPos > LENC(m.cOriginalHTML), '', SUBSTRC(m.cOriginalHTML, m.nLastPos))
m.cModifiedHTML = LEFTC(m.cModifiedHTML, aReplaceList[m.nReplaceIndex, 3] - 1) + [<font color="blue">] + IIF(THIS.PreserveCase, THIS.SetCasePreservation(SUBSTRC(m.cModifiedHTML, aReplaceList[m.nReplaceIndex, 3], aReplaceList[m.nReplaceIndex, 4]), m.cReplaceText), m.cReplaceText) + [</font>] + ;
IIF(m.nLastPos > LENC(m.cModifiedHTML), '', SUBSTRC(m.cModifiedHTML, m.nLastPos))
ENDFOR
* this is the description of the filename, class.method we're replacing on
m.cDescription = m.cFilename + ", " + ;
IIF(EMPTY(aReplaceList[1, 5]) AND EMPTY(aReplaceList[1, 6]), '', ;
aReplaceList[1, 5] + IIF(EMPTY(aReplaceList[1, 5]) OR EMPTY(aReplaceList[1, 6]), '', '.') + aReplaceList[1, 6]) + ;
IIF(aReplaceList[1, 7] == 0, '', IIF(EMPTY(aReplaceList[1,5] + aReplaceList[1,6]), '', ", ") + LTRIM(STR(aReplaceList[1, 7], 8, 0)))
IF THIS.ConfirmReplace
DO FORM FoxRefReplaceConfirm WITH m.cDescription, m.cOriginalHTML, m.cModifiedHTML TO m.lDoReplace
IF ISNULL(m.lDoReplace)
EXIT
ENDIF
ELSE
m.lDoReplace = .T.
ENDIF
IF m.lDoReplace
THIS.AddLog(LOG_PREFIX + m.cDescription + ':')
THIS.AddLog(LOG_PREFIX + m.cOriginalHTML + " -> " + m.cModifiedHTML)
IF THIS.ReplaceFile(aRefList[m.j, 1], m.cReplaceText)
m.nUpdateCnt = m.nUpdateCnt + 1
ENDIF
ELSE
THIS.AddLog(LOG_PREFIX + m.cDescription + ": " + REPLACE_SKIPPED)
ENDIF
THIS.AddLog()
ENDIF
ENDFOR
ELSE
* timestamps don't match
THIS.AddError(m.cFilename + ": " + ERROR_FILEMODIFIED_LOC)
THIS.AddLog(LOG_PREFIX + m.cFilename + ": " + ERROR_FILEMODIFIED_LOC)
ENDIF
ELSE
* file not found
THIS.AddError(m.cFilename + ": " + ERROR_FILENOTFOUND_LOC)
THIS.AddLog(LOG_PREFIX + m.cFilename + ": " + ERROR_FILENOTFOUND_LOC)
ENDIF
ENDIF
ENDFOR
THIS.SaveLog(m.cReplaceText)
SELECT (m.nSelect)
RETURN m.nUpdateCnt > 0
ENDFUNC
* take the original text, determine the case,
* and apply it the new text
FUNCTION SetCasePreservation(cOriginalText, cReplacementText)
LOCAL i
LOCAL ch
LOCAL lLower
LOCAL lUpper
IF ISUPPER(LEFTC(m.cOriginalText, 1)) AND ISLOWER(SUBSTRC(m.cOriginalText, 2, 1))
* proper case
m.cReplacementText = PROPER(m.cReplacementText)
ELSE
m.lLower = .F.
m.lUpper = .F.
FOR m.i = 1 TO LENC(m.cOriginalText)
ch = SUBSTRC(m.cOriginalText, m.i, 1)
DO CASE
CASE BETWEEN(ch, 'A', 'Z')
m.lUpper = .T.
CASE BETWEEN(ch, 'a', 'z')
m.lLower = .T.
ENDCASE
IF m.lLower AND m.lUpper
EXIT
ENDIF
ENDFOR
DO CASE
CASE m.lLower AND !m.lUpper
m.cReplacementText = LOWER(m.cReplacementText)
CASE !m.lLower AND m.lUpper
m.cReplacementText = UPPER(m.cReplacementText)
ENDCASE
ENDIF
RETURN m.cReplacementText
ENDFUNC
* Do a replacement on designated file
FUNCTION ReplaceFile(cRefID, cReplaceText, lBackupOnReplace)
LOCAL nSelect
LOCAL oFoxRefRecord
LOCAL lSuccess
LOCAL oEngine
LOCAL lBackup
LOCAL cFilename
LOCAL oException
LOCAL oReplaceCollection
m.lSuccess = .F.
IF USED("FoxRefCursor") AND VARTYPE(cRefID) == 'C'
m.nSelect = SELECT()
IF PCOUNT() < 3 OR VARTYPE(m.lBackupOnReplace) <> 'L'
m.lBackupOnReplace = THIS.BackupOnReplace
ENDIF
IF SEEK(m.cRefID, "FoxRefCursor", "RefID")
IF USED("FileCursor") AND SEEK(FoxRefCursor.FileID, "FileCursor", "UniqueID")
m.cFilename = ADDBS(RTRIM(FileCursor.Folder)) + RTRIM(FileCursor.Filename)
IF FILE(m.cFilename)
m.oEngine = THIS.GetEngine(JUSTFNAME(m.cFilename))
* if we don't have an engine object defined, then assume
* we're supposed to ignore this filetype
IF VARTYPE(m.oEngine) == 'O'
WITH m.oEngine
.PreserveCase = THIS.PreserveCase
m.lSuccess = .T.
* create a backup of the file if we haven't already
* done so in this session
IF m.lBackupOnReplace
* m.cFilename = ADDBS(RTRIM(m.oFoxRefRecord.Folder)) + RTRIM(m.oFoxRefRecord.Filename)
m.lBackup = .T.
FOR m.i = 1 TO THIS.oBackupCollection.Count
IF THIS.oBackupCollection.Item(m.i) == UPPER(m.cFilename)
m.lBackup = .F.
EXIT
ENDIF
ENDFOR
IF m.lBackup
IF .BackupFile(m.cFilename, THIS.BackupStyle)
* add to collection so we don't backup again during this session
THIS.oBackupCollection.Add(UPPER(m.cFilename))
ELSE
m.lSuccess = .F.
THIS.AddError(m.cFilename + ": " + ERROR_NOBACKUP_LOC)
ENDIF
ENDIF
ENDIF
* do the replace
IF m.lSuccess
oReplaceCollection = CREATEOBJECT("Collection")
SELECT FoxRefCursor
SCAN ALL FOR RefID == cRefID
SCATTER MEMO NAME oFoxRefRecord
oReplaceCollection.Add(oFoxRefRecord)
ENDSCAN
m.oException = .ReplaceWith(m.cReplaceText, m.oReplaceCollection, m.cFilename)
IF !ISNULL(m.oException)
m.lSuccess = .F.
THIS.AddError(m.cFilename + ": " + IIF(EMPTY(m.oException.UserValue), m.oException.Message, m.oException.UserValue))
THIS.AddLog(LOG_PREFIX + ERROR_LOC + ": " + IIF(EMPTY(m.oException.UserValue), m.oException.Message, m.oException.UserValue))
ENDIF
THIS.AddLog(.ReplaceLog)
ENDIF
ENDWITH
ELSE
THIS.AddError(m.cFilename + ": " + ERROR_NOENGINE_LOC)
ENDIF
ELSE
THIS.AddError(m.cFilename + ": " + ERROR_FILENOTFOUND_LOC)
ENDIF
ENDIF
ENDIF
SELECT (m.nSelect)
ENDIF
RETURN m.lSuccess
ENDFUNC
* Methods for updating Errors collection
PROCEDURE ClearErrors()
THIS.Errors.Remove(-1)
ENDPROC
PROCEDURE AddError(cErrorMsg)
THIS.Errors.Add(cErrorMsg)
ENDPROC
PROCEDURE AddLog(cLog)
IF PCOUNT() == 0
IF !EMPTY(THIS.ActivityLog)
THIS.ActivityLog = THIS.ActivityLog + CHR(13) + CHR(10)
ENDIF
ELSE
IF !EMPTY(m.cLog)
THIS.ActivityLog = THIS.ActivityLog + m.cLog + CHR(13) + CHR(10)
ENDIF
ENDIF
ENDPROC
* Save replacement log
FUNCTION SaveLog(cReplaceText)
IF VARTYPE(m.cReplaceText) <> 'C'
m.cReplaceText = ''
ENDIF
THIS.ReplaceLogSetID = SYS(2015)
INSERT INTO FoxRefCursor ( ;
UniqueID, ;
SetID, ;
RefID, ;
RefType, ;
FileID, ;
Symbol, ;
ClassName, ;
ProcName, ;
ProcLineNo, ;
LineNo, ;
ColPos, ;
MatchLen, ;
Abstract, ;
RecordID, ;
UpdField, ;
Checked, ;
NoReplace, ;
Timestamp, ;
Inactive ;
) VALUES ( ;
SYS(2015), ;
THIS.ReplaceLogSetID, ;
SYS(2015), ;
REFTYPE_LOG, ;
'', ;
m.cReplaceText, ;
'', ;
'', ;
0, ;
0, ;
0, ;
0, ;
THIS.ActivityLog, ;
'', ;
'', ;
.F., ;
.F., ;
DATETIME(), ;
.F. ;
)
ENDFUNC
* Make sure the Filetypes list is delimited with spaces
PROCEDURE FileTypes_Assign(cFileTypes)
THIS.FileTypes = CHRTRAN(cFileTypes, ',;', ' ')
ENDFUNC
* ---
* --- Definition Table methods
* ---
FUNCTION CreateFileTable()
LOCAL lSuccess
LOCAL cSafety
m.lSuccess = .T.
m.cSafety = SET("SAFETY")
SET SAFETY OFF
IF USED(JUSTSTEM(THIS.FileTable))
USE IN (THIS.FileTable)
ENDIF
TRY
CREATE TABLE (THIS.FileTable) FREE ( ;
UniqueID C(10), ;
Folder M, ;
Filename C(100), ;
FileAction C(1), ;
Timestamp T NULL ;
)
CATCH
m.lSuccess = .F.
MESSAGEBOX(ERROR_CREATEFILETABLE_LOC + CHR(10) + CHR(10) + FORCEEXT(THIS.FileTable, "DBF"), MB_ICONSTOP, APPNAME_LOC)
ENDTRY
IF m.lSuccess
* insert a record that represents open windows
INSERT INTO (THIS.FileTable) ( ;
UniqueID, ;
Filename, ;
Folder, ;
Timestamp, ;
FileAction ;
) VALUES ( ;
"WINDOW", ;
OPENWINDOW_LOC, ;
'', ;
DATETIME(), ;
FILEACTION_NODEFINITIONS ;
)
INDEX ON UniqueID TAG UniqueID
INDEX ON Filename TAG Filename
INDEX ON FileAction TAG FileAction
USE IN (JUSTSTEM(THIS.FileTable))
ENDIF
SET Safety &cSafety
RETURN m.lSuccess
ENDFUNC
FUNCTION CreateDefTable()
LOCAL lSuccess
LOCAL cSafety
m.lSuccess = .T.
m.cSafety = SET("SAFETY")
SET SAFETY OFF
IF USED(JUSTSTEM(THIS.DefTable))
USE IN (THIS.DefTable)
ENDIF
TRY
CREATE TABLE (THIS.DefTable) FREE ( ;
UniqueID C(10), ;
DefType C(1), ;
FileID C(10), ;
Symbol M, ;
ClassName M, ;
ProcName M, ;
ProcLineNo I, ;
LineNo I, ;
Abstract M, ;
Inactive L ;
)
CATCH
m.lSuccess = .F.
MESSAGEBOX(ERROR_CREATEDEFTABLE_LOC + CHR(10) + CHR(10) + FORCEEXT(THIS.DefTable, "DBF"), MB_ICONSTOP, APPNAME_LOC)
ENDTRY
IF m.lSuccess
INDEX ON UniqueID TAG UniqueID
INDEX ON DefType TAG DefType
INDEX ON Inactive TAG Inactive
INDEX ON FileID TAG FileID
USE IN (JUSTSTEM(THIS.DefTable))
ENDIF
SET Safety &cSafety
RETURN m.lSuccess
ENDFUNC
* Open a File & Definition tables
FUNCTION OpenTables(lExclusive, lQuiet)
LOCAL lSuccess
THIS.CloseTables()
m.lSuccess = .T.
IF !FILE(FORCEEXT(THIS.FileTable, "DBF"))
m.lSuccess = THIS.CreateFileTable()
ENDIF
IF m.lSuccess AND !FILE(FORCEEXT(THIS.DefTable, "DBF"))
m.lSuccess = THIS.CreateDefTable()
ENDIF
IF m.lSuccess
* Open the table of files processed
TRY
IF m.lExclusive
USE (THIS.FileTable) ALIAS FileCursor IN 0 EXCLUSIVE
ELSE
USE (THIS.FileTable) ALIAS FileCursor IN 0 SHARED AGAIN
ENDIF
CATCH
ENDTRY