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
|
/* $Id: alphalist_ex.c,v 1.13 2004/08/28 01:02:30 tom Exp $ */
#include <cdk.h>
#ifdef HAVE_XCURSES
char *XCursesProgramName="alphalist_ex";
#endif
/*
* This program demonstrates the Cdk alphalist widget.
*/
/*
* This reads the passwd file and retrieves user information.
*/
static int getUserList (char ***list)
{
struct passwd *ent;
int x = 0;
unsigned used = 0;
while ( (ent = getpwent ()) != 0)
{
used = CDKallocStrings(list, ent->pw_name, x++, used);
}
return x;
}
int main(int argc, char **argv)
{
/* Declare variables. */
CDKSCREEN *cdkscreen = 0;
CDKALPHALIST *alphaList = 0;
WINDOW *cursesWin = 0;
char *title = "<C></B/24>Alpha List\n<C>Title";
char *label = "</B>Account: ";
char *word = 0;
char **info = 0;
char *mesg[5], temp[256];
int count;
CDK_PARAMS params;
CDKparseParams(argc, argv, ¶ms, CDK_CLI_PARAMS);
/* Set up CDK. */
cursesWin = initscr();
cdkscreen = initCDKScreen (cursesWin);
/* Start color. */
initCDKColor();
/* Get the user list. */
count = getUserList (&info);
/* Create the alpha list widget. */
alphaList = newCDKAlphalist (cdkscreen,
CDKparamValue(¶ms, 'X', CENTER),
CDKparamValue(¶ms, 'Y', CENTER),
CDKparamValue(¶ms, 'H', 0),
CDKparamValue(¶ms, 'W', 0),
title, label,
info, count,
'_', A_REVERSE,
CDKparamValue(¶ms, 'N', TRUE),
CDKparamValue(¶ms, 'S', FALSE));
CDKfreeStrings(info);
/* Let them play with the alpha list. */
word = activateCDKAlphalist (alphaList, 0);
/* Determine what the user did. */
if (alphaList->exitType == vESCAPE_HIT)
{
mesg[0] = "<C>You hit escape. No word was selected.";
mesg[1] = "",
mesg[2] = "<C>Press any key to continue.";
popupLabel (cdkscreen, mesg, 3);
}
else if (alphaList->exitType == vNORMAL)
{
mesg[0] = "<C>You selected the following";
sprintf (temp, "<C>(%.*s)", (int)(sizeof(temp) - 10), word);
mesg[1] = temp;
mesg[2] = "";
mesg[3] = "<C>Press any key to continue.";
popupLabel (cdkscreen, mesg, 4);
}
/* Clean up. */
destroyCDKAlphalist (alphaList);
destroyCDKScreen (cdkscreen);
endCDK();
exit (EXIT_SUCCESS);
}
|