forked from sevoku/doxygen-vb-filter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvbfilter.awk
More file actions
executable file
·1398 lines (1278 loc) · 39.4 KB
/
vbfilter.awk
File metadata and controls
executable file
·1398 lines (1278 loc) · 39.4 KB
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
#----------------------------------------------------------------------------
# vbfilter.awk - doxygen VB .NET filter script - v2.4.1
#
# Creation: 26.05.2010 Vsevolod Kukol
# Last Update: 09.10.2011 Vsevolod Kukol
#
# Copyright (c) 2010-2011 Vsevolod Kukol, sevo(at)sevo(dot)org
#
# Inspired by the Visual Basic convertion script written by
# Mathias Henze. Rewritten from scratch with VB.NET support by
# Vsevolod Kukol.
#
# requirements: doxygen, gawk
#
# usage:
# 1. create a wrapper shell script:
# #!/bin/sh
# gawk -f /path/to/vbfilter.awk "$1"
# EOF
# 2. define wrapper script as INPUT_FILTER in your Doxyfile:
# INPUT_FILTER = /path/to/vbfilter.sh
# 3. take a look on the configuration options in the Configuration
# section of this file (inside BEGIN function)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#----------------------------------------------------------------------------
BEGIN {
#############################################################################
# Configuration
#############################################################################
# unix line breaks
# set to 1 if using doxygen on unix with
# windows formatted sources
UnixLineBreaks=1
# leading shift inside classes/namespaces/etc.
# default is "\t" (tab)
ShiftRight="\t"
#ShiftRight=" "
# add namespace definition at the beginning using project directory name
# should be enabled, if no explicit namespaces are used in the sources
# but doxygen should recognize package names.
# in C# unlike in VB .NET a namespace must always be defined
leadingNamespace=1
# per default the parser converts all keywords to their C# equivalents:
# Function -> function
# Sub -> void
# ....
# Set csharpStyledOutput=0 to keep the VB style in the resulting
# documentation.
csharpStyledOutput=1
#############################################################################
# helper variables, don't change
#############################################################################
fullLine=1
classNestCounter=0
className[1]=""
insideVB6Class=0
insideFunction=0
insideInterface=0
insideVB6ClassName=""
insideVB6Header=0
insideNamespace=0
insideComment=0
insideVB6Property=0
isInherited=0
lastLine=""
appShift=""
defaultFileHeaderPrinted=0
defaultClassPrinted=0
VB6ClassCommentLineCount=1
VB6ClassComment[VB6ClassCommentLineCount++]="/**"
insideVB6ClassComment=0
split("file_class_struct_enum_union_fn_var_def_namespace_package_interface", doxygen_structural_commands, "_")
split("bas_cls_ctl_frm_vb", valid_vb_extensions, "_")
exitCode=0
isVBFileExtension=1
#############################################################################
# check for valid vb file extension
#############################################################################
# if not a valid file extension then ARGV[1]
fileExtension = b[split(a[split(gensub(/\\/, "/", "G", ARGV[1]), a, "/")], b, ".")]
fileBaseName=b[split(a[split(gensub(/\\/, "/", "G", ARGV[1]), a, "/")], b, ".")-1]
if (!element_exists(fileExtension, valid_vb_extensions)) {
isVBFileExtension = 0
exitCode = 2
}
}
#############################################################################
# shifter functions
#############################################################################
function AddShift() {
appShift=appShift ShiftRight
}
function ReduceShift() {
appShift=substr(appShift,0,length(appShift)-length(ShiftRight))
}
#############################################################################
# trim functions
#############################################################################
function rtrim(s) {
sub(/[ \t\r\n]+$/, "", s)
return s
}
function ltrim(s) {
sub(/^[ \t\r\n]+/, "", s)
return s
}
function trim(s) {
return rtrim(ltrim(s))
}
#############################################################################
# check if element is part of array
#############################################################################
function element_exists(element, array, x, y) {
for (x in array) y[array[x]]
return element in y
}
#############################################################################
# join all elements of an array into one string
#############################################################################
function join(array, len, sep, result, i) {
result = array[1]
for (i = 2; i <= len; i++) {
result = result sep array[i]
}
return result
}
#############################################################################
# check for an regex in the code part of a line only
# (excluding inline comments)
#############################################################################
function is_in_code(regex, data, len, segments) {
# Split line by "/**<" to get code without inline comment
len = split(data, segments, /\/\*\*</)
if (len > 0) {
return match(segments[1], regex)
} else {
return 0
}
}
#############################################################################
# remove VBA inline comments but keep Doxygen inline comments
#############################################################################
function remove_vba_comment(s, i, c) {
# Remove leading and trailing white spaces
s = trim(s)
# Find first '
i = index(s,"'")
# Return original string when there is no comment at all or only comment and no code
if ((i == 0) || (i == 1)) {
return s
}
# Get all content from first ' to line end
c = substr(s, i)
# Check if '''< is first character
if (substr(c, 1, 4) == "'''<") {
return s
} else {
return substr(s, 1, i - 1)
}
}
#############################################################################
# in case this is not a valid vb file (*.cls, *.ctl, *.bas, *.frm, *.vb)
# don't change the file at all
#############################################################################
isVBFileExtension == 0 {
print $0
next
}
#############################################################################
# doxygen requires a file tag to be able to document global functions,
# variables, enums, typedefs and defines
# this is a default tag to ensure proper documentation of global stuff event
# there is no file header added by the user
#############################################################################
defaultFileHeaderPrinted==0 {
print "/** \\file */"
defaultFileHeaderPrinted=1
}
#############################################################################
# print leading namespace
# namespace name is extracted from file path. the last directory name in
# the path, usually the project folder, is used.
#
# can be disabled by leadingNamespace=0 in configuration section
#############################################################################
leadingNamespace==1 {
print "namespace "basename[split(gensub(/\\/, "/", "G", FILENAME), basename , "/")-1]" {"
AddShift()
leadingNamespace=2
}
#############################################################################
# apply dos2unix
#############################################################################
UnixLineBreaks==1 {
sub(/\r$/,"")
}
#############################################################################
# remove vba inline comments
#############################################################################
{
$0=remove_vba_comment($0)
}
#############################################################################
# remove leading and trailing whitespaces and tabs
#############################################################################
{
$0=trim($0)
}
#############################################################################
# merge multiline statements into one line
#############################################################################
fullLine==0 {
fullLine=1
$0= lastLine$0
lastLine=""
}
/_$/ {
fullLine=0
sub(/_$/,"")
lastLine=$0
next
}
#############################################################################
# remove Option and Region statements
#############################################################################
(/^#Region[[:blank:]]+/ ||
/.*Option[[:blank:]]+/) && insideComment!=1 {
next
}
#############################################################################
# VB6 file headers including class definitions
#############################################################################
# if file begins with a class definition, switch to VB6 mode
/.*[[:blank:]]+CLASS/ ||
/.*[[:blank:]]+VB\.Form[[:blank:]]+/ ||
/.*[[:blank:]]+VB\.UserControl[[:blank:]]+/ {
insideVB6Class=1
next
}
# ignore first line in VB6 forms
/.*VERSION[[:blank:]]+[0-9]+/ {
next
}
# get VB6 class name
/^Attribute[[:blank:]]+VB_Name.*/ {
insideVB6ClassName=gensub(".*VB_Name[[:blank:]]+[=][[:blank:]]+\"(.*)\"","\\1","g",$0)
insideVB6Header=1
}
# detect when class attributes begin, to recognize the end of VB6 header
/^Attribute[[:blank:]]+.*/ {
insideVB6Header=1
next
}
# detect the end of VB6 header
(!(/^Attribute[[:blank:]]+.*/)) && insideVB6Class==1 && insideVB6Header<=1 {
if (insideVB6Header==0) {
next
} else {
insideVB6Header=2
}
}
#############################################################################
# print default class when processing VB6 classes
#############################################################################
defaultClassPrinted==0 {
if (insideVB6Class==1) {
isInherited=1
print appShift "class " insideVB6ClassName
# for VB6 classes the class comment needs to be preprocessed as
# it needs to be located outside the class definition for proper
# doxygen processing
VB6ClassComment[VB6ClassCommentLineCount++]=" * \\class " insideVB6ClassName
VB6ClassComment[VB6ClassCommentLineCount++]=" */"
}
defaultClassPrinted=1
}
#############################################################################
# skip empty lines or finish comments when inside a comment block
#############################################################################
/^$/ {
# finish normal comment block
if (insideComment==1) {
insideComment=0
print appShift " */"
}
# finish VB6 class comment
if (insideVB6ClassComment==1) {
insideVB6ClassComment=0
VB6ClassComment[VB6ClassCommentLineCount++]=" */"
}
next
}
#############################################################################
# finish class comment here when another structural tag is found
#############################################################################
/^[[:blank:]]*('|''')[[:blank:]]*[@\\][a-zA-Z]+/ &&
insideVB6ClassComment==1 {
# get the tag name
tagname=trim(substr($0, match($0, /[\\, @]/)))
if (match(tagname, /[[:blank:]]+/)==0) {
tagname=trim(substr(tagname, 2))
} else {
tagname=trim(substr(tagname, 2, RSTART-1))
}
# check if tag is a structural tag
if (element_exists(tagname, doxygen_structural_commands)) {
# finish class tag
insideVB6ClassComment=0
VB6ClassComment[VB6ClassCommentLineCount++]=" */"
}
}
#############################################################################
# finish class comment here when no comment is in this line
#############################################################################
(!(/^[[:blank:]]*'/)) && insideVB6ClassComment==1 {
insideVB6ClassComment=0
VB6ClassComment[VB6ClassCommentLineCount++]=" */"
}
#############################################################################
# detect begin of VB6 class comment (\class, @class)
#############################################################################
/^[[:blank:]]*('|''')[[:blank:]]*[@\\]class[[:blank:]]*/ &&
insideVB6Class==1 {
if (insideVB6ClassComment==1) {
# finish class comment and start new one
VB6ClassComment[VB6ClassCommentLineCount++]=" */"
}
VB6ClassComment[VB6ClassCommentLineCount++]="/**"
VB6ClassComment[VB6ClassCommentLineCount++]=gensub("^[ \t]*[']+"," * ",1,$0)
insideVB6ClassComment=1
next
}
#############################################################################
# handle class comments of VB6 classes as they need to be located outside
# the class definition for proper doxygen output
#############################################################################
(insideVB6ClassComment==1) {
# process class comments
VB6ClassComment[VB6ClassCommentLineCount++]=gensub("^[ \t]*[']+"," * ",1,$0)
next
}
#############################################################################
# convert Imports to C# style
#
# remark: doxygen seems not to recognize
# c# using directives so converting Imports is maybe useless?
#############################################################################
/^Imports[[:blank:]]+/ || /[[:blank:]]+Imports[[:blank:]]+/ {
sub("Imports","using")
print appShift $0";"
next
}
#############################################################################
# handle comments
#############################################################################
## beginning of comment
(/^[[:blank:]]*'''[[:blank:]]*/ || /^[[:blank:]]*'[[:blank:]]*[\\<@][^ ].+/) && insideComment!=1 {
if (insideEnum==1) {
# if enum is being processed, add comment to enumComment
# instead of printing it
if (enumComment!="") {
enumComment = enumComment "\n" appShift "/**"
} else {
enumComment = appShift "/**"
}
} else if (insideType==1) {
# if type is being processed, add comment to typeComment
# instead of printing it
if (typeComment!="") {
typeComment = typeComment "\n" appShift "/**"
} else {
typeComment = appShift "/**"
}
} else {
# if inheritance is being processed, then add comment to lastLine
# instead of printing it and process the end of
# class/interface declaration
if (isInherited==1) {
endOfInheritance()
}
print appShift "/**"
}
insideComment=1
}
## strip leading '''
/^[[:blank:]]*'/ {
if (insideComment==1) {
commentString=gensub("^[ \t]*[']+"," * ",1,$0)
# if enum is being processed, add comment to enumComment
# instead of printing it
if (insideEnum==1) {
enumComment = enumComment "\n" appShift commentString
# if type is being processed, add comment to typeComment
# instead of printing it
} else if (insideType==1) {
typeComment = typeComment "\n" appShift commentString
} else {
print appShift commentString
}
next
}
}
## end of comment
(!(/^[[:blank:]]*'/)) && insideComment==1 {
# if enum is being processed, add comment to enumComment
# instead of printing it
if (insideEnum==1) {
enumComment = enumComment "\n" appShift " */"
# if type is being processed, add comment to typeComment
# instead of printing it
} else if (insideType==1) {
typeComment = typeComment "\n" appShift " */"
} else {
print appShift " */"
}
insideComment=0
}
#############################################################################
# inline comments in c# style /** ... */
#############################################################################
# strip all commented lines, if not part of a comment block
/^'+/ && insideComment!=1 {
next
}
/.+'''</ && insideComment!=1 {
sub("[[:blank:]]*'''<[[:blank:]]*"," /**< \\brief ")
$0 = $0" */"
}
#############################################################################
# strip compiler options
#############################################################################
/.*<.*>.*/ {
gsub("<.*>[ ]+","")
}
#############################################################################
# Set insideInterface variable before setting insideFunction variable
#############################################################################
/^Interface[[:blank:]]+/ || /[[:blank:]]+Interface[[:blank:]]+/ {
insideInterface=1
}
/^[ \t]*End[[:blank:]]+Interface/ && insideInterface==1 {
insideInterface=0
}
#############################################################################
# Set flag if we are inside a function/sub to avoid processing keywords
# like Enum, Sub, Function etc... within a function
# 0 - Outside function/sub
# 1 - At line fo function/sub definition
# 2 - Inside a function/sub
#############################################################################
insideFunction==1 {
insideFunction=2
}
#############################################################################
# Detect start of a Function/Sub
#############################################################################
(is_in_code("^Function[[:blank:]]+", $0) || is_in_code("[[:blank:]]+Function[[:blank:]]+", $0) ||
is_in_code("^Sub[[:blank:]]+", $0) || is_in_code("[[:blank:]]+Sub[[:blank:]]+", $0)) && insideFunction==0 &&
(!(is_in_code("^Declare[[:blank:]]+", $0) || is_in_code("[[:blank:]]+Declare[[:blank:]]+", $0))) &&
insideInterface==0 {
insideFunction=1
}
#############################################################################
# Detect end of a Function/Sub
#############################################################################
(is_in_code("^[ \t]*End[[:blank:]]+Function", $0) || is_in_code("^[ \t]*End[[:blank:]]+Sub", $0)) &&
insideFunction==2 {
insideFunction=0
}
#############################################################################
# simple rewrites
# vb -> c# style
#
# keywords used by doxygen must be rewritten. All other rewrites
# are optional and depend on the csharpStyledOutput setting.
#############################################################################
/^Private[[:blank:]]+/ || /[[:blank:]]+Private[[:blank:]]+/ {
sub("Private[[:blank:]]+","private ")
}
/^Public[[:blank:]]+/ || /[[:blank:]]+Public[[:blank:]]+/ {
sub("Public[[:blank:]]+","public ")
}
/^Dim[[:blank:]]+/ || /[[:blank:]]+Dim[[:blank:]]+/ {
sub("Dim[[:blank:]]+","private ")
}
# friend is the same as internal in c#, but Doxygen doesn't support internal,
# so make it private to get it recognized by Doxygen) and Friend appear
# in Documentation
/^Friend[[:blank:]]+/ || /[[:blank:]]+Friend[[:blank:]]+/ {
if (csharpStyledOutput==1) {
sub("Friend[[:blank:]]+","private Friend ")
} else {
print appShift"/// \\remark declared as Friend in the VB original source"
sub("Friend[[:blank:]]+","private ")
}
}
/^Protected[[:blank:]]+/ || /[[:blank:]]+Protected[[:blank:]]+/ {
sub("Protected[[:blank:]]+","protected ")
}
/^Shared[[:blank:]]+/ || /[[:blank:]]+Shared[[:blank:]]+/ {
if (csharpStyledOutput==1) {
sub("Shared", "static")
} else {
sub("Shared", "static Shared")
}
}
# Replace "Partial" by "partial" and swap order of "partial" and "public" or "private"
/^.*Partial[[:blank:]]+/ {
sub("Partial","partial")
if ($1 == "partial" && $2 ~ /public|private/) {
$1 = $2
$2 = "partial"
}
}
# Const -> const
/\<Const\>/ {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Const\>/, "const", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# No WithEvents in C# - let's treat it like variables
/^.*WithEvents[[:blank:]]+/ && (csharpStyledOutput==1) {
sub("WithEvents","")
}
# Overrides -> override
/[[:blank:]]Overrides[[:blank:]]/ && (csharpStyledOutput==1) {
sub("Overrides","override")
}
# Overridable -> virtual
/[[:blank:]]Overridable[[:blank:]]/ && (csharpStyledOutput==1) {
sub("Overridable","virtual")
}
# Optional has to be removed for c# style
/[[:blank:]]Optional[[:blank:]]/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub("Optional" ," ", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# String -> string
/\<String\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<String\>/, "string", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Boolean -> bool
/\<Boolean\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Boolean\>/, "bool", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Char -> char
/\<Char\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Char\>/, "char", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Byte -> byte
/\<Byte\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Byte\>/, "byte", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Short -> short
/\<Short\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Short\>/, "short", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Integer -> int
/\<Integer\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Integer\>/, "int", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Long -> long
/\<Long\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Long\>/, "long", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Single -> float
/\<Single\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Single\>/, "float", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Double -> double
/\<Double\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Double\>/, "double", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Decimal -> decimal
/\<Decimal\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Decimal\>/, "decimal", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Date -> DateTime
/\<Date\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Date\>/, "DateTime", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Object -> object
/\<Object\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Object\>/, "object", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# Delegate -> delegate
/\<Delegate\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<Delegate\>/, "delegate", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
# AddressOf -> &
/\<AddressOf\>/ && (csharpStyledOutput==1) {
# Split line by inline comment string sequence
# to avoid changing any keywords inside a comment
len = split($0, line_segs, /\/\*\*</)
if (len > 0) {
# Change stuff
gsub(/\<AddressOf\>/, "\\&", line_segs[1])
}
# Recombine line
$0 = join(line_segs, len, "/**<")
}
#############################################################################
# enums
#############################################################################
(is_in_code("^Enum[[:blank:]]+", $0) || is_in_code("[[:blank:]]+Enum[[:blank:]]+", $0)) && insideFunction!=2 {
sub("Enum", "enum")
# Enumerations shouldn't have type definition so remove it
if (is_in_code("[[:blank:]]+As[[:blank:]]+.*", $0)) {
sub("[[:blank:]]+As[[:blank:]]+.*", "")
}
if (isInherited==1) {
endOfInheritance()
}
print appShift $0 "\n" appShift "{"
insideEnum=1
lastEnumLine=""
AddShift()
next
}
is_in_code("^[ \t]*End[[:blank:]]+Enum", $0) && insideEnum==1 {
print appShift lastEnumLine
ReduceShift()
print appShift "}"
insideEnum=0
lastEnumLine=""
enumComment=""
next
}
insideEnum==1 {
if (lastEnumLine == "") {
lastEnumLine = $0
if (enumComment!="") {
print enumComment
}
enumComment=""
} else {
commentPart=substr(lastEnumLine,match(lastEnumLine,"[/][*][*]<"))
definitionPart=substr(lastEnumLine,0,match(lastEnumLine,"[/][*][*]<")-2)
if (definitionPart=="") {
print appShift commentPart ","
} else {
print appShift definitionPart ", " commentPart
}
lastEnumLine = $0
# print leading comment of next element, if present
if (enumComment!="") {
print enumComment
}
enumComment=""
}
next
}
#############################################################################
# types
#############################################################################
(is_in_code("^Type[[:blank:]]+", $0) || is_in_code("[[:blank:]]+Type[[:blank:]]+", $0)) && insideFunction!=2 {
sub("Type","struct")
# Types shouldn't have type definition so remove it
if (is_in_code("[[:blank:]]+As[[:blank:]]+.*", $0)) {
sub("[[:blank:]]+As[[:blank:]]+.*", "")
}
sub("+*[[:blank:]]As.*",""); # types shouldn't have type definitions
if (isInherited==1) {
endOfInheritance()
}
print appShift $0"\n"appShift"{"
insideType=1
lastTypeLine=""
AddShift()
next
}
is_in_code("^[ \t]*End[[:blank:]]+Type", $0) && insideType==1 {
if (match(lastTypeLine,"[/][*][*]<") != 0) {
commentPart=substr(lastTypeLine,match(lastTypeLine,"[/][*][*]<"))
definitionPart=substr(lastTypeLine,0,match(lastTypeLine,"[/][*][*]<")-2)
} else {
commentPart=""
definitionPart=lastTypeLine
}
if (definitionPart=="") {
print appShift commentPart ";"
} else {
print appShift convertSimpleType(definitionPart) "; " commentPart
}
ReduceShift()
print appShift "}"
insideType=0
lastTypeLine=""
typeComment=""
next
}
insideType==1 {
if (lastTypeLine == "") {
lastTypeLine = $0
if (typeComment!="") {
print typeComment
}
typeComment=""
} else {
if (match(lastTypeLine,"[/][*][*]<") != 0) {
commentPart=substr(lastTypeLine,match(lastTypeLine,"[/][*][*]<"))
definitionPart=substr(lastTypeLine,0,match(lastTypeLine,"[/][*][*]<")-2)
} else {
commentPart=""
definitionPart=lastTypeLine
}
if (definitionPart=="") {
print appShift commentPart ";"
} else {
print appShift convertSimpleType(definitionPart) "; " commentPart
}
lastTypeLine = $0
# print leading comment of next element, if present
if (typeComment!="") {
print typeComment
}
typeComment=""
}
next
}
#############################################################################
# Declares
#############################################################################
/.*Declare[[:blank:]]+/ && insideFunction!=2 {
libName=gensub(".+Lib[[:blank:]]+\"([^ ]*)\"[[:blank:]].*","\\1","g")
# exchange \ in path name with \\ to avoid doxygen warnings
gsub(/\\/, "\\\\", libName)
if (match($0,"Alias")>0) {
aliasName=gensub(".+Alias[[:blank:]]+\"([^ ]*)\"[[:blank:]].*"," (Alias: \\1)","g")
}
if (isInherited==1) {
endOfInheritance()
}
print appShift "/** \\remark Is imported from external library: " libName aliasName " */"
if (csharpStyledOutput==1) {
sub(/Declare[[:blank:]]+/, "extern ")
} else {
sub(/Declare[[:blank:]]+/, "")
}
libName=""
aliasName=""
}
# remove lib and alias from declares
/.*Lib[[:blank:]]+/ {
sub("Lib[[:blank:]]+[^[:blank:]]+","")
sub("Alias[[:blank:]]+[^[:blank:]]+","")
}
#############################################################################
# types (handle As and Of)
#############################################################################
/.*[(]Of[ ][^ ]+[)].*/ {
$0=gensub("[(]Of[ ]([^ )]+)[)]", "<\\1>","g",$0)
}
## converts a single type definition to c#
## "Var As Type" -> "Type Var"
## "Var As New Type" -> "Type Var = new Type()"
function convertSimpleType(Param) {
l=split(Param, aParam, " ")
newParam=""
for (j = 1; j <= l; j++) {
if (aParam[j] == "As") {
typeIndex = 1
if (aParam[j+1] == "New") {
typeIndex = 2
aParam[j+1] = ""
}
aParam[j]=aParam[j-1]
aParam[j-1]=aParam[j+typeIndex]
aParam[j+typeIndex]=""
}
}
for (j = 1; j <= l; j++) {
if (aParam[j]!="") {
if (j == 1) {
newParam=aParam[j]
} else {
newParam=newParam " " aParam[j]
}
}
}
l=""
delete aParam
return newParam
}
function rindex(string, find) {
ns=length(string)
nf=length(find)
for (r = ns + 1 - nf; r>=1; r--) {
if (substr(string, r, nf) == find) {
return r