[net.sources] A new USEFUL command for tip

thompson@dalcs.UUCP (Michael A. Thompson) (01/01/87)

	It has always bothered me that I couldn't find out the current
    value of a variable in tip, or for that matter find out what the
    variables are(without getting out of tip and running man only to
    be told that the list of variables in the man page is incomplete).
    Well last night it finally got to me so here are the mods to tip
    that give it the ~d command, it lists every variable in the
    current tip their type, accessability, and value. If there are
    problems please let me know.
						Mike
RCS file: RCS/cmds.c,v
retrieving revision 1.2
diff -b -c -r1.2 cmds.c
*** /tmp/,RCSt1013144	Thu Jan  1 15:14:23 1987
--- cmds.c	Wed Dec 31 20:46:20 1986
***************
*** 663,668
  }
  
  /*
   * Turn tandem mode on or off for remote tty.
   */
  tandem(option)

--- 663,786 -----
  }
  
  /*
+  * Print out all variables, with their type, accessability and current value
+  */
+ 
+ char *printchar(ch)
+ char ch;
+ {
+     static char string[5];
+     
+     string[0] = '\0';
+     if ((unsigned) ch < (unsigned) '\177' && (unsigned) ch > (unsigned) '\037') {
+ 	string[0] = ch;
+ 	string[1] = '\0';
+     }
+     else if ((unsigned) ch < (unsigned) '\177') {
+ 	string[0] = '^';
+ 	string[1] = ch + '@';
+ 	string[2] = '\0';
+     }
+     else {
+ 	ch = toascii(ch);
+ 	if ((unsigned) ch < (unsigned) '\177' && (unsigned) ch > (unsigned) '\037') {
+ 	    string[0] = 'M';
+ 	    string[1] = '-';
+ 	    string[2] = ch;
+ 	    string[3] = '\0';
+ 	}
+ 	else {
+ 	    string[0] = 'M';
+ 	    string[1] = '-';
+ 	    string[2] = '^';
+ 	    string[3] = ch + '@';
+ 	    string[4] = '\0';
+ 	}
+     }
+     return string;
+ }
+ 
+ #include <strings.h>
+ 
+ char *printstr (str)
+ char	*str;
+ {
+     static char	string[BUFSIZ];
+     int		i;
+ 
+     string[0] = '\0';
+     for (i = 0; str[i] && i * 4 < BUFSIZ-4; i++)
+       strcat(string, printchar(str[i]));
+     if (str[i])
+       strcat(string, "...");
+     return string;
+ }
+ 
+ printvars() {
+     int i;
+     printf ("\n\r%s\n\r%-15s%7s%18s%7s %s\n\r", "Variable:", "Name",
+ 	    "Type", "Read/Write Access", "Abbrev", "Value");
+     for (i=0;vtable[i].v_name;i++) {
+ 	printf("%-15s", vtable[i].v_name);
+ 	switch (vtable[i].v_type & 017) {
+ 	case STRING:
+ 	    printf("%7s","String");
+ 	    break;
+ 	case BOOL:
+ 	    printf("%7s","Bool");
+ 	    break;
+ 	case NUMBER:
+ 	    printf("%7s","Number");
+ 	    break;
+ 	case CHAR:
+ 	    printf("%7s","Char");
+ 	    break;
+ 	default:
+ 	    printf("%7s","");
+ 	    break;
+ 	}
+ 	if (vtable[i].v_access & (READ << PUBLIC))
+ 	  printf("%8s","Public");
+ 	else if (vtable[i].v_access & (READ << PRIVATE))
+ 	  printf("%8s","Private");
+ 	else if (vtable[i].v_access & (READ << ROOT))
+ 	  printf("%8s","Root");
+ 	else
+ 	  printf("%8s","");
+ 	printf (" / ");
+ 	if (vtable[i].v_access & (WRITE << PUBLIC))
+ 	  printf("%-7s","Public");
+ 	else if (vtable[i].v_access & (WRITE << PRIVATE))
+ 	  printf("%-7s","Private");
+ 	else if (vtable[i].v_access & (WRITE << ROOT))
+ 	  printf("%-7s","Root");
+ 	else
+ 	  printf("%-7s","");
+ 	printf ("%7s", vtable[i].v_abrev);
+ 	if ((vtable[i].v_access & ((READ << PUBLIC) | (READ << PRIVATE))) || ((vtable[i].v_access & (READ << ROOT)) && getuid() == 0))
+ 	  switch (vtable[i].v_type & 017) {
+ 	  case STRING:
+ 	      printf(" \"%s\"\n\r",printstr(address(vtable[i].v_value)));
+ 	      break;
+ 	  case BOOL:
+ 	      printf(" %s\n\r",boolean(vtable[i].v_value) ? "True" : "False");
+ 	      break;
+ 	  case NUMBER:
+ 	      printf(" %d\n\r",number(vtable[i].v_value));
+ 	      break;
+ 	  case CHAR:
+ 	      printf(" `%s'\n\r",printchar(character(vtable[i].v_value)));
+ 	      break;
+ 	  default:
+ 	      printf("\n\r");
+ 	      break;
+ 	  }
+ 	else
+ 	  printf(" Tsk tsk, you can't look at me!\n\r");
+     }
+ }
+ 
+ /*
   * Turn tandem mode on or off for remote tty.
   */
  tandem(option)
