added cdk to deps and building fileapprove

This commit is contained in:
Andrew Pamment
2017-03-20 21:40:32 +10:00
parent 071df70e4c
commit 71858e4583
265 changed files with 99585 additions and 18 deletions

128
deps/cdk-5.0-20161210/demos/Makefile.in vendored Normal file
View File

@@ -0,0 +1,128 @@
# $Id: Makefile.in,v 1.20 2013/07/19 23:55:03 tom Exp $
#
# Makefile for the demos 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 = \
fileview$x \
rolodex$x \
command$x \
clock$x \
stopSign$x \
appointment$x \
vinstall$x
# this needs configure-script work:
OTHER_BINS = \
serial$x
CDKSRC = \
fileview.c \
rolodex.c \
command.c \
clock.c \
stopSign.c \
appointment.c \
vinstall.c \
serial.c
# If you have Sybase installed on your system, try making
# syb. It's a full screen interface to Sybase.
#
SYBROOT = $(SYBASE)
SYBINCDIR = -I$(SYBROOT)/include
SYBLIBDIR = -L$(SYBROOT)/devlib
SYBLIBS = -lnsl -lsybdb
all : $(BINS)
#
# Standard .c to .o compile line.
#
.c.o:
@RULE_CC@
@ECHO_CC@$(CC) $(CFLAGS) $(CPPFLAGS) -c $<
#
# Most of the examples are built from a single .c file using the same libraries
#
LINKIT = @ECHO_LD@$(LINK) $(CFLAGS) $(CPPFLAGS) $? -o $@ $(LDFLAGS) $(LIBS)
# fileview - Basic file selector/file viewer combination.
fileview$x : fileview.o ; $(LINKIT)
# rolodex - A fairly robust rolodex.
rolodex$x : rolodex.o ; $(LINKIT)
# command - A basic command interface with command history.
command$x : command.o ; $(LINKIT)
# clock - A simple little clock.
clock$x : clock.o ; $(LINKIT)
# stopSign - A simple demo I wrote after a couple of pints. :)
stopSign$x : stopSign.o ; $(LINKIT)
# appointment - A basic appointment book/date keeper.
appointment$x : appointment.o ; $(LINKIT)
# serial - This probes the serial port.
serial$x : serial.o ; $(LINKIT)
# keycheck - This prints out the keys ASCII and Octal values.
keycheck$x : keycheck.o ; $(LINKIT)
# vinstall - CDK based installer.
vinstall$x : vinstall.o ; $(LINKIT)
#
# A Sybase interface.
#
syb$x : syb.c
$(CC) $(CFLAGS) -o $@ $? $(CPPFLAGS) $(SYBINCDIR) $(LDFLAGS) $(SYBLIBDIR) $(LIBS) $(SYBLIBS)
#
# Standard clean directives.
#
clean::
-$(LIBTOOL_CLEAN) $(RM) *.o core $(BINS) $(OTHER_BINS)
distclean:: clean
-rm -f 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)

View File

