OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [perl_gui/] [lib/] [perl/] [common.pl] - Blame information for rev 54

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 54 alirezamon
#!/usr/bin/perl -w
2
 
3 43 alirezamon
use strict;
4
use warnings;
5
 
6
use String::Similarity;
7 48 alirezamon
use Proc::Background;
8
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval nanosleep  clock_gettime clock_getres clock_nanosleep clock stat );
9 43 alirezamon
 
10 48 alirezamon
use List::MoreUtils qw(uniq);
11
use POSIX qw(ceil floor);
12
 
13
use Cwd 'abs_path';
14
use Term::ANSIColor qw(:constants);
15
use IPC::Run qw(start pump finish timeout pumpable);
16 43 alirezamon
 
17 54 alirezamon
use FindBin;
18
use lib $FindBin::Bin;
19
use constant::boolean;
20
use IO::CaptureOutput qw(capture qxx qxy);
21 48 alirezamon
 
22 54 alirezamon
 
23
our %glob_setting;
24
$glob_setting{'FONT_SIZE'}='default';
25
$glob_setting{'ICON_SIZE'}='default';
26
$glob_setting{'DSPLY_X'}  ='default';
27
$glob_setting{'DSPLY_Y'}  ='default';
28
 
29
 
30
 
31
 
32 48 alirezamon
sub log2{
33
        my $num=shift;
34
        my $log=($num <=1) ? 1: 0;
35
        while( (1<< $log)  < $num) {
36
                                $log++;
37
        }
38
        return  $log;
39
}
40
 
41 43 alirezamon
sub find_the_most_similar_position{
42
        my ($item ,@list)=@_;
43
        my $most_similar_pos=0;
44
        my $lastsim=0;
45
        my $i=0;
46
        # convert item to lowercase
47
        $item = lc $item;
48
        foreach my $p(@list){
49
                my $similarity= similarity $item, $p;
50
                if ($similarity > $lastsim){
51
                        $lastsim=$similarity;
52
                        $most_similar_pos=$i;
53
                }
54
                $i++;
55
        }
56
        return $most_similar_pos;
57
}
58
 
59 48 alirezamon
sub is_integer {
60
   defined $_[0] && $_[0] =~ /^[+-]?\d+$/;
61
}
62 43 alirezamon
 
63
 
64
####################
65 48 alirezamon
#        verilog file
66 43 alirezamon
##################
67
 
68
 
69
sub read_verilog_file{
70
        my @files            = @_;
71
        my %cmd_line_defines = ();
72
        my $quiet            = 1;
73
        my @inc_dirs         = ();
74
        my @lib_dirs         = ();
75
        my @lib_exts         = ();
76
        my $vdb = rvp->read_verilog(\@files,[],\%cmd_line_defines,
77
                          $quiet,\@inc_dirs,\@lib_dirs,\@lib_exts);
78
 
79
        my @problems = $vdb->get_problems();
80
        if (@problems) {
81
            foreach my $problem ($vdb->get_problems()) {
82 48 alirezamon
                print STDERR "$problem.\n" unless ( $problem =~ /smartflit_chanel_t/);
83 43 alirezamon
            }
84
            # die "Warnings parsing files!";
85
        }
86
        return $vdb;
87
}
88
 
89
 
90 48 alirezamon
sub verilog_file_get_ports_list{
91
        my ($vdb,$top_module)=@_;
92
        my @ports;
93
 
94
        foreach my $sig (sort $vdb->get_modules_signals($top_module)) {
95
        my ($line,$a_line,$i_line,$type,$file,$posedge,$negedge,
96
         $type2,$s_file,$s_line,$range,$a_file,$i_file,$dims) =
97
           $vdb->get_module_signal($top_module,$sig);
98 43 alirezamon
 
99 48 alirezamon
                if($type eq "input" or $type eq "inout" or $type eq "output" ){
100
                        push(@ports, $sig);
101
 
102
                }
103
        }
104
        return @ports;
105
}
106 43 alirezamon
 
107 48 alirezamon
 
108
 
109
sub get_ports_type{
110
        my ($vdb,$top_module)=@_;
111
        my %ports;
112
 
113
        foreach my $sig (sort $vdb->get_modules_signals($top_module)) {
114
        my ($line,$a_line,$i_line,$type,$file,$posedge,$negedge,
115
         $type2,$s_file,$s_line,$range,$a_file,$i_file,$dims) =
116
           $vdb->get_module_signal($top_module,$sig);
117
 
118
                if($type eq "input" or $type eq "inout" or $type eq "output" ){
119
                        $ports{$sig}=$type;
120
 
121
                }
122
        }
123
        return %ports;
124
}
125
 
126
 
127
 
128
sub get_ports_rang{
129
        my ($vdb,$top_module)=@_;
130
        my %ports;
131
 
132
        foreach my $sig (sort $vdb->get_modules_signals($top_module)) {
133
        my ($line,$a_line,$i_line,$type,$file,$posedge,$negedge,
134
         $type2,$s_file,$s_line,$range,$a_file,$i_file,$dims) =
135
           $vdb->get_module_signal($top_module,$sig);
136
 
137
                if($type eq "input" or $type eq "inout" or $type eq "output" ){
138
 
139
 
140
 
141
                        $ports{$sig}=remove_all_white_spaces($range);
142
 
143
                }
144
        }
145
        return %ports;
146
}
147
 
148
 
149
 
150
 
151
sub get_param_list_in_order {
152
   my $ref =shift;
153
   return undef if (!defined $ref);
154
   my %param=%{$ref};
155
   my @array = sort keys %param;
156
   my $l= scalar @array;
157
   SCAN: {
158
   foreach my $i (0..($l-2)) {
159
      my $str1=$array[$i];
160
      foreach my $j ($i+1..($l-1)) {
161
      my $str2=$array[$j];
162
        if ($param{$str1} =~ /\b$str2\b/ ) {
163
 
164
        my $tmp = $array[$i];
165
        $array[$i] =$array[$j];
166
        $array[$j]=$tmp;
167
 
168
        redo SCAN;
169
      }
170
    }
171
    }
172
  }
173
 
174
  return @array;
175
}
176
 
177
sub gen_verilator_makefile{
178
        my ($top_ref,$target_dir) =@_;
179
        my %tops = %{$top_ref};
180
        my $p='';
181
        my $q='';
182
        my $h='';
183
        my $l;
184
        my $lib_num=0;
185
        my $all_lib="";
186
        foreach my $top (sort keys %tops) {
187
                $p = "$p ${top}__ALL.a ";
188
                $q = $q."lib$lib_num:\n\t\$(MAKE) -f ${top}.mk\n";
189
                $h = "$h ${top}.h ";
190
                $l = $top;
191
                $all_lib=$all_lib." lib$lib_num";
192
                $lib_num++;
193
        }
194 54 alirezamon
 
195 48 alirezamon
        my $make= "
196
 
197
default: sim
198
 
199
 
200
 
201
include $l.mk
202
 
203
lib: $all_lib
204
 
205
$q
206
 
207
 
208
#######################################################################
209
# Compile flags
210
 
211
CPPFLAGS += -DVL_DEBUG=1
212
ifeq (\$(CFG_WITH_CCWARN),yes)  # Local... Else don't burden users
213
CPPFLAGS += -DVL_THREADED=1
214
CPPFLAGS += -W -Werror -Wall
215
endif
216
 
217 54 alirezamon
SLIB =
218
HLIB =
219
ifneq (\$(wildcard synful/synful.a),)
220
SLIB += synful/synful.a
221
HLIB += synful/synful.h
222
endif
223
 
224 48 alirezamon
#######################################################################
225
# Linking final exe -- presumes have a sim_main.cpp
226
 
227
 
228 54 alirezamon
sim:    testbench.o \$(VK_GLOBAL_OBJS) $p \$(SLIB)
229 48 alirezamon
        \$(LINK) \$(LDFLAGS) -g \$^ \$(LOADLIBES) \$(LDLIBS) -o testbench \$(LIBS) -Wall -O3 -lpthread 2>&1 | c++filt
230
 
231 54 alirezamon
testbench.o: testbench.cpp $h  \$(HLIB)
232 48 alirezamon
 
233
clean:
234
        rm *.o *.a testbench
235
";
236
 
237
save_file ($target_dir,$make);
238
 
239
}
240
 
241
 
242
####################
243
#        file
244
##################
245
 
246
 
247 43 alirezamon
sub append_text_to_file {
248
        my  ($file_path,$text)=@_;
249
        open(my $fd, ">>$file_path") or die "could not open $file_path: $!";
250
        print $fd $text;
251
        close $fd;
252
}
253
 
254
 
255
 
256
 
257
sub save_file {
258
        my  ($file_path,$text)=@_;
259
        open my $fd, ">$file_path" or die "could not open $file_path: $!";
260
        print $fd $text;
261
        close $fd;
262
}
263
 
264
sub load_file {
265
        my $file_path=shift;
266
        my $str;
267
        if (-f "$file_path") {
268
 
269
                $str = do {
270
                        local $/ = undef;
271
                        open my $fh, "<", $file_path
272
                        or die "could not open $file_path: $!";
273
                        <$fh>;
274
                };
275
 
276
        }
277
        return $str;
278
}
279
 
280
sub merg_files {
281
        my  ($source_file_path,$dest_file_path)=@_;
282
        local $/=undef;
283
        open FILE, $source_file_path or die "Couldn't open file: $!";
284
        my $string = <FILE>;
285
        close FILE;
286
         append_text_to_file ($dest_file_path,$string);
287
}
288
 
289
 
290
 
291
sub copy_file_and_folders{
292
        my ($file_ref,$project_dir,$target_dir)=@_;
293
 
294
        foreach my $f(@{$file_ref}){
295
                my $name= basename($f);
296
 
297
                my $n="$project_dir$f";
298
                if (-f "$n") { #copy file
299
                        copy ("$n","$target_dir/$name");
300
                }elsif(-f "$f" ){
301
                        copy ("$f","$target_dir/$name");
302
                }elsif (-d "$n") {#copy folder
303
                        dircopy ("$n","$target_dir/$name");
304
                }elsif(-d "$f" ){
305
                        dircopy ("$f","$target_dir/$name");
306
 
307
                }
308
        }
309
 
310
}
311
 
312
 
313
sub remove_file_and_folders{
314
        my ($file_ref,$project_dir)=@_;
315
 
316
        foreach my $f(@{$file_ref}){
317
                my $name= basename($f);
318
                my $n="$project_dir$f";
319
                if (-f "$n") { #copy file
320
                        unlink ("$n");
321
                }elsif(-f "$f" ){
322
                        unlink ("$f");
323
                }elsif (-d "$n") {#copy folder
324
                        rmtree ("$n");
325
                }elsif(-d "$f" ){
326
                        rmtree ("$f");
327
                }
328
        }
329
 
330
}
331
 
332
sub read_file_cntent {
333
        my ($f,$project_dir)=@_;
334
        my $n="$project_dir$f";
335
        my $str;
336
        if (-f "$n") {
337
 
338
                $str = do {
339
                        local $/ = undef;
340
                        open my $fh, "<", $n
341
                        or die "could not open $n: $!";
342
                        <$fh>;
343
                };
344
 
345
        }elsif(-f "$f" ){
346
                $str = do {
347
                        local $/ = undef;
348
                        open my $fh, "<", $f
349
                        or die "could not open $f: $!";
350
                        <$fh>;
351
                };
352
 
353
 
354
        }
355
        return $str;
356
 
357
}
358
 
359
 
360
sub check_file_has_string {
361
    my ($file,$string)=@_;
362
    my $r;
363
    open(FILE,$file);
364
    if (grep{/$string/} <FILE>){
365
       $r= 1; #print "word  found\n";
366
    }else{
367
       $r= 0; #print "word not found\n";
368
    }
369
    close FILE;
370
    return $r;
371
}
372
 
373 48 alirezamon
#return lines containig pattern in a givn file
374
sub unix_grep {
375
        my ($file,$pattern)=@_;
376
    open(FILE,$file);
377
    my @arr = <FILE>;
378
    my @lines = grep /$pattern/, @arr;
379
        return @lines;
380
}
381
 
382
 
383
sub count_file_line_num {
384
    my ($file)=@_;
385
    open(FILE,$file);
386
    my $n=0;
387
    while (my $line = <FILE>) {
388
           $n++;
389
        }
390
    close FILE;
391
    return $n;
392
}
393
 
