From: Werner Almesberger <wa@almesberger.net>
To: lartc@vger.kernel.org
Subject: Re: [LARTC] [tcng] tcc->tc comments
Date: Thu, 26 Sep 2002 21:58:21 +0000 [thread overview]
Message-ID: <marc-lartc-103307759108165@msgid-missing> (raw)
In-Reply-To: <marc-lartc-103305042406152@msgid-missing>
[-- Attachment #1: Type: text/plain, Size: 1652 bytes --]
raptor wrote:
> is there a way so that I can write something like that :
Hmm, looks like a good use for pragmas with tc output ;-)
After applying the attached quick and dirty patch, this
htb (pragma "#the_outer_qdisc") {
class (rate 10kbps,ceil 20kbps,pragma "#the_first_class") {
fifo(pragma "#the_inner_qdisc");
}
}
yields this:
# the_outer_qdisc
tc qdisc add dev eth0 handle 1:0 root htb
# the_first_class
tc class add dev eth0 parent 1:0 classid 1:1 htb rate 1250bps ceil 2500bps
# the_inner_qdisc
tc qdisc add dev eth0 handle 2:0 parent 1:1 pfifo
Note that you can't include spaces in pragams, but all other
non-blank characters are fine.
> And similar thing for filters/classifiers ?!
Works there too, but only if using "on". When using "if", tcc
may transform the expression quite heavily, and there's no way
for associating output items with input items (in the general
case).
But a better way to do all this is to use tcc's location map
to extract the comments directly from the source, as demonstrated
by the Perl script in the second attachment.
Input example:
/* this is the comment
for HTB */
htb {
// another comment, this
// time for a class
class (rate 10kbps,ceil 20kbps) {
// last but not least, a comment for the FIFO
fifo;
}
}
Not that, when invoking com.pl, the name of the input file
must be the last command-line argument.
- Werner
--
_________________________________________________________________________
/ Werner Almesberger, Buenos Aires, Argentina wa@almesberger.net /
/_http://www.almesberger.net/____________________________________________/
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 598 bytes --]
--- tc.c.orig Thu Sep 26 17:32:47 2002
+++ tc.c Thu Sep 26 17:37:52 2002
@@ -237,6 +237,18 @@
void tc_pragma(const PARAM *params)
{
- if (prm_present(params,&prm_pragma))
- yywarn("\"pragma\" parameter ignored by \"tc\" target");
+ const DATA_LIST *pragma;
+
+ if (!prm_present(params,&prm_pragma)) return;
+ for (pragma = prm_data(params,&prm_pragma).u.list; pragma;
+ pragma = pragma->next) {
+ const char *s;
+
+ s = pragma->ref->u.string;
+ if (*s != '#') {
+ yywarn("\"pragma\" parameter ignored by \"tc\" target");
+ return;
+ }
+ printf("# %s\n",s+1);
+ }
}
[-- Attachment #3: com.pl --]
[-- Type: text/plain, Size: 927 bytes --]
#!/usr/bin/perl
sub emit
{
return unless $in =~ /\n$_[0] /s;
($s = "\n$`") =~ s/\n\d+ /\n/gs;
return unless
$s =~ m#/\*\s*(([^*]|\*[^/])*)\*/[^\n]*$|//\s*(([^\n]*\n\s*//)*[^\n]*)$#s;
($s = defined $1 ? $1 : $3) =~ s/\n\s*/\n# /sg;
$s =~ s#\s*//\s*# #;
print "# $s\n" || die "stdout: $!";
}
open(FILE,$ARGV[$#ARGV]) || die "$ARGV[$#ARGV]: $!";
while (<FILE>) {
$in .= "$. $_";
}
close FILE;
print "out: $in\n";
open(PIPE,"tcc -l $$.out ".join(" ",@ARGV)."|") || die "tcc: $!";
@out = <PIPE>;
close PIPE;
exit $? if $?;
open(FILE,"$$.out") || die "$$.out: $!";
for (<FILE>) {
$q{$1} = $2 if /^qdisc [^:]+:(\S+) .* (\d+)$/;
$c{$1} = $2 if /^class [^:]+:(\S+) .* (\d+)$/;
}
close FILE;
unlink "$$.out" || warn "unlink $$.out: $!";
for (@out) {
&emit($q{$1}) if /^tc qdisc .* handle (\d+):0/;
&emit($c{$1}) if /^tc class .* classid (\d+:\d+)/;
print $_ || die "stdout: $!";
}
prev parent reply other threads:[~2002-09-26 21:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-09-26 14:27 [LARTC] [tcng] tcc->tc comments raptor
2002-09-26 21:58 ` Werner Almesberger [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=marc-lartc-103307759108165@msgid-missing \
--to=wa@almesberger.net \
--cc=lartc@vger.kernel.org \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.