quickjs-tart

quickjs-based runtime for wallet-core logic
Log | Files | Refs | README | LICENSE

print_c.pl (908B)


      1 #!/usr/bin/env perl
      2 #
      3 # Copyright The Mbed TLS Contributors
      4 # SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
      5 
      6 use strict;
      7 use warnings;
      8 
      9 if (!@ARGV || $ARGV[0] == '--help') {
     10     print <<EOF;
     11 Usage: $0 mbedtls_test_foo <file.pem
     12        $0 TEST_FOO mbedtls_test_foo <file.pem
     13 Print out a PEM file as C code defining a string constant.
     14 
     15 Used to include some of the test data in /library/certs.c for
     16 self-tests and sample programs.
     17 EOF
     18     exit;
     19 }
     20 
     21 my $pp_name = @ARGV > 1 ? shift @ARGV : undef;
     22 my $name = shift @ARGV;
     23 
     24 my @lines = map {chomp; s/([\\"])/\\$1/g; "\"$_\\r\\n\""} <STDIN>;
     25 
     26 if (defined $pp_name) {
     27     foreach ("#define $pp_name", @lines[0..@lines-2]) {
     28         printf "%-72s\\\n", $_;
     29     }
     30     print "$lines[@lines-1]\n";
     31     print "const char $name\[\] = $pp_name;\n";
     32 } else {
     33     print "const char $name\[\] =";
     34     foreach (@lines) {
     35         print "\n$_";
     36     }
     37     print ";\n";
     38 }