int show_info(CDKSCREEN *screen) { char *title = "<C>Wifi Info"; char *mesg; CDKSWINDOW *swindow; swindow = newCDKSwindow(screen, CENTER, CENTER, 0, 0, title, 100, TRUE, FALSE); mesg = "<C>Use the Arrow to move window."; addCDKSwindow(swindow, mesg, BOTTOM); mesg = "<C>Hit Enter to exit."; addCDKSwindow(swindow, mesg, BOTTOM); execCDKSwindow(swindow, "iwlist scanning 2>/dev/null", BOTTOM); activateCDKSwindow(swindow, 0); destroyCDKSwindow(swindow); return 0; }
/* * Demonstrate a scrolling-window. */ int main (int argc, char **argv) { /* Declare variables. */ CDKSCREEN *cdkscreen = 0; CDKSWINDOW *swindow = 0; WINDOW *cursesWin = 0; char *title = "<C></5>Error Log"; char *mesg[5]; CDK_PARAMS params; CDKparseParams(argc, argv, ¶ms, CDK_CLI_PARAMS); /* Set up CDK. */ cursesWin = initscr(); cdkscreen = initCDKScreen (cursesWin); /* Start CDK colors. */ initCDKColor(); /* Create the scrolling window. */ swindow = newCDKSwindow (cdkscreen, CDKparamValue(¶ms, 'X', CENTER), CDKparamValue(¶ms, 'Y', CENTER), CDKparamValue(¶ms, 'H', 6), CDKparamValue(¶ms, 'W', 65), title, 100, CDKparamValue(¶ms, 'N', TRUE), CDKparamValue(¶ms, 'S', FALSE)); /* Is the window null. */ if (swindow == 0) { /* Exit CDK. */ destroyCDKScreen (cdkscreen); endCDK(); /* Print out a message and exit. */ printf ("Oops. Can not seem to create the scrolling window. Is the window too small??\n"); ExitProgram (EXIT_FAILURE); } /* Draw the scrolling window. */ drawCDKSwindow (swindow, ObjOf(swindow)->box); /* Load up the scrolling window. */ addCDKSwindow (swindow, "<C></11>TOP: This is the first line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<L></11>1: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>2: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<R></11>3: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>4: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<L></11>5: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C></11>6: This is another line.", BOTTOM); addCDKSwindow (swindow, "<C>Sleeping for 1 second.", BOTTOM); sleep (1); addCDKSwindow (swindow, "<C>Done. You can now play.", BOTTOM); addCDKSwindow (swindow, "<C>This is being added to the top.", TOP); /* Activate the scrolling window. */ activateCDKSwindow (swindow, 0); /* Check how the user exited this widget. */ if (swindow->exitType == vESCAPE_HIT) { mesg[0] = "<C>You hit escape to leave this widget."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } else if (swindow->exitType == vNORMAL) { mesg[0] = "<C>You hit return to exit this widget."; mesg[1] = ""; mesg[2] = "<C>Press any key to continue."; popupLabel (cdkscreen, mesg, 3); } /* Clean up. */ destroyCDKSwindow (swindow); destroyCDKScreen (cdkscreen); endCDK(); ExitProgram (EXIT_SUCCESS); }
/* * Run the Device/Target Group Layout dialog */ void devTgtGrpLayoutDialog(CDKSCREEN *main_cdk_screen) { CDKSWINDOW *alua_info = 0; char *swindow_info[MAX_ALUA_LAYOUT_LINES] = {NULL}; int i = 0, line_pos = 0; char dir_name[MAX_SYSFS_PATH_SIZE] = {0}, tmp_buff[MAX_SYSFS_ATTR_SIZE] = {0}; DIR *dev_grp_dir_stream = NULL, *tgt_grp_dir_stream = NULL, *tgt_dir_stream = NULL, *dev_dir_stream = NULL; struct dirent *dev_grp_dir_entry = NULL, *tgt_grp_dir_entry = NULL, *tgt_dir_entry = NULL, *dev_dir_entry = NULL; /* Setup scrolling window widget */ alua_info = newCDKSwindow(main_cdk_screen, CENTER, CENTER, (ALUA_LAYOUT_ROWS + 2), (ALUA_LAYOUT_COLS + 2), "<C></31/B>SCST ALUA Device/Target Group Layout\n", MAX_ALUA_LAYOUT_LINES, TRUE, FALSE); if (!alua_info) { errorDialog(main_cdk_screen, SWINDOW_ERR_MSG, NULL); return; } setCDKSwindowBackgroundAttrib(alua_info, COLOR_DIALOG_TEXT); setCDKSwindowBoxAttribute(alua_info, COLOR_DIALOG_BOX); line_pos = 0; while (1) { /* We'll start with the SCST device groups */ snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups", SYSFS_SCST_TGT); if ((dev_grp_dir_stream = opendir(dir_name)) == NULL) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s", strerror(errno)); line_pos++; } break; } while ((dev_grp_dir_entry = readdir(dev_grp_dir_stream)) != NULL) { /* The device group names are directories; skip '.' and '..' */ if ((dev_grp_dir_entry->d_type == DT_DIR) && (strcmp(dev_grp_dir_entry->d_name, ".") != 0) && (strcmp(dev_grp_dir_entry->d_name, "..") != 0)) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "</B>Device Group:<!B> %s", dev_grp_dir_entry->d_name); line_pos++; } /* Now get all of the device names for this device group */ snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/devices", SYSFS_SCST_TGT, dev_grp_dir_entry->d_name); if ((dev_dir_stream = opendir(dir_name)) == NULL) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s", strerror(errno)); line_pos++; } break; } while ((dev_dir_entry = readdir(dev_dir_stream)) != NULL) { /* The device names are links */ if (dev_dir_entry->d_type == DT_LNK) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "\t</B>Device:<!B> %s", dev_dir_entry->d_name); line_pos++; } } } closedir(dev_dir_stream); /* Now get all of the target groups for this device group */ snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/target_groups", SYSFS_SCST_TGT, dev_grp_dir_entry->d_name); if ((tgt_grp_dir_stream = opendir(dir_name)) == NULL) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s", strerror(errno)); line_pos++; } break; } while ((tgt_grp_dir_entry = readdir(tgt_grp_dir_stream)) != NULL) { /* The target group names are directories; * skip '.' and '..' */ if ((tgt_grp_dir_entry->d_type == DT_DIR) && (strcmp(tgt_grp_dir_entry->d_name, ".") != 0) && (strcmp(tgt_grp_dir_entry->d_name, "..") != 0)) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/target_groups/%s/group_id", SYSFS_SCST_TGT, dev_grp_dir_entry->d_name, tgt_grp_dir_entry->d_name); readAttribute(dir_name, tmp_buff); SAFE_ASPRINTF(&swindow_info[line_pos], "\t</B>Target Group:<!B> %s (Group ID: %s)", tgt_grp_dir_entry->d_name, tmp_buff); line_pos++; } /* Loop over each target name for the * current target group */ snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/target_groups/%s", SYSFS_SCST_TGT, dev_grp_dir_entry->d_name, tgt_grp_dir_entry->d_name); if ((tgt_dir_stream = opendir(dir_name)) == NULL) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s", strerror(errno)); line_pos++; } break; } while ((tgt_dir_entry = readdir(tgt_dir_stream)) != NULL) { /* The target names are links (if local), * or directories (if remote); skip '.' and '..' */ if (((tgt_dir_entry->d_type == DT_DIR) && (strcmp(tgt_dir_entry->d_name, ".") != 0) && (strcmp(tgt_dir_entry->d_name, "..") != 0)) || (tgt_dir_entry->d_type == DT_LNK)) { if (line_pos < MAX_ALUA_LAYOUT_LINES) { snprintf(dir_name, MAX_SYSFS_PATH_SIZE, "%s/device_groups/%s/" "target_groups/%s/%s/rel_tgt_id", SYSFS_SCST_TGT, dev_grp_dir_entry->d_name, tgt_grp_dir_entry->d_name, tgt_dir_entry->d_name); readAttribute(dir_name, tmp_buff); SAFE_ASPRINTF(&swindow_info[line_pos], "\t\t</B>Target:<!B> %s " "(Rel Tgt ID: %s)", tgt_dir_entry->d_name, tmp_buff); line_pos++; } } } closedir(tgt_dir_stream); } } closedir(tgt_grp_dir_stream); /* Print a blank line to separate targets */ if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], " "); line_pos++; } } } closedir(dev_grp_dir_stream); break; } /* Add a message to the bottom explaining how to close the dialog */ if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], " "); line_pos++; } if (line_pos < MAX_ALUA_LAYOUT_LINES) { SAFE_ASPRINTF(&swindow_info[line_pos], CONTINUE_MSG); line_pos++; } /* Set the scrolling window content */ setCDKSwindowContents(alua_info, swindow_info, line_pos); /* The 'g' makes the swindow widget scroll to the top, then activate */ injectCDKSwindow(alua_info, 'g'); activateCDKSwindow(alua_info, 0); /* We fell through -- the user exited the widget, but we don't care how */ destroyCDKSwindow(alua_info); /* Done */ for (i = 0; i < MAX_ALUA_LAYOUT_LINES; i++) FREE_NULL(swindow_info[i]); return; }