├── tests ├── test.qc ├── test.h ├── qcall.h ├── test.cpp └── qcall.cpp ├── install └── qc.pl /tests/test.qc: -------------------------------------------------------------------------------- 1 | void main(){ 2 | printf("Hello world") 3 | return 0 4 | } 5 | -------------------------------------------------------------------------------- /install: -------------------------------------------------------------------------------- 1 | PREFIX=$HOME/.local 2 | BINFILE=$PREFIX/bin/qc 3 | cp qc.pl $BINFILE 4 | chmod +x $BINFILE 5 | 6 | 7 | -------------------------------------------------------------------------------- /tests/test.h: -------------------------------------------------------------------------------- 1 | 2 | class reactor { 3 | public: 4 | #pragma qc start 5 | void somefunction(); 6 | void init(); 7 | #pragma qc end 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /tests/qcall.h: -------------------------------------------------------------------------------- 1 | #pragma qc main 2 | #pragma once 3 | #include 4 | #include 5 | class HH { 6 | public: 7 | int x; 8 | int y; 9 | int sum(); 10 | }; 11 | -------------------------------------------------------------------------------- /tests/test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "test.h" 5 | #define cc reactor:: 6 | 7 | void cc somefunction() { 8 | 9 | 10 | } 11 | 12 | void cc init() { 13 | printf("Hello world\n"); 14 | } 15 | 16 | int main(){ 17 | reactor r; 18 | r.init(); 19 | } 20 | -------------------------------------------------------------------------------- /tests/qcall.cpp: -------------------------------------------------------------------------------- 1 | #include "qcall.h" 2 | 3 | #ifndef QC_PURE 4 | #include 5 | #include 6 | #endif 7 | #define cc HH:: 8 | 9 | #pragma qc class HH 10 | #ifdef QC_PURE 11 | int x; 12 | int y; 13 | #endif 14 | 15 | int cc sum(){ 16 | return x + y; 17 | } 18 | #pragma qc endc 19 | 20 | int main(){ 21 | HH a; 22 | a.x = 3; 23 | a.y = 8; 24 | int s; 25 | s = a.sum(); 26 | printf("the sum = %d\n", s); 27 | } 28 | -------------------------------------------------------------------------------- /qc.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use File::Basename; 4 | use File::Spec; 5 | 6 | # reduce repetitive stuff in c++ 7 | #quick C = qc 8 | our $outdir; 9 | our $errorOnChanges; 10 | 11 | $errorOnChanges = 0; 12 | 13 | sub abspath { 14 | my ($path) = @_; 15 | return File::Spec->rel2abs($path); 16 | } 17 | 18 | # get an array of all files and sub files of given filetype 19 | sub AllFiles { 20 | my ($filetype) = @_; 21 | my @files; 22 | my $filtered = []; 23 | @files = split("\n", `find ./ -type f`); 24 | 25 | foreach(@files){ 26 | if($_ =~ /^\.\/+(.*\.$filetype)$/){ 27 | push (@$filtered, $1); 28 | } 29 | } 30 | return $filtered; 31 | } 32 | 33 | sub equalArrays { 34 | my ($a, $b) = @_; 35 | 36 | if(@$a != @$b){ 37 | return 0; 38 | } 39 | my $i; 40 | for($i = 0; $i < @$a; $i++){ 41 | if($$a[$i] ne $$b[$i]){ 42 | return 0; 43 | } 44 | } 45 | return 1; 46 | } 47 | sub sameFileContents { 48 | my ($contents, $file) = @_; 49 | my $fcontents; 50 | $fcontents = loadFile($file); 51 | if(!$fcontents) { 52 | return 0; 53 | } 54 | return equalArrays($contents, $fcontents); 55 | } 56 | sub loadFile { 57 | my ($file) = @_; 58 | my ($fh); 59 | if(!(open($fh, "<$file"))){ 60 | print("could not open $file\n"); 61 | return 0; 62 | } 63 | 64 | my $lines = []; 65 | while(<$fh>){ 66 | chomp $_; 67 | push @$lines, $_; 68 | } 69 | close($fh); 70 | return $lines; 71 | } 72 | 73 | sub saveFile { 74 | my ($lines, $file) = @_; 75 | my $i; 76 | my $fh; 77 | my $r; 78 | $r = open $fh, ">$file"; 79 | if(!$r) { 80 | print "could not save $file\n"; 81 | return 0; 82 | } 83 | for($i = 0; $i < @$lines; $i++){ 84 | print $fh $$lines[$i]; 85 | print $fh "\n"; 86 | } 87 | close $fh; 88 | print "Saved $file ...\n"; 89 | } 90 | sub OKToRemake { 91 | my ($file) = @_; 92 | my $fh; 93 | if(!(open($fh, "<$file"))){ 94 | print("could not open $file\n"); 95 | return 0; 96 | } 97 | 98 | my ($line_start, $line_end); 99 | my ($line_num); 100 | $line_start = 0; 101 | $line_end = 0; 102 | 103 | $line_num =0; 104 | while(<$fh>){ 105 | if($_ =~ m/^\#pragma\s+qc start\s*/){ 106 | $line_start = $line_num; 107 | } 108 | if($_ =~ m/^\#pragma\s+qc end\s*/){ 109 | $line_end = $line_num; 110 | close($fh); 111 | return [$line_start, $line_end]; 112 | } 113 | $line_num++; 114 | 115 | } 116 | close($fh); 117 | return 0; 118 | } 119 | 120 | # return true when it is a pure header (All qc generated) 121 | sub isQCAll { 122 | my ($file) = @_; 123 | my $lines; 124 | $lines = loadFile($file); 125 | if(!$lines) { 126 | return 0; 127 | } 128 | if($$lines[0] =~ m/#pragma\s+qc main/){ 129 | return 1; 130 | } 131 | return 0; 132 | } 133 | 134 | # the new thing to do which generates entire header for you 135 | sub qcAll { 136 | my ($cppfile, $hfile) = @_; 137 | 138 | my $lines; 139 | my $gen = []; 140 | 141 | my $function; 142 | my $gl; 143 | my $list = []; 144 | my $i; 145 | my $changed; 146 | $changed = 0; 147 | 148 | my $purecopy; 149 | $lines = loadFile($cppfile); 150 | if(!$lines){ 151 | print "Could not open $cppfile"; 152 | } 153 | print "Processing $cppfile ...\n"; 154 | $purecopy = 0; 155 | 156 | push @$gen, "#pragma qc main"; 157 | push @$gen, "#pragma once"; 158 | 159 | for($i = 0; $i < @$lines; $i++){ 160 | my $l; 161 | $l = $$lines[$i]; 162 | if($purecopy > 0){ 163 | if($l =~ m/^#if/){ 164 | $purecopy++; 165 | } elsif($l =~ m/^#endif/){ 166 | $purecopy--; 167 | } 168 | if($purecopy > 0){ 169 | push @$gen, $l; 170 | } 171 | next; 172 | } 173 | if($l =~ m/^(.*)\scc\s(.*)$/){ 174 | $function = "$1 $2"; 175 | if($function =~ m/(.*?)\s*\{\s*/){ 176 | $function = $1; 177 | } 178 | if($function =~ m/^#/){ 179 | next; 180 | } 181 | 182 | # add to our list 183 | push @$gen, "$function;"; 184 | } elsif($l =~ m/^\s*cc\s(.*)$/){ 185 | $function = "$1"; 186 | if($function =~ m/(.*?)\s*\{\s*/){ 187 | $function = $1; 188 | } 189 | if($function =~ m/^#/){ 190 | next; 191 | } 192 | 193 | # add to our list 194 | push @$gen, "$function;"; 195 | } 196 | 197 | elsif($l =~ m/^#pragma\s+qc\s+class\s+(\S+)\s*\:\s*(\S+)\s*$/){ 198 | # auto put public :) 199 | $gl = "class $1 : public $2 {\npublic:\ntypedef $2 super;"; 200 | my @a; 201 | @a = split(/\n/, $gl); 202 | push @$gen, @a; 203 | }elsif ($l =~ m/^#pragma\s+qc\s+class\s+(.*)$/){ 204 | $gl = $1; 205 | $gl = "class $gl {\npublic:"; 206 | my @a; 207 | @a = split(/\n/, $gl); 208 | push @$gen, @a; 209 | } elsif ($l =~ m/^#pragma\s+qc\s+endc/){ 210 | $gl = "};"; 211 | push @$gen, $gl; 212 | } elsif ($l =~ m/^#ifdef QC_PURE/){ 213 | $purecopy = 1; 214 | } elsif ($l =~ m/^#ifndef QC_PURE/){ # so it can be in both places 215 | $purecopy = 1; 216 | } 217 | #elsif ($l =~ m/^(#include.*$)/){ 218 | # push @$gen, $1; 219 | #} elsif ($l =~ m/^(#import.*$)/){ 220 | # push @$gen, $1; 221 | #} 222 | 223 | 224 | } 225 | 226 | if(!sameFileContents($gen, $hfile)){ 227 | print ("$hfile changed\n"); 228 | saveFile($gen, $hfile); 229 | if(!sameFileContents($gen, $hfile)){ 230 | print "error::!!!! saved file but its different??"; 231 | } 232 | $changed = 1; 233 | } else { 234 | print "Error: !!! previous thing failed\n"; 235 | } 236 | return $changed; 237 | } 238 | 239 | sub dofile { 240 | my ($cppfile, $hfile) = @_; 241 | my $lines; 242 | my $changed; 243 | $changed = 0; 244 | print "Processing $cppfile/$hfile\n"; 245 | $lines = OKToRemake($hfile); 246 | my $cfh; 247 | open $cfh, "<$cppfile" or die "Could not open $cppfile"; 248 | 249 | my $function; 250 | my $list = []; 251 | while(<$cfh>){ 252 | chomp $_; 253 | if($_ =~ m/^(.*)\scc\s(.*)$/){ 254 | $function = "$1 $2"; 255 | if($function =~ m/(.*?)\s*\{\s*/){ 256 | $function = $1; 257 | } 258 | if($function =~ m/^#/){ 259 | next; 260 | } 261 | 262 | # add to our list 263 | push @$list, $function; 264 | } 265 | } 266 | 267 | close($cfh); 268 | my $hfile_lines; 269 | $hfile_lines = loadFile($hfile); 270 | 271 | my($i); 272 | 273 | 274 | my $output = []; 275 | 276 | for($i = 0; $i <= $$lines[0]; $i++){ 277 | push @$output, $$hfile_lines[$i]; 278 | #print $hfh $$hfile_lines[$i] . "\n"; 279 | 280 | } 281 | for($i =0; $i < @$list; $i++){ 282 | push @$output, $$list[$i] . ";"; 283 | #print $hfh $$list[$i] . ";\n"; 284 | } 285 | for($i = $$lines[1]; $i < @$hfile_lines; $i++){ 286 | push @$output, $$hfile_lines[$i]; 287 | #print $hfh $$hfile_lines[$i] . "\n"; 288 | } 289 | if(!sameFileContents($output, $hfile)){ 290 | saveFile($output, $hfile); 291 | $changed = 1; 292 | } 293 | return $changed; 294 | } 295 | 296 | sub getQCDir { 297 | my ($startdir) = @_; 298 | $startdir = abspath($startdir); 299 | while ($startdir && length($startdir) > 0){ 300 | if(-d "$startdir/qcout"){ 301 | return "$startdir/qcout"; 302 | } 303 | $startdir = dirname($startdir); 304 | if($startdir eq "/"){ 305 | last; 306 | } 307 | } 308 | return 0; 309 | } 310 | sub qcFileParse { 311 | my ($file) = @_; 312 | return fileparse($file, "\\.[^\\/]+\$"); 313 | } 314 | sub doqc { 315 | my ($file, $outdir) = @_; 316 | my ($cpp, $h); 317 | my ($name, $dir, $ext) = qcFileParse($file); 318 | my $hcode; 319 | my $cppcode; 320 | my $code; 321 | my $changed; 322 | 323 | $changed = 0; 324 | $code = loadFile($file); 325 | 326 | $hcode = compileH($code, $file); 327 | $cppcode = compileCPP($code, $file); 328 | if(!sameFileContents($hcode, "$outdir/$name.h")){ 329 | saveFile($hcode, "$outdir/$name.h"); 330 | $changed = 1; 331 | } 332 | if(!sameFileContents($cppcode, "$outdir/$name.cpp")){ 333 | saveFile($cppcode, "$outdir/$name.cpp"); 334 | $changed = 1; 335 | } 336 | 337 | return $changed; 338 | } 339 | 340 | sub PreFile { 341 | my ($file) = @_; 342 | 343 | my ($dir, $name, $cpp, $hfile); 344 | my $lines; 345 | my $type; 346 | my $pass; 347 | 348 | $pass = 1; 349 | if($file =~ m/^(.*)\/([^\.]*)\.(.+)$/){ 350 | $dir = $1; 351 | $name = $2; 352 | $type = $3; 353 | $cpp = "$name.$type"; 354 | $hfile = "$name.h"; 355 | } elsif ($file =~ m/^([^\/\.]+)\.(.+)$/){ 356 | $dir = "."; 357 | $name = $1; 358 | $type = $2; 359 | $cpp = "$name.$type"; 360 | $hfile = "$name.h"; 361 | } else { 362 | print "Could not match file $file\n"; 363 | $pass = 0; 364 | } 365 | return 0 if(!$pass); 366 | if($type eq "qc" or $type eq "qc.h" or $type eq "qc.cpp"){ 367 | print "Preprocessing qc file $dir/$cpp ...\n"; 368 | $outdir = getQCDir($dir); 369 | if(!$outdir){ 370 | print "Could not find suitable dir for qc output files"; 371 | return -1; 372 | } 373 | return doqc("$dir/$cpp", $outdir); 374 | } 375 | $lines = OKToRemake("$dir/$hfile"); 376 | if($lines){ 377 | return dofile("$dir/$cpp", "$dir/$hfile"); 378 | } 379 | $lines = isQCAll("$dir/$hfile"); 380 | if($lines){ 381 | return qcAll("$dir/$cpp", "$dir/$hfile"); 382 | } 383 | return 0; 384 | 385 | } 386 | 387 | sub replacements { 388 | my ($string, $search, $replace) = @_; 389 | 390 | my $i; 391 | for($i = @$search-1; $i >= 0; $i--){ 392 | my $s; 393 | my $r; 394 | $s = $$search[$i]; 395 | $r = $$replace[$i]; 396 | my $e; 397 | $e = "s/$s/$r/g;"; 398 | $e = '$string =~ ' . $e; 399 | eval $e; 400 | #$string =~ s/$s/$r/g; 401 | } 402 | return $string; 403 | } 404 | sub compileCPP { 405 | my ($code, $file) = @_; 406 | my $i; 407 | my $gen = []; 408 | my $function_prepend=""; 409 | my $braceLevel; 410 | my $inClass; 411 | my $inEnum; 412 | my $lineNumber; 413 | my $genSize; 414 | my $fileName; 415 | my $dir; 416 | my $ext; 417 | my $put; 418 | 419 | my $replaceStrings = []; 420 | my $searchStrings = []; 421 | my $lineBuffer = []; 422 | 423 | ($fileName, $dir, $ext) = qcFileParse($file); 424 | 425 | $braceLevel = 0; 426 | $inClass = 0; 427 | $inEnum = 0; 428 | $lineNumber = 0; 429 | push @$gen, "#include \"$fileName" . ".h\""; 430 | 431 | my $fullFileName; 432 | $fullFileName = abspath($file); 433 | push @$gen, "#" . "line 1 \"$fullFileName\""; 434 | $genSize = 0; 435 | for($i = 0; $i < @$code || @$lineBuffer > 0; $i++){ 436 | my $line; 437 | if(@$lineBuffer > 0){ 438 | $lineNumber = $i; 439 | $i--; 440 | push @$gen, "#" . "line $lineNumber \"$fullFileName\""; 441 | $line = pop @$lineBuffer; 442 | } else { 443 | $line = $$code[$i]; 444 | $lineNumber = $i+1; 445 | $genSize++; 446 | if(@$gen != $genSize){ 447 | push @$gen, "#" . "line $lineNumber \"$fullFileName\""; 448 | $genSize = @$gen; 449 | } 450 | } 451 | if(!($line =~ /^\s*\$replace\s+/)){ 452 | $line = replacements($line, $searchStrings, $replaceStrings); 453 | } 454 | if($line =~ m/\n/){ 455 | my @array; 456 | @array = split(/\n/, $line); 457 | @array = reverse(@array); 458 | push @$lineBuffer, @array; 459 | next; 460 | } 461 | if(!$inEnum && $line =~ m/^(\s*)if\s(.*)$/){ 462 | $put = $1 . "if ($2) {"; 463 | push @$gen, $put; 464 | } elsif ($line =~ m/^(\s*)while\s(.*)$/){ 465 | $put = $1 . "while ($2) {"; 466 | push @$gen, $put; 467 | } elsif ($line =~ m/^(\s*)for\s(.*)$/){ 468 | $put = $1 . "for ($2) {"; 469 | push @$gen, $put; 470 | } elsif($line =~ m/^(\s*)switch\s+(.*)\s*$/){ 471 | $put = $1 . "switch ($2) {"; 472 | push @$gen, $put; 473 | } elsif($line =~ m/^(\s*)case\s+(.*):\s*$/ or $line =~ m/^(\s*)case\s+(.*)\s*$/){ 474 | $put = $1 . "case $2:"; 475 | push @$gen, $put; 476 | } elsif($line =~ m/^(\s*)default\s*$/ or $line =~ m/(\s*)default:\s*$/){ 477 | push @$gen, $1 . "default:"; 478 | } elsif($line =~ m/^(\s*)end\s*$/){ 479 | if($inEnum) { 480 | $inEnum = 0; 481 | } else { 482 | push @$gen, "$1}"; 483 | } 484 | } elsif(!$inEnum && $line =~ m/^(\s*)else(\s*)$/){ 485 | push @$gen, "$1 } else {"; 486 | } elsif(!$inEnum && $line =~ m/^([^#].+)\s+(\S+\s*\(.*\).*?)\{\s*$/){ 487 | # its a function 488 | my $put; 489 | $put = "$1 $function_prepend" . "$2 {"; 490 | push @$gen, $put; 491 | $braceLevel++; 492 | } elsif($line =~ m/^([^#].+)\s+([^\(\)\s]+)\s*\{\s*$/) { 493 | # its a function with () 494 | my $put; 495 | $put = "$1 $function_prepend" . "$2 () {"; 496 | push @$gen, $put; 497 | $braceLevel++; 498 | } elsif($line =~ m/^\s*\{\s*$/){ 499 | push @$gen, $line; 500 | $braceLevel++; 501 | } elsif($line =~ m/^(\s*)\}\s*$/){ 502 | push @$gen, $1 . "}"; 503 | $braceLevel--; 504 | } elsif($line =~ m/^\s*class\s+(\S+)\s*;\s*$/){ # class aoeu; 505 | push @$gen, ""; 506 | } elsif($line =~ m/^\s*class\s+(\S+)\s*:\s*(\S+)$/){ 507 | $function_prepend = $1 . "::"; 508 | $inClass = 1; 509 | } elsif($line =~ m/^\s*class\s+(\S+)\s*$/){ 510 | $function_prepend = $1 . "::"; 511 | $inClass = 1; 512 | } elsif($line =~ m/^\s*endclass/){ 513 | # do nothing 514 | $function_prepend = ""; 515 | $inClass = 0; 516 | } elsif($line =~ m/^\s*enum\s*$/){ 517 | $inEnum = 1; 518 | } elsif($line =~ m/^\s*include\s*(".*")\s*$/){ 519 | # for includeing files 520 | push @$gen, "" 521 | } elsif($line =~ m/^\s*include\s*(<.*>)\s*$/){ 522 | # for includeing files 523 | push @$gen, "" 524 | } elsif($line =~ /^\s*require\s*(".*")\s*$/){ 525 | # include file thats only in the source but not header 526 | push @$gen, "#include $1"; 527 | } elsif($line =~ /^\$replace\s+(.*?)\s*=>\s*(.*?)\s*$/){ 528 | push @$replaceStrings, $2; 529 | push @$searchStrings, $1; 530 | } elsif($line =~ /^#/){ 531 | # header macro 532 | } elsif($line =~ /^\$(.*)$/){ 533 | # allow pasthrough custom macros 534 | push @$gen, "#" . $1; 535 | } elsif($line =~ /^%(.*)$/){ 536 | # only in header 537 | } 538 | else { 539 | if(($line =~ m/^\s*$/)) 540 | { 541 | push @$gen, "$line"; 542 | } else { 543 | if(!$inClass){ 544 | if(!$inEnum){ 545 | push @$gen, "$line" . ";"; # add a semicolor :) 546 | } 547 | } elsif($braceLevel > 0){ 548 | push @$gen, "$line" . ";"; 549 | } 550 | } 551 | } 552 | } 553 | return $gen; 554 | } 555 | sub compileH { 556 | my ($code, $file) = @_; 557 | my $i; 558 | my $gen = []; 559 | my $function_prepend=""; 560 | my $braceLevel; 561 | my $inClass; 562 | my $inEnum; 563 | my $put; 564 | my $searchStrings=[]; 565 | my $replaceStrings=[]; 566 | my $lineBuffer = []; 567 | 568 | my $lineNumber; 569 | my $genSize; 570 | 571 | $braceLevel = 0; 572 | $inClass = 0; 573 | $inEnum = 0; 574 | push @$gen, "#pragma once"; 575 | my $fullFileName; 576 | $fullFileName = abspath($file); 577 | 578 | $lineNumber = 0; 579 | $genSize = -1; 580 | for($i = 0; $i < @$code || @$lineBuffer > 0; $i++){ 581 | my $line; 582 | 583 | if(@$lineBuffer > 0){ 584 | $lineNumber = $i; 585 | $i--; 586 | push @$gen, "#" . "line $lineNumber \"$fullFileName\""; 587 | $line = pop @$lineBuffer; 588 | } else { 589 | $line = $$code[$i]; 590 | $lineNumber = $i+1; 591 | $genSize++; 592 | if(@$gen != $genSize){ 593 | push @$gen, "#" . "line $lineNumber \"$fullFileName\""; 594 | $genSize = @$gen; 595 | } 596 | } 597 | 598 | if(!($line =~ /^\s*\$replace\s+/)){ 599 | $line = replacements($line, $searchStrings, $replaceStrings); 600 | } 601 | if($line =~ m/\n/){ 602 | my @array; 603 | @array = split(/\n/, $line); 604 | @array = reverse(@array); 605 | push @$lineBuffer, @array; 606 | next; 607 | } 608 | 609 | if($line =~ m/^\s*end\s*$/){ 610 | if($inEnum){ 611 | push @$gen, "// enum ended"; 612 | 613 | push @$gen, "};"; 614 | $inEnum = 0; 615 | } 616 | } elsif($line =~ m/(.*)\s+(\S+\s*\(.*\).*?)\{\s*$/){ 617 | # its a function 618 | $put = "$1 " . "$2;"; 619 | push @$gen, $put; 620 | $braceLevel++; 621 | } elsif($line =~ m/^([^#]*)\s+([^\(\)\s]+)\s*\{\s*$/) { 622 | # its a function with () 623 | $put = "$1 $function_prepend" . "$2 ();"; 624 | push @$gen, $put; 625 | $braceLevel++; 626 | } elsif($line =~ m/^\s*class\s+(\S+)\s*;\s*$/){ 627 | $put = "class $1;"; 628 | push @$gen, $put; 629 | } elsif($line =~ m/^\s*class\s+(\S+)\s*:\s*(\S+)$/){ 630 | $put = "class $1 : public $2 {public: typedef $2 super;"; 631 | push @$gen, $put; 632 | $inClass = 1; 633 | } elsif($line =~ m/^\s*class\s+(\S+)\s*$/){ 634 | $put = "class $1 {public:"; 635 | push @$gen, $put; 636 | $inClass = 1; 637 | } elsif($line =~ m/^\s*include\s*(".*")\s*$/){ 638 | # for includeing files 639 | push @$gen, "#include $1" 640 | } elsif($line =~ m/^\s*include\s*(<.*>)\s*$/){ 641 | # for includeing files 642 | push @$gen, "#include $1" 643 | } elsif($line =~ m/^\s*endclass/){ 644 | $function_prepend = ""; 645 | $inClass = 0; 646 | push @$gen, "};"; 647 | } elsif($line =~ m/^\s*\}\s*$/){ 648 | $braceLevel--; 649 | } elsif($line =~ m/^\s*enum\s*/){ 650 | $inEnum = 1; 651 | push @$gen, "enum {"; 652 | } elsif($line =~ /^\$replace\s+(.*?)\s*=>\s*(.*?)\s*$/){ 653 | push @$replaceStrings, $2; 654 | push @$searchStrings, $1; 655 | } elsif($line =~ /^#/){ 656 | # allow pasthrough custom macros 657 | # dont print them in header 658 | push @$gen, $line; 659 | } elsif($line =~ /^\$(.*)$/){ 660 | # only in cpp macro 661 | } elsif($line =~ /^%(.*)$/){ 662 | # only in header 663 | push @$gen, $1 . ";"; 664 | } 665 | 666 | else { 667 | # nothing to do here in header file 668 | if($line =~ m/^\s*$/){ 669 | } elsif($inEnum){ 670 | $put = "$line,"; 671 | push @$gen, $put; 672 | } elsif($inClass && $braceLevel == 0){ 673 | $put = "$line" . ";"; 674 | push @$gen, $put; 675 | } 676 | } 677 | } 678 | return $gen; 679 | } 680 | 681 | my $file; 682 | my $i; 683 | my $filetypes = []; 684 | my $doall=0; 685 | push @$filetypes, "cpp"; 686 | push @$filetypes, "qc"; 687 | push @$filetypes, "qc.h"; 688 | push @$filetypes, "qc.cpp"; 689 | 690 | for($i = 0; $i < @ARGV; $i++){ 691 | if($ARGV[$i] eq "-f"){ 692 | push @$filetypes, $ARGV[$i+1]; 693 | $i++; 694 | } 695 | if($ARGV[$i] eq "--all" or $ARGV[$i] eq "-a"){ 696 | $doall = 1; 697 | } 698 | if($ARGV[$i] eq "-e"){ 699 | $errorOnChanges = 1; 700 | } 701 | 702 | } 703 | $file = $ARGV[0]; 704 | my $changed; 705 | $changed = 0; 706 | if($doall){ 707 | # do all of em 708 | my $files; 709 | my $type_n; 710 | for($type_n = 0; $type_n < @$filetypes; $type_n++){ 711 | $files = AllFiles($$filetypes[$type_n]); 712 | my $i; 713 | for($i = 0; $i < @$files; $i++){ 714 | if(PreFile($$files[$i])){ 715 | print "change is 1 " . $$files[$i] . "\n"; 716 | $changed = 1; 717 | } 718 | } 719 | } 720 | } else { 721 | $changed = PreFile($file); 722 | } 723 | 724 | if($changed && $errorOnChanges){ 725 | print "Files have been modified; giving fake error\n"; 726 | exit(1); 727 | } 728 | --------------------------------------------------------------------------------