Debian Codegraph @

src/common/proginfo.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2000 Rob Crittenden ([email protected])
3 * Copyright (C) 2001 Ross Combs ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #include "common/setup_before.h"
20 #include "common/proginfo.h"
21
22 #include <cstdio>
23 #include <cstdlib>
24 #include <cstring>
25 #include "common/setup_after.h"
26
27
28 namespace pvpgn
29 {
30
31 extern int verparts_to_vernum(unsigned short v1, unsigned short v2, unsigned short v3, unsigned short v4, unsigned long * vernum)
32 {
33 if (!vernum)
34 return -1;
35
36 *vernum = (((unsigned long)v4) << 24) |
37 (((unsigned long)v3) << 16) |
38 (((unsigned long)v2) << 8) |
39 (((unsigned long)v1));
40 return 0;
41 }
42
43
44 extern int verstr_to_vernum(char const * verstr, unsigned long * vernum)
45 {
46 unsigned long v1, v2, v3, v4;
47
48 if (!vernum)
49 return -1;
50
51 if (std::strchr(verstr, '.'))
52 {
53 int count;
54
55 count = std::sscanf(verstr, "%lu.%lu.%lu.%lu", &v4, &v3, &v2, &v1);
56 if (count < 4)
57 {
58 v1 = 0;
59 if (count < 3)
60 {
61 v2 = 0;
62 if (count < 2)
63 return -1; /* no data */
64 }
65 }
66 }
67 else
68 {
69 unsigned long temp;
70
71 temp = std::strtoul(verstr, NULL, 10);
72 v4 = (temp / 100);
73 v3 = (temp / 10) % 10;
74 v2 = (temp) % 10;
75 v1 = 0;
76 }
77
78 if (v1 > 255 || v2 > 255 || v3 > 255 || v4 > 255)
79 return -1;
80 *vernum = (v4 << 24) | (v3 << 16) | (v2 << 8) | (v1);
81 return 0;
82 }
83
84
85 extern char const * vernum_to_verstr(unsigned long vernum)
86 {
87 static char verstr[16];
88
89 std::sprintf(verstr, "%lu.%lu.%lu.%lu",
90 (vernum >> 24),
91 (vernum >> 16) & 0xff,
92 (vernum >> 8) & 0xff,
93 (vernum)& 0xff);
94 return verstr;
95 }
96
97 }