Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1003/1

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Small fixes.
 [rsc] --rw-rw-r-- M 775368 glenda sys 5951 Oct  3 07:24 sys/lib/dist/cmd/bargraph.c
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:30,36 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:30,36
	  Point ptext;
	  vlong n, d;
	  int last;
	- int lastp;
	+ int lastp = -1;
	  int first = 1;
	  
	  char backup[80];
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:40,46 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:40,47
	  {
	  	int i, j;
	  	int p;
	- 	char buf[10], bar[100];
	+ 	char buf[200], bar[100], *s;
	+ 	static char lastbar[100];
	  
	  	if(n > d || n < 0 || d <= 0)
	  		return;
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:48,56 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:49,54
	  	i = (Dx(rbar)*n)/d;
	  	p = (n*100LL)/d;
	  
	- 	if(lastp == p && last == i)
	- 		return;
	- 
	  	if(textmode){
	  		bar[0] = '|';
	  		for(j=0; j<i; j++)
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:59,78 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:57,76
	  			bar[j+1] = '-';
	  		bar[61] = '|';
	  		bar[62] = ' ';
	- 		sprint(bar+63, "%3d%%", p);
	- 		if(first)
	- 			first = 0;
	- 		else{
	- 			for(i=0; i<strlen(bar); i++)
	- 				backup[i] = '\b';
	- 			write(1, backup, i);
	- 		}
	- 		write(1, bar, strlen(bar));
	- 		lastp = p;
	- 		last = i;
	+ 		sprint(bar+63, "%3d%% ", p);
	+ 		for(i=0; bar[i]==lastbar[i] && bar[i]; i++)
	+ 			;
	+ 		memset(buf, '\b', strlen(lastbar)-i);
	+ 		strcpy(buf+strlen(lastbar)-i, bar+i);
	+ 		if(buf[0])
	+ 			write(1, buf, strlen(buf));
	+ 		strcpy(lastbar, bar);
	  		return;
	  	}
	- 		
	+ 	
	+ 	if(lastp == p && last == i)
	+ 		return;
	+ 
	  	if(lastp != p){
	  		sprint(buf, "%d%%", p);
	  		
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:220,226 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:218,224
	  	size = seek(fd, 0, 2);
	  	v = malloc(size+1);
	  	if(v == 0){
	- 		fprint(2, "page: can't malloc: %r\n");
	+ 		fprint(2, "%s: can't malloc: %r\n", argv0);
	  		exits("no mem");
	  	}
	  	seek(fd, 0, 0);
	/n/sourcesdump/2005/1003/plan9/sys/lib/dist/cmd/bargraph.c:303,313 - 
	/n/sourcesdump/2005/1004/plan9/sys/lib/dist/cmd/bargraph.c:301,311
	  	if(fd == -1)
	  		fd=open("/mnt/term/dev/screen", OREAD);
	  	if(fd == -1){
	- 		fprint(2, "page: can't open /dev/screen: %r\n");
	+ 		fprint(2, "%s: can't open /dev/screen: %r\n", argv0);
	  		exits("window read");
	  	}
	  	if(read(fd, buf, sizeof buf) != sizeof buf){
	- 		fprint(2, "page: can't read /dev/screen: %r\n");
	+ 		fprint(2, "%s: can't read /dev/screen: %r\n", argv0);
	  		exits("screen read");
	  	}
	  	close(fd);


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.