Skip to content

Commit

Permalink
import from dgcode mercurial: version 0.99.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tkittel committed Sep 4, 2016
1 parent 9875e3c commit 2d26b31
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.99.0
0.99.1
13 changes: 8 additions & 5 deletions src/mcpl/mcpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1549,7 +1549,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) {

int mcpl_str2int(const char* str, size_t len, int64_t* res)
{
//portable 64bit str2int with error checking.
//portable 64bit str2int with error checking (only INT64_MIN might not be
//possible to specify).
*res = 0;
if (!len)
len=strlen(str);
Expand All @@ -1566,11 +1567,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res)
if (str[i]<'0'||str[i]>'9') {
return 0;
}
int64_t prev = tmp;
tmp *= 10;
tmp += str[i] - '0';
if (prev>=tmp)
return 1;//overflow (hopefully it did not trigger a signal or FPE)
}
if (tmp > INT64_MAX)
return 0;
*res = sign * tmp;
return 1;
}
Expand Down Expand Up @@ -1721,15 +1723,16 @@ int mcpl_tool(int argc,char** argv) {
int32_t pdgcode_select = 0;
if (pdgcode_str) {
int64_t pdgcode64;
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<INT32_MIN || pdgcode64>INT32_MAX || !pdgcode64)
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64)
return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p.");
pdgcode_select = (int32_t)pdgcode64;
}

if (opt_num_skip>0)
mcpl_seek(fi,(uint64_t)opt_num_skip);

uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX;
//uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation
uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1;
uint64_t added = 0;
const mcpl_particle_t* particle;
while ( left-- && ( particle = mcpl_read(fi) ) ) {
Expand Down
4 changes: 2 additions & 2 deletions src/mcpl/mcpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#define MCPL_VERSION_MAJOR 0
#define MCPL_VERSION_MINOR 99
#define MCPL_VERSION_PATCH 0
#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_VERSION_PATCH 1
#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_FORMATVERSION 2 /* Format version of written files */

#ifdef __cplusplus
Expand Down
17 changes: 10 additions & 7 deletions src_fat/mcpl2ssw_app_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@

#define MCPL_VERSION_MAJOR 0
#define MCPL_VERSION_MINOR 99
#define MCPL_VERSION_PATCH 0
#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_VERSION_PATCH 1
#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_FORMATVERSION 2 /* Format version of written files */

#ifdef __cplusplus
Expand Down Expand Up @@ -4193,7 +4193,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) {

int mcpl_str2int(const char* str, size_t len, int64_t* res)
{
//portable 64bit str2int with error checking.
//portable 64bit str2int with error checking (only INT64_MIN might not be
//possible to specify).
*res = 0;
if (!len)
len=strlen(str);
Expand All @@ -4210,11 +4211,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res)
if (str[i]<'0'||str[i]>'9') {
return 0;
}
int64_t prev = tmp;
tmp *= 10;
tmp += str[i] - '0';
if (prev>=tmp)
return 1;//overflow (hopefully it did not trigger a signal or FPE)
}
if (tmp > INT64_MAX)
return 0;
*res = sign * tmp;
return 1;
}
Expand Down Expand Up @@ -4365,15 +4367,16 @@ int mcpl_tool(int argc,char** argv) {
int32_t pdgcode_select = 0;
if (pdgcode_str) {
int64_t pdgcode64;
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<INT32_MIN || pdgcode64>INT32_MAX || !pdgcode64)
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64)
return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p.");
pdgcode_select = (int32_t)pdgcode64;
}

if (opt_num_skip>0)
mcpl_seek(fi,(uint64_t)opt_num_skip);

uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX;
//uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation
uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1;
uint64_t added = 0;
const mcpl_particle_t* particle;
while ( left-- && ( particle = mcpl_read(fi) ) ) {
Expand Down
13 changes: 8 additions & 5 deletions src_fat/mcpl_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3916,7 +3916,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) {

int mcpl_str2int(const char* str, size_t len, int64_t* res)
{
//portable 64bit str2int with error checking.
//portable 64bit str2int with error checking (only INT64_MIN might not be
//possible to specify).
*res = 0;
if (!len)
len=strlen(str);
Expand All @@ -3933,11 +3934,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res)
if (str[i]<'0'||str[i]>'9') {
return 0;
}
int64_t prev = tmp;
tmp *= 10;
tmp += str[i] - '0';
if (prev>=tmp)
return 1;//overflow (hopefully it did not trigger a signal or FPE)
}
if (tmp > INT64_MAX)
return 0;
*res = sign * tmp;
return 1;
}
Expand Down Expand Up @@ -4088,15 +4090,16 @@ int mcpl_tool(int argc,char** argv) {
int32_t pdgcode_select = 0;
if (pdgcode_str) {
int64_t pdgcode64;
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<INT32_MIN || pdgcode64>INT32_MAX || !pdgcode64)
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64)
return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p.");
pdgcode_select = (int32_t)pdgcode64;
}

