Browse Source

Moved several C linkage functions into Jupiter_ namespace.

release/0.19
JustinAJ 10 years ago
parent
commit
7bfc25e81b
  1. 64
      Jupiter/Functions.c
  2. 7
      Jupiter/IRC_Client.cpp
  3. 4
      Jupiter/Readable_String_Imp.h
  4. 15
      Jupiter/Timer.cpp
  5. 10
      Jupiter/Timer.h

64
Jupiter/Functions.c

@ -568,22 +568,22 @@ const unsigned char baseTable[] =
/** Single character functions */
bool isBase(unsigned char c, int base)
bool Jupiter_isBase(unsigned char c, int base)
{
return baseTable[c] < base;
}
bool isHex(unsigned char c)
bool Jupiter_isHex(unsigned char c)
{
return isBase(c, 16);
return Jupiter_isBase(c, 16);
}
bool isDecimal(unsigned char c)
bool Jupiter_isDecimal(unsigned char c)
{
return isBase(c, 10);
return Jupiter_isBase(c, 10);
}
int getBase(unsigned char c, int base)
int Jupiter_getBase(unsigned char c, int base)
{
c = baseTable[c];
if (c < base) return c;
@ -592,16 +592,16 @@ int getBase(unsigned char c, int base)
/** Unsafe string converters */
int strtoi(const char *str, int base)
int Jupiter_strtoi(const char *str, int base)
{
while (isspace(*str)) str++;
return strtoi_nospace(str, base);
return Jupiter_strtoi_nospace(str, base);
}
unsigned int strtoui(const char *str, int base)
unsigned int Jupiter_strtoui(const char *str, int base)
{
while (isspace(*str)) str++;
return strtoi_nospace(str, base);
return Jupiter_strtoi_nospace(str, base);
}
double Jupiter_strtod(const char *str)
@ -610,17 +610,17 @@ double Jupiter_strtod(const char *str)
return Jupiter_strtod_nospace(str);
}
int strtoi_nospace(const char *str, int base)
int Jupiter_strtoi_nospace(const char *str, int base)
{
if (*str != '-') return strtoui_nospace(str, base);
return -1 * strtoui_nospace(++str, base);
if (*str != '-') return Jupiter_strtoui_nospace(str, base);
return -1 * Jupiter_strtoui_nospace(++str, base);
}
unsigned int strtoui_nospace(const char *str, int base)
unsigned int Jupiter_strtoui_nospace(const char *str, int base)
{
unsigned int total = 0;
int tval;
if (*str == '-') return strtoi_nospace(str, base);
if (*str == '-') return Jupiter_strtoi_nospace(str, base);
if (*str == '+') str++;
@ -657,7 +657,7 @@ unsigned int strtoui_nospace(const char *str, int base)
}
}
while ((tval = getBase(*str, base)) != -1)
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
str++;
@ -676,7 +676,7 @@ double Jupiter_strtod_nospace(const char *str)
if (*str == '-') return -1 * Jupiter_strtod_nospace(++str);
if (*str == '+') str++;
while ((tval = getBase(*str, base)) != -1)
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
str++;
@ -686,14 +686,14 @@ double Jupiter_strtod_nospace(const char *str)
{
str++;
tval = base;
while ((decimal = getBase(*str, base)) != -1)
while ((decimal = Jupiter_getBase(*str, base)) != -1)
{
total = total + (decimal / tval);
str++;
tval = tval * base;
}
if (*str == 'e' || *str == 'E')
total = total * pow(base, strtoi_nospace(++str, 10));
total = total * pow(base, Jupiter_strtoi_nospace(++str, 10));
}
return total;
@ -701,24 +701,24 @@ double Jupiter_strtod_nospace(const char *str)
/** Safe string converters */
int strtoi_s(const char *str, size_t length, int base)
int Jupiter_strtoi_s(const char *str, size_t length, int base)
{
while (length != 0 && isspace(*str))
{
str++;
length--;
}
return strtoi_nospace_s(str, length, base);
return Jupiter_strtoi_nospace_s(str, length, base);
}
unsigned int strtoui_s(const char *str, size_t length, int base)
unsigned int Jupiter_strtoui_s(const char *str, size_t length, int base)
{
while (length != 0 && isspace(*str))
{
str++;
length--;
}
return strtoui_nospace_s(str, length, base);
return Jupiter_strtoui_nospace_s(str, length, base);
}
double Jupiter_strtod_s(const char *str, size_t length)
@ -731,19 +731,19 @@ double Jupiter_strtod_s(const char *str, size_t length)
return Jupiter_strtod_nospace_s(str, length);
}
signed int strtoi_nospace_s(const char *str, size_t length, int base)
signed int Jupiter_strtoi_nospace_s(const char *str, size_t length, int base)
{
if (length == 0) return 0;
if (*str != '-') return strtoui_nospace_s(str, length, base);
return -1 * strtoui_nospace_s(++str, --length, base);
if (*str != '-') return Jupiter_strtoui_nospace_s(str, length, base);
return -1 * Jupiter_strtoui_nospace_s(++str, --length, base);
}
unsigned int strtoui_nospace_s(const char *str, size_t length, int base)
unsigned int Jupiter_strtoui_nospace_s(const char *str, size_t length, int base)
{
unsigned int total = 0;
int tval;
if (length == 0) return total;
if (*str == '-') return strtoi_nospace(str, base);
if (*str == '-') return Jupiter_strtoi_nospace(str, base);
if (*str == '+')
{
@ -792,7 +792,7 @@ unsigned int strtoui_nospace_s(const char *str, size_t length, int base)
}
}
while ((tval = getBase(*str, base)) != -1)
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
if (--length == 0) return total;
@ -817,7 +817,7 @@ double Jupiter_strtod_nospace_s(const char *str, size_t length)
length--;
}
while ((tval = getBase(*str, base)) != -1)
while ((tval = Jupiter_getBase(*str, base)) != -1)
{
total = base * total + tval;
if (--length == 0) return total;
@ -829,7 +829,7 @@ double Jupiter_strtod_nospace_s(const char *str, size_t length)
str++;
length--;
tval = base;
while (length != 0 && (decimal = getBase(*str, base)) != -1)
while (length != 0 && (decimal = Jupiter_getBase(*str, base)) != -1)
{
total = total + (decimal / tval);
if (--length == 0) return total;
@ -837,7 +837,7 @@ double Jupiter_strtod_nospace_s(const char *str, size_t length)
tval = tval * base;
}
if (*str == 'e' || *str == 'E')
total = total * pow(base, strtoi_nospace_s(++str, --length, 10));
total = total * pow(base, Jupiter_strtoi_nospace_s(++str, --length, 10));
}
return total;

