1 // licenses.c written by Mitchell Foral. mitchell<att>caladbolg.net.
2 // See COPYING for license information.
10 // Holds licenses and their associated details and patterns.
11 License license_map[] = {
14 "http://www.opensource.org/licenses/afl-3.0.php",
15 "Academic Free License",
16 "\\bAcademic\\s*Free\\s*License\\b",
24 "http://www.opensource.org/licenses/apl1.0.php",
25 "Adaptive Public License",
26 "\\bAdaptive\\s*Public\\s*License\\b",
34 "http://www.affero.org/oagpl.html",
35 "GNU Affero General Public License",
36 "\\bGNU\\s+Affero\\s+General\\s+Public\\s+License\\b",
44 "http://www.opensource.org/licenses/apachepl.php",
45 "Apache Software License",
46 "(\\bApache\\s*Software\\s*License(?![\\s,]*2))|(\\bapache\\s*license(?![\\s,]*2))",
54 "http://www.opensource.org/licenses/apache2.0.php",
55 "Apache License, 2.0",
56 "\\bapache\\s+(software\\s+)?license,?\\s+(version\\s+)?2",
63 LIC_APPLE_OPEN_SOURCE,
64 "http://www.opensource.org/licenses/apsl-2.0.php",
65 "Apple Public Source License",
66 "\\bApple\\s*Public\\s*Source\\s*License\\b",
74 "http://www.opensource.org/licenses/artistic-license.php",
76 "\\bartistic\\s*license\\b",
83 LIC_ATTRIBUTION_ASSURANCE,
84 "http://www.opensource.org/licenses/attribution.php",
85 "Attribution Assurance Licenses",
86 "\\battribution\\s*assurance\\s*license(s)?\\b",
94 "http://www.boost.org/LICENSE_1_0.txt",
95 "Boost Software License - Version 1.0 - August 17th, 2003",
96 "\\bboost\\s*software\\s*license\\b",
104 "http://www.opensource.org/licenses/bsd-license.php",
106 "(\\bbsd\\s*license\\b)|(The Regents of the University of California)",
114 "http://www.cecill.info/licences/Licence_CeCILL_V2-en.html",
124 "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html",
134 "http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html",
143 LIC_COMPUTER_ASSOCIATES_TRUSTED,
144 "http://www.opensource.org/licenses/ca-tosl1.1.php",
145 "Computer Associates Trusted Open Source License 1.1",
146 "\\bcomputer\\s*associates\\s*trusted\\s*open\\s*source\\s*license\\b",
153 LIC_COMMON_DEVELOPMENT_AND_DISTRIBUTION,
154 "http://www.opensource.org/licenses/cddl1.php",
155 "Common Development and Distribution License",
156 "\\bcommon\\s*development\\s*and\\s*distribution\\s*license\\b",
164 "http://www.opensource.org/licenses/cpl1.0.php",
165 "Common Public License 1.0",
166 "\\bcommon\\s*public\\s*license\\b",
174 "http://www.opensource.org/licenses/cuaoffice.php",
175 "CUA Office Public License Version 1.0",
176 "\\bCUA\\s*office\\s*public\\s*license\\b",
184 "http://www.opensource.org/licenses/eudatagrid.php",
185 "EU DataGrid Software License",
186 "\\beu\\s*datagrid\\s*software\\s*license\\b",
194 "http://www.opensource.org/licenses/eclipse-1.0.php",
195 "Eclipse Public License",
196 "\\beclipse\\s*public\\s*license\\b",
204 "http://www.opensource.org/licenses/ecl1.php",
205 "Educational Community License",
206 "\\beducational\\s*community\\s*license\\b",
214 "http://www.opensource.org/licenses/eiffel.php",
215 "Eiffel Forum License",
216 "\\beiffel\\s*forum\\s*license(?![,V\\s]*2)\\b",
224 "http://www.opensource.org/licenses/ver2_eiffel.php",
225 "Eiffel Forum License V2.0",
226 "\\beiffel\\s*forum\\s*license [,V\\s]*2",
234 "http://www.opensource.org/licenses/entessa.php",
235 "Entessa Public License",
236 "\\bentessa\\s*public\\s*license\\b",
244 "http://www.opensource.org/licenses/fair.php",
246 "\\bfair\\s*license\\b",
254 "http://www.opensource.org/licenses/frameworx.php",
256 "\\bframeworx\\s*license\\b",
264 "http://www.gnu.org/licenses/gpl-3.0.html",
265 "GNU General Public License 3.0",
266 "\\b(GNU GENERAL PUBLIC LICENSE|GPL).{0,100}(Version)? 3.{0,50}later",
267 PCRE_CASELESS | PCRE_MULTILINE,
274 "http://www.gnu.org/licenses/gpl-3.0.html",
275 "GNU General Public License 3.0",
276 "GNU (GENERAL PUBLIC LICENSE|GPL).{0,100}(Version |v)3",
277 PCRE_CASELESS | PCRE_MULTILINE,
278 "((at your option) any later version)|(GENERAL PUBLIC LICENSE.*GENERAL PUBLIC LICENSE)",
284 "http://www.gnu.org/licenses/lgpl-3.0.html",
285 "GNU Lesser General Public License 3.0",
286 "((\\blgpl\\b)|(\\bgnu\\s*(library|lesser)\\s*(general\\s*)?(public\\s*)?license\\b)|(\\b(lesser|library)\\s*gpl\\b)).{0,10}(\\bas published by the free software foundation\\b)?.{0,10}(\\bversion\\b)?.{0,10}\\b3(\\.0)?\\b",
294 "http://www.opensource.org/licenses/gpl-license.php",
295 "GNU General Public License (GPL)",
296 "(\\bgpl\\b)|(\\bgplv2\\b)|(\\bgnu\\s*general\\s*public\\s*license\\b)|(\\bwww\\.gnu\\.org\\/licenses\\/gpl\\.txt\\b)",
304 "http://www.opensource.org/licenses/lgpl-license.php",
305 "GNU Library or \"Lesser\" GPL (LGPL)",
306 "(\\blgpl\\b)|(\\bgnu\\s*(library|lesser)\\s*(general\\s*)?(public\\s*)?license\\b)|(\\b(lesser|library)\\s*gpl\\b)",
314 "http://www.opensource.org/licenses/historical.php",
315 "Historical Permission Notice and Disclaimer",
316 "\\bhistorical\\s*permission\\s*notice\\s*and\\s*disclaimer\\b",
324 "http://i9os.googlecode.com/svn/trunk/Documentation/Licenses/i9_License",
326 "\\bi9\\s*\\s*license\\b",
334 "http://www.opensource.org/licenses/ibmpl.php",
335 "IBM Public License",
336 "\\bibm\\s*public\\s*license\\b",
343 LIC_INTEL_OPEN_SOURCE,
344 "http://www.opensource.org/licenses/intel-open-source-license.php",
345 "Intel Open Source License",
346 "\\bintel\\s*open\\s*source\\s*license\\b",
353 LIC_JABBER_OPEN_SOURCE,
354 "http://www.opensource.org/licenses/jabberpl.php",
355 "Jabber Open Source License",
356 "\\bjabber\\s*open\\s*source\\s*license\\b",
364 "http://www.opensource.org/licenses/plan9.php",
365 "Lucent Public License (Plan9)",
366 "\\blucent\\s*public\\s*license[\\s(]*plan9",
374 "http://www.opensource.org/licenses/lucent1.02.php",
375 "Lucent Public License Version 1.02",
376 "\\blucent\\s*public\\s*license\\s*(version)?\\s+1",
384 "http://www.opensource.org/licenses/mit-license.php",
386 "(\\bmit\\s*license\\b)|(\\bMIT\\/X11\\s*license\\b)",
394 "http://www.opensource.org/licenses/mitrepl.php",
395 "MITRE Collaborative Virtual Workspace License (CVW License)",
396 "\\bmitre\\s*collaborative\\s*virtual\\s*workspace\\s*license\\b",
404 "http://www.opensource.org/licenses/motosoto.php",
406 "\\bmotosoto\\s*license\\b",
414 "http://www.opensource.org/licenses/mozilla1.0.php",
415 "Mozilla Public License 1.0 (MPL)",
416 "\\bmozilla\\s*public\\s*license\\b",
423 LIC_MOZILLA_PUBLIC11,
424 "http://www.opensource.org/licenses/mozilla1.1.php",
425 "Mozilla Public License 1.1 (MPL)",
426 "\\bmozilla\\s*public\\s*license 1\\.1\\b",
434 "http://www.opensource.org/licenses/nasa1.3.php",
435 "NASA Open Source Agreement 1.3",
436 "\\bnasa\\s*open\\s*source\\s*agreement\\b",
444 "http://www.opensource.org/licenses/naumen.php",
445 "Naumen Public License",
446 "\\bnaumen\\s*public\\s*license\\b",
454 "http://www.opensource.org/licenses/nethack.php",
455 "Nethack General Public License",
456 "\\bnethack\\s*general\\s*public\\s*license\\b",
463 LIC_NOKIA_OPEN_SOURCE,
464 "http://www.opensource.org/licenses/nokia.php",
465 "Nokia Open Source License",
466 "\\bnokia\\s*open\\s*source\\s*license\\b",
474 "http://www.opensource.org/licenses/oclc2.php",
475 "OCLC Research Public License 2.0",
476 "\\boclc\\s*research\\s*public\\s*license\\b",
484 "http://www.opensource.org/licenses/opengroup.php",
485 "Open Group Test Suite License",
486 "\\bopen\\s*group\\s*test\\s*suite\\s*license\\b",
494 "http://www.opensource.org/licenses/osl-3.0.php",
495 "Open Software License",
496 "\\bopen\\s*software\\s*license\\b",
504 "http://www.opensource.org/licenses/php.php",
506 "\\bphp\\s*license\\b",
514 "http://www.opensource.org/licenses/pythonpl.php",
516 "\\bpython\\s*license\\b",
523 LIC_PYTHON_SOFTWARE_FOUNDATION,
524 "http://www.opensource.org/licenses/PythonSoftFoundation.php",
525 "Python Software Foundation License",
526 "\\bpython\\s*software\\s*foundation\\s*license\\b",
534 "http://www.opensource.org/licenses/qtpl.php",
535 "Qt Public License (QPL)",
536 "\\bqt\\s*public\\s*license\\b",
543 LIC_REALNETWORKS_PUBLIC_SOURCE,
544 "http://www.opensource.org/licenses/real.php",
545 "RealNetworks Public Source License V1.0",
546 "\\brealnetworks\\s*public\\s*source\\s*license\\b",
553 LIC_RECIPROCAL_PUBLIC,
554 "http://www.opensource.org/licenses/rpl.php",
555 "Reciprocal Public License",
556 "\\breciprocal\\s*public\\s*license\\b",
564 "http://www.opensource.org/licenses/ricohpl.php",
565 "Ricoh Source Code Public License",
566 "\\bricoh\\s*source\\s*code\\s*public\\s*license\\b",
574 "http://www.opensource.org/licenses/sleepycat.php",
576 "\\bsleepycat\\s*license\\b",
584 "http://www.sugarcrm.com/SPL",
585 "SugarCRM Public License 1.1.3",
586 "\\bsugar\\s*public\\s*license\\s*version\\s*1\\.1\\.3\\b",
593 LIC_SUN_INDUSTRY_STANDARDS,
594 "http://www.opensource.org/licenses/sisslpl.php",
595 "Sun Industry Standards Source License (SISSL)",
596 "\\bsun\\s*industry\\s*standards\\s*source\\s*license\\b",
604 "http://www.opensource.org/licenses/sunpublic.php",
605 "Sun Public License",
606 "\\bsun\\s*public\\s*license\\b",
613 LIC_SYBASE_OPEN_WATCOM,
614 "http://www.opensource.org/licenses/sybase.php",
615 "Sybase Open Watcom Public License 1.0",
616 "\\bsybase\\s*open\\s*watcom\\s*public\\s*license\\b",
624 "http://www.opensource.org/licenses/UoI-NCSA.php",
625 "University of Illinois/NCSA Open Source License",
626 "\\buniversity\\s*of\\s*illinois\\/ncsa\\s*open\\s*source\\s*license\\b",
634 "http://www.opensource.org/licenses/vovidapl.php",
635 "Vovida Software License v. 1.0",
636 "\\bvovida\\s*software\\s*license\\b",
644 "http://www.opensource.org/licenses/W3C.php",
646 "\\bw3c\\s*license\\b",
654 "http://www.opensource.org/licenses/wxwindows.php",
655 "wxWindows Library License",
656 "\\bwxwindows\\s*library\\s*license\\b",
664 "http://www.opensource.org/licenses/xnet.php",
666 "\\bx\\.net\\s*license\\b",
674 "http://www.opensource.org/licenses/zpl.php",
675 "Zope Public License",
676 "\\bzope\\s*public\\s*license\\b",
684 "http://www.opensource.org/licenses/zlib-license.php",
685 "zlib/libpng license",
686 "\\bzlib\\/libpng\\s*license\\b",
695 "Apache-ish License",
696 "(\\bapache-style.*license\\b)|(\\bapache-like.*license\\b)",
706 "Copyright\\s.{1,40}All rights reserved.{0,40}Redistribution and use in source and binary forms, with or without.{0,20}modification, are permitted provided that the following conditions.{0,20}\\sare met.{1,40}Redistributions of source code must retain the above copyright\\s.*notice, this list of conditions and the following disclaimer\\.\\s+.*Redistributions in binary form must reproduce the above.*copyright\\s+.{0,10}notice, this list of conditions and the following.*disclaimer in the\\s+.*documentation.*(The (name|names) of the (author|contributors) may not|Neither the name of the).*be used to endorse or promote\\s+.*products\\s+.*derived\\s+.*from this software without specific prior written\\s+.*permission.*HOWEVER\\s+.*CAUSED AND ON ANY.*THEORY OF LIABILITY, WHETHER IN CONTRACT",
708 "The Regents of the University of California",
715 "BSD-ish (2 clause) License",
716 "Copyright\\s.{1,60}All rights reserved.{1,40}Redistribution and use in source and binary forms, with or without.{0,20}modification, are permitted provided that the following conditions.{0,20}\\sare met.{0,20}\\s{1,20}.{0,20}Redistributions of source code must retain the above copyright\\s+.*notice, this list of conditions and the following disclaimer.\\s+.*Redistributions in binary form must reproduce the above copyright\\s+.*notice, this list of conditions and the following disclaimer in the\\s+.*documentation and\\/or other materials provided with the distribution\\.\\s+.*HOWEVER CAUSED AND ON ANY.*THEORY OF LIABILITY, WHETHER IN CONTRACT",
718 "(The Regents of the University of California)|(used to endorse or promote\\s+.*products\\s+.*prior\\s+.*written\\s+.*permission\\.)",
722 { NULL, NULL, NULL, NULL, 0, NULL, 0, NULL, NULL },
724 int license_map_length = 0; // will be set dynamically
726 /** Compiles the regular expressions defined in license_map. */
727 void compile_regexps() {
728 if (license_map_length == 0)
733 for (i = 0; i < license_map_length; i++) {
734 License *l = &license_map[i];
738 if (flags & PCRE_MULTILINE)
739 flags |= PCRE_DOTALL;
740 l->regexp = pcre_compile(l->re, flags, &err, &erroffset, NULL);
743 flags = l->exclude_re_flags;
744 if (flags & PCRE_MULTILINE)
745 flags |= PCRE_DOTALL;
746 l->exclude_regexp = pcre_compile(l->exclude_re, flags, &err, &erroffset,
753 * Overrides a less-specific license l with a more-specific one if the latter
756 #define OVERRIDE_LICENSE(l, with) { \
757 if (strcmp(license_map[i].name, l) == 0) { \
758 for (j = 0; j < license_map_length; j++) \
759 if (potential_licenses_s[j] > -1 && \
760 strcmp(license_map[j].name, with) == 0) { \
767 LicenseList *ohcount_detect_license(SourceFile *sourcefile) {
768 LicenseList *list = ohcount_license_list_new();
770 // Get the size of this map and compile the REs. Only runs once.
771 if (license_map_length == 0) {
772 while (license_map[license_map_length].name) license_map_length++;
776 ohcount_sourcefile_parse(sourcefile);
780 int ovector[30]; // recommended by PCRE
781 ParsedLanguageList *iter;
782 iter = ohcount_sourcefile_get_parsed_language_list(sourcefile)->head;
784 int potential_licenses_s[license_map_length];
785 int potential_licenses_e[license_map_length];
788 char buffer[ohcount_sourcefile_get_contents_size(sourcefile)];
789 p = iter->pl->comments;
791 char *eof = p + strlen(p);
793 // Strip leading whitespace and punctuation.
794 while (*p == ' ' || *p == '\t' || ispunct(*p)) p++;
795 // Copy line contents.
796 while (p < eof && *p != '\r' && *p != '\n') *q++ = *p++;
797 // Strip newline characters.
798 while (*p == '\r' || *p == '\n') p++;
799 // Add a trailing space.
804 for (j = 0; j < license_map_length; j++) {
805 potential_licenses_s[j] = -1;
806 potential_licenses_e[j] = -1;
807 if (pcre_exec(license_map[j].regexp, NULL, buffer, q - buffer, 0, 0,
809 int m0 = ovector[0], m1 = ovector[1];
810 // Exclude terms that may not exist in the license.
811 if (license_map[j].exclude_re &&
812 pcre_exec(license_map[j].exclude_regexp, NULL, buffer + m0, m1 - m0,
813 0, 0, ovector, 30) >= 0)
815 potential_licenses_s[j] = m0;
816 potential_licenses_e[j] = m1;
817 for (k = 0; k < j; k++) {
818 // If this matched license is completely contained inside another one,
819 // do not include it.
820 if ((potential_licenses_s[k] < m0 && potential_licenses_e[k] >= m1) ||
821 (potential_licenses_s[k] <= m0 && potential_licenses_e[k] > m1)) {
822 potential_licenses_s[j] = -1;
823 potential_licenses_e[j] = -1;
825 // If this matched license completely contains another one, do not
826 // include the latter.
827 if ((m0 < potential_licenses_s[k] && m1 >= potential_licenses_e[k]) ||
828 (m0 <= potential_licenses_s[k] && m1 > potential_licenses_e[k])) {
829 potential_licenses_s[k] = -1;
830 potential_licenses_e[k] = -1;
838 // Create the list of licenses from potential licenses.
839 for (i = 0; i < license_map_length; i++) {
840 if (potential_licenses_s[i] > -1) {
842 OVERRIDE_LICENSE(LIC_GPL, LIC_GPL3);
843 OVERRIDE_LICENSE(LIC_GPL, LIC_GPL3_OR_LATER);
844 OVERRIDE_LICENSE(LIC_GPL3, LIC_GPL3_OR_LATER);
845 OVERRIDE_LICENSE(LIC_BSD_2CLAUSE_ISH, LIC_BSD_ISH);
847 if (list->head == NULL) { // empty list
850 list->head->lic = &license_map[i];
853 LicenseList *item = ohcount_license_list_new();
854 item->lic = &license_map[i];
855 list->tail->next = item;
866 LicenseList *ohcount_license_list_new() {
867 LicenseList *list = malloc(sizeof(LicenseList));
875 void ohcount_license_list_free(LicenseList *list) {
877 LicenseList *iter = list->head;
879 LicenseList *next = iter->next;