aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Brunschwig <[email protected]>2019-11-09 19:10:10 +0100
committerPatrick Brunschwig <[email protected]>2019-11-09 19:10:10 +0100
commit13e68806e83c6491a0c5a1699c5761ebe426fcd4 (patch)
tree66f7d91b1bc7841188cf380449993d67386101bb
parent74d329be62659691fce9f3480c2a2821ec422dbe (diff)
downloadenigmail-python3.tar.gz
enigmail-python3.tar.bz2
enigmail-python3.zip
use new plpp.pl instead of Preprocessor.py for CPP-like preprocessingpython3
-rw-r--r--ui/content/Makefile2
-rwxr-xr-xutil/plpp.pl112
2 files changed, 113 insertions, 1 deletions
diff --git a/ui/content/Makefile b/ui/content/Makefile
index 0cdbd608..894db7d7 100644
--- a/ui/content/Makefile
+++ b/ui/content/Makefile
@@ -139,7 +139,7 @@ $(GENDIR)/%.js: %.js
$(DEPTH)/util/prepPostbox -c $(TARGET_TOOL) $< [email protected]
$(GENDIR)/%.xul: %.xul
- $(PYTHON) $(DEPTH)/util/Preprocessor.py -I $(INCLUDE) -o [email protected] $<
+ $(PERL) $(DEPTH)/util/plpp.pl -i $(INCLUDE) -o [email protected] $<
$(GENDIR)/%.htm: %.htm
$(DEPTH)/util/install -m 644 $(DIST)/chrome/content/ui $<
diff --git a/util/plpp.pl b/util/plpp.pl
new file mode 100755
index 00000000..1c30c9f5
--- /dev/null
+++ b/util/plpp.pl
@@ -0,0 +1,112 @@
+#!/usr/bin/perl
+
+# simple C-style preprocessor
+
+my $i = -1, $incFile = "", $outFile = "", $inpFile = "", $defines = {};
+
+while (++$i <= $#ARGV) {
+ #printf("%s\n", $ARGV[$i]);
+ if ($ARGV[$i] eq "-i") {
+ $incFile = $ARGV[$i+1];
+ ++$i;
+ }
+ elsif ($ARGV[$i] eq "-o") {
+ $outFile = $ARGV[$i+1];
+ ++$i;
+ }
+ else {
+ $inpFile = $ARGV[$i];
+ }
+}
+
+#printf ("inc: %s out: %s input: %s\n", $incFile, $outFile, $inpFile);
+
+sub trim { # ($str)
+ my $str = @_[0];
+
+ $str =~ s/\s*$//;
+ $str =~ s/^\s*//;
+
+ return $str;
+}
+
+my $outDir = $outFile;
+
+if ($outDir =~ /\//) {
+ $outDir =~ s/\/[^\/]+$//;
+ (-d $outDir) || mkdir("$outDir");
+}
+
+
+# read include-file
+open($fic, $incFile) || die "Could not open $incFile";
+my $prev=0;
+
+while (<$fic>) {
+ my $buf = $_;
+ $buf =~ s/\n//;
+ $buf =~ s/\r//;
+ if (length(trim($buf)) == 0) {
+ continue;
+ }
+ elsif ($buf =~ /^#define\s+([^\s]+)/) {
+ #print "+ Define '$1'\n";
+ $term=trim($1);
+
+ $defines->{$term} = 1;
+ }
+}
+close($fic);
+
+open(OUT, ">$outFile") || die "Cannot write to $outFile";
+open($rd, $inpFile) || die "Could not open $inpFile";
+
+my $doWrite = 1;
+LINE: while (<$rd>) {
+ my $buf = $_;
+ if ($buf =~ /^#ifdef\s+(.*)/) {
+ $term = trim($1);
+ $term =~ s/[\r\n]//g;
+
+ #print "+ found ifdef '$term'\n";
+
+ if ($defines->{$term} == 1) {
+ $doWrite = 1;
+ }
+ else {
+ $doWrite = 01;
+ }
+ next LINE;
+ }
+ if ($buf =~ /^#ifndef\s+(.*)/) {
+ $term = trim($1);
+ $term =~ s/[\r\n]//g;
+
+ #print "+ found ifndef '$term'\n";
+
+ if ($defines->{$term} == 1) {
+ $doWrite = 0;
+ }
+ else {
+ $doWrite = 1;
+ }
+ next LINE;
+ }
+ elsif ($buf =~ /^#else/) {
+ #print "+ found else\n";
+ $doWrite = ($doWrite == 1 ? 0 : 1);
+ next LINE;
+ }
+ elsif ($buf =~ /^#endif/) {
+ #print "+ found endif\n";
+ $doWrite = 1;
+ next LINE;
+ }
+
+ if ($doWrite > 0) {
+ print OUT "$buf";
+ }
+}
+close($fic);
+
+close(OUT);