Code covered by the BSD License  

Highlights from
addcopyright

5.0

5.0 | 1 rating Rate this file 15 Downloads (last 30 days) File Size: 6.46 KB File ID: #16441

addcopyright

by

 

18 Sep 2007 (Updated )

add copyright information to an m-file or group of m-files.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

ADDCOPYRIGHT(TARGET,UPDATE,YEAR_OR_STRING,ORG,INFODISP)
ADDCOPYRIGHT adds or modifies the copyright info to an M-file or all M-files in a designated folder as well as subfolders.

This program was originally written by Raymond Norris and has been modified to add additional features summarized below.

The copyright line that is built up looks like the following:
% Copyright <YEAR> <ORGANIZATION>
The copyright info is placed directly above the Revision line(containing "$Revision") or after the first blank line that is not commented after the first commented section.

The program may be invoked in a variety of ways and options, please see the comment section for details. For example one common syntax is
  ADDCOPYRIGHT '' T
which calls up a dialog box to select the directory and updates the copyright info in the selected folder and all subfolders.

The following summarizes some of the differences between the original version and this version.
  1. Argument list order is changed, and number of arguments is reduced.
  2. Command line syntax is supported.
  3. If folder argument is empty, a dialog box selects the folder.
  4. Copyright info may be added to a single file.
  5. Copyright info is added either before $Revision keyword or after a blank line.
  6. Number of spaces between % and Copyright are now immaterial.
  7. The organization is checked and if different a new copyright line is added.
  8. A Def_organization constant is added.
  9. Will not attempt to add copyright info to contents.m or files that are not M-files.
  10. If copyright_string is blank and update is true then copyright line is deleted.
  11. The correct eol character for the OS is used to rewrite the files.
  12. More file checks are performed to prevent leaving temporary files.
  13. Summary output to command line has been changed to be easier to read.
  14. Added features to work with range of years as specified by year1-year2.

Please send me an email if you find this program useful, find bugs, or have recommendations.

Acknowledgements

Addcopyright inspired this file.

MATLAB release MATLAB 7.5 (R2007b)
Other requirements None
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
18 Apr 2013 Sky Sartorius

If I want to add/update copyright info for a file that's on the path but not in the current directory, a new version of the file (with copyright info) is created in the current directory. I changed line 180 to use uigetfile instead of uigetdir, which is more useful for me and helps with the aforementioned issue.

26 Dec 2011 Jiro Doke

Hi Mirko,
Very nice entry! I have a need to put copyrights to all of my MATLAB files, so this will be very handy. I noticed one problem. If I have a function with some help comments and then have MATLAB code immediately after the comments (without a blank line), it doesn't append the copyright information:

function out = testfunction(in)
%TESTFUNCTION Summary of this function goes here
% Detailed explanation goes here
out = rand(in);
end

I expected this to become

function out = testfunction(in)
%TESTFUNCTION Summary of this function goes here
% Detailed explanation goes here

% Copyright 2011 The MathWorks, Inc.
out = rand(in);
end

Also, I have a couple of suggestions. I would like the tool to keep the number of blank lines between the comments and code. For example, if I have code like this:

% This is a comment

a = rand;

then the output should be

% This is a comment

% Copyright 2011 The MathWorks, Inc.

a = rand;

Notice that there's a blank line between the copyright line and the code. This preserves the spacing that originally existed in the code.

Second, I think it the function should look for:
1. "cell divisions"
2. blank line
3. Revision line
4. code line

"cell divisions" are used in cell mode like this:

%% Title
% This is a title cell.
%% Section 1
% This is section one.

In the above case, I think the copyright info should go right after the first cell (Title cell):

%% Title
% This is a title cell.

% Copyright 2011 The MathWorks, Inc.
%% Section 1
% This is section one.

This is a great entry. Thanks for creating this (and improving on Raymond's entry)! I am planning on highlighting this for Pick of the Week.

23 Sep 2007 Mirko Hrovat

Good question, and I do not have a good answer. I am not sure what are the advantages of one method over the other. If the programs and revisons have the same name, then they may be easier to find. If they have different names, some versions may be missed because the keywords may be different. Take for example "keep" and "keep(2-5)" which are 5 versions plus there are others that have different names altogether. It is a little difficult to find them all. What might be best is for Mathworks File Exchange to support a version number along with the filename.

21 Sep 2007 Umberto .

I have not tried your submission, but your file has the same name of another submission (objectId=3949), which you acknowledge!! Why haven't you choose a different name?

Updates
02 Jun 2009

updated copyright and licensing information

21 Aug 2009

This update: reverses the meaning of the empty string, '', prior version used ' ' to mean empty, added a function to get a list of all m-files before modifying them, added an INFODISP argument, and modified EOL character to be based on the OS.

Contact us