Example #1
0
/*
 * This program demonstrates the Cdk itemlist widget.
 *
 * Options (in addition to minimal CLI parameters):
 *	-c	create the data after the widget
 */
int main(int argc, char **argv)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKITEMLIST *monthlist	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C>Pick A Month";
   char *label			= "</U/5>Month:";
   char *info[MONTHS], temp[256], *mesg[10];
   int choice, startMonth;
   struct tm *dateInfo;
   time_t clck;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "c" CDK_MIN_PARAMS);

   /*
    * Get the current date and set the default month to the
    * current month.
    */
   time (&clck);
   dateInfo	= localtime (&clck);
   startMonth	= dateInfo->tm_mon;

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

   /* Start CDK colors. */
   initCDKColor();

   /* Create the choice list. */
   info[0]	= "<C></5>January";
   info[1]	= "<C></5>February";
   info[2]	= "<C></B/19>March";
   info[3]	= "<C></5>April";
   info[4]	= "<C></5>May";
   info[5]	= "<C></K/5>June";
   info[6]	= "<C></12>July";
   info[7]	= "<C></5>August";
   info[8]	= "<C></5>September";
   info[9]	= "<C></32>October";
   info[10]	= "<C></5>November";
   info[11]	= "<C></11>December";

   /* Create the itemlist widget. */
   monthlist	= newCDKItemlist (cdkscreen,
				  CDKparamValue(&params, 'X', CENTER),
				  CDKparamValue(&params, 'Y', CENTER),
				  title,
				  label,
				  CDKparamNumber(&params, 'c') ? 0 : info,
				  CDKparamNumber(&params, 'c') ? 0 : MONTHS,
				  startMonth,
				  CDKparamValue(&params, 'N', TRUE),
				  CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (monthlist == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the itemlist box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber(&params, 'c'))
   {
      setCDKItemlistValues (monthlist, info, MONTHS, 0);
   }

   /* Activate the widget. */
   choice = activateCDKItemlist (monthlist, 0);

   /* Check how they exited from the widget. */
   if (monthlist->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No item selected.";
      mesg[1] = "";
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(monthlist), mesg, 3);
   }
   else if (monthlist->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected the %dth item which is", choice);
      mesg[0] = copyChar (temp);
      mesg[1] = info[choice];
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(monthlist), mesg, 4);
      freeChar (mesg[0]);
   }

   /* Clean up. */
   destroyCDKItemlist (monthlist);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Example #2
0
char *pedir_datos (char *tipo)
{
   /* Declare variables. */
   CDKBUTTONBOX *buttonWidget   = 0;
   CDKENTRY *entry      = 0;
   CDKENTRY *pass       = 0;
   WINDOW *cursesWin        = 0;
   char *info           = 0;
CDKSCREEN *cdkscreen     = 0;
int selection=0;
char *buttons[]      = {" OK ", " Cancel "};
   /* Set up CDK. */
   cursesWin = initscr ();
   cdkscreen = initCDKScreen (cursesWin);
	box(cursesWin,0,0);
   /* Start color. */
   initCDKColor ();

   /* Create the entry widget. */



   if(strcmp(tipo,"usuario")==0)
{
   entry = newCDKEntry (cdkscreen, CENTER, CENTER,
            "<C>Usuario", "", A_NORMAL, '.', vMIXED,
            40, 0, 256, TRUE, FALSE);
 }
 else
 {
   entry = newCDKEntry (cdkscreen, CENTER, CENTER,
            "<C>Contrasenia:", "", A_INVIS, '.', vMIXED,
            40, 0, 256, TRUE, FALSE);



        }
   if (entry == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK();

      fprintf(stderr, "Cannot create entry-widget\n");
    //  ExitProgram (EXIT_FAILURE);
   }


   /* Create the button box widget. */
   buttonWidget = newCDKButtonbox (cdkscreen,
                   getbegx (entry->win),
                   getbegy (entry->win) + entry->boxHeight - 1,
                   1, entry->boxWidth - 1,
                   0, 1, 2,
                   buttons, 2, A_REVERSE,
                   TRUE, FALSE);
   if (buttonWidget == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK();

      fprintf(stderr, "Cannot create buttonbox-widget\n");
 //     ExitProgram (EXIT_FAILURE);
   }

   /* Set the lower left and right characters of the box. */
   setCDKEntryLLChar (entry, ACS_LTEE);
   setCDKEntryLRChar (entry, ACS_RTEE);
   setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
   setCDKButtonboxURChar (buttonWidget, ACS_RTEE);

   /*
    * Bind the Tab key in the entry field to send a
    * Tab key to the button box widget.
    */
   bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget);

   /* Activate the entry field. */
   drawCDKButtonbox (buttonWidget, TRUE);
   info = copyChar (activateCDKEntry (entry, 0));
   selection = buttonWidget->currentButton;

   /* Clean up. */
   destroyCDKButtonbox (buttonWidget);
   destroyCDKEntry (entry);
   destroyCDKScreen (cdkscreen);
   endCDK ();

   /* Spit out some info. */
/*   printf ("You typed in (%s) and selected button (%s)\n",
       (info != 0) ? info : "<null>",
       buttons[selection]);
*/
  // freeChar (info);
   return info;
//   ExitProgram (EXIT_SUCCESS);
}
Example #3
0
File: fselect.c Project: dyne/MuSE
/*
 * This creates a list of the files in the current directory.
 */
