From 9ff760a8bcd2735e11fcbd8365ea2b0c9fda5d2d Mon Sep 17 00:00:00 2001 From: cvs Date: Mon, 3 Sep 2001 14:39:22 +0000 Subject: [PATCH] New TECS Version Sept. 2001 M.Z. --- tecs/instr_hosts.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ tecs/instr_hosts.h | 11 ++++++ 2 files changed, 102 insertions(+) create mode 100644 tecs/instr_hosts.c create mode 100644 tecs/instr_hosts.h diff --git a/tecs/instr_hosts.c b/tecs/instr_hosts.c new file mode 100644 index 00000000..37be5f3d --- /dev/null +++ b/tecs/instr_hosts.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include +#include "myc_str.h" +#include "sys_util.h" + +typedef struct { char *instr; char *host; char *user; int cod; } Instrument; +static Instrument list[]={ + { "DMC", "lnsa05.psi.ch", "DMC" , 1}, + { "TOPSI", "lnsa07.psi.ch", "TOPSI" , 1}, + { "SANS", "lnsa10.psi.ch", "SANS" , 3}, + { "HRPT", "lnsa11.psi.ch", "HRPT" , 1}, + { "TRICS", "lnsa13.psi.ch", "TRICS" , 1}, + { "AMOR", "lnsa14.psi.ch", "AMOR" , 1}, + { "FOCUS", "lnsa16.psi.ch", "FOCUS" , 1}, + { "TASP", "lnsa08.psi.ch", NULL , 0}, + { "PREP", "lnsa01.psi.ch", NULL , 0}, + { "TEST", "lnsa15.psi.ch", "lnslib", 2} + }; + +int InstrHost(char *input, char *instr, char *host, char *user, char *pcod + , int instr_len, int host_len, int user_len, int pcod_len) { + char buf[256]; + int i, j; + struct tm tim; + time_t t; + + j=-1; + str_upcase(buf, input); + for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) { + if (0==strcmp(buf, list[i].instr)) { + j=i; + } + } + if (j<0) { + str_lowcase(buf, input); + for (i = 0; i < sizeof(list) / sizeof(list[0]); i++) { + if (list[i].host==strstr(list[i].host, buf)) { + if (j>=0) return 0; + j=i; + } + } + } + if (j<0) return 0; + str_ncpy(instr,list[j].instr, instr_len); + str_ncpy(host, list[j].host, host_len); + if (list[j].user != NULL) { + str_ncpy(user, list[j].user, user_len); + if (list[j].cod == 1) { + str_ncpy(pcod, instr, pcod_len); + str_ncat(pcod, "LNS", pcod_len); + } else if (list[j].cod == 2) { + time(&t); + tim=*localtime(&t); + sprintf(pcod, "%02dlns%d", tim.tm_year % 100, tim.tm_mon/6+1); + } else if (list[j].cod == 3) { + str_ncpy(pcod, instr, pcod_len); + str_ncat(pcod, "ASQ", pcod_len); + } else { + str_ncpy(pcod, " ", pcod_len); + } + } + return 1; +} + + +#ifdef F_CHAR +/* compile only when fortran c interface stuff is defined */ + +#ifdef __VMS +#define instr_host_ instr_host +#endif + +int instr_host_(F_CHAR(input), F_CHAR(instr), F_CHAR(host), F_CHAR(user), F_CHAR(pcod) + , int input_len, int instr_len, int host_len, int user_len, int pcod_len) { + char buf[256], in[256], ho[256], us[256], pc[256]; + int iRet; + + STR_TO_C(buf, input); + iRet=InstrHost(buf, in, ho, us, pc, sizeof(in), sizeof(ho), sizeof(us), sizeof(pc)); + if (iRet>0) { + iRet=STR_TO_F(instr, in); + STR_TO_F(host, ho); + STR_TO_F(user, us); + STR_TO_F(pcod, pc); + } + return iRet; +} + +#endif diff --git a/tecs/instr_hosts.h b/tecs/instr_hosts.h new file mode 100644 index 00000000..13dc308d --- /dev/null +++ b/tecs/instr_hosts.h @@ -0,0 +1,11 @@ +#ifndef _INSTR_HOSTS_H_ +#define _INSTR_HOSTS_H_ + +int InstrHost(char *input, char *instr, char *host, char *user, char *pcod + , int instr_len, int host_len, int user_len, int pcod_len); + +/* input may be a host of instrument name + output is: instrument name, host name, user name and pcod (the code needed to enter...) +*/ + +#endif /* _INSTR_HOSTS_H_ */