From b6bcc4993b1698d4a1a201381eb849e4251e01be Mon Sep 17 00:00:00 2001 From: zolliker Date: Wed, 31 Aug 2005 05:58:57 +0000 Subject: [PATCH] visible difference for sics and sea --- tecs/six.c | 227 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 142 insertions(+), 85 deletions(-) diff --git a/tecs/six.c b/tecs/six.c index 11e7519..9cb66a9 100644 --- a/tecs/six.c +++ b/tecs/six.c @@ -1,3 +1,10 @@ +/* a simple commandline client for SICS and sea + + Markus Zolliker + Mar. 2003 first version + Aug. 2005 visible difference between client for SICS and sea +*/ + #include #include #include @@ -15,6 +22,8 @@ typedef enum { NORMAL, SPY, CLIENT, NMODE } Mode; #define MAXMSG 256 +static char *clcname="six", *servername="SICS"; +static int clclen=3; static char *host; static char instr[32]; static char savedHost[128]; @@ -71,14 +80,17 @@ void PutClear(void) { } void UsageNote(void) { - PutC(" (for usage type: six help)\n"); + PutC(" (for usage type: "); + PutC(clcname); + PutC(" help)\n"); } void Usage(int cmds_only) { if (!cmds_only) { + PutC(" \n "); + PutC(clcname); PutC( - " \n" - " six commandline options:\n" + " commandline options:\n" " -x login as spy\n" " -u login as user\n" " -m login as manager\n" @@ -86,33 +98,39 @@ void Usage(int cmds_only) { " -a or a ask always for username/password, forget passwords\n" " -c or c use background color instead of # and |\n" " -s or s simulation mode (on some instruments)\n" - " \"host\" connect to a SICServer on a different host\n" - " -p \"port\" connect to a SICServer on a different port\n" + " \"host\" connect to a server on a different host\n" + " -p \"port\" connect to a server on a different port\n" " -n do only a minimal login (no check of instrument)\n" " no option login with default privilege\n" ); } PutC( "\n" - " Special commands treated by six (these are no SICS commands!)\n" + " Special commands treated by "); + PutC(clcname); PutC(" (these are no "); PutC(servername); PutC(" commands!)\n" "\n" - " quit exit six\n" - " exit exit six\n" - " stop interrupt SICS\n" - " six help show this help text\n" - " six def stop define a key for stop command\n" - " six save save stop key and connection (host/port/access)\n" + " quit return to unix prompt\n" + " exit return to unix prompt\n" + " stop interrupt driving\n" + " "); PutC(clcname); + PutC(" help show this help text\n" + " "); PutC(clcname); + PutC(" def stop define a key for stop command\n" + " "); PutC(clcname); + PutC(" save save stop key and connection (host/port/access)\n" " + increase privilege\n" " - decrease privilege\n" "\n" - " The SICS status is shown, if it is not 'Eager to execute commands'.\n" + " The "); PutC(servername); + PutC(" status is shown, if it is not 'Eager to execute commands'.\n" " A shown status does not prohibit to enter commands.\n" "\n" - " When SICS is busy, an vertical bar '|' is shown at the left of the line.\n" + " When "); PutC(servername); + PutC(" is busy, a vertical bar '|' is shown at the left of the line.\n" " You may then enter more commands, but only under Spy privilege.\n" - " All messages from the six client are prefixed with a hash symbol '#'.\n" + " All messages from the client are prefixed with a hash symbol '#'.\n" "\n" - " Markus Zolliker, Mar. 2005\n" + " Markus Zolliker, Aug. 2005\n" "\n" ); Put(-1, ""); /* clear colors */ @@ -328,7 +346,9 @@ int setrights(int gotolevel) { int savepw; if (pw == NULL) pw=pswd; - str_copy(prefhead, ".six."); + str_copy(prefhead, "."); + str_append(prefhead, clcname); + str_append(prefhead, "."); str_append(prefhead, instr); if (remember) { @@ -353,15 +373,25 @@ int setrights(int gotolevel) { if (level != gotolevel) { if (gotolevel==1) { if (user1[0]=='\0') { - str_copy(user1, "lnsmanager"); + if (strcmp(clcname, "six") == 0) { + str_copy(user1, "lnsmanager"); + } else { + str_copy(user2, servername); + str_append(user2, "manager"); + } } us=user1; pw=pswd1; } else if (gotolevel==2) { if (user2[0]=='\0') { - str_copy(user2, instr); - str_lowcase(user2, user2); - str_append(user2, "user"); + if (strcmp(clcname, "six") == 0) { + str_copy(user2, instr); + str_lowcase(user2, user2); + str_append(user2, "user"); + } else { + str_copy(user2, servername); + str_append(user2, "user"); + } } us=user2; pw=pswd2; @@ -390,7 +420,8 @@ int setrights(int gotolevel) { } } if (ask) { - PutC("SICS username"); + PutC(servername); + PutC(" username"); if (us[0]!='\0') { PutC(" ["); PutC(us); @@ -488,7 +519,9 @@ int SavePrefs(void) { char *p; ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */ - str_copy(prefhead, ".six_"); + str_copy(prefhead, "."); + str_append(prefhead, clcname); + str_append(prefhead, "_"); str_append(prefhead, sim); str_append(prefhead, name); @@ -500,7 +533,7 @@ int SavePrefs(void) { if (p != NULL) { ent = gethostbyname(p); /* get ip name of "Instrument" translation */ if (ent !=NULL && strcmp(ent->h_name, name) == 0) { /* we are on an instrument computer */ - ent = gethostbyname(instr); /* get host name of SICServer */ + ent = gethostbyname(instr); /* get host name of server */ iret = (ent != NULL && strcmp(ent->h_name, name) != 0); strcpy(savedHost, "localhost"); } @@ -520,7 +553,10 @@ int LoadPrefs(void) { FILE *fil; ERR_SI(gethostname(name, sizeof name)); /* get ip name of this host */ - str_copy(prefhead, ".six_"); + str_copy(prefhead, "."); + str_append(prefhead, clcname); + str_append(prefhead, "_"); + str_append(prefhead, sim); str_append(prefhead, name); fil=term_open_pref(0, prefhead, "r"); if (fil) { @@ -588,6 +624,7 @@ int main (int argc, char *argv[]) { char *bar; char *pnam[4]={"0", "MANAGER", "user", "spy"}; char hostArg[128]; + char *subcmd; atexit(term_off); port=-1; @@ -599,6 +636,10 @@ int main (int argc, char *argv[]) { for (i=1; ih_name); host = hostArg; } - PutC("---------------------------------------------------\n"); - PutC("six, a fast SICS commandline client (doc: six help)\n"); - PutC("---------------------------------------------------\n"); LoadPrefs(); - if (port == -1) { - if (*sim == '\0') { - port = 2911; - } else { - port = 2927; + + PutC( "---------------------------------------------------\n"); + if (strcmp(clcname, "six") == 0) { + PutC("six, a fast SICS commandline client (doc: six help)\n"); + if (port == -1) { + if (*sim == '\0') { + port = 2911; + } else { + port = 2927; + } + } + } else { + PutC("seacmd, a sea commandline client (doc: seacmd help)\n"); + if (port == -1) { + port = 22911; } } + PutC( "---------------------------------------------------\n"); ERR_I(sock[0]=Connect()); if (sock[0] == 0) return 0; if (sicslogin) { @@ -698,13 +747,13 @@ int main (int argc, char *argv[]) { str_copy(instr, "SANS2"); } ERR_I(i=setrights(gotolevel)); - PutC("\rlogged in to SICS as "); + PutC("\rlogged in to "); PutC(servername); PutC(" as "); PutC(pnam[level]); PutC(" on "); PutC(instr); PutC("\n"); - sprintf(stdPrompt, "six[%s] ", instr); + sprintf(stdPrompt, "%s[%s] ", clcname, instr); ERR_I(sendCmd(sock[0], "status interest")); ERR_P(readWrite(12000,0,"OK")); @@ -713,7 +762,7 @@ int main (int argc, char *argv[]) { ERR_P(readWrite(12000,0,NULL)); } else { - sprintf(stdPrompt, "six[%s] ", host); + sprintf(stdPrompt, "%s[%s] ", clcname, host); status[0]='E'; status[1]='\0'; } @@ -721,7 +770,7 @@ int main (int argc, char *argv[]) { buf[0]='\0'; pos=0; - term_read_hist("six"); + term_read_hist(clcname); savehist = 1; while (1) { @@ -778,58 +827,65 @@ int main (int argc, char *argv[]) { PutC(pnam[level]); PutC(" privilege\n"); buf[0]='\0'; - } else if (0==strcmp(buf, "help six")) { + } else if (0==strncmp(buf, "help ", 5) && 0==strcmp(buf+5, clcname)) { PrintCmd(buf, CLIENT); Usage(1); buf[0]='\0'; - } else if (0==strcmp(buf, "six help")) { - PrintCmd(buf, CLIENT); - Usage(0); - buf[0]='\0'; - } else if (0==strncmp(buf, "six def ", 8)) { - PrintCmd(buf, CLIENT); - term_define_key(buf+8, 0); - buf[0]='\0'; - } else if (0==strcmp(buf, "six def")) { - PrintCmd(buf, CLIENT); - term_define_key("", 0); - buf[0]='\0'; - } else if (0==strcmp(buf, "six save")) { - PrintCmd(buf, CLIENT); - PutC("defaults for next calls to six:\n"); - ERR_I(i=SavePrefs()); - if (level == 0) { - gotolevel = 3; - } else { - gotolevel = level; + } else if (0==strncmp(buf, clcname, clclen) && buf[clclen] == ' ') { + subcmd = buf + clclen; + while (*subcmd <= ' ' && *subcmd != 0) { + subcmd++; } - PutC(" connect to "); - if (i == 1) { - PutC(getenv("Instrument")); - PutC(" (on "); - PutC(savedHost); - PutC(", this default can not be changed)\n"); - } else { - deflevel = gotolevel; - ERR_I(setrights(gotolevel)); - PutC(instr); - PutC(" ("); - PutC(savedHost); - if (port != 2911 && port !=2927) { - snprintf(buf, sizeof buf, ":%d", port); - PutC(buf); + if (0==strcmp(subcmd, "help")) { + PrintCmd(buf, CLIENT); + Usage(0); + buf[0]='\0'; + } else if (0==strncmp(subcmd, "def ", 4)) { + PrintCmd(buf, CLIENT); + term_define_key(subcmd+4, 0); + buf[0]='\0'; + } else if (0==strcmp(subcmd, "def")) { + PrintCmd(buf, CLIENT); + term_define_key("", 0); + buf[0]='\0'; + } else if (0==strcmp(subcmd, "save")) { + PrintCmd(buf, CLIENT); + PutC("defaults for next calls to "); + PutC(clcname); PutC(":\n"); + ERR_I(i=SavePrefs()); + if (level == 0) { + gotolevel = 3; + } else { + gotolevel = level; } - PutC(")\n login as "); - PutC(us); - PutC(" with "); - PutC(pnam[level]); - PutC(" privilege\n"); + PutC(" connect to "); + if (i == 1) { + PutC(getenv("Instrument")); + PutC(" (on "); + PutC(savedHost); + PutC(", this default can not be changed)\n"); + } else { + deflevel = gotolevel; + ERR_I(setrights(gotolevel)); + PutC(instr); + PutC(" ("); + PutC(savedHost); + if (port != 2911 && port !=2927) { + snprintf(buf, sizeof buf, ":%d", port); + PutC(buf); + } + PutC(")\n login as "); + PutC(us); + PutC(" with "); + PutC(pnam[level]); + PutC(" privilege\n"); + } + buf[0]='\0'; + } else { + PrintCmd(buf, CLIENT); + PutC("ERROR: unknown command\n"); + buf[0]='\0'; } - buf[0]='\0'; - } else if (0==strncmp(buf, "six ", 4)) { - PrintCmd(buf, CLIENT); - PutC("ERROR: unknown command\n"); - buf[0]='\0'; } else if (buf[0] == '\0') { /* empty command */ PrintCmd(buf, CLIENT); ERR_P(p=readWrite(200,0,NULL)); /* just wait a little */ @@ -865,8 +921,9 @@ int main (int argc, char *argv[]) { buf[0]='\0'; pos=0; } else if (iret>0) { /* something arrived from sockets */ - assert(iret == sock[0] || iret == sock[1]); - ERR_P(p=readWrite(500,0,NULL)); + if (iret == sock[0] || iret == sock[1]) { + ERR_P(p=readWrite(500,0,NULL)); + } } if (strcmp(p, "0") == 0) { term_clear();