From c104e56f1aaeac3d0be322b0c4e4d188bbab5ca9 Mon Sep 17 00:00:00 2001
From: Martin Mares <mj@ucw.cz>
Date: Fri, 11 Dec 2020 23:55:40 +0100
Subject: [PATCH] Scan: Implemented --exit

---
 scan/scan      | 26 ++++++++++++++++++++------
 scan/show-snmp |  2 +-
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/scan/scan b/scan/scan
index d798332..286c677 100755
--- a/scan/scan
+++ b/scan/scan
@@ -13,6 +13,7 @@ use Digest::SHA;
 
 my $verbose = 0;
 my $close = 0;
+my $opt_exit = 0;
 my $s_all = 0;
 my $s_encodings = 0;
 my $s_iodev = 0;
@@ -44,6 +45,7 @@ GetOptions(
 	"psversion!" => \$s_psversion,
 	"verbose!" => \$verbose,
 	"close!" => \$close,
+	"exit!" => \$opt_exit,
 ) and @ARGV == 1 or die <<AMEN ;
 Usage: $0 [<options>] <hostname>
 
@@ -59,6 +61,7 @@ Options:
 --psversion		Scan PS interpreter version
 --verbose		Be verbose and dump all communication with the printer
 --close			Close connection after each scan to flush buffers
+--exit			Send Universal Exit Language after each scan to flush buffers
 AMEN
 
 my ($host) = @ARGV;
@@ -236,10 +239,16 @@ sub need_ps() {
 	enter_ps();
 }
 
+sub end_ps() {
+	tx("flush\n");
+	uel() if $opt_exit;
+}
+
 sub scan_psversion() {
 	heading("PS interpreter version");
 	need_ps();
-	tx("version == revision == (%END%) = flush\n");
+	tx("version == revision == (%END%) =\n");
+	end_ps();
 	my $ver = rx_until("%END%");
 	print join(" ", @$ver), "\n";
 }
@@ -247,7 +256,8 @@ sub scan_psversion() {
 sub scan_pagedev() {
 	heading("PS page device parameters");
 	need_ps();
-	tx("currentpagedevice showdict (%END%) = flush\n");
+	tx("currentpagedevice showdict (%END%) =\n");
+	end_ps();
 	my $dict = rx_until("%END");
 	out_dict($dict);
 }
@@ -262,8 +272,9 @@ sub scan_iodev() {
 	currentdevparams showdict
 } 100 string /IODevice resourceforall
 (%>>%) =
-(%END%) = flush
+(%END%) =
 AMEN
+	end_ps();
 	out_dict(rx_until("%END"));
 }
 
@@ -277,8 +288,9 @@ sub scan_outdev() {
 	cvn /OutputDevice findresource showdict
 } 100 string /OutputDevice resourceforall
 (%>>%) =
-(%END%) = flush
+(%END%) =
 AMEN
+	end_ps();
 	my $odev = rx_until("%END%");
 	out_dict($odev);
 }
@@ -328,8 +340,9 @@ sub scan_psfonts() {
 	(%>>%) = flush	% Flush to avoid buffer management bugs on Xerox Phaser 3300
 } 100 string /Font resourceforall
 (%>>%) =
-(%END%) = flush
+(%END%) =
 AMEN
+	end_ps();
 	my $fonts = parse_dict(rx_until("%END%"));
 	if ($verbose) {
 		show_dict($fonts);
@@ -367,8 +380,9 @@ sub scan_encodings() {
 	/Encoding findresource ==
 } 100 string /Encoding resourceforall
 (%>>%) =
-(%END%) = flush
+(%END%) =
 AMEN
+	end_ps();
 	my $encs = parse_dict(rx_until("%END%"));
 	for my $e (keys %$encs) {
 		my $array = $encs->{$e};
diff --git a/scan/show-snmp b/scan/show-snmp
index 987032c..531becc 100755
--- a/scan/show-snmp
+++ b/scan/show-snmp
@@ -10,7 +10,7 @@ my $host = $ARGV[0] or die "Usage: $0 <host>\n";
 print "Scanning $host...\n";
 
 my $sess = Net::SNMP->session(
-	-hostname => $host . '.kam.hide.ms.mff.cuni.cz',
+	-hostname => $host . '.kam.mff.cuni.cz',
 	-version => 1,
 	-community => 'public',
 ) or die;
-- 
GitLab