@@ -35,13 +35,14 @@ sub processDoxygenLine
35
35
if ( $line =~ m /[\\ @] brief (.*)/ ) {
36
36
return " $1 \n " ;
37
37
}
38
- return $line ;
38
+ return " $line \n " ;
39
39
}
40
40
41
-
42
41
my $headerfile = $ARGV [0];
43
42
44
- open (my $header , " <" , $headerfile ) || die " Couldn't open '" .$headerfile ." ' for reading because: " .$! ;
43
+ open (my $handle , " <" , $headerfile ) || die " Couldn't open '" .$headerfile ." ' for reading because: " .$! ;
44
+ chomp (my @lines = <$handle >);
45
+ close $handle ;
45
46
46
47
# contexts
47
48
my $SIP_RUN = 0;
@@ -52,40 +53,44 @@ sub processDoxygenLine
52
53
my $comment = ' ' ;
53
54
my $nesting_index = 0;
54
55
my $private_section_line = ' ' ;
55
- my $line ;
56
56
my $classname = ' ' ;
57
57
my $return_type = ' ' ;
58
58
my $is_override = 0;
59
59
my %qflag_hash ;
60
60
61
- print " /************************************************************************\n " ;
62
- print " * This file has been generated automatically from *\n " ;
63
- print " * *\n " ;
64
- printf " * %-*s *\n " , 68, $headerfile ;
65
- print " * *\n " ;
66
- print " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n " ;
67
- print " ************************************************************************/\n " ;
61
+ my $line_count = @lines ;
62
+ my $line_idx = -1;
63
+ my $line ;
64
+ my @output = ();
68
65
66
+ push @output , " /************************************************************************\n " ;
67
+ push @output , " * This file has been generated automatically from *\n " ;
68
+ push @output , " * *\n " ;
69
+ push @output , sprintf " * %-*s *\n " , 68, $headerfile ;
70
+ push @output , " * *\n " ;
71
+ push @output , " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n " ;
72
+ push @output , " ************************************************************************/\n " ;
69
73
70
- while (!eof $header ){
71
- $line = readline $header ;
72
- # print $line;
74
+ while ($line_idx < $line_count ){
75
+ $line = $lines [$line_idx ];
76
+ $line_idx ++;
77
+ # push @output, "$line\n";
73
78
74
79
if ($line =~ m / ^\s *SIP_FEATURE\( (\w +) \) (.*)$ / ){
75
- print " %Feature $1$2 \n " ;
80
+ push @output , " %Feature $1$2 \n " ;
76
81
next ;
77
82
}
78
83
if ($line =~ m / ^\s *SIP_IF_FEATURE\( (\! ?\w +) \) (.*)$ / ){
79
- print " %If ($1 )$2 \n " ;
84
+ push @output , " %If ($1 )$2 \n " ;
80
85
next ;
81
86
}
82
87
if ($line =~ m / ^\s *SIP_CONVERT_TO_SUBCLASS_CODE(.*)$ / ){
83
- print " %ConvertToSubClassCode$1 \n " ;
88
+ push @output , " %ConvertToSubClassCode$1 \n " ;
84
89
next ;
85
90
}
86
91
87
92
if ($line =~ m / ^\s *SIP_END(.*)$ / ){
88
- print " %End$1 \n " ;
93
+ push @output , " %End$1 \n " ;
89
94
next ;
90
95
}
91
96
@@ -94,7 +99,7 @@ sub processDoxygenLine
94
99
if ( $line =~ m / ^\s *#ifdef SIP_RUN/ ){
95
100
$SIP_RUN = 1;
96
101
if ($ACCESS == PRIVATE){
97
- print $private_section_line
102
+ push @output , $private_section_line . " \n " ;
98
103
}
99
104
next ;
100
105
}
@@ -114,8 +119,9 @@ sub processDoxygenLine
114
119
115
120
# if there is an else at this level, code will be ignored i.e. not SIP_RUN
116
121
if ( $line =~ m / ^\s *#else/ && $nesting_index == 0){
117
- while (!eof $header ){
118
- $line = readline $header ;
122
+ while ($line_idx < $line_count ){
123
+ $line = $lines [$line_idx ];
124
+ $line_idx ++;
119
125
if ( $line =~ m / ^\s *#if(def)?\s +/ ){
120
126
$nesting_index ++;
121
127
}
@@ -134,15 +140,16 @@ sub processDoxygenLine
134
140
}
135
141
elsif ( $line =~ m / ^\s *#ifndef SIP_RUN/ ){
136
142
# code is ignored here
137
- while (!eof $header ){
138
- $line = readline $header ;
143
+ while ($line_idx < $line_count ){
144
+ $line = $lines [$line_idx ];
145
+ $line_idx ++;
139
146
if ( $line =~ m / ^\s *#if(def)?\s +/ ){
140
147
$nesting_index ++;
141
148
}
142
149
elsif ( $line =~ m / ^\s *#else/ && $nesting_index == 0 ){
143
150
# code here will be printed out
144
151
if ($ACCESS == PRIVATE){
145
- print $private_section_line ;
152
+ push @output , $private_section_line . " \n " ;
146
153
}
147
154
$SIP_RUN = 1;
148
155
last ;
@@ -167,7 +174,7 @@ sub processDoxygenLine
167
174
# TYPE HEADER CODE
168
175
if ( $HEADER_CODE && $SIP_RUN == 0 ){
169
176
$HEADER_CODE = 0;
170
- print " %End \n " ;
177
+ push @output , " %End \n " ;
171
178
}
172
179
173
180
# Skip forward declarations
@@ -205,33 +212,36 @@ sub processDoxygenLine
205
212
}
206
213
# Skip assignment operator
207
214
if ( $line =~ m / operator=\s *\( / ){
208
- print " // $line " ;
215
+ push @output , " // $line " ;
209
216
next ;
210
217
}
211
218
212
219
# Detect comment block
213
220
if ($line =~ m / ^\s *\/\* / ){
214
221
do {no warnings ' uninitialized' ;
215
- $comment = processDoxygenLine( $line =~ s / ^\s *\/\* (\* )?(.*) $/ $2 / r );
222
+ $comment = processDoxygenLine( $line =~ s / ^\s *\/\* (\* )?(.*?) \n ? $/ $2 / r );
216
223
};
217
224
$comment =~ s / ^\s *$// ;
218
- while (!eof $header ){
219
- $line = readline $header ;
220
- $comment .= processDoxygenLine( $line =~ s /\s *\* ?(.*?)(\/ )?$/ $1 / r );
225
+ # $comment =~ s/^(\s*\n)*(.+)/$2/;
226
+ while ($line_idx < $line_count ){
227
+ $line = $lines [$line_idx ];
228
+ $line_idx ++;
229
+ $comment .= processDoxygenLine( $line =~ s /\s *\* ?(.*?)(\/ )?\n ?$/ $1 / r );
221
230
if ( $line =~ m /\*\/ $ / ){
222
231
last ;
223
232
}
224
233
}
225
- $comment =~ s /( \n ) +$// ;
226
- # print $comment;
234
+ $comment =~ s /\n +$// ;
235
+ # push @output, $comment;
227
236
next ;
228
237
}
229
238
230
239
# save comments and do not print them, except in SIP_RUN
231
240
if ( $SIP_RUN == 0 ){
232
241
if ( $line =~ m / ^\s *\/\/ / ){
233
- $line =~ s / ^\s *\/\/\! *\s *(.*)\n ?$/ $1 / ;
242
+ $line =~ s / ^\s *\/\/\! *\s *(.*? )\n ?$/ $1 / ;
234
243
$comment = processDoxygenLine( $line );
244
+ $comment =~ s /\n +$// ;
235
245
next ;
236
246
}
237
247
}
@@ -263,14 +273,14 @@ sub processDoxygenLine
263
273
if ( $comment !~ m / ^\s *$ / ){
264
274
$line .= " %Docstring \n $comment \n %End \n " ;
265
275
}
266
- $line .= " \n %TypeHeaderCode \n #include \" " . basename($headerfile ) . " \"\n " ;
276
+ $line .= " \n %TypeHeaderCode \n #include \" " . basename($headerfile ) . " \" " ;
267
277
268
- print $line ;
278
+ push @output , " $line \n " ;
269
279
270
- my $skip ;
271
280
# Skip opening curly bracket, we already added that above
272
- $skip = readline $header ;
273
- $skip =~ m / ^\s *{\s $ / || die " Unexpected content on line $line " ;
281
+ my $skip = $lines [$line_idx ];
282
+ $line_idx ++;
283
+ $skip =~ m / ^\s *{\s *$ / || die " Unexpected content on line $skip " ;
274
284
275
285
$comment = ' ' ;
276
286
$HEADER_CODE = 1;
@@ -280,19 +290,21 @@ sub processDoxygenLine
280
290
281
291
# Enum declaration
282
292
if ( $line =~ m / ^\s *enum\s +\w +.*?$ / ){
283
- print $line ;
284
- $line = readline $header ;
293
+ push @output , " $line \n " ;
294
+ $line = $lines [$line_idx ];
295
+ $line_idx ++;
285
296
$line =~ m / ^\s *\{\s *$ / || die ' Unexpected content: enum should be followed by {' ;
286
- print $line ;
287
- while (!eof $header ){
288
- $line = readline $header ;
297
+ push @output , " $line \n " ;
298
+ while ($line_idx < $line_count ){
299
+ $line = $lines [$line_idx ];
300
+ $line_idx ++;
289
301
if ($line =~ m /\} ;/ ){
290
302
last ;
291
303
}
292
304
$line =~ s / (\s *\w +)(\s *=\s *[\w\s\d <|]+.*?)?(,?).*$/ $1$3 / ;
293
- print $line ;
305
+ push @output , " $line \n " ;
294
306
}
295
- print $line ;
307
+ push @output , " $line \n " ;
296
308
# enums don't have Docstring apparently
297
309
$comment = ' ' ;
298
310
next ;
@@ -305,7 +317,7 @@ sub processDoxygenLine
305
317
306
318
# remove struct member assignment
307
319
if ( $SIP_RUN != 1 && $ACCESS == PUBLIC && $line =~ m / ^(\s *\w +[\w <> *&:,]* \* ?\w +) = \w +(\( [^()]+\) )?;/ ){
308
- $line = " $1 ;\n " ;
320
+ $line = " $1 ;" ;
309
321
}
310
322
311
323
# catch Q_DECLARE_FLAGS
@@ -342,8 +354,9 @@ sub processDoxygenLine
342
354
if ( $line =~ m / ^(\s *)?(explicit )?(\w +)\( [\w\=\(\)\s\,\&\*\<\> ] *\) (?!;)$ / ){
343
355
my $newline = $line =~ s /\n / ;\n / r ;
344
356
my $nesting_index = 0;
345
- while (!eof $header ){
346
- $line = readline $header ;
357
+ while ($line_idx < $line_count ){
358
+ $line = $lines [$line_idx ];
359
+ $line_idx ++;
347
360
if ( $nesting_index == 0 ){
348
361
if ( $line =~ m / ^\s *(:|,)/ ){
349
362
next ;
@@ -368,12 +381,14 @@ sub processDoxygenLine
368
381
369
382
# remove function bodies
370
383
if ( $line =~ m / ^(\s *)?(virtual )?(static |const )*(([\w :]+(<.*?>)?\s +(\* |&)?)?(\w +|operator.{1,2})\( .*?(\( .*\) )*.*\) ( (?:const|SIP_[A-Z_]*?))*)\s *(\{ .*\} )?(?!;)(\s *\/\/ .*)?$ / ){
371
- my $newline = " $1$2$3$4 ;\n " ;
384
+ my $newline = " $1$2$3$4 ;" ;
372
385
if ($line !~ m /\{ .*?\} $ / ){
373
- $line = readline $header ;
386
+ $line = $lines [$line_idx ];
387
+ $line_idx ++;
374
388
if ( $line =~ m / ^\s *\{\s *$ / ){
375
- while (!eof $header ){
376
- $line = readline $header ;
389
+ while ($line_idx < $line_count ){
390
+ $line = $lines [$line_idx ];
391
+ $line_idx ++;
377
392
if ( $line =~ m /\}\s *$ / ){
378
393
last ;
379
394
}
@@ -385,7 +400,7 @@ sub processDoxygenLine
385
400
386
401
# remove inline declarations
387
402
if ( $line =~ m / ^(\s *)?(static |const )*(([\w :]+(<.*?>)?\s +(\* |&)?)?(\w +)( (?:const*?))*)\s *(\{ .*\} );(\s *\/\/ .*)?$ / ){
388
- my $newline = " $1$3 ;\n " ;
403
+ my $newline = " $1$3 ;" ;
389
404
$line = $newline ;
390
405
}
391
406
@@ -432,7 +447,7 @@ sub processDoxygenLine
432
447
$line =~ s /\s *% (MappedType|TypeHeaderCode|ConvertFromTypeCode|ConvertToTypeCode|MethodCode|End)/ %$1 / ;
433
448
$line =~ s /\/\s +GetWrapper\s +\/ / \/ GetWrapper\/ / ;
434
449
435
- print $line ;
450
+ push @output , " $line \n " ;
436
451
437
452
# multiline definition (parenthesis left open)
438
453
if ( $MULTILINE_DEFINITION == 1 ){
@@ -463,24 +478,27 @@ sub processDoxygenLine
463
478
# parent class Docstring
464
479
}
465
480
else {
466
- print " %Docstring \n " ;
481
+ push @output , " %Docstring \n " ;
467
482
if ( $comment !~ m / ^\s *$ / ){
468
- print " $comment \n " ;
483
+ push @output , " $comment \n " ;
469
484
}
470
485
if ($return_type ne ' ' ){
471
- print " :rtype: $return_type \n " ;
486
+ push @output , " :rtype: $return_type \n " ;
472
487
}
473
- print " %End \n " ;
488
+ push @output , " %End \n " ;
474
489
}
475
490
$comment = ' ' ;
476
491
$return_type = ' ' ;
477
492
$is_override = 0;
478
493
}
479
494
}
480
- print " /************************************************************************\n " ;
481
- print " * This file has been generated automatically from *\n " ;
482
- print " * *\n " ;
483
- printf " * %-*s *\n " , 68, $headerfile ;
484
- print " * *\n " ;
485
- print " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n " ;
486
- print " ************************************************************************/\n " ;
495
+ push @output , " /************************************************************************\n " ;
496
+ push @output , " * This file has been generated automatically from *\n " ;
497
+ push @output , " * *\n " ;
498
+ push @output , sprintf " * %-*s *\n " , 68, $headerfile ;
499
+ push @output , " * *\n " ;
500
+ push @output , " * Do not edit manually ! Edit header and run scripts/sipify.pl again *\n " ;
501
+ push @output , " ************************************************************************/\n " ;
502
+
503
+
504
+ print join (' ' ,@output )." \n " ;
0 commit comments