@@ -0,0 +1,524 @@
/* $Id: appointment.c,v 1.29 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "appointmentBook";
#endif
/*
* Create definitions.
*/
#define MAX_MARKERS 2000
/*
*
*/
static chtype GPAppointmentAttributes[] =
{
A_BLINK,
A_BOLD,
A_REVERSE,
A_UNDERLINE
};
/*
*
*/
typedef enum
{
vBirthday, vAnniversary, vAppointment, vOther
}
EAppointmentType;
/*
*
*/
struct AppointmentMarker
{
EAppointmentType type;
char *description;
int day;
int month;
int year;
};
/*
*
*/
struct AppointmentInfo
{
struct AppointmentMarker appointment[MAX_MARKERS];
int appointmentCount;
};
/*
* Declare local function prototypes.
*/
static BINDFN_PROTO (createCalendarMarkCB);
static BINDFN_PROTO (removeCalendarMarkCB);
static BINDFN_PROTO (displayCalendarMarkCB);
static BINDFN_PROTO (accelerateToDateCB);
void readAppointmentFile (char *filename, struct AppointmentInfo *appInfo);
void saveAppointmentFile (char *filename, struct AppointmentInfo *appInfo);
/*
* This program demonstrates the Cdk calendar widget.
*/
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKCALENDAR *calendar = 0;
const char *title = "<C></U>CDK Appointment Book\n<C><#HL(30)>\n";
char *filename = 0;
struct tm *dateInfo = 0;
time_t clck = 0;
struct AppointmentInfo appointmentInfo;
int day, month, year, x;
/*
* Get the current dates and set the default values for
* the day/month/year values for the calendar.
*/
/* *INDENT-EQLS* */
time (&clck);
dateInfo = gmtime (&clck);
day = dateInfo->tm_mday;
month = dateInfo->tm_mon + 1;
year = dateInfo->tm_year + 1900;
/* Check the command line for options. */
while (1)
{
int ret;
/* Are there any more command line options to parse. */
if ((ret = getopt (argc, argv, "d:m:y:t:f:")) == -1)
{
break;
}
switch (ret)
{
case 'd':
day = atoi (optarg);
break;
case 'm':
month = atoi (optarg);
break;
case 'y':
year = atoi (optarg);
break;
case 't':
title = copyChar (optarg);
break;
case 'f':
filename = copyChar (optarg);
break;
}
}
/* Create the appointment book filename. */
if (filename == 0)
{
char temp[1000];
char *home = getenv ("HOME");
if (home != 0)
{
sprintf (temp, "%.*s/.appointment", (int)sizeof (temp) - 20, home);
}
else
{
strcpy (temp, ".appointment");
}
filename = copyChar (temp);
}
/* Read the appointment book information. */
readAppointmentFile (filename, &appointmentInfo);
cdkscreen = initCDKScreen (NULL);
/* Start CDK Colors. */
initCDKColor ();
/* Create the calendar widget. */
calendar = newCDKCalendar (cdkscreen, CENTER, CENTER,
title, day, month, year,
A_NORMAL, A_NORMAL,
A_NORMAL, A_REVERSE,
TRUE, FALSE);
/* Is the widget null? */
if (calendar == 0)
{
/* Clean up the memory. */
destroyCDKScreen (cdkscreen);
/* End curses... */
endCDK ();
/* Spit out a message. */
printf ("Cannot create the calendar. Is the window too small?\n");
ExitProgram (EXIT_FAILURE);
}
/* Create a key binding to mark days on the calendar. */
bindCDKObject (vCALENDAR, calendar, 'm', createCalendarMarkCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, 'M', createCalendarMarkCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, 'r', removeCalendarMarkCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, 'R', removeCalendarMarkCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, '?', displayCalendarMarkCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, 'j', accelerateToDateCB, &appointmentInfo);
bindCDKObject (vCALENDAR, calendar, 'J', accelerateToDateCB, &appointmentInfo);
/* Set all the appointments read from the file. */
for (x = 0; x < appointmentInfo.appointmentCount; x++)
{
chtype marker = GPAppointmentAttributes[appointmentInfo.appointment[x].type];
setCDKCalendarMarker (calendar,
appointmentInfo.appointment[x].day,
appointmentInfo.appointment[x].month,
appointmentInfo.appointment[x].year,
marker);
}
/* Draw the calendar widget. */
drawCDKCalendar (calendar, ObjOf (calendar)->box);
/* Let the user play with the widget. */
activateCDKCalendar (calendar, 0);
/* Save the appointment information. */
saveAppointmentFile (filename, &appointmentInfo);
free (filename);
/* Clean up and exit. */
destroyCDKCalendar (calendar);
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
/*
* This reads a given appointment file.
*/
void readAppointmentFile (char *filename, struct AppointmentInfo *appInfo)
{
/* *INDENT-EQLS* */
int appointments = 0;
int linesRead = 0;
char **lines = 0;
int x;
/* Read the appointment file. */
linesRead = CDKreadFile (filename, &lines);
if (linesRead == -1)
{
appInfo->appointmentCount = 0;
return;
}
/* Split each line up and create an appointment. */
for (x = 0; x < linesRead; x++)
{
char **temp = CDKsplitString (lines[x], CTRL ('V'));
int segments = (int)CDKcountStrings ((CDK_CSTRING2)temp);
/*
* A valid line has 5 elements:
* Day, Month, Year, Type, Description.
*/
if (segments == 5)
{
int eType = atoi (temp[3]);
/* *INDENT-EQLS* */
appInfo->appointment[appointments].day = atoi (temp[0]);
appInfo->appointment[appointments].month = atoi (temp[1]);
appInfo->appointment[appointments].year = atoi (temp[2]);
appInfo->appointment[appointments].type = (EAppointmentType) eType;
appInfo->appointment[appointments].description = copyChar (temp[4]);
appointments++;
}
CDKfreeStrings (temp);
}
CDKfreeStrings (lines);
/* Keep the amount of appointments read. */
appInfo->appointmentCount = appointments;
}
/*
* This saves a given appointment file.
*/
void saveAppointmentFile (char *filename, struct AppointmentInfo *appInfo)
{
/* Declare local variables. */
FILE *fd;
int x;
/* Can we open the file? */
if ((fd = fopen (filename, "w")) == 0)
{
return;
}
/* Start writing. */
for (x = 0; x < appInfo->appointmentCount; x++)
{
if (appInfo->appointment[x].description != 0)
{
fprintf (fd, "%d%c%d%c%d%c%d%c%s\n",
appInfo->appointment[x].day, CTRL ('V'),
appInfo->appointment[x].month, CTRL ('V'),
appInfo->appointment[x].year, CTRL ('V'),
(int)appInfo->appointment[x].type, CTRL ('V'),
appInfo->appointment[x].description);
freeChar (appInfo->appointment[x].description);
}
}
fclose (fd);
}
/*
* This adds a marker to the calendar.
*/
static int createCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
/* *INDENT-EQLS* */
CDKCALENDAR *calendar = (CDKCALENDAR *)object;
CDKENTRY *entry = 0;
CDKITEMLIST *itemlist = 0;
const char *items[] =
{
"Birthday",
"Anniversary",
"Appointment",
"Other"
};
char *description = 0;
struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData;
int current = appointmentInfo->appointmentCount;
chtype marker;
int selection;
/* Create the itemlist widget. */
itemlist = newCDKItemlist (ScreenOf (calendar),
CENTER, CENTER, 0,
"Select Appointment Type: ",
(CDK_CSTRING2)items, 4, 0,
TRUE, FALSE);
/* Get the appointment tye from the user. */
selection = activateCDKItemlist (itemlist, 0);
/* They hit escape, kill the itemlist widget and leave. */
if (selection == -1)
{
destroyCDKItemlist (itemlist);
drawCDKCalendar (calendar, ObjOf (calendar)->box);
return (FALSE);
}
/* Destroy the itemlist and set the marker. */
destroyCDKItemlist (itemlist);
drawCDKCalendar (calendar, ObjOf (calendar)->box);
marker = GPAppointmentAttributes[selection];
/* Create the entry field for the description. */
entry = newCDKEntry (ScreenOf (calendar),
CENTER, CENTER,
"<C>Enter a description of the appointment.",
"Description: ",
A_NORMAL, (chtype)'.',
vMIXED, 40, 1, 512,
TRUE, FALSE);
/* Get the description. */
description = activateCDKEntry (entry, 0);
if (description == 0)
{
destroyCDKEntry (entry);
drawCDKCalendar (calendar, ObjOf (calendar)->box);
return (FALSE);
}
/* Destroy the entry and set the marker. */
description = copyChar (entry->info);
destroyCDKEntry (entry);
drawCDKCalendar (calendar, ObjOf (calendar)->box);
/* Set the marker. */
setCDKCalendarMarker (calendar,
calendar->day,
calendar->month,
calendar->year,
marker);
/* Keep the marker. */
appointmentInfo->appointment[current].day = calendar->day;
appointmentInfo->appointment[current].month = calendar->month;
appointmentInfo->appointment[current].year = calendar->year;
appointmentInfo->appointment[current].type = (EAppointmentType) selection;
appointmentInfo->appointment[current].description = description;
appointmentInfo->appointmentCount++;
/* Redraw the calendar. */
drawCDKCalendar (calendar, ObjOf (calendar)->box);
return (FALSE);
}
/*
* This removes a marker from the calendar.
*/
static int removeCalendarMarkCB (EObjectType objectType GCC_UNUSED, void
*object, void *clientData, chtype key GCC_UNUSED)
{
CDKCALENDAR *calendar = (CDKCALENDAR *)object;
struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData;
int x;
/* Look for the marker in the list. */
for (x = 0; x < appointmentInfo->appointmentCount; x++)
{
if ((appointmentInfo->appointment[x].day == calendar->day) &&
(appointmentInfo->appointment[x].month == calendar->month) &&
(appointmentInfo->appointment[x].year == calendar->year))
{
freeChar (appointmentInfo->appointment[x].description);
appointmentInfo->appointment[x].description = 0;
break;
}
}
/* Remove the marker from the calendar. */
removeCDKCalendarMarker (calendar,
calendar->day,
calendar->month,
calendar->year);
/* Redraw the calendar. */
drawCDKCalendar (calendar, ObjOf (calendar)->box);
return (FALSE);
}
/*
* This displays the marker(s) on the given day.
*/
static int displayCalendarMarkCB (EObjectType objectType GCC_UNUSED, void
*object, void *clientData, chtype key GCC_UNUSED)
{
/* *INDENT-EQLS* */
CDKCALENDAR *calendar = (CDKCALENDAR *)object;
CDKLABEL *label = 0;
struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData;
int found = 0;
int mesgLines = 0;
const char *type = 0;
char *mesg[10], temp[256];
int x;
/* Look for the marker in the list. */
for (x = 0; x < appointmentInfo->appointmentCount; x++)
{
/* Get the day month year. */
/* *INDENT-EQLS* */
int day = appointmentInfo->appointment[x].day;
int month = appointmentInfo->appointment[x].month;
int year = appointmentInfo->appointment[x].year;
/* Determine the appointment type. */
if (appointmentInfo->appointment[x].type == vBirthday)
{
type = "Birthday";
}
else if (appointmentInfo->appointment[x].type == vAnniversary)
{
type = "Anniversary";
}
else if (appointmentInfo->appointment[x].type == vAppointment)
{
type = "Appointment";
}
else
{
type = "Other";
}
/* Find the marker by the day/month/year. */
if ((day == calendar->day) &&
(month == calendar->month) &&
(year == calendar->year) &&
(appointmentInfo->appointment[x].description != 0))
{
/* Create the message for the label widget. */
sprintf (temp, "<C>Appointment Date: %02d/%02d/%d", day, month, year);
mesg[mesgLines++] = copyChar (temp);
mesg[mesgLines++] = copyChar (" ");
mesg[mesgLines++] = copyChar ("<C><#HL(35)>");
sprintf (temp, " Appointment Type: %s", type);
mesg[mesgLines++] = copyChar (temp);
mesg[mesgLines++] = copyChar (" Description :");
sprintf (temp, " %s", appointmentInfo->appointment[x].description);
mesg[mesgLines++] = copyChar (temp);
mesg[mesgLines++] = copyChar ("<C><#HL(35)>");
mesg[mesgLines++] = copyChar (" ");
mesg[mesgLines++] = copyChar ("<C>Press space to continue.");
found = 1;
break;
}
}
/* If we didn't find the marker, create a different message. */
if (found == 0)
{
sprintf (temp, "<C>There is no appointment for %02d/%02d/%d",
calendar->day, calendar->month, calendar->year);
mesg[mesgLines++] = copyChar (temp);
mesg[mesgLines++] = copyChar ("<C><#HL(30)>");
mesg[mesgLines++] = copyChar ("<C>Press space to continue.");
}
/* Create the label widget. */
label = newCDKLabel (ScreenOf (calendar), CENTER, CENTER,
(CDK_CSTRING2)mesg, mesgLines, TRUE, FALSE);
drawCDKLabel (label, ObjOf (label)->box);
waitCDKLabel (label, ' ');
destroyCDKLabel (label);
/* Clean up the memory used. */
for (x = 0; x < mesgLines; x++)
{
freeChar (mesg[x]);
}
/* Redraw the calendar widget. */
drawCDKCalendar (calendar, ObjOf (calendar)->box);
return (FALSE);
}
/*
* This allows the user to accelerate to a given date.
*/
static int accelerateToDateCB (EObjectType objectType GCC_UNUSED, void
*object GCC_UNUSED, void *clientData
GCC_UNUSED, chtype key GCC_UNUSED)
{
return (FALSE);
}

