Re: The BSD license problem and a trivial solution

2010-05-01 Thread Bane
> 1) Add a handler for "--printLicenses" in extern(C) int main. This ensures 
> the text can always be printed.
> 1.1) Make sure to call checkLicenses beforehand!
> 2) Public import addLicense and registerFile in object.d
> 3, optional) Extend the module statement so that `module foo under GPLv2; ` 
> is interpreted as `module foo; static this() { registerFile(__FILE__, 
> "GPLv2"); }`
> 4, optional) Extend the above system to track what licenses can import what 
> others.

The horror! The horror!


Re: The BSD license problem and a trivial solution

2010-05-01 Thread Andrej Mitrovic
bearophile Wrote:

> FeepingCreature:
> 
> > Somebody on IRC mentioned that BSD requires including the license with 
> > binaries. So .. is there any reason this won't work?
> 
> Or support for the code licences management can be added to the D syntax ;-)
> 
> Bye,
> bearophile

from __future__ import lawsuits

Oops, I'm on the wrong forum. :)


Re: The BSD license problem and a trivial solution

2010-05-01 Thread FeepingCreature
On 01.05.2010 14:33, bearophile wrote:
> FeepingCreature:
> 
>> Somebody on IRC mentioned that BSD requires including the license with 
>> binaries. So .. is there any reason this won't work?
> 
> Or support for the code licences management can be added to the D syntax ;-)
> 
> Bye,
> bearophile

I did mention extending the module syntax to cover this in the proposal. :)


Re: The BSD license problem and a trivial solution

2010-05-01 Thread bearophile
FeepingCreature:

> Somebody on IRC mentioned that BSD requires including the license with 
> binaries. So .. is there any reason this won't work?

Or support for the code licences management can be added to the D syntax ;-)

Bye,
bearophile


The BSD license problem and a trivial solution

2010-05-01 Thread FeepingCreature
Somebody on IRC mentioned that BSD requires including the license with 
binaries. So .. is there any reason this won't work?

(Bewarned: code is D1 and not tested)

--std/licenses.d--
module std.licenses; // License handling on a per-file basis

import std.stdio, std.string;

string[string] license_texts;
string[] license_order;

// Licenses must be added in order from older to newer.
void addLicense(string name, string text) {
  license_texts[name] = text;
  license_order ~= name;
}

// If, for instance, this is called with "GPL", it will default to GPLv3; ie. 
the last version in license_order.
string getFullLicenseName(string prefix) {
  string license_name;
  foreach (name; license_order)
if (name[0 .. min($, prefix.length)].tolower() == prefix.tolower())
  license_name = name;
  return license_name;
}

string getLicense(string full_name) {
  return license_texts[full_name];
}

static this() {
  addLicense("GPLv2", import("LICENSE.GPLv2"));
  addLicense("GPLv3", import("LICENSE.GPLv3"));
  // etc
}

string[string] file_licenses; // Refer to licenses by name, not text!

void registerFile(string filename, string prefix) {
  file_licenses[filename] = prefix;
}

void checkLicenses() {
  foreach (key, value; file_licenses)
if (!getFullLicenseName(value))
  throw new Exception(format("License prefix ", value, " not found in ", 
license_order));
}

void printLicenses() {
  string[][string] files_per_license;
  // invert file_licenses
  foreach (key, value; file_licenses)
files_per_license[getFullLicenseName(value)] ~= key;
  // and print
  foreach (key, value; files_per_license) {
writefln("The following files are under ", key, ": ", value);
  writefln("The full text of these licenses follows. ");
  foreach (license; files_per_license.keys) {
writefln(" === ", license, " === ");
writefln(getLicense(license));
  }
}

Then.

1) Add a handler for "--printLicenses" in extern(C) int main. This ensures the 
text can always be printed.
1.1) Make sure to call checkLicenses beforehand!
2) Public import addLicense and registerFile in object.d
3, optional) Extend the module statement so that `module foo under GPLv2; ` is 
interpreted as `module foo; static this() { registerFile(__FILE__, "GPLv2"); }`
4, optional) Extend the above system to track what licenses can import what 
others.