mdisk: Remove color from "Already mounted" message
[sunny256-utils.git] / pgsafe
blob448311b53494aaa9e183700eb9d3e7e71191b2ea
1 #!/usr/bin/env perl
3 #=======================================================================
4 # $Id$
5 # [Description]
7 # Character set: UTF-8
8 # ©opyleft 2006– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License, see end of file for legal stuff.
10 #=======================================================================
12 use strict;
13 use warnings;
14 use Getopt::Long;
16 $| = 1;
18 our $Debug = 0;
20 our %Opt = (
21 'debug' => 0,
22 'help' => 0,
23 'simple' => 0,
24 'version' => 0,
27 our $progname = $0;
28 $progname =~ s#^.*/(.*?)$#$1#;
30 my $rcs_id = '$Id$';
31 my $id_date = $rcs_id;
32 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
34 Getopt::Long::Configure("bundling");
35 GetOptions(
36 "debug" => \$Opt{'debug'},
37 "help|h" => \$Opt{'help'},
38 "simple|s" => \$Opt{'simple'},
39 "version" => \$Opt{'version'},
40 ) || die("$progname: Option error. Use -h for help.\n");
42 $Opt{'debug'} && ($Debug = 1);
43 $Opt{'help'} && usage(0);
44 $Opt{'version'} && print_version();
46 while (<>) {
47 print(postgresql_copy_safe($_));
50 sub postgresql_copy_safe {
51 # {{{
52 my $Str = shift;
53 $Str =~ s/\\/\\\\/gs;
54 if (!$Opt{'simple'}) {
55 $Str =~ s/\n/\\n/gs;
56 $Str =~ s/\r/\\r/gs;
57 $Str =~ s/\t/\\t/gs;
59 return($Str);
60 # }}}
61 } # postgresql_copy_safe()
63 sub print_version {
64 # Print program version {{{
65 print("$rcs_id\n");
66 exit(0);
67 # }}}
68 } # print_version()
70 sub usage {
71 # Send the help message to stdout {{{
72 my $Retval = shift;
74 print(<<END);
76 $rcs_id
78 Usage: $progname [options] [file [files [...]]]
80 Options:
82 -h, --help
83 Show this help.
84 -s, --simple
85 Don’t convert \\n, \\r or \\t, only backslashes.
86 --version
87 Print version information.
88 --debug
89 Print debugging messages.
91 END
92 exit($Retval);
93 # }}}
94 } # usage()
96 sub D {
97 # Print a debugging message {{{
98 $Debug || return;
99 my @call_info = caller;
100 chomp(my $Txt = shift);
101 my $File = $call_info[1];
102 $File =~ s#\\#/#g;
103 $File =~ s#^.*/(.*?)$#$1#;
104 print(STDERR "$File:$call_info[2] $$ $Txt\n");
105 return("");
106 # }}}
107 } # D()
109 __END__
111 # Plain Old Documentation (POD) {{{
113 =pod
115 =head1 NAME
119 =head1 REVISION
121 $Id$
123 =head1 SYNOPSIS
125 [options] [file [files [...]]]
127 =head1 DESCRIPTION
131 =head1 OPTIONS
133 =over 4
135 =item B<-h>, B<--help>
137 Print a brief help summary.
139 =item B<--version>
141 Print version information.
143 =item B<--debug>
145 Print debugging messages.
147 =back
149 =head1 BUGS
153 =head1 AUTHOR
155 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
157 =head1 COPYRIGHT
159 Copyleft © Øyvind A. Holm &lt;sunny@sunbase.org&gt;
160 This is free software; see the file F<COPYING> for legalese stuff.
162 =head1 LICENCE
164 This program is free software; you can redistribute it and/or modify it
165 under the terms of the GNU General Public License as published by the
166 Free Software Foundation; either version 2 of the License, or (at your
167 option) any later version.
169 This program is distributed in the hope that it will be useful, but
170 WITHOUT ANY WARRANTY; without even the implied warranty of
171 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
172 See the GNU General Public License for more details.
174 You should have received a copy of the GNU General Public License along
175 with this program; if not, write to the Free Software Foundation, Inc.,
176 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
178 =head1 SEE ALSO
180 =cut
182 # }}}
184 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :
185 # End of file $Id$