1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 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);
}
|