OsiIF::~OsiIF() { delete ws_; delete osiLP_; freeDouble(xVal_); freeDouble(yVal_); freeDouble(reco_); freeDouble(rowactivity_); freeChar(cStat_); freeChar(rStat_); }
/* * This removes a marker from the calendar. */ static int removeCalendarMarkCB (EObjectType objectType GCC_UNUSED, void *object, void *clientData, chtype key GCC_UNUSED) { CDKCALENDAR *calendar = (CDKCALENDAR *)object; struct AppointmentInfo *appointmentInfo = (struct AppointmentInfo *)clientData; int x; /* Look for the marker in the list. */ for (x = 0; x < appointmentInfo->appointmentCount; x++) { if ((appointmentInfo->appointment[x].day == calendar->day) && (appointmentInfo->appointment[x].month == calendar->month) && (appointmentInfo->appointment[x].year == calendar->year)) { freeChar (appointmentInfo->appointment[x].description); appointmentInfo->appointment[x].description = 0; break; } } /* Remove the marker from the calendar. */ removeCDKCalendarMarker (calendar, calendar->day, calendar->month, calendar->year); /* Redraw the calendar. */ drawCDKCalendar (calendar, ObjOf (calendar)->box); return (FALSE); }
/* * This actually dumps the information from the viewer to a file. */ static int dumpViewer (CDKVIEWER *widget, char *filename) { /* Declare local variables. */ FILE *outputFile = 0; char *rawLine = 0; int listSize; chtype **list = getCDKViewerInfo (widget, &listSize); int x; /* Try to open the file. */ if ((outputFile = fopen (filename, "w")) == 0) { return -1; } /* Start writing out the file. */ for (x=0; x < listSize; x++) { rawLine = chtype2Char (list[x]); fprintf (outputFile, "%s\n", rawLine); freeChar (rawLine); } /* Close the file and return the number of lines written. */ fclose (outputFile); return listSize; }
void OsiIF::loadDummyRow(OsiSolverInterface* s2, const double* lbounds, const double* ubounds, const double* objectives) { CoinPackedVector *coinrow = new CoinPackedVector(); CoinPackedMatrix *matrix = new CoinPackedMatrix(false,0,0); matrix->setDimensions(0, numCols_); ArrayBuffer<int> dummy(1,false); dummy.push(0); char *senses = new char[1]; double *rhs = new double[1]; double *ranges = new double[1]; coinrow->insert(0, 1.); matrix->appendRow(*coinrow); senses[0] = 'E'; rhs[0] = 1.; ranges[0] = 0.; lpSolverTime_.start(); s2->loadProblem(*matrix, lbounds, ubounds, objectives, senses, rhs, ranges); lpSolverTime_.stop(); _remRows(dummy); delete coinrow; delete matrix; freeChar(senses); freeDouble(rhs); freeDouble(ranges); return; }
/* * This saves a given appointment file. */ void saveAppointmentFile (char *filename, struct AppointmentInfo *appInfo) { /* Declare local variables. */ FILE *fd; int x; /* Can we open the file? */ if ((fd = fopen (filename, "w")) == 0) { return; } /* Start writing. */ for (x = 0; x < appInfo->appointmentCount; x++) { if (appInfo->appointment[x].description != 0) { fprintf (fd, "%d%c%d%c%d%c%d%c%s\n", appInfo->appointment[x].day, CTRL ('V'), appInfo->appointment[x].month, CTRL ('V'), appInfo->appointment[x].year, CTRL ('V'), (int)appInfo->appointment[x].type, CTRL ('V'), appInfo->appointment[x].description); freeChar (appInfo->appointment[x].description); } } fclose (fd); }
void MartianEngine::dead(int deathId) { // Load and display death screen _events->hideCursor(); _screen->forceFadeOut(); _files->loadScreen(48, _deaths[deathId]._screenId); _screen->setIconPalette(); _buffer2.copyBuffer(_screen); _screen->forceFadeIn(); _events->showCursor(); // Setup fonts _fonts._charSet._hi = 10; _fonts._charSet._lo = 1; _fonts._charFor._lo = 247; _fonts._charFor._hi = 255; _screen->_maxChars = 50; _screen->_printOrg = Common::Point(24, 18); _screen->_printStart = Common::Point(24, 18); // Display death message showDeathText(_deaths[deathId]._msg); _screen->forceFadeOut(); _room->clearRoom(); freeChar(); // The original was jumping to the restart label in main _restartFl = true; _events->pollEvents(); }
void freeFont(struct font* myFont) { fclose(myFont->infile); fclose(myFont->imageFile); free(myFont->myImage.pixels); freeChar(myFont->myChars, myFont->numChars); free(myFont->myChars); free(myFont); }
/** * symlinking new icon to actual.gif in .cache/weather/ */ void symlinking_image(char *image) { char *filename_new = SHARED_FOLDER; char *filename_old = 0; getCachePath(&filename_old, APP_NAME); strmcat(&filename_old, "actual.gif"); strmcat(&filename_new, "/%1.gif"); strmreplace(&filename_new, "%1", image); unlink(filename_old); if(symlink(filename_new, filename_old) == -1) outerr("Error symlinking"); freeChar(&filename_new); freeChar(&filename_old); }
/** * replace in a string the replace_hint with insert_word * need to be free() befor terminating */ int strmreplace(char **string, char *replace_hint, char *insert_word) { int oldLen; int newLen; char *tmp[3]; char *pointer; pointer = strmstr(*string, replace_hint); if(pointer == NULL) return -1; oldLen = strmlen(*string)+1; newLen = oldLen-strmlen(replace_hint)+strmlen(insert_word)+1; tmp[0] = malloc(oldLen); tmp[1] = malloc(oldLen); tmp[2] = malloc(oldLen + strmlen(insert_word)); memcpy(tmp[0], *string, oldLen); *string = NULL; pointer = strmstr(tmp[0], replace_hint); pointer += strmlen(replace_hint); memcpy(tmp[2], pointer, strmlen(pointer)+1); pointer = strmstr(tmp[0], replace_hint); *pointer = '\0'; memcpy(tmp[1], tmp[0], strmlen(tmp[0])+1); *string = malloc(newLen+1); pointer = *string; memcpy(pointer, tmp[1], strmlen(tmp[1])); pointer += strmlen(tmp[1]); memcpy(pointer, insert_word, strmlen(insert_word)); pointer += strmlen(insert_word); memcpy(pointer, tmp[2], strmlen(tmp[2])+1); freeChar(&tmp[0]); freeChar(&tmp[1]); freeChar(&tmp[2]); return 0; }
/* * This destroys the file selector. */ void destroyCDKFselect (CDKFSELECT *fselect) { /* Erase the file selector. */ eraseCDKFselect (fselect); /* Free up the character pointers. */ freeChar (fselect->pwd); freeChar (fselect->pathname); freeChar (fselect->dirAttribute); freeChar (fselect->fileAttribute); freeChar (fselect->linkAttribute); freeChar (fselect->sockAttribute); freeCharList (fselect->dirContents, fselect->fileCounter); /* Destroy the other Cdk objects. */ destroyCDKScroll (fselect->scrollField); destroyCDKEntry (fselect->entryField); /* Free up the window pointers. */ deleteCursesWindow (fselect->shadowWin); deleteCursesWindow (fselect->win); /* Unregister the object. */ unregisterCDKObject (vFSELECT, fselect); /* Free up the object pointer. */ free (fselect); }
/* * Write a string of blanks, using writeChar(). */ void writeBlanks (WINDOW *window, int xpos, int ypos, int align, int start, int end) { if (start < end) { unsigned want = (unsigned)(end - start) + 1000; char *blanks = (char *)malloc (want); if (blanks != 0) { cleanChar (blanks, (int)(want - 1), ' '); writeChar (window, xpos, ypos, blanks, align, start, end); freeChar (blanks); } } }
/* * This sets the attribute of the link attribute in the * scrolling list. */ void setCDKFselectFileAttribute (CDKFSELECT *fselect, char *attribute) { /* Make sure they are not one in the same. */ if (fselect->fileAttribute == attribute) { return; } /* Clean out the old attribute, and set the new. */ freeChar (fselect->fileAttribute); fselect->fileAttribute = copyChar (attribute); /* * We need to reset the contents of the scrolling * list using the new attribute. */ setCDKFselectDirContents (fselect); }
/** * extends strcat and combined with strcpy with malloc needed space * needs to be free() befor terminated programm */ void strmcat(char **base_str,char *append_str) { char *tmp = NULL; int const applen = strmlen(append_str); int const baselen = strmlen(*base_str); if(*base_str == NULL) { *base_str = (char*)malloc(applen + 1); if(*base_str != NULL) memcpy(*base_str, append_str, applen + 1); } else { tmp = *base_str; *base_str = malloc(baselen + applen + 1); if(*base_str!=NULL) { memcpy(*base_str, tmp, baselen); memcpy(*base_str + strmlen(tmp), append_str, applen+1); } } freeChar(&tmp); }
/* * 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); }
/* * 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, ¶ms, CDK_MIN_PARAMS); /* Set up CDK*/ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors. */ initCDKColor(); /* Declare the template. */ phoneNumber = newCDKTemplate (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), title, label, plate, Overlay, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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); }
/* * 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, ¶ms, "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(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), CDKparsePosition(CDKparamString2(¶ms, 's', "RIGHT")), CDKparamValue(¶ms, 'H', 10), CDKparamValue(¶ms, 'W', 50), CDKparamString2(¶ms, 't', title), CDKparamNumber(¶ms, 'c') ? 0 : item, CDKparamNumber(¶ms, 'c') ? 0 : count, choices, 2, A_REVERSE, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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(¶ms, '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); }
/* * 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); }
/* * 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, ¶ms, "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(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), CDKparsePosition(CDKparamString2(¶ms, 's', "NONE")), CDKparamValue(¶ms, 'H', 5), CDKparamValue(¶ms, 'W', 20), CDKparamString(¶ms, 't'), item, 3, '#' | A_REVERSE, 1, A_REVERSE, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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); }
/* * 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, ¶ms, "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(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), title, label, CDKparamNumber(¶ms, 'c') ? 0 : info, CDKparamNumber(¶ms, 'c') ? 0 : MONTHS, startMonth, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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(¶ms, '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); }
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, ¶ms, "d:m:o:p:B:L:O:P:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); minimum = CDKparamValue (¶ms, 'm', 0); mixPlate = CDKparamValue (¶ms, 'P', FALSE); defaultAnswer = CDKparamString (¶ms, 'd'); my_overlay = CDKparamString (¶ms, 'o'); plate = CDKparamString (¶ms, 'p'); buttons = CDKparamString (¶ms, 'B'); label = CDKparamString (¶ms, 'L'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, '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); }
/* * 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, ¶ms, "h:i:l:w:p:" CDK_MIN_PARAMS); digits = CDKparamNumber2(¶ms, 'p', 0); scale = 1.0; for (n = 0; n < digits; ++n) { scale = scale * 10.0; } high = CDKparamNumber2(¶ms, 'h', 100) / scale; inc = CDKparamNumber2(¶ms, 'i', 1) / scale; low = CDKparamNumber2(¶ms, 'l', 1) / scale; /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors. */ initCDKColor(); /* Create the widget. */ widget = newCDKFSlider (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), title, label, A_REVERSE | COLOR_PAIR (29) | ' ', CDKparamNumber2(¶ms, 'w', 50), low, low, high, inc, (inc*2), digits, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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); }
/* * 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); }
/* * 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); }
void OsiIF::_initialize( OptSense sense, int nRow, int maxRow, int nCol, int maxCol, Array<double> &obj, Array<double> &lBound, Array<double> &uBound, Array<Row*> &rows) { osiLP_ = getDefaultInterface(); currentSolverType_ = Exact; // switch off output from the solver // can be reset in setSolverParameters osiLP_->setHintParam(OsiDoReducePrint, true, OsiHintDo); osiLP_->messageHandler()->setLogLevel(0); master_->setSolverParameters(osiLP_, currentSolverType() == Approx); numRows_ = nRow; numCols_ = nCol; double *lbounds = new double[numCols_]; double *ubounds = new double[numCols_]; double *objectives = new double[numCols_]; CoinPackedVector *coinrow = new CoinPackedVector(); CoinPackedMatrix *matrix = new CoinPackedMatrix(false,0,0); matrix->setDimensions(0, numCols_); for (int i = 0; i < numCols_; i++){ lbounds[i] = lBound[i]; ubounds[i] = uBound[i]; objectives[i] = obj[i]; } if (currentSolverType() == Exact && numRows_ == 0 && master_->defaultLpSolver() == Master::CPLEX) { loadDummyRow(osiLP_, lbounds, ubounds, objectives); } else { char *senses = new char[numRows_]; double *rhs = new double[numRows_]; double *ranges = new double[numRows_]; for (int i = 0; i < numRows_; i++){ coinrow->clear(); for (int j = 0; j < rows[i]->nnz(); j++){ coinrow->insert(rows[i]->support(j), rows[i]->coeff(j)); } matrix->appendRow(*coinrow); senses[i] = csense2osi(rows[i]->sense()); rhs[i] = rows[i]->rhs(); ranges[i] = 0.0; } lpSolverTime_.start(); osiLP_->loadProblem(*matrix, lbounds, ubounds, objectives, senses, rhs, ranges); lpSolverTime_.stop(); freeChar(senses); freeDouble(rhs); freeDouble(ranges); } // set the sense of the optimization _sense(sense); // get the pointers to the solution, reduced costs etc. lpSolverTime_.start(); numRows_ = osiLP_->getNumRows(); numCols_ = osiLP_->getNumCols(); rhs_ = osiLP_->getRightHandSide(); rowsense_ = osiLP_->getRowSense(); colupper_ = osiLP_->getColUpper(); collower_ = osiLP_->getColLower(); objcoeff_ = osiLP_->getObjCoefficients(); if( ws_ != nullptr ) delete ws_; //ws_ = dynamic_cast<CoinWarmStartBasis *>(osiLP_->getWarmStart()); ws_=nullptr; xValStatus_ = recoStatus_ = yValStatus_ = slackStatus_ = basisStatus_ = Missing; lpSolverTime_.stop(); delete coinrow; delete matrix; freeDouble(lbounds); freeDouble(ubounds); freeDouble(objectives); }
/* * 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, ¶ms, "h:i:l:w:" CDK_MIN_PARAMS); high = CDKparamNumber2(¶ms, 'h', 100); inc = CDKparamNumber2(¶ms, 'i', 1); low = CDKparamNumber2(¶ms, 'l', 0); /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK Colors. */ initCDKColor(); /* Create the widget. */ widget = newCDKScale (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), title, label, A_NORMAL, CDKparamNumber2(¶ms, 'w', 5), low, low, high, inc, (inc*2), CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, '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); }
int main (int argc, char **argv) { /* *INDENT-EQLS* */ CDKSCREEN *cdkScreen = 0; CDKMATRIX *widget = 0; CDKBUTTONBOX *buttonWidget = 0; chtype *holder = 0; char *buttons = 0; char *CDK_WIDGET_COLOR = 0; char *temp = 0; chtype filler = A_NORMAL | '.'; int rows = -1; int cols = -1; int buttonCount = 0; int selection = 0; int shadowHeight = 0; FILE *fp = stderr; char **rowTitles; char **colTitles; char **rowTemp = 0; char **colTemp = 0; char **kolTemp = 0; char **buttonList = 0; int *colWidths; int *colTypes; int count, infoLines, x, y, j1, j2; CDK_PARAMS params; boolean boxWidget; boolean shadowWidget; char *defaultValue; char *myColTitles; char *myColTypes; char *myColWidths; char *myFiller; char *myRowTitles; char *outputFile; char *title; int vrows; int xpos; int ypos; CDKparseParams (argc, argv, ¶ms, "c:d:r:t:w:v:B:F:O:T:" CDK_MIN_PARAMS); /* *INDENT-EQLS* */ xpos = CDKparamValue (¶ms, 'X', CENTER); ypos = CDKparamValue (¶ms, 'Y', CENTER); boxWidget = CDKparamValue (¶ms, 'N', TRUE); shadowWidget = CDKparamValue (¶ms, 'S', FALSE); vrows = CDKparamValue (¶ms, 'v', -1); myColTitles = CDKparamString (¶ms, 'c'); defaultValue = CDKparamString (¶ms, 'd'); myRowTitles = CDKparamString (¶ms, 'r'); myColTypes = CDKparamString (¶ms, 't'); myColWidths = CDKparamString (¶ms, 'w'); buttons = CDKparamString (¶ms, 'B'); myFiller = CDKparamString (¶ms, 'F'); outputFile = CDKparamString (¶ms, 'O'); title = CDKparamString (¶ms, 'T'); /* 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); } } /* Make sure all the needed command line parameters were provided. */ if ((myRowTitles == 0) || (myColTitles == 0) || (myColWidths == 0) || (vrows == -1)) { fprintf (stderr, "Usage: %s %s\n", argv[0], FPUsage); ExitProgram (CLI_ERROR); } /* Convert the char * titles to a char **, offset by one */ rowTemp = CDKsplitString (myRowTitles, '\n'); rows = (int)CDKcountStrings ((CDK_CSTRING2)rowTemp); rowTitles = (char **)calloc ((size_t) rows + 1, sizeof (char *)); for (x = 0; x < rows; x++) { rowTitles[x + 1] = rowTemp[x]; } colTemp = CDKsplitString (myColTitles, '\n'); cols = (int)CDKcountStrings ((CDK_CSTRING2)colTemp); colTitles = (char **)calloc ((size_t) cols + 1, sizeof (char *)); for (x = 0; x < cols; x++) { colTitles[x + 1] = colTemp[x]; } /* Convert the column widths. */ kolTemp = CDKsplitString (myColWidths, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)kolTemp); colWidths = (int *)calloc ((size_t) count + 1, sizeof (int)); for (x = 0; x < count; x++) { colWidths[x + 1] = atoi (kolTemp[x]); } /* If they passed in the column types, convert them. */ if (myColTypes != 0) { char **ss = CDKsplitString (myColTypes, '\n'); count = (int)CDKcountStrings ((CDK_CSTRING2)ss); colTypes = (int *)calloc ((size_t) MAXIMUM (cols, count) + 1, sizeof (int)); for (x = 0; x < count; x++) { colTypes[x + 1] = char2DisplayType (ss[x]); } CDKfreeStrings (ss); } else { /* If they didn't set default values. */ colTypes = (int *)calloc ((size_t) cols + 1, sizeof (int)); for (x = 0; x < cols; x++) { colTypes[x + 1] = vMIXED; } } cdkScreen = initCDKScreen (NULL); /* Start color. */ initCDKColor (); /* Check if the user wants to set the background of the main screen. */ if ((temp = getenv ("CDK_SCREEN_COLOR")) != 0) { holder = char2Chtype (temp, &j1, &j2); wbkgd (cdkScreen->window, holder[0]); wrefresh (cdkScreen->window); freeChtype (holder); } /* Get the widget color background color. */ if ((CDK_WIDGET_COLOR = getenv ("CDK_WIDGET_COLOR")) == 0) { CDK_WIDGET_COLOR = 0; } /* If the set the filler character, set it now. */ if (myFiller != 0) { holder = char2Chtype (myFiller, &j1, &j2); filler = holder[0]; freeChtype (holder); } /* Create the matrix widget. */ widget = newCDKMatrix (cdkScreen, xpos, ypos, rows, cols, vrows, cols, title, (CDK_CSTRING2)rowTitles, (CDK_CSTRING2)colTitles, colWidths, colTypes, 1, 1, filler, COL, boxWidget, TRUE, shadowWidget); free (rowTitles); free (colTitles); /* Make sure we could create the widget. */ if (widget == 0) { /* Shut down curses and CDK. */ destroyCDKScreen (cdkScreen); endCDK (); fprintf (stderr, "Error: Cannot create the matrix. " "Is the window too small?\n"); ExitProgram (CLI_ERROR); } /* * If the user sent in a file of default values, read it and * stick the values read in from the file into the matrix. */ if (defaultValue != 0) { size_t limit = (size_t) ((rows + 1) * (cols + 1)); char **info = (char **)calloc (limit, sizeof (char *)); char **lineTemp = 0; /* Read the file. */ infoLines = CDKreadFile (defaultValue, &lineTemp); if (infoLines > 0) { int *subSize = (int *)calloc ((size_t) infoLines + 1, sizeof (int)); /* For each line, split on a CTRL-V. */ for (x = 0; x < infoLines; x++) { char **ss = CDKsplitString (lineTemp[x], CTRL ('V')); subSize[x + 1] = (int)CDKcountStrings ((CDK_CSTRING2)ss); for (y = 0; y < subSize[x + 1]; y++) { MY_INFO (x, y) = ss[y]; } free (ss); } CDKfreeStrings (lineTemp); setCDKMatrixCells (widget, (CDK_CSTRING2)info, rows, cols, subSize); for (x = 0; x < infoLines; x++) { for (y = 0; y < subSize[x + 1]; y++) { freeChar (MY_INFO (x, y)); } } free (info); free (subSize); } } /* 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, NULL, 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. */ setCDKMatrixLLChar (widget, ACS_LTEE); setCDKMatrixLRChar (widget, ACS_RTEE); /* * Bind the Tab key in the widget to send a * Tab key to the button box widget. */ bindCDKObject (vMATRIX, widget, KEY_TAB, widgetCB, buttonWidget); bindCDKObject (vMATRIX, widget, CDK_NEXT, widgetCB, buttonWidget); bindCDKObject (vMATRIX, 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 == (CDKBUTTONBOX *)NULL ? 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. */ drawCDKMatrix (widget, ObjOf (widget)->box); eraseCDKButtonbox (buttonWidget); drawCDKButtonbox (buttonWidget, ObjOf (buttonWidget)->box); } } /* Check if the user wants to set the background of the widget. */ setCDKMatrixBackgroundColor (widget, CDK_WIDGET_COLOR); /* Let them play. */ activateCDKMatrix (widget, 0); /* Print out the matrix cells. */ if (widget->exitType == vNORMAL) { for (x = 0; x < widget->rows; x++) { for (y = 0; y < widget->cols; y++) { char *data = getCDKMatrixCell (widget, x, y); if (data != 0) { fprintf (fp, "%s%c", data, CTRL ('V')); } else { fprintf (fp, "%c", CTRL ('V')); } } fprintf (fp, "\n"); } } /* If there were buttons, get the button selected. */ if (buttonWidget != 0) { selection = buttonWidget->currentButton; destroyCDKButtonbox (buttonWidget); } /* cleanup (not really needed) */ CDKfreeStrings (buttonList); free (colTypes); free (colWidths); CDKfreeStrings (rowTemp); CDKfreeStrings (colTemp); CDKfreeStrings (kolTemp); destroyCDKMatrix (widget); destroyCDKScreen (cdkScreen); endCDK (); /* do this late, in case it was stderr */ fclose (fp); ExitProgram (selection); }
/* * 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)); }
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, ¶ms, "d:f:i:m:B:F:L:M:O:T:" "X:Y:NS"); xpos = CDKparamValue(¶ms, 'X', CENTER); ypos = CDKparamValue(¶ms, 'Y', CENTER); boxWidget = CDKparamValue(¶ms, 'N', TRUE); shadowWidget = CDKparamValue(¶ms, 'S', FALSE); minValue = CDKparamValue(¶ms, 'm', 0); fieldWidth = CDKparamValue(¶ms, 'f', 0); maxValue = CDKparamValue(¶ms, 'M', 256); filename = CDKparamString(¶ms, 'f'); initValue = CDKparamString(¶ms, 'i'); buttons = CDKparamString(¶ms, 'B'); tempFiller = CDKparamString(¶ms, 'F'); label = CDKparamString(¶ms, 'L'); outputFile = CDKparamString(¶ms, 'O'); title = CDKparamString(¶ms, 'T'); if ((temp = CDKparamString(¶ms, '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); }
/* * 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); }
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); }