int setCDKFselectDirContents (CDKFSELECT *fselect)
{
   /* Declare local variables. */
   struct stat fileStat;
   char **dirList = 0;
   char temp[200], mode;
   int fileCount;
   int x = 0;

   /* Get the directory contents. */
   fileCount = CDKgetDirectoryContents (fselect->pwd, &dirList);
   if (fileCount == -1)
   {
      /* We couldn't read the directory. Return. */
      return 0;
   }

   /* Clean out the old directory list. */
   freeCharList (fselect->dirContents, fselect->fileCounter);
   fselect->fileCounter = fileCount;

   /* Set the properties of the files. */
   for (x=0; x < fselect->fileCounter; x++)
   {
      /* Stat the file. */
      lstat (dirList[x], &fileStat);

      /* Check the mode. */
      mode = ' ';
      if (((fileStat.st_mode & S_IXUSR) != 0) ||
		((fileStat.st_mode & S_IXGRP) != 0) ||
		((fileStat.st_mode & S_IXOTH) != 0))
      {
	  mode = '*';
      }

      /* Create the filename. */
      switch (mode2Filetype(fileStat.st_mode)) {
      case 'l':
	 sprintf (temp, "%s%s@", fselect->linkAttribute, dirList[x]);
	 break;
      case '@':
	 sprintf (temp, "%s%s&", fselect->sockAttribute, dirList[x]);
	 break;
      case '-':
	 sprintf (temp, "%s%s%c", fselect->fileAttribute, dirList[x], mode);
	 break;
      case 'd':
	 sprintf (temp, "%s%s/", fselect->dirAttribute, dirList[x]);
	 break;
      default:
	 sprintf (temp, "%s%c", dirList[x], mode);
	 break;
      }
      fselect->dirContents[x] = copyChar (temp);

      /* Free up this piece of memory. */
   }
   CDKfreeStrings (dirList);
   return 1;
}
Example #4
0
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKVIEWER *example   = 0;
   CDKFSELECT *fSelect  = 0;
   WINDOW *cursesWin    = 0;
   const char *title    = "<C>Pick\n<C>A\n<C>File";
   const char *label    = "File: ";
   char **info          = 0;
   const char *button[5];
   const char *mesg[4];
   char *filename;
   char vTitle[256];
   char temp[256];
   int selected, lines;

   CDK_PARAMS params;
   char *directory;

   CDKparseParams (argc, argv, &params, "d:" CDK_CLI_PARAMS);
   directory = CDKparamString2 (&params, 'd', ".");

   /* Create the viewer buttons. */
   button[0] = "</5><OK><!5>";
   button[1] = "</5><Cancel><!5>";

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

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   fSelect = newCDKFselect (cdkscreen,
			    CDKparamValue (&params, 'X', CENTER),
			    CDKparamValue (&params, 'Y', CENTER),
			    CDKparamValue (&params, 'H', 20),
			    CDKparamValue (&params, 'W', 65),
			    title, label, A_NORMAL, '_', A_REVERSE,
			    "</5>", "</48>", "</N>", "</N>",
			    CDKparamValue (&params, 'N', TRUE),
			    CDKparamValue (&params, 'S', FALSE));

   if (fSelect == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK ();

      fprintf (stderr, "Cannot create widget\n");
      ExitProgram (EXIT_FAILURE);
   }

   bindCDKObject (vFSELECT, fSelect, '?', do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F1, do_help, NULL);
   bindCDKObject (vFSELECT, fSelect, KEY_F2, do_delete, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F3, do_delete1, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F4, do_reload, fSelect);
   bindCDKObject (vFSELECT, fSelect, KEY_F5, do_undo, fSelect);

   /*
    * Set the starting directory. This is not necessary 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);
   myUserList = copyCharList ((const char **)getCDKFselectContents (fSelect, &userSize));
   myUndoList = (UNDO *) malloc ((size_t) userSize * sizeof (UNDO));
   undoSize = 0;

   /* Activate the file selector. */
   filename = 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);

      /* Exit CDK. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      ExitProgram (EXIT_SUCCESS);
   }

   /* 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. */
      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      printf ("Can't seem to 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)
   {
      filename = copyChar (filename);

      destroyCDKFselect (fSelect);
      destroyCDKScreen (cdkscreen);
      endCDK ();

      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/21>Filename:<!21></22>%20s<!22!B>", filename);
   setCDKViewer (example, vTitle,
		 (CDK_CSTRING2)info, lines,
		 A_REVERSE, TRUE, TRUE, TRUE);

   CDKfreeStrings (info);

   /* Destroy the file selector widget. */
   destroyCDKFselect (fSelect);

   /* 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);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Example #5
0
/*
 * This program demonstrates the Cdk calendar widget.
 */
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen         = 0;
   CDKCALENDAR *calendar        = 0;
   WINDOW *cursesWin            = 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, ret, x;
   char temp[1000];

   /*
    * 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)
   {
      /* 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 *home = getenv ("HOME");
      if (home != 0)
      {
	 sprintf (temp, "%.*s/.appointment", (int)sizeof (temp) - 20, home);
      }
      else
      {
	 strcat (temp, ".appointment");
      }
      filename = copyChar (temp);
   }

   /* Read the appointment book information. */
   readAppointmentFile (filename, &appointmentInfo);

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

   /* 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);
}
Example #6
0
File: fselect.c Project: dyne/MuSE
/*
 * This creates a file selection widget.
 */
CDKFSELECT *newCDKFselect (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, chtype fieldAttribute, chtype fillerChar, chtype highlight, char *dAttribute, char *fAttribute, char *lAttribute, char *sAttribute, boolean Box, boolean shadow)
{
  /* Set up some variables. */
   CDKFSELECT *fselect	= newCDKObject(CDKFSELECT, &my_funcs);
   int parentWidth	= getmaxx(cdkscreen->window) - 1;
   int parentHeight	= getmaxy(cdkscreen->window) - 1;
   int boxWidth		= width;
   int boxHeight	= height;
   int xpos		= xplace;
   int ypos		= yplace;
   int entryWidth, x, labelLen, junk;
   chtype *chtypeString;

  /*
   * If the height is a negative value, the height will
   * be ROWS-height, otherwise, the height will be the
   * given height.
   */
   boxHeight = setWidgetDimension (parentHeight, height, 0);

  /*
   * If the width is a negative value, the width will
   * be COLS-width, otherwise, the width will be the
   * given width.
   */
   boxWidth = setWidgetDimension (parentWidth, width, 0);

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Make sure the box isn't too small. */
   boxWidth = (boxWidth < 15 ? 15 : boxWidth);
   boxHeight = (boxHeight < 6 ? 6 : boxHeight);

   /* Make the file selector window. */
   fselect->win = newwin (boxHeight, boxWidth, ypos, xpos);

   /* Is the window null? */
   if (fselect->win == 0)
   {
      return (0);
   }
   keypad (fselect->win, TRUE);

   /* Set some variables. */
   ScreenOf(fselect)		= cdkscreen;
   fselect->parent		= cdkscreen->window;
   fselect->dirAttribute	= copyChar (dAttribute);
   fselect->fileAttribute	= copyChar (fAttribute);
   fselect->linkAttribute	= copyChar (lAttribute);
   fselect->sockAttribute	= copyChar (sAttribute);
   fselect->highlight		= highlight;
   fselect->fillerCharacter	= fillerChar;
   fselect->fieldAttribute	= fieldAttribute;
   fselect->boxHeight		= boxHeight;
   fselect->boxWidth		= boxWidth;
   fselect->fileCounter		= 0;
   fselect->pwd			= 0;
   fselect->exitType		= vNEVER_ACTIVATED;
   ObjOf(fselect)->box		= Box;
   fselect->shadow		= shadow;
   fselect->shadowWin		= 0;

   /* Zero out the contents of the directory listing. */
   for (x=0; x < MAX_ITEMS; x++)
   {
      fselect->dirContents[x] = 0;
   }

   /* Get the present working directory. */
   setPWD(fselect);

   /* Get the contents of the current directory. */
   setCDKFselectDirContents (fselect);

   /* Create the entry field in the selector. */
   chtypeString = char2Chtype (label, &labelLen, &junk);
   freeChtype (chtypeString);
   entryWidth = boxWidth - labelLen - 3;
   fselect->entryField = newCDKEntry (cdkscreen,
					getbegx(fselect->win),
					getbegy(fselect->win),
					title, label,
					fieldAttribute, fillerChar,
					vMIXED, entryWidth, 0, 512,
					Box, FALSE);

   /* Make sure the widget was created. */
   if (fselect->entryField == 0)
   {
      /* Clean up. */
      freeCharList (fselect->dirContents, MAX_ITEMS);
      freeChar (fselect->pwd);
      freeChar (fselect->dirAttribute);
      freeChar (fselect->fileAttribute);
      freeChar (fselect->linkAttribute);
      freeChar (fselect->sockAttribute);
      deleteCursesWindow (fselect->win);
      return (0);
   }

   /* Set the lower left/right characters of the entry field. */
   setCDKEntryLLChar (fselect->entryField, ACS_LTEE);
   setCDKEntryLRChar (fselect->entryField, ACS_RTEE);

   /* Define the callbacks for the entry field. */
   bindCDKObject (vENTRY, fselect->entryField, KEY_UP, fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, KEY_PPAGE, fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, CONTROL('B'), fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, KEY_DOWN, fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, KEY_NPAGE, fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, CONTROL('F'), fselectAdjustScrollCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, KEY_TAB, completeFilenameCB, fselect);
   bindCDKObject (vENTRY, fselect->entryField, CONTROL('^'), displayFileInfoCB, fselect);

   /* Put the current working directory in the entry field. */
   setCDKEntryValue (fselect->entryField, fselect->pwd);

   /* Create the scrolling list in the selector. */
   fselect->scrollField = newCDKScroll (cdkscreen,
					getbegx(fselect->win),
					getbegy(fselect->win) + (fselect->entryField)->titleLines + 2,
					RIGHT,
					boxHeight - (fselect->entryField)->titleLines - 3,
					boxWidth-2,
					0,
					fselect->dirContents,
					fselect->fileCounter,
					NONUMBERS, fselect->highlight,
					Box, FALSE);

   /* Set the lower left/right characters of the entry field. */
   setCDKScrollULChar (fselect->scrollField, ACS_LTEE);
   setCDKScrollURChar (fselect->scrollField, ACS_RTEE);

   /* Do we want a shadow? */
   if (shadow)
   {
      fselect->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
   }

   /* Register this baby. */
   registerCDKObject (cdkscreen, vFSELECT, fselect);

   /* Return the file selector pointer. */
   return (fselect);
}
Example #7
0
/*
 * This program demonstrates the Cdk template widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKTEMPLATE *phoneNumber	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C>Title";
   char *label			= "</5>Phone Number:<!5>";
   char *Overlay		= "</B/6>(___)<!6> </5>___-____";
   char *plate			= "(###) ###-####";
   char *info, *mixed, temp[256], *mesg[5];

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, CDK_MIN_PARAMS);

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

   /* Start CDK Colors. */
   initCDKColor();

   /* Declare the template. */
   phoneNumber = newCDKTemplate (cdkscreen,
				 CDKparamValue(&params, 'X', CENTER),
				 CDKparamValue(&params, 'Y', CENTER),
				 title, label,
				 plate, Overlay,
				 CDKparamValue(&params, 'N', TRUE),
				 CDKparamValue(&params, 'S', FALSE));

   /* Is the template pointer null? */
   if (phoneNumber == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can;'t seem to create template. Is the window too small?");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the template. */
   info = activateCDKTemplate (phoneNumber, 0);

   /* Tell them what they typed. */
   if (phoneNumber->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information typed in.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (phoneNumber->exitType == vNORMAL)
   {
      /* Mix the plate and the number. */
      mixed = mixCDKTemplate (phoneNumber);

      /* Create the message to display.				*/
      sprintf (temp, "Phone Number with out plate mixing  : %.*s", (int)(sizeof(temp) - 50), info);
      mesg[0] = copyChar (temp);
      sprintf (temp, "Phone Number with the plate mixed in: %.*s", (int)(sizeof(temp) - 50), mixed);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);

      freeChar (mesg[0]);
      freeChar (mesg[1]);
      freeChar (mixed);
   }

   /* Clean up. */
   destroyCDKTemplate (phoneNumber);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Example #8
0
/*
 * 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);
}
Example #9
0
/*
 * This program demonstrates the Cdk radio widget.
 */
int main(int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = (CDKSCREEN *) NULL;
   CDKRADIO *radio = (CDKRADIO *) NULL;
   WINDOW *cursesWin = (WINDOW *) NULL;
   char *item[5] =
   {"Choice A", "Choice B", "Choice C"};
   char *mesg[5], temp[100];
   int selection;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "s:t:" CDK_CLI_PARAMS);

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

   /* Set up CDK Colors. */
   initCDKColor ();

   /* Create the radio list. */
   radio = newCDKRadio (cdkscreen,
			CDKparamValue(&params, 'X', CENTER),
			CDKparamValue(&params, 'Y', CENTER),
			CDKparsePosition(CDKparamString2(&params, 's', "NONE")),
			CDKparamValue(&params, 'H', 5),
			CDKparamValue(&params, 'W', 20),
		        CDKparamString(&params, 't'),
			item, 3,
			'#' | A_REVERSE, 1,
			A_REVERSE,
			CDKparamValue(&params, 'N', TRUE),
			CDKparamValue(&params, 'S', FALSE));

   /* Check if the radio list is NULL. */
   if (radio == (CDKRADIO *) NULL)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK ();

      /* Print out a message and exit. */
      printf ("Oops. Can't seem to create the radio widget. ");
      printf ("Is the window too small??\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the radio list. */
   selection = activateCDKRadio (radio, (chtype *) NULL);

   /* Check the exit status of the widget. */
   if (radio->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No item selected.";
      mesg[1] = "",
	 mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (radio->exitType == vNORMAL)
   {
      mesg[0] = "<C>You selected the filename";
      sprintf (temp, "<C>%.*s", (int)(sizeof(temp) - 20), item[selection]);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
      freeChar (mesg[1]);
   }

   destroyCDKRadio (radio);
   destroyCDKScreen (cdkscreen);
   endCDK ();
   ExitProgram (EXIT_SUCCESS);
}
Example #10
0
/*
 * This creates the alphalist widget.
 */
CDKALPHALIST *newCDKAlphalist (CDKSCREEN *cdkscreen, int xplace, int yplace, int height, int width, char *title, char *label, char *list[], int listSize, chtype fillerChar, chtype highlight, boolean Box, boolean shadow)
{
   /* Set up some variables. */
   CDKALPHALIST *alphalist	= newCDKObject(CDKALPHALIST, &my_funcs);
   chtype *chtypeLabel		= 0;
   int parentWidth		= getmaxx(cdkscreen->window) - 1;
   int parentHeight		= getmaxy(cdkscreen->window) - 1;
   int boxWidth			= width;
   int boxHeight		= height;
   int xpos			= xplace;
   int ypos			= yplace;
   int entryWidth		= 0;
   int labelLen			= 0;
   int x, junk2;

  /*
   * If the height is a negative value, the height will
   * be ROWS-height, otherwise, the height will be the
   * given height.
   */
   boxHeight = setWidgetDimension (parentHeight, height, 0);

  /*
   * If the width is a negative value, the width will
   * be COLS-width, otherwise, the width will be the
   * given width.
   */
   boxWidth = setWidgetDimension (parentWidth, width, 0);

   /* Translate the label char *pointer to a chtype pointer. */
   if (label != 0)
   {
      chtypeLabel = char2Chtype (label, &labelLen, &junk2);
      freeChtype (chtypeLabel);
   }

   /* Rejustify the x and y positions if we need to. */
   alignxy (cdkscreen->window, &xpos, &ypos, boxWidth, boxHeight);

   /* Make the file selector window. */
   alphalist->win = newwin (boxHeight, boxWidth, ypos, xpos);

   if (alphalist->win == 0)
   {
      return (0);
   }
   keypad (alphalist->win, TRUE);

   /* Set some variables. */
   ScreenOf(alphalist)		= cdkscreen;
   alphalist->parent		= cdkscreen->window;
   alphalist->highlight		= highlight;
   alphalist->fillerChar	= fillerChar;
   alphalist->boxHeight		= boxHeight;
   alphalist->boxWidth		= boxWidth;
   alphalist->exitType		= vNEVER_ACTIVATED;
   ObjOf(alphalist)->box	= Box;
   alphalist->shadow		= shadow;
   alphalist->shadowWin		= 0;

   /* Do we want a shadow? */
   if (shadow)
   {
      alphalist->shadowWin = newwin (boxHeight, boxWidth, ypos + 1, xpos + 1);
   }

   /* We need to sort the list before we use it. */
   sortList (list, listSize);

   /* Copy the list information. */
   for (x=0; x < listSize; x++)
   {
      alphalist->list[x] = copyChar (list[x]);
   }
   alphalist->listSize = listSize;

   /* Create the entry field. */
   entryWidth = boxWidth - (labelLen + 4);
   alphalist->entryField = newCDKEntry (cdkscreen,
					getbegx(alphalist->win) + 1,
					getbegy(alphalist->win) + 1,
					title, label,
					A_NORMAL, fillerChar, 
					vMIXED, entryWidth, 0, 512,
					Box, FALSE);
   setCDKEntryLLChar (alphalist->entryField, ACS_LTEE);
   setCDKEntryLRChar (alphalist->entryField, ACS_RTEE);

   /* Set the key bindings for the entry field. */
   bindCDKObject (vENTRY, alphalist->entryField, KEY_UP, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_DOWN, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_NPAGE, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, CONTROL('F'), adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_PPAGE, adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, CONTROL('B'), adjustAlphalistCB, alphalist);
   bindCDKObject (vENTRY, alphalist->entryField, KEY_TAB, completeWordCB, alphalist);

   /* Set up the post-process function for the entry field. */
   setCDKEntryPreProcess (alphalist->entryField, preProcessEntryField, alphalist);

   /* Create the scrolling list. */
   alphalist->scrollField = newCDKScroll (cdkscreen, 
					  getbegx(alphalist->win) + 1,
					  getbegy(alphalist->win) + (alphalist->entryField)->titleLines + 3,
					  RIGHT,
					  boxHeight-((alphalist->entryField)->titleLines + 3),
					  boxWidth-3,
					  0, list, listSize,
					  NONUMBERS, A_REVERSE,
					  Box, FALSE);
   setCDKScrollULChar (alphalist->scrollField, ACS_LTEE);
   setCDKScrollURChar (alphalist->scrollField, ACS_RTEE);

   /* Register this baby. */
   registerCDKObject (cdkscreen, vALPHALIST, alphalist);

   /* Return the file selector pointer. */
   return (alphalist);
}
Example #11
0
char * _activateCDKFselect (CDKFSELECT * widget, chtype *act)
{
	return copyChar(activateCDKFselect(widget, act));
}
Example #12
0
catList *newCat(catList *head, char letter, char*v[])  {
   
	int i, j, max, count;
	catList *root, *curr, *maxNode;
	root = head;
	curr = root;
	char *tempVector[head->wordsNum], tempAgent[atoi(v[1])], **adress = NULL;
	
	
	
	
	/*Temporary vector with pointers to words of dictionary list */
	for(i=0; i<head->wordsNum; i++)  {
	  
		tempVector[i] = head->vector[i];
	}
	
	
	
	
	
	/* If only 2 words remaining and user is one letter to go, we are looking to cheat */
	if ( (head->wordsNum == 2) && (count_chars(curr->agent, '_' ) == 1) )  {
	  
		count = 0;
		
		for(i=0; i<2; i++)  {
			if(strchr(tempVector[i], letter) == NULL)  {
				count = count + 1;
			}
		}
		
		/* Return the current node if no word has the letter */
		if (count == 2)  {
			return curr;
		}
		/* Creating final node */
		curr->nxt = malloc(sizeof(catList));
		if (curr->nxt == NULL)  {
			printf("ERROR: Memory allocation error in newCat\n");
			exit(1);
		}
		curr->nxt->prv = curr;
		curr = curr->nxt;
		curr->wordsNum = 1;
		curr->vector = (char**)malloc(sizeof(char *));
		if (curr->vector == NULL) {
			printf("ERROR: Memory allocation error in newCat\n");
			exit(1);
		}
		curr->agent = (char*)malloc((sizeof(char))*atoi(v[1])+1);
		if (curr->agent == NULL) {
			printf("ERROR: Memory allocation error in newCat\n");
			exit(1);
		}
		/* From the 2 remaining words, store the one that doesn't have the letter
		in the missing position */
		for(i=0; i<2; i++)  {
			if(strchr(tempVector[i], letter) == NULL)  {
				curr->vector[0] = tempVector[i];
				strcpy(curr->agent, head->agent);
				
				
			}
		}
		
		curr->nxt = NULL;
		return curr;
	}







	/* Creating the node with the words that don't have the letter user gave */
	curr->nxt = malloc(sizeof(catList));
	if (curr->nxt == NULL) {
		printf("ERROR: Memory allocation error in newCat\n");
		exit(1);
	}
	root = curr->nxt;
	curr->nxt->prv = curr;
	curr = curr->nxt;
	curr->wordsNum = 0;
	curr->vector = NULL;
	curr->agent = malloc((sizeof(char))*atoi(v[1])+1);
	if (curr->agent == NULL) {
		printf("ERROR: Memory allocation error in newCat\n");
		exit(1);
	}
	/* Representative is still the initial, since no word here has the letter user gave */
	strcpy(curr->agent, head->agent);
	
	count = 0;
	for(i=0; i<head->wordsNum; i++)  {
	  
		/*Storing the pointers to words that dont have the letter, in the dynamic array */
		if(strchr(tempVector[i], letter) == NULL)  {
			
			count = count +1;
			curr->wordsNum = count;
			curr->vector = (char **)realloc(adress, curr->wordsNum*sizeof(char *));
			if (curr->vector == NULL) {
				printf("ERROR: Memory allocation error in newCat\n");
				exit(1);
			}
			curr->vector[count-1] = tempVector[i];
			adress = curr->vector;
		}
	}
		
		
		
	/* Running the temporary vector */
	for(i=0; i<head->wordsNum; i++)  {

		/* We are looking for words that HAVE the letter */
		if ( (tempVector[i] != NULL)  && (strchr(tempVector[i], letter) != NULL) )  {
			
			
			/* For the first word that has the letter we create new category */
			curr->nxt = malloc(sizeof(catList));
			if (curr->nxt == NULL) {
				printf("ERROR: Memory allocation error in newCat\n");
				exit(1);
			}
			curr->nxt->prv = curr;
			curr = curr->nxt;
			curr->agent = malloc((sizeof(char))*atoi(v[1])+1);
			if (curr->agent == NULL) {
				printf("ERROR: Memory allocation error in newCat\n");
				exit(1);
			}
			/* Representative is the initial representative with 'letter' in same position(s) as word */
			strcpy(curr->agent, head->agent);
			copyChar(curr->agent, tempVector[i], letter);
			curr->vector = (char **)malloc(sizeof(char *));
			if (curr->vector == NULL) {
				printf("ERROR: Memory allocation error in newCat\n");
				exit(1);
			}
			curr->vector[0] = tempVector[i];
			curr->wordsNum = 1;
			
			/* We fill that category with all words below,
			that have the letter in the exact same position(s) */
			for(j=i+1; j<head->wordsNum; j++)  {
			
				
				if(tempVector[j] != NULL)  {
					  
					  strcpy(tempAgent, head->agent);
					  copyChar(tempAgent, tempVector[j], letter);
					  if(strcmp(curr->agent, tempAgent) == 0)  {
					
						curr->wordsNum = curr->wordsNum + 1;
						curr->vector = realloc(curr->vector, curr->wordsNum*sizeof(char *));
						if (curr->vector == NULL) {
							printf("ERROR: Memory allocation error in newCat\n");
							exit(1);
						}
						curr->vector[curr->wordsNum-1] = tempVector[j];
						/* Mark as NULL the pointers to words already categorized so we dont use them again */
						tempVector[j] = NULL;
						
  
					}
					
					
				}
			
				
			}
			
		}
		
		
	}
	curr->nxt = NULL;
	

	
	
	/* Running the category list from the second node and so,  to find the most crowded one */
	curr = root;
	max = curr->wordsNum;
	while(curr != NULL)  {
		if(curr->wordsNum>max)  {max = curr->wordsNum;}

		curr = curr->nxt;
	}
	
	
	/* Function will return the last node that has "max" words */
	curr = root;
	while(curr != NULL)  {
		if(curr->wordsNum == max)  {maxNode = curr;}
		curr = curr->nxt;
	}
 
 
 
  
	
	return maxNode;
 


}
Example #13
0
int main()
{
	char *mesg[4],*infobuf[2];
	char *shared_memory;
	char string[1024],temp[1024];
	FILE *file;
	Nodeinfo *mynode;
	int segment_id, sem_id, i = 1024, k = 1024, line, j, count;
	void *buf;
	
	signal(SIGTERM, cleanup_handler);
	signal(SIGINT, cleanup_handler);

	req.tv_nsec = 5000000;
	cursesWin = initscr();
	cdkscreen = initCDKScreen(cursesWin);

	initCDKColor();
	sprintf(temp,"<C></B/3>Process Migration - GUI for Statistics and Testing");
	mesg[0] = copyChar(temp);
	title = newCDKLabel(cdkscreen, CENTER, TOP, mesg,1,1,0);
      	setCDKLabel (title, mesg, 1, 1);
      	drawCDKLabel (title, 1);
	freeChar (mesg[0]);

	loadDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.10, (LINES - 12) * 0.40, 12, 50, "<C></B/5>Load Daemon", 1000, 1, 0);
	commsDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.90, (LINES - 12) * 0.40, 12, 50, "<C></B/5>Communication Daemon", 1000, 1, 0);
	migrateDaemon = newCDKSwindow (cdkscreen, (COLS - 50) * 0.10, (LINES - 12) * 0.90, 12, 50, "<C></B/5>Migration Control Daemon", 1000, 1, 0);
	extraInfo = newCDKSwindow (cdkscreen, (COLS - 50) * 0.90, (LINES - 12) * 0.90, 12, 50, "<C></B/5>Information", 1000, 1, 0);


	//setCDKSwindowBackgroundColor(loadDaemon, "</5>");
	//setCDKSwindowBackgroundColor(commsDaemon, "</5>");
	//setCDKSwindowBackgroundColor(migrateDaemon, "</5>");
	//setCDKSwindowBackgroundColor(extraInfo, "</5>");

	file = fopen("/var/log/load","r");
	while(fgets(string, 1025, file) != NULL) {
		substr(&temp[0],&string[0]);
		addCDKSwindow (loadDaemon, temp, BOTTOM);
	}
	fclose(file);
	
	
	file = fopen("/var/log/migrate","r");
	while(fgets(string, 1025, file) != NULL) {
		substr(&temp[0],&string[0]);
		addCDKSwindow (migrateDaemon, temp, BOTTOM);
	}
	fclose(file);
	
	buf = malloc(33);

	file = fopen(INFO_SHM_ID_PATH,"r");
	fgets(string,33,file);
	segment_id = atoi(string);
	fclose(file);

	file = fopen(INFO_SEM_ID_PATH,"r");
	fgets(string,33,file);
	sem_id = atoi(string);
	fclose(file);
	
	info = newCDKLabel(cdkscreen, 0, (LINES - 5) * 0.15, infobuf,3,0,0);
	shared_memory = (void *) shmat(segment_id, 0, 0);
	//setCDKLabelBackgroundColor(info, "</55>");
	refreshCDKScreen(cdkscreen);
	binary_semaphore_post(sem_id);
	cp_loadlog();
	cp_migratelog();
	for(;;) {
		if(i-- == 0) {
			cp_loadlog();
			i = 1024;
		}
		file = popen("diff /tmp/migrate/load.temp /var/log/load | sed 1d | wc -l","r");
		strcpy(string,"\0");
		fgets(string, 1025, file);
		count = atoi(string);
		pclose(file);
		sprintf(string,"count: %d",count);
		if(count != 0) {
			file = popen("diff /tmp/migrate/load.temp /var/log/load | sed 1d","r");
			for(j = 0; j < count; j++) {
				fgets(string, 1025, file);
				substr(&temp[0],&string[0]);
				addCDKSwindow (loadDaemon, temp, BOTTOM);
			}
			pclose(file);
			i = 0;
		}
		/*if(k-- == 0) {
			cp_migratelog();
			k = 1024;
		}
		file = popen("diff /tmp/migrate/migrate.temp /var/log/migrate | sed 1d | wc -l","r");
		strcpy(string,"\0");
		fgets(string, 1025, file);
		count = atoi(string);
		pclose(file);
		sprintf(string,"count: %d",count);
		if(count != 0) {
			file = popen("diff /tmp/migrate/migrate.temp /var/log/migrate | sed 1d","r");
			for(j = 0; j < count; j++) {
				fgets(string, 1025, file);
				substr(&temp[0],&string[0]);
				addCDKSwindow (migrateDaemon, temp, BOTTOM);
			}
			pclose(file);
			k = 0;
		}*/
		binary_semaphore_wait(sem_id);
		memcpy(buf, shared_memory, 33);
		binary_semaphore_post(sem_id);
		mynode = nodeinfo__unpack(NULL, 33, buf);
		if(mynode == NULL) {
			fprintf(stderr,"error unpacking message\n");
			exit(1);
		}
		sprintf(temp,"\t\t\t\t\t\t\t</B/U/7>STATISTICS");
		infobuf[0] = copyChar(temp);
		sprintf(temp,"\t</B>Load:<!B> %0.2f\t</B>No. of peers connected:<!B> %d\t</B>No. of processes migrated:<!B> %d\t</B>No. of processes accepted:<!B> %d\t",mynode->load,mynode->np,mynode->npm,mynode->npa);
		infobuf[1] = copyChar(temp);
		sprintf(temp,"\t\t\t\t</B>Upper Threshold:<!B> %.2f\t</B>Lower Threshold:<!B> %.2f",mynode->uthresh,mynode->lthresh);
		infobuf[2] = copyChar(temp);
		setCDKLabel (info, infobuf, 3, 0);
		drawCDKLabel (info, 0);
		freeChar (infobuf[0]);
		freeChar (infobuf[1]);
		freeChar (infobuf[2]);
		sleep(1);
	}
	exit(0);
}
Example #14
0
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkScreen		= 0;
   CDKENTRY *widget		= 0;
   CDKBUTTONBOX	*buttonWidget	= 0;
   WINDOW *cursesWindow		= 0;
   chtype *holder		= 0;
   chtype fieldAttr		= A_NORMAL;
   char *answer			= 0;
   char *CDK_WIDGET_COLOR	= 0;
   char *temp			= 0;
   char filler			= '.';
   EDisplayType dType		= vMIXED;
   int buttonCount		= 0;
   int selection		= 0;
   int shadowHeight		= 0;
   FILE *fp			= stderr;
   char **buttonList		= 0;
   int j1, j2;

   CDK_PARAMS params;
   boolean boxWidget;
   boolean shadowWidget;
   char *buttons;
   char *filename;
   char *outputFile;
   char *initValue;
   char *title;
   char *label;
   char *tempFiller;
   int maxValue;
   int fieldWidth;
   int minValue;
   int xpos;
   int ypos;

   CDKparseParams(argc, argv, &params, "d:f:i:m:B:F:L:M:O:T:" "X:Y:NS");

   xpos         = CDKparamValue(&params, 'X', CENTER);
   ypos         = CDKparamValue(&params, 'Y', CENTER);
   boxWidget    = CDKparamValue(&params, 'N', TRUE);
   shadowWidget = CDKparamValue(&params, 'S', FALSE);

   minValue     = CDKparamValue(&params, 'm', 0);
   fieldWidth   = CDKparamValue(&params, 'f', 0);
   maxValue     = CDKparamValue(&params, 'M', 256);
   filename     = CDKparamString(&params, 'f');
   initValue    = CDKparamString(&params, 'i');
   buttons      = CDKparamString(&params, 'B');
   tempFiller   = CDKparamString(&params, 'F');
   label        = CDKparamString(&params, 'L');
   outputFile   = CDKparamString(&params, 'O');
   title        = CDKparamString(&params, 'T');

   if ((temp = CDKparamString(&params, 'd')) != 0)
      dType = char2DisplayType (temp);

   /* Make sure all the command line parameters were provided. */
   if (fieldWidth <= 0)
   {
      fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
      ExitProgram (CLI_ERROR);
   }

   /* 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);
	 ExitProgram (CLI_ERROR);
      }
   }

   /* 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;
   }

   /* If the set the filler character, set it now. */
   if (tempFiller != 0)
   {
      holder	= char2Chtype (tempFiller, &j1, &j2);
      fieldAttr	= A_ATTRIBUTES & holder[0];
      filler	= (chtype)holder[0];
      freeChtype (holder);
   }

   /* Create the entry widget. */
   widget = newCDKEntry (cdkScreen, xpos, ypos,
				title, label,
				fieldAttr, filler | fieldAttr,
				dType, fieldWidth,
				minValue, maxValue,
				boxWidget, FALSE);

   /* Check to make sure we created the dialog box. */
   if (widget == 0)
   {
      /* Shut down curses and CDK. */
      destroyCDKScreen (cdkScreen);
      endCDK();

      fprintf (stderr, "Error: Could not create the entry field. Is the window too small?\n");

      ExitProgram (CLI_ERROR);
   }

   /* Split the buttons if they supplied some. */
   if (buttons != 0)
   {
      buttonList = CDKsplitString (buttons, '\n');
      buttonCount = CDKcountStrings (buttonList);

      buttonWidget = newCDKButtonbox (cdkScreen,
					getbegx (widget->win),
					getbegy (widget->win) + widget->boxHeight - 1,
					1, widget->boxWidth - 1,
					0, 1, buttonCount,
					buttonList, buttonCount,
					A_REVERSE, boxWidget, FALSE);
      CDKfreeStrings (buttonList);

      setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
      setCDKButtonboxURChar (buttonWidget, ACS_RTEE);

     /*
      * We need to set the lower left and right
      * characters of the entry field.
      */
      setCDKEntryLLChar (widget, ACS_LTEE);
      setCDKEntryLRChar (widget, ACS_RTEE);

      /*
       * Bind the Tab key in the entry field to send a
       * Tab key to the button box widget.
       */
      bindCDKObject (vENTRY, widget, KEY_TAB, widgetCB, buttonWidget);
      bindCDKObject (vENTRY, widget, CDK_NEXT, widgetCB, buttonWidget);
      bindCDKObject (vENTRY, widget, CDK_PREV, widgetCB, buttonWidget);

      /* Check if the user wants to set the background of the widget. */
      setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);

      /* Draw the button widget. */
      drawCDKButtonbox (buttonWidget, boxWidget);
   }

   /*
    * If the user asked for a shadow, we need to create one.  Do this instead
    * of using the shadow parameter because the button widget is not part of
    * the main widget and if the user asks for both buttons and a shadow, we
    * need to create a shadow big enough for both widgets.  Create the shadow
    * window using the widgets shadowWin element, so screen refreshes will draw
    * them as well.
    */
   if (shadowWidget == TRUE)
   {
      /* Determine the height of the shadow window. */
      shadowHeight = (buttonWidget == 0 ?
			widget->boxHeight :
			widget->boxHeight + buttonWidget->boxHeight - 1);

      /* Create the shadow window. */
      widget->shadowWin = newwin (shadowHeight,
					widget->boxWidth,
					getbegy (widget->win) + 1,
					getbegx (widget->win) + 1);

      /* Make sure we could have created the shadow window. */
      if (widget->shadowWin != 0)
      {
	 widget->shadow = TRUE;

	/*
	 * We force the widget and buttonWidget to be drawn so the
	 * buttonbox widget will be drawn when the widget is activated.
	 * Otherwise the shadow window will draw over the button widget.
	 */
	 drawCDKEntry (widget, ObjOf(widget)->box);
	 eraseCDKButtonbox (buttonWidget);
	 drawCDKButtonbox (buttonWidget, ObjOf(buttonWidget)->box);
      }
   }

   /* Check if the user wants to set the background of the widget. */
   setCDKEntryBackgroundColor (widget, CDK_WIDGET_COLOR);

   /* If there was an initial value, set it. */
   if (initValue != 0)
   {
      setCDKEntryValue (widget, initValue);
   }

   /* Activate the widget. */
   answer = copyChar (activateCDKEntry (widget, 0));

   /* If there were buttons, get the button selected. */
   if (buttonWidget != 0)
   {
      selection = buttonWidget->currentButton;
      destroyCDKButtonbox (buttonWidget);
   }

   /* End CDK. */
   destroyCDKEntry (widget);
   destroyCDKScreen (cdkScreen);
   endCDK();

   /* Print the value from the widget. */
   if (answer != 0)
   {
      fprintf (fp, "%s\n", answer);
      freeChar (answer);
   }
   fclose (fp);

   /* Exit with the button number picked. */
   ExitProgram (selection);
}
Example #15
0
/*
 * This program demonstrates the Cdk selection widget.
 *
 * Options (in addition to normal CLI parameters):
 *	-c	create the data after the widget
 *	-s SPOS	location for the scrollbar
 *	-t TEXT	title for the widget
 *
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen		= 0;
   CDKSELECTION *selection	= 0;
   WINDOW *cursesWin		= 0;
   char *title			= "<C></5>Pick one or more accounts.";
   char *choices[]		= {"   ", "-->"};
   char **item = 0;
   char temp[256], *mesg[200];
   struct passwd *ent;
   unsigned x, y;
   unsigned used = 0;
   unsigned count = 0;

   CDK_PARAMS params;

   CDKparseParams(argc, argv, &params, "cs:t:" CDK_CLI_PARAMS);

   /* Use the account names to create a list. */
   count = 0;
   while ((ent = getpwent ()) != 0)
   {
      used = CDKallocStrings(&item, ent->pw_name, count++, used);
   }
   endpwent();
   count--;

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

   /* Set up CDK Colors. */
   initCDKColor();

   /* Create the selection list. */
   selection = newCDKSelection (cdkscreen,
				CDKparamValue(&params, 'X', CENTER),
				CDKparamValue(&params, 'Y', CENTER),
				CDKparsePosition(CDKparamString2(&params, 's', "RIGHT")),
				CDKparamValue(&params, 'H', 10),
				CDKparamValue(&params, 'W', 50),
				CDKparamString2(&params, 't', title),
				CDKparamNumber(&params, 'c') ? 0 : item,
				CDKparamNumber(&params, 'c') ? 0 : count,
				choices, 2,
				A_REVERSE,
				CDKparamValue(&params, 'N', TRUE),
				CDKparamValue(&params, 'S', FALSE));

   /* Is the selection list null? */
   if (selection == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message and exit. */
      printf ("Oops. Can;t seem to create the selection list. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   if (CDKparamNumber(&params, 'c'))
   {
      setCDKSelectionItems (selection, item, count);
   }

   /* Activate the selection list. */
   activateCDKSelection (selection, 0);

   /* Check the exit status of the widget. */
   if (selection->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No items selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (selection->exitType == vNORMAL)
   {
      mesg[0] = "<C>Here are the accounts you selected.";
      y = 1;
      for (x=0; x < count; x++)
      {
	 if (selection->selections[x] == 1)
	 {
	    sprintf (temp, "<C></5>%.*s", (int)(sizeof(temp) - 20), item[x]);
	    mesg[y++] = copyChar (temp);
	 }
      }
      popupLabel (cdkscreen, mesg, y);

      /* Clean up. */
      for (x=1; x < y; x++)
      {
	  freeChar (mesg[x]);
      }
   }

   /* Clean up. */
   CDKfreeStrings (item);
   destroyCDKSelection (selection);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Example #16
0
int OCR_lib_TestRotationBestFit ( int * cImageRaw, int w, int h, int * error  )
{
    float score=0;
    float maxScore =0;
    int bestRotation= -1;

    int rotationIndex = 0;

    int * cImageSS ; // character image scaled to standard h & w
    int * rotatedImage;


    cImageSS = (int *) malloc ( sizeof(int) * STANDARD_WIDTH * STANDARD_HEIGHT);
    if ( cImageSS == 0 )
    {
        *error = 1;
        return (0);
    }

    rotatedImage = (int *) malloc ( sizeof(int) * STANDARD_WIDTH * STANDARD_HEIGHT);
    if (rotatedImage == 0 )
    {
        *error = 1;
        return (0);
    }


    int sw, sh;
    sw = STANDARD_WIDTH;
    sh = STANDARD_HEIGHT;


    prepChar(cImageRaw, w, h, cImageSS, error );


    maxScore = 0.0;
    bestRotation = -1;

    for (rotationIndex = 0; rotationIndex < NUM_ROTATIONS; rotationIndex ++)
    {

        copyChar (cImageSS, rotatedImage, sw, sh);

        //LPROCR_lib_RotateImage (rotatedImage,  sw,  sh, rotations[ rotationIndex],  error );//

        LPROCR_lib_unroll (rotatedImage,  sw,  sh, (float) rotations[ rotationIndex],  error, 0  );

        scoreMatchOnRotationTestChar(rotatedImage, sw, sh,  & score);

        if ( score > maxScore)
        {
            maxScore =  score ;
            bestRotation = rotationIndex ;
        }
    }

    freeMemory (&cImageSS);
    freeMemory (&rotatedImage);

    return(bestRotation );

}
Example #17
0
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKLABEL *demo	= 0;
   WINDOW *cursesWin	= 0;
   int boxLabel		= 0;
   char *mesg[4], temp[256];
   struct tm *currentTime;
   time_t clck;
   int ret;

   /* Parse up the command line. */
   while ((ret = getopt (argc, argv, "b")) != -1)
   {
      switch (ret)
      {
	 case 'b' :
	      boxLabel = 1;
      }
   }

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

   /* Start CDK Colors */
   initCDKColor();

   /* Set the labels up. */
   mesg[0] = "</1/B>HH:MM:SS";

   /* Declare the labels. */
   demo = newCDKLabel (cdkscreen, CENTER, CENTER, mesg, 1, boxLabel, FALSE);

   /* Is the label null??? */
   if (demo == 0)
   {
      /* Clean up the memory. */
      destroyCDKScreen (cdkscreen);

      /* End curses... */
      endCDK();

      /* Spit out a message. */
      printf ("Oops. Can't seem to 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
   {
      /* 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, mesg, 1, ObjOf(demo)->box);

      /* Clean up the memory used. */
      freeChar (mesg[0]);

      /* 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);
}
Example #18
0
/*
 * 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 day                                      = 0;
   int month                                    = 0;
   int year                                     = 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* */
      day       = appointmentInfo->appointment[x].day;
      month     = appointmentInfo->appointment[x].month;
      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);
}
Example #19
0
/*
 * This program demonstrates the Cdk buttonbox widget.
 */
int main (void)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkscreen         = 0;
   CDKBUTTONBOX *buttonWidget   = 0;
   CDKENTRY *entry              = 0;
   WINDOW *cursesWin            = 0;
   const char *buttons[]        =
   {
      " OK ",
      " Cancel "
   };
   char *info                   = 0;
   int selection;

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

   /* Start color. */
   initCDKColor ();

   /* Create the entry widget. */
   entry = newCDKEntry (cdkscreen, CENTER, CENTER,
			"<C>Enter a name", "Name ", A_NORMAL, '.', vMIXED,
			40, 0, 256, TRUE, FALSE);
   if (entry == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK ();

      fprintf (stderr, "Cannot create entry-widget\n");
      ExitProgram (EXIT_FAILURE);
   }


   /* Create the button box widget. */
   buttonWidget = newCDKButtonbox (cdkscreen,
				   getbegx (entry->win),
				   getbegy (entry->win) + entry->boxHeight - 1,
				   1, entry->boxWidth - 1,
				   0, 1, 2,
				   (CDK_CSTRING2) buttons, 2, A_REVERSE,
				   TRUE, FALSE);
   if (buttonWidget == 0)
   {
      destroyCDKScreen (cdkscreen);
      endCDK ();

      fprintf (stderr, "Cannot create buttonbox-widget\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Set the lower left and right characters of the box. */
   setCDKEntryLLChar (entry, ACS_LTEE);
   setCDKEntryLRChar (entry, ACS_RTEE);
   setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
   setCDKButtonboxURChar (buttonWidget, ACS_RTEE);

   /*
    * Bind the Tab key in the entry field to send a
    * Tab key to the button box widget.
    */
   bindCDKObject (vENTRY, entry, KEY_TAB, entryCB, buttonWidget);

   /* Activate the entry field. */
   drawCDKButtonbox (buttonWidget, TRUE);
   info = copyChar (activateCDKEntry (entry, 0));
   selection = buttonWidget->currentButton;

   /* Clean up. */
   destroyCDKButtonbox (buttonWidget);
   destroyCDKEntry (entry);
   destroyCDKScreen (cdkscreen);
   endCDK ();

   printf ("You typed in (%s) and selected button (%s)\n",
	   (info != 0) ? info : "<null>",
	   buttons[selection]);

   freeChar (info);
   ExitProgram (EXIT_SUCCESS);
}
Example #20
0
File: fselect.c Project: dyne/MuSE
   freeCharList (mesg, 9);

   /* Redraw the file selector. */
   drawCDKFselect (fselect, ObjOf(fselect)->box);
   return (TRUE);
}

/*
 * This tries to complete the filename.
 */
static int completeFilenameCB (EObjectType objectType GCC_UNUSED, void *object GCC_UNUSED, void *clientData, chtype key GCC_UNUSED)
{
   CDKFSELECT *fselect	= (CDKFSELECT *)clientData;
   CDKSCROLL *scrollp	= (CDKSCROLL *)fselect->scrollField;
   CDKENTRY *entry	= (CDKENTRY *)fselect->entryField;
   char *filename	= copyChar (entry->info);
   char *my_basename	= baseName (filename);
   char *dirname	= dirName (filename);
   char *dirPWD		= dirName (fselect->pwd);
   char *basePWD	= baseName (fselect->pwd);
   char *newFilename	= 0;
   chtype *tempChtype	= 0;
   char *tempChar	= 0;
   int filenameLen	= 0;
   int currentIndex	= 0;
   int matches		= 0;
   int baseChars	= 0;
   int secondaryMatches = 0;
   int isDirectory	= 0;
   char *list[MAX_ITEMS], temp[1000];
   int Index, pos, ret, j, j2, x;
Example #21
0
/*
 * This program demonstrates the Cdk slider widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKFSLIDER *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C></U>Enter a value:";
   char *label		= "</B>Current Value:";
   char temp[256], *mesg[5];
   float selection;

   CDK_PARAMS params;
   float high;
   float inc;
   float low;

   float scale;
   int n, digits;

   CDKparseParams(argc, argv, &params, "h:i:l:w:p:" CDK_MIN_PARAMS);
   digits = CDKparamNumber2(&params, 'p', 0);

   scale = 1.0;
   for (n = 0; n < digits; ++n) {
      scale = scale * 10.0;
   }

   high   = CDKparamNumber2(&params, 'h', 100) / scale;
   inc    = CDKparamNumber2(&params, 'i', 1) / scale;
   low    = CDKparamNumber2(&params, 'l', 1) / scale;

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

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the widget. */
   widget = newCDKFSlider (cdkscreen,
			  CDKparamValue(&params, 'X', CENTER),
			  CDKparamValue(&params, 'Y', CENTER),
			  title, label,
			  A_REVERSE | COLOR_PAIR (29) | ' ',
			  CDKparamNumber2(&params, 'w', 50),
			  low, low, high,
			  inc, (inc*2),
			  digits,
			  CDKparamValue(&params, 'N', TRUE),
			  CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message. */
      printf ("Oops. Can't make the widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the widget. */
   selection = activateCDKFSlider (widget, 0);

   /* Check the exit value of the widget. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %.*f", digits, selection);
      mesg[0] = copyChar (temp);
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (mesg[0]);
   }

   /* Clean up.*/
   destroyCDKFSlider (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Example #22
0
File: fselect.c Project: dyne/MuSE
/*
 * This function sets the information inside the file selector.
 */
void setCDKFselect (CDKFSELECT *fselect, char *directory, chtype fieldAttrib, chtype filler, chtype highlight, char *dirAttribute, char *fileAttribute, char *linkAttribute, char *sockAttribute, boolean Box GCC_UNUSED)
{
   /* Declare local variables. */
   CDKSCROLL *fscroll	= fselect->scrollField;
   CDKENTRY *fentry	= fselect->entryField;
   char *tempDir	= 0;
   char *mesg[10], newDirectory[2000], temp[100];
   int ret;

   /* Keep the info sent to us. */
   fselect->fieldAttribute	= fieldAttrib;
   fselect->fillerCharacter	= filler;
   fselect->highlight		= highlight;
   strcpy (newDirectory, directory);

   /* Set the attributes of the entry field/scrolling list. */
   setCDKEntryFillerChar (fentry, filler);
   setCDKScrollHighlight (fscroll, highlight);

   /* Only do the directory stuff if the directory is not null. */
   if (directory != 0)
   {
      /* Try to expand the directory if it starts with a ~ */
      if (directory[0] == '~')
      {
	 tempDir = expandFilename (directory);
	 if (tempDir != 0)
	 {
	    strcpy (newDirectory, tempDir);
	    freeChar (tempDir);
	 }
      }

      /* Change directories. */
      ret = chdir (newDirectory);
      if (ret != 0)
      {
	 /* Beep at them. */
	 Beep();

	 /* Couldn't get into the directory, pop up a little message. */
	 sprintf (temp, "<C>Could not change into %s", newDirectory);
	 mesg[0] = copyChar (temp);

#ifdef HAVE_STRERROR
	 sprintf (temp, "<C></U>%s", strerror(errno));
	 mesg[1] = copyChar (temp);
#else
	 sprintf (temp, "<C></U>Unknown reason.");
	 mesg[1] = copyChar (temp);
#endif

	 mesg[2] = " ";
	 mesg[3] = "<C>Press Any Key To Continue.";

	 /* Pop Up a message. */
	 popupLabel (ScreenOf(fselect), mesg, 4);

	 /* Clean up some memory. */
	 freeCharList (mesg, 4);

	 /* Get out of here. */
	 eraseCDKFselect (fselect);
	 drawCDKFselect (fselect, ObjOf(fselect)->box);
	 return;
      }
   }

   /*
    * If the information coming in is the same as the information
    * that is already there, there is no need to destroy it.
    */
   if (fselect->pwd != directory)
   {
      setPWD(fselect);
   }
   if (fselect->fileAttribute != fileAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->fileAttribute);
      fselect->fileAttribute = copyChar (fileAttribute);
   }
   if (fselect->dirAttribute != dirAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->dirAttribute);
      fselect->dirAttribute = copyChar (dirAttribute);
   }
   if (fselect->linkAttribute != linkAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->linkAttribute);
      fselect->linkAttribute = copyChar (linkAttribute);
   }
   if (fselect->sockAttribute != sockAttribute)
   {
      /* Remove the old pointer and set the new value. */
      freeChar (fselect->sockAttribute);
      fselect->sockAttribute = copyChar (sockAttribute);
   }

   /* Set the contents of the entry field. */
   setCDKEntryValue (fentry, fselect->pwd);
   drawCDKEntry (fentry, ObjOf(fentry)->box);

   /* Get the directory contents. */
   if (setCDKFselectDirContents (fselect) == 0)
   {
      Beep();
      return;
   }

   /* Set the values in the scrolling list. */
   setCDKScrollItems (fscroll,
			fselect->dirContents,
			fselect->fileCounter,
			FALSE);
}
Example #23
0
int main (int argc, char **argv)
{
   /* *INDENT-EQLS* */
   CDKSCREEN *cdkScreen         = 0;
   CDKTEMPLATE *widget          = 0;
   CDKBUTTONBOX *buttonWidget   = 0;
   WINDOW *cursesWindow         = 0;
   char *answer                 = 0;
   char *tmp                    = 0;
   char *CDK_WIDGET_COLOR       = 0;
   char *temp                   = 0;
   chtype *holder               = 0;
   int buttonCount              = 0;
   int selection                = 0;
   int shadowHeight             = 0;
   FILE *fp                     = stderr;
   char **buttonList            = 0;
   int j1, j2;

   CDK_PARAMS params;
   boolean boxWidget;
   boolean mixPlate;
   boolean shadowWidget;
   char *buttons;
   char *defaultAnswer;
   char *label;
   char *my_overlay;
   char *outputFile;
   char *plate;
   char *title;
   int minimum;
   int xpos;
   int ypos;

   CDKparseParams (argc, argv, &params, "d:m:o:p:B:L:O:P:T:" CDK_MIN_PARAMS);

   /* *INDENT-EQLS* */
   xpos            = CDKparamValue (&params, 'X', CENTER);
   ypos            = CDKparamValue (&params, 'Y', CENTER);
   boxWidget       = CDKparamValue (&params, 'N', TRUE);
   shadowWidget    = CDKparamValue (&params, 'S', FALSE);
   minimum         = CDKparamValue (&params, 'm', 0);
   mixPlate        = CDKparamValue (&params, 'P', FALSE);
   defaultAnswer   = CDKparamString (&params, 'd');
   my_overlay      = CDKparamString (&params, 'o');
   plate           = CDKparamString (&params, 'p');
   buttons         = CDKparamString (&params, 'B');
   label           = CDKparamString (&params, 'L');
   outputFile      = CDKparamString (&params, 'O');
   title           = CDKparamString (&params, 'T');

   /* Make sure all the command line parameters were provided. */
   if (plate == 0)
   {
      fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage);
      ExitProgram (CLI_ERROR);
   }

   /* 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);
	 ExitProgram (CLI_ERROR);
      }
   }

   /* 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 template widget. */
   widget = newCDKTemplate (cdkScreen, xpos, ypos,
			    title, label,
			    plate, my_overlay,
			    boxWidget, shadowWidget);

   /* Check to make sure we created the widget. */
   if (widget == 0)
   {
      /* Shut down curses and CDK. */
      destroyCDKScreen (cdkScreen);
      endCDK ();

      fprintf (stderr,
	       "Error: Could not create the template field. "
	       "Is the window too small?\n");

      ExitProgram (CLI_ERROR);
   }

   /* Split the buttons if they supplied some. */
   if (buttons != 0)
   {
      /* Split the button list up. */
      buttonList = CDKsplitString (buttons, '\n');
      buttonCount = (int)CDKcountStrings ((CDK_CSTRING2) buttonList);

      /* We need to create a buttonbox widget. */
      buttonWidget = newCDKButtonbox (cdkScreen,
				      getbegx (widget->win),
				      (getbegy (widget->win)
				       + widget->boxHeight - 1),
				      1, widget->boxWidth - 1,
				      0, 1, buttonCount,
				      (CDK_CSTRING2) buttonList, buttonCount,
				      A_REVERSE, boxWidget, FALSE);
      setCDKButtonboxULChar (buttonWidget, ACS_LTEE);
      setCDKButtonboxURChar (buttonWidget, ACS_RTEE);

      /*
       * We need to set the lower left and right
       * characters of the widget.
       */
      setCDKTemplateLLChar (widget, ACS_LTEE);
      setCDKTemplateLRChar (widget, ACS_RTEE);

      /*
       * Bind the Tab key in the widget to send a
       * Tab key to the button box widget.
       */
      bindCDKObject (vTEMPLATE, widget, KEY_TAB, widgetCB, buttonWidget);
      bindCDKObject (vTEMPLATE, widget, CDK_NEXT, widgetCB, buttonWidget);
      bindCDKObject (vTEMPLATE, widget, CDK_PREV, widgetCB, buttonWidget);

      /* Check if the user wants to set the background of the widget. */
      setCDKButtonboxBackgroundColor (buttonWidget, CDK_WIDGET_COLOR);

      /* Draw the button widget. */
      drawCDKButtonbox (buttonWidget, boxWidget);
   }

   /*
    * If the user asked for a shadow, we need to create one.  Do this instead
    * of using the shadow parameter because the button widget is not part of
    * the main widget and if the user asks for both buttons and a shadow, we
    * need to create a shadow big enough for both widgets.  Create the shadow
    * window using the widgets shadowWin element, so screen refreshes will draw
    * them as well.
    */
   if (shadowWidget == TRUE)
   {
      /* Determine the height of the shadow window. */
      shadowHeight = (buttonWidget == 0 ?
		      widget->boxHeight :
		      widget->boxHeight + buttonWidget->boxHeight - 1);

      /* Create the shadow window. */
      widget->shadowWin = newwin (shadowHeight,
				  widget->boxWidth,
				  getbegy (widget->win) + 1,
				  getbegx (widget->win) + 1);

      /* Make sure we could have created the shadow window. */
      if (widget->shadowWin != 0)
      {
	 widget->shadow = TRUE;

	 /*
	  * We force the widget and buttonWidget to be drawn so the
	  * buttonbox widget will be drawn when the widget is activated.
	  * Otherwise the shadow window will draw over the button widget.
	  */
	 drawCDKTemplate (widget, ObjOf (widget)->box);
	 eraseCDKButtonbox (buttonWidget);
	 drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box);
      }
   }

   /* Check if the user wants to set the background of the widget. */
   setCDKTemplateBackgroundColor (widget, CDK_WIDGET_COLOR);

   /* If a default answer were proivded, set it in the widget. */
   if (defaultAnswer != 0)
   {
      setCDKTemplateValue (widget, defaultAnswer);
   }

   /* If the user asked for a minimum value, set it. */
   setCDKTemplateMin (widget, minimum);

   /* Activate the widget. */
   tmp = activateCDKTemplate (widget, 0);

   /* If the user asked for plate mixing, give it to them. */
   if (mixPlate == TRUE)
   {
      answer = mixCDKTemplate (widget);
   }
   else
   {
      answer = copyChar (tmp);
   }

   /* If there were buttons, get the button selected. */
   if (buttonWidget != 0)
   {
      selection = buttonWidget->currentButton;
      destroyCDKButtonbox (buttonWidget);
   }

   /* End CDK. */
   destroyCDKTemplate (widget);
   destroyCDKScreen (cdkScreen);
   endCDK ();

   /* Print the value from the widget. */
   if (answer != 0)
   {
      fprintf (fp, "%s\n", answer);
      freeChar (answer);
   }
   fclose (fp);

   /* Exit with the button number picked. */
   ExitProgram (selection);
}
Example #24
0
File: fselect.c Project: dyne/MuSE
/*
 * This is a callback to the scrolling list which displays information
 * about the current file. (and the whole directory as well)
 */
static int displayFileInfoCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED)
{
   /* Declare local variables. */
   CDKENTRY		*entry		= (CDKENTRY *)object;
   CDKFSELECT		*fselect	= (CDKFSELECT *)clientData;
   CDKLABEL		*infoLabel;
   struct stat		fileStat;
   struct passwd	*pwEnt;
   struct group		*grEnt;
   char			*filename;
   char			*filetype;
   char			*mesg[10];
   char			temp[100];
   char			stringMode[15];
   int			len;
   int			intMode;

   /* Get the file name. */
   filename	= fselect->entryField->info;

   /* Get specific information about the files. */
   lstat (filename, &fileStat);

   /* Determine the file type. */
   switch (mode2Filetype(fileStat.st_mode)) {
   case 'l':
      filetype = "Symbolic Link";
      break;
   case '@':
      filetype = "Socket";
      break;
   case '-':
      filetype = "Regular File";
      break;
   case 'd':
      filetype = "Directory";
      break;
   case 'c':
      filetype = "Character Device";
      break;
   case 'b':
      filetype = "Block Device";
      break;
   case '&':
      filetype = "FIFO Device";
      break;
   default:
      filetype = "Unknown";
      break;
   }

   /* Get the user name and group name. */
   pwEnt = getpwuid (fileStat.st_uid);
   grEnt = getgrgid (fileStat.st_gid);

   /* Convert the mode_t type to both string and int. */
   intMode = mode2Char (stringMode, fileStat.st_mode);

   /* Create the message. */
   sprintf (temp, "Directory  : </U>%s", fselect->pwd);
   mesg[0] = copyChar (temp);

   sprintf (temp, "Filename   : </U>%s", filename);
   mesg[1] = copyChar (temp);

   sprintf (temp, "Owner      : </U>%s<!U> (%d)", pwEnt->pw_name, (int)fileStat.st_uid);
   mesg[2] = copyChar (temp);

   sprintf (temp, "Group      : </U>%s<!U> (%d)", grEnt->gr_name, (int)fileStat.st_gid);
   mesg[3] = copyChar (temp);

   sprintf (temp, "Permissions: </U>%s<!U> (%o)", stringMode, intMode);
   mesg[4] = copyChar (temp);

   sprintf (temp, "Size       : </U>%ld<!U> bytes", (long) fileStat.st_size);
   mesg[5] = copyChar (temp);

   sprintf (temp, "Last Access: </U>%s", ctime (&fileStat.st_atime));
   len = (int)strlen (temp);
   temp[len] = '\0'; temp[len-1] = '\0';
   mesg[6] = copyChar (temp);

   sprintf (temp, "Last Change: </U>%s", ctime (&fileStat.st_ctime));
   len = (int)strlen (temp);
   temp[len] = '\0'; temp[len-1] = '\0';
   mesg[7] = copyChar (temp);

   sprintf (temp, "File Type  : </U>%s", filetype);
   mesg[8] = copyChar (temp);

   /* Create the pop up label. */
   infoLabel = newCDKLabel (entry->obj.screen, CENTER, CENTER,
				mesg, 9, TRUE, FALSE);
   drawCDKLabel (infoLabel, TRUE);
   wgetch (infoLabel->win);

   /* Clean up some memory. */
   destroyCDKLabel (infoLabel);
   freeCharList (mesg, 9);

   /* Redraw the file selector. */
   drawCDKFselect (fselect, ObjOf(fselect)->box);
   return (TRUE);
}
Example #25
0
/*
 * 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;
   WINDOW *cursesWin     = 0;
   const char *title     = "<C>Pick a file.";
   const char *label     = "File: ";
   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, ret;

   /* Parse up the command line. */
   while (1)
   {
      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>";

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

   /* Start color. */
   initCDKColor ();

   /* Get the filename. */
   if (filename == 0)
   {
      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);
}
Example #26
0
byte *FontRenderer::buildTextSprite(byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines) {
	uint16 i;

	// Find the width of the widest line in the output text

	uint16 spriteWidth = 0;

	for (i = 0; i < noOfLines; i++)
		if (line[i].width > spriteWidth)
			spriteWidth = line[i].width;


	// Check that text sprite has even horizontal resolution in PSX version
	// (needed to work around a problem in some sprites, which reports an odd
	// number as horiz resolution, but then have the next even number as true width)
	if (Sword2Engine::isPsx())
		spriteWidth = (spriteWidth % 2) ? spriteWidth + 1 : spriteWidth;

	// Find the total height of the text sprite: the total height of the
	// text lines, plus the total height of the spacing between them.

	uint16 char_height = charHeight(fontRes);
	uint16 spriteHeight = char_height * noOfLines + _lineSpacing * (noOfLines - 1);

	// Allocate memory for the text sprite

	uint32 sizeOfSprite = spriteWidth * spriteHeight;
	byte *textSprite = (byte *)malloc(FrameHeader::size() + sizeOfSprite);

	// At this stage, textSprite points to an unmovable memory block. Set
	// up the frame header.

	FrameHeader frame_head;

	frame_head.compSize = 0;
	frame_head.width = spriteWidth;
	frame_head.height = spriteHeight;

	// Normally for PSX frame header we double the height
	// of the sprite artificially to regain correct aspect
	// ratio, but this is an "artificially generated" text
	// sprite, which gets created with correct aspect, so
	// fix the height.
	if (Sword2Engine::isPsx())
		frame_head.height /= 2;

	frame_head.write(textSprite);

	debug(4, "Text sprite size: %ux%u", spriteWidth, spriteHeight);

	// Clear the entire sprite to make it transparent.

	byte *linePtr = textSprite + FrameHeader::size();
	memset(linePtr, 0, sizeOfSprite);

	byte *charSet = _vm->_resman->openResource(fontRes);

	// Build the sprite, one line at a time

	uint16 pos = 0;

	for (i = 0; i < noOfLines; i++) {
		// Center each line
		byte *spritePtr = linePtr + (spriteWidth - line[i].width) / 2;

		// copy the sprite for each character in this line to the
		// text sprite and inc the sprite ptr by the character's
		// width minus the 'overlap'

		for (uint j = 0; j < line[i].length; j++) {
			byte *charPtr = findChar(sentence[pos++], charSet);

			frame_head.read(charPtr);

			assert(frame_head.height == char_height);
			copyChar(charPtr, spritePtr, spriteWidth, pen);

			// We must remember to free memory for generated character in psx,
			// as it is extracted differently than pc version (copyed from a
			// char atlas).
			if (Sword2Engine::isPsx())
				free(charPtr);

			spritePtr += frame_head.width + _charSpacing;
		}

		// Skip space at end of last word in this line
		pos++;

		if (Sword2Engine::isPsx())
			linePtr += (char_height / 2 + _lineSpacing) * spriteWidth;
		else
			linePtr += (char_height + _lineSpacing) * spriteWidth;
	}

	_vm->_resman->closeResource(fontRes);

	return textSprite;
}
Example #27
0
/*
 * This program demonstrates the Cdk scale widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKSCALE *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C>Select a value";
   char *label		= "</5>Current value";
   char temp[256], *mesg[5];
   int selection;

   CDK_PARAMS params;
   int high;
   int inc;
   int low;

   CDKparseParams(argc, argv, &params, "h:i:l:w:" CDK_MIN_PARAMS);
   high   = CDKparamNumber2(&params, 'h', 100);
   inc    = CDKparamNumber2(&params, 'i', 1);
   low    = CDKparamNumber2(&params, 'l', 0);

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

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the widget. */
   widget = newCDKScale (cdkscreen,
			CDKparamValue(&params, 'X', CENTER),
			CDKparamValue(&params, 'Y', CENTER),
			title, label,
			A_NORMAL,
			CDKparamNumber2(&params, 'w', 5),
			low, low, high,
			inc, (inc*2),
			CDKparamValue(&params, 'N', TRUE),
			CDKparamValue(&params, 'S', FALSE));

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message. */
      printf ("Oops. Can't make the widget. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   /* Activate the widget. */
   selection = activateCDKScale (widget, 0);

   /* Check the exit value of the widget. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %d", selection);
      mesg[0] = copyChar (temp);
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (mesg[0]);
   }

   /* Clean up. */
   destroyCDKScale (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}
Example #28
0
/*
 * This function allows the user to dump the
 * information from the viewer into a file.
 */
static void saveInformation (CDKVIEWER *widget)
{
   /* Declare local variables. */
   CDKENTRY *entry	= 0;
   char *filename	= 0;
   char temp[256], *mesg[10];
   int linesSaved;

   /* Create the entry field to get the filename. */
   entry = newCDKEntry (ScreenOf(widget), CENTER, CENTER,
				"<C></B/5>Enter the filename of the save file.",
				"Filename: ",
				A_NORMAL, '_', vMIXED,
				20, 1, 256,
				TRUE, FALSE);

   /* Get the filename. */
   filename = activateCDKEntry (entry, 0);

   /* Did they hit escape? */
   if (entry->exitType == vESCAPE_HIT)
   {
      /* Popup a message. */
      mesg[0] = "<C></B/5>Save Canceled.";
      mesg[1] = "<C>Escape hit. Scrolling window information not saved.";
      mesg[2] = " ";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 4);

      destroyCDKEntry (entry);
      return;
   }

   /* Write the contents of the viewer to the file. */
   linesSaved = dumpViewer (widget, filename);

   /* Was the save successful? */
   if (linesSaved == -1)
   {
      /* Nope, tell 'em. */
      mesg[0] = "<C></B/16>Error";
      mesg[1] = "<C>Could not save to the file.";
      sprintf (temp, "<C>(%s)", filename);
      mesg[2] = copyChar (temp);
      mesg[3] = " ";
      mesg[4] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 5);
      freeChar (mesg[2]);
   }
   else
   {
      mesg[0] = "<C></B/5>Save Successful";
      sprintf (temp, "<C>There were %d lines saved to the file", linesSaved);
      mesg[1] = copyChar (temp);
      sprintf (temp, "<C>(%s)", filename);
      mesg[2] = copyChar (temp);
      mesg[3] = " ";
      mesg[4] = "<C>Press any key to continue.";
      popupLabel (ScreenOf(widget), mesg, 5);
      freeChar (mesg[1]); freeChar (mesg[2]);
   }

   destroyCDKEntry (entry);
   eraseCDKScreen (ScreenOf(widget));
   drawCDKScreen (ScreenOf(widget));
}
Example #29
0
/*
 * This demonstrates the Cdk preprocess feature.
 */
int main (void)
{
   /* Declare local variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKENTRY *widget	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C>Type in anything you want\n<C>but the dreaded letter </B>G<!B>!";
   char *info, *mesg[10], temp[256];

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

   /* Start CDK colors. */
   initCDKColor();

   /* Create the entry field widget. */
   widget = newCDKEntry (cdkscreen, CENTER, CENTER,
			 title, 0, A_NORMAL, '.', vMIXED,
			 40, 0, 256, TRUE, FALSE);

   /* Is the widget null? */
   if (widget == 0)
   {
      /* Clean up. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a little message. */
      printf ("Oops. Can't seem to create the entry box. Is the window too small?\n");
      ExitProgram (EXIT_FAILURE);
   }

   setCDKEntryPreProcess (widget, entryPreProcessCB, 0);

   /* Activate the entry field. */
   info = activateCDKEntry (widget, 0);

   /* Tell them what they typed. */
   if (widget->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No information passed back.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (widget->exitType == vNORMAL)
   {
      mesg[0] = "<C>You typed in the following";
      sprintf (temp, "<C>(%.*s)", (int)(sizeof(temp) - 20), info);
      mesg[1] = copyChar (temp);
      mesg[2] = "";
      mesg[3] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 4);
      freeChar (mesg[1]);
   }

   /* Clean up and exit. */
   destroyCDKEntry (widget);
   destroyCDKScreen (cdkscreen);
   endCDK();
   ExitProgram (EXIT_SUCCESS);
}