[Fai-commit] r4009 - in trunk: bin man
fai-commit at lists.alioth.debian.org
fai-commit at lists.alioth.debian.org
Sun Sep 24 19:01:43 UTC 2006
Author: lange
Date: 2006-09-24 19:01:42 +0000 (Sun, 24 Sep 2006)
New Revision: 4009
Modified:
trunk/bin/ainsl
trunk/man/ainsl.1
Log:
add option -a, add our definition, change verbose messages
Modified: trunk/bin/ainsl
===================================================================
--- trunk/bin/ainsl 2006-09-22 16:06:00 UTC (rev 4008)
+++ trunk/bin/ainsl 2006-09-24 19:01:42 UTC (rev 4009)
@@ -27,9 +27,10 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#*********************************************************************
-my $version = "Version 0.2, 21-september-2006";
+my $version = "Version 1.0, 24-september-2006";
use Getopt::Std;
+our ($opt_a,$opt_h,$opt_D,$opt_n,$opt_s,$opt_v);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub usage {
@@ -41,10 +42,11 @@
Usage: ainsl [OPTION] FILE LINE [PATTERN]
+ -a Autocreate file if not existing.
-D Create debug output.
-h Show summary of options.
-n Print the actions, but do not execute them.
- -s Convert blanks in line to '\s+' regexp
+ -s Convert blanks in line to '\\s+' regexp
-v Create verbose output.
Report bugs to <lange\@informatik.uni-koeln.de>.
@@ -52,8 +54,17 @@
exit 0;
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-getopts('Dhsvn');
+sub autocreate {
+ -f $filename && return;
+ print "ainsl: create $filename\n" if $verbose;
+ $opt_n && return;
+ open (FILE,">$filename") || die "ainsl: can't create $filename $!";
+ close (FILE);
+}
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+getopts('aDhsvn');
+
$opt_h && usage;
$verbose = $opt_v || $ENV{verbose} || 0;
$debug = $opt_D || $ENV{debug} || 0;
@@ -66,6 +77,7 @@
print "FILE: $filename\nLINE: $line\nPATTERN $pattern\n" if $debug;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+$opt_a && autocreate;
$pattern = (defined $optpattern) ? $optpattern: $line;
# process pattern and line
@@ -82,14 +94,14 @@
$pattern =~s/\)/\\)/g;
}
-print "newpattern: $pattern XXX $pat\n" if $debug;
-print "newline: $line\n" if $debug;
+print "ainsl: newpattern: $pattern\n" if $debug;
+print "ainsl: newline: $line\n" if $debug;
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check if pattern already included in file
open (INFILE, "<$filename") or die "Can't open $filename $!";
while (<INFILE>) {
if (/$pattern/o) {
- print "Pattern found. Nothing to append.\n" if $debug;
+ print "aisnl: Pattern found. Nothing to append.\n" if $debug;
$found=1;
last;
}
@@ -98,8 +110,8 @@
exit 0 if $found; # nothing to append
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Append line to file
-print "Appending to $filename: $line\n" if $verbose;
+print "ainsl: appending to $filename: $line\n" if $verbose;
exit 0 if $opt_n;
-open (INFILE, ">>$filename") or die "Can't open $filename for writing. $!";
+open (INFILE, ">>$filename") or die "ainsl: can't open $filename for writing. $!";
print INFILE $line,"\n";
close(INFILE);
Modified: trunk/man/ainsl.1
===================================================================
--- trunk/man/ainsl.1 2006-09-22 16:06:00 UTC (rev 4008)
+++ trunk/man/ainsl.1 2006-09-24 19:01:42 UTC (rev 4009)
@@ -29,6 +29,9 @@
.SH OPTIONS
.TP
+.B \-a
+Autocreate file if it does not exist.
+.TP
.B \-D
Create debugging output.
.TP
More information about the Fai-commit
mailing list