blob: 561e0676ce1eb25a9ff95bfbea40c26408af9211 [file] [log] [blame]
Manuel Pégourié-Gonnard684e9dc2013-09-20 15:11:44 +02001#!/usr/bin/perl
2
3# activate a pre-defined configuration
4
5use warnings;
6use strict;
7
8my $config_h = "../include/polarssl/config.h";
9
10exit( main() );
11
12sub read_default {
13 open my $fh, '<', $config_h or die "Failed to read $config_h: $!\n";
14
15 my (@pre, @post);
16 my $state = 'pre';
17
18 while( my $line = <$fh> ) {
19 if( $state eq 'pre' ) {
20 push @pre, $line;
21 $state = 'skip' if $line =~ /} name SECTION: System support/;
22 }
23 elsif( $state eq 'skip' ) {
24 $state = 'post' if $line =~/} name SECTION: PolarSSL modules/;
25 }
26 else {
27 push @post, $line;
28 }
29 }
30
31 die "Failed to parse $config_h\n" if( $state ne 'post' );
32
33 close $fh;
34
35 push @pre, "\n";
36
37 return \@pre, \@post;
38}
39
40sub read_custom {
41 my ($file_name) = @_;
42
43 open my $fh, '<', $file_name or die "Failed to read $file_name: $!\n";
44 my @content = <$fh>;
45 close $fh;
46
47 return \@content;
48}
49
50sub write_custom {
51 my ($pre, $mid, $post) = @_;
52
53 open my $fh, '>', $config_h or die "Failed to write $config_h: $!\n";
54 print $fh @$pre;
55 print $fh @$mid;
56 print $fh @$post;
57 close $fh;
58}
59
60sub main {
61 my $custom_file_name = $ARGV[0];
62
63 my ($pre, $post) = read_default();
64 my $mine = read_custom( $custom_file_name );
65 write_custom( $pre, $mine, $post );
66
67 return 0;
68}