Closed Bug 222759 Opened 21 years ago Closed 21 years ago

Replace "Copyright ©" by "Copyright (C)" in JS test suite sources

Categories

(Core :: JavaScript Engine, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: igor, Assigned: pschwartau)

Details

Attachments

(1 file)

Currently JS testsuite contains in many place a line like:

 * Copyright © 1997, 1998 Netscape Communications Corporation,

which is all very fine except when I tried to run the test suite against Rhino
on a Linux box with UTF-8 as the default encoding. Since Rhino uses the standard
JAVA API to convert text input into Java chars, then the tests fail since
Latin-1 encoding of © as 0xA9 byte is not a valid UTF-8 and Java throws an
exception on it. 

It would be nice if the files would either be converted to use (C) and be pure
ASCII ot at least converted to UTF-8 so even if somebody will use a one-byte
encoding, the convertion would not fail but rather represent the symbol as 2
starnge looking characters.
I used the following perl script that was constructed from a bailer plate and
which can be replaced no doubts by one liner and which I run by:

find -name \*.java \*.js | xargs perl fix_copyright.pl



#!/usr/bin/perl

use strict;

my $backup_orig = 0;

sub read_handle
{
	my $handle = $_[0];
	my $chunk = $_[1] || 4096;
	my $offset = 0;
	my $data = "";
	for (;;) {
		my $n = sysread($handle,  $data,  $chunk, $offset);
		die "read failed: $!\n" if !defined($n);
		last if ($n == 0);
		if ($n == $chunk && $offset != 0) {
			$chunk *= 2;
		}
		$offset += $n;
	}
	return $data;
}

sub write_handle($$)
{
	my $handle = $_[0];
	my $data = $_[1] || 4096;
	my $L = length($data);
	my $offset = 0;
	while ($offset != $L) {
		my $n = syswrite($handle,  $data,  $L - $offset, $offset);
		die "write failed $!\n" if !defined($n);
		$offset += $n;
	}
	return $data;
}

sub read_file($)
{
	my $file_name = $_[0];
	use FileHandle;
	my $handle = new FileHandle($file_name, "r");
	die "Failed to open $file_name to read: $!\n" if !defined($handle); 
	my $data = read_handle($handle, -s $handle);
	undef $handle;
	return $data;
}

sub write_file($$)
{
	my $file_name = $_[0];
	my $data = $_[1];

	use FileHandle;
	my $handle = new FileHandle($file_name, "w");
	die "Failed to open $file_name to write: $!\n" if !defined($handle); 
	write_handle($handle, $data);
	undef $handle;
}


sub action($) 
{
	use FileHandle;
	my $file_name = $_[0];

	my $orig = read_file($file_name);
	
	my $data = $orig;
	$data =~ s/Copyright \xA9/Copyright \(C\)/g;
	
	if ($orig ne $data) {
		print("Processed: $file_name\n");
		if ($backup_orig) {
			write_file("$file_name.orig", $orig);
		}
		write_file($file_name, $data);
	}
}

foreach my $i (@ARGV) {
	action($i);
}
Assigning to self -
Assignee: rogerl → PhilSchwartau
Committed the patch; marking FIXED.

Igor: thank you for this patch; let me know if I missed any -
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Not that it really matters, but "(C)" is not a valid copyright symbol in the US.
However, the word "Copyright" is fine by itself.

http://www.copyright.gov/circs/circ1.html#noc
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: