X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=src%2FSDCCutil.c;h=134774f3c6ea2cdb84512db1f68e797be708c7a4;hb=df600563e3005614c5ab09aab6ba39218bbd3191;hp=381d53d04380cc3d679027aa9bfa1e9206037951;hpb=8518bef327102806ce21008f3f668320f956a8e3;p=fw%2Fsdcc diff --git a/src/SDCCutil.c b/src/SDCCutil.c index 381d53d0..134774f3 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -22,6 +22,8 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +#include + #ifdef _WIN32 #include #include @@ -32,6 +34,11 @@ #include "SDCCmacro.h" #include "SDCCutil.h" #include "newalloc.h" +#ifndef _WIN32 +#include "findme.h" +#endif + +#include "version.h" /** Given an array of name, value string pairs creates a new hash containing all of the pairs. @@ -143,18 +150,29 @@ getBinPath(const char *prel) char * getBinPath(const char *prel) { - char *p; - size_t len; static char path[PATH_MAX]; - - if ((p = strrchr(prel, DIR_SEPARATOR_CHAR)) == NULL) - return NULL; + const char *ret_path; + + if (NULL != (ret_path = findProgramPath(prel))) { + char *p; + size_t len; - len = min((sizeof path) - 1, p - prel); - strncpy(path, prel, len); - path[len] = '\0'; + if (NULL != (p = strrchr(ret_path, DIR_SEPARATOR_CHAR)) && + PATH_MAX > (len = p - ret_path)) { + memcpy(path, ret_path, len); + path[len] = '\0'; + free((void *)ret_path); + + return path; + } + else { + free((void *)ret_path); - return path; + return NULL; + } + } + else + return NULL; } #endif @@ -179,14 +197,22 @@ setMainValue (const char *pname, const char *pvalue) } void -buildCmdLine2 (char *pbuffer, const char *pcmd, size_t len) +buildCmdLine2 (char *pbuffer, size_t len, const char *pcmd, ...) { + va_list ap; char *poutcmd; + assert(pbuffer && pcmd); assert(_mainValues); - poutcmd = msprintf(_mainValues, pcmd); + va_start(ap, pcmd); + + poutcmd = mvsprintf(_mainValues, pcmd, ap); + + va_end(ap); + strncpyz(pbuffer, poutcmd, len); + Safe_free(poutcmd); } void @@ -264,6 +290,65 @@ char *strncatz(char *dest, const char *src, size_t n) } +/*-----------------------------------------------------------------*/ +/* getBuildNumber - return build number */ +/*-----------------------------------------------------------------*/ +const char *getBuildNumber(void) +{ + return (SDCC_BUILD_NUMBER); +} + +/*-----------------------------------------------------------------*/ +/* doubleFromFixed16x16 - convert a fixed16x16 to double */ +/*-----------------------------------------------------------------*/ +double doubleFromFixed16x16(TYPE_UDWORD value) +{ +#if 0 + /* This version is incorrect negative values. */ + double tmp=0, exp=2; + + tmp = (value & 0xffff0000) >> 16; + + while(value) { + value &= 0xffff; + if(value & 0x8000)tmp += 1/exp; + exp *= 2; + value <<= 1; + } + + return (tmp); +#else + return ((double)(value * 1.0) / (double)(1UL << 16)); +#endif +} + +TYPE_UDWORD fixed16x16FromDouble(double value) +{ +#if 0 + /* This version is incorrect negative values. */ + unsigned int tmp=0, pos=16; + TYPE_UDWORD res; + + tmp = floor( value ); + res = tmp << 16; + value -= tmp; + + tmp = 0; + while(pos--) { + value *= 2; + if(value >= 1.0)tmp |= (1 << pos); + value -= floor( value ); + } + + res |= tmp; + + return (res); +#else + return (TYPE_UDWORD)(value * (double)(1UL << 16)); +#endif +} + + #if defined(HAVE_VSNPRINTF) || defined(HAVE_VSPRINTF) size_t SDCCsnprintf(char *dst, size_t n, const char *fmt, ...) {