90
deps/cdk-5.0-20161210/demos/clock.c vendored Normal file
View File

@@ -0,0 +1,90 @@
/* $Id: clock.c,v 1.11 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "label_ex";
#endif
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKLABEL *demo = 0;
int boxLabel = 0;
const char *mesg[4];
char temp[256];
time_t clck;
int ret;
/* Parse up the command line. */
while ((ret = getopt (argc, argv, "b")) != -1)
{
switch (ret)
{
case 'b':
boxLabel = 1;
}
}
cdkscreen = initCDKScreen (NULL);
/* Start CDK Colors */
initCDKColor ();
/* Set the labels up. */
mesg[0] = "</1/B>HH:MM:SS";
/* Declare the labels. */
demo = newCDKLabel (cdkscreen, CENTER, CENTER,
(CDK_CSTRING2)mesg, 1,
boxLabel, FALSE);
/* Is the label null??? */
if (demo == 0)
{
/* Clean up the memory. */
destroyCDKScreen (cdkscreen);
/* End curses... */
endCDK ();
printf ("Cannot create the label. Is the window too small?\n");
ExitProgram (EXIT_FAILURE);
}
curs_set (0);
wtimeout (WindowOf (demo), 50);
/* Do this for-a-while... */
do
{
struct tm *currentTime;
/* Get the current time. */
time (&clck);
currentTime = localtime (&clck);
/* Put the current time in a string. */
sprintf (temp, "<C></B/29>%02d:%02d:%02d",
currentTime->tm_hour,
currentTime->tm_min,
currentTime->tm_sec);
mesg[0] = copyChar (temp);
/* Set the label contents. */
setCDKLabel (demo, (CDK_CSTRING2)mesg, 1, ObjOf (demo)->box);
/* Draw the label, and sleep. */
drawCDKLabel (demo, ObjOf (demo)->box);
napms (500);
}
while (wgetch (WindowOf (demo)) == ERR);
/* Clean up */
destroyCDKLabel (demo);
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}

446
deps/cdk-5.0-20161210/demos/command.c vendored Normal file
View File

