Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zmap
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
zmap
Commits
c7b68fb6
Commit
c7b68fb6
authored
17 years ago
by
edgrif
Browse files
Options
Downloads
Patches
Plain Diff
add string to bool and string to float routines and tidy up existing routines.
parent
0ce7151e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/ZMap/zmapUtils.h
+5
-2
5 additions, 2 deletions
src/include/ZMap/zmapUtils.h
src/zmapUtils/zmapUtils.c
+111
-8
111 additions, 8 deletions
src/zmapUtils/zmapUtils.c
with
116 additions
and
10 deletions
src/include/ZMap/zmapUtils.h
+
5
−
2
View file @
c7b68fb6
...
...
@@ -24,9 +24,9 @@
*
* Description: Utility functions for ZMap.
* HISTORY:
* Last edited:
Oct 17 10:2
1 200
7
(edgrif)
* Last edited:
Feb 20 09:4
1 200
8
(edgrif)
* Created: Thu Feb 26 10:33:10 2004 (edgrif)
* CVS info: $Id: zmapUtils.h,v 1.3
3
200
7-10-17 15:48:0
0 edgrif Exp $
* CVS info: $Id: zmapUtils.h,v 1.3
4
200
8-02-20 14:16:3
0 edgrif Exp $
*-------------------------------------------------------------------
*/
#ifndef ZMAP_UTILS_H
...
...
@@ -111,6 +111,7 @@ typedef char* ZMapMagic ;
}
/*!
* Types of date formats that can be returned by zMapGetTimeString(). */
typedef
enum
...
...
@@ -163,9 +164,11 @@ gboolean zMapUtilsConfigDebug(char *debug_flag, gboolean *value) ;
char
*
zMapGetTimeString
(
ZMapTimeFormat
format
,
char
*
format_str_in
)
;
gboolean
zMapStr2Bool
(
char
*
str
,
gboolean
*
bool_out
)
;
gboolean
zMapStr2Int
(
char
*
str_in
,
int
*
int_out
)
;
gboolean
zMapInt2Str
(
int
int_in
,
char
**
str_out
)
;
gboolean
zMapStr2LongInt
(
char
*
str
,
long
int
*
long_int_out
)
;
gboolean
zMapStr2Float
(
char
*
str
,
float
*
float_out
)
;
gboolean
zMapStr2Double
(
char
*
str
,
double
*
double_out
)
;
#define zMapUtilsSwop(TYPE, FIRST, SECOND) \
...
...
This diff is collapsed.
Click to expand it.
src/zmapUtils/zmapUtils.c
+
111
−
8
View file @
c7b68fb6
...
...
@@ -26,9 +26,9 @@
*
* Exported functions: See ZMap/zmapUtils.h
* HISTORY:
* Last edited:
May 31 12:1
4 200
7
(edgrif)
* Last edited:
Feb 20 09:5
4 200
8
(edgrif)
* Created: Fri Mar 12 08:16:24 2004 (edgrif)
* CVS info: $Id: zmapUtils.c,v 1.2
5
200
7
-0
5-31
1
1
:1
5:46
edgrif Exp $
* CVS info: $Id: zmapUtils.c,v 1.2
6
200
8
-0
2-20
1
4
:1
6:30
edgrif Exp $
*-------------------------------------------------------------------
*/
...
...
@@ -37,6 +37,7 @@
#include
<string.h>
#include
<errno.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<zmapUtils_P.h>
...
...
@@ -262,6 +263,39 @@ char *zMapGetTimeString(ZMapTimeFormat format, char *format_str_in)
/* There follow a series of conversion routines. These are provided either
* because there are no existing ones or because the existing ones have
* arcane usage.
*
* All of them can just be used to test for validity without needing a
* return variable.
* */
gboolean
zMapStr2Bool
(
char
*
str
,
gboolean
*
bool_out
)
{
gboolean
result
=
FALSE
;
gboolean
retval
;
zMapAssert
(
str
&&
*
str
)
;
if
(
g_ascii_strcasecmp
(
"true"
,
str
)
==
0
)
{
retval
=
TRUE
;
result
=
TRUE
;
}
else
if
(
g_ascii_strcasecmp
(
"false"
,
str
)
==
0
)
{
retval
=
FALSE
;
result
=
TRUE
;
}
if
(
result
&&
bool_out
)
*
bool_out
=
retval
;
return
result
;
}
gboolean
zMapStr2Int
(
char
*
str
,
int
*
int_out
)
{
gboolean
result
=
FALSE
;
...
...
@@ -274,7 +308,8 @@ gboolean zMapStr2Int(char *str, int *int_out)
{
if
(
retval
<=
INT_MAX
||
retval
>=
INT_MIN
)
{
*
int_out
=
(
int
)
retval
;
if
(
int_out
)
*
int_out
=
(
int
)
retval
;
result
=
TRUE
;
}
}
...
...
@@ -294,7 +329,8 @@ gboolean zMapInt2Str(int int_in, char **str_out)
str
=
g_strdup_printf
(
"%d"
,
int_in
)
;
if
(
str
&&
*
str
)
{
*
str_out
=
str
;
if
(
str_out
)
*
str_out
=
str
;
result
=
TRUE
;
}
...
...
@@ -331,7 +367,8 @@ gboolean zMapStr2LongInt(char *str, long int *long_int_out)
else
{
result
=
TRUE
;
*
long_int_out
=
retval
;
if
(
long_int_out
)
*
long_int_out
=
retval
;
}
...
...
@@ -339,10 +376,55 @@ gboolean zMapStr2LongInt(char *str, long int *long_int_out)
}
gboolean
zMapStr2Float
(
char
*
str
,
float
*
float_out
)
{
gboolean
result
=
FALSE
;
char
*
end_ptr
=
NULL
;
float
ret_val
;
zMapAssert
(
str
&&
*
str
)
;
errno
=
0
;
ret_val
=
strtof
(
str
,
&
end_ptr
)
;
if
(
ret_val
==
0
&&
end_ptr
==
str
)
{
/* Standard says: no conversion performed */
result
=
FALSE
;
}
else
if
(
*
end_ptr
!=
'\0'
)
{
/* Standard says: string contains stuff that could not be converted. */
result
=
FALSE
;
}
else
if
(
errno
==
ERANGE
)
{
if
(
ret_val
==
0
)
{
/* Standard says: Underflow */
result
=
FALSE
;
}
else
{
/* Standard says: Overflow (+ or - HUGEVALF resturned. */
result
=
FALSE
;
}
}
else
{
result
=
TRUE
;
if
(
float_out
)
*
float_out
=
ret_val
;
}
return
result
;
}
gboolean
zMapStr2Double
(
char
*
str
,
double
*
double_out
)
{
gboolean
result
=
FALSE
;
char
*
end_ptr
;
char
*
end_ptr
=
NULL
;
double
ret_val
;
zMapAssert
(
str
&&
*
str
)
;
...
...
@@ -351,8 +433,29 @@ gboolean zMapStr2Double(char *str, double *double_out)
ret_val
=
strtod
(
str
,
&
end_ptr
)
;
if
(
*
end_ptr
!=
'\0'
||
errno
!=
0
)
result
=
FALSE
;
if
(
ret_val
==
0
&&
end_ptr
==
str
)
{
/* Standard says: no conversion performed */
result
=
FALSE
;
}
else
if
(
*
end_ptr
!=
'\0'
)
{
/* Standard says: string contains stuff that could not be converted. */
result
=
FALSE
;
}
else
if
(
errno
==
ERANGE
)
{
if
(
ret_val
==
0
)
{
/* Standard says: Underflow */
result
=
FALSE
;
}
else
{
/* Standard says: Overflow (+ or - HUGEVAL resturned. */
result
=
FALSE
;
}
}
else
{
result
=
TRUE
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment