| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Autor: Boris Däppen, 2018 | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # No guarantee given, use at own risk and will | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | # PODNAME: backup-hanoi | ||||||||||||||||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: predict on which device to put next backup | ||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 5 | ▶ | use v5.6.0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 5 | ▶ | use Backup::Hanoi; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # we fake say, to support older perl | ||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub say { | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | print "$_[0]\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
say: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 5 | my $help = <<'END_MESSAGE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | backup-hanoi tells you where to write your next backup | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | You need to list your devices in a text file, separated by newline | ||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | example usages: | ||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # list repeatable pattern | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | backup-hanoi device-list.txt | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # list which device should be used for backup number 40 | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | backup-hanoi device-list.txt 40 | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # create a device-list for the backups 40 up to 60 | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | backup-hanoi device-list.txt 40 60 | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # first initialise all backups (fifo), then replace 40 times (hanoi) | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | backup-hanoi device-list.txt init 40 | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | END_MESSAGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 5 | ▶ | unless (@ARGV) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | say $help; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | exit 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 5 | my $devices_file = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 5 | my $cycle = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 5 | my $cycle_top = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 5 | open my $file_handle, '<', $devices_file; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | chomp(my @devices = <$file_handle>); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 5 | close $file_handle; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 5 | my $backup = Backup::Hanoi->new(\@devices); | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 5 | ▶ | if (defined $cycle_top and ($cycle_top or $cycle_top == 0)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
defined $cycle_top and $cycle_top || $cycle_top == 0
$cycle_top or $cycle_top == 0
MC/DC0%0/3
defined $cycle_top and $cycle_top || $cycle_top == 0
defined $cycle_top
$cycle_top
$cycle_top == 0
Truth table0%0/4
A and B or C
A= defined $cycle_topB= $cycle_topC= $cycle_top == 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | # start with negative number for FIFO | ||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 3 | ▶ | $cycle = 1 - (scalar @devices) if ($cycle eq 'init'); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | for ($cycle .. $cycle_top) { | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | say $backup->get_device_for_cycle($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ▶ | elsif (defined $cycle and ($cycle or $cycle == 0)) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
defined $cycle and $cycle || $cycle == 0
$cycle or $cycle == 0
MC/DC0%0/3
defined $cycle and $cycle || $cycle == 0
defined $cycle
$cycle
$cycle == 0
Truth table0%0/4
A and B or C
A= defined $cycleB= $cycleC= $cycle == 0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | say $backup->get_device_for_cycle($cycle); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | for (0 .. ((2**(scalar @devices))/2)-1) { | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | say $backup->get_device_for_cycle($_); | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||