-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdkdiff.cpp
4817 lines (4101 loc) · 157 KB
/
sdkdiff.cpp
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
/*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* Copyright (c) Microsoft Corporation. All Rights Reserved.
*/
/*
* Sdkdiff
*
* file and directory comparisons.
*
* Compare two directories (including all files and subdirs). Look for names
* that are present in both (report all that are not). For files that
* are present in both, produce a line-by-line comparison of the differences
* between the two files (if any).
*
* Overview of Sdkdiff internals - the whole program.
*
* Sdkdiff is built from several modules (a "module" has a .h file
* which describes its interface and a .c file which implements it)
* Apart from THIS comment which tries to give an overview of the whole
* scheme of things, each module is as self-contained as possible.
* This is enforced by the use of opaque data types. Modules cannot
* see each others' internal data structures. Modules are abstract
* data types. The term "Module" (from Modula2) and "Class" (from C++)
* are used synonymously.
*
* Sdkdiff - main program - parse arguments, put up main window,
* handle input, calling other modules as needed
* invoke table class to create the main display and
* service callbacks from the table class.
* Contains global flags for options (e.g. ignore_blanks)
* list - (in gutils) a generalised LIST of anything data type
* has full set of operations for insert, delete, join etc.
* line - a LINE is a numbered line of text. Information is kept to
* allow fast comparisons of LINEs. A LINE can hold a
* link to another LINE. The links are used to connect
* lines in one file to matching lines in the other file.
* file - a FILEDATA represents a file as a file name in the form
* of a DIRITEM and a LIST of LINEs
* scandir - a DIRITEM represents information about a file. (for
* instance its name, whether it has a known checksum whether
* it has a local copy).
* a DIRLIST represents a directory, has information on how to
* get to it (pipename? password? UNC name etc) and
* (within an imbedded DIRECT structure) a LIST of DIRITEMs
* representing the files in the directory and a LIST of
* DIRECTs representing its subdirectories.
* compitem - a COMPITEM is a pair of files together with information
* on how they compare in the form of a breakdown of the
* files into a LIST of matching or non-matching sections.
* Either file can be absent. This module contains the
* file "contrast" algorithm used for the actual comparison
* (Algorithm people see ci_compare then talk to Laurie).
* tree (in gutils) A binary tree. Important because it is what
* gives the file comparison its speed as it makes it
* an "N log N" algorithm rather than "N squared"
* complist - a COMPLIST is the master data structure. It has a DIRLIST
* of the left hand files, a DIRLIST of the right hand files
* and a LIST of COMPITEMs. The left and right hand DIRLISTs
* are working data used to produce the COMPLIST. The LIST
* is displayed as the outline table. Any given COMPITEM can
* be displayed as an expanded item.
* section - a SECTION is a section of a file (first line, last line)
* and information as to what it matches in the other file.
* bar.c - the picture down the left of the screen
* has a WNDPROC. There is no bar.h, neither is there much
* of writeup! ???
* view - Although the COMPLIST is the master state, it doesn't do
* all the work itself. The data is actually displayed by
* the table class which is highly generalised. View
* owns a COMPLIST (and therefore calls upon the functions
* in complist to fill it and interrogate it) and calls
* upon (and is called back by) the functions in table to
* actually display it. Read about table in gutils.h
* table.c (in gutils) a highly generalised system for displaying
* data in rows and columns. The interface is in gutils.h
* read it if you hope to understand view!
* status.c (in gutils) the status line at the top. See gutils.h
*
* The data structures:
* Each "module" owns storage which is an encapsulated data type, inaccessable
* from the outside. Thus COMPLIST holds a list of COMPITEMs, but they are
* pointers to structures whose definitions are out of scope, thus they are
* "just opaque pointers". To access anything in the COMPITEM you have to
* call functions in COMPITEM.C. And so on. The overall scheme of how they
* link together is below. Some things are identified by field name, some by
* type name, some both, some abbreviations. Many connecting arrows omitted.
* Look in the C files for details.
*
* COMPLIST
* > left -----------> DIRLIST <--------------------
* > right -----------> > rootname |
* > LIST of items-- > bFile |
* | > bSum |
* ---------------- > dot--------> DIRECT <------+-------------------------
* | > server > relname | |
* | > hpipe > DIRLIST head --- |
* | > uncname > DIRECT parent |
* | > password > bScanned |
* | > LIST of diritems-----> DIRITEM |
* | > LIST OF directs -> > name |
* | > enum pos | > int size |
* | > DIRECT curdir | > int checksum |
* | | > bool sumvalid |
* | | > DIRECT direct ---
* | | > localname
* --->COMPITEM | > bLocalIsTemp
* > left-------------------> FILEDATA |
* > right------------------> > DIRITEM-----------------
* > LIST of CompSecs--- > LIST of lines--> LINE
* > LIST of LeftSecs---| --> > flags
* > LIST of RightSecs--| | > text
* | | > hash
* | | > link
* | | > linenr
* --> SECTION |
* > first--------|
* > last---------
* > bDiscard
* > SECTION link
* > SECTION correspond
* > int state
* > int leftbase
* > int rightbase
*
*
*************************************************************************
*
* Overview of THIS file's business:
*
* we create a table window (gutils.dll) to show the files and the
* results of their comparisons. We create a COMPLIST object representing
* a list of files and their differences, and a VIEW object to map between
* the rows of the table window and the COMPLIST.
*
* This module is responsible for creating and managing the main window,
* placing the child windows (table, status window etc) within it, and
* handling all menu items. We maintain global option flags set by
* menu commands.
*
* Creating a COMPLIST creates a list of unmatched files, and of matching
* files that are compared with each other (these are COMPITEMS).
* The VIEW provides a mapping between rows on the screen, and items in
* the COMPLIST.
*
* Something about threads: (See also thread DOGMA, below)
*
* The win32 version tries to maintain a responsive user interface by
* creating worker threads to do long jobs. This potentially creates
* conflicts between the threads as they will both want to update common
* variables (for instance the UI thread may be changing the options to
* exclude identical files while the worker thread is adding in the
* results of new comparisons). Critical sections are used to manage
* the conflicts (as you'd expect).
*
* The Edit options invoke an editor on a separate thread. This allows
* us to repaint our window and thereby allow the user to refer back to
* what he saw before invoking the editor. When he's finished editing,
* we would of course like to refresh things and if this is still on the
* separate thread it might clash. We avoid this clash by POSTing ourselves
* a (WM_COMMAND, IDM_UPDATE) message.
*/
#include "precomp.h"
#include <shellapi.h>
#include "table.h"
#include <richedit.h> /* needed for usage dialog */
#include "list.h" /* needed for compitem.h */
#include "scandir.h" /* needed for file.h */
#include "file.h" /* needed for compitem.h */
#include "compitem.h" /* needed for view.h */
#include "complist.h"
#include "view.h"
#include "findgoto.h"
#include "state.h"
#include "sdkdiff.h"
#include "wdiffrc.h"
/*--constants and data types--------------------------------------------*/
CRITICAL_SECTION CSSdkdiff;
/* IF EVER YOU MIGHT ACQUIRE BOTH CSSdkdiff AND CSView, THEN DO SO IN
THE ORDER: FIRST GET CSSdkdiff THEN GET CSView
else risk deadlock when an idm_exit happens!
*/
#define WDEnter() EnterCriticalSection(&CSSdkdiff);
#define WDLeave() LeaveCriticalSection(&CSSdkdiff);
int Version = 2;
int SubVersion = 01;
char pszWorkingDirectoryName[MAX_PATH];
/* When we print the current table, we pass this id as the table id
* When we are queried for the properties of this table, we know they
* want the printing properties for the current view. We use this to
* select different fonts and colours for the printer.
*/
#define TABID_PRINTER 1
BOOL __BERR;
/*
* structure containing args passed to worker thread in initial
* case (executing command line instructions) (in WIN16 case,
* the worker thread function is called synchronously with these args).
*/
typedef struct {
LPSTR first;
LPSTR second;
LPSTR savelist;
LPSTR savecomp;
LPSTR notify;
UINT listopts;
UINT compopts;
VIEW view;
BOOL fDeep;
BOOL fExit;
BOOL fOpenedFiles;
BOOL fDescribeFiles;
BOOL fInputFile; // TRUE means read file list from input file
BOOL fInputFileSingle; // TRUE means input file has one filename per line
} THREADARGS, FAR * PTHREADARGS;
/* structure containing all the arguments we'd like to give to do_editfile
Need a structure because CreateThread only allows for one argument.
*/
typedef struct {
VIEW view;
int option;
long selection;
} EDITARGS, FAR * PEDITARGS;
/*---- string constants --------------------------- */
const CHAR szSdkDiff[] = "SdkDiff";
static const char szD[] = "%d";
static const char szBlanks[] = "Blanks";
static const char szAlgorithm2[] = "Algorithm2";
static const char szPicture[] = "Picture";
static const char szMonoColours[] = "MonoColours";
static const char szHideMark[] = "HideMark";
static const char szSdkDiffViewerClass[] = "SdkDiffViewerClass";
static const char szSdkDiffMenu[] = "SdkDiffMenu";
static const char szOutlineMenu[] = "OutlineFloatMenu";
static const char szExpandMenu[] = "ExpandFloatMenu";
static const char szSdkDiffAccel[] = "SdkDiffAccel";
static const char szBarClass[] = "BarClass";
static const char szLineNumbers[] = "LineNumbers";
static const char szFileInclude[] = "FileInclude";
static const char szLineInclude[] = "LineInclude";
static const char szOutlineSaved[] = "OutlineSaved";
static const char szOutlineShowCmd[] = "OutlineShowCmd";
static const char szOutlineMaxX[] = "OutlineMaxX";
static const char szOutlineMaxY[] = "OutlineMaxY";
static const char szOutlineNormLeft[] = "OutlineNormLeft";
static const char szOutlineNormTop[] = "OutlineNormTop";
static const char szOutlineNormRight[] = "OutlineNormRight";
static const char szOutlineNormBottom[] = "OutlineNormBottom";
static const char szEditor[] = "Editor";
static const char szFontFaceName[] = "FontFaceName";
static const char szFontHeight[] = "FontHeight";
static const char szFontBold[] = "FontBold";
static const char szFontCharSet[] = "FontCharSet";
static const char szExpandedSaved[] = "ExpandedSaved";
static const char szExpandShowCmd[] = "ExpandShowCmd";
static const char szExpandMaxX[] = "ExpandMaxX";
static const char szExpandMaxY[] = "ExpandMaxY";
static const char szExpandNormLeft[] = "ExpandNormLeft";
static const char szExpandNormTop[] = "ExpandNormTop";
static const char szExpandNormRight[] = "ExpandNormRight";
static const char szExpandNormBottom[] = "ExpandNormBottom";
static const char szColourPrinting[] = "ColourPrinting";
static const char szTabWidth[] = "TabWidth";
static const char szShowWhitespace[] = "ShowWhitespace";
static const char szrgb_outlinehi[] = "RGBOutlineHi";
static const char szrgb_leftfore[] = "RGBLeftFore";
static const char szrgb_leftback[] = "RGBLeftBack";
static const char szrgb_rightfore[] = "RGBRightFore";
static const char szrgb_rightback[] = "RGBRightBack";
static const char szrgb_similarleft[] = "RGBSimilarLeft";
static const char szrgb_similarright[] = "RGBSimilarRight";
static const char szrgb_similar[] = "RGBSimilar";
static const char szrgb_mleftfore[] = "RGBMLeftFore";
static const char szrgb_mleftback[] = "RGBMLeftBack";
static const char szrgb_mrightfore[] = "RGBMRightFore";
static const char szrgb_mrightback[] = "RGBMRightBack";
static const char szrgb_barleft[] = "RGBBarLeft";
static const char szrgb_barright[] = "RGBBarRight";
static const char szrgb_barcurrent[] = "RGBBarCurrent";
static const char szrgb_defaultfore[] = "RGBDefaultFore";
static const char szrgb_defaultforews[] = "RGBDefaultForeWS";
static const char szrgb_defaultback[] = "RGBDefaultBack";
static const char szrgb_fileleftfore[] = "RGBFileLeftFore";
static const char szrgb_fileleftback[] = "RGBFileLeftBack";
static const char szrgb_filerightfore[] = "RGBFileRightFore";
static const char szrgb_filerightback[] = "RGBFileRightBack";
/*---- colour scheme------------------------------- */
DWORD rgb_outlinehi = RGB(255, 0, 0); /* hilighted files in outline mode */
/* expand view */
DWORD rgb_leftfore; /* foregrnd for left lines */
DWORD rgb_leftback; /* backgrnd for left lines */
DWORD rgb_rightfore; /* foregrnd for right lines*/
DWORD rgb_rightback; /* backgrnd for right lines*/
/* temp hack */
DWORD rgb_similarleft; /* forground zebra */
DWORD rgb_similarright; /* foreground zebra */
DWORD rgb_similar; /* unused */
/* moved lines */
DWORD rgb_mleftfore; /* foregrnd for moved-left */
DWORD rgb_mleftback; /* backgrnd for moved-left */
DWORD rgb_mrightfore; /* foregrnd for moved-right*/
DWORD rgb_mrightback; /* backgrnd for moved-right*/
/* bar window */
DWORD rgb_barleft; /* bar sections in left only */
DWORD rgb_barright; /* bar sections in right only */
DWORD rgb_barcurrent; /* current pos markers in bar */
DWORD rgb_defaultfore; /* default foreground */
DWORD rgb_defaultforews; /* default foreground whitespace */
DWORD rgb_defaultback; /* default background */
DWORD rgb_fileleftfore; /* outline mode left only file */
DWORD rgb_fileleftback; /* outline mode left only file */
DWORD rgb_filerightfore; /* outline mode right only file */
DWORD rgb_filerightback; /* outline mode right only file */
BOOL gbPerverseCompare = FALSE; // break lines on punctuation (broken & useless)
/* PickUpProfile */
void PickUpProfile( DWORD * pfoo, LPCSTR szfoo)
{
*pfoo = GetProfileInt(APPNAME, szfoo, *pfoo);
}
void SetColours(void)
{
/* outline */
rgb_outlinehi = (DWORD)RGB(255, 0, 0); /* hilighted files in outline mode */
PickUpProfile(&rgb_outlinehi, szrgb_outlinehi);
rgb_fileleftfore = (DWORD)RGB(0, 0, 0); /* left only outline mode */
PickUpProfile(&rgb_fileleftfore, szrgb_fileleftfore);
rgb_fileleftback = (DWORD)RGB(255, 255, 255);
PickUpProfile(&rgb_fileleftback, szrgb_fileleftback);
rgb_filerightfore = (DWORD)RGB(0, 0, 0); /* right only outline mode */
PickUpProfile(&rgb_filerightfore, szrgb_filerightfore);
rgb_filerightback = (DWORD)RGB(255, 255, 255);
PickUpProfile(&rgb_filerightback, szrgb_filerightback);
/* expand view */
rgb_leftfore = (DWORD)RGB( 0, 0, 0); /* foregrnd for left lines */
PickUpProfile(&rgb_leftfore, szrgb_leftfore);
rgb_leftback = (DWORD)RGB(255, 0, 0); /* backgrnd for left lines */
PickUpProfile(&rgb_leftback, szrgb_leftback);
rgb_rightfore = (DWORD)RGB( 0, 0, 0); /* foregrnd for right lines*/
PickUpProfile(&rgb_rightfore, szrgb_rightfore);
rgb_rightback = (DWORD)RGB(255, 255, 0); /* backgrnd for right lines*/
PickUpProfile(&rgb_rightback, szrgb_rightback);
rgb_similarleft= (DWORD)RGB( 0, 255, 255); /* foreground zebra */
PickUpProfile(&rgb_similarleft, szrgb_similarleft);
rgb_similarright=(DWORD)RGB( 0, 127, 127); /* forground zebra */
PickUpProfile(&rgb_similarright, szrgb_similarright);
rgb_similar = (DWORD)RGB( 127, 127, 255); /* same within comp options*/
PickUpProfile(&rgb_similar, szrgb_similar);
/* moved lines */
rgb_mleftfore = (DWORD)RGB( 0, 0, 128); /* foregrnd for moved-left */
PickUpProfile(&rgb_mleftfore, szrgb_mleftfore);
rgb_mleftback = (DWORD)RGB(255, 0, 0); /* backgrnd for moved-left */
PickUpProfile(&rgb_mleftback, szrgb_mleftback);
rgb_mrightfore = (DWORD)RGB( 0, 0, 255); /* foregrnd for moved-right*/
PickUpProfile(&rgb_mrightfore, szrgb_mrightfore);
rgb_mrightback = (DWORD)RGB(255, 255, 0); /* backgrnd for moved-right*/
PickUpProfile(&rgb_mrightback, szrgb_mrightback);
/* bar window */
rgb_barleft = (DWORD)RGB(255, 0, 0); /* bar sections in left only */
PickUpProfile(&rgb_barleft, szrgb_barleft);
rgb_barright = (DWORD)RGB(255, 255, 0); /* bar sections in right only */
PickUpProfile(&rgb_barright, szrgb_barright);
rgb_barcurrent = (DWORD)RGB( 0, 0, 255); /* current pos markers in bar */
PickUpProfile(&rgb_barcurrent, szrgb_barcurrent);
/* defaults */
rgb_defaultfore = (DWORD)RGB( 0, 0, 0); /* default foreground colour */
PickUpProfile(&rgb_defaultfore, szrgb_defaultfore);
rgb_defaultforews = (DWORD)RGB(192, 192, 192); /* default foreground whitespace colour */
PickUpProfile(&rgb_defaultforews, szrgb_defaultforews);
rgb_defaultback = (DWORD)RGB(255, 255, 255); /* default background colour */
PickUpProfile(&rgb_defaultback, szrgb_defaultback);
} /* SetColours */
void SetMonoColours(void)
{
rgb_outlinehi = GetSysColor(COLOR_WINDOW); /* hilighted files in outline mode */
/* expand view - all changed or moved lines are white on black */
rgb_leftfore = GetSysColor(COLOR_WINDOW); /* foregrnd for left lines */
rgb_leftback = GetSysColor(COLOR_WINDOWTEXT); /* backgrnd for left lines */
rgb_rightfore = GetSysColor(COLOR_WINDOW); /* foregrnd for right lines*/
rgb_rightback = GetSysColor(COLOR_WINDOWTEXT); /* backgrnd for right lines*/
rgb_similarleft= GetSysColor(COLOR_WINDOW); /* foreground zebra */
rgb_similarright=GetSysColor(COLOR_WINDOW); /* foreground zebra */
rgb_similar = GetSysColor(COLOR_WINDOWTEXT); /* same within comp options*/
/* moved lines - black on white */
rgb_mleftfore = GetSysColor(COLOR_WINDOWTEXT); /* foregrnd for moved-left */
rgb_mleftback = GetSysColor(COLOR_WINDOW); /* backgrnd for moved-left */
rgb_mrightfore = GetSysColor(COLOR_WINDOWTEXT); /* foregrnd for moved-right*/
rgb_mrightback = GetSysColor(COLOR_WINDOW); /* backgrnd for moved-right*/
/* bar WINDOWTEXT */
rgb_barleft = GetSysColor(COLOR_WINDOWTEXT); /* bar sections in left only */
rgb_barright = GetSysColor(COLOR_WINDOWTEXT); /* bar sections in right only */
rgb_barcurrent = GetSysColor(COLOR_WINDOWTEXT); /* current pos markers in bar */
rgb_defaultfore = GetSysColor(COLOR_WINDOWTEXT); /* default foreground colour */
rgb_defaultforews = GetSysColor(COLOR_WINDOWTEXT); /* default foreground whitespace colour */
rgb_defaultback = GetSysColor(COLOR_WINDOW); /* default background colour */
} /* SetMonoColours */
/* -------------------------------------------------- */
/* module static data -------------------------------------------------*/
/* current value of window title */
char AppTitle[256];
HWND hwndClient; /* main window */
HWND hwndRCD; /* table window */
HWND hwndStatus; /* status bar across top */
HWND hwndBar; /* graphic of sections as vertical bars */
HACCEL haccel;
/* the status bar told us it should be this high. Rest of client area
* goes to the hwndBar and hwndRCD.
*/
int status_height;
#if 0
#ifndef HINSTANCE
#define HINSTANCE HANDLE
#endif
#endif
HINSTANCE hInst; /* handle to current app instance */
HMENU hMenu; /* handle to menu for hwndClient */
int nMinMax = SW_SHOWNORMAL; /* default state of window normal */
/* the message sent to us as a callback by the table window needs to be
* registered - table_msgcode is the result of the RegisterMessage call
*/
UINT table_msgcode;
/* true if we are currently doing some scan or comparison.
* WIN32: must get critical section before checking/changing this (call
* SetBusy.
*/
BOOL fBusy = FALSE;
long selection = -1; /* selected row in table*/
long selection_nrows = 0; /* number of rows in selection */
/* options for DisplayMode field indicating what is currently shown.
* we use this to know whether or not to show the graphic bar window.
*/
#define MODE_NULL 0 /* nothing displayed */
#define MODE_OUTLINE 1 /* a list of files displayed */
#define MODE_EXPAND 2 /* view is expanded view of one file */
int DisplayMode = MODE_NULL; /* indicates whether we are in expand mode */
VIEW current_view = NULL;
BOOL fAutoExpand = TRUE; /* Should we auto expand ? */
/* These two flags are peeked at by lots of other modules */
BOOL bAbort; /* set to request abort of current operation */
BOOL bTrace; /* set if tracing is to be enabled */
BOOL bJapan; /* set if primary language is Japanese */
BOOL bDBCS; /* set if primary language is Japanese/Korean/Chinese */
extern char*s;
char editor_cmdline[1024] = "notepad %p"; /* editor cmdline */
char g_szFontFaceName[LF_FACESIZE];
int g_nFontHeight;
BOOL g_fFontBold;
BYTE g_bFontCharSet;
HFONT g_hFont = 0;
/* app-wide global data --------------------------------------------- */
/* current state of menu options */
int line_numbers = IDM_LNRS;
int expand_mode = IDM_BOTHFILES;
int outline_include = INCLUDE_ALL;
int expand_include = INCLUDE_ALL;
BOOL ignore_blanks = TRUE;
BOOL show_whitespace = FALSE;
BOOL Algorithm2 = TRUE; /* Try duplicates - used in compitem.c */
BOOL picture_mode = TRUE;
BOOL hide_markedfiles = FALSE;
BOOL mono_colours = FALSE; /* monochrome display */
// tab width - set from TabWidth entry in registry
int g_tabwidth = TABWIDTH_DEFAULT;
BOOL TrackLeftOnly = TRUE;
BOOL TrackRightOnly = TRUE;
BOOL TrackSame = TRUE;
BOOL TrackDifferent = TRUE;
BOOL TrackReadonly = TRUE;
/* function prototypes ---------------------------------------------*/
BOOL InitApplication(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);
void CreateTools(void);
void DeleteTools(void);
INT_PTR APIENTRY MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL SetBusy(void);
void SetNotBusy(void);
void SetSelection(long rownr, long nrows, long dyRowsFromTop);
void SetButtonText(LPSTR cmd);
BOOL ToExpand(HWND hwnd);
void ParseArgs(char * lpCmdLine);
void Trace_Status(LPSTR str);
DWORD WINAPI wd_initial(LPVOID arg);
static HANDLE ghThread = NULL;
/* Some DOGMA about threads:
When we spin off threads and then while they are still running, try to Exit
we get race conditions with one thread allocating and the other freeing the
storage.
It might be that given a final structure of A->B->C we have A->B with NULL
pointers in B when the Exit comes in. The cleanup thread will clear out
B and A and THEN the worker thread might try to attach C to B which is no
longer there. This means that the worker thread must be Stopped. To allow
this to happen quickly, we TerminateThread it. This will leave the initial
stack around, but presumably that gets cleaned up on app exit anyway.
There is only at most one worker thread running, and ghThread is its handle.
*/
static DWORD gdwMainThreadId; /* threadid of main (user interface) thread
initialised in winmain(), thereafter constant.
See sdkdiff_UI()
*/
/* if you are about to put up a dialog box or in fact process input in any way
on any thread other than the main thread - or if you MIGHT be on a thread other
than the main thread, then you must call this function with TRUE before doing
it and with FALSE immediately afterwards. Otherwise you will get one of a
number of flavours of not-very-responsiveness
*/
void sdkdiff_UI(BOOL bAttach)
{
DWORD dwThreadId = GetCurrentThreadId();
if (dwThreadId==gdwMainThreadId) return;
if (bAttach) GetDesktopWindow();
AttachThreadInput(dwThreadId, gdwMainThreadId, bAttach);
} /* sdkdiff_UI */
/*-functions----------------------------------------------------------*/
/* main entry point. register window classes, create windows,
* parse command line arguments and then perform a message loop
*/
int WINAPI
WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
int len = 0;
// Get working directory.
memset(pszWorkingDirectoryName, 0, MAX_PATH);
len = GetModuleFileName(hInstance, pszWorkingDirectoryName, MAX_PATH);
if (len != 0) {
while (pszWorkingDirectoryName[len-1] != '\\' ) {
len--;
}
pszWorkingDirectoryName[len] = 0;
}
InitGutils(GetModuleHandle(NULL), DLL_PROCESS_ATTACH, NULL);
gdwMainThreadId = GetCurrentThreadId();
/* create any pens/brushes etc and read in profile defaults */
CreateTools();
/* init window class unless other instances running */
if (!hPrevInstance)
if (!InitApplication(hInstance))
return(FALSE);
/* init this instance - create all the windows */
if (!InitInstance(hInstance, nCmdShow))
return(FALSE);
ParseArgs(lpCmdLine);
/* message loop */
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(hwndClient, haccel, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
Trace_Close();
return (msg.wParam ? 1 : 0);
}
/* InitApplication
*
* - register window class for the main window and the bar window.
*/
BOOL
InitApplication(
HINSTANCE hInstance
)
{
WNDCLASS wc;
BOOL resp;
LCID lcid = GetThreadLocale();
// set the boolean value for bJapan variable
bJapan = (PRIMARYLANGID(LANGIDFROMLCID(lcid)) == LANG_JAPANESE);
bDBCS = ((PRIMARYLANGID(LANGIDFROMLCID(lcid)) == LANG_JAPANESE) ||
(PRIMARYLANGID(LANGIDFROMLCID(lcid)) == LANG_KOREAN) ||
(PRIMARYLANGID(LANGIDFROMLCID(lcid)) == LANG_CHINESE));
/* register the bar window class */
InitBarClass(hInstance);
wc.style = 0;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, szSdkDiff);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszClassName = (LPSTR) szSdkDiffViewerClass;
wc.lpszMenuName = NULL;
resp = RegisterClass(&wc);
return(resp);
}
/*
* create and show the windows
*/
BOOL
InitInstance(
HINSTANCE hInstance,
int nCmdShow
)
{
RECT rect;
HANDLE hstatus;
int bar_width;
RECT childrc;
HIGHCONTRAST hc;
hInst = hInstance;
/* initialise the list package */
List_Init();
hMenu = LoadMenu(hInstance, szSdkDiffMenu);
haccel = LoadAccelerators(hInstance, szSdkDiffAccel);
/* create the main window */
hwndClient = CreateWindow(szSdkDiffViewerClass,
szSdkDiff,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
hMenu,
hInstance,
NULL
);
if (!hwndClient) {
return(FALSE);
}
/* create 3 child windows, one status, one table and one bar
* Initially, the bar window is hidden and covered by the table.
*/
/* create a status bar window as
* a child of the main window.
*/
/* build a status struct for two labels and an abort button */
hstatus = StatusAlloc(3);
StatusAddItem(hstatus, 0, SF_STATIC, SF_LEFT|SF_VAR|SF_SZMIN, IDL_STATLAB, 14, NULL);
StatusAddItem(hstatus, 1, SF_BUTTON, SF_RIGHT|SF_RAISE, IDM_ABORT, 8,
LoadRcString(IDS_EXIT));
StatusAddItem(hstatus, 2, SF_STATIC, SF_LOWER|SF_LEFT|SF_VAR,
IDL_NAMES, 60, NULL);
/* ask the status bar how high it should be for the controls
* we have chosen, and save this value for re-sizing.
*/
status_height = StatusHeight(hstatus);
/* create a window of this height */
GetClientRect(hwndClient, &rect);
childrc = rect;
childrc.bottom = status_height;
hwndStatus = StatusCreate(hInst, hwndClient, IDC_STATUS, &childrc,
hstatus);
/* layout constants are stated as percentages of the window width */
bar_width = (rect.right - rect.left) * BAR_WIN_WIDTH / 100;
/* create the table class covering all the remaining part of
* the main window
*/
hwndRCD = CreateWindow(TableClassName,
NULL,
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
0,
status_height,
(int)(rect.right - rect.left),
(int)(rect.bottom - status_height),
hwndClient,
(HMENU) IDC_RCDISP1,
hInst,
NULL);
/* create a bar window as a child of the main window.
* this window remains hidden until we switch into MODE_EXPAND
*/
hwndBar = CreateWindow(szBarClass,
NULL,
WS_CHILD | WS_VISIBLE,
0,
status_height,
bar_width,
(int)(rect.bottom - status_height),
hwndClient,
(HMENU) IDC_BAR,
hInst,
NULL);
/* nMinMax indicates whether we are to be minimised on startup,
* on command line parameters
*/
ShowWindow(hwndBar, SW_HIDE);
if (GetProfileInt(APPNAME, szOutlineSaved, 0)) {
WINDOWPLACEMENT wp;
/* restore the previous expanded size and position */
wp.length = sizeof(wp);
wp.flags = 0;
wp.showCmd = GetProfileInt( APPNAME, szOutlineShowCmd,
SW_SHOWNORMAL);
wp.ptMaxPosition.x = GetProfileInt( APPNAME, szOutlineMaxX, 0);
wp.ptMaxPosition.y = GetProfileInt( APPNAME, szOutlineMaxY, 0);
wp.rcNormalPosition.left = (int)GetProfileInt( APPNAME, szOutlineNormLeft, (UINT)(-1));
wp.rcNormalPosition.top = (int)GetProfileInt( APPNAME, szOutlineNormTop, (UINT)(-1));
wp.rcNormalPosition.right = (int)GetProfileInt( APPNAME, szOutlineNormRight, (UINT)(-1));
wp.rcNormalPosition.bottom = (int)GetProfileInt( APPNAME, szOutlineNormBottom,(UINT)(-1));
if (!SetWindowPlacement(hwndClient,&wp)) {
ShowWindow(hwndClient, nMinMax);
}
} else ShowWindow(hwndClient, nMinMax);
/* initialise busy flag and status line to show we are idle
* (ie not comparing or scanning)
*/
SetNotBusy();
/* initialise the colour globals */
hc.cbSize = sizeof(hc);
SystemParametersInfo(SPI_GETHIGHCONTRAST,0 ,&hc, 0);
mono_colours = (hc.dwFlags & HCF_HIGHCONTRASTON);
if (mono_colours) {
SetMonoColours();
} else {
SetColours();
}
PostMessage(hwndClient, WM_SYSCOLORCHANGE, 0 , 0);
UpdateWindow(hwndClient);
return(TRUE);
} /* InitInstance */
/*
* complain to command line users about poor syntax
*/
typedef struct
{
UINT m_ids;
BOOL m_fInternalOnly;
BOOL m_fExternalOnly;
int m_cIndent;
} UsageStringInfo;
static const UsageStringInfo c_rg[] =
{
{ (UINT)-1, 0, 0, 0 },
{ IDS_USAGE_STR00, 0, 0, 0 },
{ IDS_USAGE_STR01, 0, 0, 0 },
{ IDS_USAGE_STR02, 0, 0, 1 },
{ IDS_USAGE_STR03, 0, 0, 1 },
{ IDS_USAGE_STR04, 0, 0, 3 },
{ IDS_USAGE_STR05, 0, 0, 1 },
{ IDS_USAGE_STR06, 0, 1, 1 },
{ IDS_USAGE_STR07, 1, 0, 1 },
{ IDS_USAGE_STR08, 1, 0, 1 },
{ IDS_USAGE_STR08B, 0, 0, 1 },
{ IDS_USAGE_STR09, 1, 0, 1 },
{ IDS_USAGE_STR10, 1, 0, 1 },
{ IDS_USAGE_STR11, 1, 0, 1 },
{ IDS_USAGE_STR12, 1, 0, 1 },
{ IDS_USAGE_STR12B, 1, 0, 1 },
{ IDS_USAGE_STR12C, 1, 0, 1 },
{ IDS_USAGE_STR13, 1, 0, 1 },
{ IDS_USAGE_STR14, 1, 0, 1 },
{ IDS_USAGE_STR15, 0, 0, 1 },
{ IDS_USAGE_STR16, 0, 0, 1 },
{ IDS_USAGE_STR17, 0, 0, 1 },
{ IDS_USAGE_STR18, 0, 0, 1 },
{ IDS_USAGE_STR19, 0, 0, 3 },
{ IDS_USAGE_STR20, 0, 0, 1 },
{ IDS_USAGE_STR21, 1, 0, 1 },
{ IDS_USAGE_STR22, 1, 0, 3 },
{ IDS_USAGE_STR23, 1, 0, 0 },
{ IDS_USAGE_STR24, 1, 0, -1 },
{ IDS_USAGE_STR25, 1, 0, -1 },
{ IDS_USAGE_STR26, 1, 0, -1 },
};
INT_PTR FAR PASCAL UsageDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
HWND hwnd = GetDlgItem(hDlg, IDC_USAGE_TEXT);
if (hwnd)
{
const UsageStringInfo *p;
int c;
PARAFORMAT pf;
CHARFORMAT cf;
int pos;
pf.cbSize = sizeof(pf);
SendMessage(hwnd, EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
SendMessage(hwnd, EM_SETMARGINS, EC_LEFTMARGIN|EC_RIGHTMARGIN, MAKELONG(4, 4));
for (p = c_rg, c = NUMELMS(c_rg); c--; p++)
{
LPCSTR psz;
psz=LoadRcString(p->m_ids);
if (p->m_fExternalOnly)
continue;
if (p->m_fInternalOnly)
continue;
pos = LOWORD(SendMessage(hwnd, EM_GETSEL, 0, 0));
SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM)psz);
SendMessage(hwnd, EM_SETSEL, pos, -1);
SendMessage(hwnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
if (p->m_cIndent >= 0)
{
static const int c_rgIndents[] = { 320*1, 320*5, 320*6 };
static const int c_rgOffsets[] = { 320*4, 0, 0 };
pf.dwMask |= PFM_STARTINDENT|PFM_OFFSET|PFM_TABSTOPS;
pf.dxStartIndent = 0;
pf.dxOffset = 0;
if (p->m_cIndent)
{
pf.dxStartIndent = c_rgIndents[p->m_cIndent - 1];
pf.dxOffset = c_rgOffsets[p->m_cIndent - 1];
}
pf.cTabCount = 2;
pf.rgxTabs[0] = c_rgIndents[0];
pf.rgxTabs[1] = c_rgIndents[1];
}
else
{
pf.dwMask |= PFM_STARTINDENT|PFM_OFFSET|PFM_NUMBERING;
pf.dxStartIndent = 320;
pf.dxOffset = 180;
pf.wNumbering = PFN_BULLET;
}
SendMessage(hwnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
SendMessage(hwnd, EM_SETSEL, (WPARAM)-1, -1);
}
cf.cbSize = sizeof(cf);
cf.dwMask = CFM_COLOR;
cf.dwEffects = 0;
cf.crTextColor = GetSysColor(COLOR_BTNTEXT);
SendMessage(hwnd, EM_SETSEL, 0, -1);
SendMessage(hwnd, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf);
SendMessage(hwnd, EM_SETSEL, (WPARAM)-1, -1);
pos = LOWORD(SendMessage(hwnd, EM_GETSEL, 0, 0));
SendMessage(hwnd, EM_SETSEL, pos - 1, pos);
SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)"");
SendMessage(hwnd, EM_SETSEL, 0, 0);
}
}
break;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
case IDCANCEL:
EndDialog(hDlg, wParam);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
void
sdkdiff_usage(
LPSTR msg
)
{
INT_PTR retval;
UINT fuStyle = MB_ICONINFORMATION|MB_OKCANCEL;
HRESULT hr;