improved tecs driver M.Z.
This commit is contained in:
143
tecs/six.c
143
tecs/six.c
@@ -22,27 +22,32 @@ static char pswd1[32]="";
|
||||
static char user2[32]="";
|
||||
static char pswd2[32]="";
|
||||
|
||||
void Usage(void) {
|
||||
printf("\n");
|
||||
printf(" six commandline options:\n");
|
||||
printf(" - login as spy\n");
|
||||
printf(" + login as manager\n");
|
||||
printf(" 0 login as user\n");
|
||||
printf(" -- set spy as default\n");
|
||||
printf(" 00 set user as default\n");
|
||||
printf(" ++ set manager as default\n");
|
||||
printf(" help show this help text\n");
|
||||
printf(" -a or a ask always for username/password, forget passwords\n");
|
||||
printf(" -s or s simulation mode (on some instruments)\n");
|
||||
printf(" -w or w do not skip welcome message\n");
|
||||
printf(" -h \"host\" connect to a SICServer on a different host\n");
|
||||
printf(" no option login with default privilege\n");
|
||||
void Usage(int cmds_only) {
|
||||
if (!cmds_only) {
|
||||
printf("\n");
|
||||
printf(" six commandline options:\n");
|
||||
printf(" - login as spy\n");
|
||||
printf(" + login as manager\n");
|
||||
printf(" 0 login as user\n");
|
||||
printf(" -- set spy as default\n");
|
||||
printf(" 00 set user as default\n");
|
||||
printf(" ++ set manager as default\n");
|
||||
printf(" help show this help text\n");
|
||||
printf(" -a or a ask always for username/password, forget passwords\n");
|
||||
printf(" -s or s simulation mode (on some instruments)\n");
|
||||
printf(" -w or w do not skip welcome message\n");
|
||||
printf(" -h \"host\" connect to a SICServer on a different host\n");
|
||||
printf(" -p \"port\" connect to a SICServer on a different port\n");
|
||||
printf(" -n do not login\n");
|
||||
printf(" no option login with default privilege\n");
|
||||
}
|
||||
printf("\n");
|
||||
printf(" Special commands treated by six (these are no SICS commands!)\n");
|
||||
printf("\n");
|
||||
printf(" quit exit six\n");
|
||||
printf(" exit exit six\n");
|
||||
printf(" stop interrupt SICS\n");
|
||||
printf(" help show this help text\n");
|
||||
printf(" + increase privilege\n");
|
||||
printf(" - decrease privilege\n");
|
||||
printf("\n");
|
||||
@@ -350,7 +355,7 @@ int setrights(int gotolevel) {
|
||||
level=gotolevel;
|
||||
ERR_I(sendCmd(fd, "config list"));
|
||||
ERR_P(p=readWrite(fd,10000,1,"UserRights = "));
|
||||
if (p!=NULL) {
|
||||
if (*p!='\0') {
|
||||
level=*p-'0';
|
||||
}
|
||||
if (level==3) {
|
||||
@@ -393,11 +398,11 @@ int setrights(int gotolevel) {
|
||||
int main (int argc, char *argv[]) {
|
||||
int iret, pos;
|
||||
fd_set mask;
|
||||
int l, i, j, port, skip, gotolevel;
|
||||
int l, i, j, port, skip, gotolevel, sicslogin;
|
||||
char buf[128], lbuf[16], ilow[64];
|
||||
char stdPrompt[128], prompt[256];
|
||||
char *sim="";
|
||||
char *p, *statusMatch;
|
||||
char *p, *statusMatch=NULL;
|
||||
char *pnam[4]={"0", "MANAGER", "user", "spy"};
|
||||
|
||||
struct sockaddr_in sadr;
|
||||
@@ -407,6 +412,7 @@ int main (int argc, char *argv[]) {
|
||||
printf("---------------------------------------------------\n");
|
||||
port=1301;
|
||||
skip=1;
|
||||
sicslogin=1;
|
||||
j=0;
|
||||
deflevel=0;
|
||||
gotolevel=0;
|
||||
@@ -434,27 +440,40 @@ int main (int argc, char *argv[]) {
|
||||
gotolevel=2;
|
||||
deflevel=2;
|
||||
} else if (0==strcmp(argv[i], "help")) {
|
||||
Usage();
|
||||
Usage(0);
|
||||
return 0;
|
||||
} else if (0==strcmp(argv[i], "-h")) {
|
||||
i++;
|
||||
if (i>=argc) {
|
||||
printf("missing host\n");
|
||||
Usage(); return 0;
|
||||
Usage(0); return 0;
|
||||
}
|
||||
host=argv[i];
|
||||
} else if (0==strcmp(argv[i], "-p")) {
|
||||
i++;
|
||||
if (i>=argc) {
|
||||
printf("missing port\n");
|
||||
Usage(0); return 0;
|
||||
}
|
||||
port=atoi(argv[i]);
|
||||
if (port == 0) {
|
||||
printf("illegal port\n");
|
||||
Usage(0); return 0;
|
||||
}
|
||||
} else if (0==strcmp(argv[i], "-n")) {
|
||||
sicslogin=0;
|
||||
} else {
|
||||
if (strlen(argv[i])>=32) {
|
||||
printf("argument too long\n");
|
||||
Usage(); return 0;
|
||||
Usage(0); return 0;
|
||||
} else if (argv[i][0]!='-') {
|
||||
if (j==0) {
|
||||
printf("syntax has changed, username can not be given as argument\n");
|
||||
Usage(); j=1;
|
||||
Usage(0); j=1;
|
||||
}
|
||||
} else {
|
||||
printf("unknown option: %s\n", argv[i]);
|
||||
Usage(); return 0;
|
||||
Usage(0); return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -462,38 +481,44 @@ int main (int argc, char *argv[]) {
|
||||
ERR_SI(fd=socket(AF_INET, SOCK_STREAM, 0));
|
||||
term_reg_socket(fd);
|
||||
ERR_SI(connect(fd, (struct sockaddr *)&sadr, sizeof(sadr)));
|
||||
ERR_I(sendCmd(fd, "sicslogin Spy 007"));
|
||||
ERR_P(p=readWrite(fd,10000,skip,"SICS"));
|
||||
if (*p=='\0') {
|
||||
printf("rejected\n");
|
||||
return 0;
|
||||
}
|
||||
if (skip) printf("reading welcome message ...\n");
|
||||
if (sicslogin) {
|
||||
ERR_I(sendCmd(fd, "sicslogin Spy 007"));
|
||||
ERR_P(p=readWrite(fd,10000,skip,"SICS"));
|
||||
if (*p=='\0') {
|
||||
printf("rejected\n");
|
||||
return 0;
|
||||
}
|
||||
if (skip) printf("reading welcome message ...\n");
|
||||
|
||||
ERR_I(sendCmd(fd, "status interest"));
|
||||
ERR_P(readWrite(fd,10000,0,"OK"));
|
||||
ERR_I(sendCmd(fd, "status interest"));
|
||||
ERR_P(readWrite(fd,10000,0,"OK"));
|
||||
|
||||
ERR_I(sendCmd(fd, "Instrument"));
|
||||
ERR_P(p=readWrite(fd,10000,0,"Instrument = "));
|
||||
str_copy(instr, p);
|
||||
if (*instr=='\0') {
|
||||
printf("can not detect instrument\n");
|
||||
return 0;
|
||||
}
|
||||
p=strchr(instr,' ');
|
||||
if (p!=NULL) *p='\0';
|
||||
if (0==strcmp(instr,"SANS-II")) {
|
||||
str_copy(instr, "SANS2");
|
||||
}
|
||||
ERR_I(i=setrights(gotolevel));
|
||||
if (i==1) return 0;
|
||||
printf("\rlogged in to SICS as %s on %s\n", pnam[level], instr);
|
||||
ERR_I(sendCmd(fd, "Instrument"));
|
||||
ERR_P(p=readWrite(fd,10000,0,"Instrument = "));
|
||||
str_copy(instr, p);
|
||||
if (*instr=='\0') {
|
||||
printf("can not detect instrument\n");
|
||||
return 0;
|
||||
}
|
||||
p=strchr(instr,' ');
|
||||
if (p!=NULL) *p='\0';
|
||||
if (0==strcmp(instr,"SANS-II")) {
|
||||
str_copy(instr, "SANS2");
|
||||
}
|
||||
ERR_I(i=setrights(gotolevel));
|
||||
if (i==1) return 0;
|
||||
printf("\rlogged in to SICS as %s on %s\n", pnam[level], instr);
|
||||
|
||||
str_lowcase(ilow,instr);
|
||||
sprintf(stdPrompt, "six[%s] ", ilow);
|
||||
str_lowcase(ilow,instr);
|
||||
sprintf(stdPrompt, "six[%s] ", ilow);
|
||||
|
||||
ERR_I(sendCmd(fd, "status"));
|
||||
ERR_P(p=readWrite(fd,10000,0,"status = "));
|
||||
ERR_I(sendCmd(fd, "status"));
|
||||
ERR_P(p=readWrite(fd,10000,0,"status = "));
|
||||
|
||||
} else {
|
||||
sprintf(stdPrompt, "six[%s] ", host);
|
||||
p="E";
|
||||
}
|
||||
|
||||
iret=1;
|
||||
buf[0]='\0';
|
||||
@@ -514,7 +539,7 @@ int main (int argc, char *argv[]) {
|
||||
str_lowcase(lbuf, buf);
|
||||
if (0==strcmp(lbuf,"quit")) break;
|
||||
if (0==strcmp(lbuf,"exit")) break;
|
||||
statusMatch="status = ";
|
||||
if (sicslogin) statusMatch="status = ";
|
||||
skip=0;
|
||||
printf("\n");
|
||||
if (0==strcmp(lbuf,"stop")) {
|
||||
@@ -542,14 +567,16 @@ int main (int argc, char *argv[]) {
|
||||
}
|
||||
skip=1;
|
||||
strcpy(buf, "status");
|
||||
} else if (0==strcmp(buf, "help")) {
|
||||
Usage(1);
|
||||
strcpy(buf, "status");
|
||||
} else if (0==strcmp(buf, "six help")) {
|
||||
Usage();
|
||||
Usage(0);
|
||||
strcpy(buf, "status");
|
||||
} else if (0==strcmp(buf, "")) {
|
||||
strcpy(buf, "status");
|
||||
statusMatch=NULL;
|
||||
}
|
||||
|
||||
ERR_I(sendCmd(fd, buf));
|
||||
ERR_P(p=readWrite(fd,1000,skip,statusMatch));
|
||||
buf[0]='\0';
|
||||
@@ -559,13 +586,15 @@ int main (int argc, char *argv[]) {
|
||||
} else { /* socket iret ready to read */
|
||||
assert(fd==iret);
|
||||
ERR_P(p=readWrite(fd,1000,0,"status = "));
|
||||
if (strcmp(p, "0") == 0) {
|
||||
printf("\nconnection lost\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
fputs("\n", stdout);
|
||||
term_save_hist(1); /* save history wihtout last line */
|
||||
term_save_hist(1); /* save history without last line */
|
||||
return 0;
|
||||
Usage:
|
||||
return 0;
|
||||
OnError:
|
||||
ErrShow("end");
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user