blob: b584578341a5c7bd06efaf6fbea8b36e3fdada75 [file] [log] [blame]
Gilles Peskinef040a172017-05-05 18:56:12 +02001#!/usr/bin/env perl
2# Usage:
3# print_c mbedtls_test_foo <file.pem
4# print_c TEST_FOO mbedtls_test_foo <file.pem
5use strict;
6use warnings;
7
8my $pp_name = @ARGV > 1 ? shift @ARGV : undef;
9my $name = shift @ARGV;
10
11my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>;
12
13if (defined $pp_name) {
14 foreach ("#define $pp_name", @lines[0..@lines-2]) {
15 printf "%-72s\\\n", $_;
16 }
17 print "$lines[@lines-1]\n";
18 print "const char $name\[\] = $pp_name;\n";
19} else {
20 print "const char $name\[\] =";
21 foreach (@lines) {
22 print "\n$_";
23 }
24 print ";\n";
25}