All of lore.kernel.org
 help / color / mirror / Atom feed
* [LARTC] [tcng] tcc->tc comments
@ 2002-09-26 14:27 raptor
  2002-09-26 21:58 ` Werner Almesberger
  0 siblings, 1 reply; 2+ messages in thread
From: raptor @ 2002-09-26 14:27 UTC (permalink / raw)
  To: lartc

hi,

is there a way so that I can write something like that :

htb {
   class ( rate 10kbps, ceil 20kbps, comment "this is a comment") {
   }
}


and later in the tcc-output I get something like this :

#this is a comment
tc ...blah.. classid X:Y ....

And similar thing for filters/classifiers ?!
The idea is to be able read easly if I have alot of classes and classifiers.

thanx alot in advance
_______________________________________________
LARTC mailing list / LARTC@mailman.ds9a.nl
http://mailman.ds9a.nl/mailman/listinfo/lartc HOWTO: http://lartc.org/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [LARTC] [tcng] tcc->tc comments
  2002-09-26 14:27 [LARTC] [tcng] tcc->tc comments raptor
@ 2002-09-26 21:58 ` Werner Almesberger
  0 siblings, 0 replies; 2+ messages in thread
From: Werner Almesberger @ 2002-09-26 21:58 UTC (permalink / raw)
  To: lartc

[-- 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: $!";
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-09-26 21:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-09-26 14:27 [LARTC] [tcng] tcc->tc comments raptor
2002-09-26 21:58 ` Werner Almesberger

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.