@@ -0,0 +1,446 @@
/* $Id: command.c,v 1.22 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "command";
#endif
/* Define some global variables. */
#define MAXHISTORY 5000
static const char *introductionMessage[] =
{
"<C></B/16>Little Command Interface", "",
"<C>Written by Mike Glover", "",
"<C>Type </B>help<!B> to get help."};
/* This structure is used for keeping command history. */
struct history_st
{
int count;
int current;
char *command[MAXHISTORY];
};
/* Define some local prototypes. */
char *uc (char *word);
void help (CDKENTRY *entry);
static BINDFN_PROTO (historyUpCB);
static BINDFN_PROTO (historyDownCB);
static BINDFN_PROTO (viewHistoryCB);
static BINDFN_PROTO (listHistoryCB);
static BINDFN_PROTO (jumpWindowCB);
/*
* Written by: Mike Glover
* Purpose:
* This creates a very simple command interface.
*/
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKSWINDOW *commandOutput = 0;
CDKENTRY *commandEntry = 0;
chtype *convert = 0;
const char *prompt = "</B/24>Command >";
const char *title = "<C></B/5>Command Output Window";
int promptLen = 0;
int commandFieldWidth = 0;
struct history_st history;
char temp[600];
int junk;
/* Set up the history. */
history.current = 0;
history.count = 0;
/* Check the command line for options. */
while (1)
{
int ret;
/* Are there any more command line options to parse. */
if ((ret = getopt (argc, argv, "t:p:")) == -1)
{
break;
}
switch (ret)
{
case 'p':
prompt = copyChar (optarg);
break;
case 't':
title = copyChar (optarg);
break;
default:
break;
}
}
cdkscreen = initCDKScreen (NULL);
/* Start color. */
initCDKColor ();
/* Create the scrolling window. */
commandOutput = newCDKSwindow (cdkscreen, CENTER, TOP, -8, -2,
title, 1000, TRUE, FALSE);
/* Convert the prompt to a chtype and determine its length. */
convert = char2Chtype (prompt, &promptLen, &junk);
commandFieldWidth = COLS - promptLen - 4;
freeChtype (convert);
/* Create the entry field. */
commandEntry = newCDKEntry (cdkscreen, CENTER, BOTTOM,
0, prompt,
A_BOLD | COLOR_PAIR (8),
COLOR_PAIR (24) | '_',
vMIXED, commandFieldWidth, 1, 512, FALSE, FALSE);
/* Create the key bindings. */
bindCDKObject (vENTRY, commandEntry, KEY_UP, historyUpCB, &history);
bindCDKObject (vENTRY, commandEntry, KEY_DOWN, historyDownCB, &history);
bindCDKObject (vENTRY, commandEntry, KEY_TAB, viewHistoryCB, commandOutput);
bindCDKObject (vENTRY, commandEntry, CTRL ('^'), listHistoryCB, &history);
bindCDKObject (vENTRY, commandEntry, CTRL ('G'), jumpWindowCB, commandOutput);
/* Draw the screen. */
refreshCDKScreen (cdkscreen);
/* Show them who wrote this and how to get help. */
popupLabel (cdkscreen, (CDK_CSTRING2)introductionMessage, 5);
eraseCDKEntry (commandEntry);
/* Do this forever. */
for (;;)
{
char *command = 0;
char *upper;
/* Get the command. */
drawCDKEntry (commandEntry, ObjOf (commandEntry)->box);
command = activateCDKEntry (commandEntry, 0);
upper = uc (command);
/* Check the output of the command. */
if (strcmp (upper, "QUIT") == 0 ||
strcmp (upper, "EXIT") == 0 ||
strcmp (upper, "Q") == 0 ||
strcmp (upper, "E") == 0 ||
commandEntry->exitType == vESCAPE_HIT)
{
/* All done. */
freeChar (upper);
while (history.count-- > 0)
free (history.command[history.count]);
destroyCDKEntry (commandEntry);
destroyCDKSwindow (commandOutput);
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
else if (strcmp (command, "clear") == 0)
{
/* Keep the history. */
history.command[history.count] = copyChar (command);
history.count++;
history.current = history.count;
cleanCDKSwindow (commandOutput);
cleanCDKEntry (commandEntry);
}
else if (strcmp (command, "history") == 0)
{
/* Display the history list. */
listHistoryCB (vENTRY, commandEntry, &history, 0);
/* Keep the history. */
history.command[history.count] = copyChar (command);
history.count++;
history.current = history.count;
}
else if (strcmp (command, "help") == 0)
{
/* Keep the history. */
history.command[history.count] = copyChar (command);
history.count++;
history.current = history.count;
/* Display the help. */
help (commandEntry);
/* Clean the entry field. */
cleanCDKEntry (commandEntry);
eraseCDKEntry (commandEntry);
}
else
{
/* Keep the history. */
history.command[history.count] = copyChar (command);
history.count++;
history.current = history.count;
/* Jump to the bottom of the scrolling window. */
jumpToLineCDKSwindow (commandOutput, BOTTOM);
/* Insert a line providing the command. */
sprintf (temp, "Command: </R>%s", command);
addCDKSwindow (commandOutput, temp, BOTTOM);
/* Run the command. */
execCDKSwindow (commandOutput, command, BOTTOM);
/* Clean out the entry field. */
cleanCDKEntry (commandEntry);
}
/* Clean up a little. */
freeChar (upper);
}
}
/*
* This is the callback for the down arrow.
*/
static int historyUpCB (EObjectType cdktype GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
CDKENTRY *entry = (CDKENTRY *)object;
struct history_st *history = (struct history_st *)clientData;
/* Make sure we don't go out of bounds. */
if (history->current == 0)
{
Beep ();
return (FALSE);
}
/* Decrement the counter. */
history->current--;
/* Display the command. */
setCDKEntryValue (entry, history->command[history->current]);
drawCDKEntry (entry, ObjOf (entry)->box);
return (FALSE);
}
/*
* This is the callback for the down arrow.
*/
static int historyDownCB (EObjectType cdktype GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
CDKENTRY *entry = (CDKENTRY *)object;
struct history_st *history = (struct history_st *)clientData;
/* Make sure we don't go out of bounds. */
if (history->current == history->count)
{
Beep ();
return (FALSE);
}
/* Increment the counter... */
history->current++;
/* If we are at the end, clear the entry field. */
if (history->current == history->count)
{
cleanCDKEntry (entry);
drawCDKEntry (entry, ObjOf (entry)->box);
return (FALSE);
}
/* Display the command. */
setCDKEntryValue (entry, history->command[history->current]);
drawCDKEntry (entry, ObjOf (entry)->box);
return (FALSE);
}
/*
* This callback allows the user to play with the scrolling window.
*/
static int viewHistoryCB (EObjectType cdktype GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
CDKSWINDOW *swindow = (CDKSWINDOW *)clientData;
CDKENTRY *entry = (CDKENTRY *)object;
/* Let them play... */
activateCDKSwindow (swindow, 0);
/* Redraw the entry field. */
drawCDKEntry (entry, ObjOf (entry)->box);
return (FALSE);
}
/*
* This callback jumps to a line in the scrolling window.
*/
static int jumpWindowCB (EObjectType cdktype GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
CDKENTRY *entry = (CDKENTRY *)object;
CDKSWINDOW *swindow = (CDKSWINDOW *)clientData;
CDKSCALE *scale = 0;
int line;
/* Ask them which line they want to jump to. */
scale = newCDKScale (ScreenOf (entry), CENTER, CENTER,
"<C>Jump To Which Line",
"Line",
A_NORMAL, 5,
0, 0, swindow->listSize, 1, 2, TRUE, FALSE);
/* Get the line. */
line = activateCDKScale (scale, 0);
/* Clean up. */
destroyCDKScale (scale);
/* Jump to the line. */
jumpToLineCDKSwindow (swindow, line);
/* Redraw the widgets. */
drawCDKEntry (entry, ObjOf (entry)->box);
return (FALSE);
}
/*
* This callback allows the user to pick from the history list from a
* scrolling list.
*/
static int listHistoryCB (EObjectType cdktype GCC_UNUSED, void *object,
void *clientData,
chtype key GCC_UNUSED)
{
CDKENTRY *entry = (CDKENTRY *)object;
struct history_st *history = (struct history_st *)clientData;
CDKSCROLL *scrollList;
int height = (history->count < 10 ? history->count + 3 : 13);
int selection;
/* No history, no list. */
if (history->count == 0)
{
/* Popup a little window telling the user there are no commands. */
const char *mesg[] =
{
"<C></B/16>No Commands Entered",
"<C>No History"
};
popupLabel (ScreenOf (entry), (CDK_CSTRING2)mesg, 2);
/* Redraw the screen. */
eraseCDKEntry (entry);
drawCDKScreen (ScreenOf (entry));
/* And leave... */
return (FALSE);
}
/* Create the scrolling list of previous commands. */
scrollList = newCDKScroll (ScreenOf (entry), CENTER, CENTER, RIGHT,
height, 20, "<C></B/29>Command History",
(CDK_CSTRING2)history->command,
history->count,
NUMBERS, A_REVERSE, TRUE, FALSE);
/* Get the command to execute. */
selection = activateCDKScroll (scrollList, 0);
destroyCDKScroll (scrollList);
/* Check the results of the selection. */
if (selection >= 0)
{
/* Get the command and stick it back in the entry field. */
setCDKEntryValue (entry, history->command[selection]);
}
/* Redraw the screen. */
eraseCDKEntry (entry);
drawCDKScreen (ScreenOf (entry));
return (FALSE);
}
/*
* This function displays help.
*/
void help (CDKENTRY *entry)
{
const char *mesg[25];
/* Create the help message. */
mesg[0] = "<C></B/29>Help";
mesg[1] = "";
mesg[2] = "</B/24>When in the command line.";
mesg[3] = "<B=history > Displays the command history.";
mesg[4] = "<B=Ctrl-^ > Displays the command history.";
mesg[5] = "<B=Up Arrow > Scrolls back one command.";
mesg[6] = "<B=Down Arrow> Scrolls forward one command.";
mesg[7] = "<B=Tab > Activates the scrolling window.";
mesg[8] = "<B=help > Displays this help window.";
mesg[9] = "";
mesg[10] = "</B/24>When in the scrolling window.";
mesg[11] = "<B=l or L > Loads a file into the window.";
mesg[12] = "<B=s or S > Saves the contents of the window to a file.";
mesg[13] = "<B=Up Arrow > Scrolls up one line.";
mesg[14] = "<B=Down Arrow> Scrolls down one line.";
mesg[15] = "<B=Page Up > Scrolls back one page.";
mesg[16] = "<B=Page Down > Scrolls forward one page.";
mesg[17] = "<B=Tab/Escape> Returns to the command line.";
mesg[18] = "";
mesg[19] = "<C> (</B/24>Refer to the scrolling window online manual for more help<!B!24>.)";
popupLabel (ScreenOf (entry), (CDK_CSTRING2)mesg, 20);
}
/*
* This converts a word to upper case.
*/
char *uc (char *word)
{
char *upper = 0;
int length = 0;
int x;
/* Make sure the word is not null. */
if (word == 0)
{
return 0;
}
length = (int)strlen (word);
/* Get the memory for the new word. */
upper = (char *)malloc (sizeof (char) * (size_t) (length + 2));
if (upper == 0)
{
return (word);
}
/* Start converting the case. */
for (x = 0; x < length; x++)
{
int ch = (unsigned char)(word[x]);
if (isalpha (ch))
{
upper[x] = (char)toupper (ch);
}
else
{
upper[x] = word[x];
}
}
upper[length] = '\0';
return upper;
}

159
deps/cdk-5.0-20161210/demos/fileview.c vendored Normal file
View File

@@ -0,0 +1,159 @@
/* $Id: fileview.c,v 1.14 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "codeViewer";
#endif
/*
* This program demonstrates the file selector and the viewer widget.
*/
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKVIEWER *example = 0;
CDKFSELECT *fSelect = 0;
const char *directory = ".";
char *filename = 0;
char **info = 0;
const char *button[5];
const char *mesg[4];
char vtitle[256];
char temp[256];
int selected, lines;
/* Parse up the command line. */
while (1)
{
int ret = getopt (argc, argv, "d:f:");
if (ret == -1)
{
break;
}
switch (ret)
{
case 'd':
directory = strdup (optarg);
break;
case 'f':
filename = strdup (optarg);
break;
}
}
/* Create the viewer buttons. */
button[0] = "</5><OK><!5>";
button[1] = "</5><Cancel><!5>";
cdkscreen = initCDKScreen (NULL);
/* Start color. */
initCDKColor ();
/* Get the filename. */
if (filename == 0)
{
const char *title = "<C>Pick a file.";
const char *label = "File: ";
fSelect = newCDKFselect (cdkscreen, CENTER, CENTER, 20, 65,
title, label, A_NORMAL, '_', A_REVERSE,
"</5>", "</48>", "</N>", "</N>", TRUE, FALSE);
/*
* Set the starting directory. This is not neccessary because when
* the file selector starts it uses the present directory as a default.
*/
setCDKFselect (fSelect, directory, A_NORMAL, '.', A_REVERSE,
"</5>", "</48>", "</N>", "</N>", ObjOf (fSelect)->box);
/* Activate the file selector. */
filename = copyChar (activateCDKFselect (fSelect, 0));
/* Check how the person exited from the widget. */
if (fSelect->exitType == vESCAPE_HIT)
{
/* Pop up a message for the user. */
mesg[0] = "<C>Escape hit. No file selected.";
mesg[1] = "";
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
/* Destroy the file selector. */
destroyCDKFselect (fSelect);
/* Exit CDK. */
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
}
/* Destroy the file selector. */
destroyCDKFselect (fSelect);
/* Create the file viewer to view the file selected. */
example = newCDKViewer (cdkscreen, CENTER, CENTER, 20, -2,
(CDK_CSTRING2)button, 2,
A_REVERSE, TRUE, FALSE);
/* Could we create the viewer widget? */
if (example == 0)
{
/* Exit CDK. */
destroyCDKScreen (cdkscreen);
endCDK ();
/* Print out a message and exit. */
printf ("Cannot create viewer. Is the window too small?\n");
ExitProgram (EXIT_SUCCESS);
}
/* Open the file and read the contents. */
lines = CDKreadFile (filename, &info);
if (lines == -1)
{
printf ("Could not open %s\n", filename);
ExitProgram (EXIT_FAILURE);
}
/* Set up the viewer title, and the contents to the widget. */
sprintf (vtitle, "<C></B/22>%20s<!22!B>", filename);
setCDKViewer (example, vtitle,
(CDK_CSTRING2)info, lines,
A_REVERSE, TRUE, TRUE, TRUE);
/* Activate the viewer widget. */
selected = activateCDKViewer (example, 0);
/* Check how the person exited from the widget. */
if (example->exitType == vESCAPE_HIT)
{
mesg[0] = "<C>Escape hit. No Button selected.";
mesg[1] = "";
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
}
else if (example->exitType == vNORMAL)
{
sprintf (temp, "<C>You selected button %d", selected);
mesg[0] = temp;
mesg[1] = "";
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, (CDK_CSTRING2)mesg, 3);
}
/* Clean up. */
destroyCDKViewer (example);
destroyCDKScreen (cdkscreen);
CDKfreeStrings (info);
freeChar (filename);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}

1937
deps/cdk-5.0-20161210/demos/rolodex.c vendored Normal file

File diff suppressed because it is too large Load Diff

113
deps/cdk-5.0-20161210/demos/rolodex.h vendored Normal file
View File

@@ -0,0 +1,113 @@
/* $Id: rolodex.h,v 1.10 2012/03/21 00:59:17 tom Exp $ */
#include <cdk_test.h>
#include <time.h>
#include <fcntl.h>
#include <unistd.h>
#define MAXGROUPS 100
#define GLINETYPECOUNT 9
/*
* Declare some global variables.
*/
static char *GCurrentGroup = 0;
static char *GRCFile = 0;
static char *GDBMDir = 0;
static int GGroupModified = FALSE;
static const char *GLineType[] = {
"Voice",
"Cell",
"Pager",
"First FAX",
"Second FAX",
"Third FAX",
"First Data Line",
"Second Data Line",
"Third Data Line"
};
/*
* Create some definitions.
*/
typedef enum {vUnknown = -1, vVoice = 0, vCell, vPager, vFAX1, vFAX2, vFAX3, vData1, vData2, vData3} ELineType;
/*
* Define the group record structure.
*/
struct _group_st {
char *name;
char *desc;
char *dbm;
};
typedef struct _group_st SRolodex;
/*
* Define a phone record structure;
*/
struct _record_st {
char *name;
ELineType lineType;
char *phoneNumber;
char *address;
char *city;
char *province;
char *postalCode;
char *desc;
};
typedef struct _record_st SPhoneRecord;
struct _phone_data_st {
SPhoneRecord record[MAX_ITEMS];
int recordCount;
};
typedef struct _phone_data_st SPhoneData;
/*
* Define the callback prototypes.
*/
BINDFN_PROTO(helpCB);
BINDFN_PROTO(groupInfoCB);
BINDFN_PROTO(insertPhoneEntryCB);
BINDFN_PROTO(deletePhoneEntryCB);
BINDFN_PROTO(phoneEntryHelpCB);
int entryPreProcessCB (EObjectType cdkType, void *object, void *clientData, chtype input);
/*
* These functions use/modify the rolodex RC file.
*/
int readRCFile (char *filename, SRolodex *groupInfo);
int openNewRCFile (CDKSCREEN *screen, SRolodex *groups, int groupCount);
int writeRCFile (CDKSCREEN *screen, char *file, SRolodex *groups, int count);
int writeRCFileAs (CDKSCREEN *screen, SRolodex *groups, int count);
/*
* These functions use/modify rolodex phone groups.
*/
int addRolodexGroup (CDKSCREEN *screen, SRolodex *groups, int count);
int deleteRolodexGroup (CDKSCREEN *screen, SRolodex *groups, int count);
int pickRolodexGroup (CDKSCREEN *screen, const char *title, SRolodex *groups, int count);
void useRolodexGroup (CDKSCREEN *screen, char *name, char *desc, char *dbm);
/*
* These functions display misc information about the rolodex program.
*/
void displayRolodexStats (CDKSCREEN *screen, int groupCount);
void aboutCdkRolodex (CDKSCREEN *screen);
void displayPhoneInfo (CDKSCREEN *screen, SPhoneRecord record);
/*
* These functions use/modify phone data lists.
*/
int readPhoneDataFile (char *filename, SPhoneData *record);
int savePhoneDataFile (char *filename, SPhoneData *record);
int addPhoneRecord (CDKSCREEN *screen, SPhoneData *phoneData);
int deletePhoneRecord (CDKSCREEN *screen, SPhoneData *phoneData);
int getLargePhoneRecord (CDKSCREEN *screen, SPhoneRecord *phoneRecord);
int getSmallPhoneRecord (CDKSCREEN *screen, SPhoneRecord *phoneRecord);
/*
* These functions allow us to print out phone numbers.
*/
void printGroupNumbers (CDKSCREEN *screen, SRolodex *groups, int count);
int printGroup (SRolodex groupRecord, const char *filename, char *printer);

264
deps/cdk-5.0-20161210/demos/serial.c vendored Normal file
View File

@@ -0,0 +1,264 @@
/* $Id: serial.c,v 1.8 2016/12/04 15:22:16 tom Exp $ */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/termios.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <time.h>
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "serial";
#endif
/*
* Create global definitions.
*/
#define DEFAULT_PORT "/dev/ttya"
#define DEFAULT_POLL_INTERVAL 1 /* milliseconds */
/*
* This is the working function which probes the serial port.
*/
boolean probeModem (void);
/*
* Define some global variables.
*/
CDKLABEL *label = 0;
int LLastState = 0;
int LCurrentState = 0;
extern char *optarg;
char port[256];
int LFD;
/*
*
*/
int main (int argc, char **argv)
{
CDKSCREEN *cdkScreen = 0;
int lines = 0;
char *info[256], temp[256];
struct termios termInfo;
/* Set the deault values. */
strcpy (port, DEFAULT_PORT);
/* Parse up the command line. */
while (1)
{
int ret;
if ((ret = getopt (argc, argv, "p:h")) == -1)
{
break;
}
switch (ret)
{
case 'p':
strcpy (port, optarg);
break;
case 'h':
printf
("Usage: %s [-p Port] [-i Poll Interval] [-c Poll Count] [-v] [-h]\n",
argv[0]);
ExitProgram (EXIT_SUCCESS);
break;
}
}
cdkScreen = initCDKScreen (NULL);
/* Start CDK color. */
initCDKColor ();
/*
* Set the title of the main window.
*/
sprintf (temp, "<C>Serial Port Monitor (%s)", port);
info[lines++] = copyChar (temp);
info[lines++] = copyChar ("<C><#HL(30)>");
info[lines++] = copyChar ("");
info[lines++] = copyChar ("Line Enabled : -");
info[lines++] = copyChar ("Data Terminal Ready: -");
info[lines++] = copyChar ("Carrier Detect : -");
info[lines++] = copyChar ("Request To Send : -");
info[lines++] = copyChar ("Clear To Send : -");
info[lines++] = copyChar ("Secondary Transmit : -");
info[lines++] = copyChar ("Secondary Receive : -");
info[lines++] = copyChar ("");
/* Create the label widget. */
label = newCDKLabel (cdkScreen, CENTER, CENTER, info, lines, TRUE, FALSE);
drawCDKLabel (label, TRUE);
/*
* Open the serial port read only.
*/
if ((LFD = open (port, O_RDONLY | O_NDELAY, 0)) == -1)
{
/* Create a pop-up dialog box... */
printf ("Error: Open of <%s> failed.\n", port);
ExitProgram (EXIT_FAILURE);
}
termInfo.c_cflag = CRTSCTS | CLOCAL;
if (tcgetattr (LFD, &termInfo) != 0)
{
/* Really should create a pop-up dialog box... */
printf ("Error: Could not get port attributes. Closing the port.\n");
close (LFD);
ExitProgram (EXIT_FAILURE);
}
for (;;)
{
/* Probe the modem. */
probeModem ();
/*
* Sleep for the given amount of time. We do this first so no
* weird refresh things happen.
*/
napms (DEFAULT_POLL_INTERVAL);
}
}
/*
* This probes the modem and determines if we need to update
* the display.
*/
boolean probeModem (void)
{
int lines = 0;
char *info[256], temp[256];
/* Start building the label. */
sprintf (temp, "<C>Serial Port Monitor (%s)", port);
info[lines++] = copyChar (temp);
info[lines++] = copyChar ("<C><#HL(30)>");
info[lines++] = copyChar ("");
/*
* Get the serial port info.
*/
ioctl (LFD, TIOCMGET, &LCurrentState);
/*
* If the states are different, change the display.
*/
if (LLastState != LCurrentState)
{
/*
* Check for line enabled.
*/
if (LCurrentState & TIOCM_LE)
{
info[lines++] = copyChar ("Line Enabled : <#DI>");
}
else
{
info[lines++] = copyChar ("Line Enabled : ");
}
/*
* Check for data terminal ready.
*/
if (LCurrentState & TIOCM_DTR)
{
info[lines++] = copyChar ("Data Terminal Ready: <#DI>");
}
else
{
info[lines++] = copyChar ("Data Terminal Ready: ");
}
/*
* Check for carrier detect.
*/
if (LCurrentState & TIOCM_CAR)
{
info[lines++] = copyChar ("Carrier Detect : <#DI>");
}
else
{
info[lines++] = copyChar ("Carrier Detect : ");
}
/*
* Check for request to send.
*/
if (LCurrentState & TIOCM_RTS)
{
info[lines++] = copyChar ("Request To Send : <#DI>");
}
else
{
info[lines++] = copyChar ("Request To Send : ");
}
/*
* Check for clear to send.
*/
if (LCurrentState & TIOCM_CTS)
{
info[lines++] = copyChar ("Clear To Send : <#DI>");
}
else
{
info[lines++] = copyChar ("Clear To Send : ");
}
/*
* Check for secondary transmit.
*/
if (LCurrentState & TIOCM_ST)
{
info[lines++] = copyChar ("Secondary Transmit : <#DI>");
}
else
{
info[lines++] = copyChar ("Secondary Transmit : ");
}
/*
* Check for secondary receive.
*/
if (LCurrentState & TIOCM_SR)
{
info[lines++] = copyChar ("Secondary Receive : <#DI>");
}
else
{
info[lines++] = copyChar ("Secondary Receive : ");
}
}
info[lines++] = copyChar ("");
/* Only do this if things have changed. */
if (LLastState != LCurrentState)
{
eraseCDKLabel (label);
setCDKLabel (label, info, lines, TRUE);
drawCDKLabel (label, TRUE);
}
/*
* Keep the current state.
*/
LLastState = LCurrentState;
/*
* Return False to tell X that we want this funtion to be
* run again.
*/
return FALSE;
}

83
deps/cdk-5.0-20161210/demos/stopSign.c vendored Normal file
View File

