-
Notifications
You must be signed in to change notification settings - Fork 3
/
npp-generator.sp
1364 lines (1124 loc) · 35.5 KB
/
npp-generator.sp
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
#define PLUGIN_VERSION "1.3.0"
#pragma newdecls required
#pragma semicolon 1
#include <sourcemod>
#include <profiler>
//-----------------------------------
// Pre-compiler option
//-----------------------------------
#define DEBUG_BITS 0//(DEBUG_BIT_LOG|DEBUG_BIT_ERROR|DEBUG_BIT_COMMON|DEBUG_BIT_COMMENTARY)
#define ADD_NPP_STYLE_METHODMAP 1 // write to NPP_STYLE_FUNCTION file all strings but fake methodmaps (e.g., MM_ArrayList_Handle_M_GetArray)
#define ADD_DOCS_OPERATORS_MISC 1
#define ADD_DOCS_VARIABLES 1
#define CASE_SENSITIVE_SORTING true
#define USE_SHORT_PREFIX 1
#define IGNORE_CASE "yes"
// -----------------------------------
// bits
enum (<<= 1)
{
DEBUG_BIT_COMMON = 1,
DEBUG_BIT_FUNC_PARAM,
DEBUG_BIT_METHODMAP,
DEBUG_BIT_BRACKET,
DEBUG_BIT_COMMENTARY,
DEBUG_BIT_XML,
DEBUG_BIT_ERROR,
// <- adds new bit here
DEBUG_BIT_PRINT,
DEBUG_BIT_LOG,
DEBUG_BIT_ALL = 510
}
enum (<<= 1)
{
PROP_BIT_GET = 1,
PROP_BIT_SET
}
enum ()
{
DEBUG_TAG_COMMOM,
DEBUG_TAG_FUNC_PARAM,
DEBUG_TAG_METHODMAP,
DEBUG_TAG_BRACKET,
DEBUG_TAG_COMMENTARY,
DEBUG_TAG_XML,
DEBUG_TAG_ERROR,
DEBUG_TOTAL
}
enum ()
{
PREFIX_METHODMAP,
PREFIX_METHOD,
PREFIX_CONSTRUCTOR,
PREFIX_PROP,
PREFIX_TOTAL
}
enum ()
{
COMMENT_PARAM,
COMMENT_NOTES,
COMMENT_ERROR,
COMMENT_RETURN,
COMMENT_TOTAL
}
enum (<<= 1)
{
READSTRING_BIT_INVALID = 1,
READSTRING_BIT_VALID,
READSTRING_BIT_BUFFER,
READSTRING_BIT_INLINE,
READSTRING_BIT_LAST
}
#define MAX_WIDTH 28
#define WIDTH MAX_WIDTH - 4
#define SPACE_CHAR ' '
#define SPACE_X4 " "
#define SPACE_X8 " "
#define SPACE_X12 " "
#define SPACE_X16 " "
#define SPACE_X28 " "
#define TEXT_PARAM "@param"
#define TEXT_RETURN "@return"
#define TEXT_NORETURN "@noreturn"
#define TEXT_ERROR "@error"
#define PATH_INCLUDE "addons/sourcemod/scripting/include"
#define FILE_SOURCEMOD "addons/sourcemod/plugins/NPP/sourcemod.xml"
#define FILE_OPERATORS "addons/sourcemod/plugins/NPP/NPP_STYLE_OPERATORS.sp"
#define FILE_FUNCTIONS "addons/sourcemod/plugins/NPP/NPP_STYLE_FUNCTION.sp"
#define FILE_CONSTANT "addons/sourcemod/plugins/NPP/NPP_STYLE_CONSTANT.sp"
#define FILE_MISC "addons/sourcemod/plugins/NPP/NPP_STYLE_MISC.sp"
// ( ) [ ] ; , - style separator
#define NPP_STYLE_OPERATORS "( ) [ ] ; , * / % + - << >> >>> < > <= >= == != & && ^ | || ? : = += -= *= /= %= &= ^= |= <<= >>= >>>= ++ -- ~ !"
#define NPP_STYLE_OPERATORS_MISC "for if else do while switch case default return break delete continue new decl public stock const enum forward static funcenum functag native sizeof view_as true false union function methodmap typedef property struct this null typeset"
#define NPP_STYLE_VARIABLES "bool char int float Handle"
#define LOG "logs\\npp-generator.log"
public Plugin myinfo =
{
name = "Npp-generator",
author = "MCPAN (mcpan@foxmail.com), raziEiL [disawar1]",
description = "Generate auto-completion files & sourcemod.xml docs",
version = PLUGIN_VERSION,
url = "https://github.com/raziEiL/SourceMod-Npp-Docs"
}
char g_Debug[DEBUG_TOTAL][] = {"COMMON", "FUNC PARAM", "METHODMAP", "BRACKET", "COMMENTARY", "XML", "ERROR"},
g_FuncPrefix[][] = {"forward", "native", "stock", "public native", "property", "public"},
g_CommentType[COMMENT_TOTAL][] = {"Params:", "Notes:", "Error:", "Return:"},
g_ConstSMVars[][] = {"NULL_VECTOR", "NULL_STRING", "MaxClients"},
DEBUG[PLATFORM_MAX_PATH], g_MethodmapName[48], g_MethodmapTag[48];
#if USE_SHORT_PREFIX
char g_Prefix[PREFIX_TOTAL][] = {"MM_", "M", "C", "P"};
#else
char g_Prefix[PREFIX_TOTAL][] = {"METHODMAP_", "METHOD", "CONSTRUCTOR", "PROP"};
#endif
File g_FileDebug, g_FileSourcemodXML;
StringMap g_FuncTrie, g_Property;
ArrayList g_FuncArray, g_ConstArray, g_MiscArray; // Class ,tag, vars
int g_XMLFixCount;
public void OnPluginStart()
{
BuildPath(Path_SM, DEBUG, PLATFORM_MAX_PATH, LOG);
RegServerCmd("sm_makedocs", Cmd_Start, "starts to parse SourceMod includes and generates output files");
}
public Action Cmd_Start(int argc)
{
PrintToServer("> starts to parse includes! (debug bytes = %d)", DEBUG_BITS);
#if (DEBUG_BITS & DEBUG_BIT_LOG)
g_FileDebug = OpenFile(DEBUG, "wb");
#endif
Debug(DEBUG_BIT_COMMON, "--------------------------------------------");
g_XMLFixCount = 0;
Handle prof = CreateProfiler();
StartProfiling(prof);
CreateDirectory("addons/sourcemod/plugins/NPP", 511);
int i, size, count[3];
char buffer[PLATFORM_MAX_PATH];
ArrayList fileArray = CreateArray(ByteCountToCells(PLATFORM_MAX_PATH)), g_CommonArray = CreateArray(ByteCountToCells(64));
g_Property = CreateTrie();
g_FuncTrie = CreateTrie();
g_FuncArray = CreateArray(ByteCountToCells(64));
g_ConstArray = CreateArray(ByteCountToCells(64));
g_MiscArray = CreateArray(ByteCountToCells(64));
Debug(DEBUG_BIT_COMMON, "> --------------------------------");
Debug(DEBUG_BIT_COMMON, "> PARSING STARTED");
Debug(DEBUG_BIT_COMMON, "> --------------------------------");
Debug(DEBUG_BIT_COMMON, "> I. ADD IN ARRAY");
Debug(DEBUG_BIT_COMMON, "> --------------------------------");
if ((size = ReadDirFileList(fileArray, PATH_INCLUDE, "inc")))
{
for (i = 0; i < size; i++)
{
fileArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
ReadIncludeFile(buffer, i);
}
}
Debug(DEBUG_BIT_COMMON, "> --------------------------------");
Debug(DEBUG_BIT_COMMON, "> II. SORT ARRAY AND WRITE");
Debug(DEBUG_BIT_COMMON, "> --------------------------------");
SortADTArrayCustom(g_FuncArray, SortFuncADTArray);
File file = OpenFile(FILE_FUNCTIONS, "wb");
g_FileSourcemodXML = OpenFile(FILE_SOURCEMOD, "wb");
g_FileSourcemodXML.WriteLine("<?xml version=\"1.0\" encoding=\"Windows-1252\" ?>");
g_FileSourcemodXML.WriteLine("<NotepadPlus>");
g_FileSourcemodXML.WriteLine("%s<AutoComplete language=\"sourcemod\">", SPACE_X4);
g_FileSourcemodXML.WriteLine("%s<Environment ignoreCase=\"%s\"/>", SPACE_X4, IGNORE_CASE);
if ((count[0] = size = GetArraySize(g_FuncArray)))
{
int value;
char funcname[64];
for (i = 0; i < size; i++)
{
g_FuncArray.GetString(i, funcname, 63);
g_FuncTrie.GetValue(funcname, value);
fileArray.GetString(value, buffer, PLATFORM_MAX_PATH-1);
ReadIncludeFile(buffer, _, funcname);
if (ADD_NPP_STYLE_METHODMAP && StrContains(funcname, g_Prefix[PREFIX_METHODMAP]) != -1)
continue;
file.WriteLine("%s ", funcname);
}
}
#if ADD_DOCS_OPERATORS_MISC
char temp[42][32];
ExplodeString(NPP_STYLE_OPERATORS_MISC, " ", temp, sizeof(temp), sizeof(temp[]));
for (i = 0; i < sizeof(temp); i++)
{
if (!temp[i])
break;
if (FindStringInArray(g_CommonArray, temp[i]) == -1)
PushArrayString(g_CommonArray, temp[i]);
}
#endif
#if ADD_DOCS_VARIABLES
char temp2[5][16];
ExplodeString(NPP_STYLE_VARIABLES, " ", temp2, sizeof(temp2), sizeof(temp2[]));
for (i = 0; i < sizeof(temp2); i++)
{
if (!temp2[i])
break;
if (FindStringInArray(g_MiscArray, temp2[i]) == -1)
PushArrayString(g_MiscArray, temp2[i]);
}
#endif
if ((count[1] = size = GetArraySize(g_MiscArray)))
{
for (i = 0; i < size; i++)
{
g_MiscArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
PushArrayString(g_CommonArray, buffer);
}
}
for (i = 0; i < sizeof(g_ConstSMVars); i++)
{
if (FindStringInArray(g_ConstArray, g_ConstSMVars[i]) == -1)
PushArrayString(g_ConstArray, g_ConstSMVars[i]);
}
if ((count[2] = size = GetArraySize(g_ConstArray)))
{
for (i = 0; i < size; i++)
{
g_ConstArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
PushArrayString(g_CommonArray, buffer);
}
}
SortADTArrayCustom(g_CommonArray, SortFuncADTArray);
SortADTArrayCustom(g_ConstArray, SortFuncADTArray);
SortADTArrayCustom(g_MiscArray, SortFuncADTArray);
if ((size = GetArraySize(g_CommonArray)))
{
for (i = 0; i < size; i++)
{
g_CommonArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
if (buffer[0])
g_FileSourcemodXML.WriteLine("%s<KeyWord name=\"%s\"/>", SPACE_X8, buffer);
}
}
g_FileSourcemodXML.WriteLine("%s</AutoComplete>", SPACE_X4);
g_FileSourcemodXML.WriteLine("</NotepadPlus>");
delete file;
delete fileArray;
delete g_FuncTrie;
delete g_Property;
delete g_FuncArray;
delete g_FileSourcemodXML;
delete g_CommonArray;
file = OpenFile(FILE_CONSTANT, "wb");
if ((size = GetArraySize(g_ConstArray)))
{
for (i = 0; i < size; i++)
{
g_ConstArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
file.WriteLine("%s ", buffer);
}
}
delete file;
delete g_ConstArray;
file = OpenFile(FILE_MISC, "wb");
if ((size = GetArraySize(g_MiscArray)))
{
for (i = 0; i < size; i++)
{
g_MiscArray.GetString(i, buffer, PLATFORM_MAX_PATH-1);
file.WriteLine("%s ", buffer);
}
}
delete file;
delete g_MiscArray;
file = OpenFile(FILE_OPERATORS, "wb");
file.WriteLine("%s\n", NPP_STYLE_OPERATORS);
file.WriteLine(NPP_STYLE_OPERATORS_MISC);
delete file;
delete g_FileDebug;
StopProfiling(prof);
PrintToServer("> Job Done!\n> Time used: %.2fs. / XML error fixed: %d\n> Totally generated: function: %d, misc %d, define %d", GetProfilerTime(prof), g_XMLFixCount, count[0], count[1], count[2]);
delete prof;
return Plugin_Handled;
}
void ReadIncludeFile(char[] filepath, int fileArrayIdx=-1, char[] search="")
{
File file;
if ((file = OpenFile(filepath, "rb")) == INVALID_HANDLE)
{
LogError("Open file faild '%s'", filepath);
return;
}
int value, i;
bool found_params, found_return, found_error, found_func, found_property, in_property;
char temp[1024], buffer[1024], funcprefix[14], retval[32], funcname[128], funcnameBak[128], funcparam[32], lastPropName[128], retval2[32];
ArrayList array_comment[COMMENT_TOTAL];
for (int elem = 0; elem < COMMENT_TOTAL; elem++)
array_comment[elem] = CreateArray(ByteCountToCells(1024));
bool isMethodmap, diveInDeep;
int comment_byte, nextDeep, propDeep, currentDeep, commentDeep, tempVal, tempVal2;
Debug(DEBUG_BIT_COMMON, "----- NEW FILE ------");
Debug(DEBUG_BIT_COMMON, "ReadIncludeFile(PATH=%s, fileIndex=%d, search=%s)", filepath, fileArrayIdx, search);
ReadString("", 0, true);
while (ReadFileLine(file, buffer, 1023))
{
Debug(DEBUG_BIT_COMMON, "----- new line ------");
comment_byte = ReadString(buffer, 1023);
if (comment_byte & READSTRING_BIT_INVALID)
{
continue;
}
else if ((comment_byte & READSTRING_BIT_LAST) && (comment_byte & (READSTRING_BIT_BUFFER|READSTRING_BIT_INLINE)))
{
found_params = false;
found_return = false;
found_error = false;
for (i = 0; i < COMMENT_TOTAL; i++)
ClearArray(array_comment[i]);
Debug(DEBUG_BIT_COMMENTARY, "clear all comments");
commentDeep = nextDeep;
}
Debug(DEBUG_BIT_COMMENTARY, "'%s' byte=%d, %s, Buffer: %d, Inline: %d, Last was comment: %d", buffer,comment_byte, READSTRING_BIT_INVALID & comment_byte ? "Invalid" : "Valid", (READSTRING_BIT_BUFFER & comment_byte) != 0, (READSTRING_BIT_INLINE & comment_byte) != 0, (READSTRING_BIT_LAST & comment_byte) != 0 );
diveInDeep = false;
if (!(comment_byte & (READSTRING_BIT_BUFFER|READSTRING_BIT_INLINE))){
tempVal = CountCharInString(buffer, '{');
tempVal2 = CountCharInString(buffer, '}');
diveInDeep = tempVal > tempVal2;
nextDeep += tempVal - tempVal2;
currentDeep = nextDeep - (diveInDeep ? 1 : 0);
Debug(DEBUG_BIT_BRACKET, "%d - current, %d - next", currentDeep, nextDeep);
// check if in methodmap selection
if (!isMethodmap){
strcopy(funcprefix, 10, buffer);
TrimString(funcprefix);
if (strcmp(funcprefix, "methodmap") == 0 && ReadMethodmapHeader(buffer)){
isMethodmap = true;
continue;
}
}
else if (nextDeep <= 0){
isMethodmap = false;
}
if (found_property){
if (nextDeep <= propDeep){
found_property = in_property = false;
Debug(DEBUG_BIT_BRACKET, "prop brackets ended");
}
else {
in_property = true;
}
}
}
if (comment_byte & (READSTRING_BIT_BUFFER|READSTRING_BIT_INLINE))
{
if (!search[0])
{
Debug(DEBUG_BIT_COMMENTARY, "skip comment");
continue;
}
if (buffer[0] == '*'/* (value = FindCharInString2(buffer, '*')) != -1 */)
{
strcopy(buffer, 1023, buffer[1]);
//strcopy(buffer, 1023, buffer[++value]);
}
TrimString(buffer);
if (!buffer[0])
{
continue;
}
if (StrContains(buffer, TEXT_PARAM) == -1 &&
StrContains(buffer, TEXT_RETURN) == -1 &&
StrContains(buffer, TEXT_NORETURN) == -1 &&
StrContains(buffer, TEXT_ERROR) == -1)
{
Debug(DEBUG_BIT_COMMENTARY, "'%s'", buffer);
if (found_params)
{
FormatEx(temp, 1023, "%s%s", SPACE_X28, buffer);
PushArrayString(array_comment[COMMENT_PARAM], temp);
}
else if (found_return)
{
FormatEx(temp, 1023, "%s%s", SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_RETURN], temp);
}
else if (found_error)
{
FormatEx(temp, 1023, "%s%s", SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_ERROR], temp);
}
else
{
ReplaceString(buffer, 1023, "@note", "");
ReplaceString(buffer, 1023, "@brief", "");
TrimString(buffer);
FormatEx(temp, 1023, "%s%s", SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_NOTES], temp);
}
}
else if ((value = StrContains(buffer, TEXT_PARAM)) != -1)
{
found_params = true;
found_return = false;
found_error = false;
strcopy(buffer, 1023, buffer[value+6]);
TrimString(buffer);
if (buffer[0] && (value = FindCharInString2(buffer, SPACE_CHAR)) != -1)
{
strcopy(funcparam, value+1, buffer);
strcopy(buffer, 1023, buffer[value]);
TrimString(buffer);
if ((value = WIDTH - value) > 0)
{
for (i = 0; i < value; i++)
{
temp[i] = SPACE_CHAR;
}
temp[value] = 0;
}
else
{
LogMessage("need space, set MAX_WIDTH >= %d", MAX_WIDTH - value);
}
Format(temp, 1023, "%s%s%s%s", SPACE_X4, funcparam, value > 0 ? temp : SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_PARAM], temp);
}
}
else if ((value = StrContains(buffer, TEXT_RETURN)) != -1 || StrContains(buffer, TEXT_NORETURN) != -1)
{
found_params = false;
found_return = true;
found_error = false;
if (StrContains(buffer, TEXT_NORETURN) != -1)
{
found_return = false;
continue;
}
strcopy(buffer, 1023, buffer[value+7]);
TrimString(buffer);
FormatEx(temp, 1023, "%s%s", SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_RETURN], temp);
}
else if ((value = StrContains(buffer, TEXT_ERROR)) != -1)
{
found_params = false;
found_return = false;
found_error = true;
strcopy(buffer, 1023, buffer[value+6]);
TrimString(buffer);
FormatEx(temp, 1023, "%s%s", SPACE_X4, buffer);
PushArrayString(array_comment[COMMENT_ERROR], temp);
}
else
{
LogMessage(buffer);
}
}
else if (StrContains(buffer, "#pragma deprecated") != -1 && ReadFileLine(file, buffer, 1023))
{
strcopy(funcprefix, 7, buffer);
TrimString(funcprefix);
do
{
if (strcmp(funcprefix, "stock") == 0 && buffer[0] == '}' ||
strcmp(funcprefix, "stock") != 0 && FindCharInString2(buffer, ')') != -1)
{
break;
}
}
while (ReadFileLine(file, buffer, 1023));
}
else
{
if ((value = StrContains(buffer, "#define ")) != -1)
{
if (search[0] ||
StrContains(buffer, "_included") != -1 ||
//FindCharInString2(buffer, '(') != -1 || // adds define like: FCVAR_UNREGISTERED (1<<0)
FindCharInString2(buffer, '[') != -1)
{
continue;
}
strcopy(buffer, 1023, buffer[value+7]);
TrimString(buffer);
if ((value = FindCharInString2(buffer, SPACE_CHAR)) != -1)
{
strcopy(buffer, ++value, buffer);
TrimString(buffer);
}
if (IsValidString(buffer) && FindStringInArray(g_ConstArray, buffer) == -1)
{
PushArrayString(g_ConstArray, buffer);
}
}
else if ((value = IsTypeString(buffer, "enum")) != -1)
{
if (search[0])
continue;
strcopy(buffer, 1023, buffer[value+4]);
TrimString(buffer);
strcopy(temp, 1023, buffer);
ReplaceString(temp, 1023, "{", "");
if (IsValidString(temp) && FindStringInArray(g_MiscArray, temp) == -1)
{
PushArrayString(g_MiscArray, temp);
}
if ((value = FindCharInString2(buffer, '{')) != -1)
{
strcopy(temp, ++value, buffer);
strcopy(buffer, 1023, buffer[value]);
TrimString(temp);
TrimString(buffer);
if (WriteDefines(g_ConstArray, buffer, 1023, FindCharInString2(buffer, '}')))
{
while (ReadFileLine(file, buffer, 1023))
{
if (!WriteDefines(g_ConstArray, buffer, 1023, FindCharInString2(buffer, '}')))
{
break;
}
}
}
}
else
{
while (ReadFileLine(file, buffer, 1023))
{
if (ReadString(buffer, 1023) & (READSTRING_BIT_INVALID|READSTRING_BIT_BUFFER|READSTRING_BIT_INLINE))
{
continue;
}
if ((value = FindCharInString2(buffer, '{')) != -1)
{
strcopy(temp, ++value, buffer);
strcopy(buffer, 1023, buffer[value]);
TrimString(temp);
TrimString(buffer);
if (WriteDefines(g_ConstArray, buffer, 1023, FindCharInString2(buffer, '}')))
{
while (ReadFileLine(file, buffer, 1023))
{
if (ReadString(buffer, 1023) & (READSTRING_BIT_INVALID|READSTRING_BIT_BUFFER|READSTRING_BIT_INLINE))
{
continue;
}
if (!WriteDefines(g_ConstArray, buffer, 1023, FindCharInString2(buffer, '}')))
{
break;
}
}
}
break;
}
}
}
}
else if ((value = IsTypeString(buffer, "typeset")) != -1)
{
if (search[0])
continue;
strcopy(buffer, 1023, buffer[value+7]);
TrimString(buffer);
ReplaceString(buffer, 1023, "{", "");
if (IsValidString(buffer) && FindStringInArray(g_MiscArray, buffer) == -1)
{
PushArrayString(g_MiscArray, buffer);
}
}
else
{
found_func = false;
for (i = 0; i < sizeof(g_FuncPrefix); i++){
tempVal = strlen(g_FuncPrefix[i])+1;
strcopy(funcprefix, tempVal, buffer);
TrimString(funcprefix);
if (strcmp(funcprefix, g_FuncPrefix[i]) == 0){
found_func = true;
strcopy(buffer, sizeof(buffer)-tempVal, buffer[tempVal]);
Debug(DEBUG_BIT_COMMON, "Ffound: funcprefix='%s' funcname='%s'", funcprefix, buffer);
break;
}
}
// is property
if (strcmp(funcprefix, g_FuncPrefix[4]) == 0){
found_property = true;
propDeep = currentDeep;
}
if (found_func)
{
if (ReadFuncString(buffer, retval, funcname, found_property, in_property) && IsValidString(funcname)){
retval2[0] = 0;
if (isMethodmap){
Debug(DEBUG_BIT_COMMON, "%s", funcname);
if (found_property)
temp = g_Prefix[PREFIX_PROP];
else if (!retval[0]){
temp = g_Prefix[PREFIX_CONSTRUCTOR];
if (g_MethodmapTag[0])
strcopy(retval2, sizeof(retval2), g_MethodmapTag);
}
else
temp = g_Prefix[PREFIX_METHOD];
strcopy(funcnameBak, sizeof(funcnameBak), funcname);
if (g_MethodmapTag[0])
Format(temp, 128, "%s%s_%s_%s_", g_Prefix[PREFIX_METHODMAP], g_MethodmapName, g_MethodmapTag, temp);
else
Format(temp, 128, "%s%s_%s_", g_Prefix[PREFIX_METHODMAP], g_MethodmapName, temp);
Format(funcname, 128, "%s%s", temp, funcname);
Debug(DEBUG_BIT_COMMON, "Ftype:Methodmap: %s", funcname);
if (!in_property)
lastPropName = funcname;
else {
i = 0;
GetTrieValue(g_Property, lastPropName, i);
if (strcmp(funcnameBak, "get") == 0)
i |= PROP_BIT_GET;
else if (strcmp(funcnameBak, "set") == 0)
i |= PROP_BIT_SET;
SetTrieValue(g_Property, lastPropName, i);
Debug(DEBUG_BIT_COMMON, "Set lastprop get/set byte: val=%d, '%s'", i, lastPropName);
continue;
}
}
else
Debug(DEBUG_BIT_COMMON, "Ftype:Normal: funcname='%s', retval='%s' ", funcname, retval[0] ? retval : (retval2[0] ? retval2 : "void"));
if (search[0])
{
if (strcmp(funcname, search) == 0)
{
WriteFileLine(g_FileSourcemodXML, "%s<KeyWord name=\"%s\" func=\"yes\">", SPACE_X8, funcname);
WriteFileLine(g_FileSourcemodXML, "%s<Overload retVal=\"%s %s\" descr=\"", SPACE_X12, funcprefix, retval[0] ? retval : (retval2[0] ? retval2 : "void"));
if (IsValidString(retval) && FindStringInArray(g_MiscArray, retval) == -1)
{
PushArrayString(g_MiscArray, retval);
}
Debug(DEBUG_BIT_BRACKET, "currentDeep=%d, commentDeep=%d", currentDeep, commentDeep);
if (isMethodmap){
WriteFileLine(g_FileSourcemodXML, "Methodmap notes:");
WriteFileLine(g_FileSourcemodXML, "%sThis string is not a real Sourcemod Function!\n%sTo use function remove the '%s' prefix\n%sRead more here: https://github.com/raziEiL/SourceMod-Npp-Docs", SPACE_X4, SPACE_X4, temp, SPACE_X4);
Debug(DEBUG_BIT_COMMON, "trie search: '%s', result=%d", funcname, GetTrieValue(g_Property, funcname, i));
if (GetTrieValue(g_Property, funcname, i)){
WriteFileLine(g_FileSourcemodXML, "Property methods:");
if (i){
if (i & PROP_BIT_GET)
WriteFileLine(g_FileSourcemodXML, "%sHas getter", SPACE_X4);
if (i & PROP_BIT_SET)
WriteFileLine(g_FileSourcemodXML, "%sHas setter", SPACE_X4);
}
else
WriteFileLine(g_FileSourcemodXML, "%sNone", SPACE_X4);
}
}
if (currentDeep == commentDeep)
{
for (int comment = 0; comment < COMMENT_TOTAL; comment++){
if ((value = GetArraySize(array_comment[comment])))
{
WriteFileLine(g_FileSourcemodXML, g_CommentType[comment]);
Debug(DEBUG_BIT_COMMENTARY, "comment type: '%s'", g_CommentType[comment]);
for (i = 0; i < value; i++)
{
temp[0] = 0;
GetArrayString(array_comment[comment], i, temp, 1023);
ValidateXML(temp, 1023);
WriteFileLine(g_FileSourcemodXML, temp);
Debug(DEBUG_BIT_COMMENTARY, "'%s'", temp);
}
}
}
}
WriteFileLine(g_FileSourcemodXML, "\">");
if (!found_property){
if (buffer[0] == '(')
{
value = 1;
buffer[0] = SPACE_CHAR;
}
else
value = 0;
do
{
value += CountCharInString(buffer, '(') - CountCharInString(buffer, ')');
WriteFuncParams(g_FileSourcemodXML, buffer, 1023, value > 0) ;
} while (value > 0 && ReadFileLine(file, buffer, 1023));
}
WriteFileLine(g_FileSourcemodXML, "%s</Overload>", SPACE_X12);
WriteFileLine(g_FileSourcemodXML, "%s</KeyWord>", SPACE_X8);
break;
}
}
else if (FindStringInArray(g_FuncArray, funcname) == -1)
{
PushArrayString(g_FuncArray, funcname);
SetTrieValue(g_FuncTrie, funcname, fileArrayIdx);
}
else
Debug(DEBUG_BIT_ERROR,"UHM...same func name '%s'", funcname);
}
for (i = 0; i < COMMENT_TOTAL; i++)
ClearArray(array_comment[i]);
}
}
}
}
for (i = 0; i < COMMENT_TOTAL; i++)
CloseHandle(array_comment[i]);
CloseHandle(file);
}
int ReadString(char[] buffer, int maxlength, bool clear = false)
{
static int pos, byte;
static bool comment_start, last_line, c_buffer, comment_buffer;
comment_start = false;
if (clear){
last_line = c_buffer = false;
return 0;
}
ReplaceString(buffer, maxlength, "\t", " ");
ReplaceString(buffer, maxlength, "\"", "'");
ReplaceString(buffer, maxlength, "%", "%%");
TrimString(buffer);
if (strlen(buffer))
{
pos = 0;
if (!comment_buffer){
if (buffer[0] == '/' && (buffer[1] == '/' || (c_buffer = comment_buffer = buffer[1] == '*')))
{
comment_start = true;
strcopy(buffer, 1023, buffer[2]);
Debug(DEBUG_BIT_COMMENTARY, "%s comment: '%s'", comment_buffer ? "block" : "inline" , buffer);
}
}
if (comment_buffer && (pos = StrContains(buffer, "*/")) != -1)
{
c_buffer = false;
buffer[pos] = 0;
TrimString(buffer);
Debug(DEBUG_BIT_COMMENTARY, "end of block comment: '%s'", buffer);
}
if (!comment_start && !comment_buffer){
if ((pos = StrContains(buffer, "/*")) != -1 || (pos = StrContains(buffer, "//")) != -1)
buffer[pos] = 0;
}
//else if (comment_buffer)
// Debug(DEBUG_BIT_COMMENTARY, "in block comment: '%s'", buffer);
TrimString(buffer);
}
byte = strlen(buffer) ? READSTRING_BIT_VALID : READSTRING_BIT_INVALID;
if (comment_buffer)
byte |= READSTRING_BIT_BUFFER;
else if (comment_start)
byte |= READSTRING_BIT_INLINE;
if (last_line)
byte |= READSTRING_BIT_LAST;
if (!(byte & READSTRING_BIT_INLINE) && !(byte & READSTRING_BIT_BUFFER))
last_line = true;
else if ((byte & READSTRING_BIT_INLINE) || (byte & READSTRING_BIT_BUFFER))
last_line = false;
comment_buffer = c_buffer;
return byte;
}
bool ReadFuncString(char[] buffer, char[] retval, char[] funcname, bool found_property = false, bool in_property = false)
{
retval[0] = 0;
funcname[0] = 0;
static int pos, len;
if ((len = strlen(buffer)))
{
if (found_property && !in_property){
if ((pos = FindCharInString2(buffer, '{')) == -1)
pos = len;
}
else if ((pos = FindCharInString2(buffer, '(')) == -1)
return false;
strcopy(funcname, pos+1, buffer);
strcopy(buffer, len, buffer[pos]);
TrimString(funcname);
Debug(DEBUG_BIT_COMMON, "ReadFuncString -> '%s'", funcname);
if (strcmp(funcname, "VerifyCoreVersion") == 0 ||
StrContains(funcname, "operator") != -1)
{
return false;
}
if ((pos = FindCharInString2(funcname, 32)) != -1 || (pos = FindCharInString2(funcname, 58)) != -1)
{
strcopy(retval, ++pos, funcname);
strcopy(funcname, len, funcname[pos]);
if(retval[0] == 70) // little fix 'F' -> 'f'
retval[0] = 102;
}
return true;
}
return false;
}
bool ReadMethodmapHeader(char[] buffer)
{
// ex: 'methodmap ArrayList < Handle {'
// result: str1=ArrayList, str2=Handle
g_MethodmapName[0] = 0;
g_MethodmapTag[0] = 0;
TrimString(buffer);
if (buffer[0]){
static char str[1024];
str[0] = 0;
strcopy(str, 10, buffer);
if (strcmp(str, "methodmap") == 0){
static int pos;
str[0] = 0;
strcopy(str, sizeof(str), buffer);
strcopy(str, sizeof(str), str[10]);
ReplaceString(str, sizeof(str), "{", "");
TrimString(str);
Debug(DEBUG_BIT_METHODMAP, "methodmap detected! '%s'", buffer);
if ((pos = FindCharInString2(str, '<')) != -1)
{
strcopy(g_MethodmapTag, sizeof(g_MethodmapTag), str[pos+1]);
strcopy(str, pos, str);
TrimString(g_MethodmapTag);
TrimString(str);
Debug(DEBUG_BIT_METHODMAP, "tag detected! calss='%s', tag='%s'", str, g_MethodmapTag);
if (IsValidString(g_MethodmapTag)){
if (FindStringInArray(g_MiscArray, g_MethodmapTag) == -1)
PushArrayString(g_MiscArray, g_MethodmapTag);
}
else
g_MethodmapTag[0] = 0;
}
strcopy(g_MethodmapName, sizeof(g_MethodmapName), str);
if (IsValidString(g_MethodmapName)){
if (FindStringInArray(g_MiscArray, g_MethodmapName) == -1)
PushArrayString(g_MiscArray, g_MethodmapName);
Debug(DEBUG_BIT_METHODMAP, "success! calss='%s', tag='%s'", g_MethodmapName, g_MethodmapTag);
return true;
}
else {
g_MethodmapName[0] = 0;
g_MethodmapTag[0] = 0;
Debug(DEBUG_BIT_ERROR, "Failed to detect methodmap class/tag. Called from %s", g_Debug[DEBUG_TAG_METHODMAP]);
return false;