added cdk to deps and building fileapprove
This commit is contained in:
107
deps/cdk-5.0-20161210/cli/Makefile.in
vendored
Normal file
107
deps/cdk-5.0-20161210/cli/Makefile.in
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# $Id: Makefile.in,v 1.7 2013/07/19 23:55:03 tom Exp $
|
||||
#
|
||||
# Makefile for the cli directory.
|
||||
#
|
||||
SHELL = /bin/sh
|
||||
|
||||
prefix = @prefix@
|
||||
exec_prefix = @exec_prefix@
|
||||
|
||||
srcdir = @srcdir@
|
||||
VPATH = $(srcdir)
|
||||
|
||||
CC = @CC@
|
||||
RM = rm -f
|
||||
CTAGS = @CTAGS@
|
||||
ETAGS = @ETAGS@
|
||||
LINT = @LINT@
|
||||
LINT_OPTS = @LINT_OPTS@
|
||||
|
||||
LIBS = -l@LIB_ROOTNAME@ @LIBS@
|
||||
|
||||
LIBTOOL = @LIBTOOL@ @ECHO_LT@
|
||||
LIBTOOL_CLEAN = @LIB_CLEAN@
|
||||
LIBTOOL_LINK = @LIB_LINK@
|
||||
LINK = $(LIBTOOL_LINK)
|
||||
|
||||
x = @EXEEXT@
|
||||
o = .@OBJEXT@
|
||||
LOCAL_LIBDIR = @top_builddir@
|
||||
|
||||
CFLAGS = @CFLAGS@ @EXTRA_CFLAGS@
|
||||
CPPFLAGS = @DEFS@ -I../include -I$(srcdir)/../include -I. @CPPFLAGS@
|
||||
LDFLAGS = -L.. @LDFLAGS@ @LOCAL_LDFLAGS@
|
||||
|
||||
BINS = \
|
||||
cdkalphalist$x \
|
||||
cdkcalendar$x \
|
||||
cdkdialog$x \
|
||||
cdkentry$x \
|
||||
cdkfselect$x \
|
||||
cdkitemlist$x \
|
||||
cdklabel$x \
|
||||
cdkmatrix$x \
|
||||
cdkmentry$x \
|
||||
cdkradio$x \
|
||||
cdkscale$x \
|
||||
cdkscroll$x \
|
||||
cdkselection$x \
|
||||
cdkslider$x \
|
||||
cdktemplate$x \
|
||||
cdkviewer$x
|
||||
|
||||
CDKSRC = \
|
||||
cdkalphalist.c \
|
||||
cdkcalendar.c \
|
||||
cdkdialog.c \
|
||||
cdkentry.c \
|
||||
cdkfselect.c \
|
||||
cdkitemlist.c \
|
||||
cdklabel.c \
|
||||
cdkmatrix.c \
|
||||
cdkmentry.c \
|
||||
cdkradio.c \
|
||||
cdkscale.c \
|
||||
cdkscroll.c \
|
||||
cdkselection.c \
|
||||
cdkslider.c \
|
||||
cdktemplate.c \
|
||||
cdkviewer.c
|
||||
|
||||
LINKIT = @ECHO_LD@$(LINK) $(CFLAGS) $(CPPFLAGS) $? -o $@ $(LDFLAGS) $(LIBS)
|
||||
|
||||
all : $(BINS)
|
||||
|
||||
cdkalphalist$x : cdkalphalist.c ; $(LINKIT)
|
||||
cdkcalendar$x : cdkcalendar.c ; $(LINKIT)
|
||||
cdkdialog$x : cdkdialog.c ; $(LINKIT)
|
||||
cdkentry$x : cdkentry.c ; $(LINKIT)
|
||||
cdkfselect$x : cdkfselect.c ; $(LINKIT)
|
||||
cdkitemlist$x : cdkitemlist.c ; $(LINKIT)
|
||||
cdklabel$x : cdklabel.c ; $(LINKIT)
|
||||
cdkmatrix$x : cdkmatrix.c ; $(LINKIT)
|
||||
cdkmentry$x : cdkmentry.c ; $(LINKIT)
|
||||
cdkradio$x : cdkradio.c ; $(LINKIT)
|
||||
cdkscale$x : cdkscale.c ; $(LINKIT)
|
||||
cdkscroll$x : cdkscroll.c ; $(LINKIT)
|
||||
cdkselection$x : cdkselection.c ; $(LINKIT)
|
||||
cdkslider$x : cdkslider.c ; $(LINKIT)
|
||||
cdktemplate$x : cdktemplate.c ; $(LINKIT)
|
||||
cdkviewer$x : cdkviewer.c ; $(LINKIT)
|
||||
#
|
||||
# Standard clean directives.
|
||||
#
|
||||
clean::
|
||||
- $(LIBTOOL_CLEAN) $(RM) *.o core $(BINS)
|
||||
|
||||
distclean:: clean
|
||||
$(RM) Makefile
|
||||
|
||||
@MAKE_LOWER_TAGS@tags :
|
||||
@MAKE_LOWER_TAGS@ $(CTAGS) *.[ch] */*.[ch]
|
||||
|
||||
@MAKE_LOWER_TAGS@TAGS :
|
||||
@MAKE_LOWER_TAGS@ $(ETAGS) *.[ch] */*.[ch]
|
||||
|
||||
lint: $(CDKSRC)
|
||||
$(LINT) $(LINT_OPTS) $(CPPFLAGS) $(CDKSRC)
|
276
deps/cdk-5.0-20161210/cli/cdkalphalist.c
vendored
Normal file
276
deps/cdk-5.0-20161210/cli/cdkalphalist.c
vendored
Normal file
@@ -0,0 +1,276 @@
|
||||
/* $Id: cdkalphalist.c,v 1.18 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkalphalist";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-l List | -f filename [-F Field Character] [-T Title] [-L Label] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-H Height] [-W Width] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKALPHALIST *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *answer = 0;
|
||||
char *buttons;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
chtype filler = A_NORMAL | '.';
|
||||
int scrollLines = -1;
|
||||
int buttonCount = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **scrollList = 0;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *filename;
|
||||
char *label;
|
||||
char *list;
|
||||
char *outputFile;
|
||||
char *tempFiller;
|
||||
char *title;
|
||||
int height;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "f:l:B:F:L:O:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', -1);
|
||||
width = CDKparamValue (¶ms, 'W', -1);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
list = CDKparamString (¶ms, 'l');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
tempFiller = CDKparamString (¶ms, 'F');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did they provide a list of items. */
|
||||
if (list == 0)
|
||||
{
|
||||
/* Maybe they gave a filename to use to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
scrollLines = CDKreadFile (filename, &scrollList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (scrollLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* They didn't provide anything. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the scroll lines up. */
|
||||
scrollList = CDKsplitString (list, '\n');
|
||||
scrollLines = (int)CDKcountStrings ((CDK_CSTRING2)scrollList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* If they set the filler character, set it now. */
|
||||
if (tempFiller != 0)
|
||||
{
|
||||
holder = char2Chtype (tempFiller, &j1, &j2);
|
||||
filler = holder[0];
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Create the widget. */
|
||||
widget = newCDKAlphalist (cdkScreen, xpos, ypos,
|
||||
height, width,
|
||||
title, label,
|
||||
(CDK_CSTRING *)scrollList, scrollLines,
|
||||
filler, A_REVERSE,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (scrollList);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the alphalist. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win) + 1,
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 3,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2)buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the entry field.
|
||||
*/
|
||||
setCDKAlphalistLLChar (widget, ACS_LTEE);
|
||||
setCDKAlphalistLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the entry field to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vENTRY, widget->entryField, KEY_RIGHT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vENTRY, widget->entryField, KEY_LEFT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vENTRY, widget->entryField, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vENTRY, widget->entryField, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKAlphalist (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKAlphalistBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the widget. */
|
||||
answer = copyChar (activateCDKAlphalist (widget, 0));
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
destroyCDKAlphalist (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print out the answer. */
|
||||
if (answer != 0)
|
||||
{
|
||||
fprintf (fp, "%s\n", answer);
|
||||
freeChar (answer);
|
||||
}
|
||||
|
||||
/* Exit with the selected button. */
|
||||
ExitProgram (0);
|
||||
}
|
||||
|
||||
int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void)injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
252
deps/cdk-5.0-20161210/cli/cdkcalendar.c
vendored
Normal file
252
deps/cdk-5.0-20161210/cli/cdkcalendar.c
vendored
Normal file
@@ -0,0 +1,252 @@
|
||||
/* $Id: cdkcalendar.c,v 1.17 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkcalendar";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static void getTodaysDate (int *day, int *month, int *year);
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKCALENDAR *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
struct tm *dateInfo = 0;
|
||||
time_t selected = 0;
|
||||
chtype dayAttrib = A_NORMAL;
|
||||
chtype monthAttrib = A_NORMAL;
|
||||
chtype yearAttrib = A_NORMAL;
|
||||
chtype highlight = A_REVERSE;
|
||||
chtype *holder = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int day;
|
||||
int month;
|
||||
int xpos;
|
||||
int year;
|
||||
int ypos;
|
||||
|
||||
getTodaysDate (&day, &month, &year);
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:m:y:B:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
day = CDKparamValue (¶ms, 'd', day);
|
||||
month = CDKparamValue (¶ms, 'm', month);
|
||||
year = CDKparamValue (¶ms, 'y', year);
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the calendar width. */
|
||||
widget = newCDKCalendar (cdkScreen, xpos, ypos, title,
|
||||
day, month, year,
|
||||
dayAttrib, monthAttrib,
|
||||
yearAttrib, highlight,
|
||||
boxWidget, shadowWidget);
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the calendar. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKCalendarLLChar (widget, ACS_LTEE);
|
||||
setCDKCalendarLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vCALENDAR, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vCALENDAR, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
bindCDKObject (vCALENDAR, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKCalendar (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKCalendarBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the calendar widget. */
|
||||
selected = activateCDKCalendar (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
destroyCDKCalendar (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print out the date selected. D/M/Y format. */
|
||||
dateInfo = gmtime (&selected);
|
||||
fprintf (fp, "%02d/%02d/%d\n",
|
||||
dateInfo->tm_mday,
|
||||
(dateInfo->tm_mon + 1),
|
||||
(dateInfo->tm_year + 1900));
|
||||
fclose (fp);
|
||||
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
/*
|
||||
* This returns what day of the week the month starts on.
|
||||
*/
|
||||
static void getTodaysDate (int *day, int *month, int *year)
|
||||
{
|
||||
struct tm *dateInfo;
|
||||
time_t clck;
|
||||
|
||||
/* Determine the current time and determine if we are in DST. */
|
||||
time (&clck);
|
||||
dateInfo = gmtime (&clck);
|
||||
|
||||
/* Set the pointers accordingly. */
|
||||
(*day) = dateInfo->tm_mday;
|
||||
(*month) = dateInfo->tm_mon + 1;
|
||||
(*year) = dateInfo->tm_year + 1900;
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
178
deps/cdk-5.0-20161210/cli/cdkdialog.c
vendored
Normal file
178
deps/cdk-5.0-20161210/cli/cdkdialog.c
vendored
Normal file
@@ -0,0 +1,178 @@
|
||||
/* $Id: cdkdialog.c,v 1.15 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkdialog";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-m Message String | -f filename [-B Buttons] [-O Output file] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKDIALOG *widget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *button = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int answer = 0;
|
||||
int messageLines = -1;
|
||||
int buttonCount = 0;
|
||||
FILE *fp = stderr;
|
||||
char **messageList = 0;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *filename;
|
||||
char *outputFile;
|
||||
char *message;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "f:m:B:O:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
message = CDKparamString (¶ms, 'm');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure we have a message to display. */
|
||||
if (message == 0)
|
||||
{
|
||||
/* No message, maybe they provided a file to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
messageLines = CDKreadFile (filename, &messageList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (messageLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file %s\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No message, no file, it's an error. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the message up. */
|
||||
messageList = CDKsplitString (message, '\n');
|
||||
messageLines = (int)CDKcountStrings ((CDK_CSTRING2)messageList);
|
||||
}
|
||||
|
||||
/* Set up the buttons for the dialog box. */
|
||||
if (buttons == 0)
|
||||
{
|
||||
buttonList = calloc(sizeof(char *), 3);
|
||||
buttonList[0] = copyChar ("OK");
|
||||
buttonList[1] = copyChar ("Cancel");
|
||||
buttonCount = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the dialog box. */
|
||||
widget = newCDKDialog (cdkScreen, xpos, ypos,
|
||||
(CDK_CSTRING2)messageList, messageLines,
|
||||
(CDK_CSTRING2)buttonList, buttonCount,
|
||||
A_REVERSE,
|
||||
boxWidget, boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (messageList);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the dialog box. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKDialogBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the dialog box. */
|
||||
answer = activateCDKDialog (widget, 0);
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKDialog (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the name of the button selected. */
|
||||
if (answer >= 0)
|
||||
{
|
||||
button = copyChar (buttonList[answer]);
|
||||
fprintf (fp, "%s\n", button);
|
||||
freeChar (button);
|
||||
}
|
||||
|
||||
CDKfreeStrings (messageList);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
/* Exit with the button number picked. */
|
||||
ExitProgram (answer);
|
||||
}
|
267
deps/cdk-5.0-20161210/cli/cdkentry.c
vendored
Normal file
267
deps/cdk-5.0-20161210/cli/cdkentry.c
vendored
Normal file
@@ -0,0 +1,267 @@
|
||||
/* $Id: cdkentry.c,v 1.16 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkentry";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-f Field Width [-d Display Type] [-F Field Character] [-i Initial Value] [-m Minimum Length] [-M Maximum Length] [-T Title] [-L Label] [-B Buttons] [-O Output file] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKENTRY *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
chtype *holder = 0;
|
||||
chtype fieldAttr = A_NORMAL;
|
||||
char *answer = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
char filler = '.';
|
||||
EDisplayType dType = vMIXED;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *outputFile;
|
||||
char *initValue;
|
||||
char *title;
|
||||
char *label;
|
||||
char *tempFiller;
|
||||
int maxValue;
|
||||
int fieldWidth;
|
||||
int minValue;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:f:i:m:B:F:L:M:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
minValue = CDKparamValue (¶ms, 'm', 0);
|
||||
fieldWidth = CDKparamValue (¶ms, 'f', 0);
|
||||
maxValue = CDKparamValue (¶ms, 'M', 256);
|
||||
initValue = CDKparamString (¶ms, 'i');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
tempFiller = CDKparamString (¶ms, 'F');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
if ((temp = CDKparamString (¶ms, 'd')) != 0)
|
||||
dType = char2DisplayType (temp);
|
||||
|
||||
/* Make sure all the command line parameters were provided. */
|
||||
if (fieldWidth <= 0)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* If the set the filler character, set it now. */
|
||||
if (tempFiller != 0)
|
||||
{
|
||||
holder = char2Chtype (tempFiller, &j1, &j2);
|
||||
fieldAttr = A_ATTRIBUTES & holder[0];
|
||||
filler = (char)holder[0];
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Create the entry widget. */
|
||||
widget = newCDKEntry (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
fieldAttr,
|
||||
(chtype)filler | fieldAttr,
|
||||
dType, fieldWidth,
|
||||
minValue, maxValue,
|
||||
boxWidget, FALSE);
|
||||
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the entry field. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2)buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the entry field.
|
||||
*/
|
||||
setCDKEntryLLChar (widget, ACS_LTEE);
|
||||
setCDKEntryLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the entry field to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vENTRY, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vENTRY, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vENTRY, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKEntry (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKEntryBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* If there was an initial value, set it. */
|
||||
if (initValue != 0)
|
||||
{
|
||||
setCDKEntryValue (widget, initValue);
|
||||
}
|
||||
|
||||
/* Activate the widget. */
|
||||
answer = copyChar (activateCDKEntry (widget, 0));
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKEntry (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the value from the widget. */
|
||||
if (answer != 0)
|
||||
{
|
||||
fprintf (fp, "%s\n", answer);
|
||||
freeChar (answer);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the button number picked. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void)injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
238
deps/cdk-5.0-20161210/cli/cdkfselect.c
vendored
Normal file
238
deps/cdk-5.0-20161210/cli/cdkfselect.c
vendored
Normal file
@@ -0,0 +1,238 @@
|
||||
/* $Id: cdkfselect.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkfselect";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKFSELECT *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *filename = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
int buttonCount = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *directory;
|
||||
char *label;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int height;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:B:L:O:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', 0);
|
||||
width = CDKparamValue (¶ms, 'W', 0);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
directory = CDKparamString (¶ms, 'd');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* If they didn't provide a directory, use . */
|
||||
if (directory == 0)
|
||||
{
|
||||
directory = copyChar (".");
|
||||
}
|
||||
|
||||
/* Set the label of the file selector if it hasn't been yet. */
|
||||
if (label == 0)
|
||||
{
|
||||
label = copyChar ("Directory: ");
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the file selector widget. */
|
||||
widget = newCDKFselect (cdkScreen, xpos, ypos, height, width,
|
||||
title, label, A_NORMAL, '.', A_REVERSE,
|
||||
"", "", "", "",
|
||||
boxWidget, shadowWidget);
|
||||
freeChar (label);
|
||||
|
||||
/* Check to make sure we created the file selector. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the file selector. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 2),
|
||||
1, widget->boxWidth - 2,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKFselectLLChar (widget, ACS_LTEE);
|
||||
setCDKFselectLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vFSELECT, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vFSELECT, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vFSELECT, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKFselect (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKFselectBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Set the information for the file selector. */
|
||||
setCDKFselectDirectory (widget, directory);
|
||||
|
||||
/* Activate the file selector. */
|
||||
filename = copyChar (activateCDKFselect (widget, 0));
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
destroyCDKFselect (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the filename selected. */
|
||||
fprintf (fp, "%s\n", filename);
|
||||
freeChar (filename);
|
||||
fclose (fp);
|
||||
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
271
deps/cdk-5.0-20161210/cli/cdkitemlist.c
vendored
Normal file
271
deps/cdk-5.0-20161210/cli/cdkitemlist.c
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
/* $Id: cdkitemlist.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkitemlist";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-l List | -f filename [-d Default Item] [-T Title] [-L Label] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKITEMLIST *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
chtype *holder = 0;
|
||||
char *answer = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
int ret = 0;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **itemlistList = 0;
|
||||
char **buttonList = 0;
|
||||
int itemlistLines, j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *filename;
|
||||
char *label;
|
||||
char *list;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int defaultItem;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:f:l:B:L:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
defaultItem = CDKparamValue (¶ms, 'd', 0);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
list = CDKparamString (¶ms, 'l');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did they provide a list of items. */
|
||||
if (list == 0)
|
||||
{
|
||||
/* Maybe they gave a filename to use to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
itemlistLines = CDKreadFile (filename, &itemlistList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (itemlistLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* They didn't provide anything. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the itemlist lines up. */
|
||||
itemlistList = CDKsplitString (list, '\n');
|
||||
itemlistLines = (int)CDKcountStrings ((CDK_CSTRING2) itemlistList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the item list. */
|
||||
widget = newCDKItemlist (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
(CDK_CSTRING2) itemlistList, itemlistLines,
|
||||
defaultItem,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (itemlistList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the item list. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKItemlistLLChar (widget, ACS_LTEE);
|
||||
setCDKItemlistLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vITEMLIST, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vITEMLIST, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vITEMLIST, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKItemlist (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKItemlistBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the item list. */
|
||||
ret = activateCDKItemlist (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
destroyCDKItemlist (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print out the answer. */
|
||||
if (ret >= 0)
|
||||
{
|
||||
holder = char2Chtype (itemlistList[ret], &j1, &j2);
|
||||
answer = chtype2Char (holder);
|
||||
fprintf (fp, "%s\n", answer);
|
||||
freeChar (answer);
|
||||
freeChtype (holder);
|
||||
}
|
||||
CDKfreeStrings (itemlistList);
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the answer. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
164
deps/cdk-5.0-20161210/cli/cdklabel.c
vendored
Normal file
164
deps/cdk-5.0-20161210/cli/cdklabel.c
vendored
Normal file
@@ -0,0 +1,164 @@
|
||||
/* $Id: cdklabel.c,v 1.15 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdklabel";
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_SLEEP) && defined (_WIN32) /* Mingw */
|
||||
#define sleep(x) _sleep(x*1000)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-m Message String | -f filename [-c Command] [-p Pause Character] [-s Sleep] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKLABEL *widget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int messageLines = -1;
|
||||
char **messageList = 0;
|
||||
char tempCommand[1000];
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *command;
|
||||
char *filename;
|
||||
char *message;
|
||||
char waitChar = 0;
|
||||
int sleepLength;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "c:f:m:p:s:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
sleepLength = CDKparamValue (¶ms, 's', 0);
|
||||
command = CDKparamString (¶ms, 'c');
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
message = CDKparamString (¶ms, 'm');
|
||||
|
||||
if ((temp = CDKparamString (¶ms, 'p')) != 0)
|
||||
waitChar = *temp;
|
||||
|
||||
/* Make sure we have a message to display. */
|
||||
if (message == 0)
|
||||
{
|
||||
/* No message, maybe they provided a file to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
messageLines = CDKreadFile (filename, &messageList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (messageLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file %s\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* No message, no file, it's an error. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the message up. */
|
||||
messageList = CDKsplitString (message, '\n');
|
||||
messageLines = (int)CDKcountStrings ((CDK_CSTRING2) messageList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the label widget. */
|
||||
widget = newCDKLabel (cdkScreen, xpos, ypos,
|
||||
(CDK_CSTRING2) messageList, messageLines,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (messageList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the label. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKLabelBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the widget. */
|
||||
drawCDKLabel (widget, boxWidget);
|
||||
|
||||
/* If they supplied a command, run it. */
|
||||
if (command != 0)
|
||||
{
|
||||
const char *fmt = "(sh -c %.*s) >/dev/null 2>&1";
|
||||
sprintf (tempCommand, fmt, (int)(sizeof (tempCommand) - strlen (fmt)), command);
|
||||
system (tempCommand);
|
||||
}
|
||||
|
||||
/* If they supplied a wait character, wait for the user to hit it. */
|
||||
if (waitChar != 0)
|
||||
{
|
||||
waitCDKLabel (widget, waitChar);
|
||||
}
|
||||
|
||||
/* If they supplied a sleep time, sleep for the given length. */
|
||||
if (sleepLength > 0)
|
||||
{
|
||||
sleep ((unsigned)sleepLength);
|
||||
}
|
||||
|
||||
CDKfreeStrings (messageList);
|
||||
|
||||
destroyCDKLabel (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Exit cleanly. */
|
||||
ExitProgram (0);
|
||||
}
|
386
deps/cdk-5.0-20161210/cli/cdkmatrix.c
vendored
Normal file
386
deps/cdk-5.0-20161210/cli/cdkmatrix.c
vendored
Normal file
@@ -0,0 +1,386 @@
|
||||
/* $Id: cdkmatrix.c,v 1.19 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkmatrix";
|
||||
#endif
|
||||
|
||||
#define MY_INFO(x,y) info[(x + 1) * cols + (y + 1)]
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-r Row Titles -c Column Titles -v Visible Rows -w Column Widths [-t Column Types] [-d Default Values] [-F Field Character] [-T Title] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKMATRIX *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
chtype *holder = 0;
|
||||
char *buttons = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype filler = A_NORMAL | '.';
|
||||
int rows = -1;
|
||||
int cols = -1;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **rowTitles;
|
||||
char **colTitles;
|
||||
char **rowTemp = 0;
|
||||
char **colTemp = 0;
|
||||
char **kolTemp = 0;
|
||||
char **buttonList = 0;
|
||||
int *colWidths;
|
||||
int *colTypes;
|
||||
int count, infoLines, x, y, j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *defaultValue;
|
||||
char *myColTitles;
|
||||
char *myColTypes;
|
||||
char *myColWidths;
|
||||
char *myFiller;
|
||||
char *myRowTitles;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int vrows;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "c:d:r:t:w:v:B:F:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
vrows = CDKparamValue (¶ms, 'v', -1);
|
||||
myColTitles = CDKparamString (¶ms, 'c');
|
||||
defaultValue = CDKparamString (¶ms, 'd');
|
||||
myRowTitles = CDKparamString (¶ms, 'r');
|
||||
myColTypes = CDKparamString (¶ms, 't');
|
||||
myColWidths = CDKparamString (¶ms, 'w');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
myFiller = CDKparamString (¶ms, 'F');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure all the needed command line parameters were provided. */
|
||||
if ((myRowTitles == 0) ||
|
||||
(myColTitles == 0) ||
|
||||
(myColWidths == 0) ||
|
||||
(vrows == -1))
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Convert the char * titles to a char **, offset by one */
|
||||
rowTemp = CDKsplitString (myRowTitles, '\n');
|
||||
rows = (int)CDKcountStrings ((CDK_CSTRING2)rowTemp);
|
||||
rowTitles = (char **)calloc ((size_t) rows + 1, sizeof (char *));
|
||||
for (x = 0; x < rows; x++)
|
||||
{
|
||||
rowTitles[x + 1] = rowTemp[x];
|
||||
}
|
||||
|
||||
colTemp = CDKsplitString (myColTitles, '\n');
|
||||
cols = (int)CDKcountStrings ((CDK_CSTRING2)colTemp);
|
||||
colTitles = (char **)calloc ((size_t) cols + 1, sizeof (char *));
|
||||
for (x = 0; x < cols; x++)
|
||||
{
|
||||
colTitles[x + 1] = colTemp[x];
|
||||
}
|
||||
|
||||
/* Convert the column widths. */
|
||||
kolTemp = CDKsplitString (myColWidths, '\n');
|
||||
count = (int)CDKcountStrings ((CDK_CSTRING2)kolTemp);
|
||||
colWidths = (int *)calloc ((size_t) count + 1, sizeof (int));
|
||||
for (x = 0; x < count; x++)
|
||||
{
|
||||
colWidths[x + 1] = atoi (kolTemp[x]);
|
||||
}
|
||||
|
||||
/* If they passed in the column types, convert them. */
|
||||
if (myColTypes != 0)
|
||||
{
|
||||
char **ss = CDKsplitString (myColTypes, '\n');
|
||||
count = (int)CDKcountStrings ((CDK_CSTRING2)ss);
|
||||
colTypes = (int *)calloc ((size_t) MAXIMUM (cols, count) + 1, sizeof (int));
|
||||
for (x = 0; x < count; x++)
|
||||
{
|
||||
colTypes[x + 1] = char2DisplayType (ss[x]);
|
||||
}
|
||||
CDKfreeStrings (ss);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If they didn't set default values. */
|
||||
colTypes = (int *)calloc ((size_t) cols + 1, sizeof (int));
|
||||
for (x = 0; x < cols; x++)
|
||||
{
|
||||
colTypes[x + 1] = vMIXED;
|
||||
}
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* If the set the filler character, set it now. */
|
||||
if (myFiller != 0)
|
||||
{
|
||||
holder = char2Chtype (myFiller, &j1, &j2);
|
||||
filler = holder[0];
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Create the matrix widget. */
|
||||
widget = newCDKMatrix (cdkScreen, xpos, ypos,
|
||||
rows, cols, vrows, cols,
|
||||
title, (CDK_CSTRING2)rowTitles, (CDK_CSTRING2)colTitles,
|
||||
colWidths, colTypes, 1, 1,
|
||||
filler, COL,
|
||||
boxWidget, TRUE, shadowWidget);
|
||||
free (rowTitles);
|
||||
free (colTitles);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Cannot create the matrix. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user sent in a file of default values, read it and
|
||||
* stick the values read in from the file into the matrix.
|
||||
*/
|
||||
if (defaultValue != 0)
|
||||
{
|
||||
size_t limit = (size_t) ((rows + 1) * (cols + 1));
|
||||
char **info = (char **)calloc (limit, sizeof (char *));
|
||||
char **lineTemp = 0;
|
||||
|
||||
/* Read the file. */
|
||||
infoLines = CDKreadFile (defaultValue, &lineTemp);
|
||||
if (infoLines > 0)
|
||||
{
|
||||
int *subSize = (int *)calloc ((size_t) infoLines + 1, sizeof (int));
|
||||
|
||||
/* For each line, split on a CTRL-V. */
|
||||
for (x = 0; x < infoLines; x++)
|
||||
{
|
||||
char **ss = CDKsplitString (lineTemp[x], CTRL ('V'));
|
||||
subSize[x + 1] = (int)CDKcountStrings ((CDK_CSTRING2)ss);
|
||||
for (y = 0; y < subSize[x + 1]; y++)
|
||||
{
|
||||
MY_INFO (x, y) = ss[y];
|
||||
}
|
||||
free (ss);
|
||||
}
|
||||
CDKfreeStrings (lineTemp);
|
||||
|
||||
setCDKMatrixCells (widget, (CDK_CSTRING2)info, rows, cols, subSize);
|
||||
|
||||
for (x = 0; x < infoLines; x++)
|
||||
{
|
||||
for (y = 0; y < subSize[x + 1]; y++)
|
||||
{
|
||||
freeChar (MY_INFO (x, y));
|
||||
}
|
||||
}
|
||||
free (info);
|
||||
free (subSize);
|
||||
}
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
NULL, 1, buttonCount,
|
||||
(CDK_CSTRING2)buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKMatrixLLChar (widget, ACS_LTEE);
|
||||
setCDKMatrixLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vMATRIX, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vMATRIX, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vMATRIX, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == (CDKBUTTONBOX *)NULL ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKMatrix (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKMatrixBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Let them play. */
|
||||
activateCDKMatrix (widget, 0);
|
||||
|
||||
/* Print out the matrix cells. */
|
||||
if (widget->exitType == vNORMAL)
|
||||
{
|
||||
for (x = 0; x < widget->rows; x++)
|
||||
{
|
||||
for (y = 0; y < widget->cols; y++)
|
||||
{
|
||||
char *data = getCDKMatrixCell (widget, x, y);
|
||||
if (data != 0)
|
||||
{
|
||||
fprintf (fp, "%s%c", data, CTRL ('V'));
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (fp, "%c", CTRL ('V'));
|
||||
}
|
||||
}
|
||||
fprintf (fp, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* cleanup (not really needed) */
|
||||
CDKfreeStrings (buttonList);
|
||||
free (colTypes);
|
||||
free (colWidths);
|
||||
|
||||
CDKfreeStrings (rowTemp);
|
||||
CDKfreeStrings (colTemp);
|
||||
CDKfreeStrings (kolTemp);
|
||||
|
||||
destroyCDKMatrix (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* do this late, in case it was stderr */
|
||||
fclose (fp);
|
||||
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void)injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
270
deps/cdk-5.0-20161210/cli/cdkmentry.c
vendored
Normal file
270
deps/cdk-5.0-20161210/cli/cdkmentry.c
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
/* $Id: cdkmentry.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkmentry";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-f Field Width -s Screen Rows -v Virtual Rows [-d Display Type] [-F Field Character] [-i Initial Value] [-m Minimum Length] [-T Title] [-L Label] [-B Buttons] [-O Output file] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKMENTRY *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
chtype *holder = 0;
|
||||
chtype fieldAttr = 0;
|
||||
char *answer = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
char filler = '.';
|
||||
EDisplayType dType = vMIXED;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *initValue;
|
||||
char *label;
|
||||
char *outputFile;
|
||||
char *tempFiller;
|
||||
char *title;
|
||||
int fieldWidth;
|
||||
int min;
|
||||
int screenRows;
|
||||
int virtualRows;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:f:i:m:s:v:B:F:L:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
fieldWidth = CDKparamValue (¶ms, 'f', 0);
|
||||
min = CDKparamValue (¶ms, 'm', 0);
|
||||
screenRows = CDKparamValue (¶ms, 's', 0);
|
||||
virtualRows = CDKparamValue (¶ms, 'v', 0);
|
||||
initValue = CDKparamString (¶ms, 'i');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
tempFiller = CDKparamString (¶ms, 'F');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
if ((temp = CDKparamString (¶ms, 'd')) != 0)
|
||||
dType = char2DisplayType (temp);
|
||||
|
||||
/* Make sure all the command line parameters were provided. */
|
||||
if ((fieldWidth <= 0) || (screenRows <= 0) || (virtualRows <= 0))
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* If the set the filler character, set it now. */
|
||||
if (tempFiller != 0)
|
||||
{
|
||||
holder = char2Chtype (tempFiller, &j1, &j2);
|
||||
fieldAttr = A_ATTRIBUTES & holder[0];
|
||||
filler = (char)holder[0];
|
||||
freeChtype (holder);
|
||||
}
|
||||
/* Create the mentry widget. */
|
||||
widget = newCDKMentry (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
fieldAttr,
|
||||
(chtype)filler | fieldAttr,
|
||||
dType, fieldWidth,
|
||||
screenRows, virtualRows,
|
||||
min, boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the multiple line entry field. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
NULL, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKMentryLLChar (widget, ACS_LTEE);
|
||||
setCDKMentryLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vMENTRY, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vMENTRY, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vMENTRY, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == (CDKBUTTONBOX *)NULL ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKMentry (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKMentryBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* If there was an initial value, set it. */
|
||||
if (initValue != 0)
|
||||
{
|
||||
setCDKMentryValue (widget, initValue);
|
||||
}
|
||||
|
||||
/* Activate the widget. */
|
||||
answer = copyChar (activateCDKMentry (widget, 0));
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKMentry (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the value from the widget. */
|
||||
if (answer != 0)
|
||||
{
|
||||
fprintf (fp, "%s\n", answer);
|
||||
freeChar (answer);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the button number picked. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
293
deps/cdk-5.0-20161210/cli/cdkradio.c
vendored
Normal file
293
deps/cdk-5.0-20161210/cli/cdkradio.c
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
/* $Id: cdkradio.c,v 1.13 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkradio";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-l List | -f filename [-c Choice Character] [-d Default Item] [-s Scroll Bar Position] [-n Numbers] [-i Item Index] [-T Title] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-H Height] [-W Width] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKRADIO *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *buttons = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
chtype *choiceChar = 0;
|
||||
int answer = 0;
|
||||
int spos = NONE;
|
||||
int scrollLines = -1;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
char **scrollList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean numberOutput;
|
||||
boolean shadowWidget;
|
||||
const char *choice;
|
||||
char *filename;
|
||||
char *list;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int defaultItem;
|
||||
int height;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "l:f:s:c:d:iB:O:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', 10);
|
||||
width = CDKparamValue (¶ms, 'W', 1);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
defaultItem = CDKparamValue (¶ms, 'd', 0);
|
||||
numberOutput = CDKparamValue (¶ms, 'i', FALSE);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
list = CDKparamString (¶ms, 'l');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
if ((choice = CDKparamString (¶ms, 'c')) == 0)
|
||||
choice = "</R>X";
|
||||
|
||||
spos = CDKparsePosition (CDKparamString (¶ms, 's'));
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did they provide a list of items. */
|
||||
if (list == 0)
|
||||
{
|
||||
/* Maybe they gave a filename to use to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
scrollLines = CDKreadFile (filename, &scrollList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (scrollLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* They didn't provide anything. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the scroll lines up. */
|
||||
scrollList = CDKsplitString (list, '\n');
|
||||
scrollLines = (int)CDKcountStrings ((CDK_CSTRING2) scrollList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Convert the char * choiceChar to a chtype * */
|
||||
choiceChar = char2Chtype (choice, &j1, &j2);
|
||||
|
||||
/* Create the scrolling list. */
|
||||
widget = newCDKRadio (cdkScreen, xpos, ypos, spos,
|
||||
height, width, title,
|
||||
(CDK_CSTRING2) scrollList, scrollLines,
|
||||
choiceChar[0], defaultItem,
|
||||
A_REVERSE,
|
||||
boxWidget, shadowWidget);
|
||||
free (choiceChar);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the radio list. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
NULL, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKRadioLLChar (widget, ACS_LTEE);
|
||||
setCDKRadioLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vRADIO, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vRADIO, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vRADIO, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == (CDKBUTTONBOX *)NULL ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKRadio (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKRadioBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the scrolling list. */
|
||||
answer = activateCDKRadio (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* Shut down curses. */
|
||||
destroyCDKRadio (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print out the answer. */
|
||||
if (answer >= 0)
|
||||
{
|
||||
if (numberOutput == TRUE)
|
||||
{
|
||||
fprintf (fp, "%d\n", answer);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (fp, "%s\n", scrollList[answer]);
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
/* Exit with the button selected. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
281
deps/cdk-5.0-20161210/cli/cdkscale.c
vendored
Normal file
281
deps/cdk-5.0-20161210/cli/cdkscale.c
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
/* $Id: cdkscale.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkscale";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-f Field Width -l Low Value -h High Value [-s Initial Value]] [-i Increment Value] [-a Accelerated Increment Value] [-T Title] [-L Label] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKSCALE *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int answer = 0;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int tmp, j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *label;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int fieldWidth;
|
||||
int incrementStep;
|
||||
int acceleratedStep;
|
||||
int initValue;
|
||||
int lowValue;
|
||||
int highValue;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "a:f:h:i:l:s:B:L:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
acceleratedStep = CDKparamValue (¶ms, 'a', -1);
|
||||
fieldWidth = CDKparamValue (¶ms, 'f', 0);
|
||||
highValue = CDKparamValue (¶ms, 'h', INT_MIN);
|
||||
incrementStep = CDKparamValue (¶ms, 'i', 1);
|
||||
lowValue = CDKparamValue (¶ms, 'l', INT_MAX);
|
||||
initValue = CDKparamValue (¶ms, 's', INT_MIN);
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
incrementStep = abs (incrementStep);
|
||||
|
||||
/* Make sure all the command line parameters were provided. */
|
||||
if (fieldWidth <= 0)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Make sure the user supplied the low/high values. */
|
||||
if ((lowValue == INT_MAX) || (highValue == INT_MIN))
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure the low is lower than the high (and vice versa). */
|
||||
if (lowValue > highValue)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
tmp = lowValue;
|
||||
lowValue = highValue;
|
||||
highValue = tmp;
|
||||
}
|
||||
|
||||
/* Make sure the starting value is in range. */
|
||||
if (initValue < lowValue)
|
||||
{
|
||||
initValue = lowValue;
|
||||
}
|
||||
else if (initValue > highValue)
|
||||
{
|
||||
initValue = highValue;
|
||||
}
|
||||
|
||||
/* Check if the accelerated incremnt value was set. */
|
||||
if (acceleratedStep <= 0)
|
||||
{
|
||||
acceleratedStep = (int)((highValue - lowValue) / 10);
|
||||
acceleratedStep = MAXIMUM (1, acceleratedStep);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the entry widget. */
|
||||
widget = newCDKScale (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
A_NORMAL, fieldWidth,
|
||||
initValue, lowValue, highValue,
|
||||
incrementStep, acceleratedStep,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the numeric scale field. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKScaleLLChar (widget, ACS_LTEE);
|
||||
setCDKScaleLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vSCALE, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSCALE, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSCALE, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKScale (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKScaleBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the widget. */
|
||||
answer = activateCDKScale (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKScale (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the value from the widget. */
|
||||
fprintf (fp, "%d\n", answer);
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the answer. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
284
deps/cdk-5.0-20161210/cli/cdkscroll.c
vendored
Normal file
284
deps/cdk-5.0-20161210/cli/cdkscroll.c
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
/* $Id: cdkscroll.c,v 1.13 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkscroll";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-l List | -f filename [-s Scroll Bar Position] [-n Numbers] [-i Item Index] [-T Title] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-H Height] [-W Width] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKSCROLL *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int answer = 0;
|
||||
int spos = NONE;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int scrollLines = -1;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **scrollList = 0;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *filename;
|
||||
char *list;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int height;
|
||||
int numberOutput;
|
||||
int numbers;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "f:il:ns:B:O:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', 1);
|
||||
width = CDKparamValue (¶ms, 'W', 1);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
numberOutput = CDKparamValue (¶ms, 'i', FALSE);
|
||||
numbers = CDKparamValue (¶ms, 'n', FALSE);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
list = CDKparamString (¶ms, 'l');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
spos = CDKparsePosition (CDKparamString (¶ms, 's'));
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did they provide a list of items. */
|
||||
if (list == 0)
|
||||
{
|
||||
/* Maybe they gave a filename to use to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
scrollLines = CDKreadFile (filename, &scrollList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (scrollLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* They didn't provide anything. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the scroll lines up. */
|
||||
scrollList = CDKsplitString (list, '\n');
|
||||
scrollLines = (int)CDKcountStrings ((CDK_CSTRING2) scrollList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the scrolling list. */
|
||||
widget = newCDKScroll (cdkScreen, xpos, ypos, spos,
|
||||
height, width, title,
|
||||
(CDK_CSTRING2) scrollList, scrollLines,
|
||||
numbers, A_REVERSE,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the scrolling list. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKScrollLLChar (widget, ACS_LTEE);
|
||||
setCDKScrollLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vSCROLL, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSCROLL, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSCROLL, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKScroll (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKScrollBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the scrolling list. */
|
||||
answer = activateCDKScroll (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* Shut down curses. */
|
||||
destroyCDKScroll (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print out the answer. */
|
||||
if (answer >= 0)
|
||||
{
|
||||
if (numberOutput == TRUE)
|
||||
{
|
||||
fprintf (fp, "%d\n", answer);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf (fp, "%s\n", scrollList[answer]);
|
||||
}
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
/* Exit with the answer. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
341
deps/cdk-5.0-20161210/cli/cdkselection.c
vendored
Normal file
341
deps/cdk-5.0-20161210/cli/cdkselection.c
vendored
Normal file
@@ -0,0 +1,341 @@
|
||||
/* $Id: cdkselection.c,v 1.15 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkselection";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-l List | -f filename [-c Choices ] [-s Selection Bar Position] [-T Title] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-H Height] [-W Width] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKSELECTION *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
chtype *holder = 0;
|
||||
char *item = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
int scrollLines = -1;
|
||||
int choiceSize = -1;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **scrollList = 0;
|
||||
char **choiceList = 0;
|
||||
char **buttonList = 0;
|
||||
char **items = 0;
|
||||
int choiceValues[MAX_ITEMS];
|
||||
int editModes[MAX_ITEMS];
|
||||
int x, fields, j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *choices;
|
||||
char *filename;
|
||||
char *list;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int height;
|
||||
int numbers;
|
||||
int spos;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "c:f:ln:s:B:O:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', 10);
|
||||
width = CDKparamValue (¶ms, 'W', 10);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
choices = CDKparamString (¶ms, 'c');
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
list = CDKparamString (¶ms, 'l');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
numbers = CDKparamValue (¶ms, 'n', FALSE);
|
||||
spos = CDKparsePosition (CDKparamString (¶ms, 's'));
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Did they provide a list of items. */
|
||||
if (list == 0)
|
||||
{
|
||||
/* Maybe they gave a filename to use to read. */
|
||||
if (filename != 0)
|
||||
{
|
||||
/* Read the file in. */
|
||||
scrollLines = CDKreadFile (filename, &scrollList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (scrollLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file '%s'.\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* For each line, we will split on a CTRL-V and look for a selection
|
||||
* value/edit mode. The format of the input file can be the following:
|
||||
* Index value [choice value] [edit flag]
|
||||
*/
|
||||
for (x = 0; x < scrollLines; x++)
|
||||
{
|
||||
/* Split the line on CTRL-V. */
|
||||
items = CDKsplitString (scrollList[x], CTRL ('V'));
|
||||
fields = (int)CDKcountStrings ((CDK_CSTRING2)items);
|
||||
|
||||
/* Check the field count. */
|
||||
if (fields == 1)
|
||||
{
|
||||
choiceValues[x] = 0;
|
||||
editModes[x] = 0;
|
||||
}
|
||||
else if (fields == 2)
|
||||
{
|
||||
freeChar (scrollList[x]);
|
||||
scrollList[x] = copyChar (items[0]);
|
||||
|
||||
choiceValues[x] = (int)atoi (items[1]);
|
||||
editModes[x] = 0;
|
||||
}
|
||||
else if (fields == 3)
|
||||
{
|
||||
freeChar (scrollList[x]);
|
||||
scrollList[x] = copyChar (items[0]);
|
||||
|
||||
choiceValues[x] = (int)atoi (items[1]);
|
||||
editModes[x] = (int)atoi (items[2]);
|
||||
}
|
||||
|
||||
CDKfreeStrings (items);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* They didn't provide anything. */
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the scroll lines up. */
|
||||
scrollList = CDKsplitString (list, '\n');
|
||||
scrollLines = (int)CDKcountStrings ((CDK_CSTRING2)scrollList);
|
||||
}
|
||||
|
||||
/* Did they supply a chopice list. */
|
||||
if (choices == 0)
|
||||
{
|
||||
choiceList = calloc(sizeof(char *), 3);
|
||||
choiceList[0] = copyChar ("Yes ");
|
||||
choiceList[1] = copyChar ("No ");
|
||||
choiceSize = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the choices up. */
|
||||
choiceList = CDKsplitString (choices, '\n');
|
||||
choiceSize = (int)CDKcountStrings ((CDK_CSTRING2)choiceList);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the scrolling list. */
|
||||
widget = newCDKSelection (cdkScreen, xpos, ypos, spos,
|
||||
height, width, title,
|
||||
(CDK_CSTRING2)scrollList, scrollLines,
|
||||
(CDK_CSTRING2)choiceList, choiceSize,
|
||||
A_REVERSE,
|
||||
boxWidget, shadowWidget);
|
||||
CDKfreeStrings (choiceList);
|
||||
|
||||
/* Make sure we could create the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the selection list. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Set up the default selection choices. */
|
||||
setCDKSelectionChoices (widget, choiceValues);
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2)buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKSelectionLLChar (widget, ACS_LTEE);
|
||||
setCDKSelectionLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vSELECTION, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSELECTION, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSELECTION, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKSelection (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKSelectionBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Set up the default selection modes. */
|
||||
setCDKSelectionModes (widget, editModes);
|
||||
|
||||
/* Activate the selection list. */
|
||||
activateCDKSelection (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* Print out the answer. */
|
||||
for (x = 0; x < scrollLines; x++)
|
||||
{
|
||||
holder = char2Chtype (scrollList[x], &j1, &j2);
|
||||
item = chtype2Char (holder);
|
||||
fprintf (fp, "%d %s\n", widget->selections[x], item);
|
||||
freeChtype (holder);
|
||||
freeChar (item);
|
||||
}
|
||||
|
||||
CDKfreeStrings (scrollList);
|
||||
|
||||
/* Shut down curses. */
|
||||
destroyCDKSelection (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void)injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
290
deps/cdk-5.0-20161210/cli/cdkslider.c
vendored
Normal file
290
deps/cdk-5.0-20161210/cli/cdkslider.c
vendored
Normal file
@@ -0,0 +1,290 @@
|
||||
/* $Id: cdkslider.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkslider";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-f Field Width -l Low Value -h High Value [-s Initial Value]] [-i Increment Value] [-a Accelerated Increment Value] [-F Field Character] [-T Title] [-L Label] [-B Buttons] [-O Output File] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKSLIDER *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
chtype fieldAttr = A_REVERSE | ' ';
|
||||
int answer = 0;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2, tmp;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean shadowWidget;
|
||||
char *barAttribute;
|
||||
char *buttons;
|
||||
char *label;
|
||||
char *outputFile;
|
||||
char *title;
|
||||
int fieldWidth;
|
||||
int incrementStep;
|
||||
int acceleratedStep;
|
||||
int initValue;
|
||||
int lowValue;
|
||||
int highValue;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "a:f:h:i:l:s:B:F:L:O:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
acceleratedStep = CDKparamValue (¶ms, 'a', -1);
|
||||
fieldWidth = CDKparamValue (¶ms, 'f', 0);
|
||||
highValue = CDKparamValue (¶ms, 'h', INT_MIN);
|
||||
incrementStep = CDKparamValue (¶ms, 'i', 1);
|
||||
lowValue = CDKparamValue (¶ms, 'l', INT_MAX);
|
||||
initValue = CDKparamValue (¶ms, 's', INT_MIN);
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
barAttribute = CDKparamString (¶ms, 'F');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
incrementStep = abs (incrementStep);
|
||||
|
||||
/* Make sure all the command line parameters were provided. */
|
||||
if (fieldWidth <= 0)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Make sure the user supplied the low/high values. */
|
||||
if ((lowValue == INT_MAX) || (highValue == INT_MIN))
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/* Make sure the low is lower than the high (and vice versa). */
|
||||
if (lowValue > highValue)
|
||||
{
|
||||
tmp = lowValue;
|
||||
lowValue = highValue;
|
||||
highValue = tmp;
|
||||
}
|
||||
|
||||
/* Make sure the starting value is in range. */
|
||||
if (initValue < lowValue)
|
||||
{
|
||||
initValue = lowValue;
|
||||
}
|
||||
else if (initValue > highValue)
|
||||
{
|
||||
initValue = highValue;
|
||||
}
|
||||
|
||||
/* Check if the accelerated incremnt value was set. */
|
||||
if (acceleratedStep <= 0)
|
||||
{
|
||||
acceleratedStep = (int)((highValue - lowValue) / 10);
|
||||
acceleratedStep = MAXIMUM (1, acceleratedStep);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Did the user ask to change the bar attribute? */
|
||||
if (barAttribute != 0)
|
||||
{
|
||||
holder = char2Chtype (barAttribute, &j1, &j2);
|
||||
fieldAttr = holder[0];
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Create the entry widget. */
|
||||
widget = newCDKSlider (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
fieldAttr, fieldWidth,
|
||||
initValue, lowValue, highValue,
|
||||
incrementStep, acceleratedStep,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the dialog box. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the numeric slider field. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKSliderLLChar (widget, ACS_LTEE);
|
||||
setCDKSliderLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vSLIDER, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSLIDER, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vSLIDER, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKSlider (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKSliderBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Activate the widget. */
|
||||
answer = activateCDKSlider (widget, 0);
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKSlider (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the value from the widget. */
|
||||
fprintf (fp, "%d\n", answer);
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the button selected. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
264
deps/cdk-5.0-20161210/cli/cdktemplate.c
vendored
Normal file
264
deps/cdk-5.0-20161210/cli/cdktemplate.c
vendored
Normal file
@@ -0,0 +1,264 @@
|
||||
/* $Id: cdktemplate.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdktemplate";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-p Plate [-o Overlay] [-P Mix Plate] [-d Default Answer] [-m Minimum Length] [-T Title] [-L Label] [-B Buttons] [-O Output file] [-X X Position] [-Y Y Position] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKTEMPLATE *widget = 0;
|
||||
CDKBUTTONBOX *buttonWidget = 0;
|
||||
char *answer = 0;
|
||||
char *tmp = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int buttonCount = 0;
|
||||
int selection = 0;
|
||||
int shadowHeight = 0;
|
||||
FILE *fp = stderr;
|
||||
char **buttonList = 0;
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean mixPlate;
|
||||
boolean shadowWidget;
|
||||
char *buttons;
|
||||
char *defaultAnswer;
|
||||
char *label;
|
||||
char *my_overlay;
|
||||
char *outputFile;
|
||||
char *plate;
|
||||
char *title;
|
||||
int minimum;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "d:m:o:p:B:L:O:P:T:" CDK_MIN_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
minimum = CDKparamValue (¶ms, 'm', 0);
|
||||
mixPlate = CDKparamValue (¶ms, 'P', FALSE);
|
||||
defaultAnswer = CDKparamString (¶ms, 'd');
|
||||
my_overlay = CDKparamString (¶ms, 'o');
|
||||
plate = CDKparamString (¶ms, 'p');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
label = CDKparamString (¶ms, 'L');
|
||||
outputFile = CDKparamString (¶ms, 'O');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* Make sure all the command line parameters were provided. */
|
||||
if (plate == 0)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* If the user asked for an output file, try to open it. */
|
||||
if (outputFile != 0)
|
||||
{
|
||||
if ((fp = fopen (outputFile, "w")) == 0)
|
||||
{
|
||||
fprintf (stderr, "%s: Can not open output file %s\n", argv[0], outputFile);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the template widget. */
|
||||
widget = newCDKTemplate (cdkScreen, xpos, ypos,
|
||||
title, label,
|
||||
plate, my_overlay,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the widget. */
|
||||
if (widget == 0)
|
||||
{
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the template field. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Split the buttons if they supplied some. */
|
||||
if (buttons != 0)
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);
|
||||
|
||||
/* We need to create a buttonbox widget. */
|
||||
buttonWidget = newCDKButtonbox (cdkScreen,
|
||||
getbegx (widget->win),
|
||||
(getbegy (widget->win)
|
||||
+ widget->boxHeight - 1),
|
||||
1, widget->boxWidth - 1,
|
||||
0, 1, buttonCount,
|
||||
(CDK_CSTRING2) buttonList, buttonCount,
|
||||
A_REVERSE, boxWidget, FALSE);
|
||||
setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
|
||||
setCDKButtonboxURChar (buttonWidget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* We need to set the lower left and right
|
||||
* characters of the widget.
|
||||
*/
|
||||
setCDKTemplateLLChar (widget, ACS_LTEE);
|
||||
setCDKTemplateLRChar (widget, ACS_RTEE);
|
||||
|
||||
/*
|
||||
* Bind the Tab key in the widget to send a
|
||||
* Tab key to the button box widget.
|
||||
*/
|
||||
bindCDKObject (vTEMPLATE, widget, KEY_TAB, widgetCB, buttonWidget);
|
||||
bindCDKObject (vTEMPLATE, widget, CDK_NEXT, widgetCB, buttonWidget);
|
||||
bindCDKObject (vTEMPLATE, widget, CDK_PREV, widgetCB, buttonWidget);
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Draw the button widget. */
|
||||
drawCDKButtonbox (buttonWidget, boxWidget);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the user asked for a shadow, we need to create one. Do this instead
|
||||
* of using the shadow parameter because the button widget is not part of
|
||||
* the main widget and if the user asks for both buttons and a shadow, we
|
||||
* need to create a shadow big enough for both widgets. Create the shadow
|
||||
* window using the widgets shadowWin element, so screen refreshes will draw
|
||||
* them as well.
|
||||
*/
|
||||
if (shadowWidget == TRUE)
|
||||
{
|
||||
/* Determine the height of the shadow window. */
|
||||
shadowHeight = (buttonWidget == 0 ?
|
||||
widget->boxHeight :
|
||||
widget->boxHeight + buttonWidget->boxHeight - 1);
|
||||
|
||||
/* Create the shadow window. */
|
||||
widget->shadowWin = newwin (shadowHeight,
|
||||
widget->boxWidth,
|
||||
getbegy (widget->win) + 1,
|
||||
getbegx (widget->win) + 1);
|
||||
|
||||
/* Make sure we could have created the shadow window. */
|
||||
if (widget->shadowWin != 0)
|
||||
{
|
||||
widget->shadow = TRUE;
|
||||
|
||||
/*
|
||||
* We force the widget and buttonWidget to be drawn so the
|
||||
* buttonbox widget will be drawn when the widget is activated.
|
||||
* Otherwise the shadow window will draw over the button widget.
|
||||
*/
|
||||
drawCDKTemplate (widget, ObjOf (widget)->box);
|
||||
eraseCDKButtonbox (buttonWidget);
|
||||
drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKTemplateBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* If a default answer were proivded, set it in the widget. */
|
||||
if (defaultAnswer != 0)
|
||||
{
|
||||
setCDKTemplateValue (widget, defaultAnswer);
|
||||
}
|
||||
|
||||
/* If the user asked for a minimum value, set it. */
|
||||
setCDKTemplateMin (widget, minimum);
|
||||
|
||||
/* Activate the widget. */
|
||||
tmp = activateCDKTemplate (widget, 0);
|
||||
|
||||
/* If the user asked for plate mixing, give it to them. */
|
||||
if (mixPlate == TRUE)
|
||||
{
|
||||
answer = mixCDKTemplate (widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
answer = copyChar (tmp);
|
||||
}
|
||||
|
||||
/* If there were buttons, get the button selected. */
|
||||
if (buttonWidget != 0)
|
||||
{
|
||||
selection = buttonWidget->currentButton;
|
||||
destroyCDKButtonbox (buttonWidget);
|
||||
}
|
||||
|
||||
/* End CDK. */
|
||||
destroyCDKTemplate (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Print the value from the widget. */
|
||||
if (answer != 0)
|
||||
{
|
||||
fprintf (fp, "%s\n", answer);
|
||||
freeChar (answer);
|
||||
}
|
||||
fclose (fp);
|
||||
|
||||
/* Exit with the button number picked. */
|
||||
ExitProgram (selection);
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED,
|
||||
void *object GCC_UNUSED,
|
||||
void *clientData,
|
||||
chtype key)
|
||||
{
|
||||
CDKBUTTONBOX *buttonbox = (CDKBUTTONBOX *)clientData;
|
||||
(void) injectCDKButtonbox (buttonbox, key);
|
||||
return (TRUE);
|
||||
}
|
285
deps/cdk-5.0-20161210/cli/cdkviewer.c
vendored
Normal file
285
deps/cdk-5.0-20161210/cli/cdkviewer.c
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
/* $Id: cdkviewer.c,v 1.15 2016/12/04 15:22:16 tom Exp $ */
|
||||
|
||||
#include <cdk_test.h>
|
||||
|
||||
#ifdef XCURSES
|
||||
char *XCursesProgramName = "cdkviewer";
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declare file local prototypes.
|
||||
*/
|
||||
static void saveInformation (CDKVIEWER *widget);
|
||||
static int dumpViewer (CDKVIEWER *widget, char *filename);
|
||||
static int widgetCB (EObjectType cdktype, void *object, void *clientData, chtype key);
|
||||
|
||||
/*
|
||||
* Define file local variables.
|
||||
*/
|
||||
static const char *FPUsage = "-f filename [-i Interpret] [-l Show Line Stats] [-T Title] [-B Buttons] [-X X Position] [-Y Y Position] [-H Height] [-W Width] [-N] [-S]";
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKSCREEN *cdkScreen = 0;
|
||||
CDKVIEWER *widget = 0;
|
||||
char *filename = 0;
|
||||
char *CDK_WIDGET_COLOR = 0;
|
||||
char *temp = 0;
|
||||
chtype *holder = 0;
|
||||
int answer = 0;
|
||||
int messageLines = -1;
|
||||
int buttonCount = 0;
|
||||
char **messageList = 0;
|
||||
char **buttonList = 0;
|
||||
char tempTitle[256];
|
||||
int j1, j2;
|
||||
|
||||
CDK_PARAMS params;
|
||||
boolean boxWidget;
|
||||
boolean interpret;
|
||||
boolean shadowWidget;
|
||||
boolean showInfoLine;
|
||||
char *buttons;
|
||||
char *title;
|
||||
int height;
|
||||
int width;
|
||||
int xpos;
|
||||
int ypos;
|
||||
|
||||
CDKparseParams (argc, argv, ¶ms, "f:il:B:T:" CDK_CLI_PARAMS);
|
||||
|
||||
/* *INDENT-EQLS* */
|
||||
xpos = CDKparamValue (¶ms, 'X', CENTER);
|
||||
ypos = CDKparamValue (¶ms, 'Y', CENTER);
|
||||
height = CDKparamValue (¶ms, 'H', 20);
|
||||
width = CDKparamValue (¶ms, 'W', 60);
|
||||
boxWidget = CDKparamValue (¶ms, 'N', TRUE);
|
||||
shadowWidget = CDKparamValue (¶ms, 'S', FALSE);
|
||||
interpret = CDKparamValue (¶ms, 'i', FALSE);
|
||||
showInfoLine = CDKparamValue (¶ms, 'l', FALSE);
|
||||
filename = CDKparamString (¶ms, 'f');
|
||||
buttons = CDKparamString (¶ms, 'B');
|
||||
title = CDKparamString (¶ms, 'T');
|
||||
|
||||
/* Make sure they gave us a file to read. */
|
||||
if (filename == 0)
|
||||
{
|
||||
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Read the file in. */
|
||||
messageLines = CDKreadFile (filename, &messageList);
|
||||
|
||||
/* Check if there was an error. */
|
||||
if (messageLines == -1)
|
||||
{
|
||||
fprintf (stderr, "Error: Could not open the file %s\n", filename);
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Set up the buttons of the viewer. */
|
||||
if (buttons == 0)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
buttonList = calloc(sizeof(char *), 3);
|
||||
buttonList[0] = copyChar ("OK");
|
||||
buttonList[1] = copyChar ("Cancel");
|
||||
buttonCount = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Split the button list up. */
|
||||
buttonList = CDKsplitString (buttons, '\n');
|
||||
buttonCount = (int)CDKcountStrings ((CDK_CSTRING2)buttonList);
|
||||
}
|
||||
|
||||
/* Set up the title of the viewer. */
|
||||
if (title == 0)
|
||||
{
|
||||
sprintf (tempTitle, "<C>Filename: </U>%s<!U>", filename);
|
||||
title = copyChar (tempTitle);
|
||||
}
|
||||
|
||||
cdkScreen = initCDKScreen (NULL);
|
||||
|
||||
/* Start color. */
|
||||
initCDKColor ();
|
||||
|
||||
/* Check if the user wants to set the background of the main screen. */
|
||||
if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0)
|
||||
{
|
||||
holder = char2Chtype (temp, &j1, &j2);
|
||||
wbkgd (cdkScreen->window, holder[0]);
|
||||
wrefresh (cdkScreen->window);
|
||||
freeChtype (holder);
|
||||
}
|
||||
|
||||
/* Get the widget color background color. */
|
||||
if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0)
|
||||
{
|
||||
CDK_WIDGET_COLOR = 0;
|
||||
}
|
||||
|
||||
/* Create the viewer widget. */
|
||||
widget = newCDKViewer (cdkScreen, xpos, ypos, height, width,
|
||||
(CDK_CSTRING2)buttonList, buttonCount, A_REVERSE,
|
||||
boxWidget, shadowWidget);
|
||||
|
||||
/* Check to make sure we created the file viewer. */
|
||||
if (widget == 0)
|
||||
{
|
||||
CDKfreeStrings (messageList);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
/* Shut down curses and CDK. */
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
fprintf (stderr,
|
||||
"Error: Could not create the file viewer. "
|
||||
"Is the window too small?\n");
|
||||
|
||||
ExitProgram (CLI_ERROR);
|
||||
}
|
||||
|
||||
/* Check if the user wants to set the background of the widget. */
|
||||
setCDKViewerBackgroundColor (widget, CDK_WIDGET_COLOR);
|
||||
|
||||
/* Set a binding for saving the info. */
|
||||
bindCDKObject (vVIEWER, widget, 'S', widgetCB, 0);
|
||||
|
||||
/* Set the information needed for the viewer. */
|
||||
setCDKViewer (widget, title, (CDK_CSTRING2)messageList, messageLines,
|
||||
A_REVERSE, interpret, showInfoLine, TRUE);
|
||||
|
||||
/* Activate the viewer. */
|
||||
answer = activateCDKViewer (widget, 0);
|
||||
|
||||
CDKfreeStrings (messageList);
|
||||
CDKfreeStrings (buttonList);
|
||||
|
||||
destroyCDKViewer (widget);
|
||||
destroyCDKScreen (cdkScreen);
|
||||
endCDK ();
|
||||
|
||||
/* Exit with the button number picked. */
|
||||
ExitProgram (answer);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function allows the user to dump the
|
||||
* information from the viewer into a file.
|
||||
*/
|
||||
static void saveInformation (CDKVIEWER *widget)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
CDKENTRY *entry = 0;
|
||||
char *filename = 0;
|
||||
char temp[256];
|
||||
const char *mesg[10];
|
||||
int linesSaved;
|
||||
|
||||
/* Create the entry field to get the filename. */
|
||||
entry = newCDKEntry (ScreenOf (widget), CENTER, CENTER,
|
||||
"<C></B/5>Enter the filename of the save file.",
|
||||
"Filename: ",
|
||||
A_NORMAL, '_', vMIXED,
|
||||
20, 1, 256,
|
||||
TRUE, FALSE);
|
||||
|
||||
/* Get the filename. */
|
||||
filename = activateCDKEntry (entry, 0);
|
||||
|
||||
/* Did they hit escape? */
|
||||
if (entry->exitType == vESCAPE_HIT)
|
||||
{
|
||||
/* Popup a message. */
|
||||
mesg[0] = "<C></B/5>Save Canceled.";
|
||||
mesg[1] = "<C>Escape hit. Scrolling window information not saved.";
|
||||
mesg[2] = " ";
|
||||
mesg[3] = "<C>Press any key to continue.";
|
||||
popupLabel (ScreenOf (widget), (CDK_CSTRING2)mesg, 4);
|
||||
|
||||
destroyCDKEntry (entry);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write the contents of the viewer to the file. */
|
||||
linesSaved = dumpViewer (widget, filename);
|
||||
|
||||
/* Was the save successful? */
|
||||
if (linesSaved == -1)
|
||||
{
|
||||
/* Nope, tell 'em. */
|
||||
mesg[0] = "<C></B/16>Error";
|
||||
mesg[1] = "<C>Could not save to the file.";
|
||||
sprintf (temp, "<C>(%s)", filename);
|
||||
mesg[2] = temp;
|
||||
mesg[3] = " ";
|
||||
mesg[4] = "<C>Press any key to continue.";
|
||||
popupLabel (ScreenOf (widget), (CDK_CSTRING2)mesg, 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *msg_1;
|
||||
|
||||
mesg[0] = "<C></B/5>Save Successful";
|
||||
sprintf (temp, "<C>There were %d lines saved to the file", linesSaved);
|
||||
mesg[1] = msg_1 = copyChar (temp);
|
||||
sprintf (temp, "<C>(%s)", filename);
|
||||
mesg[2] = temp;
|
||||
mesg[3] = " ";
|
||||
mesg[4] = "<C>Press any key to continue.";
|
||||
popupLabel (ScreenOf (widget), (CDK_CSTRING2)mesg, 5);
|
||||
freeChar (msg_1);
|
||||
}
|
||||
|
||||
destroyCDKEntry (entry);
|
||||
eraseCDKScreen (ScreenOf (widget));
|
||||
drawCDKScreen (ScreenOf (widget));
|
||||
}
|
||||
|
||||
/*
|
||||
* This actually dumps the information from the viewer to a file.
|
||||
*/
|
||||
static int dumpViewer (CDKVIEWER *widget, char *filename)
|
||||
{
|
||||
/* *INDENT-EQLS* */
|
||||
FILE *outputFile = 0;
|
||||
char *rawLine = 0;
|
||||
int listSize;
|
||||
chtype **list = getCDKViewerInfo (widget, &listSize);
|
||||
int x;
|
||||
|
||||
/* Try to open the file. */
|
||||
if ((outputFile = fopen (filename, "w")) == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Start writing out the file. */
|
||||
for (x = 0; x < listSize; x++)
|
||||
{
|
||||
rawLine = chtype2Char (list[x]);
|
||||
fprintf (outputFile, "%s\n", rawLine);
|
||||
freeChar (rawLine);
|
||||
}
|
||||
|
||||
/* Close the file and return the number of lines written. */
|
||||
fclose (outputFile);
|
||||
return listSize;
|
||||
}
|
||||
|
||||
static int widgetCB (EObjectType cdktype GCC_UNUSED, void *object,
|
||||
void *clientData GCC_UNUSED,
|
||||
chtype key GCC_UNUSED)
|
||||
{
|
||||
CDKVIEWER *widget = (CDKVIEWER *)object;
|
||||
saveInformation (widget);
|
||||
return (TRUE);
|
||||
}
|
116
deps/cdk-5.0-20161210/cli/samples/alphalist.sh
vendored
Executable file
116
deps/cdk-5.0-20161210/cli/samples/alphalist.sh
vendored
Executable file
@@ -0,0 +1,116 @@
|
||||
#!/bin/sh
|
||||
# $Id: alphalist.sh,v 1.7 2005/12/27 16:04:57 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the alphalist widget.
|
||||
#
|
||||
|
||||
#
|
||||
# This gets the password file.
|
||||
#
|
||||
getPasswordFile()
|
||||
{
|
||||
system=$1
|
||||
file=$2
|
||||
|
||||
#
|
||||
# Depeding on the system, get the password file
|
||||
# using nicat, ypcat, or just plain old /etc/passwd
|
||||
#
|
||||
if [ "$system" = "NIS" ]; then
|
||||
niscat passwd.org_dir > $file
|
||||
elif [ "$system" = "YP" ]; then
|
||||
ypcat passwd > $file
|
||||
else
|
||||
cp /etc/passwd $file
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This displays account information.
|
||||
#
|
||||
displayAccountInformation()
|
||||
{
|
||||
userAccount=$1
|
||||
passwordFile=$2
|
||||
|
||||
#
|
||||
# Get the user account information.
|
||||
#
|
||||
line=`grep "^${userAccount}" $passwordFile`
|
||||
uid=`echo $line | cut -d: -f3`
|
||||
gid=`echo $line | cut -d: -f4`
|
||||
info=`echo $line | cut -d: -f5`
|
||||
home=`echo $line | cut -d: -f6`
|
||||
shell=`echo $line | cut -d: -f7`
|
||||
|
||||
#
|
||||
# Create the label message information.
|
||||
#
|
||||
accountMessage="<C></U>Account
|
||||
<C><#HL(30)>
|
||||
Account: </U>${userAccount}
|
||||
UID : </U>${uid}
|
||||
GID : </U>${gid}
|
||||
Info : </U>${info}
|
||||
Home : </U>${home}
|
||||
Shell : </U>${shell}
|
||||
<C><#HL(30)>
|
||||
<C>Hit </R>space<!R> to continue"
|
||||
|
||||
#
|
||||
# Create the popup label.
|
||||
#
|
||||
${CDK_LABEL} -m "${accountMessage}" -p " "
|
||||
}
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_ALPHALIST="${CDK_BINDIR=..}/cdkalphalist"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
tmpPass="${TMPDIR=/tmp}/sl.$$"
|
||||
output="${TMPDIR=/tmp}/alphalist.$$"
|
||||
userAccounts="${TMPDIR=/tmp}/ua.$$"
|
||||
|
||||
#
|
||||
# Create the message for the scrolling list.
|
||||
#
|
||||
title="<C>Pick an account
|
||||
<C>you want to view."
|
||||
|
||||
#
|
||||
# Get the password file and stick it into the temp file.
|
||||
#
|
||||
#getPasswordFile "YP" "$tmpPass"
|
||||
#getPasswordFile "NIS" "$tmpPass"
|
||||
getPasswordFile "Other" "$tmpPass"
|
||||
|
||||
#
|
||||
# Get the user account from the password file.
|
||||
#
|
||||
awk 'BEGIN {FS=":"} {printf "%s\n", $1}' $tmpPass | sort > ${userAccounts}
|
||||
|
||||
#
|
||||
# Create the scrolling list.
|
||||
#
|
||||
${CDK_ALPHALIST} -T "${title}" -f ${userAccounts} -H -10 -W -20 2> ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`sed -e 's/^[ ]*//' -e 's/[ ]*$//' ${output}`
|
||||
|
||||
#
|
||||
# Display the account information.
|
||||
#
|
||||
if [ -n "$answer" ]; then
|
||||
displayAccountInformation $answer $tmpPass
|
||||
fi
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${output} ${tmpPass} ${userAccounts}
|
89
deps/cdk-5.0-20161210/cli/samples/calendar.sh
vendored
Executable file
89
deps/cdk-5.0-20161210/cli/samples/calendar.sh
vendored
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/bin/sh
|
||||
# $Id: calendar.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the celendar widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_CALENDAR="${CDK_BINDIR=..}/cdkcalendar"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
date="${TMPDIR=/tmp}/cal.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
xpos=CENTER
|
||||
ypos=CENTER
|
||||
|
||||
#
|
||||
# Get today's date.
|
||||
#
|
||||
day=`date +%d`
|
||||
month=`date +%m`
|
||||
year=`date +%Y`
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt d:m:y:X:Y: $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-d) day=$2; shift 2;;
|
||||
-m) month=$2; shift 2;;
|
||||
-y) year=$2; shift 2;;
|
||||
-X) xpos=$2; shift 2;;
|
||||
-Y) ypos=$2; shift 2;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the title and buttons.
|
||||
#
|
||||
title="<C><#HL(22)>
|
||||
<C>Select a date
|
||||
<C><#HL(22)>"
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the calendar widget.
|
||||
#
|
||||
${CDK_CALENDAR} -B "${buttons}" -d ${day} -m ${month} -y ${year} -T "${title}" -X ${xpos} -Y ${ypos} -O ${date} -S
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${date}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>You chose the following date" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C><#HL(10)>" >> ${tmp}
|
||||
echo "<C>${answer}" >> ${tmp}
|
||||
echo "<C><#HL(10)>" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${date}
|
88
deps/cdk-5.0-20161210/cli/samples/dialog.sh
vendored
Executable file
88
deps/cdk-5.0-20161210/cli/samples/dialog.sh
vendored
Executable file
@@ -0,0 +1,88 @@
|
||||
#!/bin/sh
|
||||
# $Id: dialog.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the dialog widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_DIALOG="${CDK_BINDIR=..}/cdkdialog"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/dialog_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the message for the scrolling list.
|
||||
#
|
||||
message="<C>Pick which command
|
||||
<C>you wish to run."
|
||||
|
||||
#
|
||||
# Create the button labels.
|
||||
#
|
||||
commands="</B>who
|
||||
</B>w
|
||||
</B>uptime
|
||||
</B>date
|
||||
</B>pwd
|
||||
</B>whoami
|
||||
</B>df
|
||||
</B>fortune"
|
||||
|
||||
#
|
||||
# Create the dialog box.
|
||||
#
|
||||
${CDK_DIALOG} -m "${message}" -B "${commands}" 2> ${output}
|
||||
selection=$?
|
||||
if [ "$selection" -eq 255 ]; then
|
||||
exit;
|
||||
fi
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the result of the command" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
|
||||
#
|
||||
# Determine which command to run.
|
||||
#
|
||||
if [ "${selection}" -eq 0 ]; then
|
||||
who | awk '{printf "</B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 1 ]; then
|
||||
w | awk '{printf "</B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 2 ]; then
|
||||
uptime | awk '{printf "<C></B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 3 ]; then
|
||||
date | awk '{printf "<C></B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 4 ]; then
|
||||
pwd | awk '{printf "<C></B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 5 ]; then
|
||||
whoami | awk '{printf "<C></B>%s\n", $0}' >> ${tmp}
|
||||
elif [ "${selection}" -eq 6 ]; then
|
||||
#
|
||||
# We will use the label demo to do this.
|
||||
#
|
||||
./label.sh
|
||||
rm -f ${tmp} ${output} ${fileSystemList}
|
||||
exit 0;
|
||||
elif [ "${selection}" -eq 7 ]; then
|
||||
fortune | awk '{printf "</B>%s\n", $0}' >> ${tmp}
|
||||
fi
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output} ${fileSystemList}
|
54
deps/cdk-5.0-20161210/cli/samples/entry.sh
vendored
Executable file
54
deps/cdk-5.0-20161210/cli/samples/entry.sh
vendored
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# $Id: entry.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the entry widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_ENTRY="${CDK_BINDIR=..}/cdkentry"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/entry_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the title.
|
||||
#
|
||||
title="<C> Type a simple string. "
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the entry box.
|
||||
#
|
||||
${CDK_ENTRY} -f 20 -T "${title}" -B "${buttons}" -F "</5>_ " -O ${output} -S
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the string you typed in" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C></R>${answer}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output}
|
82
deps/cdk-5.0-20161210/cli/samples/fselect.sh
vendored
Executable file
82
deps/cdk-5.0-20161210/cli/samples/fselect.sh
vendored
Executable file
@@ -0,0 +1,82 @@
|
||||
#!/bin/sh
|
||||
# $Id: fselect.sh,v 1.4 2005/12/27 17:56:05 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the file selection widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_FSELECT="${CDK_BINDIR=..}/cdkfselect"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
directory="."
|
||||
label="File: "
|
||||
title="<C>Select a file"
|
||||
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
xpos="CENTER"
|
||||
ypos="CENTER"
|
||||
|
||||
width=0
|
||||
height=-5
|
||||
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
file="${TMPDIR=/tmp}/fs.$$"
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt d:L:T:X:Y:W:H: $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-d) directory=$2; shift 2;;
|
||||
-T) title=$2; shift 2;;
|
||||
-L) label=$2; shift 2;;
|
||||
-X) xpos=$2; shift 2;;
|
||||
-Y) ypos=$2; shift 2;;
|
||||
-W) width=$2; shift 2;;
|
||||
-H) height=$2; shift 2;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the CDK file selector.
|
||||
#
|
||||
${CDK_FSELECT} -d "${directory}" -T "${title}" -L "${label}" -X ${xpos} -Y ${ypos} -W ${width} -H ${height} -B "${buttons}" 2> ${file}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${file}`
|
||||
|
||||
#
|
||||
# Diplay the file the user selected.
|
||||
#
|
||||
echo "<C>You selected the following file" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C><#HL(10)>" >> ${tmp}
|
||||
echo "<C></B>${answer}" >> ${tmp}
|
||||
echo "<C><#HL(10)>" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Press </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${file}
|
135
deps/cdk-5.0-20161210/cli/samples/itemlist.sh
vendored
Executable file
135
deps/cdk-5.0-20161210/cli/samples/itemlist.sh
vendored
Executable file
@@ -0,0 +1,135 @@
|
||||
#!/bin/sh
|
||||
# $Id: itemlist.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the itemlist list widget.
|
||||
#
|
||||
|
||||
#
|
||||
# This gets the password file.
|
||||
#
|
||||
getPasswordFile()
|
||||
{
|
||||
system=$1
|
||||
file=$2
|
||||
|
||||
#
|
||||
# Depeding on the system, get the password file
|
||||
# using nicat, ypcat, or just plain old /etc/passwd
|
||||
#
|
||||
if [ "$system" = "NIS" ]; then
|
||||
niscat passwd.org_dir | sort > $file
|
||||
elif [ "$system" = "YP" ]; then
|
||||
ypcat passwd | sort > $file
|
||||
else
|
||||
sort /etc/passwd > $file
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This displays account information.
|
||||
#
|
||||
displayAccountInformation()
|
||||
{
|
||||
userAccount=$1
|
||||
passwordFile=$2
|
||||
|
||||
#
|
||||
# Get the user account information.
|
||||
#
|
||||
line=`grep "^${userAccount}" $passwordFile`
|
||||
uid=`echo $line | cut -d: -f3`
|
||||
gid=`echo $line | cut -d: -f4`
|
||||
info=`echo $line | cut -d: -f5`
|
||||
home=`echo $line | cut -d: -f6`
|
||||
shell=`echo $line | cut -d: -f7`
|
||||
|
||||
#
|
||||
# Create the label message information.
|
||||
#
|
||||
accountMessage="<C></U>Account
|
||||
<C><#HL(30)>
|
||||
Account: </U>${userAccount}
|
||||
UID : </U>${uid}
|
||||
GID : </U>${gid}
|
||||
Info : </U>${info}
|
||||
Home : </U>${home}
|
||||
Shell : </U>${shell}
|
||||
<C><#HL(30)>
|
||||
<C>Hit </R>space<!R> to continue"
|
||||
|
||||
#
|
||||
# Create the popup label.
|
||||
#
|
||||
${CDK_LABEL} -m "${accountMessage}" -p " "
|
||||
}
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_ITEMLIST="${CDK_BINDIR=..}/cdkitemlist"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
tmpPass="${TMPDIR=/tmp}/sl.$$"
|
||||
output="${TMPDIR=/tmp}/output.$$"
|
||||
userAccounts="${TMPDIR=/tmp}/ua.$$"
|
||||
|
||||
TYPE="Other";
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt nNh $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-n) TYPE="YP"; shift;;
|
||||
-N) TYPE="NIS"; shift;;
|
||||
-h) echo "$0 [-n YP] [-N NIS+] [-h]"; exit 0;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the message for the item list.
|
||||
#
|
||||
title="<C>Pick an account you want to view."
|
||||
label="Account Name "
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Get the password file and stick it into the temp file.
|
||||
#
|
||||
getPasswordFile "${TYPE}" "$tmpPass"
|
||||
|
||||
#
|
||||
# Get the user account from the password file.
|
||||
#
|
||||
awk 'BEGIN {FS=":"} {printf "</R>%s\n", $1}' $tmpPass | sort > ${userAccounts}
|
||||
|
||||
#
|
||||
# Create the item list.
|
||||
#
|
||||
${CDK_ITEMLIST} -d 3 -L "${label}" -T "${title}" -B "${buttons}" -f "${userAccounts}" 2> ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Display the account information.
|
||||
#
|
||||
displayAccountInformation $answer $tmpPass
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${output} ${tmpPass} ${userAccounts}
|
81
deps/cdk-5.0-20161210/cli/samples/label.sh
vendored
Executable file
81
deps/cdk-5.0-20161210/cli/samples/label.sh
vendored
Executable file
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
# $Id: label.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the label widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
dfTmp="${TMPDIR=/tmp}/label.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
top="${TMPDIR=/tmp}/dfTop.$$"
|
||||
bottom="${TMPDIR=/tmp}/dfBottom.$$"
|
||||
|
||||
#
|
||||
# Get the filesystem information.
|
||||
#
|
||||
getDiskInfo()
|
||||
{
|
||||
fileName=$1;
|
||||
command="df"
|
||||
|
||||
#
|
||||
# Determine the type of operating system.
|
||||
#
|
||||
machine=`uname -s`
|
||||
if [ "$machine" = "SunOS" ]; then
|
||||
level=`uname -r`
|
||||
|
||||
if [ "$level" -gt 4 ]; then
|
||||
command="df -kl"
|
||||
fi
|
||||
else
|
||||
if [ "$machine" = "AIX" ]; then
|
||||
command="df -i"
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Run the command.
|
||||
#
|
||||
${command} > ${fileName}
|
||||
}
|
||||
|
||||
#
|
||||
# Get the disk information.
|
||||
#
|
||||
getDiskInfo ${dfTmp}
|
||||
|
||||
#
|
||||
# Bold the first line of the df command.
|
||||
#
|
||||
head -1 ${dfTmp} | awk '{printf "</B>%s\n", $0}' > ${top}
|
||||
tail +2 ${dfTmp} > ${bottom}
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>This is the current" > ${tmp}
|
||||
echo "<C>status of your local filesystems." >> ${tmp}
|
||||
echo "<C><#HL(2)>" >> ${tmp}
|
||||
cat ${top} >> ${tmp}
|
||||
cat ${bottom} >> ${tmp}
|
||||
echo "<C><#HL(2)>" >> ${tmp}
|
||||
echo "" >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f "${tmp}" -p " " -c "ls" -S
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output} ${dfTmp} ${top} ${bottom}
|
123
deps/cdk-5.0-20161210/cli/samples/matrix.sh
vendored
Executable file
123
deps/cdk-5.0-20161210/cli/samples/matrix.sh
vendored
Executable file
@@ -0,0 +1,123 @@
|
||||
#!/bin/sh
|
||||
# $Id: matrix.sh,v 1.4 2005/12/27 17:07:00 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the matrix widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_MATRIX="${CDK_BINDIR=..}/cdkmatrix"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
fileSystemList="${TMPDIR=/tmp}/fsList.$$"
|
||||
info="${TMPDIR=/tmp}/fsInfo.$$"
|
||||
diskInfo="${TMPDIR=/tmp}/diskInfo.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Get the filesystem information.
|
||||
#
|
||||
getDiskInfo()
|
||||
{
|
||||
fileName=$1;
|
||||
command="df"
|
||||
|
||||
#
|
||||
# Determine the type of operating system.
|
||||
#
|
||||
machine=`uname -s`
|
||||
if [ "$machine" = "SunOS" ]; then
|
||||
level=`uname -r`
|
||||
|
||||
if [ "$level" -gt 4 ]; then
|
||||
command="df -kl"
|
||||
fi
|
||||
else
|
||||
if [ "$machine" = "AIX" ]; then
|
||||
command="df -i"
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Run the command.
|
||||
#
|
||||
${command} > ${fileName}
|
||||
}
|
||||
|
||||
#
|
||||
# Get the disk information.
|
||||
#
|
||||
getDiskInfo ${diskInfo}
|
||||
|
||||
#
|
||||
# Create the row titles.
|
||||
#
|
||||
rowTitles=`tail +2 ${diskInfo} | awk '{printf "%s\n", $1}'`
|
||||
|
||||
#
|
||||
# Create the column titles.
|
||||
#
|
||||
colTitles="KBytes
|
||||
Used
|
||||
Avail
|
||||
Capacity
|
||||
Mounted on"
|
||||
|
||||
#
|
||||
# Define the matrix title.
|
||||
#
|
||||
title="<C></U>Current Filesystem Information"
|
||||
|
||||
#
|
||||
# Create the data file to fill in the matrix.
|
||||
#
|
||||
tail +2 ${diskInfo} | awk '{printf "%s%s%s%s%s\n", $2, $3, $4, $5, $6}' > ${info}
|
||||
|
||||
#
|
||||
# Set the widths of the columns.
|
||||
#
|
||||
colWidths="5
|
||||
5
|
||||
5
|
||||
5
|
||||
5"
|
||||
|
||||
#
|
||||
# Set the cells as uneditable.
|
||||
#
|
||||
types="VIEWONLY
|
||||
VIEWONLY
|
||||
VIEWONLY
|
||||
VIEWONLY
|
||||
VIEWONLY"
|
||||
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Start the matrix.
|
||||
#
|
||||
${CDK_MATRIX} -r "${rowTitles}" -c "${colTitles}" -v 3 -w "${colWidths}" -d "${info}" -t "${types}" -T "${title}" -B "${buttons}" -O"$tmp"
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>You chose button #${selected}" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f "${tmp}" -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${info} ${fileSystemList} ${tmp} ${diskInfo}
|
54
deps/cdk-5.0-20161210/cli/samples/mentry.sh
vendored
Executable file
54
deps/cdk-5.0-20161210/cli/samples/mentry.sh
vendored
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/bin/sh
|
||||
# $Id: mentry.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the multiple line entry widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_MENTRY="${CDK_BINDIR=..}/cdkmentry"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/mentry_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the title.
|
||||
#
|
||||
title="<C>Type in a short message."
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the mentry box.
|
||||
#
|
||||
${CDK_MENTRY} -s 5 -v 10 -f 20 -T "${title}" -B "${buttons}" -F '_' -O ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the message you typed in" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C></R>${answer}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output}
|
95
deps/cdk-5.0-20161210/cli/samples/radio.sh
vendored
Executable file
95
deps/cdk-5.0-20161210/cli/samples/radio.sh
vendored
Executable file
@@ -0,0 +1,95 @@
|
||||
#!/bin/sh
|
||||
# $Id: radio.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the radio widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_RADIO="${CDK_BINDIR=..}/cdkradio"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
fileSystemList="${TMPDIR=/tmp}/fsList.$$"
|
||||
diskInfo="${TMPDIR=/tmp}/diskInfo.$$"
|
||||
output="${TMPDIR=/tmp}/radio_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Get the filesystem information.
|
||||
#
|
||||
getDiskInfo()
|
||||
{
|
||||
fileName=$1;
|
||||
command="df"
|
||||
|
||||
#
|
||||
# Determine the type of operating system.
|
||||
#
|
||||
machine=`uname -s`
|
||||
if [ "$machine" = "SunOS" ]; then
|
||||
level=`uname -r`
|
||||
|
||||
if [ "$level" -gt 4 ]; then
|
||||
command="df -kl"
|
||||
fi
|
||||
else
|
||||
if [ "$machine" = "AIX" ]; then
|
||||
command="df -i"
|
||||
fi
|
||||
fi
|
||||
|
||||
#
|
||||
# Run the command.
|
||||
#
|
||||
${command} > ${fileName}
|
||||
}
|
||||
|
||||
#
|
||||
# Create the title for the scrolling list.
|
||||
#
|
||||
title="<C>Pick a filesystem to view."
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Get a list of the local filesystems.
|
||||
#
|
||||
getDiskInfo ${diskInfo}
|
||||
|
||||
#
|
||||
# Create the file system list.
|
||||
#
|
||||
grep "^/" ${diskInfo} | awk '{printf "%s\n", $1}' > ${fileSystemList}
|
||||
|
||||
#
|
||||
# Create the radio list.
|
||||
#
|
||||
${CDK_RADIO} -T "${title}" -f "${fileSystemList}" -c "</U>*" -B "${buttons}" 2> $output
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
#
|
||||
# The selection is now in the file $output.
|
||||
#
|
||||
fs=`cat ${output}`
|
||||
echo "<C></R>File Statistics on the filesystem ${fs}" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
grep "${fs}" ${diskInfo} | awk '{printf "</B>%s\n", $0}' >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output} ${fileSystemList} ${diskInfo}
|
55
deps/cdk-5.0-20161210/cli/samples/scale.sh
vendored
Executable file
55
deps/cdk-5.0-20161210/cli/samples/scale.sh
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
# $Id: scale.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the scale widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_SCALE="${CDK_BINDIR=..}/cdkscale"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/scale_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the title.
|
||||
#
|
||||
title="<C>Enter a value using the cursor keys."
|
||||
label="</R>Value"
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the scale box.
|
||||
#
|
||||
${CDK_SCALE} -f 20 -l 0 -h 100 -i 5 -L "${label}" -T "${title}" -B "${buttons}" -O ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the value you selected" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C></R>${answer}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output}
|
136
deps/cdk-5.0-20161210/cli/samples/scroll.sh
vendored
Executable file
136
deps/cdk-5.0-20161210/cli/samples/scroll.sh
vendored
Executable file
@@ -0,0 +1,136 @@
|
||||
#!/bin/sh
|
||||
# $Id: scroll.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the scrolling list widget.
|
||||
#
|
||||
|
||||
#
|
||||
# This gets the password file.
|
||||
#
|
||||
getPasswordFile()
|
||||
{
|
||||
system=$1
|
||||
file=$2
|
||||
|
||||
#
|
||||
# Depeding on the system, get the password file
|
||||
# using nicat, ypcat, or just plain old /etc/passwd
|
||||
#
|
||||
if [ "$system" = "NIS" ]; then
|
||||
niscat passwd.org_dir > $file
|
||||
elif [ "$system" = "YP" ]; then
|
||||
ypcat passwd > $file
|
||||
else
|
||||
cp /etc/passwd $file
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This displays account information.
|
||||
#
|
||||
displayAccountInformation()
|
||||
{
|
||||
userAccount=$1
|
||||
passwordFile=$2
|
||||
|
||||
#
|
||||
# Get the user account information.
|
||||
#
|
||||
line=`grep "^${userAccount}" $passwordFile`
|
||||
uid=`echo $line | cut -d: -f3`
|
||||
gid=`echo $line | cut -d: -f4`
|
||||
info=`echo $line | cut -d: -f5`
|
||||
home=`echo $line | cut -d: -f6`
|
||||
shell=`echo $line | cut -d: -f7`
|
||||
|
||||
#
|
||||
# Create the label message information.
|
||||
#
|
||||
accountMessage="<C></U>Account
|
||||
<C><#HL(30)>
|
||||
Account: </U>${userAccount}
|
||||
UID : </U>${uid}
|
||||
GID : </U>${gid}
|
||||
Info : </U>${info}
|
||||
Home : </U>${home}
|
||||
Shell : </U>${shell}
|
||||
<C><#HL(30)>
|
||||
<C>Hit </R>space<!R> to continue"
|
||||
|
||||
#
|
||||
# Create the popup label.
|
||||
#
|
||||
${CDK_LABEL} -m "${accountMessage}" -p " "
|
||||
}
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_SCROLL="${CDK_BINDIR=..}/cdkscroll"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
tmpPass="${TMPDIR=/tmp}/sl.$$"
|
||||
output="${TMPDIR=/tmp}/output.$$"
|
||||
userAccounts="${TMPDIR=/tmp}/ua.$$"
|
||||
|
||||
TYPE="Other"
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt nNh $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-n) TYPE="YP"; shift;;
|
||||
-N) TYPE="NIS"; shift;;
|
||||
-h) echo "$0 [-n YP] [-N NIS+] [-h]"; exit 0;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the message for the scrolling list.
|
||||
#
|
||||
title="<C><#HL(30)>
|
||||
<C>Pick an account you want to view.
|
||||
<C><#HL(30)>"
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Get the password file and stick it into the temp file.
|
||||
#
|
||||
getPasswordFile "${TYPE}" "$tmpPass"
|
||||
|
||||
#
|
||||
# Get the user account from the password file.
|
||||
#
|
||||
awk 'BEGIN {FS=":"} {printf "%s\n", $1}' $tmpPass | sort > ${userAccounts}
|
||||
|
||||
#
|
||||
# Create the scrolling list.
|
||||
#
|
||||
${CDK_SCROLL} -T "${title}" -f ${userAccounts} -n -B "${buttons}" 2> ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Display the account information.
|
||||
#
|
||||
displayAccountInformation $answer $tmpPass
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${output} ${tmpPass} ${userAccounts}
|
191
deps/cdk-5.0-20161210/cli/samples/selection.sh
vendored
Executable file
191
deps/cdk-5.0-20161210/cli/samples/selection.sh
vendored
Executable file
@@ -0,0 +1,191 @@
|
||||
#!/bin/sh
|
||||
# $Id: selection.sh,v 1.4 2005/12/27 17:56:58 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the selection widget.
|
||||
#
|
||||
|
||||
#
|
||||
# This gets the password file.
|
||||
#
|
||||
getPasswordFile()
|
||||
{
|
||||
system=$1
|
||||
file=$2
|
||||
|
||||
#
|
||||
# Depending on the system, get the password file
|
||||
# using nicat, ypcat, or just plain old /etc/passwd
|
||||
#
|
||||
if [ "$system" = "NIS" ]; then
|
||||
niscat passwd.org_dir > $file
|
||||
elif [ "$system" = "YP" ]; then
|
||||
ypcat passwd > $file
|
||||
else
|
||||
cp /etc/passwd $file
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This displays account information.
|
||||
#
|
||||
displayAccountInformation()
|
||||
{
|
||||
totalSelections=$1
|
||||
currentSelection=$2
|
||||
userAccount=$3
|
||||
passwordFile=$4
|
||||
|
||||
#
|
||||
# Get the user account information.
|
||||
#
|
||||
line=`grep "^${userAccount}" $passwordFile`
|
||||
uid=`echo $line | cut -d: -f3`
|
||||
gid=`echo $line | cut -d: -f4`
|
||||
info=`echo $line | cut -d: -f5`
|
||||
home=`echo $line | cut -d: -f6`
|
||||
shell=`echo $line | cut -d: -f7`
|
||||
|
||||
#
|
||||
# Create the label message information.
|
||||
#
|
||||
accountMessage="<C></U>Account ${currentSelection}/${totalSelections}
|
||||
<C><#HL(30)>
|
||||
Account: </U>${userAccount}
|
||||
UID : </U>${uid}
|
||||
GID : </U>${gid}
|
||||
Info : </U>${info}
|
||||
Home : </U>${home}
|
||||
Shell : </U>${shell}
|
||||
<C><#HL(30)>
|
||||
<C>Hit </R>space<!R> to continue"
|
||||
|
||||
#
|
||||
# Create the popup label.
|
||||
#
|
||||
${CDK_LABEL} -m "${accountMessage}" -p " "
|
||||
}
|
||||
|
||||
#
|
||||
# Define where the CDK widgets are.
|
||||
#
|
||||
CDK_SELECTION="${CDK_BINDIR=..}/cdkselection"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
TYPE="Other"
|
||||
|
||||
#
|
||||
# Define the output files.
|
||||
#
|
||||
accountList="${TMPDIR=/tmp}/accList.$$"
|
||||
userAccounts="${TMPDIR=/tmp}/userAccList.$$"
|
||||
output="${TMPDIR=/tmp}/selection_output.$$"
|
||||
tmpPass="${TMPDIR=/tmp}/ps.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt nNh $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-n) TYPE="YP"; shift;;
|
||||
-N) TYPE="NIS"; shift;;
|
||||
-h) echo "$0 [-n YP] [-N NIS+] [-h]"; exit 0;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the message for the selection list.
|
||||
#
|
||||
title="<C>Pick a user account to view."
|
||||
|
||||
#
|
||||
# Get the password file and stick it into the temp file.
|
||||
#
|
||||
getPasswordFile "${TYPE}" "$tmpPass"
|
||||
|
||||
#
|
||||
# Create the user account list.
|
||||
#
|
||||
awk 'BEGIN {FS=":"} {printf "%s\n", $1}' $tmpPass | sort > ${userAccounts}
|
||||
awk '{printf "<C></B>%s\n", $1}' ${userAccounts} > ${accountList}
|
||||
accounts=`cat ${userAccounts}`
|
||||
|
||||
#
|
||||
# Create the choices list.
|
||||
#
|
||||
choices="<C></B>No
|
||||
<C></B> Yes "
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the selection list.
|
||||
#
|
||||
${CDK_SELECTION} -T "${title}" -f "${accountList}" -c "${choices}" -B "${buttons}" 2> $output
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
#
|
||||
# Initialize the variables.
|
||||
#
|
||||
selection=""
|
||||
value=""
|
||||
|
||||
#
|
||||
# Count how many were selected.
|
||||
#
|
||||
count=`grep -c "^1" ${output}`
|
||||
current=0
|
||||
|
||||
#
|
||||
# Create the label.
|
||||
#
|
||||
for i in `cat ${output}`
|
||||
do
|
||||
#
|
||||
# Since every other variable is value/selection, we
|
||||
# store every other value in the correct variable.
|
||||
#
|
||||
if [ "$value" = "" ]; then
|
||||
value="$i"
|
||||
else
|
||||
selection="$i"
|
||||
|
||||
#
|
||||
# Only display the selected accounts.
|
||||
#
|
||||
if [ "$value" -eq 1 ]; then
|
||||
#
|
||||
# Increment our counter.
|
||||
#
|
||||
current=`expr $current + 1`
|
||||
|
||||
#
|
||||
# Display the account information.
|
||||
#
|
||||
displayAccountInformation $count $current $selection $tmpPass
|
||||
fi
|
||||
|
||||
#
|
||||
# Reset the variables.
|
||||
#
|
||||
value=""
|
||||
selection=""
|
||||
fi
|
||||
done
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${accountList} ${userAccounts} ${output} ${tmpPass} ${tmp}
|
55
deps/cdk-5.0-20161210/cli/samples/slider.sh
vendored
Executable file
55
deps/cdk-5.0-20161210/cli/samples/slider.sh
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
# $Id: slider.sh,v 1.4 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the slider widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_SLIDER="${CDK_BINDIR=..}/cdkslider"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/slider_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the title.
|
||||
#
|
||||
title="<C>Enter a value using the cursor keys"
|
||||
label="Value: "
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the slider box.
|
||||
#
|
||||
${CDK_SLIDER} -f 20 -l 0 -h 100 -i 5 -L "${label}" -T "${title}" -F "</R>*" -B "${buttons}" -O ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the value you selected" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C></R>${answer}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output}
|
55
deps/cdk-5.0-20161210/cli/samples/template.sh
vendored
Executable file
55
deps/cdk-5.0-20161210/cli/samples/template.sh
vendored
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
# $Id: template.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the template widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_TEMPLATE="${CDK_BINDIR=..}/cdktemplate"
|
||||
CDK_LABEL="${CDK_BINDIR=..}/cdklabel"
|
||||
|
||||
output="${TMPDIR=/tmp}/template_output.$$"
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
|
||||
#
|
||||
# Create the title.
|
||||
#
|
||||
title="<C> Type in the
|
||||
<C>IP Address for this machine."
|
||||
buttons=" OK
|
||||
Cancel "
|
||||
|
||||
#
|
||||
# Create the template box.
|
||||
#
|
||||
${CDK_TEMPLATE} -p "###.###.###.###" -o "___.___.___.___" -T "${title}" -P -B "${buttons}" 2> ${output}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${output}`
|
||||
|
||||
#
|
||||
# Create the message for the label widget.
|
||||
#
|
||||
echo "<C>Here is the IP you typed in" > ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C></R>${answer}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>You chose button #${selected}" >> ${tmp}
|
||||
echo " " >> ${tmp}
|
||||
echo "<C>Hit </R>space<!R> to continue." >> ${tmp}
|
||||
|
||||
#
|
||||
# Create the label widget to display the information.
|
||||
#
|
||||
${CDK_LABEL} -f ${tmp} -p " "
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${output}
|
76
deps/cdk-5.0-20161210/cli/samples/viewer.sh
vendored
Executable file
76
deps/cdk-5.0-20161210/cli/samples/viewer.sh
vendored
Executable file
@@ -0,0 +1,76 @@
|
||||
#!/bin/sh
|
||||
# $Id: viewer.sh,v 1.3 2005/12/27 15:53:06 tom Exp $
|
||||
|
||||
#
|
||||
# Description:
|
||||
# This demonstrates the CDK command line
|
||||
# interface to the viewer widget.
|
||||
#
|
||||
|
||||
#
|
||||
# Create some global variables.
|
||||
#
|
||||
CDK_FSELECT="${CDK_BINDIR=..}/cdkfselect"
|
||||
CDK_VIEWER="${CDK_BINDIR=..}/cdkviewer"
|
||||
|
||||
tmp="${TMPDIR=/tmp}/tmp.$$"
|
||||
file="${TMPDIR=/tmp}/fs.$$"
|
||||
|
||||
directory="."
|
||||
xpos=CENTER
|
||||
ypos=CENTER
|
||||
width="-2"
|
||||
height="0"
|
||||
interpret=0
|
||||
|
||||
#
|
||||
# Chop up the command line.
|
||||
#
|
||||
set -- `getopt d:x:y:w:h:i $*`
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo $USAGE
|
||||
exit 2
|
||||
fi
|
||||
for c in $*
|
||||
do
|
||||
case $c in
|
||||
-d) directory=$2; shift 2;;
|
||||
-x) xpos=$2; shift 2;;
|
||||
-y) ypos=$2; shift 2;;
|
||||
-w) width=$2; shift 2;;
|
||||
-h) height=$2; shift 2;;
|
||||
-i) interpret=1; shift 1;;
|
||||
--) shift; break;;
|
||||
esac
|
||||
done
|
||||
|
||||
#
|
||||
# Create the CDK file selector.
|
||||
#
|
||||
${CDK_FSELECT} -T "<C>Select a file" -d "${directory}" 2> ${file}
|
||||
selected=$?
|
||||
test $selected = 255 && exit 1
|
||||
|
||||
answer=`cat ${file}`
|
||||
|
||||
#
|
||||
# Create the title and buttons for the viewer.
|
||||
#
|
||||
title="<C>CDK File Viewer Widget
|
||||
<C></U>${answer}"
|
||||
buttons="OK"
|
||||
|
||||
#
|
||||
# Create the file viewer.
|
||||
#
|
||||
if [ "$interpret" -eq 1 ]; then
|
||||
${CDK_VIEWER} -f "${answer}" -T "${title}" -B "${buttons}" -i -X ${xpos} -Y ${ypos} -H "${height}" -W "${width}"
|
||||
else
|
||||
${CDK_VIEWER} -f "${answer}" -T "${title}" -B "${buttons}" -X ${xpos} -Y ${ypos} -H "${height}" -W "${width}" -B "${buttons}"
|
||||
fi
|
||||
|
||||
#
|
||||
# Clean up.
|
||||
#
|
||||
rm -f ${tmp} ${file}
|
686
deps/cdk-5.0-20161210/cli/utils/adduser
vendored
Executable file
686
deps/cdk-5.0-20161210/cli/utils/adduser
vendored
Executable file
@@ -0,0 +1,686 @@
|
||||
#!/bin/sh
|
||||
# $Id: adduser,v 1.3 2002/07/16 22:24:53 tom Exp $
|
||||
|
||||
#
|
||||
# Written by: Mike Glover, March 1997
|
||||
# E-mail : vexus@home.com, glover@credit.erin.utoronto.ca
|
||||
#
|
||||
# Purpose:
|
||||
# This is a graphical adduser program. The widgets are
|
||||
# the CDK command line widgets provided by the CDK
|
||||
# distribution. If you have any questions about CDK,
|
||||
# or the command line widgets please feel free to mail
|
||||
# me at one of the two above addresses.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright 2000, Mike Glover
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. All advertising materials mentioning features or use of this software
|
||||
# must display the following acknowledgment:
|
||||
# This product includes software developed by Mike Glover
|
||||
# and contributors.
|
||||
# 4. Neither the name of Mike Glover nor the names of contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY MIKE GLOVER AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL MIKE GLOVER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
|
||||
#
|
||||
# Set the screen and widget colors.
|
||||
#
|
||||
CDK_WIDGET_COLOR="</5>"; export CDK_WIDGET_COLOR
|
||||
CDK_SCREEN_COLOR="</1>"; export CDK_SCREEN_COLOR
|
||||
|
||||
#
|
||||
# Set up some variables.
|
||||
#
|
||||
CDK_DIALOG="../cdkdialog"
|
||||
CDK_ENTRY="../cdkentry"
|
||||
CDK_SCROLL="../cdkscroll"
|
||||
tmpFile="/tmp/tmp.$$"
|
||||
tmpInfo="/tmp/adduserInfo.$$"
|
||||
shellFile="/tmp/shells.$$"
|
||||
ACCOUNT_SHELL=""
|
||||
ACCOUNT_INFO=""
|
||||
ACCOUNT_NAME=""
|
||||
ACCOUNT_HOME=""
|
||||
ACCOUNT_GID=""
|
||||
ACCOUNT_UID=""
|
||||
GROUP_NAME=""
|
||||
CURRENT_FUNCTION=1;
|
||||
|
||||
#
|
||||
# This quits the program.
|
||||
#
|
||||
quitProgram()
|
||||
{
|
||||
#
|
||||
# The person has decided to quit.
|
||||
#
|
||||
buttons="< OK >"
|
||||
message="<C></B><#HL(30)>
|
||||
<C></B>Add New User Canceled
|
||||
<C></B>Program exiting
|
||||
<C></B><#HL(30)>"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" -N 2> /dev/null
|
||||
exit;
|
||||
}
|
||||
|
||||
#
|
||||
# This warns the user to what is about to happen. It
|
||||
# gives them a safe 'out'
|
||||
#
|
||||
warnUser()
|
||||
{
|
||||
#
|
||||
# Pop up a little message telling the user what is
|
||||
# about to happen.
|
||||
#
|
||||
message="<C></B>Adding New User
|
||||
|
||||
You are about to add a new user. If you do not want to
|
||||
do this, move the cursor to the cancel button and hit
|
||||
return. This will exit this program. Otherwise hit
|
||||
return to continue."
|
||||
buttons="< OK >
|
||||
< Cancel >"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
quitProgram;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the account name from the user.
|
||||
#
|
||||
getAccountName()
|
||||
{
|
||||
#
|
||||
# Keep doing this until we hit an account which does not
|
||||
# already exist.
|
||||
#
|
||||
count=1;
|
||||
while [ $count -ne 0 ]; do
|
||||
#
|
||||
# Get the account name from the user.
|
||||
#
|
||||
buttons="Next
|
||||
Cancel"
|
||||
label="</24/B>Account Name: "
|
||||
title="<C></B>Account Name
|
||||
|
||||
<C>The name is the identity of the account which the
|
||||
<C>user will use to access the system.
|
||||
|
||||
"
|
||||
|
||||
${CDK_ENTRY} -i "${ACCOUNT_NAME}" -f 15 -m 3 -F "</56/B>_" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_NAME=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected button.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
|
||||
#
|
||||
# Look for the account name in the password file.
|
||||
#
|
||||
count=`grep -c "^${ACCOUNT_NAME}" /etc/passwd`
|
||||
if [ ${count} -eq 1 ]; then
|
||||
buttons="< OK >"
|
||||
message="<C></B>Account Found
|
||||
|
||||
<C>The account you provided
|
||||
<C></B>${ACCOUNT_NAME}
|
||||
<C>already exists in the password file. Please pick
|
||||
<C>another account name."
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the account information.
|
||||
#
|
||||
getAccountInfo()
|
||||
{
|
||||
#
|
||||
# Set up the entry field.
|
||||
#
|
||||
buttons="Next
|
||||
Previous
|
||||
Cancel"
|
||||
label="</24/B>Personal Info: "
|
||||
title="<C></B>Account Information.
|
||||
|
||||
Enter in </B>${ACCOUNT_NAME}<!B>'s personal information. This is usually the
|
||||
account holders name, phone number, or extension. This is fairly freeform.
|
||||
The only character you can not use is a colon (:). If you do all colons will
|
||||
be stripped out by this process.
|
||||
|
||||
"
|
||||
${CDK_ENTRY} -f 40 -i "${ACCOUNT_INFO}" -F "</56/B>_" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_INFO=`cat ${tmpFile} | tr ':' ' '`
|
||||
|
||||
#
|
||||
# Check the selected button.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
DIRECTION=-1; export DIRECTION;
|
||||
return;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the account GID.
|
||||
#
|
||||
getAccountGID()
|
||||
{
|
||||
#
|
||||
# Get the 'users' GID from /etc/group.
|
||||
#
|
||||
if [ "$ACCOUNT_GID" = "" ]; then
|
||||
count=`grep -c "^users" /etc/group`
|
||||
if [ $count -eq 0 ]; then
|
||||
USER_GID="100";
|
||||
else
|
||||
USER_GID=`grep "^users" /etc/group | cut -d: -f3`
|
||||
fi
|
||||
else
|
||||
USER_GID="$ACCOUNT_GID";
|
||||
fi
|
||||
|
||||
#
|
||||
# Keep doing this until we get a GID which exists.
|
||||
#
|
||||
count=0;
|
||||
while [ $count -eq 0 ]; do
|
||||
#
|
||||
# Get the GID.
|
||||
#
|
||||
buttons="Next
|
||||
Previous
|
||||
Cancel"
|
||||
label="</24/B>Account GID: "
|
||||
title="<C></B>Account GID
|
||||
|
||||
The GID (Group IDentification) must be a number which already
|
||||
exists in the /etc/group file. The default group </B>users<!B>
|
||||
has been provided for you.
|
||||
|
||||
"
|
||||
${CDK_ENTRY} -f 6 -m 1 -i "${USER_GID}" -F "</56/B>_" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_GID=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected button.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
DIRECTION=-1; export DIRECTION;
|
||||
return;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
|
||||
#
|
||||
# Look for GID in the /etc/group
|
||||
#
|
||||
count=`grep -c ".*:.*:${ACCOUNT_GID}:" /etc/group`
|
||||
if [ ${count} -eq 0 ]; then
|
||||
buttons="< OK >"
|
||||
message="<C></B>Error: No Such GID
|
||||
|
||||
<C>The GID you provided does not exist.
|
||||
<C>Please pick a GID which does exist.
|
||||
"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
quitProgram;
|
||||
fi
|
||||
else
|
||||
#
|
||||
# Get the group name for later.
|
||||
#
|
||||
GROUP_NAME=`grep ".*:.*:${ACCOUNT_GID}:" /etc/group | cut -d: -f1`
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the account UID.
|
||||
#
|
||||
getAccountUID()
|
||||
{
|
||||
#
|
||||
# Try to find the next available UID.
|
||||
#
|
||||
if [ "$ACCOUNT_UID" = "" ]; then
|
||||
nextUID=`awk 'BEGIN {FS=":"} {print $3}' /etc/passwd | sort -n | grep -v "65535" | tail -1`
|
||||
nextUID=`expr $nextUID + 1`
|
||||
else
|
||||
nextUID="$ACCOUNT_UID"
|
||||
fi
|
||||
|
||||
#
|
||||
# Keep doing this until we get a UID which does not exist.
|
||||
#
|
||||
count=1;
|
||||
while [ $count -ne 0 ]; do
|
||||
#
|
||||
# Get the UID.
|
||||
#
|
||||
buttons="Next
|
||||
Previous
|
||||
Cancel"
|
||||
label="</24/B>Account UID: "
|
||||
title="<C></B>Account UID
|
||||
|
||||
The UID (User IDentification) must be a number which does not
|
||||
already exist in the /etc/passwd file. The value filled in is
|
||||
the next available UID found from the password file.
|
||||
|
||||
"
|
||||
${CDK_ENTRY} -f 6 -i "${nextUID}" -m 1 -F "</56/B>_" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_UID=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected button.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
DIRECTION=-1; export DIRECTION;
|
||||
return;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
|
||||
#
|
||||
# Look for UID in the /etc/passwd
|
||||
#
|
||||
count=`grep -c ".*:.*:${ACCOUNT_UID}:" /etc/passwd`
|
||||
if [ ${count} -ne 0 ]; then
|
||||
owner=`grep ".*:.*:${ACCOUNT_UID}:" /etc/passwd | head -1 |cut -d: -f1`
|
||||
buttons="< OK >"
|
||||
message="<C></B>Error: Duplicate UID
|
||||
|
||||
<C>The UID you provided is already owned by
|
||||
<C>the account </B>$owner<!B>. Please pick a
|
||||
<C>UID which does not already exist.
|
||||
"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
quitProgram;
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the account home directory.
|
||||
#
|
||||
getAccountHome()
|
||||
{
|
||||
if [ "${ACCOUNT_HOME}" = "" ]; then
|
||||
defaultHome="/home/${ACCOUNT_NAME}"
|
||||
else
|
||||
defaultHome="${ACCOUNT_HOME}"
|
||||
fi
|
||||
|
||||
#
|
||||
# Set up the entry field.
|
||||
#
|
||||
buttons="Next
|
||||
Previous
|
||||
Cancel"
|
||||
label="</24/B>Home Directory: "
|
||||
title="<C></B>Account Home Directory.
|
||||
|
||||
Enter in the account's home directory. If the directory
|
||||
does not currently exist, it will be created in the account
|
||||
creation phase of this process. A reasonable default value
|
||||
for the home directory has been provided.
|
||||
|
||||
"
|
||||
${CDK_ENTRY} -f 20 -F "</56/B>_" -i "${defaultHome}" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_HOME=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected button.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
DIRECTION=-1; export DIRECTION;
|
||||
return;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This gets the shell the user want to assign to
|
||||
# the account.
|
||||
#
|
||||
getAccountShell()
|
||||
{
|
||||
count=0;
|
||||
|
||||
while [ "$count" -eq 0 ]; do
|
||||
#
|
||||
# Get the shell they want to use.
|
||||
#
|
||||
buttons="Next
|
||||
Previous
|
||||
Cancel"
|
||||
title="<C>Account Shell
|
||||
|
||||
Pick one of the shells to use. If you want to use a
|
||||
custom shell, pick </B>Custom<!B> and you will be
|
||||
prompted for it's path.
|
||||
"
|
||||
echo "Custom" > ${shellFile}
|
||||
cat /etc/shells >> ${shellFile}
|
||||
${CDK_SCROLL} -H 5 -W 10 -T "${title}" -f ${shellFile} -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_SHELL=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected buttons.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
count=1;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
DIRECTION=-1; export DIRECTION;
|
||||
return;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
|
||||
#
|
||||
# Check the answer.
|
||||
#
|
||||
if [ "$ACCOUNT_SHELL" = "Custom" ]; then
|
||||
#
|
||||
# Get the shell from the user.
|
||||
#
|
||||
buttons="Next
|
||||
Previuous
|
||||
Cancel"
|
||||
label="</24/B>Shell Pathname: "
|
||||
title="<C></B>Custom Account Shell
|
||||
|
||||
Enter in the path to the custom shell. The authenticity
|
||||
of the shell will not be checked here. It is assumed that
|
||||
the shell will exist when the account is ready to be used.
|
||||
|
||||
"
|
||||
${CDK_ENTRY} -f 20 -F "</56/B>_" -T "${title}" -L "${label}" -B "${buttons}" 2> ${tmpFile}
|
||||
selected=$?
|
||||
ACCOUNT_SHELL=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Check the selected buttons.
|
||||
#
|
||||
if [ $selected -eq 0 ]; then
|
||||
DIRECTION=1; export DIRECTION;
|
||||
count=1;
|
||||
elif [ $selected -eq 1 ]; then
|
||||
count=0;
|
||||
else
|
||||
quitProgram;
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
#
|
||||
# This confirms the new account information.
|
||||
#
|
||||
confirmAccount()
|
||||
{
|
||||
message="<C></B>Confirm New Account.
|
||||
You are about to add an account with the following
|
||||
information:
|
||||
|
||||
<C><#HL(30)>
|
||||
Account Name : </B>$ACCOUNT_NAME
|
||||
Account Info : </B>$ACCOUNT_INFO
|
||||
Account Home : </B>$ACCOUNT_HOME
|
||||
Account Shell: </B>$ACCOUNT_SHELL
|
||||
Account UID : </B>$ACCOUNT_UID
|
||||
Account GID : </B>$ACCOUNT_GID
|
||||
<C><#HL(30)>
|
||||
|
||||
Are you sure you want to do this. Hit </R>Yes<!R> if you
|
||||
want to add the account; hit </R>No<!R> if you want to
|
||||
edit the information; hit </R>Cancel<!R> if you want to
|
||||
abandon all information.
|
||||
"
|
||||
buttons="< Yes >
|
||||
< No >
|
||||
< Cancel >"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
answer=$?
|
||||
|
||||
#
|
||||
# Check the answer.
|
||||
#
|
||||
if [ "$answer" -eq 2 -o "$answer" -eq 255 ]; then
|
||||
quitProgram;
|
||||
fi
|
||||
if [ "$answer" -eq 0 ]; then
|
||||
confirm=1; export confirm;
|
||||
else
|
||||
confirm=0; export confirm;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Find out if the user wants to change the password
|
||||
# or not.
|
||||
#
|
||||
changeAccountPassword()
|
||||
{
|
||||
buttons="< Yes >
|
||||
< No >"
|
||||
message="<C></B>Change Account Password Now
|
||||
|
||||
Since the account was added without a password, this account
|
||||
can be logged in to without providing a password. Would you
|
||||
like to change the account's password now?
|
||||
"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
answer=$?
|
||||
if [ "$answer" -eq 0 ]; then
|
||||
passwd $ACCOUNT_NAME
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This verifies the users ability to modify the
|
||||
# password file.
|
||||
#
|
||||
checkPermissions()
|
||||
{
|
||||
#
|
||||
# Try to touch the passwd file.
|
||||
#
|
||||
touch /etc/passwd >/dev/null 2>&1
|
||||
if [ $? -ne 0 ]; then
|
||||
#
|
||||
# Can't touch the password file. Let's tell them and go.
|
||||
#
|
||||
buttons="< Log Into Root Now >
|
||||
< Exit >"
|
||||
message="<C></B>Can Not Edit Password File
|
||||
|
||||
It appears that you do not have permission to edit the
|
||||
password file. To add a new user to this machine you
|
||||
must be logged in as root. Would you like to su to root
|
||||
now or exit and log in. If you try to su now, this
|
||||
program will be restarted.
|
||||
"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
su root -c "$0"
|
||||
fi
|
||||
exit;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# This creates the account and copies all needed
|
||||
# information.
|
||||
#
|
||||
createAccount()
|
||||
{
|
||||
if [ ! -d "$ACCOUNT_HOME" ]; then
|
||||
mkdir $ACCOUNT_HOME
|
||||
fi
|
||||
if [ "$ACCOUNT_SHELL" = "/bin/sh" ]; then
|
||||
cp /etc/profile ${ACCOUNT_HOME}/.profile
|
||||
fi
|
||||
if [ "$ACCOUNT_SHELL" = "/bin/bash" ]; then
|
||||
cp /etc/profile ${ACCOUNT_HOME}/.profile
|
||||
fi
|
||||
if [ "$ACCOUNT_SHELL" = "/bin/csh" ]; then
|
||||
cp /etc/csh.cshrc ${ACCOUNT_HOME}/.cshrc
|
||||
cp /etc/csh.login ${ACCOUNT_HOME}/.login
|
||||
fi
|
||||
if [ "$ACCOUNT_SHELL" = "/bin/tcsh" ]; then
|
||||
cp /etc/csh.cshrc ${ACCOUNT_HOME}/.cshrc
|
||||
cp /etc/csh.login ${ACCOUNT_HOME}/.login
|
||||
fi
|
||||
chown -R ${ACCOUNT_NAME}.${GROUP_NAME} $ACCOUNT_HOME
|
||||
}
|
||||
|
||||
###########################################################
|
||||
#
|
||||
# This is the start of the info retrieval.
|
||||
#
|
||||
###########################################################
|
||||
|
||||
#
|
||||
# Set up the intermiediate functions so we can go
|
||||
# backward and forward.
|
||||
#
|
||||
function1()
|
||||
{
|
||||
getAccountName;
|
||||
}
|
||||
function2()
|
||||
{
|
||||
getAccountInfo;
|
||||
}
|
||||
function3()
|
||||
{
|
||||
getAccountGID;
|
||||
}
|
||||
function4()
|
||||
{
|
||||
getAccountUID;
|
||||
}
|
||||
function5()
|
||||
{
|
||||
getAccountHome;
|
||||
}
|
||||
function6()
|
||||
{
|
||||
getAccountShell;
|
||||
}
|
||||
function7()
|
||||
{
|
||||
confirmAccount;
|
||||
}
|
||||
|
||||
#
|
||||
# Make sure the user has permission to edit the password file.
|
||||
#
|
||||
checkPermissions;
|
||||
|
||||
#
|
||||
# Tell the user what they are about to do.
|
||||
#
|
||||
warnUser;
|
||||
|
||||
#
|
||||
# Call the functions to get the needed info.
|
||||
#
|
||||
confirm=0;
|
||||
NUMBER=0;
|
||||
DIRECTION=1;
|
||||
while [ "$confirm" -eq 0 ]; do
|
||||
NUMBER=`expr $NUMBER + $DIRECTION`
|
||||
if [ $NUMBER -le 0 ]; then
|
||||
NUMBER = 1;
|
||||
fi
|
||||
CURRENT_FUNCTION="function${NUMBER}";
|
||||
$CURRENT_FUNCTION;
|
||||
done
|
||||
|
||||
#
|
||||
# Add the account to the password file.
|
||||
#
|
||||
cp /etc/passwd /etc/passwd.old
|
||||
echo "${ACCOUNT_NAME}::${ACCOUNT_UID}:${ACCOUNT_GID}:${ACCOUNT_INFO}:${ACCOUNT_HOME}:${ACCOUNT_SHELL}" >> /etc/passwd
|
||||
|
||||
#
|
||||
# Find out if the user wants to change the password or not.
|
||||
#
|
||||
changeAccountPassword;
|
||||
|
||||
#
|
||||
# Create the account and copy . files.
|
||||
#
|
||||
createAccount;
|
||||
|
||||
#
|
||||
# Pop up a last little message and tell the user everything
|
||||
# if OK.
|
||||
#
|
||||
buttons="< OK >"
|
||||
message="<C></B>Account Add Complete
|
||||
|
||||
The account </B>${ACCOUNT_NAME}<!B> has been added to the password
|
||||
file. You should be able to log in under this account
|
||||
now.
|
||||
"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" 2> /dev/null
|
415
deps/cdk-5.0-20161210/cli/utils/netconfig
vendored
Executable file
415
deps/cdk-5.0-20161210/cli/utils/netconfig
vendored
Executable file
@@ -0,0 +1,415 @@
|
||||
#!/bin/sh
|
||||
# $Id: netconfig,v 1.3 2002/07/16 22:25:56 tom Exp $
|
||||
|
||||
#
|
||||
# Written by: Mike Glover, March 1997
|
||||
# E-mail : vexus@home.com, glover@credit.erin.utoronto.ca
|
||||
#
|
||||
# Purpose:
|
||||
# This is a graphical network configuration program.
|
||||
# It was inspired by the cdialog interface that Linux
|
||||
# uses. The widgets are the CDK command line widgets
|
||||
# provided by the CDK distribution. If you have any
|
||||
# questions about CDK, or the command line widgets
|
||||
# please feel free to mail me at one of the two above
|
||||
# addresses.
|
||||
#
|
||||
|
||||
#
|
||||
# Copyright 2000, Mike Glover
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# 3. All advertising materials mentioning features or use of this software
|
||||
# must display the following acknowledgment:
|
||||
# This product includes software developed by Mike Glover
|
||||
# and contributors.
|
||||
# 4. Neither the name of Mike Glover nor the names of contributors
|
||||
# may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY MIKE GLOVER AND CONTRIBUTORS ``AS IS'' AND
|
||||
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
# ARE DISCLAIMED. IN NO EVENT SHALL MIKE GLOVER OR CONTRIBUTORS BE LIABLE
|
||||
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
# SUCH DAMAGE.
|
||||
#
|
||||
|
||||
#
|
||||
# Set up the root directory for the system files.
|
||||
#
|
||||
if [ "$1" = "" ]; then
|
||||
ROOTDIR=""
|
||||
else
|
||||
ROOTDIR=$1;
|
||||
fi
|
||||
|
||||
#
|
||||
# This copies a file to it's destination and
|
||||
# sets the file mode.
|
||||
#
|
||||
copyFile()
|
||||
{
|
||||
source=$1;
|
||||
dest=$2;
|
||||
mode=$3;
|
||||
|
||||
#
|
||||
# If the original exists, make a copy.
|
||||
#
|
||||
if [ -f "${dest}" ]; then
|
||||
cp ${dest} ${dest}.old
|
||||
fi
|
||||
mv ${source} ${dest}
|
||||
chmod ${mode} ${dest}
|
||||
}
|
||||
|
||||
#
|
||||
# Set up some variables.
|
||||
#
|
||||
CDK_DIALOG="../cdkdialog"
|
||||
CDK_ENTRY="../cdkentry"
|
||||
CDK_TEMPLATE="../cdktemplate"
|
||||
NETWORKS="${ROOTDIR}/etc/networks"
|
||||
HOSTS="${ROOTDIR}/etc/hosts"
|
||||
HOSTNAME_FILE="${ROOTDIR}/etc/HOSTNAME"
|
||||
RESOLV="${ROOTDIR}/etc/resolv.conf"
|
||||
INET="${ROOTDIR}/etc/rc.d/rc.inet1"
|
||||
IFCONFIG="${ROOTDIR}/sbin/ifconfig"
|
||||
ROUTE="${ROOTDIR}/sbin/route"
|
||||
tmpFile="/tmp/tmp.$$"
|
||||
|
||||
#
|
||||
# Define some global variables.
|
||||
#
|
||||
IP=""
|
||||
HOST=""
|
||||
DOMAIN=""
|
||||
GATEWAY=""
|
||||
NETMASK=""
|
||||
NETWORK=""
|
||||
BROADCAST=""
|
||||
NAMESERVER=""
|
||||
|
||||
#
|
||||
# Set the screen and widget colors.
|
||||
#
|
||||
CDK_WIDGET_COLOR="</5>"; export CDK_WIDGET_COLOR
|
||||
CDK_SCREEN_COLOR="</7>"; export CDK_SCREEN_COLOR
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
exitMessage()
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
#
|
||||
# Create the opening window.
|
||||
#
|
||||
intro()
|
||||
{
|
||||
program=`basename $0`
|
||||
buttons="</R>< OK >"
|
||||
message="<C></B>Network Configuration
|
||||
|
||||
We will now attempt to configure your mail and TCP/IP. This
|
||||
process probably won't work on all possible network
|
||||
configurations; but should give you a good start. You will
|
||||
be able to reconfigure your network at any time by typing
|
||||
in the command:
|
||||
<C>${program}"
|
||||
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
|
||||
}
|
||||
|
||||
#
|
||||
# Get the hostname of the machine.
|
||||
#
|
||||
getHostname()
|
||||
{
|
||||
label="</24/B>Enter Hostname: "
|
||||
title="<C></B>Enter Hostname
|
||||
|
||||
We need to give the machine a name. We only need the base
|
||||
hostname of the machine; the domain will be queried for
|
||||
next.
|
||||
"
|
||||
|
||||
${CDK_ENTRY} -i "${HOST}" -f 20 -F "</56/B>_" -T "${title}" -L "${label}" -S 2> ${tmpFile}
|
||||
HOST=`cat ${tmpFile}`
|
||||
}
|
||||
|
||||
#
|
||||
# Get the domain name of the machine.
|
||||
#
|
||||
getDomainName()
|
||||
{
|
||||
label="</24/B>Enter Domain Name: "
|
||||
title="<C></B>Enter Domain Name
|
||||
|
||||
Now enter in the domain in which this machine will
|
||||
reside. Do </K>NOT<!K> supply a leading '.'
|
||||
|
||||
"
|
||||
|
||||
${CDK_ENTRY} -i "${DOMAIN}" -f 20 -F "</56/B>_" -T "${title}" -L "${label}" -S 2> ${tmpFile}
|
||||
DOMAIN=`cat ${tmpFile}`
|
||||
}
|
||||
|
||||
#
|
||||
# Ask them if they plan to use loopback only.
|
||||
#
|
||||
loopback()
|
||||
{
|
||||
buttons="< Yes >
|
||||
< No >"
|
||||
message="<C></B>Loopback
|
||||
|
||||
Do you plan to only use loopback? If so then your address will
|
||||
be 127.0.0.1 and most of the following questions can be skipped.
|
||||
|
||||
<C>Do you plan to ONLY use loopback?
|
||||
"
|
||||
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
|
||||
answer=$?
|
||||
if [ $answer -eq 0 ]; then
|
||||
exitMessage;
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Get the IP Address.
|
||||
#
|
||||
getIPAddress()
|
||||
{
|
||||
title="<C> </B>Enter Machine IP Address
|
||||
|
||||
<C>Enter the IP address you plan to assign to this machine.
|
||||
"
|
||||
plate="###.###.###.###"
|
||||
overlay="</56/B>___.___.___.___"
|
||||
${CDK_TEMPLATE} -i "${IP}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
|
||||
IP=`cat ${tmpFile}`
|
||||
}
|
||||
|
||||
#
|
||||
#
|
||||
#
|
||||
getGatewayAddress()
|
||||
{
|
||||
NETWORK=`echo ${IP} | awk 'BEGIN {FS="."} {printf ("%s.%s.%s.0",$1,$2,$3)}'`
|
||||
BROADCAST=`echo ${IP} | awk 'BEGIN {FS="."} {printf ("%s.%s.%s.255",$1,$2,$3)}'`
|
||||
|
||||
#
|
||||
# Get the machine's gateway address.
|
||||
#
|
||||
title="<C> </B>Enter Gateway Address
|
||||
|
||||
Enter the address of the gateway for this machine. If you do not
|
||||
know, or have one, use the IP address of this machine. The IP
|
||||
address you assigned to this machine should already be filled
|
||||
in. If you want to erase it press control-x to erase the field
|
||||
or hit the backspace or delete key to erase portions of the field.
|
||||
"
|
||||
tmp=`echo ${IP} | sed 's/\.//g'`
|
||||
plate="###.###.###.###"
|
||||
overlay="</B/56>___.___.___.___"
|
||||
${CDK_TEMPLATE} -d "${tmp}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
|
||||
GATEWAY=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Get the machine's netmask.
|
||||
#
|
||||
title="<C> </B>Enter Netmask
|
||||
|
||||
Enter your netmask. More often than not this value will be
|
||||
255.255.255.0 A defaulted value of 255.255.255.0 is already
|
||||
filled in. If you want to erase it press control-x to erase
|
||||
the field or hit the backspace or delete key to erase
|
||||
portions of the field.
|
||||
"
|
||||
plate="###.###.###.###"
|
||||
overlay="</B/56>___.___.___.___"
|
||||
${CDK_TEMPLATE} -d "2552552550" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
|
||||
NETMASK=`cat ${tmpFile}`
|
||||
|
||||
#
|
||||
# Find out if the user will be accessing a domain name server.
|
||||
#
|
||||
message="<C> </B>Named Services
|
||||
|
||||
Will you be accessing a name server.
|
||||
"
|
||||
buttons="< Yes >
|
||||
< No >"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
|
||||
answer=$?
|
||||
|
||||
#
|
||||
# If they answered yes, get the IP address.
|
||||
#
|
||||
if [ "$answer" -eq 0 ]; then
|
||||
#
|
||||
# Get the machine's domain name server address.
|
||||
#
|
||||
title="<C> </B>Enter DNS Address
|
||||
|
||||
Enter the address of the domain name server (DNS) which you want to
|
||||
use. The value of the DNS server has been filled in with the
|
||||
gateway address you provided. If you want to erase it press
|
||||
control-x to erase the field or hit the backspace or delete key
|
||||
to erase portions of the field.
|
||||
"
|
||||
tmp=`echo ${GATEWAY} | sed 's/\.//g'`
|
||||
plate="###.###.###.###"
|
||||
overlay="</B/56>___.___.___.___"
|
||||
${CDK_TEMPLATE} -d "${tmp}" -p "${plate}" -o "${overlay}" -T "${title}" -m 10 -P -S 2> ${tmpFile}
|
||||
NAMESERVER=`cat ${tmpFile}`
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
# Call the functions needed.
|
||||
#
|
||||
|
||||
|
||||
#########################################
|
||||
# Create the hosts file.
|
||||
#
|
||||
cat << EOF > ${tmpFile}
|
||||
#
|
||||
# hosts This file describes a number of hostname-to-address
|
||||
# mappings for the TCP/IP subsystem. It is mostly
|
||||
# used at boot time, when no name servers are running.
|
||||
# On small systems, this file can be used instead of a
|
||||
# "named" name server. Just add the names, addresses
|
||||
# and any aliases to this file...
|
||||
#
|
||||
# By the way, Arnt Gulbrandsen <agulbra@nvg.unit.no> says that 127.0.0.1
|
||||
# should NEVER be named with the name of the machine. It causes problems
|
||||
# for some (stupid) programs, irc and reputedly talk. :^)
|
||||
#
|
||||
|
||||
# For loopbacking.
|
||||
127.0.0.1 localhost
|
||||
$IP ${HOST}.${DOMAIN} ${HOST}
|
||||
# End of hosts
|
||||
EOF
|
||||
copyFile ${tmpFile} "${HOSTS}" 644
|
||||
echo "${HOST}.${DOMAIN}" > ${tmpFile}
|
||||
copyFile ${tmpFile} ${HOSTNAME_FILE} 644
|
||||
|
||||
#########################################
|
||||
# Create the resolv.conf file.
|
||||
#
|
||||
cat << EOF > ${tmpFile}
|
||||
domain ${DOMAIN}
|
||||
nameserver ${NAMESERVER}
|
||||
EOF
|
||||
copyFile ${tmpFile} "${RESOLV}" 644
|
||||
|
||||
#########################################
|
||||
# Create the /etc/networks file.
|
||||
#
|
||||
cat << EOF > ${tmpFile}
|
||||
#
|
||||
# networks This file describes a number of netname-to-address
|
||||
# mappings for the TCP/IP subsystem. It is mostly
|
||||
# used at boot time, when no name servers are running.
|
||||
#
|
||||
|
||||
loopback 127.0.0.0
|
||||
localnet ${IP}
|
||||
|
||||
# End of networks.
|
||||
EOF
|
||||
copyFile ${tmpFile} "${NETWORKS}" 644
|
||||
|
||||
#########################################
|
||||
# Create the /etc/rc.d/inet1 file.
|
||||
#
|
||||
cat << EOF > ${tmpFile}
|
||||
#! /bin/sh
|
||||
#
|
||||
# rc.inet1 This shell script boots up the base INET system.
|
||||
#
|
||||
# Version: @(#)/etc/rc.d/rc.inet1 1.01 05/27/93
|
||||
#
|
||||
|
||||
HOSTNAME=\`cat /etc/HOSTNAME\`
|
||||
|
||||
# Attach the loopback device.
|
||||
${IFCONFIG} lo 127.0.0.1
|
||||
${ROUTE} add -net 127.0.0.0
|
||||
|
||||
# IF YOU HAVE AN ETHERNET CONNECTION, use these lines below to configure the
|
||||
# eth0 interface. If you're only using loopback or SLIP, don't include the
|
||||
# rest of the lines in this file.
|
||||
|
||||
# Edit for your setup.
|
||||
IPADDR="$IP" # REPLACE with YOUR IP address!
|
||||
NETMASK="$NETMASK" # REPLACE with YOUR netmask!
|
||||
NETWORK="$NETWORK" # REPLACE with YOUR network address!
|
||||
BROADCAST="$BROADCAST" # REPLACE with YOUR broadcast address, if you
|
||||
# have one. If not, leave blank and edit below.
|
||||
GATEWAY="$GATEWAY" # REPLACE with YOUR gateway address!
|
||||
|
||||
# Uncomment the line below to configure your ethernet card.
|
||||
${IFCONFIG} eth0 \${IP} broadcast \${BROADCAST} netmask \${NETMASK}
|
||||
|
||||
# If the line above is uncommented, the code below can also be uncommented.
|
||||
# It sees if the ethernet was properly initialized, and gives the admin some
|
||||
# hints about what to do if it wasn't.
|
||||
if [ ! \$? = 0 ]; then
|
||||
cat << END
|
||||
Your ethernet card was not initialized properly. Here are some reasons why this
|
||||
may have happened, and the solutions:
|
||||
1. Your kernel does not contain support for your card. Including all the
|
||||
network drivers in a Linux kernel can make it too large to even boot, and
|
||||
sometimes including extra drivers can cause system hangs. To support your
|
||||
ethernet, either edit /etc/rc.d/rc.modules to load the support at boottime,
|
||||
or compile and install a kernel that contains support.
|
||||
2. You don't have an ethernet card, in which case you should comment out this
|
||||
section of /etc/rc.d/rc.inet1. (Unless you don't mind seeing this error...)
|
||||
END
|
||||
fi
|
||||
|
||||
# Uncomment these to set up your IP routing table.
|
||||
${ROUTE} add -net \${NETWORK} netmask \${NETMASK}
|
||||
${ROUTE} add default gw \${GATEWAY} metric 1
|
||||
|
||||
# End of rc.inet1
|
||||
EOF
|
||||
copyFile ${tmpFile} "${INET}" 755
|
||||
|
||||
#
|
||||
# Spit out the 'we are done' message.
|
||||
#
|
||||
message="<C></B>Network Setup Complete
|
||||
|
||||
Your network software has now been configured. You may
|
||||
rerun this program to reconfigure or you may edit the
|
||||
respective system files."
|
||||
buttons="< OK >"
|
||||
${CDK_DIALOG} -m "${message}" -B "${buttons}" -S 2> /dev/null
|
||||
|
||||
#
|
||||
# Clean up
|
||||
#
|
||||
rm -f ${tmpFile}
|
Reference in New Issue
Block a user