/* * 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) { /* *INDENT-EQLS* */ CDKSCREEN *cdkscreen = 0; CDKMENTRY *widget = 0; char *info = 0; const char *label = "</R>Message"; const char *title = "<C></5>Enter a message (\".\" to exit).<!5>\n" "<C>It can be </3>multi<!3>-line!"; int boxWidth; CDK_PARAMS params; CDKparseParams (argc, argv, ¶ms, "w:h:l:" CDK_MIN_PARAMS); cdkscreen = initCDKScreen (NULL); /* Start CDK Colors. */ initCDKColor (); /* Set up the multi-line entry field. */ boxWidth = CDKparamValue (¶ms, 'w', 40); widget = newCDKMentry (cdkscreen, CDKparamValue (¶ms, 'X', CENTER), CDKparamValue (¶ms, 'Y', CENTER), title, label, A_BOLD, '.', vMIXED, boxWidth, CDKparamValue (¶ms, 'h', 5), CDKparamValue (¶ms, 'l', 20), 0, CDKparamValue (¶ms, 'N', TRUE), CDKparamValue (¶ms, 'S', FALSE)); /* Is the object null? */ if (widget == 0) { /* Shut down CDK. */ destroyCDKScreen (cdkscreen); endCDK (); printf ("Cannot create CDK object. Is the window too small?\n"); ExitProgram (EXIT_FAILURE); } refreshCDKScreen (cdkscreen); for (;;) { info = getCdkTitle (ObjOf (widget)); setCDKMentry (widget, info, 0, TRUE); free (info); activateCDKMentry (widget, 0); if (strlen (widget->info) > 1) { setCdkTitle (ObjOf (widget), widget->info, getmaxx (widget->win)); eraseCDKScreen (ScreenOf (widget)); drawCDKScreen (ScreenOf (widget)); } else { break; } } destroyCDKMentry (widget); destroyCDKScreen (cdkscreen); endCDK (); ExitProgram (EXIT_SUCCESS); }