7
Jupiter/IRC_Client.cpp

@ -774,13 +774,13 @@ int Jupiter::IRC::Client::primaryHandler()
Jupiter::IRC::Client::data_->sock->send(Jupiter::StringS::Format("NICK %.*s" ENDL, Jupiter::IRC::Client::data_->nickname.size(), Jupiter::IRC::Client::data_->nickname.ptr()));
}
// Note: Add a series of contains() functions to String_Type.
else //if (stristr(Jupiter::IRC::Client::data_->nickname.c_str(), configNick.c_str()) == Jupiter::IRC::Client::data_->nickname.c_str()) // We're already adding numbers.
else
{
if (completelyBadNick == false) // If this nick is invalid, adding numbers won't help.
{
if (Jupiter::IRC::Client::data_->nickname.size() > configNick.size())
{
int n = strtoi_nospace_s(Jupiter::IRC::Client::data_->nickname.ptr() + configNick.size(), Jupiter::IRC::Client::data_->nickname.size() - configNick.size(), 10);
int n = Jupiter_strtoi_nospace_s(Jupiter::IRC::Client::data_->nickname.ptr() + configNick.size(), Jupiter::IRC::Client::data_->nickname.size() - configNick.size(), 10);
Jupiter::IRC::Client::data_->nickname.format("%.*s%d", configNick.size(), configNick.ptr(), n);
}
else
@ -1283,7 +1283,8 @@ void Jupiter::IRC::Client::disconnect(bool stayDead)
bool ssl = Jupiter::IRC::Client::readConfigBool(STRING_LITERAL_AS_REFERENCE("SSL"));
if (ssl != Jupiter::IRC::Client::data_->ssl)
{
if (Jupiter::IRC::Client::data_->ssl = ssl)
Jupiter::IRC::Client::data_->ssl = ssl;
if (Jupiter::IRC::Client::data_->ssl)
{
Jupiter::SecureTCPSocket *t = new Jupiter::SecureTCPSocket(std::move(*Jupiter::IRC::Client::data_->sock));
if (Jupiter::IRC::Client::data_->SSLCertificate.size() != 0)

4
Jupiter/Readable_String_Imp.h

@ -830,7 +830,7 @@ template<typename T> bool Jupiter::Readable_String<T>::asBool() const
template<> int inline Jupiter::Readable_String<char>::asInt(int base) const
{
return strtoi_s(this->ptr(), this->size(), base);
return Jupiter_strtoi_s(this->ptr(), this->size(), base);
}
template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
@ -840,7 +840,7 @@ template<typename T> int Jupiter::Readable_String<T>::asInt(int base) const
template<> unsigned int inline Jupiter::Readable_String<char>::asUnsignedInt(int base) const
{
return strtoui_s(this->ptr(), this->size(), base);
return Jupiter_strtoui_s(this->ptr(), this->size(), base);
}
template<typename T> unsigned int Jupiter::Readable_String<T>::asUnsignedInt(int base) const

15
Jupiter/Timer.cpp

@ -19,7 +19,7 @@ struct TimerKiller
TimerKiller::~TimerKiller()
{
killTimers();
Jupiter_killTimers();
}
struct Jupiter::Timer::Data
@ -104,22 +104,22 @@ bool Jupiter::Timer::kill()
return false;
}
extern "C" void addTimer(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int, void *), void *parameters)
extern "C" void Jupiter_addTimer(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int, void *), void *parameters)
{
new Jupiter::Timer(iterations, timeDelay, function, parameters, immediate);
}
extern "C" void addTimerNoParams(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int))
extern "C" void Jupiter_addTimerNoParams(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int))
{
new Jupiter::Timer(iterations, timeDelay, function, immediate);
}
extern "C" unsigned int totalTimers()
extern "C" unsigned int Jupiter_totalTimers()
{
return timers.size();
}
extern "C" unsigned int checkTimers()
extern "C" unsigned int Jupiter_checkTimers()
{
unsigned int r = 0;
Jupiter::Timer *t;
@ -140,9 +140,10 @@ extern "C" unsigned int checkTimers()
return r;
}
extern "C" unsigned int killTimers()
extern "C" unsigned int Jupiter_killTimers()
{
unsigned int r = timers.size();
while (timers.size() != 0) delete timers.remove(unsigned int(0));
while (timers.size() != 0)
delete timers.remove(0U);
return r;
}

10
Jupiter/Timer.h

@ -151,7 +151,7 @@ extern "C"
* @param function Function for the timer to call.
* @param parameters Parameters to pass to the function.
*/
JUPITER_API void addTimer(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int, void *), void *parameters);
JUPITER_API void Jupiter_addTimer(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int, void *), void *parameters);
/**
* @brief Creates a timer.
@ -161,28 +161,28 @@ JUPITER_API void addTimer(unsigned int iterations, time_t timeDelay, bool immedi
* @param immediate True if the function should be execute on the next check.
* @param function Function for the timer to call.
*/
JUPITER_API void addTimerNoParams(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int));
JUPITER_API void Jupiter_addTimerNoParams(unsigned int iterations, time_t timeDelay, bool immediate, void(*function)(unsigned int));
/**
* @brief Fetches the number of active timers.
*
* @return Total number of timers active.
*/
JUPITER_API unsigned int totalTimers();
JUPITER_API unsigned int Jupiter_totalTimers();
/**
* @brief Calls think() for every timer, and removes them if neccessary.
*
* @return Total number of timers removed.
*/
JUPITER_API unsigned int checkTimers();
JUPITER_API unsigned int Jupiter_checkTimers();
/**
* @brief Immediately destroys all timers.
*
* @return Total number of timers removed.
*/
JUPITER_API unsigned int killTimers();
JUPITER_API unsigned int Jupiter_killTimers();
#if defined __cplusplus
}

Loading…
Cancel
Save