@@ -0,0 +1,83 @@
/* $Id: stopSign.c,v 1.13 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "sillyness_ex";
#endif
int main (void)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkscreen = 0;
CDKLABEL *stopSign = 0;
CDKLABEL *title = 0;
const char *mesg[5];
const char *sign[4];
chtype key;
boolean functionKey;
cdkscreen = initCDKScreen (NULL);
/* Start CDK Colors. */
initCDKColor ();
/* Set the labels up. */
mesg[0] = "<C><#HL(40)>";
mesg[1] = "<C>Press </B/16>r<!B!16> for the </B/16>red light";
mesg[2] = "<C>Press </B/32>y<!B!32> for the </B/32>yellow light";
mesg[3] = "<C>Press </B/24>g<!B!24> for the </B/24>green light";
mesg[4] = "<C><#HL(40)>";
sign[0] = " <#DI> ";
sign[1] = " <#DI> ";
sign[2] = " <#DI> ";
/* Declare the labels. */
title = newCDKLabel (cdkscreen, CENTER, TOP,
(CDK_CSTRING2) mesg, 5,
FALSE, FALSE);
stopSign = newCDKLabel (cdkscreen, CENTER, CENTER,
(CDK_CSTRING2) sign, 3,
TRUE, TRUE);
/* Do this until they hit q or escape. */
for (;;)
{
drawCDKLabel (title, FALSE);
drawCDKLabel (stopSign, TRUE);
key = (chtype)getchCDKObject (ObjOf (stopSign), &functionKey);
if (key == KEY_ESC || key == 'q' || key == 'Q')
{
break;
}
else if (key == 'r' || key == 'R')
{
sign[0] = " </B/16><#DI> ";
sign[1] = " o ";
sign[2] = " o ";
}
else if (key == 'y' || key == 'Y')
{
sign[0] = " o ";
sign[1] = " </B/32><#DI> ";
sign[2] = " o ";
}
else if (key == 'g' || key == 'G')
{
sign[0] = " o ";
sign[1] = " o ";
sign[2] = " </B/24><#DI> ";
}
/* Set the contents of the label and re-draw it. */
setCDKLabel (stopSign, (CDK_CSTRING2) sign, 3, TRUE);
}
/* Clean up. */
destroyCDKLabel (title);
destroyCDKLabel (stopSign);
destroyCDKScreen (cdkscreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}

1139
deps/cdk-5.0-20161210/demos/syb.c vendored Normal file

File diff suppressed because it is too large Load Diff

508
deps/cdk-5.0-20161210/demos/vinstall.c vendored Normal file
View File

