Subject: Re: bin/7655: Dodgy keyboard case translation in /usr/bin/systat
To: None <gnats-bugs@netbsd.org, netbsd-bugs@netbsd.org>
From: Geoff Wing <gcw@pobox.com>
List: netbsd-bugs
Date: 05/28/1999 14:01:09
This will translate the commands, but will display text as typed instead of
translating.

*** /usr/src/usr.bin/systat/cmds.c	Sun Dec 20 23:18:28 1998
--- /obj/src/usr.bin/systat/cmds.c	Fri May 28 13:55:22 1999
***************
*** 185,197 ****
  	error("Showing %s, refresh every %d seconds.", curcmd->c_name, naptime);
  }
  
  int
  prefix(s1, s2)
  	char *s1, *s2;
  {
  
! 	while (*s1 == *s2) {
! 		if (*s1 == '\0')
  			return (1);
  		s1++, s2++;
  	}
--- 185,203 ----
  	error("Showing %s, refresh every %d seconds.", curcmd->c_name, naptime);
  }
  
+ /* case insensitive prefix comparison */
  int
  prefix(s1, s2)
  	char *s1, *s2;
  {
+ 	char c1, c2;
  
! 	while (1) {
! 		c1 = *s1 >= 'A' && *s1 <= 'Z' ? *s1 + 'a' - 'A' : *s1;	
! 		c2 = *s2 >= 'A' && *s2 <= 'Z' ? *s2 + 'a' - 'A' : *s2;	
! 		if (c1 != c2)
! 			break;
! 		if (c1 == '\0')
  			return (1);
  		s1++, s2++;
  	}

*** /usr/src/usr.bin/systat/keyboard.c	Sun Jul 12 21:12:03 1998
--- /obj/src/usr.bin/systat/keyboard.c	Fri May 28 10:22:01 1999
***************
*** 55,62 ****
  int
  keyboard()
  {
! 	char ch, *line;
! 	int linesz;
  	sigset_t set;
  
  	sigemptyset(&set);
--- 55,62 ----
  int
  keyboard()
  {
! 	char ch, rch, *line;
! 	int i, linesz;
  	sigset_t set;
  
  	sigemptyset(&set);
***************
*** 79,84 ****
--- 79,85 ----
  				clearerr(stdin);
  				continue;
  			}
+ 			rch = ch;
  			if (ch >= 'A' && ch <= 'Z')
  				ch += 'a' - 'A';
  			if (col == 0) {
***************
*** 124,138 ****
  				clrtoeol();
  				continue;
  			}
! 			if (isprint(ch) || ch == ' ') {
  				if (col < linesz) {
! 					line[col] = ch;
! 					mvaddch(CMDLINE, col, ch);
  					col++;
  				}
  			}
  		} while (col == 0 || (ch != '\r' && ch != '\n'));
  		line[col] = '\0';
  		sigprocmask(SIG_BLOCK, &set, NULL);
  		command(line + 1);
  		sigprocmask(SIG_UNBLOCK, &set, NULL);
--- 125,143 ----
  				clrtoeol();
  				continue;
  			}
! 			if (isprint(rch) || ch == ' ') {
  				if (col < linesz) {
! 					line[col] = rch;
! 					mvaddch(CMDLINE, col, rch);
  					col++;
  				}
  			}
  		} while (col == 0 || (ch != '\r' && ch != '\n'));
  		line[col] = '\0';
+ 		/* pass commands as lowercase */
+ 		for (i = 1; i < col && line[i] != ' '; i++)
+ 		    if (line[i] >= 'A' && line[i] <= 'Z')
+ 			line[i] += 'a' - 'A';
  		sigprocmask(SIG_BLOCK, &set, NULL);
  		command(line + 1);
  		sigprocmask(SIG_UNBLOCK, &set, NULL);


-- 
Geoff Wing   <gcw@pobox.com>     NEW>>>>Mobile : (Australia) 0413 431 874
Work URL: http://www.primenet.com.au/   Ego URL: http://pobox.com/~gcw/