Skip to content
Snippets Groups Projects
Commit 3f173ce9 authored by rswindell's avatar rswindell
Browse files

Create iniRead/Get/SetDuration() for working with durations or possibly

intervals (in seconds or fractions of a second) with values in .ini files.
parent ed86abfe
No related branches found
No related tags found
No related merge requests found
......@@ -570,6 +570,28 @@ char* DLLCALL iniSetBytes(str_list_t* list, const char* section, const char* key
return iniSetString(list, section, key, str, style);
}
char* DLLCALL iniSetDuration(str_list_t* list, const char* section, const char* key
,double value, ini_style_t* style)
{
char str[INI_MAX_VALUE_LEN];
if(fmod(value,365.0*24.0*60.0*60.0)==0)
SAFEPRINTF(str,"%gY",value/(365.0*24.0*60.0*60.0));
else if(fmod(value,7.0*24.0*60.0*60.0)==0)
SAFEPRINTF(str,"%gW",value/(7.0*24.0*60.0*60.0));
else if(fmod(value,24.0*60.0*60.0)==0)
SAFEPRINTF(str,"%gD",value/(24.0*60.0*60.0));
else if(fmod(value,60.0*60.0)==0)
SAFEPRINTF(str,"%gH",value/(60.0*60.0));
else if(fmod(value,60.0)==0)
SAFEPRINTF(str,"%gM",value/60.0);
else
SAFEPRINTF(str,"%gS",value);
return iniSetString(list, section, key, str, style);
}
#if !defined(NO_SOCKET_SUPPORT)
char* DLLCALL iniSetIpAddress(str_list_t* list, const char* section, const char* key, ulong value
,ini_style_t* style)
......@@ -1270,6 +1292,32 @@ int64_t DLLCALL iniGetBytes(str_list_t list, const char* section, const char* ke
return(parse_byte_count(vp,unit));
}
double DLLCALL iniReadDuration(FILE* fp, const char* section, const char* key, double deflt)
{
char* value;
char buf[INI_MAX_VALUE_LEN];
if((value=read_value(fp,section,key,buf))==NULL)
return(deflt);
if(*value==0) /* blank value */
return(deflt);
return(parse_duration(value));
}
double DLLCALL iniGetDuration(str_list_t list, const char* section, const char* key, double deflt)
{
char* vp=NULL;
get_value(list, section, key, NULL, &vp);
if(vp==NULL || *vp==0) /* blank value or missing key */
return(deflt);
return(parse_duration(vp));
}
#if !defined(NO_SOCKET_SUPPORT)
int DLLCALL iniGetSocketOptions(str_list_t list, const char* section, SOCKET sock
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2011 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -94,6 +94,8 @@ DLLEXPORT ulong DLLCALL iniReadLongInt(FILE*, const char* section, const char*
,ulong deflt);
DLLEXPORT int64_t DLLCALL iniReadBytes(FILE*, const char* section, const char* key
,ulong unit, int64_t deflt);
DLLEXPORT double DLLCALL iniReadDuration(FILE*, const char* section, const char* key
,double deflt);
DLLEXPORT double DLLCALL iniReadFloat(FILE*, const char* section, const char* key
,double deflt);
DLLEXPORT BOOL DLLCALL iniReadBool(FILE*, const char* section, const char* key
......@@ -146,9 +148,11 @@ DLLEXPORT ushort DLLCALL iniGetShortInt(str_list_t, const char* section, const
,ushort deflt);
DLLEXPORT ulong DLLCALL iniGetLongInt(str_list_t, const char* section, const char* key
,ulong deflt);
DLLEXPORT int64_t DLLCALL iniGetBytes(str_list_t, const char* section, const char* key
DLLEXPORT int64_t DLLCALL iniGetBytes(str_list_t, const char* section, const char* key
,ulong unit, int64_t deflt);
DLLEXPORT double DLLCALL iniGetFloat(str_list_t, const char* section, const char* key
DLLEXPORT double DLLCALL iniGetDuration(str_list_t, const char* section, const char* key
,double deflt);
DLLEXPORT double DLLCALL iniGetFloat(str_list_t, const char* section, const char* key
,double deflt);
DLLEXPORT BOOL DLLCALL iniGetBool(str_list_t, const char* section, const char* key
,BOOL deflt);
......@@ -196,6 +200,8 @@ DLLEXPORT char* DLLCALL iniSetLongInt(str_list_t*, const char* section, const c
,ini_style_t*);
DLLEXPORT char* DLLCALL iniSetBytes(str_list_t*, const char* section, const char* key, ulong unit, int64_t value
,ini_style_t*);
DLLEXPORT char* DLLCALL iniSetDuration(str_list_t*, const char* section, const char* key, double value
,ini_style_t*);
DLLEXPORT char* DLLCALL iniSetHexInt(str_list_t*, const char* section, const char* key, ulong value
,ini_style_t*);
DLLEXPORT char* DLLCALL iniSetFloat(str_list_t*, const char* section, const char* key, double value
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment