File: summarise

package info (click to toggle)
oskit 0.97.20000202-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 58,008 kB
  • ctags: 172,612
  • sloc: ansic: 832,827; asm: 7,640; sh: 3,920; yacc: 3,664; perl: 1,457; lex: 427; makefile: 337; csh: 141; awk: 78
file content (41 lines) | stat: -rwxr-xr-x 954 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#! /usr/local/bin/perl 

# Usage: summarise prefix_1 ...prefix_n
#
# Tries to match lines of input against a list of prefixes.
# Non-matching lines are copied to stdout.
# Matching lines are collected together and printed in the form:
#
#  prefix{suffix1, ... suffixn}
#
# Often used in conjunction with imports and exports:
#
#  exports liboskit_kern.a \
#  | summarise pdir_ oskit_ pic_ i16_bios_ i16_ phys_ intr_ \
#              mem_ gdb_ console_ com_ dos_ cpu_ base_critical_ \
#              base_ anno_ direct_cons_
#
#  imports liboskit_kern.a  | summarise str lmm osenv_ oskit_ 


foreach $prefix (@ARGV) {
    @entries{$prefix} = [];
}

LINE: while (<STDIN>) {
    foreach $prefix (@ARGV) {
	if (/^(\s*)$prefix(\w*)/) {
	    $foo = $entries{$prefix};
	    push(@$foo,$2);
	    $indent = $1;
	    next LINE;
	}
    }
    print;
}

foreach $prefix (@ARGV) {
    $foo = $entries{$prefix};
    print "$indent$prefix\{", join(",",@$foo), "}\n";
}