- bug fixes in tecs client routines
- improved instr_host routine - double control etc. in tecs
This commit is contained in:
@@ -44,17 +44,14 @@ static char *getItem(char *line, char *name, char *value, int value_len) {
|
||||
return result;
|
||||
}
|
||||
|
||||
int InstrHost(char *service, char *input, char *instr, int instr_len,
|
||||
char *host, int host_len, int *port) {
|
||||
void scanHostList(void (*func)(char *)) {
|
||||
int i;
|
||||
FILE *fil, *lfil;
|
||||
char *hostlist;
|
||||
char localhostlist[512];
|
||||
char line[512], lline[512], hostport[64];
|
||||
char *found, *colon, *crit;
|
||||
int dirty, home, finished;
|
||||
char line[512], lline[512];
|
||||
int dirty;
|
||||
|
||||
home = 0;
|
||||
hostlist = getenv("InstrumentHostList");
|
||||
if (!hostlist) {
|
||||
hostlist="/afs/psi.ch/project/sinq/common/lib/sea/hostlist";
|
||||
@@ -66,44 +63,18 @@ int InstrHost(char *service, char *input, char *instr, int instr_len,
|
||||
if (fil) {
|
||||
if (!lfil) dirty = 1;
|
||||
} else {
|
||||
if (!lfil) return 0;
|
||||
if (!lfil) return;
|
||||
fil = lfil;
|
||||
lfil = NULL;
|
||||
}
|
||||
*port = 0;
|
||||
if (input == NULL || input[0] <= ' ') {
|
||||
crit = "host";
|
||||
input = getenv("HOST");
|
||||
} else {
|
||||
crit = "instr";
|
||||
}
|
||||
finished = 0;
|
||||
while (NULL != fgets(line, sizeof line, fil)) {
|
||||
if (!dirty && lfil
|
||||
&& (fgets(lline, sizeof lline, lfil) == NULL
|
||||
|| strcmp(line, lline) != 0)) {
|
||||
dirty = 1;
|
||||
}
|
||||
if (!finished && getItem(line, crit, input, 0) != NULL) {
|
||||
hostport[0]='\0';
|
||||
found = getItem(line, service, hostport, sizeof hostport);
|
||||
if (found) {
|
||||
instr[0] = '\0';
|
||||
getItem(line, "instr", instr, instr_len);
|
||||
colon = strchr(hostport, ':');
|
||||
if (colon) {
|
||||
i = atoi(colon+1);
|
||||
if (i > 0) {
|
||||
*colon='\0';
|
||||
snprintf(host, host_len, "%s", hostport);
|
||||
finished = 1;
|
||||
*port = i;
|
||||
if (getItem(line, "host", getenv("HOST"), 0) != NULL) {
|
||||
home = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line[0] != '#') {
|
||||
func(line);
|
||||
}
|
||||
}
|
||||
if (fil) fclose(fil);
|
||||
@@ -121,9 +92,104 @@ int InstrHost(char *service, char *input, char *instr, int instr_len,
|
||||
fclose(fil);
|
||||
}
|
||||
}
|
||||
return home;
|
||||
}
|
||||
|
||||
static char *service;
|
||||
static char *crit;
|
||||
static char *input;
|
||||
static int finished;
|
||||
static int home;
|
||||
static char hostport[128];
|
||||
static char *instr;
|
||||
static int instr_len;
|
||||
static char *host;
|
||||
static int host_len;
|
||||
static int port;
|
||||
|
||||
void findCrit(char *line) {
|
||||
char *colon;
|
||||
int i;
|
||||
|
||||
if (getItem(line, crit, input, 0) != NULL) {
|
||||
hostport[0]='\0';
|
||||
if (getItem(line, service, hostport, sizeof hostport) != NULL) {
|
||||
instr[0] = '\0';
|
||||
if (finished == 0) {
|
||||
getItem(line, "instr", instr, instr_len);
|
||||
}
|
||||
colon = strchr(hostport, ':');
|
||||
if (colon) {
|
||||
i = atoi(colon+1);
|
||||
if (i > 0) {
|
||||
*colon='\0';
|
||||
if (finished == 0) {
|
||||
snprintf(host, host_len, "%s", hostport);
|
||||
port = i;
|
||||
}
|
||||
finished++;
|
||||
if (getItem(line, "host", getenv("HOST"), 0) != NULL) {
|
||||
home = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int InstrHost(char *serviceArg, char *inputArg, char *instrArg, int instr_lenArg,
|
||||
char *hostArg, int host_lenArg, int *portArg) {
|
||||
service = serviceArg;
|
||||
input = inputArg;
|
||||
instr = instrArg;
|
||||
instr_len = instr_lenArg;
|
||||
host = hostArg;
|
||||
host_len = host_lenArg;
|
||||
port = 0;
|
||||
home = 0;
|
||||
finished = 0;
|
||||
|
||||
if (input == NULL || input[0] <= ' ') {
|
||||
crit = "host";
|
||||
input = getenv("HOST");
|
||||
} else {
|
||||
crit = "instr";
|
||||
}
|
||||
|
||||
scanHostList(findCrit);
|
||||
|
||||
*portArg = port;
|
||||
return home * finished;
|
||||
}
|
||||
|
||||
static char *list;
|
||||
static int list_len;
|
||||
|
||||
void listInstr(char *line) {
|
||||
int l;
|
||||
*list='\0';
|
||||
if (getItem(line, service, "", 0) &&
|
||||
getItem(line, "instr", list, list_len)) {
|
||||
l = strlen(list);
|
||||
list += l;
|
||||
list_len -= l;
|
||||
} else if (line[0] > ' ') {
|
||||
return;
|
||||
}
|
||||
if (list_len > 0) {
|
||||
*list = ' ';
|
||||
list++;
|
||||
list_len--;
|
||||
}
|
||||
}
|
||||
|
||||
void InstrList(char *serviceArg, char *listArg, int list_lenArg) {
|
||||
service = serviceArg;
|
||||
list = listArg;
|
||||
list_len = list_lenArg;
|
||||
scanHostList(listInstr);
|
||||
if (list > listArg) list--; /* remove trailing blank */
|
||||
*list = '\0';
|
||||
}
|
||||
|
||||
#ifdef MYC_FORTRAN
|
||||
/* compile only when fortran c interface stuff is defined */
|
||||
|
||||
Reference in New Issue
Block a user