mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-10-04 12:48:20 +00:00
change strcpy to strlcpy
Change-Id: I8b9429a3c225a82842fce136bdb14b8b135066d3 Signed-off-by: lilei19 <lilei19@xiaomi.com>
This commit is contained in:
parent
e86745b9a2
commit
41f60bd669
33 changed files with 238 additions and 180 deletions
|
|
@ -41,7 +41,7 @@
|
|||
****************************************************************************/
|
||||
|
||||
#ifdef A_COLOR
|
||||
# define TITLECOLOR 1 /* color pair indices */
|
||||
# define TITLECOLOR 1 /* color pair indices */
|
||||
# define MAINMENUCOLOR (2 | A_BOLD)
|
||||
# define MAINMENUREVCOLOR (3 | A_BOLD | A_REVERSE)
|
||||
# define SUBMENUCOLOR (4 | A_BOLD)
|
||||
|
|
@ -51,7 +51,7 @@
|
|||
# define INPUTBOXCOLOR 8
|
||||
# define EDITBOXCOLOR (9 | A_BOLD | A_REVERSE)
|
||||
#else
|
||||
# define TITLECOLOR 0 /* color pair indices */
|
||||
# define TITLECOLOR 0 /* color pair indices */
|
||||
# define MAINMENUCOLOR (A_BOLD)
|
||||
# define MAINMENUREVCOLOR (A_BOLD | A_REVERSE)
|
||||
# define SUBMENUCOLOR (A_BOLD)
|
||||
|
|
@ -62,11 +62,11 @@
|
|||
# define EDITBOXCOLOR (A_BOLD | A_REVERSE)
|
||||
#endif
|
||||
|
||||
#define th 1 /* title window height */
|
||||
#define mh 1 /* main menu height */
|
||||
#define sh 2 /* status window height */
|
||||
#define th 1 /* title window height */
|
||||
#define mh 1 /* main menu height */
|
||||
#define sh 2 /* status window height */
|
||||
#define bh (LINES - th - mh - sh) /* body window height */
|
||||
#define bw COLS /* body window width */
|
||||
#define bw COLS /* body window width */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
|
|
@ -298,7 +298,12 @@ static void mainhelp(void)
|
|||
|
||||
static void mainmenu(menu *mp)
|
||||
{
|
||||
int nitems, barlen, old = -1, cur = 0, c, cur0;
|
||||
int nitems;
|
||||
int barlen;
|
||||
int c;
|
||||
int cur0;
|
||||
int old = -1;
|
||||
int cur = 0;
|
||||
|
||||
menudim(mp, &nitems, &barlen);
|
||||
repaintmainmenu(barlen, mp);
|
||||
|
|
@ -599,13 +604,12 @@ void domenu(const menu *mp)
|
|||
do
|
||||
{
|
||||
cur = (cur + 1) % nitems;
|
||||
|
||||
}
|
||||
while ((cur != cur0) && (hotkey(mp[cur].name) != toupper((int)key)));
|
||||
while ((cur != cur0) && (hotkey(mp[cur].name)
|
||||
!= toupper((int)key)));
|
||||
|
||||
key = (hotkey(mp[cur].name) == toupper((int)key)) ? '\n' : ERR;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
rmerror();
|
||||
|
|
@ -692,18 +696,27 @@ static void repainteditbox(WINDOW *win, int x, char *buf)
|
|||
|
||||
int weditstr(WINDOW *win, char *buf, int field)
|
||||
{
|
||||
char org[MAXSTRLEN], *tp, *bp = buf;
|
||||
bool defdisp = true, stop = false, insert = false;
|
||||
int cury, curx, begy, begx, oldattr;
|
||||
WINDOW *wedit;
|
||||
char org[MAXSTRLEN];
|
||||
char *tp;
|
||||
char *bp = buf;
|
||||
bool defdisp = true;
|
||||
bool stop = false;
|
||||
bool insert = false;
|
||||
int cury;
|
||||
int curx;
|
||||
int begy;
|
||||
int begx;
|
||||
int oldattr;
|
||||
int c = 0;
|
||||
WINDOW *wedit;
|
||||
|
||||
if ((field >= MAXSTRLEN) || (buf == NULL) || ((int)strlen(buf) > field - 1))
|
||||
if ((field >= MAXSTRLEN) || (buf == NULL) ||
|
||||
((int)strlen(buf) > field - 1))
|
||||
{
|
||||
return ERR;
|
||||
}
|
||||
|
||||
strcpy(org, buf); /* save original */
|
||||
strlcpy(org, buf, sizeof(org)); /* save original */
|
||||
|
||||
wrefresh(win);
|
||||
getyx(win, cury, curx);
|
||||
|
|
@ -760,7 +773,7 @@ int weditstr(WINDOW *win, char *buf, int field)
|
|||
case KEY_DC:
|
||||
if (*bp != 0)
|
||||
{
|
||||
memmove((void *)(bp), (const void *)(bp+1), strlen(bp));
|
||||
memmove((void *)(bp), (const void *)(bp + 1), strlen(bp));
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -769,7 +782,8 @@ int weditstr(WINDOW *win, char *buf, int field)
|
|||
{
|
||||
if (bp > buf)
|
||||
{
|
||||
memmove((void *)(bp - 1), (const void *)bp, strlen(bp) + 1);
|
||||
memmove((void *)(bp - 1), (const void *)bp,
|
||||
strlen(bp) + 1);
|
||||
bp--;
|
||||
}
|
||||
}
|
||||
|
|
@ -834,7 +848,10 @@ int weditstr(WINDOW *win, char *buf, int field)
|
|||
WINDOW *winputbox(WINDOW *win, int nlines, int ncols)
|
||||
{
|
||||
WINDOW *winp;
|
||||
int cury, curx, begy, begx;
|
||||
int cury;
|
||||
int curx;
|
||||
int begy;
|
||||
int begx;
|
||||
|
||||
getyx(win, cury, curx);
|
||||
getbegyx(win, begy, begx);
|
||||
|
|
@ -848,7 +865,16 @@ WINDOW *winputbox(WINDOW *win, int nlines, int ncols)
|
|||
int getstrings(const char *desc[], char *buf[], int field)
|
||||
{
|
||||
WINDOW *winput;
|
||||
int oldy, oldx, maxy, maxx, nlines, ncols, i, n, l, mmax = 0;
|
||||
int oldy;
|
||||
int oldx;
|
||||
int maxy;
|
||||
int maxx;
|
||||
int nlines;
|
||||
int ncols;
|
||||
int i;
|
||||
int n;
|
||||
int l;
|
||||
int mmax = 0;
|
||||
int c = 0;
|
||||
bool stop = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/****************************************************************************
|
||||
* apps/examples/pdcurses/tui.c
|
||||
* apps/examples/pdcurses/tui_main.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
|
|
@ -70,11 +70,21 @@ static const char *g_fieldname[6] =
|
|||
|
||||
menu g_mainmenu[] =
|
||||
{
|
||||
{"Asub", sub0, "Go inside first submenu"},
|
||||
{"Bsub", sub1, "Go inside second submenu"},
|
||||
{"Csub", sub2, "Go inside third submenu"},
|
||||
{"Dsub", sub3, "Go inside fourth submenu"},
|
||||
{"", (FUNC)0, ""} /* always add this as the last item! */
|
||||
{
|
||||
"Asub", sub0, "Go inside first submenu"
|
||||
},
|
||||
{
|
||||
"Bsub", sub1, "Go inside second submenu"
|
||||
},
|
||||
{
|
||||
"Csub", sub2, "Go inside third submenu"
|
||||
},
|
||||
{
|
||||
"Dsub", sub3, "Go inside fourth submenu"
|
||||
},
|
||||
{
|
||||
"", (FUNC)0, "" /* always add this as the last item! */
|
||||
}
|
||||
};
|
||||
|
||||
static const menu g_submenu0[] =
|
||||
|
|
@ -145,7 +155,8 @@ static char *getfname(char *desc, char *fname, int field)
|
|||
fieldname[1] = 0;
|
||||
fieldbuf[0] = fname;
|
||||
|
||||
return (getstrings((const char **)fieldname, fieldbuf, field) == KEY_ESC) ? NULL : fname;
|
||||
return (getstrings((const char **)fieldname,
|
||||
fieldbuf, field) == KEY_ESC) ? NULL : fname;
|
||||
}
|
||||
|
||||
static void showfile(char *fname)
|
||||
|
|
@ -240,7 +251,7 @@ static void subfunc2(void)
|
|||
{
|
||||
char fname[MAXSTRLEN];
|
||||
|
||||
strcpy(fname, FNAME);
|
||||
strlcpy(fname, FNAME, sizeof(fname));
|
||||
if (getfname("File to browse:", fname, 50))
|
||||
{
|
||||
showfile(fname);
|
||||
|
|
@ -262,6 +273,7 @@ int main(int argc, FAR char *argv[])
|
|||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
startmenu(g_mainmenu, "TUI - 'textual user interface' demonstration program");
|
||||
startmenu(g_mainmenu,
|
||||
"TUI - 'textual user interface' demonstration program");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue