diff --git a/lib/include/bofstd/bofstd.h b/lib/include/bofstd/bofstd.h index f2b77e7..d696625 100644 --- a/lib/include/bofstd/bofstd.h +++ b/lib/include/bofstd/bofstd.h @@ -424,13 +424,32 @@ const uintptr_t BOF_INVALID_HANDLE_VALUE = ((uintptr_t)-1); ((((v) % (a)) != 0) ? ((a) - ((v) % (a))) : a) // If aligned add a zone of a byte before the next one #define BOF_ALIGN_ADD_NB_PADDING_BYTE(v, a) \ ((((v) % (a)) != 0) ? ((a) - ((v) % (a))) : 0) // If aligned add a zone of a byte before the next one -#define BOF_ALIGN_VALUE_ON(v, a) (((v) + (a)-1) & ~((a)-1)) -#define BOF_SNPRINTF_NULL_CLIPPED(pBuffer, MaxBufferSize, Format, ...) \ +#define BOF_ALIGN_VALUE_ON(v, a) (((v) + (a) - 1) & ~((a) - 1)) +// #define BOF_SNPRINTF_NULL_CLIPPED(pBuffer, MaxBufferSize, Format, ...) +// { +// snprintf(pBuffer, MaxBufferSize, Format, ##__VA_ARGS__); +// pBuffer[MaxBufferSize - 1] = 0; +// } +// Use Bof_StrNCpy #define BOF_STRNCPY_NULL_CLIPPED(pDst, pSrc, Count) {strncpy(pDst, pSrc, Count);pDst[Count-1]=0;} +#define BOF_SPRINTF(Txt, Format, ...) \ { \ - snprintf(pBuffer, MaxBufferSize, Format, ##__VA_ARGS__); \ - pBuffer[MaxBufferSize - 1] = 0; \ + if (Format) \ + { \ + std::va_list Arg; \ + int SizeBuffer_i, Size_i; \ + va_start(Arg, Format); \ + SizeBuffer_i = vsnprintf(nullptr, 0, Format, Arg); \ + va_end(Arg); \ + if (SizeBuffer_i >= 0) \ + { \ + Txt.resize(SizeBuffer_i + 4); \ + va_start(Arg, Format); \ + Size_i = vsnprintf(Txt.data(), SizeBuffer_i + 1, Format, Arg); \ + va_end(Arg); \ + BOF_ASSERT(Size_i == SizeBuffer_i); \ + } \ + } \ } -// Use Bof_StrNCpy #define BOF_STRNCPY_NULL_CLIPPED(pDst, pSrc, Count) {strncpy(pDst, pSrc, Count);pDst[Count-1]=0;} #define BOF_SET_ADDRESS_MAGIC_NUMBER(p, mn) \ { \ (p)->MagicNumber_U64 = (reinterpret_cast(p) ^ static_cast(mn)); \ @@ -527,7 +546,7 @@ extern uint32_t GL_BofDbgPrintfStartTime_U32; { \ unsigned int i; \ bool StsBit; \ - U32 FoundBitNum = (U32)-1; \ + U32 FoundBitNum = (U32) - 1; \ uint8_t MaskOfFirstByte, Val; \ MaskOfFirstByte = 0xFF ^ ((1 << (BitNum & 0x07)) - 1); \ if (SetOrReset) \ diff --git a/lib/src/bofconio.cpp b/lib/src/bofconio.cpp index 68eee60..4ecddce 100644 --- a/lib/src/bofconio.cpp +++ b/lib/src/bofconio.cpp @@ -1115,44 +1115,25 @@ BOFERR BofConio::S_Clear(CONIO_CLEAR _ClearType_E) BOFERR BofConio::S_PrintLine(const char *_pFormat_c, ...) { BOFERR Rts_E = BOF_ERR_NO_ERROR; - char pText_c[0x1000]; - va_list Arg; - - va_start(Arg, _pFormat_c); - vsnprintf(pText_c, sizeof(pText_c), _pFormat_c, Arg); - va_end(Arg); - printf("%s%s%sm%s", S_mpTextAttribute_c, S_mpTextForeAttribute_c, S_mpTextBackAttribute_c, pText_c); - // printf("%s%sm%s", S_mpTextAttribute_c, S_mpTextForeAttribute_c, pText_c); - // printf("%s", pText_c); - /* - printf("\033[0;95;40m%s", pText_c); - printf("\033[0;95;41m%s", pText_c); - printf("\033[0;95;42m%s", pText_c); - printf("\033[0;95;43m%s", pText_c); - printf("\033[0;95;44m%s", pText_c); - printf("\033[0;95;45m%s", pText_c); - printf("\033[0;95;46m%s", pText_c); - printf("\033[0;95;47m%s", pText_c); - printf("\033[0;95;100m%s", pText_c); - printf("\033[0;95;101m%s", pText_c); - */ + std::string Txt_S; + + BOF_SPRINTF(Txt_S, _pFormat_c); + printf("%s%s%sm%s", S_mpTextAttribute_c, S_mpTextForeAttribute_c, S_mpTextBackAttribute_c, Txt_S.c_str()); + // printf("\033[0;95;40m%s", pText_c); return Rts_E; } void BofConio::S_PrintLineColorAt(CONIO_TEXT_COLOR _ForegroundColor_E, uint32_t _x_U32, uint32_t _y_U32, const char *_pFormat_c, ...) { uint32_t x_U32, y_U32; - char pText_c[0x1000]; + std::string Txt_S; if ((_x_U32) && (_y_U32)) { S_SetTextCursorPosition(_x_U32, _y_U32); } S_SetForegroundTextColor(_ForegroundColor_E); - va_list Arg; - va_start(Arg, _pFormat_c); - vsnprintf(pText_c, sizeof(pText_c), _pFormat_c, Arg); - va_end(Arg); - S_PrintLine(pText_c); + BOF_SPRINTF(Txt_S, _pFormat_c); + S_PrintLine(Txt_S.c_str()); } END_BOF_NAMESPACE() \ No newline at end of file diff --git a/lib/src/boffs.cpp b/lib/src/boffs.cpp index 9ee6c97..0e4dc3e 100644 --- a/lib/src/boffs.cpp +++ b/lib/src/boffs.cpp @@ -404,9 +404,11 @@ BOFERR Bof_DirectoryParser(const BofPath &_rPath, const std::string &_rPattern_S { EntryOk_B = true; ItIsADirectory_B = (S_ISDIR(FileStat_X.st_mode)) ? true : false; - FileFound_X.Path = _rPath; - FileFound_X.Path.Combine(pDirEntry_X->d_name); - // pr6intf("2:EntryOk_B %d ItIsADirectory_B %d\n",EntryOk_B,ItIsADirectory_B); + // FileFound_X.Path = _rPath; + // FileFound_X.Path.Combine(pDirEntry_X->d_name); + FileFound_X.Path = pPath_c; + // printf("2:EntryOk %d ItIsADirectory %d Path %s PathComb %s\n", EntryOk_B, ItIsADirectory_B, _rPath.FullPathName(false).c_str(), FileFound_X.Path.FullPathName(false).c_str()); + // printf("==>pPath_c %s Size %zu\n", pPath_c, FileStat_X.st_size); } // printf("3:EntryOk_B %d ItIsADirectory_B %d\n",EntryOk_B,ItIsADirectory_B); }