Squash  0.7.0
license.c
1 /* Copyright (c) 2015 The Squash Authors
2  *
3  * Permission is hereby granted, free of charge, to any person
4  * obtaining a copy of this software and associated documentation
5  * files (the "Software"), to deal in the Software without
6  * restriction, including without limitation the rights to use, copy,
7  * modify, merge, publish, distribute, sublicense, and/or sell copies
8  * of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
18  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  *
23  * Authors:
24  * Evan Nemerson <evan@nemerson.com>
25  */
26 
27 #include "internal.h"
28 
29 #include <strings.h>
30 
36 const struct { SquashLicense value; const char* name; } licenses[] = {
37  { SQUASH_LICENSE_PUBLIC_DOMAIN, "Public Domain" },
38  { SQUASH_LICENSE_BSD2, "BSD2" },
39  { SQUASH_LICENSE_BSD3, "BSD3" },
40  { SQUASH_LICENSE_BSD4, "BSD4" },
41  { SQUASH_LICENSE_MIT, "MIT" },
42  { SQUASH_LICENSE_ZLIB, "zlib" },
43  { SQUASH_LICENSE_WTFPL, "WTFPL" },
44  { SQUASH_LICENSE_X11, "X11" },
45  { SQUASH_LICENSE_APACHE, "Apache 2.0" },
46  { SQUASH_LICENSE_APACHE2, "Apache" },
47  { SQUASH_LICENSE_CDDL, "CDDL" },
48  { SQUASH_LICENSE_MSPL, "MsPL" },
49  { SQUASH_LICENSE_MPL, "MPL" },
50  { SQUASH_LICENSE_LGPL2P1, "LGPLv2.1" },
51  { SQUASH_LICENSE_LGPL2P1_PLUS, "LGPLv2.1+" },
52  { SQUASH_LICENSE_LGPL3, "LGPLv3" },
53  { SQUASH_LICENSE_LGPL3_PLUS, "LGPLv3+" },
54  { SQUASH_LICENSE_GPL1, "GPLv1" },
55  { SQUASH_LICENSE_GPL1_PLUS, "GPLv1+" },
56  { SQUASH_LICENSE_GPL2, "GPLv2" },
57  { SQUASH_LICENSE_GPL2_PLUS, "GPLv2+" },
58  { SQUASH_LICENSE_GPL3, "GPLv3" },
59  { SQUASH_LICENSE_GPL3_PLUS, "GPLv3+" },
60  { SQUASH_LICENSE_PROPRIETARY, "Proprietary" },
61 
62  { SQUASH_LICENSE_UNKNOWN, NULL }
63 };
64 
65 const char*
66 squash_license_to_string (SquashLicense license) {
67  int i;
68  for (i = 0 ; licenses[i].value != SQUASH_LICENSE_UNKNOWN ; i++)
69  if (license == licenses[i].value)
70  return licenses[i].name;
71  return NULL;
72 }
73 
74 SquashLicense
75 squash_license_from_string (const char* license) {
76  int i;
77  for (i = 0 ; licenses[i].value != SQUASH_LICENSE_UNKNOWN ; i++)
78  if (strcasecmp (license, licenses[i].name) == 0)
79  return licenses[i].value;
80 
81  return SQUASH_LICENSE_UNKNOWN;
82 }