1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
/*
* Copyright 1998-1999, University of Notre Dame.
* Authors: Brian W. Barrett, Arun F. Rodrigues, Jeffrey M. Squyres,
* and Andrew Lumsdaine
*
* This file is part of XMPI
*
* You should have received a copy of the License Agreement for XMPI
* along with the software; see the file LICENSE. If not, contact
* Office of Research, University of Notre Dame, Notre Dame, IN 46556.
*
* Permission to modify the code and to distribute modified code is
* granted, provided the text of this NOTICE is retained, a notice that
* the code was modified is included with the above COPYRIGHT NOTICE and
* with the COPYRIGHT NOTICE in the LICENSE file, and that the LICENSE
* file is distributed with the modified code.
*
* LICENSOR MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED.
* By way of example, but not limitation, Licensor MAKES NO
* REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY
* PARTICULAR PURPOSE OR THAT THE USE OF THE LICENSED SOFTWARE COMPONENTS
* OR DOCUMENTATION WILL NOT INFRINGE ANY PATENTS, COPYRIGHTS, TRADEMARKS
* OR OTHER RIGHTS.
*
* Additional copyrights may follow.
*
* $Id: xmpi_nodes.c,v 1.4 1999/11/11 04:47:33 arodrig6 Exp $
*
* Function: - node list panel in builder dialog
* - only understands host file syntax
*/
#define _NO_PROTO
#include <stdlib.h>
#include <string.h>
#include <Xm/Frame.h>
#include <Xm/Label.h>
#include <Xm/List.h>
#include <Xm/PanedW.h>
#include <Xm/TextF.h>
#include <Xm/Xm.h>
#include "args.h"
#include "xmpi.h"
/*
* global functions
*/
void xmpi_nodes_build();
/*
* external functions
*/
extern int bhostparse();
extern void itoa();
/*
* local functions
*/
static void nodes_fill();
static void nodes_select_cb();
/*
* local variables
*/
#define MAXLINE 80
static char linebuf[MAXLINE];
static Widget list_w;
/*
* xmpi_nodes_build
*
* Function: - builds node panel
* Accepts: - parent widget
*/
void
xmpi_nodes_build(parent_w)
Widget parent_w;
{
Widget mgr_w;
XmString xstr;
mgr_w = XtVaCreateWidget("nodes_mgr",
xmPanedWindowWidgetClass, parent_w,
XmNsashWidth, 1,
XmNsashHeight, 1,
XmNseparatorOn, False,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 2,
XmNleftOffset, 5,
XmNrightOffset, 1,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
xstr = XmStringCreateSimple("Select Nodes");
XtVaCreateManagedWidget("banner",
xmLabelWidgetClass, mgr_w,
XmNlabelString, xstr,
NULL);
XmStringFree(xstr);
XtVaCreateManagedWidget("nodes_text",
xmTextFieldWidgetClass, mgr_w,
XmNvalue, xmpi_info,
XmNeditable, False,
XmNcursorPositionVisible, False,
NULL);
list_w = XmCreateScrolledList(mgr_w, "nodes_list", NULL, 0);
XtVaSetValues(list_w,
XmNscrollBarDisplayPolicy, XmSTATIC,
XmNscrollHorizontal, False,
XmNselectionPolicy, XmEXTENDED_SELECT,
NULL);
XtAddCallback(list_w, XmNdefaultActionCallback, nodes_select_cb, NULL);
XtAddCallback(list_w, XmNextendedSelectionCallback,
nodes_select_cb, NULL);
XtManageChild(list_w);
/*
* Fill the list.
*/
nodes_fill();
xmpi_nosash(mgr_w);
XtManageChild(mgr_w);
}
/*
* nodes_select_cb
*
* Function: - builds mnemonic node specification string
* from all selected list members
* Accepts: - widget
* - client data
* - ptr callback struct
*/
static void
nodes_select_cb(w, cdata, p_callback)
Widget w;
XtPointer cdata;
XmListCallbackStruct *p_callback;
{
int i;
int *pposn;
int n; /* current mnemonic size */
int running; /* current end of range */
int size; /* current mnemonic buffer size */
int start; /* start of range */
char *mnemonic;
char *p;
Arg arg;
if (p_callback->selected_item_count == 0) {
return;
}
pposn = p_callback->selected_item_positions;
/*
* Lesstif seems to have a bug...?
*/
XtSetArg(arg, XmNitemCount, &size);
XtGetValues(list_w, &arg, 1);
if (p_callback->selected_item_count > size) {
return;
}
/*
* MAXLINE must be longer than SAFETY.
*/
size = MAXLINE;
mnemonic = malloc((unsigned) size);
if (!mnemonic) xmpi_fail("xmpi (malloc)");
/*
* Handle special mnemonics.
*/
if (pposn[0] < 3) {
mnemonic[0] = (pposn[0] == 1) ? 'N' : 'h';
mnemonic[1] = '\0';
xmpi_run_set_nodes(mnemonic);
free(mnemonic);
return;
}
mnemonic[0] = 'n';
pposn[0] -= 3;
itoa(pposn[0], mnemonic + 1);
n = strlen(mnemonic);
p = mnemonic + n;
start = running = pposn[0];
for (i = 1; i < p_callback->selected_item_count; ++i) {
pposn[i] -= 3;
if (pposn[i] == (running + 1)) {
running += 1;
continue;
}
if (running > start) {
*p = '-';
itoa(running, p + 1);
n += strlen(p);
p = mnemonic + n;
}
*p = ',';
itoa(pposn[i], p + 1);
n += strlen(p);
p = mnemonic + n;
start = running = pposn[i];
/*
* SAFETY must be long enough to fit two decimal numbers plus two commas.
*/
#define SAFETY 30
if (n >= (size - SAFETY)) {
size *= 2;
p = malloc((unsigned) size);
if (!p) xmpi_fail("xmpi (malloc)");
strcpy(p, mnemonic);
free(mnemonic);
mnemonic = p;
}
}
if (running > start) {
*p = '-';
itoa(running, p + 1);
}
xmpi_run_set_nodes(mnemonic);
free(mnemonic);
}
/*
* nodes_fill
*
* Function: - fills list with node names and numbers
*/
static void
nodes_fill()
{
XmString xstr;
char **nodev;
int i;
/*
* Delete all current list entries.
*/
XmListDeselectAllItems(list_w);
XmListDeleteAllItems(list_w);
/*
* Add special mnemonics.
*/
xstr = XmStringCreateSimple("ALL NODES");
XmListAddItem(list_w, xstr, 0);
XmStringFree(xstr);
xstr = XmStringCreateSimple("LOCAL NODE");
XmListAddItem(list_w, xstr, 0);
XmStringFree(xstr);
/*
* Establish a node<->hostname correspondence.
*/
if ((nodev = xmpi_sys_hosts()) == 0) {
return;
}
/*
* Place node entries from the parsed boot schema into the list.
*/
for (i = 0; nodev[i]; i++) {
linebuf[0] = 'n';
linebuf[1] = '\0';
itoa(i, linebuf + 1);
strcat(linebuf, " ");
strncat(linebuf, nodev[i], (MAXLINE - strlen(linebuf)) - 1);
xstr = XmStringCreateSimple(linebuf);
XmListAddItem(list_w, xstr, 0);
XmStringFree(xstr);
}
sfh_argv_free(nodev);
}
|