This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Populate metaconfig branch.
[metaconfig.git] / dist-3.0at70b / pl / profile.pl
CommitLineData
959f3c4c
JH
1;# $Id: profile.pl,v 3.0.1.1 1994/01/24 14:33:53 ram Exp $
2;#
3;# Copyright (c) 1991-1993, Raphael Manfredi
4;#
5;# You may redistribute only under the terms of the Artistic Licence,
6;# as specified in the README file that comes with the distribution.
7;# You may reuse parts of this distribution only within the terms of
8;# that same Artistic Licence; a copy of which may be found at the root
9;# of the source tree for dist 3.0.
10;#
11;# $Log: profile.pl,v $
12;# Revision 3.0.1.1 1994/01/24 14:33:53 ram
13;# patch16: created
14;#
15;#
16;# Dist profile management (works like MH and its ~/.mh_profile):
17;# - Profile name is held in the environment variable DIST. If not defined,
18;# use ~/.dist_profile by default.
19;# - Each line in the profile not starting with a '#' (comment line) should
20;# have the following format:
21;# progname: additional command line options
22;# The profile is parsed once when the command is launched and profile
23;# options are added at the beginning of the @ARGV array.
24;#
25;# Per-program configuration values may be also be added. For instance,
26;# program foo may pay attention to a profile component 'bar', which may be
27;# set via:
28;# foo-bar: value
29;# i.e. the program name is followed by a '-', followed by the profile
30;# component.
31;#
32;# Uses &tilda_expand to perform ~name substitution.
33;# Requires shellwords.pl to properly quote shell words (perl library).
34;#
35# Set up profile components into %Profile, add any profile-supplied options
36# into @ARGV and return the command invocation name.
37sub profile {
38 local($profile) = &tilda_expand($ENV{'DIST'} || '~/.dist_profile');
39 local($me) = $0; # Command name
40 $me =~ s|.*/(.*)|$1|; # Keep only base name
41 return $me unless -s $profile;
42 local(*PROFILE); # Local file descriptor
43 local($options) = ''; # Options we get back from profile
44 unless (open(PROFILE, $profile)) {
45 warn "$me: cannot open $profile: $!\n";
46 return;
47 }
48 local($_);
49 local($component);
50 while (<PROFILE>) {
51 next if /^\s*#/; # Skip comments
52 next unless /^$me/o;
53 if (s/^$me://o) { # progname: options
54 chop;
55 $options .= $_; # Merge options if more than one line
56 }
57 elsif (s/^$me-([^:]+)://o) { # progname-component: value
58 $component = $1;
59 chop;
60 s/^\s+//; # Trim leading and trailing spaces
61 s/\s+$//;
62 $Profile{$component} = $_;
63 }
64 }
65 close PROFILE;
66 return unless $options;
67 require 'shellwords.pl';
68 local(@opts);
69 eval '@opts = &shellwords($options)'; # Protect against mismatched quotes
70 unshift(@ARGV, @opts);
71 return $me; # Return our invocation name
72}
73