Browse Source

Add gwinPrintg() and fix null pointer handling in sprintg()

remotes/origin_old/ugfx_release_2.6
Andrew Hannam 5 years ago
parent
commit
9ac3c368b4
  1. 2
      docs/releases.txt
  2. 10
      src/gfile/gfile_fs_strings.c
  3. 38
      src/gwin/gwin_widget.c
  4. 18
      src/gwin/gwin_widget.h

2
docs/releases.txt

@ -7,6 +7,8 @@ FIX: Fixing bug where the list item count wasn't decremented when an item was r
FEATURE: Add options GFILE_FATFS_EXTERNAL_LIB and GFILE_PETITFSFS_EXTERNAL_LIB
FEATURE: Added FT6x06 driver
FIX: Fixing issue in STM32F746G-Discovery board file that resulted in bad color reproduction
FEATURE: Added gwinPrintg()
FIX: Fix sprintg and related functions handling of NULL pointers.
*** Release 2.5 ***

10
src/gfile/gfile_fs_strings.c

@ -22,12 +22,18 @@ static int StringRead(GFILE *f, void *buf, int size) {
int res;
char *p;
if (!f->obj)
return 0;
p = ((char *)f->obj) + f->pos;
for(res = 0; res < size && *p; res++, p++, buf = ((char *)buf)+1)
((char *)buf)[0] = *p;
return res;
}
static int StringWrite(GFILE *f, const void *buf, int size) {
if (!f->obj)
return 0;
if ((f->flags & GFILEFLG_APPEND)) {
while(((char *)f->obj)[f->pos])
f->pos++;
@ -50,7 +56,7 @@ static const GFILEVMT StringVMT = {
};
static void gfileOpenStringFromStaticGFILE(GFILE *f, char *str) {
if ((f->flags & GFILEFLG_TRUNC))
if ((f->flags & GFILEFLG_TRUNC) && str)
str[0] = 0;
f->vmt = &StringVMT;
f->obj = str;
@ -62,7 +68,7 @@ GFILE *gfileOpenString(char *str, const char *mode) {
GFILE *f;
// Get an empty file and set the flags
if (!(f = _gfileFindSlot(mode)))
if (!str || !(f = _gfileFindSlot(mode)))
return 0;
// File is open - fill in all the details

38
src/gwin/gwin_widget.c

@ -530,6 +530,44 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc) {
_gwinUpdate(gh);
}
#if GFX_USE_GFILE && GFILE_NEED_PRINTG && GFILE_NEED_STRINGS
#include <stdarg.h>
void gwinPrintg(GHandle gh, const char * fmt, ...) {
char *str;
va_list va;
int size;
if (!(gh->flags & GWIN_FLG_WIDGET))
return;
// Dispose of the old string
if ((gh->flags & GWIN_FLG_ALLOCTXT)) {
gh->flags &= ~GWIN_FLG_ALLOCTXT;
if (gw->text) {
gfxFree((void *)gw->text);
gw->text = "";
}
}
// Alloc the new text
va_start (va, fmt);
size = vsnprintg(0, 0, fmt, va) + 1; //determine the buffer size required
if ((str = gfxAlloc(size))) {
gh->flags |= GWIN_FLG_ALLOCTXT;
vsnprintg(str, size, fmt, va);
gw->text = (const char *)str;
} else
gw->text = "";
va_end (va);
_gwinUpdate(gh);
}
#endif
const char *gwinGetText(GHandle gh) {
if (!(gh->flags & GWIN_FLG_WIDGET))
return 0;

18
src/gwin/gwin_widget.h

@ -231,6 +231,24 @@ void gwinSetText(GHandle gh, const char *text, bool_t useAlloc);
*/
const char *gwinGetText(GHandle gh);
#if (GFX_USE_GFILE && GFILE_NEED_PRINTG && GFILE_NEED_STRINGS) || defined(__DOXYGEN__)
/**
* @brief Set the text of a widget using a printf style format.
* @pre GFX_USE_GFILE, GFILE_NEED_PRINTG and GFILE_NEED_STRINGS must all be TRUE
*
* @param[in] gh The widget handle
* @param[in] fmt The format string using a printf/g syntax. See @p vsnprintg()
* @param[in] ... The printg paramters.
*
* @note The widget is automatically redrawn
* @note Non-widgets will ignore this call.
* @note The memory for the text is always allocated by this function.
*
* @api
*/
void gwinPrintg(GHandle gh, const char * fmt,...);
#endif
/**
* @brief Check whether a handles is a widget handle or not
*

Loading…
Cancel
Save