From f9fdfc22e8f6d46d3b6aae1e10fb05b1facf3ac4 Mon Sep 17 00:00:00 2001 From: Oskar Strengbohm Date: Sat, 27 Apr 2024 20:22:36 +0200 Subject: [PATCH] misc: pstring: Remove unneccesary or unused functions. --- lib/pstring.h | 32 ---------------- misc/pstring.cpp | 95 +----------------------------------------------- 2 files changed, 1 insertion(+), 126 deletions(-) diff --git a/lib/pstring.h b/lib/pstring.h index 994c4b8d..5f51d7aa 100644 --- a/lib/pstring.h +++ b/lib/pstring.h @@ -38,41 +38,9 @@ #ifndef _PSTRING_H_ #define _PSTRING_H_ -#include - -// Pvsprintf -// Similar to vsprintf/_vsnprintf, however handles the case of a buffer overflow. Arguments are the -// same as _vsnprintf. In the case of count, pass in the size of the buffer, in the case where there is -// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string. -int Pvsprintf(char *buffer, int count, const char *format, va_list argptr); - -// Psprintf -// Similar to sprintf/_snprintf, however handles the case of a buffer overflow. Arguments are the -// same as _snprintf. In the case of count, pass in the size of the buffer, in the case where there is -// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string. -int Psprintf(char *buffer, int count, const char *format, ...); - // CleanupStr // this function strips all leading and trailing spaces, keeping internal spaces. this goes // for tabs too. int CleanupStr(char *dest, const char *src, int destlen); -// tStringTok -// you may start a string tokenization object by calling the start function -// then call next, to get the following tokens. -// note that this class uses it's own copy of the string to ensure that strtok doesn't -// get corrupted. - -class tStringTok { - char *m_strbuf; - char *m_curptr; - -public: - tStringTok() : m_strbuf(0), m_curptr(0){}; - ~tStringTok(); - - char *start(const char *str, const char *tokens); - char *next(const char *tokens); -}; - #endif diff --git a/misc/pstring.cpp b/misc/pstring.cpp index 54ddcf1f..550f69be 100644 --- a/misc/pstring.cpp +++ b/misc/pstring.cpp @@ -39,38 +39,9 @@ */ #include -#include -#include -#include + #include "pstring.h" -#ifdef __LINUX__ -#include "lnxfix.h" -#endif - -// Pvsprintf -// Similar to vsprintf/_vsnprintf, however handles the case of a buffer overflow. Arguments are the -// same as _vsnprintf. In the case of count, pass in the size of the buffer, in the case where there is -// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string. -int Pvsprintf(char *buffer, int count, const char *format, va_list argptr) { - int ret = _vsnprintf(buffer, count - 1, format, argptr); - if (ret == -1) - buffer[count - 1] = '\0'; - return ret; -} - -// Psprintf -// Similar to sprintf/_snprintf, however handles the case of a buffer overflow. Arguments are the -// same as _snprintf. In the case of count, pass in the size of the buffer, in the case where there is -// a buffer overflow, a \0 will be tacked on as the last byte in the buffer, ensuring a valid string. -int Psprintf(char *buffer, int count, const char *format, ...) { - va_list ap; - va_start(ap, format); - int ret = Pvsprintf(buffer, count, format, ap); - va_end(ap); - return ret; -} - // CleanupStr // this function strips all leading and trailing spaces, keeping internal spaces. this goes // for tabs too. @@ -111,67 +82,3 @@ int CleanupStr(char *dest, const char *src, int destlen) { return 0; } - -// tStringTok -// you may start a string tokenization object by calling the start function -// then call next, to get the following tokens. -// note that this class uses it's own copy of the string to ensure that strtok doesn't -// get corrupted. - -tStringTok::~tStringTok() { - if (m_strbuf) - delete[] m_strbuf; -} - -char *tStringTok::start(const char *str, const char *tokens) { - // if we pass a null string, then reset this object - if (str == NULL) { - if (m_strbuf) - delete[] m_strbuf; - m_strbuf = NULL; - m_curptr = NULL; - return NULL; - } - - char *new_str = new char[strlen(str) + 1]; - - // copy string into new string buffer. AFTER THIS, delete the current string buffer, since the pointer - // passed in could point to the current m_strbuf ptr. - strcpy(new_str, str); - - if (m_strbuf) - delete[] m_strbuf; - m_strbuf = new_str; - m_curptr = m_strbuf; - - return this->next(tokens); -} - -char *tStringTok::next(const char *tokens) { - // create string by terminating m_strbuf when a token is it. - char *cur_str, *end_str; - int slen2, j; - - if (!m_curptr) - return m_curptr; - - slen2 = strlen(tokens); - cur_str = NULL; - - for (j = 0; j < slen2; j++) { - end_str = strchr(m_curptr, tokens[j]); - if (end_str) { - *end_str = 0; - cur_str = m_curptr; - m_curptr = end_str + 1; - return cur_str; - } - } - // at this point, we found no tokens, so m_curptr will point to the string we want to return. - // then we set m_curptr to NULL, telling any subsequent calls to next to return NULL. - - cur_str = m_curptr; - m_curptr = NULL; - - return cur_str; -}