int menucallback(void *obj, void* display) { char message[200]; int sel = currentSelection(obj); if (sel >= 0) { sprintf(message, "menucallback: %s", getObjList(obj)[sel].item); dialog_notify(message); } else Error("currentSelection"); return 1; }
/* Put up a message in a popup confirmation box */ void msgConfirm(const char *fmt, ...) { va_list args; char *errstr; WINDOW *w = savescr(); errstr = (char *)alloca(FILENAME_MAX); va_start(args, fmt); vsnprintf(errstr, FILENAME_MAX, fmt, args); va_end(args); use_helpline(NULL); use_helpfile(NULL); if (OnVTY) { ioctl(0, VT_ACTIVATE, 1); msgInfo(NULL); } dialog_notify(errstr); restorescr(w); }
void /* ANSI C can bite me */ main() { int rc; char result[20]; int sc=0, ch=0; extern int LINES, COLS; init_dialog(); while (1) { rc = dialog_menu(0, "Choose a dialog function to test", LINES-2, COLS-2, NRCHOICES, NRCHOICES, choices, result, &sc, &ch); if (rc != 0) break; if (strstr(result, "menu")) { int sc2=0, ch2=0; rc = dialog_menu("menu", "menu box", -1, -1, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); sc2=0, ch2=0; rc = dialog_menu("menu", "menu box\nnumber 2", 13, 35, 4, 7, menu, result, &sc2, &ch2); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"check")) { rc = dialog_checklist("checklist", "checklist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result,"radio")) { rc = dialog_radiolist("radiolist", "radiolist box", -1, -1, 4, 7, checklist, result); if (rc == 0) dialog_notify(result); else if (rc == 1) dialog_notify("CANCEL"); else dialog_notify("Ooops"); } else if (strstr(result, "notify")) dialog_notify("A Notification box"); else if (strstr(result, "msg")) { dialog_msgbox("msgbox", "Sleeping 2 seconds on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "Sleeping 1 second on a\n" "msg box without user input", -1, -1, 0); sleep(1); dialog_msgbox("msgbox", "A msg box that wants user input", -1, -1, 1); } else if (strstr(result, "mesg")) dialog_mesgbox("mesgbox", "A mesg box", -1, -1); else if (strstr(result, "yesno")) { rc = dialog_yesno("yesno", "Test me\nPress YES or NO", -1, -1); if (rc == 0) dialog_notify("You pressed YES"); else if (rc > 0) dialog_notify("You pressed NO"); else dialog_notify("Something Wicked Happened!"); } else if (strstr(result, "gauge")) { int x; for (x=0; x<=20; x++) { dialog_gauge("test", "gauge", -1, -1, -1, 40, x*5); usleep(300000); } } } end_dialog(); exit((rc < 0) ? 1 : 0); }
static int install_zone_file(const char *filename) { struct stat sb; int fd1, fd2; int copymode; char *msg; ssize_t len; char buf[1024]; if (lstat(_PATH_LOCALTIME, &sb) < 0) /* Nothing there yet... */ copymode = 1; else if(S_ISLNK(sb.st_mode)) copymode = 0; else copymode = 1; #ifdef VERBOSE if (copymode) asprintf(&msg, "Copying %s to " _PATH_LOCALTIME, filename); else asprintf(&msg, "Creating symbolic link " _PATH_LOCALTIME " to %s", filename); dialog_notify(msg); free(msg); #endif if (reallydoit) { if (copymode) { fd1 = open(filename, O_RDONLY, 0); if (fd1 < 0) { asprintf(&msg, "Could not open %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } unlink(_PATH_LOCALTIME); fd2 = open(_PATH_LOCALTIME, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IRGRP|S_IROTH); if (fd2 < 0) { asprintf(&msg, "Could not open " _PATH_LOCALTIME ": %s", strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } while ((len = read(fd1, buf, sizeof buf)) > 0) len = write(fd2, buf, len); if (len == -1) { asprintf(&msg, "Error copying %s to " _PATH_LOCALTIME ": %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); /* Better to leave none than a corrupt one. */ unlink(_PATH_LOCALTIME); return DITEM_FAILURE | DITEM_RECREATE; } close(fd1); close(fd2); } else { if (access(filename, R_OK) != 0) { asprintf(&msg, "Cannot access %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } unlink(_PATH_LOCALTIME); if (symlink(filename, _PATH_LOCALTIME) < 0) { asprintf(&msg, "Cannot create symbolic link " _PATH_LOCALTIME " to %s: %s", filename, strerror(errno)); dialog_mesgbox("Error", msg, 8, 72); free(msg); return DITEM_FAILURE | DITEM_RECREATE; } } } #ifdef VERBOSE if (copymode) asprintf(&msg, "Copied timezone file from %s to " _PATH_LOCALTIME, filename); else asprintf(&msg, "Created symbolic link from " _PATH_LOCALTIME " to %s", filename); dialog_mesgbox("Done", msg, 8, 72); free(msg); #endif return DITEM_LEAVE_MENU; }
/* whine */ static void feepout(char *msg) { beep(); dialog_notify(msg); }