From: "Stefan Monnier" <monnier+lists/zsh/users/news/@tequila.cs.yale.edu>
To: zsh-users@sunsite.auc.dk
Subject: Re: completions for make targets?
Date: 21 Jun 1999 08:05:24 -0400 [thread overview]
Message-ID: <5l3dzl3gjf.fsf@tequila.cs.yale.edu> (raw)
In-Reply-To: <Pine.SV4.3.93.990621101124.5328A-100000@tagore>
>>>>> "Raju" == Raju K V <rajukv@wipinfo.soft.net> writes:
> How can I use compctl to complate make targets?
Admittedly, my solution doesn't exploit compctl too much (maybe
because I had it for tcsh before and just adapted it), but it's
probably a bit fancier (in some respects) than many others:
comp_make () {
local cmd args i where
read -Ac cmd; read -cn where
i=1
while [[ "$i" -lt "$#cmd" ]]; do
if [[ "$cmd[$i]" = "-f" ]]; then
reply=("${(@f)$(~/libexec/complete/make.perl "$cmd[$[$i + 1]]" 2>/dev/null)}")
comp_fixreply
return 0;
else
((i += 1))
fi
done
reply=("${(@f)$(~/libexec/complete/make.perl 2>/dev/null)}")
comp_fixreply
}
compctl -x 'c[-1,-f]' -f -- + -Q -S '' -K comp_make + gmake make
now, you'll notice that this depends on a perl file that does the actual
target extraction. The perl file is appended.
Stefan
#!/usr/bin/env perl
# read all the var definitions into the "vars" hash-table
# and the target lines into the "targetlines" array
sub ReadFile {
local($file) = @_;
local($prevs) = ("");
open(MAKEFILE, "<$file") || return;
for (<MAKEFILE>) {
chomp();
$_ = $prevs . $_; $prevs = "";
if (s/\\$//o ) {
$prevs = $_;
} elsif (/^[- \t]*include[ \t]+([^ \t]+)/) {
push(@includes, $1);
} elsif (/^[ \t]*([-a-zA-Z0-9_.]+)[ \t]*=(.*)$/o) {
$vars{$1} = $2;
} elsif (/^((([-a-zA-Z0-9_ ][-a-zA-Z0-9_. ]*)|(\$\((([^()]+)|(\$\([^()]+\)))\)))+)[\t ]*:/o) {
push(@targetlines, $1);
}
}
close(MAKEFILE);
if ($file = pop(@includes)) {
ReadFile($file);
}
}
# debugging: dump out the vars, their values and the targetlines
#print "**bindings**\n";
#@vars = keys(%vars);
#for (@vars) {
# print "<$_> is <$vars{$_}>\n";
#}
#print "**targets**\n";
#for (@targetlines) {
# print "$_\n";
#}
sub ExpandTargets {
local(@targets);
# look for potential targets (lines with a ":")
for $targets (@targetlines) {
# for each set of targets, look for variables to substitue
while (($var) = $targets =~ /\$\( *([^()\$]*)\)/o ) {
# print "var =$var: <$targets> => <";
# first case: a simple macro
if ($tmpvar = $vars{$var}) {
$var =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var
$targets =~ s/\$\( *$var\)/$tmpvar/g ;
#second case: a macro with simple substitution
} elsif (($var0, $s1, $s2) = $var =~ / *(.*):(.*)=(.*)/o) {
if ($tmpvar = $vars{$var0}) {
$s1 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote s1
$tmpvar =~ s/$s1/$s2/g ;
$s2 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote s2
$var0 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var0
$targets =~ s/\$\( *$var0:$s1=$s2\)/$tmpvar/g ;
} else {
$var0 =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var0
$targets =~ s/\$\( *$var0:$s1=$s2\)//g ;
}
} else {
$var =~ s/([^a-zA-Z0-9 ])/\\$1/og; # quote var
$targets =~ s/\$\( *$var\)//g ;
}
# print "$targets>\n";
}
$targets =~ s/:.*$//; # removes anything after a :
# split the "targets line" into an array of targets
@targets = ($targets =~ /([^ ]+)/og );
#put each target into a hash-table (to remove duplicates)
for $target (@targets) {
$targets{$target} = true;
}
}
}
if ($#ARGV < 0) {
if (-r "GNUmakefile") { $file = "GNUmakefile"; }
elsif (-r "Makefile") { $file = "Makefile"; }
elsif (-r "makefile") { $file = "makefile"; }
else { $file = "/dev/null"; }
} else {
$file = $ARGV[0];
}
ReadFile($file);
ExpandTargets();
# dump out the table of targets
for $target (keys(%targets)) { print "$target \n"; }
for $var (keys(%vars)) { print "$var=\n"; }
prev parent reply other threads:[~1999-06-21 12:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-21 4:46 Raju K. V.
1999-06-21 7:06 ` Thomas Köhler
1999-06-21 9:17 ` Falk Hueffner
1999-06-21 12:05 ` Stefan Monnier [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5l3dzl3gjf.fsf@tequila.cs.yale.edu \
--to=monnier+lists/zsh/users/news/@tequila.cs.yale.edu \
--cc=zsh-users@sunsite.auc.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).