Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  text2macro.pl

  Sprache: Shell
 


# Copyright (c) 2021-2025, PostgreSQL Global Development Group

# src/pl/plperl/text2macro.pl

=head1 NAME

text2macro.pl - convert text files into C string-literal macro definitions

=head1 SYNOPSIS

  text2macro [options] file ... > output.h

Options:

  --prefix=S   - add prefix S to the names of the macros
  --name=S     - use S as the macro name (assumes only one file)

=head1 DESCRIPTION

Reads one or more text files and outputs a corresponding series of C
pre-processor macro definitions. Each macro defines a string literal that
contains the contents of the corresponding text file. The basename of the text
file is capitalized and used as the name of the macro, along with an optional prefix.

=cut

use strict;
use warnings FATAL => 'all';

use Getopt::Long;

GetOptions(
 'prefix=s' => \my $opt_prefix,
 'name=s' => \my $opt_name,
 'selftest!' => sub { exit selftest() },) or exit 1;

# This was once a command-line option, but meson is obstreperous
# about passing backslashes through custom targets.
my $opt_strip = '^(#.*|\s*)$';

die "No text files specified"
  unless @ARGV;

print qq{
/*
 * DO NOT EDIT - THIS FILE IS AUTOGENERATED - CHANGES WILL BE LOST
 * Generated by src/pl/plperl/text2macro.pl
 */
};

for my $src_file (@ARGV)
{

 (my $macro = $src_file) =~ s/ .*? (\w+) (?:\.\w+) $/$1/x;

 open my $src_fh, '<', $src_file
   or die "Can't open $src_file: $!";

 printf qq{#define %s%s \\\n},
   $opt_prefix || '',
   ($opt_name) ? $opt_name : uc $macro;
 while (<$src_fh>)
 {
  chomp;

  next if $opt_strip and m/$opt_strip/o;

  # escape the text to suite C string literal rules
  s/\\/\\\\/g;
  s/"/\\"/g;

  printf qq{"%s\\n" \\\n}, $_;
 }
 print qq{""\n\n};
}

print "/* end */\n";

exit 0;


sub selftest
{
 my $tmp = "text2macro_tmp";
 my $string = q{a '' '\\'' "" "\\"" "\\\\" "\\\\n" b};

 open my $fh, '>'"$tmp.pl" or die;
 print $fh $string;
 close $fh;

 system("perl $0 --name=X $tmp.pl > $tmp.c") == 0 or die;
 open $fh, '>>'"$tmp.c" or die;
 print $fh "#include <stdio.h>\n";
 print $fh "int main() { puts(X); return 0; }\n";
 close $fh;
 system("cat -n $tmp.c") == 0 or die;

 system("make $tmp") == 0 or die;
 open $fh, '<'"./$tmp |" or die;
 my $result = <$fh>;
 unlink <$tmp.*>;

 warn "Test string: $string\n";
 warn "Result     : $result";
 die "Failed!" if $result ne "$string\n";
 return;
}

Messung V0.5 in Prozent
C=93 H=20 G=67

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet am  2026-08-06) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002