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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
/*
* 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: ndi_parse.c,v 1.3 1999/11/08 06:20:21 bbarrett Exp $
*
* Function: - node identifier parsing package
* - id_range() based in part on Trollius 2.0,
* Copyright 1990 The Ohio State University and Cornell
* Research Foundation
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "all_list.h"
#include "args.h"
#include "ndi.h"
#include "lam.h"
#define NEW 1
#define ONE 2
#define MANY 3
/*
* global functions
*/
LIST * ndi_parse();
int4 ndi_parse1();
void ndi_fmt();
void ndi_usage();
/*
* local functions
*/
static int id_range(); /* parse a range of identifiers */
/*
* ndi_parse
*
* Functions: - parses node identifier mnemonics
* Accepts: - command line count
* - command line vector
* - leftover vector (returned)
* Returns: - node list or null
*/
LIST *
ndi_parse(argc, argv, othersv)
int argc;
char ** argv;
char *** othersv;
{
int index = 0; /* current index */
int othersc; /* leftover count */
struct ndi new; /* new list element */
LIST * nodelist; /* node ID list */
/*
* Initialize the list.
*/
nodelist = al_init(sizeof(struct ndi), 0);
if (nodelist == 0) return(0);
/*
* Pass argument 0 through.
*/
if (othersv) {
othersc = 0;
*othersv = 0;
if (argvadd(&othersc, othersv, argv[0])) {
al_free(nodelist);
return(0);
}
}
argc--;
argv++;
/*
* Loop through all the arguments.
*/
while (argc) {
/*
* Is it a generic node identifier?
*/
if ((**argv == 'n') && isdigit((int)*(*argv + 1))) {
if (id_range(*argv + 1, 0, &index, nodelist)) {
al_free(nodelist);
if (othersv) argvfree(*othersv);
return(0);
}
}
/*
* Is it the local host identifier (h)?
*/
else if ((**argv == 'h') && (*(*argv + 1) == '\0')) {
new.ndi_node = LOCAL;
new.ndi_flags = NT_ME;
new.ndi_count = 1;
new.ndi_index = index++;
if (al_append(nodelist, &new) == 0) {
al_free(nodelist);
if (othersv) argvfree(*othersv);
return(0);
}
}
/*
* Is it a multicast destination?
*/
else if ((**argv == 'O') && (*(*argv + 1) == '\0')) {
new.ndi_node = HOST2OTB;
new.ndi_flags = NT_CAST;
new.ndi_count = -1;
new.ndi_index = index++;
if (al_append(nodelist, &new) == 0) {
al_free(nodelist);
if (othersv) argvfree(*othersv);
return(0);
}
}
else if ((**argv == 'C') && (*(*argv + 1) == '\0')) {
new.ndi_node = HOST2COMP;
new.ndi_flags = NT_CAST;
new.ndi_count = -1;
new.ndi_index = index++;
if (al_append(nodelist, &new) == 0) {
al_free(nodelist);
if (othersv) argvfree(*othersv);
return(0);
}
}
else if ((**argv == 'N') && (*(*argv + 1) == '\0')) {
new.ndi_node = HOST2ALL;
new.ndi_flags = NT_CAST;
new.ndi_count = -1;
new.ndi_index = index++;
if (al_append(nodelist, &new) == 0) {
al_free(nodelist);
if (othersv) argvfree(*othersv);
return(0);
}
}
/*
* Bump the non-nodeid pointer and counter.
*/
else if (othersv) {
if (argvadd(&othersc, othersv, argv[0])) {
al_free(nodelist);
argvfree(*othersv);
return(0);
}
}
argc--;
argv++;
}
return(nodelist);
}
/*
* ndi_fmt
*
* Function: - translates a node identifier into a mnemonic string
* Accepts: - node identifier
* - string buffer
*/
void
ndi_fmt(node, fmt_str)
int4 node;
char *fmt_str;
{
if (node == NOTNODEID) {
strcpy(fmt_str, "?");
} else if (node == LOCAL) {
strcpy(fmt_str, "local");
} else if (node == HOST2OTB) {
strcpy(fmt_str, "O");
} else if (node == HOST2ALL) {
strcpy(fmt_str, "N");
} else if (node == HOST2COMP) {
strcpy(fmt_str, "C");
} else {
sprintf(fmt_str, "n%d", node);
}
}
/*
* ndi_parse1
*
* Function: - parses one node identifier
* Accepts: - mnemonic string
* Returns: - node identifier
*/
int4
ndi_parse1(s)
char *s;
{
int4 node;
if (strcmp(s, "h") == 0) {
node = LOCAL;
} else if (strcmp(s, "local") == 0) {
node = LOCAL;
} else if (strcmp(s, "O") == 0) {
node = HOST2OTB;
} else if (strcmp(s, "N") == 0) {
node = HOST2ALL;
} else if (strcmp(s, "C") == 0) {
node = HOST2COMP;
}
else if (sscanf(s, " n%d", &node) == 1) {
}
else {
node = NOTNODEID;
}
return(node);
}
/*
* ndi_usage
*
* Function: - prints a nodespec usage message
*/
void
ndi_usage()
{
printf("\nNodes: n<list>, eg., n0-3,5,0xa,12-15\n");
}
/*
* id_range
*
* Function: - parses the ID range format
* - example: 1,3-5,7
* Accepts: - range string
* - flags to use with every value found
* - current index ptr
* - list descriptor ptr
* Returns: - 0 or ERROR
*/
static int
id_range(s, flags, ixp, lp)
char *s;
int4 flags;
int *ixp;
LIST *lp;
{
int c; /* current character */
int4 id; /* current identifier */
int4 oldid; /* previous identifier */
int mode; /* parsing state */
struct ndi new; /* new list entry */
char *t; /* bumped up s */
mode = NEW;
while ((c = *s) != '\0') {
if (c == ',') {
if (mode == NEW) {
errno = EBADIDSPEC;
return(LAMERROR);
}
++s;
mode = NEW;
}
else if (c == '-') {
if (mode != ONE) {
errno = EBADIDSPEC;
return(LAMERROR);
}
++s;
mode = MANY;
}
else {
id = strtol(s, &t, 0);
if ((id == 0) && (s == t)) {
errno = EBADIDSPEC;
return(LAMERROR);
}
s = t;
if (mode == NEW) {
new.ndi_node = id;
new.ndi_flags = flags;
new.ndi_count = 1;
new.ndi_index = (*ixp)++;
if (al_append(lp, &new) == 0) return(LAMERROR);
oldid = id;
mode = ONE;
}
else if (mode == MANY) {
if (id < oldid) {
errno = EBADIDSPEC;
return(LAMERROR);
}
while (++oldid <= id) {
new.ndi_node = oldid;
new.ndi_flags = flags;
new.ndi_count = 1;
new.ndi_index = (*ixp)++;
if (al_append(lp, &new) == 0)
return(LAMERROR);
}
}
else {
errno = EIMPOSSIBLE;
return(LAMERROR);
}
}
} /* while() */
return (0);
}
|