Last active
March 18, 2019 12:14
-
-
Save yoursunny/6297f3c70f5441213184 to your computer and use it in GitHub Desktop.
NDN project license boilerplate update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://gist.github.com/yoursunny/6297f3c70f5441213184 | |
LICENSE_NFD='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
/* | |
* Copyright (c) 2014-2019, Regents of the University of California, | |
* Arizona Board of Regents, | |
* Colorado State University, | |
* University Pierre & Marie Curie, Sorbonne University, | |
* Washington University in St. Louis, | |
* Beijing Institute of Technology, | |
* The University of Memphis. | |
* | |
* This file is part of NFD (Named Data Networking Forwarding Daemon). | |
* See AUTHORS.md for complete list of NFD authors and contributors. | |
* | |
* NFD is free software: you can redistribute it and/or modify it under the terms | |
* of the GNU General Public License as published by the Free Software Foundation, | |
* either version 3 of the License, or (at your option) any later version. | |
* | |
* NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
* PURPOSE. See the GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License along with | |
* NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.''' | |
LICENSE_NDNCXX='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
/* | |
* Copyright (c) 2013-2019 Regents of the University of California. | |
* | |
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). | |
* | |
* ndn-cxx library is free software: you can redistribute it and/or modify it under the | |
* terms of the GNU Lesser General Public License as published by the Free Software | |
* Foundation, either version 3 of the License, or (at your option) any later version. | |
* | |
* ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY | |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | |
* | |
* You should have received copies of the GNU General Public License and GNU Lesser | |
* General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see | |
* <http://www.gnu.org/licenses/>. | |
* | |
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.''' | |
LICENSE_PSYNC='''/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
/* | |
* Copyright (c) 2014-2019, The University of Memphis | |
* | |
* This file is part of PSync. | |
* See AUTHORS.md for complete list of PSync authors and contributors. | |
* | |
* PSync is free software: you can redistribute it and/or modify it under the terms | |
* of the GNU Lesser General Public License as published by the Free Software Foundation, | |
* either version 3 of the License, or (at your option) any later version. | |
* | |
* PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | |
* PURPOSE. See the GNU Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public License along with | |
* PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.''' | |
LICENSE_END=' */' | |
if git remote show origin | grep 'NFD' > /dev/null; then | |
LICENSE=$LICENSE_NFD | |
elif git remote show origin | grep 'ndn-cxx' > /dev/null; then | |
LICENSE=$LICENSE_NDNCXX | |
elif git remote show origin | grep 'PSync' > /dev/null; then | |
LICENSE=$LICENSE_PSYNC | |
LICENSE_END=' **/' | |
else | |
echo 'unknown project' | |
exit 1 | |
fi | |
function update_license { | |
F=$1 | |
echo "$LICENSE" > $F.new | |
awk ' | |
BEGIN { | |
FS = "6175a610-db7d-4871-886e-e7931739d899" | |
foundLicense = "before" | |
nAuthors = 0 | |
nBlanksAfter = 0 | |
} | |
foundLicense == "before" && $1 !~ /^[\/ ]\*/ { | |
foundLicense = "just-after" | |
print " */" | |
} | |
foundLicense == "before" && /\* Copyright/ { | |
foundLicense = "in" | |
} | |
foundLicense == "in" && $1 ~ /^ \* [\\\@]author/ { | |
if (nAuthors++ == 0) { | |
print " *" | |
} | |
next | |
} | |
foundLicense == "in" && /^ \*[\*]?\// { | |
foundLicense = "just-after" | |
print "'"$LICENSE_END"'" | |
next | |
} | |
foundLicense == "just-after" && $1 == "" { | |
if (++nBlanksAfter == 1) { | |
} | |
} | |
foundLicense == "just-after" && $1 != "" { | |
foundLicense = "after" | |
} | |
foundLicense == "after" { | |
} | |
' $F >> $F.new | |
mv $F.new $F | |
} | |
BASE=$1 | |
if [[ -z $BASE ]]; then | |
BASE=HEAD | |
fi | |
for F in $(git diff $BASE --name-only | grep -E '(\.hpp|\.cpp)$'); do | |
if [[ -f $F ]]; then | |
echo $F | |
update_license $F | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment