2 # various utilities which are exported globally
4 # Copyright (c) 1998 - Dirk Koopman G1TLH
16 @EXPORT = qw(atime ztime cldate cldatetime slat slong yesno promptf parray parraypairs
17 print_all_fields cltounix
20 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
22 # a full time for logging and other purposes
26 my ($sec,$min,$hour,$mday,$mon,$year) = gmtime((defined $t) ? $t : time);
28 my $buf = sprintf "%02d%s%04d\@%02d:%02d:%02d", $mday, $month[$mon], $year, $hour, $min, $sec;
32 # get a zulu time in cluster format (2300Z)
36 my ($sec,$min,$hour) = gmtime((defined $t) ? $t : time);
38 my $buf = sprintf "%02d%02dZ", $hour, $min;
43 # get a cluster format date (23-Jun-1998)
47 my ($sec,$min,$hour,$mday,$mon,$year) = gmtime((defined $t) ? $t : time);
49 my $buf = sprintf "%2d-%s-%04d", $mday, $month[$mon], $year;
53 # return a cluster style date time
57 my $date = cldate($t);
62 # return a unix date from a cluster date and time
67 my ($thisyear) = (gmtime)[5] + 1900;
69 return 0 unless $date =~ /^\s*(\d+)-(\w\w\w)-([12][90]\d\d)$/;
70 return 0 unless abs($thisyear-$3) <= 1;
72 return 0 unless $time =~ /^([012]\d)([012345]\d)Z$/;
73 $time = "$1:$2 +0000";
74 return str2time("$date $time");
77 # turn a latitude in degrees into a string
81 my ($deg, $min, $let);
82 $let = $n >= 0 ? 'N' : 'S';
85 $min = int ((($n - $deg) * 60) + 0.5);
86 return "$deg $min $let";
89 # turn a longitude in degrees into a string
93 my ($deg, $min, $let);
94 $let = $n >= 0 ? 'E' : 'W';
97 $min = int ((($n - $deg) * 60) + 0.5);
98 return "$deg $min $let";
101 # turn a true into 'yes' and false into 'no'
105 return $n ? $main::yes : $main::no;
108 # format a prompt with its current value and return it with its privilege
111 my ($line, $value) = @_;
112 my ($priv, $prompt, $action) = split ',', $line;
114 # if there is an action treat it as a subroutine and replace $value
116 my $q = qq{\$value = $action(\$value)};
119 $prompt = sprintf "%15s: %s", $prompt, $value;
120 return ($priv, $prompt);
123 # take an arg as an array list and print it
127 return join(', ', @{$ref});
130 # take the arg as an array reference and print as a list of pairs
137 for ($i = 0; $i < @$ref; $i += 2) {
139 my $r2 = @$ref[$i+1];
142 chop $out; # remove last space
143 chop $out; # remove last comma
147 # print all the fields for a record according to privilege
149 # The prompt record is of the format '<priv>,<prompt>[,<action>'
150 # and is expanded by promptf above
154 my $self = shift; # is a dxchan
155 my $ref = shift; # is a thingy with field_prompt and fields methods defined
157 my @fields = $ref->fields;
160 foreach $field (sort @fields) {
161 if (defined $ref->{$field}) {
162 my ($priv, $ans) = promptf($ref->field_prompt($field), $ref->{$field});
163 push @out, $ans if ($self->priv >= $priv);