Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | /* |
2 | * ========== Copyright Header Begin ========================================== | |
3 | * | |
4 | * OpenSPARC T2 Processor File: vercheck.h | |
5 | * Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES. | |
7 | * | |
8 | * The above named program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public | |
10 | * License version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * The above named program is distributed in the hope that it will be | |
13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public | |
18 | * License along with this work; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. | |
20 | * | |
21 | * ========== Copyright Header End ============================================ | |
22 | */ | |
23 | #ifndef _vercheck_h | |
24 | #define _vercheck_h | |
25 | ||
26 | // | |
27 | // At the end of this file I provide copy-and-paste code. | |
28 | // | |
29 | // General code for doing vs compiletime vs runtime version checking. | |
30 | // To use this code: | |
31 | // | |
32 | // 1) In your module.c file | |
33 | // #include "vercheck.c" // Yes, include the .c not the .h (!) | |
34 | // // I know this is ugly, but its very convenient | |
35 | // | |
36 | // Since many modules will have this code | |
37 | // the following functions are all defined static. | |
38 | ||
39 | // 2) Define an array of triple doubles, like the example shown below. | |
40 | // You might call it xyz_vequivtab | |
41 | // | |
42 | // // Set of triples (AA,BB,CC), where | |
43 | // // Versions in the range [AA,BB) are compatiable. | |
44 | // // Versions with the same CC value are considered semi-compatible. | |
45 | // // Versions with different CC values are incompatible | |
46 | // // The last entry MUST have AA = BB = CC = -1 . | |
47 | // // Thus for this table: | |
48 | // // 1.00 vs. 1.03 => compatible. | |
49 | // // 1.00 vs. 1.04 => not compatible. | |
50 | // // 1.04 vs. 1.06 => semi-compatible. | |
51 | // // 1.07 vs. 1.09 => semi-compatible. | |
52 | // // 1.10 vs. 2.02 => compatible. | |
53 | // double rst_vequivtab [][3] = { | |
54 | // { 0.00, 1.00, 0 }, | |
55 | // { 1.00, 1.04, 1 }, | |
56 | // { 1.04, 1.06, 2 }, | |
57 | // { 1.06, 1.08, 2 }, | |
58 | // { 1.08, 1.10, 2 }, | |
59 | // { 1.10, 2.09, 3 }, | |
60 | // { -1, -1.0, -1 }, | |
61 | // }; | |
62 | // | |
63 | // 2) In your module.c code for XYZ, define | |
64 | // XYZ_version_check_fn (const char* ct_version); | |
65 | // I suggest trying: | |
66 | // | |
67 | // int xyz_version_check_fn (const char* ct_version) { | |
68 | // const char* rt_str = XYZ_VERSION_STR; // run time version | |
69 | // return generic_verCheck(ct_version, rt_str, xyz_vequivtab, "XYZ"); | |
70 | // } | |
71 | // | |
72 | ||
73 | enum { | |
74 | VERCHECK_MATCH = 0, | |
75 | VERCHECK_ERROR = 1, // unknown error comparing versions | |
76 | VERCHECK_SEMIMATCH = 2, | |
77 | VERCHECK_MISMATCH = 4 | |
78 | }; | |
79 | ||
80 | // get the index in equivTab | |
81 | static int verIndex (double ver, double equivTab [][3] ); | |
82 | ||
83 | // compare version strings, by converting them to doubles via atof() | |
84 | // Note that via atof(): "1.2" => 1.2 and "1.10" => 1.1 | |
85 | // compare compile version CT_STR with runtime version RT_STR using | |
86 | // version comparison table VT. | |
87 | // If problems, use modname XYZ in the error/warning messages. | |
88 | static int generic_verCheck ( | |
89 | const char* ct_str, const char* rt_str, double vt[][3], const char* modname | |
90 | ); | |
91 | ||
92 | // compare version CT_VER with runtime version RT_VER using | |
93 | // version comparison table VT. | |
94 | // If problems, use modname XYZ in the error/warning messages. | |
95 | static int ver_check_dbl ( | |
96 | double ct_ver, double rt_ver, double vt[][3], const char* modname | |
97 | ); | |
98 | ||
99 | /* ================================================================ | |
100 | * ================================================================ | |
101 | * Copy-and-paste code. Replace XYZ with your module name. | |
102 | * | |
103 | * Put the following in one of your .c files | |
104 | * ---------------- | |
105 | ||
106 | #include "vercheck.c" // Yes, include the .c not the .h (!) | |
107 | ||
108 | double xyz_vequivtab [][3] = { | |
109 | { 0.00, 1.00, 0 }, | |
110 | { 1.00, 1.04, 1 }, | |
111 | { 1.04, 1.06, 2 }, | |
112 | { 1.06, 1.08, 2 }, | |
113 | { 1.08, 1.10, 2 }, | |
114 | { 1.10, 2.09, 3 }, | |
115 | { -1, -1.0, -1 }, | |
116 | }; | |
117 | ||
118 | int xyz_version_check_fn (const char* ct_version) { | |
119 | const char* rt_str = XYZ_VERSION_STR; // run time version | |
120 | return generic_verCheck(ct_version, rt_str, xyz_vequivtab, "XYZ"); | |
121 | } | |
122 | ||
123 | * ================================================================ | |
124 | * Put the following in your .h file | |
125 | * ================================================================ | |
126 | ||
127 | #define XYZ_VERSION_STR "2.04" | |
128 | int xyz_version_check_fn (const char* compile_time_version); | |
129 | ||
130 | // Convenience macro for version checking | |
131 | #define XYZ_CHECK_VERSION() xyz_version_check_fn(XYZ_VERSION_STR) | |
132 | ||
133 | * End cut-and-paste | |
134 | * ================================================================ */ | |
135 | ||
136 | #endif /* _vercheck_h */ |