Skip to content
Snippets Groups Projects
Commit b7c3ec5f authored by rswindell's avatar rswindell
Browse files

uifcapi_t:

- msg() now returns an int (e.g. 0 for OK, non-zero otherwise)
- add msgf() a printf-style version of msg()
- add confirm() a printf-stle yes/no dialog (returns TRUE on "Yes"/default)
- add deny() a printf-style no/yes dialog (returns TRUE on "No"/default)
- add yesNoOpts to allow application to over-ride "Yes"/"No" strings.
parent a7a4542e
Branches
Tags
No related merge requests found
...@@ -415,6 +415,11 @@ typedef struct { ...@@ -415,6 +415,11 @@ typedef struct {
/****************************************************************************/ /****************************************************************************/
uifc_graphics_t *chars; uifc_graphics_t *chars;
/****************************************************************************/
/* Allow application override */
/****************************************************************************/
char** yesNoOpts;
/****************************************************************************/ /****************************************************************************/
/* Exit/uninitialize function. */ /* Exit/uninitialize function. */
/****************************************************************************/ /****************************************************************************/
...@@ -428,7 +433,10 @@ typedef struct { ...@@ -428,7 +433,10 @@ typedef struct {
/****************************************************************************/ /****************************************************************************/
/* Popup a message, maybe wait for the user to hit a key or click button. */ /* Popup a message, maybe wait for the user to hit a key or click button. */
/****************************************************************************/ /****************************************************************************/
void (*msg) (char* str); int (*msg) (char* str);
int (*msgf) (char* fmt, ...);
BOOL (*deny) (char* fmt, ...);
BOOL (*confirm) (char* fmt, ...);
/****************************************************************************/ /****************************************************************************/
/* Popup/down a status message. */ /* Popup/down a status message. */
/* str is the message to display on popup. */ /* str is the message to display on popup. */
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#endif #endif
#include <genwrap.h> // for alloca() #include <genwrap.h> // for alloca()
#include <datewrap.h> // localtime_r() #include <datewrap.h> // localtime_r()
#include "xpprintf.h"
#include "ciolib.h" #include "ciolib.h"
#include "uifc.h" #include "uifc.h"
...@@ -80,7 +81,10 @@ static int ulist(int mode, int left, int top, int width, int *dflt, int *bar ...@@ -80,7 +81,10 @@ static int ulist(int mode, int left, int top, int width, int *dflt, int *bar
,char *title, char **option); ,char *title, char **option);
static int uinput(int imode, int left, int top, char *prompt, char *str static int uinput(int imode, int left, int top, char *prompt, char *str
,int len ,int kmode); ,int len ,int kmode);
static void umsg(char *str); static int umsg(char *str);
static int umsgf(char *fmt, ...);
static BOOL confirm(char *fmt, ...);
static BOOL deny(char *fmt, ...);
static void upop(char *str); static void upop(char *str);
static void sethelp(int line, char* file); static void sethelp(int line, char* file);
static void showbuf(int mode, int left, int top, int width, int height, char *title static void showbuf(int mode, int left, int top, int width, int height, char *title
...@@ -212,10 +216,16 @@ int UIFCCALL uifcini32(uifcapi_t* uifcapi) ...@@ -212,10 +216,16 @@ int UIFCCALL uifcini32(uifcapi_t* uifcapi)
if (api->chars == NULL) if (api->chars == NULL)
api->chars = &cp437_chars; api->chars = &cp437_chars;
if (api->yesNoOpts == NULL)
api->yesNoOpts = uifcYesNoOpts;
/* install function handlers */ /* install function handlers */
api->bail=uifcbail; api->bail=uifcbail;
api->scrn=uscrn; api->scrn=uscrn;
api->msg=umsg; api->msg=umsg;
api->msgf=umsgf;
api->confirm=confirm;
api->deny=deny;
api->pop=upop; api->pop=upop;
api->list=ulist; api->list=ulist;
api->input=uinput; api->input=uinput;
...@@ -1875,16 +1885,69 @@ int uinput(int mode, int left, int top, char *inprompt, char *str, ...@@ -1875,16 +1885,69 @@ int uinput(int mode, int left, int top, char *inprompt, char *str,
/****************************************************************************/ /****************************************************************************/
/* Displays the message 'str' and waits for the user to select "OK" */ /* Displays the message 'str' and waits for the user to select "OK" */
/****************************************************************************/ /****************************************************************************/
void umsg(char *str) int umsg(char *str)
{ {
int i=0; int i=0;
char *ok[2]={"OK",""}; char *ok[2]={"OK",""};
if(api->mode&UIFC_INMSG) /* non-cursive */ if(api->mode&UIFC_INMSG) /* non-cursive */
return; return -1;
api->mode|=UIFC_INMSG; api->mode|=UIFC_INMSG;
ulist(WIN_SAV|WIN_MID,0,0,0,&i,0,str,ok); i = ulist(WIN_SAV|WIN_MID,0,0,0,&i,0,str,ok);
api->mode&=~UIFC_INMSG; api->mode&=~UIFC_INMSG;
return i;
}
/* Same as above, using printf-style varargs */
int umsgf(char* fmt, ...)
{
int retval = -1;
va_list va;
char* buf = NULL;
va_start(va, fmt);
vasprintf(&buf, fmt, va);
va_end(va);
if(buf != NULL) {
retval = umsg(buf);
free(buf);
}
return retval;
}
static int yesno(int dflt, char* fmt, va_list va)
{
int retval;
char* buf = NULL;
vasprintf(&buf, fmt, va);
if(buf == NULL)
return dflt;
retval = ulist(WIN_SAV|WIN_MID,0,0,0,&dflt,0,buf,api->yesNoOpts);
free(buf);
return retval;
}
static BOOL confirm(char* fmt, ...)
{
int retval;
va_list va;
va_start(va, fmt);
retval = yesno(0, fmt, va);
va_end(va);
return retval == 0;
}
static BOOL deny(char* fmt, ...)
{
int retval;
va_list va;
va_start(va, fmt);
retval = yesno(1, fmt, va);
va_end(va);
return retval != 0;
} }
/***************************************/ /***************************************/
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "genwrap.h" #include "genwrap.h"
#include "gen_defs.h" #include "gen_defs.h"
#include "xpprintf.h"
#include "uifc.h" #include "uifc.h"
#include <sys/types.h> #include <sys/types.h>
...@@ -58,7 +59,10 @@ static int ulist(int mode, int left, int top, int width, int *dflt, int *bar ...@@ -58,7 +59,10 @@ static int ulist(int mode, int left, int top, int width, int *dflt, int *bar
,char *title, char **option); ,char *title, char **option);
static int uinput(int imode, int left, int top, char *prompt, char *str static int uinput(int imode, int left, int top, char *prompt, char *str
,int len ,int kmode); ,int len ,int kmode);
static void umsg(char *str); static int umsg(char *str);
static int umsgf(char *str, ...);
static BOOL confirm(char *str, ...);
static BOOL deny(char *str, ...);
static void upop(char *str); static void upop(char *str);
static void sethelp(int line, char* file); static void sethelp(int line, char* file);
...@@ -84,16 +88,23 @@ static int uprintf(int x, int y, unsigned attr, char *fmat, ...) ...@@ -84,16 +88,23 @@ static int uprintf(int x, int y, unsigned attr, char *fmat, ...)
/****************************************************************************/ /****************************************************************************/
int UIFCCALL uifcinix(uifcapi_t* uifcapi) int UIFCCALL uifcinix(uifcapi_t* uifcapi)
{ {
static char* yesNoOpts[] = {"Yes", "No", NULL};
if(uifcapi==NULL || uifcapi->size!=sizeof(uifcapi_t)) if(uifcapi==NULL || uifcapi->size!=sizeof(uifcapi_t))
return(-1); return(-1);
api=uifcapi; api=uifcapi;
if (api->yesNoOpts == NULL)
api->yesNoOpts = yesNoOpts; // Not currently used in this interface instance
/* install function handlers */ /* install function handlers */
api->bail=uifcbail; api->bail=uifcbail;
api->scrn=uscrn; api->scrn=uscrn;
api->msg=umsg; api->msg=umsg;
api->msgf=umsgf;
api->confirm=confirm;
api->deny=deny;
api->pop=upop; api->pop=upop;
api->list=ulist; api->list=ulist;
api->input=uinput; api->input=uinput;
...@@ -160,7 +171,6 @@ static int getstr(char* str, int maxlen) ...@@ -160,7 +171,6 @@ static int getstr(char* str, int maxlen)
return(len); return(len);
} }
/****************************************************************************/ /****************************************************************************/
/* Local utility function. */ /* Local utility function. */
/****************************************************************************/ /****************************************************************************/
...@@ -349,11 +359,57 @@ int uinput(int mode, int left, int top, char *prompt, char *outstr, ...@@ -349,11 +359,57 @@ int uinput(int mode, int left, int top, char *prompt, char *outstr,
} }
/****************************************************************************/ /****************************************************************************/
/* Displays the message 'str' and waits for the user to select "OK" */ /* Displays the message 'str' and waits for the user to hit ENTER */
/****************************************************************************/ /****************************************************************************/
void umsg(char *str) int umsg(char *str)
{
int ch;
printf("%s\nHit enter to continue:",str);
ch = getchar();
return ch == '\r' || ch == '\n';
}
/* Same as above, using printf-style varargs */
int umsgf(char* fmt, ...)
{
int retval = -1;
va_list va;
char* buf = NULL;
va_start(va, fmt);
vasprintf(&buf, fmt, va);
va_end(va);
if(buf != NULL) {
retval = umsg(buf);
free(buf);
}
return retval;
}
BOOL confirm(char* fmt, ...)
{
int ch;
va_list va;
va_start(va, fmt);
vprintf(fmt, va);
va_end(va);
printf(" (Y/n)? ");
ch = getchar();
return tolower(ch) != 'n' && ch != EOF;
}
BOOL deny(char* fmt, ...)
{ {
printf("%s\n",str); int ch;
va_list va;
va_start(va, fmt);
vprintf(fmt, va);
va_end(va);
printf(" (N/y)? ");
ch = getchar();
return tolower(ch) != 'y';
} }
/****************************************************************************/ /****************************************************************************/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment