change build number calculation to be more accurate
[spider.git] / perl / DXUtil.pm
index 0b3de9511e964f41c6834f025bcf4e60b1dc2f2d..9a911b70e4f6dccc2c7968bc9e4523d0ce4734f1 100644 (file)
@@ -12,14 +12,25 @@ use Date::Parse;
 use IO::File;
 use Data::Dumper;
 
+use strict;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+use vars qw(@month %patmap @ISA @EXPORT);
+
 require Exporter;
 @ISA = qw(Exporter);
 @EXPORT = qw(atime ztime cldate cldatetime slat slong yesno promptf 
-                        parray parraypairs shellregex readfilestr writefilestr
-             print_all_fields cltounix unpad is_callsign
-                        is_freq is_digits is_pctext is_pcflag insertitem deleteitem
+                        parray parraypairs phex shellregex readfilestr writefilestr
+             print_all_fields cltounix unpad is_callsign is_latlong
+                        is_qra is_freq is_digits is_pctext is_pcflag insertitem deleteitem
             );
 
+
 @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
 %patmap = (
                   '*' => '.*',
@@ -141,6 +152,13 @@ sub promptf
        return ($priv, $prompt);
 }
 
+# turn a hex field into printed hex
+sub phex
+{
+       my $val = shift;
+       return sprintf '%X', $val;
+}
+
 # take an arg as an array list and print it
 sub parray
 {
@@ -305,7 +323,7 @@ sub unpad
 # check that a field only has callsign characters in it
 sub is_callsign
 {
-       return $_[0] =~ /^(?:[A-Z]{1,2}\d+|\d[A-Z]\d+)[A-Z0-9\/\-]+$/;
+       return $_[0] =~ /^(?:[A-Z]{1,2}\d+|\d[A-Z]\d+)[A-Z]+(?:-\d{1,2}|\/[A-Z0-9]+)?$/;
 }
 
 # check that a PC protocol field is valid text
@@ -332,6 +350,18 @@ sub is_digits
        return $_[0] =~ /^[\d]+$/;
 }
 
+# does it look like a qra locator?
+sub is_qra
+{
+       return $_[0] =~ /^[A-Za-z][A-Za-z]\d\d[A-Za-z][A-Za-z]$/o;
+}
+
+# does it look like a valid lat/long
+sub is_latlong
+{
+       return $_[0] =~ /^\s*\d{1,2}\s+\d{1,2}\s*[NnSs]\s+\d{1,2}\s+\d{1,2}\s*[EeWw]\s*$/;
+}
+
 # insert an item into a list if it isn't already there returns 1 if there 0 if not
 sub insertitem
 {