2 ################################################################################
4 # File: ecrc: ECR client
5 # Description: This script is a test client for ecrd.
6 # Author: Andrew@DeFaria.com
7 # Created: Tue Feb 15 11:01:24 PST 2005
11 # (c) Copyright 2005, LynuxWorks, all rights reserved.
13 ################################################################################
18 my ($me, $abs_path, $lib_path, $bin_path, $log_path);
21 # Extract relative path and basename from script name.
22 $0 =~ /(.*)[\/\\](.*)/;
24 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
25 $me = (!defined $2) ? $0 : $2;
29 $bin_path = "$abs_path";
30 $lib_path = "$abs_path/../lib";
31 $log_path = "$abs_path/../log";
33 # Add the appropriate path to our modules to @INC array.
34 unshift (@INC, "$lib_path");
40 my $servername = (!defined $ENV {ECRDSERVER}) ? "lynx12" : $ENV {ECRDSERVER};
41 my $port = (!defined $ENV {ECRDPORT}) ? 1500 : $ENV {ECRDPORT};
43 my @query_fields = ();
54 print "ERROR: $msg\n\n" if defined $msg;
56 print "Usage: ecrc [-u] [-v] [-d] [ -s <server> ] [ -p <port> ] ";
57 print "ECR [ fieldname... ]\n";
59 print "\t-u:\t\tDisplay usage\n";
60 print "\t-v:\t\tTurn on verbose mode (Default off)\n";
61 print "\t-d:\t\tTurn on debug mode (Default off)\n";
62 print "\t-s:\t\tUse server named servername (Default lynx12)\n";
63 print "\t-s:\t\tUse port (Default 1500)\n";
64 print "\tECR:\t\tECR number to obtain info about\n";
65 print "\tfieldname:\tECR field names to retrieve info about (Default all)\n";
72 if ($ARGV [0] eq "-v") {
75 } elsif ($ARGV [0] eq "-d") {
78 } elsif ($ARGV [0] eq "-u") {
80 } elsif ($ARGV [0] eq "-p") {
82 Usage "Port not specified" if !$ARGV [0];
84 } elsif ($ARGV [0] eq "-s") {
86 Usage "Server name not specified" if !$ARGV [0];
87 $servername = shift @ARGV;
95 @query_fields = @ARGV;
97 # Downshift any query_fields
100 foreach (@query_fields) {
101 $query_fields [$i++] = lc $_;
108 die "Unable to connect to $servername:$port\n" if !ecrc::Connect ($servername, $port);
112 @ecrs = ecrc::GetECRRecord $ecr;
121 %fields = ecrc::GetECRRecord ($ecr);
124 print "ECR $ecr was not found\n";
127 foreach (@query_fields) {
128 if (@query_fields > 1) {
129 if (defined $fields{$_}) {
130 print "$_: $fields{$_}\n";
132 print "$_: <FIELD NOT FOUND>\n";
135 if (defined $fields{$_}) {
136 print "$fields{$_}\n";
138 print "$_: <FIELD NOT FOUND>\n";
143 while (($key, $value) = each (%fields)) {
144 print "$key: $value\n";
151 while (my $command = <STDIN>) {
153 last if $command =~ m/exit|quit/i;
158 my @ecrs = ecrc::GetECRRecord $ecr;
164 %fields = ecrc::GetECRRecord $ecr;
167 print "ECR $ecr was not found\n";
169 while (($key, $value) = each (%fields)) {
170 print "$key: $value\n";