394
sub set_path_env{
395
        my $project_dir   = get_project_dir(); #mpsoc dir addr
396
        my $paths_file= "$project_dir/mpsoc/perl_gui/lib/Paths";
397
        #print "$paths_file\n";
398
        my $paths= do $paths_file;
399
        my $pronoc_work =object_get_attribute($paths,"PATH","PRONOC_WORK");
400
        my $quartus = object_get_attribute($paths,"PATH","QUARTUS_BIN");
401
        my $vivado  = object_get_attribute($paths,"PATH","VIVADO_BIN");
402
        my $sdk     = object_get_attribute($paths,"PATH","SDK_BIN");
403
 
404
        my $modelsim = object_get_attribute($paths,"PATH","MODELSIM_BIN");
405
        $ENV{'PRONOC_WORK'}= $pronoc_work if( defined $pronoc_work);
406
        $ENV{'QUARTUS_BIN'}= $quartus if( defined $quartus);
407
        $ENV{'VIVADO_BIN'}= $vivado if( defined $vivado);
408
        $ENV{'SDK_BIN'}= $vivado if( defined $sdk);
409
        $ENV{'MODELSIM_BIN'}= $modelsim if( defined $modelsim);
410
 
411
        if( defined $pronoc_work){if(-d $pronoc_work ){
412
                        mkpath("$pronoc_work/emulate",1,01777) unless -d "$pronoc_work/emulate";
413
                        mkpath("$pronoc_work/simulate",1,01777) unless -d "$pronoc_work/simulate";
414
                        mkpath("$pronoc_work/tmp",1,01777) unless -d "$pronoc_work/tmp";
415
        }}
416
 
417
        #add quartus_bin to PATH linux environment if it does not exist in PATH
418
        my $add;
419
        if( defined $quartus){
420
                my @q =split  (/:/,$ENV{'PATH'});
421
                my $p=get_scolar_pos ($quartus,@q);
422
                $ENV{'PATH'}= $ENV{'PATH'}.":$quartus" unless ( defined $p);
423
                $add=(defined $add)? $add.":$quartus" : $quartus unless ( defined $p);
424
 
425
        }
426
 
427
        if( defined $vivado){
428
                my @q =split  (/:/,$ENV{'PATH'});
429
                my $p=get_scolar_pos ($vivado,@q);
430
                $ENV{'PATH'}= $ENV{'PATH'}.":$vivado" unless ( defined $p);
431
                $add=(defined $add)? $add.":$vivado" : $vivado unless ( defined $p);
432
 
433
        }
434
 
435
        if( defined $sdk){
436
                my @q =split  (/:/,$ENV{'PATH'});
437
                my $p=get_scolar_pos ($sdk,@q);
438
                $ENV{'PATH'}= $ENV{'PATH'}.":$sdk" unless ( defined $p);
439
                $add=(defined $add)? $add.":$sdk" : $sdk unless ( defined $p);
440
 
441
        }
442
        if(defined $add){
443
                print GREEN, "Info: $add has been added to linux PATH envirement.\n",RESET,"\n";
444
 
445
        }
446
 
447
 
448
}
449
 
450
 
451
 
452
sub source_file {
453
    my $file = shift;
454
    open my $fh, "<", $file   or return  "could not open $file: $!";
455
 
456
    while (<$fh>) {
457
        chomp;
458
        #FIXME: this regex isn't quite good enough
459 54 alirezamon
        next unless my ($var, $value) = /\s*(\w+)=([^#]+)/;
460 48 alirezamon
        $ENV{$var} = $value;
461
    }
462
    return undef;
463
}
464
 
465
 
466 43 alirezamon
##############
467
#  clone_obj
468
#############
469
 
470
sub clone_obj{
471
        my ($self,$clone)=@_;
472
 
473
        foreach my $p (keys %$self){
474
                delete ($self->{$p});
475
        }
476
        foreach my $p (keys %$clone){
477
                $self->{$p}= $clone->{$p};
478
                my $ref= ref ($clone->{$p});
479
                if( $ref eq 'HASH' ){
480
 
481
                        foreach my $q (keys %{$clone->{$p}}){
482
                                $self->{$p}{$q}= $clone->{$p}{$q};
483
                                my $ref= ref ($self->{$p}{$q});
484
                                if( $ref eq 'HASH' ){
485
 
486
                                        foreach my $z (keys %{$clone->{$p}{$q}}){
487
                                                $self->{$p}{$q}{$z}= $clone->{$p}{$q}{$z};
488
                                                my $ref= ref ($self->{$p}{$q}{$z});
489
                                                if( $ref eq 'HASH' ){
490
 
491
                                                        foreach my $w (keys %{$clone->{$p}{$q}{$z}}){
492
                                                                $self->{$p}{$q}{$z}{$w}= $clone->{$p}{$q}{$z}{$w};
493
                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w});
494
                                                                if( $ref eq 'HASH' ){
495
 
496
 
497
                                                                        foreach my $m (keys %{$clone->{$p}{$q}{$z}{$w}}){
498
                                                                                $self->{$p}{$q}{$z}{$w}{$m}= $clone->{$p}{$q}{$z}{$w}{$m};
499
                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m});
500
                                                                                if( $ref eq 'HASH' ){
501
 
502
                                                                                        foreach my $n (keys %{$clone->{$p}{$q}{$z}{$w}{$m}}){
503
                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}= $clone->{$p}{$q}{$z}{$w}{$m}{$n};
504
                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n});
505
                                                                                                if( $ref eq 'HASH' ){
506
 
507
                                                                                                        foreach my $l (keys %{$clone->{$p}{$q}{$z}{$w}{$m}{$n}}){
508
                                                                                                                $self->{$p}{$q}{$z}{$w}{$m}{$n}{$l}= $clone->{$p}{$q}{$z}{$w}{$m}{$n}{$l};
509
                                                                                                                my $ref= ref ($self->{$p}{$q}{$z}{$w}{$m}{$n}{$l});
510
                                                                                                                if( $ref eq 'HASH' ){
511
                                                                                                                }
512
                                                                                                        }
513
 
514
                                                                                                }#if                                                                                                            
515
                                                                                        }#n
516
                                                                                }#if
517
                                                                        }#m                                                     
518
                                                                }#if
519
                                                        }#w
520
                                                }#if
521
                                        }#z
522
                                }#if
523
                        }#q
524
                }#if    
525
        }#p
526
}#sub   
527
 
528
 
529
sub get_project_dir{ #mpsoc directory address
530
        my $dir = Cwd::getcwd();
531 48 alirezamon
        my @p=  split('/perl_gui',$dir);
532
        @p=     split('/Integration_test',$p[0]);
533
    my $d         = abs_path("$p[0]/../");
534
 
535
        return $d;
536 43 alirezamon
}
537
 