RCS file: RCS/cmdtab.c,v
retrieving revision 1.1
diff -b -c -r1.1 cmdtab.c
*** /tmp/,RCSt1013165	Thu Jan  1 15:15:28 1987
--- cmdtab.c	Wed Dec 31 20:46:24 1986
***************
*** 7,12
  extern	int shell(), getfl(), sendfile(), chdirectory();
  extern	int finish(), help(), pipefile(), consh(), variable();
  extern	int cu_take(), cu_put(), dollar(), genbrk(), suspend();
  
  esctable_t etable[] = {
  	{ '!',	NORM,	"shell",			 shell },

--- 7,13 -----
  extern	int shell(), getfl(), sendfile(), chdirectory();
  extern	int finish(), help(), pipefile(), consh(), variable();
  extern	int cu_take(), cu_put(), dollar(), genbrk(), suspend();
+ extern  int printvars();
  
  esctable_t etable[] = {
  	{ '!',	NORM,	"shell",			 shell },
***************
*** 23,28
  	{CTRL(d),NORM,	"exit from tip",		 finish },
  	{CTRL(z),NORM,	"suspend tip",			 suspend },
  	{ 's',	NORM,	"set variable",			 variable },
  	{ '?',	NORM,	"get this summary",		 help },
  	{ '#',	NORM,	"send break",			 genbrk },
  	{ 0, 0, 0 }

--- 24,30 -----
  	{CTRL(d),NORM,	"exit from tip",		 finish },
  	{CTRL(z),NORM,	"suspend tip",			 suspend },
  	{ 's',	NORM,	"set variable",			 variable },
+ 	{ 'd',  NORM,   "print variables and their values", printvars },
  	{ '?',	NORM,	"get this summary",		 help },
  	{ '#',	NORM,	"send break",			 genbrk },
  	{ 0, 0, 0 }
-- 
Michael A. Thompson, Dept. Math, Stats, & C.S., Dalhousie U., Halifax, N.S.
CDN or BITNET: thompson@cs.dal.cdn	CSNET: thompson%cs.dal.cdn@ubc.csnet
UUCP:	    ...!{garfield|seismo|utai|watmath}!dalcs!thompson
ARPA:	      thompson%cs.dal.cdn%ubc.csnet@CSNET-RELAY.ARPA

thompson@dalcs.UUCP (Michael A. Thompson) (01/02/87)

	Oops, It seems that ~s all lists all the variables with their
    values, so what I've written is a verbose version of ~s all.
-- 
Michael A. Thompson, Dept. Math, Stats, & C.S., Dalhousie U., Halifax, N.S.
CDN or BITNET: thompson@cs.dal.cdn	CSNET: thompson%cs.dal.cdn@ubc.csnet
UUCP:	    ...!{garfield|seismo|utai|watmath}!dalcs!thompson
ARPA:	      thompson%cs.dal.cdn%ubc.csnet@CSNET-RELAY.ARPA