[interchange-cvs] interchange - jon modified eg/te
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Wed Sep 4 00:22:01 2002
User: jon
Date: 2002-09-04 04:21:41 GMT
Modified: eg te
Log:
Revert indents to tabs instead of spaces.
Revision Changes Path
2.6 +112 -112 interchange/eg/te
rev 2.6, prev_rev 2.5
Index: te
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/eg/te,v
retrieving revision 2.5
retrieving revision 2.6
diff -u -u -r2.5 -r2.6
--- te 4 Sep 2002 04:19:05 -0000 2.5
+++ te 4 Sep 2002 04:21:40 -0000 2.6
@@ -84,7 +84,7 @@
=20
=3Dhead1 VERSION
=20
-$Id: te,v 2.5 2002/09/04 04:19:05 jon Exp $
+$Id: te,v 2.6 2002/09/04 04:21:40 jon Exp $
=20
=3Dhead1 CHANGELOG
=20
@@ -136,8 +136,8 @@
Edit tab-delimited file with easy field name delineation.
=20
Options:
- -i Ignores case on vim jump search.
- -s TEXT Jumps to first line where TEXT is. Only for vim.
+ -i Ignores case on vim jump search.
+ -s TEXT Jumps to first line where TEXT is. Only for vim.
-f Do not look for field names on first line of file.
-n Number rows in comments
=20
@@ -171,45 +171,45 @@
}
=20
for my $filename (@ARGV) {
- my (@fieldnames, $fieldcount, @fields);
- my ($name, $path, $tmpfile, $newfile, $digest1, $digest2);
- unless (-e $filename) {
- warn "Skipping '$filename': file does not exist\n";
- next;
- }
- unless (-f $filename) {
- warn "Skipping '$filename': not a regular file\n";
- next;
- }
- unless (open IN, "<$filename") {
- warn "Error 'opening' $filename for reading: $!\n";
- next;
- }
+ my (@fieldnames, $fieldcount, @fields);
+ my ($name, $path, $tmpfile, $newfile, $digest1, $digest2);
+ unless (-e $filename) {
+ warn "Skipping '$filename': file does not exist\n";
+ next;
+ }
+ unless (-f $filename) {
+ warn "Skipping '$filename': not a regular file\n";
+ next;
+ }
+ unless (open IN, "<$filename") {
+ warn "Error 'opening' $filename for reading: $!\n";
+ next;
+ }
=20
# get field names
- $_ =3D <IN>;
- s/\x0d?\x0a?$//;
- $fieldcount =3D tr/\t/\t/ + 1;
+ $_ =3D <IN>;
+ s/\x0d?\x0a?$//;
+ $fieldcount =3D tr/\t/\t/ + 1;
if ($opt_f) {
@fieldnames =3D map { "field$_" } (1 .. $fieldcount);
seek IN, 0, 0;
}
else {
die "Error in '$filename' header: null field name found\n" if /\t\t/;
- @fieldnames =3D split /\t/, $_, $fieldcount;
+ @fieldnames =3D split /\t/, $_, $fieldcount;
}
=20
- ($name, $path) =3D fileparse($filename);
+ ($name, $path) =3D fileparse($filename);
=20
- # I tried keeping the whole file in memory (for MD5's sake) instea=
d of
- # first writing to disk, but doing it this way turned out to be ab=
out 5
- # times faster and used 1/10th the memory on large files. (My benc=
hmark
+ # I tried keeping the whole file in memory (for MD5's sake) instead of
+ # first writing to disk, but doing it this way turned out to be about 5
+ # times faster and used 1/10th the memory on large files. (My benchmark
# was a 12 MB products.txt table for Interchange.)
=20
- $tmpfile =3D "$path.$name.tmp.$$";
- open OUT, ">$tmpfile" or die "Error opening '$tmpfile' for writing=
: $!\n";
- print STDERR "Prettifying $filename\n";
- print OUT <<EOF;
+ $tmpfile =3D "$path.$name.tmp.$$";
+ open OUT, ">$tmpfile" or die "Error opening '$tmpfile' for writing: $!\n";
+ print STDERR "Prettifying $filename\n";
+ print OUT <<EOF;
#
# This is a temporary file, automatically generated from the data file:
#
@@ -220,101 +220,101 @@
#
EOF
my $rowcount =3D 0;
- while (<IN>) {
- s/\x0d?\x0a?$//;
+ while (<IN>) {
+ s/\x0d?\x0a?$//;
++$rowcount, print OUT "# row $rowcount\n" if $opt_n;
- @fields =3D split /\t/, $_, $fieldcount;
- for (my $i =3D 0; $i < @fieldnames; $i++) {
- print OUT $fieldnames[$i], ":",
- defined $fields[$i] ? $fields[$i] : '', "\=
n";
- }
- print OUT "#\n";
- }
- if (@fields) {
- print OUT <<EOF;
+ @fields =3D split /\t/, $_, $fieldcount;
+ for (my $i =3D 0; $i < @fieldnames; $i++) {
+ print OUT $fieldnames[$i], ":",
+ defined $fields[$i] ? $fields[$i] : '', "\n";
+ }
+ print OUT "#\n";
+ }
+ if (@fields) {
+ print OUT <<EOF;
# You can uncomment the following lines to use as a template for inserting
# a new row into the table. Copy as many times as needed to add many rows.
#
EOF
- } else {
- print OUT <<EOF;
+ } else {
+ print OUT <<EOF;
# Your file was empty -- it had no data rows, only field definitions.
# You can copy the following empty row template as many times as needed
# to add new rows to the table.
#
EOF
- }
- print OUT join("\n", map { (@fields ? '#' : '') . $_ . ":" } @fiel=
dnames);
- print OUT "\n#\n";
- close IN;
- print OUT <<EOF;
+ }
+ print OUT join("\n", map { (@fields ? '#' : '') . $_ . ":" } @fieldnames);
+ print OUT "\n#\n";
+ close IN;
+ print OUT <<EOF;
# end of file
#
EOF
- close OUT or die "Error closing '$tmpfile' after writing: $!\n";
- open IN, "<$tmpfile" or die "Error opening '$tmpfile' for reading:=
$!\n";
- binmode IN;
- $digest1 =3D Digest::MD5->new->addfile(*IN)->digest;
- close IN;
- system (@ED, $tmpfile) =3D=3D 0
- or do {
- @ED =3D ('gvim', '-f', 'some quotes " "', "some sp=
ace");
- for(@ED) {
- next unless /\s/;
- s/"/\\"/g;
- $_ =3D qq["$_"];
- }
- my $editor =3D join " ", @ED;
- die "Error calling editor '$editor' with '$tmpfile=
': $!\n";
- };
- open IN, "<$tmpfile" or die "Error opening '$tmpfile' for reading:=
$!\n";
- binmode IN;
- $digest2 =3D Digest::MD5->new->addfile(*IN)->digest;
- if ($digest1 eq $digest2) {
- print STDERR "No changes made; '$filename' untouched\n";
- close IN;
- unlink $tmpfile;
- next;
- }
- print STDERR "Importing changes back into '$filename'\n";
- $newfile =3D "$path.$name.new.$$";
- open OUT, ">$newfile" or die "Error opening '$newfile' for writing=
: $!\n";
+ close OUT or die "Error closing '$tmpfile' after writing: $!\n";
+ open IN, "<$tmpfile" or die "Error opening '$tmpfile' for reading: $!\n";
+ binmode IN;
+ $digest1 =3D Digest::MD5->new->addfile(*IN)->digest;
+ close IN;
+ system (@ED, $tmpfile) =3D=3D 0
+ or do {
+ @ED =3D ('gvim', '-f', 'some quotes " "', "some space");
+ for(@ED) {
+ next unless /\s/;
+ s/"/\\"/g;
+ $_ =3D qq["$_"];
+ }
+ my $editor =3D join " ", @ED;
+ die "Error calling editor '$editor' with '$tmpfile': $!\n";
+ };
+ open IN, "<$tmpfile" or die "Error opening '$tmpfile' for reading: $!\n";
+ binmode IN;
+ $digest2 =3D Digest::MD5->new->addfile(*IN)->digest;
+ if ($digest1 eq $digest2) {
+ print STDERR "No changes made; '$filename' untouched\n";
+ close IN;
+ unlink $tmpfile;
+ next;
+ }
+ print STDERR "Importing changes back into '$filename'\n";
+ $newfile =3D "$path.$name.new.$$";
+ open OUT, ">$newfile" or die "Error opening '$newfile' for writing: $!\n";
print OUT join("\t", @fieldnames), "\n" unless $opt_f;
- my $tabcounter =3D 0;
- my $fieldpos =3D 0;
- my $done;
- seek IN, 0, 0 or die "Error rewinding file '$tmpfile': $!\n";
- @fields =3D ();
- while (<IN>) {
- $done =3D 1 if /^#\s*DONE/;
- next if /^\s*#/ || /^\s*$/;
- /^([^:]+):(.*)$/ or
- die "Error parsing line $. of '$tmpfile': line for=
mat unknown:\n$_";
- $1 eq $fieldnames[$fieldpos] or
- die "Error parsing line $. of '$tmpfile': expected=
field name '$fieldnames[$fieldpos]', found '$1'\n";
- $_ =3D $2;
- $tabcounter +=3D s/\t/ /g;
- push @fields, $_;
- if (++$fieldpos >=3D $fieldcount) {
- print OUT join("\t", @fields), "\n";
- @fields =3D ();
- $fieldpos =3D 0;
- }
- }
- print STDERR "$tabcounter tab character",
- $tabcounter =3D=3D 1 ? ' was' : 's were',
- " found in the data! Each tab was replaced with a space.\n"
- if $tabcounter;
- close OUT or die "Error closing '$filename.new' after writing: $!\=
n";
- close IN or die "Error closing '$tmpfile' after reading: $!\n";
- my ($mode, $uid, $gid) =3D (stat($filename))[2,4,5];
- chmod $mode, $newfile;
- chown $uid, $gid, $newfile if $> =3D=3D 0;
- rename $newfile, $filename or
- die "Error renaming '$newfile' to '$filename': $!\n";
- unlink $tmpfile;
- if ($done) {
- print STDERR "Found 'DONE' command; skipping rest of files=
\n";
- last;
- }
+ my $tabcounter =3D 0;
+ my $fieldpos =3D 0;
+ my $done;
+ seek IN, 0, 0 or die "Error rewinding file '$tmpfile': $!\n";
+ @fields =3D ();
+ while (<IN>) {
+ $done =3D 1 if /^#\s*DONE/;
+ next if /^\s*#/ || /^\s*$/;
+ /^([^:]+):(.*)$/ or
+ die "Error parsing line $. of '$tmpfile': line format unknown:\n$_";
+ $1 eq $fieldnames[$fieldpos] or
+ die "Error parsing line $. of '$tmpfile': expected field name '$fieldna=
mes[$fieldpos]', found '$1'\n";
+ $_ =3D $2;
+ $tabcounter +=3D s/\t/ /g;
+ push @fields, $_;
+ if (++$fieldpos >=3D $fieldcount) {
+ print OUT join("\t", @fields), "\n";
+ @fields =3D ();
+ $fieldpos =3D 0;
+ }
+ }
+ print STDERR "$tabcounter tab character",
+ $tabcounter =3D=3D 1 ? ' was' : 's were',
+ " found in the data! Each tab was replaced with a space.\n"
+ if $tabcounter;
+ close OUT or die "Error closing '$filename.new' after writing: $!\n";
+ close IN or die "Error closing '$tmpfile' after reading: $!\n";
+ my ($mode, $uid, $gid) =3D (stat($filename))[2,4,5];
+ chmod $mode, $newfile;
+ chown $uid, $gid, $newfile if $> =3D=3D 0;
+ rename $newfile, $filename or
+ die "Error renaming '$newfile' to '$filename': $!\n";
+ unlink $tmpfile;
+ if ($done) {
+ print STDERR "Found 'DONE' command; skipping rest of files.\n";
+ last;
+ }
}