if (opt_num_skip>0)
mcpl_seek(fi,(uint64_t)opt_num_skip);

uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX;
//uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation
uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1;
uint64_t added = 0;
const mcpl_particle_t* particle;
while ( left-- && ( particle = mcpl_read(fi) ) ) {
Expand Down
17 changes: 10 additions & 7 deletions src_fat/mcpltool_app_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@

#define MCPL_VERSION_MAJOR 0
#define MCPL_VERSION_MINOR 99
#define MCPL_VERSION_PATCH 0
#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_VERSION_PATCH 1
#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_FORMATVERSION 2 /* Format version of written files */

#ifdef __cplusplus
Expand Down Expand Up @@ -4119,7 +4119,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) {

int mcpl_str2int(const char* str, size_t len, int64_t* res)
{
//portable 64bit str2int with error checking.
//portable 64bit str2int with error checking (only INT64_MIN might not be
//possible to specify).
*res = 0;
if (!len)
len=strlen(str);
Expand All @@ -4136,11 +4137,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res)
if (str[i]<'0'||str[i]>'9') {
return 0;
}
int64_t prev = tmp;
tmp *= 10;
tmp += str[i] - '0';
if (prev>=tmp)
return 1;//overflow (hopefully it did not trigger a signal or FPE)
}
if (tmp > INT64_MAX)
return 0;
*res = sign * tmp;
return 1;
}
Expand Down Expand Up @@ -4291,15 +4293,16 @@ int mcpl_tool(int argc,char** argv) {
int32_t pdgcode_select = 0;
if (pdgcode_str) {
int64_t pdgcode64;
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<INT32_MIN || pdgcode64>INT32_MAX || !pdgcode64)
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64)
return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p.");
pdgcode_select = (int32_t)pdgcode64;
}

if (opt_num_skip>0)
mcpl_seek(fi,(uint64_t)opt_num_skip);

uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX;
//uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation
uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1;
uint64_t added = 0;
const mcpl_particle_t* particle;
while ( left-- && ( particle = mcpl_read(fi) ) ) {
Expand Down
17 changes: 10 additions & 7 deletions src_fat/ssw2mcpl_app_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@

#define MCPL_VERSION_MAJOR 0
#define MCPL_VERSION_MINOR 99
#define MCPL_VERSION_PATCH 0
#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_VERSION_PATCH 1
#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */
#define MCPL_FORMATVERSION 2 /* Format version of written files */

#ifdef __cplusplus
Expand Down Expand Up @@ -4193,7 +4193,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) {

int mcpl_str2int(const char* str, size_t len, int64_t* res)
{
//portable 64bit str2int with error checking.
//portable 64bit str2int with error checking (only INT64_MIN might not be
//possible to specify).
*res = 0;
if (!len)
len=strlen(str);
Expand All @@ -4210,11 +4211,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res)
if (str[i]<'0'||str[i]>'9') {
return 0;
}
int64_t prev = tmp;
tmp *= 10;
tmp += str[i] - '0';
if (prev>=tmp)
return 1;//overflow (hopefully it did not trigger a signal or FPE)
}
if (tmp > INT64_MAX)
return 0;
*res = sign * tmp;
return 1;
}
Expand Down Expand Up @@ -4365,15 +4367,16 @@ int mcpl_tool(int argc,char** argv) {
int32_t pdgcode_select = 0;
if (pdgcode_str) {
int64_t pdgcode64;
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<INT32_MIN || pdgcode64>INT32_MAX || !pdgcode64)
if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64)
return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p.");
pdgcode_select = (int32_t)pdgcode64;
}

if (opt_num_skip>0)
mcpl_seek(fi,(uint64_t)opt_num_skip);

uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX;
//uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation
uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1;
uint64_t added = 0;
const mcpl_particle_t* particle;
while ( left-- && ( particle = mcpl_read(fi) ) ) {
Expand Down

0 comments on commit 2d26b31

Please sign in to comment.