File: general.pl

package info (click to toggle)
language-env 0.64
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,588 kB
  • ctags: 125
  • sloc: perl: 6,243; makefile: 83; tcl: 64; sh: 18
file content (127 lines) | stat: -rw-r--r-- 3,565 bytes parent folder | download | duplicates (3)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#
#
#   user-ja-conf
#
#   This file is a part of the Debian user-ja package.
#
#
# Copyright (C) 1998-2003 Tomohiro KUBOTA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# On Debian GNU/Linux systems, the complete text of the GNU General
# Public License can be found in `/usr/share/common-licenses/GPL'.
#
#
#
#
# These sub-routines are to be used by dot.*.pl.
#
# ------------------------------------------------
# isinstalled() checks whether a package is 
# installed or not.
# ------------------------------------------------
sub isinstalled ($) {
	my $a;
	$a = $_[0];
	if (grep(/^$a$/,@::DPKG_LIST)) {return 1;}
	return 0;
}

# ------------------------------------------------
# addlist() adds a package name to a 
# required package list
# ------------------------------------------------
sub addlist ($) {
	my $a;
	$a = $_[0];
	if (isinstalled($a)) {return 0;}
	if (grep($_ eq $a, @::RequiredPackageList)) {return 0;}
	@::RequiredPackageList = (@::RequiredPackageList , $a);
	return 0;
}

# ------------------------------------------------
# disp() displays a message suitable for native
# character environment.
# The 1st parameter is a message written in ASCII.
# The 2nd parameter is a message written in local
# codeset for source code.
# ------------------------------------------------
sub disp ($$) {
	if ($NC) {print STDERR &$::Lang_sourceset2displayset($_[1]);}
	else {print STDERR $_[0];}
}

# ------------------------------------------------
# This is used only internally.
# ------------------------------------------------
sub yesno_ ($$$) {
	my ($a, $disp1, $disp2);
	$disp1 = $_[0]; $disp2 = $_[1];
	chomp($disp1);
	chomp($disp2);
	&disp($disp1, $disp2);
	if ($_[2]) {
		print STDERR " [$Lang::yes_upper/$Lang::no_lower] ";
	} else {
		print STDERR " [$Lang::yes_lower/$Lang::no_upper] ";
	}
	if ($DEFAULT) {
		if ($_[2]) {print STDERR $Lang::yes_upper,"\n"; return 1;}
		print STDERR $Lang::no_upper,"\n"; return 0;
	}
	$a = <STDIN>; chomp($a);
	if ($a eq $Lang::yes_upper || $a eq $Lang::yes_lower) {return 1;}
	if ($a eq  $Lang::no_upper || $a eq  $Lang::no_lower) {return 0;}
	return $_[2];
}

# ------------------------------------------------
# select 1,2,...,$_[2] and return the number
# or $_[3] for out value.
# ------------------------------------------------
sub select ($$$$) {
	my $a;
	&disp($_[0],$_[1]);
	print STDERR " (1..$_[2], [Enter]=$_[3]) ";
	if ($DEFAULT) {
		print STDERR $_[3],"\n";
		return $_[3];
	}
	$a = <STDIN>; chomp($a);
	if ($a >= 1 && $a <= $_[2]) {return $a;}
	$_[3];
}

# ------------------------------------------------
# Reply yes or no. Default is Yes.
# ------------------------------------------------
sub yesno ($$) {
	&yesno_ ($_[0], $_[1], 1);
}

# ------------------------------------------------
# Reply yes or no. Default is No.
# ------------------------------------------------
sub noyes ($$) {
	&yesno_ ($_[0], $_[1], 0);
}

# ------------------------------------------------
# Reply string and return.
# ------------------------------------------------
sub ask ($$) {
	my $a;
	&disp($_[0], $_[1]);
	$a = <STDIN>; chomp($a);
	return $a;
}