RSSyl: Allow use of .netrc by libcurl. Bug/enhancement #3309, by Vincent Pelletier
[claws.git] / src / plugins / perl / tools / insert_perl.pl
1 #!/usr/bin/perl -w
2 # parameters: <cmd> what perl-code c-code
3 #
4 # The purpose of this script is to be able to develop the embedded perl
5 # code outside of the c-code. This script then updates the c-code, escaping
6 # the perl code as needed and putting it into the c code as strings.
7 #
8 # usage:
9 #  - go to directory of perl plugin sources
10 #    - tools/insert_perl.pl perl_filter_action perl_filter_action.pl perl_plugin.c
11 #    - tools/insert_perl.pl perl_filter_matcher perl_filter_matcher.pl perl_plugin.c
12 #    - tools/insert_perl.pl perl_persistent perl_persistent.pl perl_plugin.c
13 #    - tools/insert_perl.pl perl_utils perl_utils.pl perl_plugin.c
14 use strict;
15 use File::Copy;
16
17 die "Wrong parameters\n" if $#ARGV != 2;
18
19 my ($what,$perl_code,$c_code) = @ARGV;
20
21 copy($c_code,$c_code.".bak") or die "Copy failed: $!";
22
23 open FH,"<",$perl_code or die "Cannot open $perl_code: $!";
24 my @perl_code = <FH>; close FH;
25
26 foreach (@perl_code) {
27     s|\\|\\\\|g;
28     s|\"|\\\"|g;
29     s|(.*)|\"$1\\n\"|;
30 }
31
32 open FH,"<",$c_code or die "Cannot open $c_code: $!";
33 my @c_code = <FH>; close FH;
34
35 my (@c_code_new,$line);
36
37 while($line = shift @c_code) {
38     if($line =~ /const\s+char\s+$what\s*\[\s*\]\s*=\s*\{/) {
39         push @c_code_new,$line;
40         push @c_code_new,$_ foreach (@perl_code);
41         $line = shift @c_code while(not ($line =~ m/^\s*\}\s*;\s*$/));
42         push @c_code_new,$line;
43     }
44     else {
45         push @c_code_new,$line;
46     }
47 }
48
49 open FH,">",$c_code or die "Cannot open $c_code: $!";
50 print FH "$_" foreach (@c_code_new);