Overview
Comment:Sorts components alphabetically within categories: internal ports, components, 0, 1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 3e3724adcd77b78ba19395783ecb5b20971d4ddbd5f5f277622b8711bade2a04
User & Date: geraint@users.sourceforge.net on 2004-08-05 01:42:49
Other Links: branch diff | manifest | tags
Context
2004-08-05
09:07:51
Sorts by type:name within categories: ports, components, 0, 1 check-in: 649ef6492a user: geraint@users.sourceforge.net tags: origin/master, trunk
01:42:49
Sorts components alphabetically within categories: internal ports, components, 0, 1. check-in: 3e3724adcd user: geraint@users.sourceforge.net tags: origin/master, trunk
00:54:03
Fixed punctuation in cmp.m check-in: 7d91b853bb user: geraint@users.sourceforge.net tags: origin/master, trunk
Changes

Modified mttroot/mtt/bin/trans/lbl2cmp_txt2m.pl from [2d9036e052] to [975fe12492].

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
42
43
44
sub read_cmp_file;
sub read_cmp_line;
sub name_anonymous_component;
sub port_or_component_or_junction;
sub read_lbl_file;
sub read_lbl_line;
sub sort_components;

sub write_header;
sub write_body;
sub write_component;

my $debug = 0;

## fields to write to cmp.m
my (@component_name,
    %component_type,    
    %component_cr,
    %component_arg,
    %component_rep);

my (@component_name_lbl_index,
    %sorted_component_list,
    %component_class,
    %anonymous_component_type_index);

## files to read/write
my ($cmp, $lbl, $out);

my $sys = '';







>













<
|







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
42
43
44
sub read_cmp_file;
sub read_cmp_line;
sub name_anonymous_component;
sub port_or_component_or_junction;
sub read_lbl_file;
sub read_lbl_line;
sub sort_components;
sub sort_rule;
sub write_header;
sub write_body;
sub write_component;

my $debug = 0;

## fields to write to cmp.m
my (@component_name,
    %component_type,    
    %component_cr,
    %component_arg,
    %component_rep);


my (%sorted_component_list,
    %component_class,
    %anonymous_component_type_index);

## files to read/write
my ($cmp, $lbl, $out);

my $sys = '';
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	# class is inferred from type and name
	# (cr and args are placeholders)

	($type, $name, $rep) = read_cmp_line($line);
	$name = name_anonymous_component($type) if ($name eq '');	
	$class = port_or_component_or_junction ($type, $name);

	$component_name  [++$i]   = $name;
	$component_type  {$name}  = $type;
	$component_rep   {$name}  = $rep;
	$component_cr    {$name}  = '';
	$component_arg   {$name}  = '';
	$component_class {$name}  = $class;
    }
    close (CMP);







|







86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
	# class is inferred from type and name
	# (cr and args are placeholders)

	($type, $name, $rep) = read_cmp_line($line);
	$name = name_anonymous_component($type) if ($name eq '');	
	$class = port_or_component_or_junction ($type, $name);

	$component_name  [$i++]   = $name;
	$component_type  {$name}  = $type;
	$component_rep   {$name}  = $rep;
	$component_cr    {$name}  = '';
	$component_arg   {$name}  = '';
	$component_class {$name}  = $class;
    }
    close (CMP);
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
	
	# lbl provides name, cr and arg information

	($name, $cr, $arg) = read_lbl_line (@line);
	
	$component_cr{$name}  = $cr;
	$component_arg{$name} = $arg;

	$component_name_lbl_index[++$i] = $name;
    }

    close (LBL);
}

sub read_lbl_line() {
    my @line = @_;







<
<







177
178
179
180
181
182
183


184
185
186
187
188
189
190
	
	# lbl provides name, cr and arg information

	($name, $cr, $arg) = read_lbl_line (@line);
	
	$component_cr{$name}  = $cr;
	$component_arg{$name} = $arg;


    }

    close (LBL);
}

sub read_lbl_line() {
    my @line = @_;
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259


















260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
EOF

    close (OUT);
}

sub sort_components ()
{
    # sorts components into the order in which they are found in the label
    # file within the classes: ports, components then junctions.

    my ($name, $class, $i, $j, $target);

    $i = 0;
    foreach $target ("port", "component", "0junction", "1junction") {
	# get targets in lbl
	for ($j = 1; $j < scalar @component_name_lbl_index; $j++) {
	    $name  = $component_name_lbl_index[$j];
	    $class = $component_class{$name};
	    if ($class eq $target) {
		$sorted_component_list{$name} = ++$i;
		print "sorted: '$name' '$i'\n" if ($debug); 
	    }
	}
	# get targets not in lbl
	for ($j = 1; $j < scalar @component_name; $j++) {
	    $name  = $component_name[$j];
	    $class = $component_class{$name};
	    if ($class eq $target) {
		if (! defined ($sorted_component_list{$name})) {
		    $sorted_component_list{$name} = ++$i;
		    print "sorted: '$name' '$i'\n" if ($debug); 
		}
	    }
	}
    }
}


















    
sub write_body() {
    my (%reverse_sorted_component_list, $name);
    
    %reverse_sorted_component_list = reverse (%sorted_component_list);
    for (my $key = 1; $key < scalar @component_name; $key++) {
	$name = $reverse_sorted_component_list{$key};
	write_component ($name);
    }
}

sub write_component() {
    my ($name) = @_;

    my $i = $sorted_component_list{$name};

    open (OUT, ">>$out") or
	die "MTT: cannot open $out for writing.\n";

    print OUT
	"if (i == $i)\n" .
	"\tcomp_type   = '$component_type{$name}';\n" .







|
|





<
<
|
<
<
|
<
<
<
<
<
<



|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





|








|







222
223
224
225
226
227
228
229
230
231
232
233
234
235


236


237






238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
EOF

    close (OUT);
}

sub sort_components ()
{
    # sorts components into alphabetical order (type:name)
    # within the classes: ports, components then junctions.

    my ($name, $class, $i, $j, $target);

    $i = 0;
    foreach $target ("port", "component", "0junction", "1junction") {


	my @sorted_list = sort (sort_rule @component_name);


	for $name (@sorted_list) {






	    $class = $component_class{$name};
	    if ($class eq $target) {
		if (! defined ($sorted_component_list{$name})) {
		    $sorted_component_list{$name} = $i++;
		    print "sorted: '$name' '$i'\n" if ($debug); 
		}
	    }
	}
    }
}

sub sort_rule ()
{
    my ($type1, $name1, $string1,
	$type2, $name2, $string2);

    $name1 = $a;
    $name2 = $b;

    $type1 = $component_type{$name1};
    $type2 = $component_type{$name2};

    $string1 = sprintf ("%s:%s", $type1, $name1);
    $string2 = sprintf ("%s:%s", $type2, $name2);

    return ($string1 cmp $string2);
}
    
    
sub write_body() {
    my (%reverse_sorted_component_list, $name);
    
    %reverse_sorted_component_list = reverse (%sorted_component_list);
    for (my $key = 0; $key < scalar @component_name; $key++) {
	$name = $reverse_sorted_component_list{$key};
	write_component ($name);
    }
}

sub write_component() {
    my ($name) = @_;

    my $i = $sorted_component_list{$name}+1;

    open (OUT, ">>$out") or
	die "MTT: cannot open $out for writing.\n";

    print OUT
	"if (i == $i)\n" .
	"\tcomp_type   = '$component_type{$name}';\n" .


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]