From 9ddd071ec28050b3be572f25f3ae7d44e46e4039 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Tue, 22 Dec 2015 12:43:31 +0000 Subject: [PATCH] Stop copying the licence text into C source code. Now all the uses of the licence text or the short copyright notice get it from a new header "licence.h", which in turn is built by a Perl script licence.pl invoked by mkfiles.pl, using LICENCE itself as the source. Hence, I can completely remove a whole section from the list of licence locations in CHECKLST.txt :-) --- .gitignore | 1 + CHECKLST.txt | 19 +------------- licence.pl | 64 +++++++++++++++++++++++++++++++++++++++++++++ mkfiles.pl | 5 ++-- unix/gtkdlg.c | 35 +++---------------------- windows/version.rc2 | 3 ++- windows/windlg.c | 35 +++---------------------- windows/winpgen.c | 34 +++--------------------- windows/winpgnt.c | 34 +++--------------------- 9 files changed, 83 insertions(+), 147 deletions(-) create mode 100644 licence.pl diff --git a/.gitignore b/.gitignore index a0ec6001..df31c030 100644 --- a/.gitignore +++ b/.gitignore @@ -63,6 +63,7 @@ /missing /uxconfig.in /uxconfig.h +/licence.h /*.a /charset/sbcsdat.c /contrib/cygtermd/cygtermd.exe diff --git a/CHECKLST.txt b/CHECKLST.txt index 2cf15dc7..034f5708 100644 --- a/CHECKLST.txt +++ b/CHECKLST.txt @@ -4,7 +4,7 @@ Checklists for PuTTY administrative procedures Locations of the licence ------------------------ -The PuTTY copyright notice and licence are stored in quite a few +The PuTTY copyright notice and licence are stored in multiple places. At the start of a new year, the copyright year needs updating in all of them; and when someone sends a massive patch, their name needs adding in all of them too. @@ -13,23 +13,6 @@ The LICENCE file in the main source distribution: - putty/LICENCE -The various About and Licence boxes: - - - putty/windows/winpgnt.c - + the copyright date appears twice, once in the About box and - once in the Licence box. Don't forget to change both! - - putty/windows/winpgen.c - + the copyright date appears twice, once in the About box and - once in the Licence box. Don't forget to change both! - - putty/windows/windlg.c - + the copyright date appears twice, once in the About box and - once in the Licence box. Don't forget to change both! - - putty/windows/version.rc2 - + the copyright date appears once only. - - putty/unix/gtkdlg.c - + the copyright date appears twice, once in the About box and - once in the Licence box. Don't forget to change both! - The documentation (both the preamble blurb and the licence appendix): - putty/doc/blurb.but diff --git a/licence.pl b/licence.pl new file mode 100644 index 00000000..12d38a55 --- /dev/null +++ b/licence.pl @@ -0,0 +1,64 @@ +#!/usr/bin/env perl -w + +# This script generates licence.h (containing the PuTTY licence in the +# form of macros expanding to C string literals) from the LICENCE +# master file. + +use File::Basename; + +$infile = "LICENCE"; +$outfile = "licence.h"; +open my $in, $infile or die "$infile: open: $!\n"; +open my $out, ">", $outfile or die "$outfile: open: $!\n"; +select $out; + +print "/*\n"; +print " * $outfile - macro definitions for the PuTTY licence.\n"; +print " *\n"; +print " * Generated by @{[basename __FILE__]} from $infile.\n"; +print " * You should edit those files rather than editing this one.\n"; +print " */\n"; +print "\n"; + +my @lines = (); +while (<$in>) { + chomp; + push @lines, $_; +} +close $in; + +# Format into paragraphs. +my @paras = (); +my $para = undef; +for my $line (@lines) { + if ($line eq "") { + $para = undef; + } elsif (!defined $para) { + push @paras, $line; + $para = \$paras[$#paras]; + } else { + $$para .= " " . $line; + } +} + +print "#define LICENCE_TEXT(parsep) \\\n"; +for my $i (0..$#paras) { + my $lit = &stringlit($paras[$i]); + print " parsep \\\n" if $i > 0; + print " \"$lit\""; + print " \\" if $i < $#paras; + print "\n"; +} +print "\n"; + +die "bad format of first paragraph\n" + unless $paras[0] =~ m!copyright ([^\.]*)\.!i; + +printf "#define SHORT_COPYRIGHT_DETAILS \"%s\"\n", &stringlit($1); + +sub stringlit { + my ($lit) = @_; + $lit =~ s!\\!\\\\!g; + $lit =~ s!"!\\"!g; + return $lit; +} diff --git a/mkfiles.pl b/mkfiles.pl index 51fa6c18..0e748488 100755 --- a/mkfiles.pl +++ b/mkfiles.pl @@ -45,9 +45,10 @@ open IN, "Recipe" or do { }; # HACK: One of the source files in `charset' is auto-generated by -# sbcsgen.pl. We need to generate that _now_, before attempting -# dependency analysis. +# sbcsgen.pl, and licence.h is likewise generated by licence.pl. We +# need to generate those _now_, before attempting dependency analysis. eval 'chdir "charset"; require "sbcsgen.pl"; chdir ".."; select STDOUT;'; +eval 'require "licence.pl"; select STDOUT;'; @srcdirs = ("./"); diff --git a/unix/gtkdlg.c b/unix/gtkdlg.c index 5f79fc71..7058c6e1 100644 --- a/unix/gtkdlg.c +++ b/unix/gtkdlg.c @@ -33,6 +33,7 @@ #include "storage.h" #include "dialog.h" #include "tree234.h" +#include "licence.h" #if GTK_CHECK_VERSION(2,0,0) /* Decide which of GtkFileChooserDialog and GtkFileSelection to use */ @@ -3626,39 +3627,9 @@ static void licence_clicked(GtkButton *button, gpointer data) { char *title; - const char *licence = - "Copyright 1997-2015 Simon Tatham.\n\n" - - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " - "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " - "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\n\n" - - "Permission is hereby granted, free of charge, to any person " - "obtaining a copy of this software and associated documentation " - "files (the ""Software""), to deal in the Software without restriction, " - "including without limitation the rights to use, copy, modify, merge, " - "publish, distribute, sublicense, and/or sell copies of the Software, " - "and to permit persons to whom the Software is furnished to do so, " - "subject to the following conditions:\n\n" - - "The above copyright notice and this permission notice shall be " - "included in all copies or substantial portions of the Software.\n\n" - - "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " - "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " - "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " - "MERCHANTABILITY, FITNESS FOR A PARTICULAR " - "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " - "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " - "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " - "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " - "CONNECTION WITH THE SOFTWARE OR THE USE OR " - "OTHER DEALINGS IN THE SOFTWARE."; - title = dupcat(appname, " Licence", NULL); assert(aboutbox != NULL); - messagebox(aboutbox, title, licence, + messagebox(aboutbox, title, LICENCE_TEXT("\n\n"), string_width("LONGISH LINE OF TEXT SO THE LICENCE" " BOX ISN'T EXCESSIVELY TALL AND THIN"), TRUE, "OK", 'o', 1, 1, NULL); @@ -3702,7 +3673,7 @@ void about_box(void *window) char *label_text = dupprintf ("%s\n\n%s\n\n%s", appname, ver, - "Copyright 1997-2015 Simon Tatham. All rights reserved"); + "Copyright " SHORT_COPYRIGHT_DETAILS ". All rights reserved"); w = gtk_label_new(label_text); gtk_label_set_justify(GTK_LABEL(w), GTK_JUSTIFY_CENTER); #if GTK_CHECK_VERSION(2,0,0) diff --git a/windows/version.rc2 b/windows/version.rc2 index f3c002df..500f9002 100644 --- a/windows/version.rc2 +++ b/windows/version.rc2 @@ -7,6 +7,7 @@ */ #include "version.h" +#include "licence.h" /* * The actual VERSIONINFO resource. @@ -44,7 +45,7 @@ BEGIN VALUE "OriginalFilename", APPNAME VALUE "FileVersion", TEXTVER VALUE "ProductVersion", TEXTVER - VALUE "LegalCopyright", "Copyright \251 1997-2015 Simon Tatham." + VALUE "LegalCopyright", "Copyright \251 " SHORT_COPYRIGHT_DETAILS "." #if (!defined SNAPSHOT) && (!defined RELEASE) && (!defined PRERELEASE) /* Only if VS_FF_PRIVATEBUILD. */ VALUE "PrivateBuild", TEXTVER /* NBI */ diff --git a/windows/windlg.c b/windows/windlg.c index 826876e3..8248ce83 100644 --- a/windows/windlg.c +++ b/windows/windlg.c @@ -14,6 +14,7 @@ #include "win_res.h" #include "storage.h" #include "dialog.h" +#include "licence.h" #include #include @@ -170,37 +171,7 @@ static int CALLBACK LicenceProc(HWND hwnd, UINT msg, char *str = dupprintf("%s Licence", appname); SetWindowText(hwnd, str); sfree(str); - - SetDlgItemText(hwnd, IDA_TEXT, - "Copyright 1997-2015 Simon Tatham.\r\n\r\n" - - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " - "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " - "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\r\n\r\n" - - "Permission is hereby granted, free of charge, to any person " - "obtaining a copy of this software and associated documentation " - "files (the ""Software""), to deal in the Software without restriction, " - "including without limitation the rights to use, copy, modify, merge, " - "publish, distribute, sublicense, and/or sell copies of the Software, " - "and to permit persons to whom the Software is furnished to do so, " - "subject to the following conditions:\r\n\r\n" - - "The above copyright notice and this permission notice shall be " - "included in all copies or substantial portions of the Software.\r\n\r\n" - - "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " - "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " - "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " - "MERCHANTABILITY, FITNESS FOR A PARTICULAR " - "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " - "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " - "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " - "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " - "CONNECTION WITH THE SOFTWARE OR THE USE OR " - "OTHER DEALINGS IN THE SOFTWARE." -); + SetDlgItemText(hwnd, IDA_TEXT, LICENCE_TEXT("\r\n\r\n")); } return 1; case WM_COMMAND: @@ -232,7 +203,7 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg, char *text = dupprintf ("%s\r\n\r\n%s\r\n\r\n%s", appname, ver, - "\251 1997-2015 Simon Tatham. All rights reserved."); + "\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved."); SetDlgItemText(hwnd, IDA_TEXT, text); sfree(text); } diff --git a/windows/winpgen.c b/windows/winpgen.c index 612692b4..db55145c 100644 --- a/windows/winpgen.c +++ b/windows/winpgen.c @@ -11,6 +11,7 @@ #include "putty.h" #include "ssh.h" +#include "licence.h" #include @@ -253,36 +254,7 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg, rd.right - rd.left, rd.bottom - rd.top, TRUE); } - SetDlgItemText(hwnd, 1000, - "Copyright 1997-2015 Simon Tatham.\r\n\r\n" - - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " - "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " - "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\r\n\r\n" - - "Permission is hereby granted, free of charge, to any person " - "obtaining a copy of this software and associated documentation " - "files (the ""Software""), to deal in the Software without restriction, " - "including without limitation the rights to use, copy, modify, merge, " - "publish, distribute, sublicense, and/or sell copies of the Software, " - "and to permit persons to whom the Software is furnished to do so, " - "subject to the following conditions:\r\n\r\n" - - "The above copyright notice and this permission notice shall be " - "included in all copies or substantial portions of the Software.\r\n\r\n" - - "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " - "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " - "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " - "MERCHANTABILITY, FITNESS FOR A PARTICULAR " - "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " - "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " - "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " - "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " - "CONNECTION WITH THE SOFTWARE OR THE USE OR " - "OTHER DEALINGS IN THE SOFTWARE." -); + SetDlgItemText(hwnd, 1000, LICENCE_TEXT("\r\n\r\n")); return 1; case WM_COMMAND: switch (LOWORD(wParam)) { @@ -326,7 +298,7 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, char *text = dupprintf ("Pageant\r\n\r\n%s\r\n\r\n%s", ver, - "\251 1997-2015 Simon Tatham. All rights reserved."); + "\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved."); SetDlgItemText(hwnd, 1000, text); sfree(text); } diff --git a/windows/winpgnt.c b/windows/winpgnt.c index 04b58bb2..2109d1c6 100644 --- a/windows/winpgnt.c +++ b/windows/winpgnt.c @@ -16,6 +16,7 @@ #include "tree234.h" #include "winsecur.h" #include "pageant.h" +#include "licence.h" #include @@ -125,36 +126,7 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg, { switch (msg) { case WM_INITDIALOG: - SetDlgItemText(hwnd, 1000, - "Copyright 1997-2015 Simon Tatham.\r\n\r\n" - - "Portions copyright Robert de Bath, Joris van Rantwijk, Delian " - "Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas " - "Barry, Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, " - "Markus Kuhn, Colin Watson, Christopher Staite, and CORE SDI S.A.\r\n\r\n" - - "Permission is hereby granted, free of charge, to any person " - "obtaining a copy of this software and associated documentation " - "files (the ""Software""), to deal in the Software without restriction, " - "including without limitation the rights to use, copy, modify, merge, " - "publish, distribute, sublicense, and/or sell copies of the Software, " - "and to permit persons to whom the Software is furnished to do so, " - "subject to the following conditions:\r\n\r\n" - - "The above copyright notice and this permission notice shall be " - "included in all copies or substantial portions of the Software.\r\n\r\n" - - "THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT " - "WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, " - "INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF " - "MERCHANTABILITY, FITNESS FOR A PARTICULAR " - "PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE " - "COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES " - "OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, " - "TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN " - "CONNECTION WITH THE SOFTWARE OR THE USE OR " - "OTHER DEALINGS IN THE SOFTWARE." -); + SetDlgItemText(hwnd, 1000, LICENCE_TEXT("\r\n\r\n")); return 1; case WM_COMMAND: switch (LOWORD(wParam)) { @@ -183,7 +155,7 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg, char *text = dupprintf ("Pageant\r\n\r\n%s\r\n\r\n%s", ver, - "\251 1997-2015 Simon Tatham. All rights reserved."); + "\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved."); SetDlgItemText(hwnd, 1000, text); sfree(text); } -- 2.45.2