Subject: bin/3075: Add -t (print totals) flags to size(1)
To: None <gnats-bugs@gnats.netbsd.org>
From: Ty Sarna <tsarna@endicor.com>
List: netbsd-bugs
Date: 12/31/1996 14:51:37
>Number:         3075
>Category:       bin
>Synopsis:       Add -t (print totals) flags to size(1)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 31 13:05:01 1996
>Last-Modified:
>Originator:     Ty Sarna
>Organization:
	Endicor Technologies, Inc., San Antonio, Texas
>Release:        NetBSD-current mid-November
>Environment:

System: NetBSD lotharon.endicor.com 1.2B NetBSD 1.2B (LOTHARON) #1:
Thu Dec 12 12:09:19 CST 1996
tsarna@lotharon.endicor.com:/usr/src/sys/arch/sun3/compile/LOTHARON sun3

>Description:
	I've found it useful to be able to get the total sizes of the
	members of an archive or set of object files. I used to use an
	awk script, but size(1) can calculate totals itself quite easily.
	An included patch adds a -t flag that causes it to do just this.
>How-To-Repeat:
	"man size", notice no option to print totals.
>Fix:
	Apply the following patch, which revises size.1 and size.c
	to implement a new -t flag. It also removes whitespace from a
	line that contains only whitespace.

*** size.1.orig	Tue Dec 31 14:40:02 1996
--- size.1	Tue Dec 31 14:42:45 1996
***************
*** 41,46 ****
--- 41,47 ----
  .Nd display object file segment sizes (text, data and bss)
  .Sh SYNOPSIS
  .Nm size
+ .Op Fl t
  .Op Fl w
  .Ar
  .Sh DESCRIPTION
***************
*** 59,64 ****
--- 60,68 ----
  attempts to report on the file
  .Pa a.out .
  .Bl -tag -width flag
+ .It Fl t
+ At the end of the output print a total of the
+ sizes of all the object files processed.
  .It Fl w
  Warn about non-object archive members.
  Normally,
*** size.c.orig	Tue Dec 31 14:27:02 1996
--- size.c	Tue Dec 31 14:38:52 1996
***************
*** 56,62 ****
--- 56,64 ----
  #include <stdio.h>
  #include <err.h>
  
+ unsigned long total_text, total_data, total_bss, total_total;
  int ignore_bad_archive_entries = 1;
+ int print_totals = 0;
  
  int	process_file __P((int, char *));
  int	show_archive __P((int, char *, FILE *));
***************
*** 72,82 ****
  {
  	int ch, eval;
  
! 	while ((ch = getopt(argc, argv, "w")) != EOF)
  		switch(ch) {
  		case 'w':
  			ignore_bad_archive_entries = 0;
  			break;
  		case '?':
  		default:
  			usage();
--- 74,87 ----
  {
  	int ch, eval;
  
! 	while ((ch = getopt(argc, argv, "wt")) != EOF)
  		switch(ch) {
  		case 'w':
  			ignore_bad_archive_entries = 0;
  			break;
+ 		case 't':
+ 			print_totals = 1;
+ 			break;
  		case '?':
  		default:
  			usage();
***************
*** 91,96 ****
--- 96,106 ----
  		} while (*++argv);
  	else
  		eval |= process_file(1, "a.out");
+ 
+ 	if (print_totals)
+ 		(void)printf("\n%lu\t%lu\t%lu\t%lu\t%lx\tTOTAL\n",
+ 		    total_text, total_data, total_bss,
+ 		    total_total, total_total);
  	exit(eval);
  }
  
***************
*** 108,114 ****
  	FILE *fp;
  	int retval;
  	char magic[SARMAG];
!     
  	if (!(fp = fopen(fname, "r"))) {
  		warnx("cannot read %s", fname);
  		return(1);
--- 118,124 ----
  	FILE *fp;
  	int retval;
  	char magic[SARMAG];
! 
  	if (!(fp = fopen(fname, "r"))) {
  		warnx("cannot read %s", fname);
  		return(1);
***************
*** 282,287 ****
--- 292,303 ----
  	    head.a_bss, total, total);
  	if (count > 1)
  		(void)printf("\t%s", name);
+ 
+ 	total_text += head.a_text;
+ 	total_data += head.a_data;
+ 	total_bss += head.a_bss;
+ 	total_total += total;
+ 
  	(void)printf("\n");
  	return (0);
  }

>Audit-Trail:
>Unformatted: