File: alphalist_ex.c

package info (click to toggle)
libcdk 4.9.9-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,008 kB
  • ctags: 2,239
  • sloc: ansic: 28,664; sh: 334; makefile: 275; cpp: 42
file content (83 lines) | stat: -rw-r--r-- 1,998 bytes parent folder | download | duplicates (2)
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
#include "cdk.h"

#ifdef HAVE_XCURSES
char *XCursesProgramName="alphalist_ex";
#endif

/*
 * This program demonstrates the Cdk alphalist widget.
 */
#define	MAXINFOLINES	10000

int getUserList (char **list, int maxItems);

int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= (CDKSCREEN *)NULL;
   CDKALPHALIST *alphaList	= (CDKALPHALIST *)NULL;
   WINDOW *cursesWin		= (WINDOW *)NULL;
   char *title			= "<C></B/24>Alpha List\n<C>Title";
   char *label			= "</B>Account: ";
   char *word			= (char *)NULL;
   char *info[MAXINFOLINES], *mesg[10], temp[256];
   int count;

   /* Set up CDK. */ 
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start color. */
   initCDKColor();

   /* Get the user list. */
   count = getUserList (info, MAXINFOLINES);

   /* Create the alpha list widget. */
   alphaList = newCDKAlphalist (cdkscreen, CENTER, CENTER, 
				0, 0, title, label,
				info, count,
				'_', A_REVERSE, TRUE, FALSE);

   /* Let them play with the alpha list. */
   word = activateCDKAlphalist (alphaList, NULL);

   /* 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)", word);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
   }

   /* Clean up. */
   destroyCDKAlphalist (alphaList);
   delwin (cursesWin);
   endCDK();
   exit (0);
}

/*
 * This reads the passwd file and retrieves user information.
 */
int getUserList (char **list, int maxItems)
{
   struct passwd *ent;
   int x = 0;

   while ( (ent = getpwent ()) != NULL)
   {
      list[x++] = copyChar (ent->pw_name);
   }
   return x;
}