/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1990-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* Glenn Fowler
* AT&T Bell Laboratories
*
* remote coshell server miscellaneous support
*/
#include "service.h"
#include <hashkey.h>
typedef struct
{
char* data;
int size;
} String_t;
/*
* create a remote service connect stream
* malloc'd stream pathname is returned
*/
char*
{
register int fd;
register char* path;
return(path);
}
/*
* copy string v length n into s max length m
* v==0 || v=="-" converted to "*"
*/
static void
copystring(char* s, int m, const char* v, int n)
{
if (n <= 0) n = strlen(v);
if (n <= 0 || n == 1 && *v == '-')
{
n = 1;
s[0] = '*';
}
else
{
if (n >= m) n = m - 1;
memcpy(s, v, n);
}
s[n] = 0;
}
/*
* save string s length n into p
* v==0 || v=="-" converted to 0
*/
static char*
{
if (n <= 0 || n == 1 && *v == '-')
return(0);
if (n >= p->size)
{
}
p->data[n] = 0;
return(p->data);
}
/*
* evaluate n1 op n2
*/
static int
{
switch (op)
{
case EQ:
case NE:
case LT:
case LE:
case GE:
case GT:
}
return(0);
}
/*
* compare the string value vp with the string (sb,se-1)
*/
static int
{
int c;
int r;
c = *se;
*se = 0;
switch (op)
{
case EQ:
case NE:
break;
case LT:
break;
case LE:
break;
case GE:
break;
case GT:
break;
default:
r = 0;
break;
}
*se = c;
return(r);
}
/*
* return attribute value for s in sp
* if set!=0 then non-zero returned if s is set in sp and e points to
* the matched attribute in sp
* otherwise value is returned and e is set to point to after the
* end of the attribute id in s
* if set!=0 && rep!=0 then replace value in sp with s up to rep
*/
static long
{
register char* s = (char*)as;
register char* cp;
register char* np;
register int c;
unsigned long x;
int no;
int op;
char* bp;
char* sb;
char* se;
char* st;
char* ee;
if (s && (isalpha(*s) || *s == '_'))
{
osp = 0;
bp = s;
x = 0;
while (isalnum(c = *s++) || c == '_')
if (s <= sb)
x = HASHKEYPART(x, c);
s--;
sb = 0;
if (!set)
{
if (*cp == '@')
{
*e = cp;
c = *cp;
*cp = 0;
*cp = c;
if (!sp) return(0);
*e = cp;
}
else *e = (char*)s;
switch (*cp)
{
case '<':
break;
case '>':
break;
case '=':
break;
case '!':
break;
default:
op = 0;
break;
}
if (op)
{
if (*++cp == '=')
{
cp++;
}
{
}
{
if (*se == '@')
{
c = *cp;
*cp = 0;
*cp = c;
if (tsp)
{
c = *st;
*st = 0;
if ((st - sb) == 4 && (*sb == 'n' && !strncmp(sb, "name", 4) || *sb == 't' && !strncmp(sb, "type", 4)))
{
}
*st = c;
}
}
}
}
switch (x)
{
return(osp ? osp->bias == sp->bias : op ? miscop(sp->bias, op, strton(cp, e, NiL, 100)) : sp->bias);
x = 0;
if (sb)
{
*e = ee;
do
{
{
x = 1;
break;
}
} while (!x && sb);
if (c) *se = c;
}
return(osp ? osp->stat.idle == sp->stat.idle : op ? miscop(sp->stat.idle, op, strelapsed(cp, e, 1)) : sp->stat.idle);
return(osp ? (osp->stat.load / osp->scale) == (sp->stat.load / sp->scale) : op ? miscop(sp->stat.load / sp->scale, op, strton(cp, e, NiL, 100)) : sp->stat.load / sp->scale);
if (sb)
{
*e = ee;
}
return(osp ? osp->rating == sp->rating : op ? miscop(sp->rating, op, strton(cp, e, NiL, 100)) : sp->rating);
if (sb)
{
*e = ee;
}
x = 0;
if (sb)
{
*e = ee;
do
{
{
x = 1;
break;
}
} while (sb);
if (c) *se = c;
}
}
}
for (;;)
{
if (np >= s)
{
{
{
np = *e;
if (*cp++)
add:
{
for (;;)
{
{
break;
}
np++;
}
}
*np = 0;
}
return(1);
}
if (*cp++ == '=')
{
if (set)
{
if (rep)
{
goto replace;
}
*e = cp;
return(1);
}
if (sb)
{
*e = ee;
c = *np;
*np = 0;
*np = c;
return(set);
}
if (osp)
{
}
return(set);
}
break;
}
cp--;
for (;;)
{
if (!*cp)
{
{
goto add;
}
if (sb)
{
*e = ee;
}
return(0);
}
if (*cp++ == ' ') break;
}
}
}
return(0);
}
/*
* parse host attributes from s into p
* d points to optional default attributes
*/
void
{
register char* b;
register char* v;
char* e;
char* r;
char* u;
int n;
int m;
int c;
int t;
int q;
int expr;
unsigned long x;
if (d) *p = *d;
if (s)
{
expr = 0;
for (;;)
{
while (isspace(*s) || *s == ',') s++;
if (!(t = *(b = s)) || t == '#') break;
r = v = 0;
m = 0;
x = 0;
for (;;)
{
switch (c = *s++)
{
case '=':
if (*s != '=')
{
if (!v)
{
v = s;
if ((q = *s) == '"' || q == '\'')
{
v++;
while (*++s && *s != q)
if (*s == '\\' && *(s + 1)) s++;
n = s - v;
if (*s) s++;
break;
}
}
continue;
}
/*FALLTHROUGH*/
case '|':
case '&':
case '<':
case '>':
case '!':
case '(':
case ')':
if (!v)
{
v = s;
t = '*';
if (!expr)
{
expr = 2;
}
}
continue;
case '@':
if (!r) r = s;
continue;
case 0:
case ',':
case ' ':
case '\t':
case '\n':
if (!v)
{
v = b;
}
n = s - v - 1;
if (!c) s--;
break;
default:
if (m++ < HASHKEYMAX)
{
if (m == (s - b))
{
if (islower(c))
x = HASHKEYPART(x, c);
else
{
if (isalnum(c) || c == '_')
x = 0;
m = HASHKEYMAX;
}
}
else m = 6;
}
continue;
}
break;
}
if (r && t != '*')
{
v = r;
m = v[n];
v[n] = 0;
v[n] = m;
if (!sp) continue;
}
else sp = 0;
switch (x)
{
else
{
}
continue;
continue;
if (!sp)
{
}
continue;
else
{
}
continue;
continue;
if (!sp)
{
}
continue;
if (!sp)
{
}
continue;
if (!sp)
{
}
continue;
if (!sp)
{
}
continue;
if (!sp)
{
}
continue;
continue;
continue;
if (!sp && n)
{
if (n >= sizeof(p->label))
{
v += n - sizeof(p->label);
n = sizeof(p->label) - 1;
}
p->label[n] = 0;
}
continue;
if (!sp)
{
}
continue;
continue;
if (!sp)
{
}
continue;
continue;
{
}
continue;
{
}
continue;
{
}
continue;
{
}
continue;
continue;
if (!sp)
{
}
continue;
continue;
{
}
else
{
}
continue;
continue;
if (!sp)
{
}
continue;
continue;
{
}
else
{
}
continue;
if ((v - b) > 6 && *(b + 4) == '.')
{
v = b + HASHKEYMAX;
while (b < v)
{
if (islower(q = *b++))
x = HASHKEYPART(x, q);
else
{
if (isalnum(q) || q == '_')
x = 0;
break;
}
}
switch (x)
{
break;
break;
break;
break;
}
continue;
}
break;
continue;
}
{
u = p->misc;
}
if (!sp) n = s - b - (*s != 0);
{
for (v = b = e; *b && *b != ' '; b++);
n = v - b;
}
else n = 0;
{
if (expr)
{
if (expr == 4)
{
*u++ = '&';
*u++ = '&';
}
else expr = 4;
*u++ = '(';
}
else if (u != p->misc) *u++ = ' ';
memcpy(u, b, n);
u += n;
if (expr) *u++ = ')';
}
*u = 0;
}
}
}
/*
* add misc attributes in s to sp
*/
void
{
char* tp;
for (;;)
{
while (isspace(*s)) s++;
if (!*s) return;
while (!isspace(*s)) if (!*s++) return;
}
}
/*
* evaluate miscmatch() expression operand
*/
static long
{
if (!s)
{
return(0);
}
}
/*
* evaluate misc attribute expression p on shell info sp
*/
int
{
}
/*
* format pseudo-float
*/
char*
fmtfloat(int n)
{
static int inx;
}