The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mpp::Text - Subs for manipulating typical makefile text

pattern_substitution

  @pieces = pattern_substitution($pattern, $dest, @words)

Performs a pattern substitution like the $(patsubst ) function (in fact, $(patsubst ) is implemented using this. $pattern contains a % as a wildcard, and $dest contains a matching %. The substitution is applied to each word in @words, and the result returned as an array.

For example:

  @pieces = pattern_substitution('%.c', '%.o', 'file1.c', 'file2.c')

returns ('file1.o', 'file2.o').

find_unquoted

  my $index = find_unquoted string, 'char'[, position[, type];

Works like index $string, 'char'[, position], except that the char is to be found outside quotes or make expressions.

If type is 1, char may be inside a make expression (for historical reasons opposite to split_on_whitespace).

If type is 2, ignores only the characters in '' and the one after \, i.e. makes the same difference between single and double quotes as does the Shell or Perl.

rfind_unquoted

Like find_unquoted, except that it returns the index to the last instance rather than the first.

split_on_whitespace

  @pieces = split_on_whitespace $string[, type];

Works like

  @pieces = split ' ', $string

except that whitespace inside quoted strings is not counted as whitespace. This should be called after expanding all make variables; it does not know anything about things like "$(make expressions)".

There are three kinds of quoted strings, as in the shell. Single quoted strings are terminated by a matching single quote. Double quoted strings are terminated by a matching double quote that isn't escaped by a backslash. Backquoted strings are terminated by a matching backquote that isn't escaped by a backslash.

If type is 1, doesn't split inside make expressions (for historical reasons opposite to find_unquoted).

join_with_protection

  $string = join_with_protection(@pieces);

Works like

  $string = join ' ', @pieces

except that strings in @pieces that contain shell metacharacters are protected from the shell.

split_on_colon

  @pieces = split_on_colon('string');

Works like

  @pieces = split /:+/, 'string'

except that colons inside double quoted strings or make expressions are passed over. Also, a semicolon terminates the expression; any colons after a semicolon are ignored. This is to support grokking of this rule:

  $(srcdir)/cat-id-tbl.c: stamp-cat-id; @:

unquote

  $text = unquote($quoted_text)

or on an implicit $_:

  $text = unquote

Removes quotes and escaping backslashes from a name. Thus if you give it as an argument \""a bc"'"'

it will return the string

    "a bc"

You must already have expanded all of the make variables in the string. unquote() knows nothing about make expressions. In the 1st variant, you may not pass anny regextp special vars, because it uses regexps directly on the argument.

hash_neq

  if (hash_neq(\%a, \%b)) { ... }

Returns true (actually, returns the first key encountered that's different) if the two associative arrays are unequal, and '' if not.

is_cpp_source_name

  if (is_cpp_source_name($filename))  { ... }

Returns true if the given filename has the appropriate extension to be a C or C++ source or include file.

is_object_or_library_name

  if (is_object_or_library_name($filename)) { ... }

Returns true if the given filename has the appropriate extension to be some sort of object or library file.

getopts

  getopts %vars, strictflag, [qw(o optlong), \$var, wantarg, handler], ...

Almost as useful as Getopt::Long and much smaller :-)

%vars is optional, any VAR=VALUE pairs get stored in it if passed.

strictflag is optional, means to stop at first non-option.

Short opt may be empty, longopt may be a regexp (grouped if alternative).

$var gets incremented for each occurrence of this option or, if optional wantarg is true, it gets set to the argument. This can be undef if you don't need it.

If an optional handler is given, it gets called after assigning $var, if it is a ref (a sub). Any other value is assigned to $var.