2 # various utilities which are exported globally
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
15 @EXPORT = qw(atime ztime cldate cldatetime slat slong yesno promptf parray parraypairs
16 print_all_fields cltounix
19 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
21 # a full time for logging and other purposes
25 my ($sec,$min,$hour,$mday,$mon,$year) = gmtime((defined $t) ? $t : time);
27 my $buf = sprintf "%02d%s%04d\@%02d:%02d:%02d", $mday, $month[$mon], $year, $hour, $min, $sec;
31 # get a zulu time in cluster format (2300Z)
35 my ($sec,$min,$hour) = gmtime((defined $t) ? $t : time);
37 my $buf = sprintf "%02d%02dZ", $hour, $min;
42 # get a cluster format date (23-Jun-1998)
46 my ($sec,$min,$hour,$mday,$mon,$year) = gmtime((defined $t) ? $t : time);
48 my $buf = sprintf "%02d-%s-%04d", $mday, $month[$mon], $year;
52 # return a cluster style date time
56 my $date = cldate($t);
61 # return a unix date from a cluster date and time
66 $date =~ s/^\s*(\d+)-(\w\w\w)-(19\d\d)$/$1 $2 $3/;
67 $time =~ s/^(\d\d)(\d\d)Z$/$1:$2 +0000/;
68 return str2time("$date $time");
71 # turn a latitude in degrees into a string
75 my ($deg, $min, $let);
76 $let = $n >= 0 ? 'N' : 'S';
79 $min = int (($n - $deg) * 60);
80 return "$deg $min $let";
83 # turn a longitude in degrees into a string
87 my ($deg, $min, $let);
88 $let = $n >= 0 ? 'E' : 'W';
91 $min = int (($n - $deg) * 60);
92 return "$deg $min $let";
95 # turn a true into 'yes' and false into 'no'
99 return $n ? $main::yes : $main::no;
102 # format a prompt with its current value and return it with its privilege
105 my ($line, $value) = @_;
106 my ($priv, $prompt, $action) = split ',', $line;
108 # if there is an action treat it as a subroutine and replace $value
110 my $q = qq{\$value = $action(\$value)};
113 $prompt = sprintf "%15s: %s", $prompt, $value;
114 return ($priv, $prompt);
117 # take an arg as an array list and print it
120 return join(', ', @{shift});
123 # take the arg as an array reference and print as a list of pairs
130 for ($i = 0; $i < @$ref; $i += 2) {
132 my $r2 = @$ref[$i+1];
135 chop $out; # remove last space
136 chop $out; # remove last comma
140 # print all the fields for a record according to privilege
142 # The prompt record is of the format '<priv>,<prompt>[,<action>'
143 # and is expanded by promptf above
147 my $self = shift; # is a dxchan
148 my $ref = shift; # is a thingy with field_prompt and fields methods defined
151 my @fields = $ref->fields;
155 foreach $field (sort @fields) {
156 my ($priv, $ans) = promptf($ref->field_prompt($field), $ref->{$field});
157 push @out, $ans if ($self->priv >= $priv);