File: question.pl

package info (click to toggle)
cfingerd 1.4.3-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 968 kB
  • sloc: ansic: 3,776; perl: 501; makefile: 137; sh: 73
file content (57 lines) | stat: -rw-r--r-- 1,191 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## Ask question script
## by Ken Hollis <khollis@bitgate.com>
##
## This has been tested in JigModIRC2.8.21, and XIRC.  It also includes
## a routine to display text files.
##
## This program is GPLed.  Please read LICENSE for more information.
## Copyright (C) 1996, Bitgate Software.
##
## Directions for inclusion:
##	Include "require 'question.pl'" in your Perl program, and call
##	ask_question to ask your question.

sub ask_question {
	local($question, $value, $type, $cfile) = @_;

repeat_ask:
	print "$question ";
	if ($type eq "1") {
		$value =~ tr/a-z/A-Z/;
		print (($value eq "Y") ? "[Y/n/?] " : "[y/N/?] ");
	} elsif ($type eq "2") {
		print "[$value] ";
	} elsif ($type eq "3") {
		print "$value ";
	}

	$entry = <stdin>;
	chop($entry);

	if ($type eq "1") {
		$entry =~ tr/a-z/A-Z/;
		if ($entry eq "") {
			$entry = $value;
		} elsif ($entry eq "Y") {
			$entry = "Y";
		} elsif ($entry eq "N") {
			$entry = "N";
		} else {
			&disp_file($cfile);
			goto repeat_ask;
		}
	} elsif (($type eq "2") || ($type eq "3")) {
		if ($entry eq "") {
			$entry = $value;
		}
	}

	return $entry;
}

sub disp_file {
	open(FL, "$_[0]") || die "$_[0]: $!\n";
	print $_ while (<FL>);
}

1;