538 48 alirezamon
sub cut_dir_path{
539
        my ($dir,$folder_name) = @_;
540
        my @p=  split (/\/$folder_name\//,$dir);
541
        return $p[-1];
542
}
543 43 alirezamon
 
544 48 alirezamon
 
545 43 alirezamon
sub remove_project_dir_from_addr{
546
        my $file=shift;
547
        my $project_dir   = get_project_dir();
548
        $file =~ s/$project_dir//;
549
        return $file;
550
}
551
 
552
sub add_project_dir_to_addr{
553
        my $file=shift;
554
        my $project_dir   = get_project_dir();
555
        return $file if(-f $file );
556
        return "$project_dir/$file";
557
 
558
}
559
 
560
sub get_full_path_addr{
561
        my $file=shift;
562
        my $dir = Cwd::getcwd();
563
        my $full_path = "$dir/$file";
564
        return $full_path  if -f ($full_path );
565
        return $file;
566
}
567
 
568
sub regen_object {
569
        my $path=shift;
570
        $path = get_full_path_addr($path);
571
        my $pp= eval { do $path };
572
        my $r= ($@ || !defined $pp);
573
        return ($pp,$r,$@);
574
}
575
 
576
 
577
################
578
#       general
579
#################
580
 
581 48 alirezamon
sub remove_not_hex {
582
        my $s=shift;
583
        $s =~ s/[^0-9a-fA-F]//g;
584
        return $s;
585
}
586 43 alirezamon
 
587 48 alirezamon
sub remove_not_number {
588
        my $s=shift;
589
        $s =~ s/[^0-9]//g;
590
        return $s;
591
 
592
}
593 43 alirezamon
 
594
sub  trim { my $s = shift;  $s=~s/[\n]//gs; return $s };
595
 
596
sub remove_all_white_spaces($)
597
{
598
  my $string = shift;
599
  $string =~ s/\s+//g;
600
  return $string;
601
}
602
 
603
 
604 48 alirezamon
sub check_scolar_exist_in_array{
605
        my ($value,$ref)=@_;
606
        my @array= @{$ref};
607
        if ( grep( /^\Q$value\E$/, @array ) ) {
608
          return 1;
609
        }
610
        return 0
611
}
612 43 alirezamon
 
613 48 alirezamon
sub get_item_pos{#if not in return 0
614
                my ($item,@list)=@_;
615
                my $pos=0;
616
                foreach my $p (@list){
617
                                #print "$p eq $item\n";
618
                                if ($p eq $item){return $pos;}
619
                                $pos++;
620
                }
621
                return 0;
622
 
623
}
624 43 alirezamon
 
625
sub get_scolar_pos{
626
        my ($item,@list)=@_;
627
        my $pos;
628
        my $i=0;
629
        foreach my $c (@list)
630
        {
631
                if(  $c eq $item) {$pos=$i}
632
                $i++;
633
        }
634
        return $pos;
635 48 alirezamon
}
636 43 alirezamon
 
637 48 alirezamon
sub get_pos{
638
        my ($item,@list)=@_;
639
        my $pos=0;
640
        foreach my $p (@list){
641
                #print "$p eq $item\n";
642
                if ($p eq $item){return $pos;}
643
                $pos++;
644
        }
645
        return undef;
646
}
647
 
648 43 alirezamon
sub remove_scolar_from_array{
649
        my ($array_ref,$item)=@_;
650
        my @array=@{$array_ref};
651
        my @new;
652
        foreach my $p (@array){
653
                if($p ne $item ){
654
                        push(@new,$p);
655
                }
656
        }
657
        return @new;
658
}
659
 
660
sub replace_in_array{
661
        my ($array_ref,$item1,$item2)=@_;
662
        my @array=@{$array_ref};
663
        my @new;
664
        foreach my $p (@array){
665
                if($p eq $item1 ){
666
                        push(@new,$item2);
667
                }else{
668
                        push(@new,$p);
669
                }
670
        }
671
        return @new;
672
}
673
 
674
 
675
 
676
# return an array of common elemnts between two input arays 
677
sub get_common_array{
678
        my ($a_ref,$b_ref)=@_;
679
        my @A=@{$a_ref};
680
        my @B=@{$b_ref};
681
        my @C;
682
        foreach my $p (@A){
683
                if( grep (/^\Q$p\E$/,@B)){push(@C,$p)};
684
        }
685
        return  @C;
686
}
687
 
688
#a-b
689
sub get_diff_array{
690
        my ($a_ref,$b_ref)=@_;
691
        my @A=@{$a_ref};
692
        my @B=@{$b_ref};
693
        my @C;
694
        foreach my $p (@A){
695
                if( !grep  (/^\Q$p\E$/,@B)){push(@C,$p)};
696
        }
697
        return  @C;
698
 
699
}
700
 
701
 
702 48 alirezamon
sub return_not_unique_names_in_array{
703
        my @array = @_;
704
        my %seen;
705
        my @r;
706
        foreach my $value (@array) {
707
                if (! $seen{$value}) {
708
                $seen{$value} = 1;
709
                }else{
710
                        push(@r,$value);
711
                }
712
        }
713
        return @r;
714
}
715 43 alirezamon
 
716 48 alirezamon
 
717 43 alirezamon
sub compress_nums{
718
        my      @nums=@_;
719
        my @f=sort { $a <=> $b } @nums;
720
        my $s;
721
        my $ls;
722
        my $range=0;
723
        my $x;
724
 
725
 
726
        foreach my $p (@f){
727
                if(!defined $x) {
728
                        $s="$p";
729
                        $ls=$p;
730
 
731
                }
732
                else{
733
                        if($p-$x>1){ #gap exist
734
                                if( $range){
735
                                        $s=($x-$ls>1 )? "$s:$x,$p": "$s,$x,$p";
736
                                        $ls=$p;
737
                                        $range=0;
738
                                }else{
739
                                $s= "$s,$p";
740
                                $ls=$p;
741
 
742
                                }
743
 
744
                        }else {$range=1;}
745
 
746
 
747
 
748
                }
749
 
750
                $x=$p
751
        }
752
        if($range==1){ $s= ($x-$ls>1 )? "$s:$x":  "$s,$x";}
753
        #update $s($ls,$hs);
754
 
755
        return $s;
756
 
757
}
758
 
759
 
760
 
761
sub metric_conversion{
762
        my $size=shift;
763 48 alirezamon
        my $size_text=  $size<=0  ? 'Error ':
764 43 alirezamon
                        $size<(1 << 10)? $size:
765
                        $size<(1 << 20)? join (' ', ($size>>10,"K")) :
766
                        $size<(1 << 30)? join (' ', ($size>>20,"M")) :
767
                                         join (' ', ($size>>30,"G")) ;
768
return $size_text;
769
}
770
 
771
 
772
 
773
 
774
 
775
######
776
#  state
777
#####
778
sub set_gui_status{
779
        my ($object,$status,$timeout)=@_;
780
        $object->object_add_attribute('gui_status','status',$status);
781
        $object->object_add_attribute('gui_status','timeout',$timeout);
782
}
783
 
784
 
785
sub get_gui_status{
786
        my ($object)=@_;
787
        my $status= $object->object_get_attribute('gui_status','status');
788
        my $timeout=$object->object_get_attribute('gui_status','timeout');
789
        return ($status,$timeout);
790
}
791
 
792
 
793
 
794
 
795
###########
796
#  color
797
#########
798
 
799
 
800
 
801
sub get_color {
802
        my $num=shift;
803
 
804
        my @colors=(
805
        0x6495ED,#Cornflower Blue
806
        0xFAEBD7,#Antiquewhite
807
        0xC71585,#Violet Red
808
        0xC0C0C0,#silver
809
        0xADD8E6,#Lightblue     
810
        0x6A5ACD,#Slate Blue
811
        0x00CED1,#Dark Turquoise
812
        0x008080,#Teal
813
        0x2E8B57,#SeaGreen
814
        0xFFB6C1,#Light Pink
815
        0x008000,#Green
816
        0xFF0000,#red
817
        0x808080,#Gray
818
        0x808000,#Olive
819
        0xFF69B4,#Hot Pink
820
        0xFFD700,#Gold
821
        0xDAA520,#Goldenrod
822
        0xFFA500,#Orange
823
        0x32CD32,#LimeGreen
824
        0x0000FF,#Blue
825
        0xFF8C00,#DarkOrange
826
        0xA0522D,#Sienna
827
        0xFF6347,#Tomato
828
        0x0000CD,#Medium Blue
829
        0xFF4500,#OrangeRed
830
        0xDC143C,#Crimson       
831
        0x9932CC,#Dark Orchid
832
        0x800000,#marron
833
        0x800080,#Purple
834
        0x4B0082,#Indigo
835
        0xFFFFFF,#white 
836 54 alirezamon
        0x000000, #Black                
837
                #heatmap
838
        0xbdff00, #     (189,255,0)
839
        0xe3f018, #     (227,240,24)
840
        0xffce00, #     (255,206,0)
841
        0xff6612, #     (255,102,18)
842
        0xc12424, #     (193,36,36)
843 43 alirezamon
                );
844
 
845
        my $color=      ($num< scalar (@colors))? $colors[$num]: 0xFFFFFF;
846
        my $red=        ($color & 0xFF0000) >> 8;
847
        my $green=      ($color & 0x00FF00);
848
        my $blue=       ($color & 0x0000FF) << 8;
849
 
850
        return ($red,$green,$blue);
851
 
852
}
853
 
854
 
855
sub get_color_hex_string {
856
        my $num=shift;
857
 
858
        my @colors=(
859
        "6495ED",#Cornflower Blue
860
        "FAEBD7",#Antiquewhite
861
        "C71585",#Violet Red
862
        "C0C0C0",#silver
863
        "ADD8E6",#Lightblue     
864
        "6A5ACD",#Slate Blue
865
        "00CED1",#Dark Turquoise
866
        "008080",#Teal
867
        "2E8B57",#SeaGreen
868
        "FFB6C1",#Light Pink
869
        "008000",#Green
870
        "FF0000",#red
871
        "808080",#Gray
872
        "808000",#Olive
873
        "FF69B4",#Hot Pink
874
        "FFD700",#Gold
875
        "DAA520",#Goldenrod
876
        "FFA500",#Orange
877
        "32CD32",#LimeGreen
878
        "0000FF",#Blue
879
        "FF8C00",#DarkOrange
880
        "A0522D",#Sienna
881
        "FF6347",#Tomato
882
        "0000CD",#Medium Blue
883
        "FF4500",#OrangeRed
884
        "DC143C",#Crimson       
885
        "9932CC",#Dark Orchid
886
        "800000",#marron
887
        "800080",#Purple
888
        "4B0082",#Indigo
889
        "FFFFFF",#white 
890 54 alirezamon
        "000000", #Black        
891
                #heatmap
892
        "bdff00", #     (189,255,0)
893
        "e3f018", #     (227,240,24)
894
        "ffce00", #     (255,206,0)
895
        "ff6612", #     (255,102,18)
896
        "c12424", #     (193,36,36)
897
 
898
 
899 43 alirezamon
                );
900
 
901
        my $color=      ($num< scalar (@colors))? $colors[$num]: "FFFFFF";
902
        return $color;
903
 
904
}
905
 
906
 
907
 
908
 
909
 
910
sub check_verilog_identifier_syntax {
911
        my $in=shift;
912
        my $error=0;
913
        my $message='';
914 48 alirezamon
#check if $in is defined
915
        if(!defined $in){
916
                return "Identifier is not defined! An Identifier must begin with an alphabetic character.\n";
917
        }
918
 
919
        if(length $in ==0){
920
                return "Identifier length is zero! An Identifier must begin with an alphabetic character.\n";
921
        }
922
 
923 43 alirezamon
# an Identifiers must begin with an alphabetic character or the underscore character
924
        if ($in =~ /^[0-9\$]/){
925 48 alirezamon
                return "An Identifier must begin with an alphabetic character or the underscore character.\n";
926 43 alirezamon
        }
927
 
928
 
929
#       Identifiers may contain alphabetic characters, numeric characters, the underscore, and the dollar sign (a-z A-Z 0-9 _ $ )
930
        if ($in =~ /[^a-zA-Z0-9_\$]+/){
931 48 alirezamon
                 #print "use of illegal character after\n" ;
932 43 alirezamon
                 my @w= split /([^a-zA-Z0-9_\$]+)/, $in;
933 48 alirezamon
                 return "Contain illegal character of \"$w[1]\" after $w[0]. Identifiers may contain alphabetic characters, numeric characters, the underscore, and the dollar sign (a-z A-Z 0-9 _ \$ )\n";
934 43 alirezamon
 
935
        }
936
 
937
 
938
# check Verilog reserved words
939
        my @keys =                      ("always","and","assign","automatic","begin","buf","bufif0","bufif1","case","casex","casez","cell","cmos","config","deassign","default","defparam","design","disable","edge","else","end","endcase","endconfig","endfunction","endgenerate","endmodule","endprimitive","endspecify","endtable","endtask","event","for","force","forever","fork","function","generate","genvar","highz0","highz1","if","ifnone","incdir","include","initial","inout","input","instance","integer","join","large","liblist","library","localparam","macromodule","medium","module","nand","negedge","nmos","nor","noshowcancelled","not","notif0","notif1","or","output","parameter","pmos","posedge","primitive","pull0","pull1","pulldown","pullup","pulsestyle_onevent","pulsestyle_ondetect","remos","real","realtime","reg","release","repeat","rnmos","rpmos","rtran","rtranif0","rtranif1","scalared","showcancelled","signed","small","specify","specparam","strong0","strong1","supply0","supply1","table","task","time","tran","tranif0","tranif1","tri","tri0","tri1","triand","trior","trireg","unsigned","use","vectored","wait","wand","weak0","weak1","while","wire","wor","xnor","xor");
940
        if( grep (/^$in$/,@keys)){
941 48 alirezamon
                return  "$in is a Verlig reserved word.\n";
942 43 alirezamon
        }
943
        return undef;
944
 
945
}
946
 
947
 
948
sub capture_number_after {
949
        my ($after,$text)=@_;
950
        my @q =split  (/$after/,$text);
951
        #my $d=$q[1];
952
        my @d = split (/[^0-9. ]/,$q[1]);
953
        return $d[0];
954
 
955
}
956
 
957
sub capture_string_between {
958
        my ($start,$text,$end)=@_;
959
        my @q =split  (/$start/,$text);
960
        my @d = split (/$end/,$q[1]);
961
        return $d[0];
962
}
963
 
964 48 alirezamon
sub capture_cores_data {
965
        my ($data,$text)=@_;
966
        my %result;
967
        my @q =split  (/End_point/,$text);
968
        my $i=0;
969
        foreach my $p (@q){
970
                if ($i!=0){
971
                        my @d = split (/[^0-9. ]/,$p);
972
                        my $n=  $d[0];
973
                        my $val = capture_number_after("$data",$p);
974
                        $result{remove_all_white_spaces($n)}=remove_all_white_spaces($val);
975
                }
976
                $i++;
977
        }
978
        return %result;
979
}
980 43 alirezamon
 
981
sub make_undef_as_string {
982
        foreach my $p  (@_){
983
                $$p= 'undef' if (! defined $$p);
984
 
985
        }
986
}
987
 
988
sub powi{ # x^y
989
        my ($x,$y)=@_; # compute x to the y
990
        my $r=1;
991
        for (my $i = 0; $i < $y; ++$i ) {
992
        $r *= $x;
993
        }
994
  return $r;
995
}
996
 
997
sub sum_powi{ # x^(y-1) + x^(y-2) + ...+ 1;
998
        my ($x,$y)=@_; # compute x to the y
999
        my $r = 0;
1000
    for (my $i = 0; $i < $y; $i++){
1001
        $r += powi( $x, $i );
1002
    }
1003
        return $r;
1004
}
1005 48 alirezamon
 
1006
 
1007
 
1008
 
1009
 
1010
#############
1011
# object
1012
############
1013
 
1014
sub object_add_attribute{
1015
        my ($self,$attribute1,$attribute2,$value)=@_;
1016
        if(!defined $attribute2){$self->{$attribute1}=$value;}
1017
        else {$self->{$attribute1}{$attribute2}=$value;}
1018
 
1019
}
1020
 
1021
 
1022
 
1023
sub object_get_attribute{
1024
        my ($self,$attribute1,$attribute2)=@_;
1025
        if(!defined $attribute2) {return $self->{$attribute1};}
1026
        return $self->{$attribute1}{$attribute2};
1027
}
1028
 
1029
 
1030
sub object_add_attribute_order{
1031
        my ($self,$attribute,@param)=@_;
1032
        my $r = $self->{'parameters_order'}{$attribute};
1033
        my @a;
1034
        @a = @{$r} if(defined $r);
1035
        push (@a,@param);
1036
        @a=uniq(@a);
1037
        $self->{'parameters_order'}{$attribute} =\@a;
1038
}
1039
 
1040
sub object_remove_attribute_order{
1041
        my ($self,$attribute,$param)=@_;
1042
        my @r=@{$self->{parameters_order}{$attribute}};
1043
        my @n;
1044
        foreach my $p(@r){
1045
                if( $p ne $param) {push(@n,$p)};
1046
 
1047
        }
1048
        $self->{parameters_order}{$attribute}=\@n;
1049
 
1050
}
1051
 
1052
sub object_get_attribute_order{
1053
        my ($self,$attribute)=@_;
1054
        return unless(defined $self->{parameters_order}{$attribute});
1055
        my @order=@{$self->{parameters_order}{$attribute}};
1056
        return uniq(@order)
1057
}
1058
 
1059
sub object_remove_attribute{
1060
        my ($self,$attribute1,$attribute2)=@_;
1061
        if(!defined $attribute2){
1062
                delete $self->{$attribute1} if ( exists( $self->{$attribute1}));
1063
        }
1064
        else {
1065
                delete $self->{$attribute1}{$attribute2} if ( exists( $self->{$attribute1}{$attribute2})); ;
1066
        }
1067
}
1068
 
1069
 
1070
#############
1071
#  graphviz
1072
#############
1073
 
1074
 
1075
sub generate_and_show_graph_using_graphviz {
1076
        my ($self,$scrolled_win,$dotfile, $graph_name)=@_;
1077 43 alirezamon
 
1078
 
1079 48 alirezamon
        #empty the scrolled win 
1080
        if(defined $scrolled_win){
1081
                my @list = $scrolled_win->get_children();
1082
                foreach my $l (@list){
1083
                        $scrolled_win->remove($l);
1084
                }
1085
        }
1086
 
1087
        my $scale=$self->object_get_attribute($graph_name,"scale");
1088
        $scale= 1 if (!defined $scale);
1089
        my $diagram;
1090
 
1091 54 alirezamon
        my $cmd = "echo \'$dotfile\' | dot -Tpng -q";
1092 48 alirezamon
        my ($stdout,$exit,$stderr)= run_cmd_in_back_ground_get_stdout ($cmd);
1093
        if ( length( $stderr || '' ) !=0)  {
1094
                message_dialog("$stderr\nHave you installed graphviz? If not run \n \t \"sudo apt-get install graphviz\" \n in terminal",'error');
1095
        }
1096
        $diagram =open_inline_image( $stdout,70*$scale,70*$scale,'percent');
1097
        if(defined $scrolled_win){
1098
                add_widget_to_scrolled_win($diagram,$scrolled_win);
1099
                $scrolled_win->show_all();
1100
        }
1101
    my $save=$self->object_get_attribute("graph_save","enable");
1102
        $save=0 if(!defined $save);
1103
        if($save==1){
1104
                my $file = $self->object_get_attribute("graph_save","name");
1105
                my $ext  = $self->object_get_attribute("graph_save","extension");
1106
                my $pixbuff= $diagram->get_pixbuf;
1107
            $pixbuff->save ("$file.$ext", "$ext");
1108
            $self->object_add_attribute("graph_save","enable",'0');
1109
        }
1110
 
1111
 
1112
}
1113 43 alirezamon
 
1114
 
1115 48 alirezamon
###########
1116
#       run_multiple_proc_in_background (@cmds) 
1117
#       run parallel application in background and return err, stdout
1118
#       return for $ith application i start from 0
1119
#               $pipes{$i}{"out"}= stdout;
1120
#               $pipes{$i}{"err"}= stderr;     
1121
###########
1122
 
1123
sub run_multiple_proc_in_background
1124
{
1125
        my @cmds = @_;
1126
        my %pipes;
1127
    my $i=0;
1128
        #open seprate pipe for each command
1129
        foreach my $cmd (@cmds){
1130
                #print "$cmd\n";
1131
                my ($pipe,$in, $out, $err,$r);
1132
                $pipes{$i}{"out"}=\$out;
1133
                $pipes{$i}{"err"}=\$err;
1134
        $pipes{$i}{"pipe"}=\$pipe;
1135
                my @cat = split ('\s+', $cmd );
1136
                my $cmd_name=$cat[0];
1137
                #perevent pipe from crock               
1138
                if (!(-e $cmd_name)) {
1139
                        $err= "file not found: $cmd_name";
1140
                }elsif (!(-f $cmd_name)) {
1141
                $err= "not a file: $cmd_name";
1142
                }elsif (!(-x $cmd_name)) {
1143
                        $err= "permission denied: $cmd_name";
1144
                }
1145
                if (defined  $err){
1146
                        $i++;
1147
                        next;
1148
                }
1149
 
1150
                $pipe =start \@cat, \$in, \$out, \$err or $r=$?;
1151
                if(defined $r){
1152
                        #add_colored_info($tview," quartus_stp got an Error: $r\n",'red');
1153
                        $err= "Pipe got an Error: $r\n";
1154
                        $i++;
1155
                        next;
1156
                }
1157
        $i++;
1158
        }
1159
 
1160
        my $pumpble=0;
1161
        my $cnt=0;
1162
        do{
1163
                $pumpble=0;
1164
                for (my $i=0; $i< scalar @cmds; $i++){
1165
                        my $pipe= ${$pipes{$i}{"pipe"}};
1166
                        next if(!defined $pipe);
1167
                        if (pumpable ($pipe)) {
1168
                                pump $pipe;
1169
                            $pumpble=1;
1170
                            print "pump $i\n";
1171
                        }
1172
                }
1173
                #if($cnt==100) {
1174
                #               $cnt=0;                 
1175
                                refresh_gui();
1176
                #}
1177
                #$cnt++
1178
        }while($pumpble);
1179
 
1180
 
1181
        for (my $i=0; $i< scalar @cmds; $i++){
1182
                my $pipe= ${$pipes{$i}{"pipe"}};
1183
                next if(!defined $pipe);
1184
                finish $pipe;
1185
        }
1186
        return %pipes;
1187
}
1188
 
1189
 
1190
sub add_param_widget {
1191
         my ($self,$name,$param, $default,$type,$content,$info, $table,$row,$column,$show,$attribut1,$ref_delay,$new_status,$loc)=@_;
1192
         my $label;
1193
         $label =gen_label_in_left(" $name") if(defined $name);
1194
         my $widget;
1195
         my $value=$self->object_get_attribute($attribut1,$param);
1196
         if(! defined $value) {
1197
                        $self->object_add_attribute($attribut1,$param,$default);
1198
                        $self->object_add_attribute_order($attribut1,$param);
1199
                        $value=$default;
1200
         }
1201
         if(! defined $new_status){
1202
                $new_status='ref';
1203
         }
1204
         if (! defined $loc){
1205
                 $loc = "vertical";
1206
         }
1207
         if ($type eq "Entry"){
1208
                $widget=gen_entry($value);
1209
                $widget-> signal_connect("changed" => sub{
1210
                        my $new_param_value=$widget->get_text();
1211
                        $self->object_add_attribute($attribut1,$param,$new_param_value);
1212
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1213
                });
1214
         }
1215
         elsif ($type eq "Combo-box"){
1216
                 my @combo_list=split(/\s*,\s*/,$content);
1217
                 my $pos=get_pos($value, @combo_list) if(defined $value);
1218
                 if(!defined $pos){
1219
                        $self->object_add_attribute($attribut1,$param,$default);
1220
                        $pos=get_item_pos($default, @combo_list) if (defined $default);
1221
 
1222
                 }
1223
                #print " my $pos=get_item_pos($value, @combo_list);\n";
1224
                 $widget=gen_combo(\@combo_list, $pos);
1225
                 $widget-> signal_connect("changed" => sub{
1226
                 my $new_param_value=$widget->get_active_text();
1227
                 $self->object_add_attribute($attribut1,$param,$new_param_value);
1228
                 set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1229
                 });
1230
 
1231
         }
1232
         elsif ($type eq "EntryCombo"){
1233
                 my @combo_list;
1234
                 @combo_list=split(/\s*,\s*/,$content) if(defined $content);
1235
                 my $pos=get_pos($value, @combo_list) if(defined $value && defined $content);
1236
                 $widget= gen_combo_entry (\@combo_list,$pos);
1237
                 my $child = combo_entry_get_chiled($widget);
1238
                 $child->signal_connect('changed' => sub {
1239
                                my ($entry) = @_;
1240
                                my $new_param_value=$entry->get_text();
1241
                                $self->object_add_attribute($attribut1,$param,$new_param_value);
1242
                                set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1243
                 });
1244
         }
1245 43 alirezamon
 
1246 48 alirezamon
         elsif  ($type eq "Spin-button"){
1247
                my ($min,$max,$step,$digit)=split(/\s*,\s*/,$content);
1248
 
1249
                $value=~ s/[^0-9.\-]//g;
1250
                $min=~   s/[^0-9.\-]//g;
1251
                $max=~   s/[^0-9.\-]//g;
1252
                $step=~  s/[^0-9.\-]//g;
1253
                $digit=~ s/[^0-9.\-]//g if (defined $digit);
1254
                  #$max = $min if($max<$min);
1255
                  $widget=gen_spin($min,$max,$step,$digit);
1256
                  $widget->set_value($value);
1257
                  $widget-> signal_connect("value_changed" => sub{
1258
                  my $new_param_value=$widget->get_value();
1259
                  $self->object_add_attribute($attribut1,$param,$new_param_value);
1260
                  set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1261
              });
1262
 
1263
                 # $box=def_label_spin_help_box ($param,$info, $value,$min,$max,$step, 2);
1264
         }
1265
 
1266
        elsif ( $type eq "Check-box"){
1267
                $widget = def_hbox(FALSE,0);
1268
                my @check;
1269
                for (my $i=0;$i<$content;$i++){
1270
                        $check[$i]= gen_checkbutton();
1271
                }
1272
                for (my $i=0;$i<$content;$i++){
1273
                        $widget->pack_end(  $check[$i], FALSE, FALSE, 0);
1274
 
1275
                        my @chars = split("",$value);
1276
                        #check if saved value match the size of check box
1277
                        if($chars[0] ne $content ) {
1278
                                $self->object_add_attribute($attribut1,$param,$default);
1279
                                $value=$default;
1280
                                @chars = split("",$value);
1281
                        }
1282
                        #set initial value
1283
 
1284
                        #print "\@chars=@chars\n";
1285
                        for (my $i=0;$i<$content;$i++){
1286
                                my $loc= (scalar @chars) -($i+1);
1287
                                        if( $chars[$loc] eq '1') {$check[$i]->set_active(TRUE);}
1288
                                        else {$check[$i]->set_active(FALSE);}
1289
                        }
1290
 
1291
 
1292
                        #get new value
1293
                        $check[$i]-> signal_connect("toggled" => sub{
1294
                                my $new_val="$content\'b";
1295
 
1296
                                for (my $i=$content-1; $i >= 0; $i--){
1297
                                        if($check[$i]->get_active()) {$new_val="${new_val}1" ;}
1298
                                        else {$new_val="${new_val}0" ;}
1299
                                }
1300
                                $self->object_add_attribute($attribut1,$param,$new_val);
1301
                                #print "\$new_val=$new_val\n";
1302
                                set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1303
                        });
1304
                }
1305
 
1306
        }
1307
        elsif ( $type eq "DIR_path"){
1308
                        $widget =get_dir_in_object ($self,$attribut1,$param,$value,'ref',10,$default);
1309
                        set_gui_status($self,$new_status,$ref_delay) if(defined $ref_delay);
1310
        }
1311
        elsif ( $type eq "FILE_path"){ # use $content as extention
1312
                        $widget =get_file_name_object ($self,$attribut1,$param,$content,undef,$new_status,$ref_delay);
1313
 
1314
        }
1315
        elsif ( $type eq 'Fixed'){
1316
                 $self->object_add_attribute($attribut1,$param,$default);
1317
                 $widget =gen_label_in_left("$default");
1318
        }
1319
        else {
1320
                 $widget =gen_label_in_left("unsuported widget type!");
1321
        }
1322
 
1323
        my $inf_bt= (defined $info)? gen_button_message ($info,"icons/help.png"):gen_label_in_left(" ");
1324
        if($show==1){
1325
                attach_widget_to_table ($table,$row,$label,$inf_bt,$widget,$column);
1326
                if ($loc eq "vertical"){
1327
                        #print "$loc\n";
1328
                         $row ++;}
1329
                else {
1330
 
1331
                        $column+=4;
1332
                }
1333
        }
1334
    return ($row,$column,$widget);
1335
}
1336
 
1337
 
1338 54 alirezamon
#get the list of files matching the given extention
1339
sub get_file_list_by_extention {
1340
        my ($open_in, $ext)=@_;
1341
        my @files = glob "$open_in/*";
1342
        my $file_list="";
1343
        foreach my $file (@files){
1344
                my ($name,$path,$suffix) = fileparse("$file",qr"\..[^.]*$");
1345
                if($suffix eq $ext || $suffix eq ".$ext" ){
1346
                        $file_list.=",$name";
1347
                }
1348
        }
1349
        return  ($file_list,\@files);
1350
}
1351 48 alirezamon
 
1352 54 alirezamon
 
1353
 
1354
 
1355
sub set_gui_setting{
1356
        my $paths=shift;
1357
        my %p=%{$paths};
1358
        $glob_setting{'FONT_SIZE'}= $p{'GUI_SETTING'}{'FONT_SIZE'} if (defined $p{'GUI_SETTING'}{'FONT_SIZE'});
1359
        $glob_setting{'ICON_SIZE'}= $p{'GUI_SETTING'}{'ICON_SIZE'} if (defined $p{'GUI_SETTING'}{'ICON_SIZE'});
1360
        $glob_setting{'DSPLY_X'}  = $p{'GUI_SETTING'}{'DSPLY_X'}   if (defined $p{'GUI_SETTING'}{'DSPLY_X'});
1361
        $glob_setting{'DSPLY_Y'}  = $p{'GUI_SETTING'}{'DSPLY_Y'}   if (defined $p{'GUI_SETTING'}{'DSPLY_Y'});
1362
}
1363
 
1364
my ($screen_x,$screen_y);
1365
 
1366
sub get_default_screen_size{
1367
        return  ($screen_x,$screen_y) if (defined $screen_x && defined $screen_y);
1368
 
1369
        my $fh= 'xrandr --current | awk \'$2~/\*/{print $1}\'' ;
1370
        my ($stdout, $stderr, $success) = qxx( ($fh) );
1371
        my @a = split ("\n",$stdout);
1372
        ($screen_x,$screen_y) = split ("x",$a[0]);
1373
        $screen_x = 600 if(!defined $screen_x);
1374
        $screen_y = 800 if(!defined $screen_y);
1375
        return  ($screen_x,$screen_y);
1376
}
1377
 
1378
 
1379
sub get_current_monitor_working_area{
1380
    my $screen = get_default_screen();
1381
        my $hight = $screen->get_height();
1382
        my $active = $screen->get_active_window();
1383
        my $monitor =   $screen->get_monitor_at_window($active);
1384
        my $warea = $screen->get_monitor_workarea($monitor);#get_width(); 
1385
        #print  Data::Dumper->Dump ([$warea],['ttt']);  
1386
        return ($warea->{'width'},$warea->{'height'});
1387
}
1388
 
1389
 
1390
 
1391
 
1392
sub max_win_size {
1393
        my ($x,$y);
1394
        $x= int($glob_setting{'DSPLY_X'}) if ($glob_setting{'DSPLY_X'} ne 'default');
1395
        $y= int($glob_setting{'DSPLY_Y'}) if ($glob_setting{'DSPLY_Y'} ne 'default');
1396
        if (!defined $x || !defined $y){
1397
                my ($X,$Y)=get_current_monitor_working_area();
1398
                $x=$X if (!defined $x);
1399
                $y=$Y if (!defined $y);
1400
        }
1401
 
1402
        return ($x,$y);
1403
 
1404
 
1405
}
1406
 
1407
 
1408 48 alirezamon
1

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.