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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
/* $Id: cdkdialog.c,v 1.7 2005/03/08 19:51:24 tom Exp $ */
#include <cdk.h>
#ifdef XCURSES
char *XCursesProgramName="cdkdialog";
#endif
/*
* Define file local variables.
*/
static 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)
{
/* Declare variables. */
CDKSCREEN *cdkScreen = 0;
CDKDIALOG *widget = 0;
WINDOW *cursesWindow = 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 x, 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:" "X:Y:NS");
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);
exit (-1);
}
}
/* 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);
exit (-1);
}
}
else
{
/* No message, no file, it's an error. */
fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
exit (-1);
}
}
else
{
/* Split the message up. */
messageList = CDKsplitString (message, '\n');
messageLines = CDKcountStrings (messageList);
}
/* Set up the buttons for the dialog box. */
if (buttons == 0)
{
buttonList[0] = copyChar ("OK");
buttonList[1] = copyChar ("Cancel");
buttonCount = 2;
}
else
{
/* Split the button list up. */
buttonList = CDKsplitString (buttons, '\n');
buttonCount = CDKcountStrings (buttonList);
}
/* Set up CDK. */
cursesWindow = initscr();
cdkScreen = initCDKScreen (cursesWindow);
/* 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,
messageList, messageLines,
buttonList, buttonCount,
A_REVERSE,
boxWidget, boxWidget, shadowWidget);
/* Check to make sure we created the dialog box. */
if (widget == 0)
{
/* Clean up used memory. */
for (x=0; x < messageLines; x++)
{
freeChar (messageList[x]);
}
for (x=0; x < buttonCount; x++)
{
freeChar (buttonList[x]);
}
/* Shut down curses and CDK. */
destroyCDKScreen (cdkScreen);
endCDK();
/* Spit out the message. */
fprintf (stderr, "Error: Could not create the dialog box. Is the window too small?\n");
/* Exit with an error. */
exit (-1);
}
/* 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);
}
/* Clean up. */
for (x=0; x < messageLines; x++)
{
freeChar (messageList[x]);
}
for (x=0; x < buttonCount; x++)
{
freeChar (buttonList[x]);
}
/* Exit with the button number picked. */
exit (answer);
}
|