- bug fixes in tecs client routines

- improved instr_host routine
- double control etc. in tecs
This commit is contained in:
zolliker
2006-08-17 15:40:29 +00:00
parent ce25823567
commit fdddef7ed9
5 changed files with 109 additions and 38 deletions

View File

@ -206,7 +206,7 @@ int CocPushArg(CocConn *conn, const char *name, void *value, int type, int size)
assert(NULL==strchr(name, ' ')); assert(NULL==strchr(name, ' '));
buf=&conn->cmdbuf; buf=&conn->cmdbuf;
n=conn->nargs; n=conn->nargs;
if (n>=sizeof(conn->args)) ERR_MSG("too many return arguments"); if (n>=sizeof(conn->args)/sizeof(conn->args[0])) ERR_MSG("too many return arguments");
conn->args[n].adr=value; conn->args[n].adr=value;
conn->args[n].type=type; conn->args[n].type=type;
conn->args[n].size=size; conn->args[n].size=size;

View File

@ -44,17 +44,14 @@ static char *getItem(char *line, char *name, char *value, int value_len) {
return result; return result;
} }
int InstrHost(char *service, char *input, char *instr, int instr_len, void scanHostList(void (*func)(char *)) {
char *host, int host_len, int *port) {
int i; int i;
FILE *fil, *lfil; FILE *fil, *lfil;
char *hostlist; char *hostlist;
char localhostlist[512]; char localhostlist[512];
char line[512], lline[512], hostport[64]; char line[512], lline[512];
char *found, *colon, *crit; int dirty;
int dirty, home, finished;
home = 0;
hostlist = getenv("InstrumentHostList"); hostlist = getenv("InstrumentHostList");
if (!hostlist) { if (!hostlist) {
hostlist="/afs/psi.ch/project/sinq/common/lib/sea/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 (fil) {
if (!lfil) dirty = 1; if (!lfil) dirty = 1;
} else { } else {
if (!lfil) return 0; if (!lfil) return;
fil = lfil; fil = lfil;
lfil = NULL; 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)) { while (NULL != fgets(line, sizeof line, fil)) {
if (!dirty && lfil if (!dirty && lfil
&& (fgets(lline, sizeof lline, lfil) == NULL && (fgets(lline, sizeof lline, lfil) == NULL
|| strcmp(line, lline) != 0)) { || strcmp(line, lline) != 0)) {
dirty = 1; dirty = 1;
} }
if (!finished && getItem(line, crit, input, 0) != NULL) { if (line[0] != '#') {
hostport[0]='\0'; func(line);
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 (fil) fclose(fil); if (fil) fclose(fil);
@ -121,9 +92,104 @@ int InstrHost(char *service, char *input, char *instr, int instr_len,
fclose(fil); 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 #ifdef MYC_FORTRAN
/* compile only when fortran c interface stuff is defined */ /* compile only when fortran c interface stuff is defined */

View File

@ -12,4 +12,7 @@ int InstrHost(char *service, char *input, char *instr, int instr_len,
0 else 0 else
*/ */
void InstrList(char *service, char *list, int list_len);
/* get an instrument list supporting named service, separated with blanks */
#endif /* _INSTR_HOSTS_H_ */ #endif /* _INSTR_HOSTS_H_ */

View File

@ -472,7 +472,7 @@ int setrights(int gotolevel) {
} }
} }
level=3; level=3;
ERR_I(sendCmd(sock[0], "config list")); ERR_I(sendCmd(sock[0], "config myrights"));
ERR_P(p=readWrite(12000,1,"UserRights = ")); ERR_P(p=readWrite(12000,1,"UserRights = "));
PutC("."); PutC(".");
if (*p!='\0') { if (*p!='\0') {

View File

@ -3359,6 +3359,8 @@ int main(int argc, char *argv[]) {
CocDefStr(update, RW); CocHdl(UpdateHdl); CocDefStr(update, RW); CocHdl(UpdateHdl);
CocDefStr(lscfg, RD); CocDefStr(lscfg, RD);
CocDefStr(ttp, RD); CocDefStr(ttp, RD);
CocDefStr(alarmChannels, RD);
CocDefStr(alarmHistory, RD);
CocDefInt(cod1, RD); CocDefInt(cod1, RD);
CocDefInt(cod2, RD); CocDefInt(cod2, RD);