@@ -0,0 +1,508 @@
/* $Id: vinstall.c,v 1.21 2016/12/04 15:22:16 tom Exp $ */
#include <cdk_test.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName = "vinstall";
#endif
/*
* Written by: Mike Glover
* Purpose:
* This is a fairly basic install interface.
*/
/* Declare global types and prototypes. */
static const char *FPUsage = "-f filename [-s source directory] [-d destination directory] [-t title] [-o Output file] [-q]";
typedef enum
{
vCanNotOpenSource,
vCanNotOpenDest,
vOK
}
ECopyFile;
static ECopyFile copyFile (CDKSCREEN *cdkScreen, char *src, char *dest);
static int verifyDirectory (CDKSCREEN *screen, char *directory);
int main (int argc, char **argv)
{
/* *INDENT-EQLS* */
CDKSCREEN *cdkScreen = 0;
CDKSWINDOW *installOutput = 0;
CDKENTRY *sourceEntry = 0;
CDKENTRY *destEntry = 0;
CDKLABEL *titleWin = 0;
CDKHISTOGRAM *progressBar = 0;
char *sourcePath = 0;
char *destPath = 0;
char *sourceDir = 0;
char *destDir = 0;
char *filename = 0;
char *title = 0;
char *output = 0;
int quiet = FALSE;
int errors = 0;
int sWindowHeight = 0;
char *titleMessage[10];
char **fileList = 0;
const char *mesg[20];
char oldPath[512], newPath[512], temp[2000];
int count, ret, x;
/* Parse up the command line. */
while (1)
{
ret = getopt (argc, argv, "d:s:f:t:o:q");
if (ret == -1)
{
break;
}
switch (ret)
{
case 's':
sourcePath = strdup (optarg);
break;
case 'd':
destPath = strdup (optarg);
break;
case 'f':
filename = strdup (optarg);
break;
case 't':
title = strdup (optarg);
break;
case 'o':
output = strdup (optarg);
break;
case 'q':
quiet = TRUE;
break;
}
}
/* Make sure have everything we need. */
if (filename == 0)
{
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
ExitProgram (EXIT_FAILURE);
}
/* Open the file list file and read it in. */
count = CDKreadFile (filename, &fileList);
if (count == 0)
{
fprintf (stderr, "%s: Input filename <%s> is empty.\n", argv[0], filename);
ExitProgram (EXIT_FAILURE);
}
/*
* Cycle through what was given to us and save it.
*/
for (x = 0; x < count; x++)
{
/* Strip white space from the line. */
stripWhiteSpace (vBOTH, fileList[x]);
}
cdkScreen = initCDKScreen (NULL);
/* Start color. */
initCDKColor ();
/* Create the title label. */
titleMessage[0] = copyChar ("<C></32/B><#HL(30)>");
if (title == 0)
{
sprintf (temp, "<C></32/B>CDK Installer");
}
else
{
sprintf (temp, "<C></32/B>%.256s", title);
}
titleMessage[1] = copyChar (temp);
titleMessage[2] = copyChar ("<C></32/B><#HL(30)>");
titleWin = newCDKLabel (cdkScreen, CENTER, TOP,
(CDK_CSTRING2)titleMessage, 3,
FALSE, FALSE);
freeCharList (titleMessage, 3);
/* Allow them to change the install directory. */
if (sourcePath == 0)
{
sourceEntry = newCDKEntry (cdkScreen, CENTER, 8,
0, "Source Directory :",
A_NORMAL, '.', vMIXED,
40, 0, 256, TRUE, FALSE);
}
if (destPath == 0)
{
destEntry = newCDKEntry (cdkScreen, CENTER, 11,
0, "Destination Directory:", A_NORMAL,
'.', vMIXED, 40, 0, 256, TRUE, FALSE);
}
/* Get the source install path. */
if (sourceEntry != 0)
{
drawCDKScreen (cdkScreen);
sourceDir = copyChar (activateCDKEntry (sourceEntry, 0));
}
else
{
sourceDir = copyChar (sourcePath);
}
/* Get the destination install path. */
if (destEntry != 0)
{
drawCDKScreen (cdkScreen);
destDir = copyChar (activateCDKEntry (destEntry, 0));
}
else
{
destDir = copyChar (destPath);
}
/* Destroy the path entry fields. */
if (sourceEntry != 0)
{
destroyCDKEntry (sourceEntry);
}
if (destEntry != 0)
{
destroyCDKEntry (destEntry);
}
/*
* Verify that the source directory is valid.
*/
if (verifyDirectory (cdkScreen, sourceDir) != 0)
{
/* Clean up and leave. */
freeChar (destDir);
freeChar (sourceDir);
destroyCDKLabel (titleWin);
destroyCDKScreen (cdkScreen);
endCDK ();
ExitProgram (EXIT_FAILURE);
}
/*
* Verify that the source directory is valid.
*/
if (verifyDirectory (cdkScreen, destDir) != 0)
{
/* Clean up and leave. */
freeChar (destDir);
freeChar (sourceDir);
destroyCDKLabel (titleWin);
destroyCDKScreen (cdkScreen);
endCDK ();
ExitProgram (EXIT_FAILURE);
}
/* Create the histogram. */
progressBar = newCDKHistogram (cdkScreen, CENTER, 5,
3, 0, HORIZONTAL,
"<C></56/B>Install Progress",
TRUE, FALSE);
/* Set the top left/right characters of the histogram. */
setCDKHistogramLLChar (progressBar, ACS_LTEE);
setCDKHistogramLRChar (progressBar, ACS_RTEE);
/* Set the initial value of the histogram. */
setCDKHistogram (progressBar, vPERCENT, TOP, A_BOLD,
1, count, 1,
COLOR_PAIR (24) | A_REVERSE | ' ',
TRUE);
/* Determine the height of the scrolling window. */
if (LINES >= 16)
{
sWindowHeight = LINES - 13;
}
else
{
sWindowHeight = 3;
}
/* Create the scrolling window. */
installOutput = newCDKSwindow (cdkScreen, CENTER, BOTTOM,
sWindowHeight, 0,
"<C></56/B>Install Results",
2000, TRUE, FALSE);
/* Set the top left/right characters of the scrolling window. */
setCDKSwindowULChar (installOutput, ACS_LTEE);
setCDKSwindowURChar (installOutput, ACS_RTEE);
/* Draw the screen. */
drawCDKScreen (cdkScreen);
/* Start copying the files. */
for (x = 0; x < count; x++)
{
char **files;
int chunks;
/*
* If the 'file' list file has 2 columns, the first is
* the source filename, the second being the destination
* filename.
*/
files = CDKsplitString (fileList[x], ' ');
chunks = (int)CDKcountStrings ((CDK_CSTRING2)files);
if (chunks == 2)
{
/* Create the correct paths. */
sprintf (oldPath, "%s/%s", sourceDir, files[0]);
sprintf (newPath, "%s/%s", destDir, files[1]);
}
else
{
/* Create the correct paths. */
sprintf (oldPath, "%s/%s", sourceDir, fileList[x]);
sprintf (newPath, "%s/%s", destDir, fileList[x]);
}
CDKfreeStrings (files);
/* Copy the file from the source to the destination. */
ret = copyFile (cdkScreen, oldPath, newPath);
if (ret == vCanNotOpenSource)
{
sprintf (temp,
"</16>Error: Can not open source file \"%.256s\"<!16>", oldPath);
errors++;
}
else if (ret == vCanNotOpenDest)
{
sprintf (temp,
"</16>Error: Can not open destination file \"%.256s\"<!16>", newPath);
errors++;
}
else
{
sprintf (temp, "</24>%.256s -> %.256s", oldPath, newPath);
}
/* Add the message to the scrolling window. */
addCDKSwindow (installOutput, temp, BOTTOM);
drawCDKSwindow (installOutput, ObjOf (installOutput)->box);
/* Update the histogram. */
setCDKHistogram (progressBar, vPERCENT, TOP, A_BOLD,
1, count, x + 1,
COLOR_PAIR (24) | A_REVERSE | ' ',
TRUE);
/* Update the screen. */
drawCDKHistogram (progressBar, TRUE);
}
/*
* If there were errors, inform the user and allow them to look at the
* errors in the scrolling window.
*/
if (errors != 0)
{
/* Create the information for the dialog box. */
const char *buttons[] =
{
"Look At Errors Now",
"Save Output To A File",
"Ignore Errors"
};
mesg[0] = "<C>There were errors in the installation.";
mesg[1] = "<C>If you want, you may scroll through the";
mesg[2] = "<C>messages of the scrolling window to see";
mesg[3] = "<C>what the errors were. If you want to save";
mesg[4] = "<C>the output of the window you may press </R>s<!R>";
mesg[5] = "<C>while in the window, or you may save the output";
mesg[6] = "<C>of the install now and look at the install";
mesg[7] = "<C>history at a later date.";
/* Popup the dialog box. */
ret = popupDialog (cdkScreen,
(CDK_CSTRING2)mesg, 8,
(CDK_CSTRING2)buttons, 3);
if (ret == 0)
{
activateCDKSwindow (installOutput, 0);
}
else if (ret == 1)
{
(void)injectCDKSwindow (installOutput, 's');
}
}
else
{
/*
* If they specified the name of an output file, then save the
* results of the installation to that file.
*/
if (output != 0)
{
dumpCDKSwindow (installOutput, output);
}
else
{
/* Ask them if they want to save the output of the scrolling window. */
if (quiet == FALSE)
{
const char *buttons[] =
{
"No",
"Yes"
};
mesg[0] = "<C>Do you want to save the output of the";
mesg[1] = "<C>scrolling window to a file?";
if (popupDialog (cdkScreen,
(CDK_CSTRING2)mesg, 2,
(CDK_CSTRING2)buttons, 2) == 1)
{
(void)injectCDKSwindow (installOutput, 's');
}
}
}
}
/* Clean up. */
destroyCDKLabel (titleWin);
destroyCDKHistogram (progressBar);
destroyCDKSwindow (installOutput);
destroyCDKScreen (cdkScreen);
endCDK ();
ExitProgram (EXIT_SUCCESS);
}
/*
* This copies a file from one place to another. (tried rename
* library call, but it is equivalent to mv)
*/
static ECopyFile copyFile (CDKSCREEN *cdkScreen GCC_UNUSED, char *src, char *dest)
{
char command[2000];
FILE *fd;
/* Make sure we can open the source file. */
if ((fd = fopen (src, "r")) == 0)
{
return vCanNotOpenSource;
}
fclose (fd);
/*
* Remove the destination file first, just in case it already exists.
* This allows us to check if we can write to the desintation file.
*/
sprintf (command, "rm -f %s", dest);
system (command);
/* Try to open the destination. */
if ((fd = fopen (dest, "w")) == 0)
{
return vCanNotOpenDest;
}
fclose (fd);
/*
* Copy the file. There has to be a better way to do this. I
* tried rename and link but they both have the same limitation
* as the 'mv' command that you can not move across partitions.
* Quite limiting in an install binary.
*/
sprintf (command, "rm -f %s; cp %s %s; chmod 444 %s", dest, src, dest, dest);
system (command);
return vOK;
}
/*
* This makes sure that the directory given exists. If it
* doesn't then it will make it.
* THINK
*/
static int verifyDirectory (CDKSCREEN *cdkScreen, char *directory)
{
int status = 0;
#if !defined (__MINGW32__)
mode_t dirMode = S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH;
#endif
struct stat fileStat;
char temp[512];
/* Stat the directory. */
if (lstat (directory, &fileStat) != 0)
{
/* The directory does not exist. */
if (errno == ENOENT)
{
const char *buttons[] =
{
"Yes",
"No"
};
const char *mesg[10];
char *error[10];
/* Create the question. */
mesg[0] = "<C>The directory ";
sprintf (temp, "<C>%.256s", directory);
mesg[1] = temp;
mesg[2] = "<C>Does not exist. Do you want to";
mesg[3] = "<C>create it?";
/* Ask them if they want to create the directory. */
if (popupDialog (cdkScreen,
(CDK_CSTRING2)mesg, 4,
(CDK_CSTRING2)buttons, 2) == 0)
{
/* Create the directory. */
#if defined (__MINGW32__)
if (mkdir (directory) != 0)
#else
if (mkdir (directory, dirMode) != 0)
#endif
{
/* Create the error message. */
error[0] = copyChar ("<C>Could not create the directory");
sprintf (temp, "<C>%.256s", directory);
error[1] = copyChar (temp);
#ifdef HAVE_STRERROR
sprintf (temp, "<C>%.256s", strerror (errno));
#else
sprintf (temp, "<C>Check the permissions and try again.");
#endif
error[2] = copyChar (temp);
/* Pop up the error message. */
popupLabel (cdkScreen, (CDK_CSTRING2)error, 3);
freeCharList (error, 3);
status = -1;
}
}
else
{
/* Create the message. */
error[0] = copyChar ("<C>Installation aborted.");
/* Pop up the error message. */
popupLabel (cdkScreen, (CDK_CSTRING2)error, 1);
freeCharList (error, 1);
status = -1;
}
}
}
return status;
}