int i, aout, didmmap;
int i, aout;
show_file(int count, int warn_fmt, const char *name, FILE *fp, off_t foff, union hdr *head){	u_long text, data, bss, total;	struct nlist *np;	Elf_Shdr *shdr;	off_t staboff;	int i, aout, didmmap;	aout = 0;	if (IS_ELF(head->elf) &&	    head->elf.e_ident[EI_CLASS] == ELF_TARG_CLASS &&	    head->elf.e_ident[EI_VERSION] == ELF_TARG_VER) {		elf_fix_header(&head->elf);		if ((shdr = malloc(head->elf.e_shentsize *		    head->elf.e_shnum)) == NULL) {			warn("%s: malloc shdr", name);			return (1);		}		if (fseeko(fp, foff + head->elf.e_shoff, SEEK_SET)) {			warn("%s: fseeko", name);			free(shdr);			return (1);		}		if (fread(shdr, head->elf.e_shentsize, head->elf.e_shnum,		    fp) != head->elf.e_shnum) {			warnx("%s: premature EOF", name);			free(shdr);			return(1);		}		elf_fix_shdrs(&head->elf, shdr);		if (issize) {			text = data = bss = 0;			for (i = 0; i < head->elf.e_shnum; i++) {				if (!(shdr[i].sh_flags & SHF_ALLOC))					;				else if (shdr[i].sh_flags & SHF_EXECINSTR ||				    !(shdr[i].sh_flags & SHF_WRITE))					text += shdr[i].sh_size;				else if (shdr[i].sh_type == SHT_NOBITS)					bss += shdr[i].sh_size;				else					data += shdr[i].sh_size;			}			free(shdr);		} else {			i = elf_symload(name, fp, foff, &head->elf, shdr);			free(shdr);			if (i)				return (i);		}	} else if (BAD_OBJECT(head->aout)) {		if (warn_fmt)			warnx("%s: bad format", name);		return (1);	} else do {		aout++;		fix_header_order(&head->aout);		if (issize) {			text = head->aout.a_text;			data = head->aout.a_data;			bss = head->aout.a_bss;			break;		}		/* stop if the object file contains no symbol table */		if (!head->aout.a_syms) {			warnx("%s: no name list", name);			return(1);		}		if (fseeko(fp, foff + N_SYMOFF(head->aout), SEEK_SET)) {			warn("%s", name);			return(1);		}		/* get memory for the symbol table */		if ((names = malloc(head->aout.a_syms)) == NULL) {			warn("%s: malloc names", name);			return (1);		}		nrawnames = head->aout.a_syms / sizeof(*names);		if ((snames = malloc(nrawnames * sizeof(struct nlist *))) == NULL) {			warn("%s: malloc snames", name);			free(names);			return (1);		}		if (fread(names, head->aout.a_syms, 1, fp) != 1) {			warnx("%s: cannot read symbol table", name);			free(snames);			free(names);			return(1);		}		fix_nlists_order(names, nrawnames, N_GETMID(head->aout));		staboff = ftello(fp);		/*		 * Following the symbol table comes the string table.		 * The first 4-byte-integer gives the total size of the		 * string table _including_ the size specification itself.		 */		if (fread(&stabsize, sizeof(stabsize), (size_t)1, fp) != 1) {			warnx("%s: cannot read stab size", name);			free(snames);			free(names);			return(1);		}		MMAP(stab, stabsize, PROT_READ, MAP_PRIVATE|MAP_FILE,		    fileno(fp), staboff);		if (stab == MAP_FAILED) {			free(snames);			free(names);			return (1);		}		stabsize -= 4;		/* we already have the size */	} while (0);	if (issize) {		static int first = 1;		if (first) {			first = 0;			printf("text\tdata\tbss\tdec\thex\n");		}		total = text + data + bss;		printf("%lu\t%lu\t%lu\t%lu\t%lx",		    text, data, bss, total, total);		if (count > 1)			(void)printf("\t%s", name);		total_text += text;		total_data += data;		total_bss += bss;		total_total += total;		printf("\n");		return (0);	}	/* else we are nm */	/*	 * it seems that string table is sequential	 * relative to the symbol table order	 */	if (sfunc == NULL && madvise(stab, stabsize, MADV_SEQUENTIAL)) {		warn("%s: madvise", name);		free(snames);		free(names);		MUNMAP(stab, stabsize);		return (1);	}	/*	 * fix up the symbol table and filter out unwanted entries	 *	 * common symbols are characterized by a n_type of N_UNDF and a	 * non-zero n_value -- change n_type to N_COMM for all such	 * symbols to make life easier later.	 *	 * filter out all entries which we don't want to print anyway	 */	for (np = names, i = nnames = 0; i < nrawnames; np++, i++) {		/*		 * make n_un.n_name a character pointer by adding the string		 * table's base to n_un.n_strx		 *		 * don't mess with zero offsets		 */		if (np->n_un.n_strx)			np->n_un.n_name = stab + np->n_un.n_strx;		else			np->n_un.n_name = "";		if (aout && SYMBOL_TYPE(np->n_type) == N_UNDF && np->n_value)			np->n_type = N_COMM | (np->n_type & N_EXT);		if (!print_all_symbols && IS_DEBUGGER_SYMBOL(np->n_type))			continue;		if (print_only_external_symbols && !IS_EXTERNAL(np->n_type))			continue;		if (print_only_undefined_symbols &&		    SYMBOL_TYPE(np->n_type) != N_UNDF)			continue;		snames[nnames++] = np;	}	/* sort the symbol table if applicable */	if (sfunc)		qsort(snames, (size_t)nnames, sizeof(*snames), sfunc);	if (count > 1)		(void)printf("\n%s:\n", name);	/* print out symbols */	for (i = 0; i < nnames; i++) {		if (show_extensions && snames[i] != names &&		    SYMBOL_TYPE((snames[i] -1)->n_type) == N_INDR)			continue;		print_symbol(name, snames[i], aout);	}	free(snames);	free(names);	MUNMAP(stab, stabsize);	return(0);}