Home | History | Annotate | Line # | Download | only in common
file.c revision 1.2
      1 /*	$NetBSD: file.c,v 1.2 1997/03/25 03:07:12 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995-96 Mats O Jansson.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Mats O Jansson.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #ifndef LINT
     33 static char rcsid[] = "$NetBSD: file.c,v 1.2 1997/03/25 03:07:12 thorpej Exp $";
     34 #endif
     35 
     36 #include "os.h"
     37 #include "common/common.h"
     38 #include "common/mopdef.h"
     39 
     40 #ifndef NOAOUT
     41 #if defined(__NetBSD__) || defined(__OpenBSD__)
     42 #include <sys/exec_aout.h>
     43 #endif
     44 #if defined(__bsdi__)
     45 #define NOAOUT
     46 #endif
     47 #if defined(__FreeBSD__)
     48 #include <sys/imgact_aout.h>
     49 #endif
     50 #if !defined(MID_VAX)
     51 #define MID_VAX 140
     52 #endif
     53 #endif
     54 
     55 void
     56 mopFilePutLX(buf, index, value, cnt)
     57 	u_char	*buf;
     58 	int	index, cnt;
     59 	u_long	value;
     60 {
     61 	int i;
     62 	for (i = 0; i < cnt; i++) {
     63 		buf[index+i] = value % 256;
     64 		value = value / 256;
     65 	}
     66 }
     67 
     68 void
     69 mopFilePutBX(buf, index, value, cnt)
     70 	u_char	*buf;
     71 	int	index, cnt;
     72 	u_long	value;
     73 {
     74 	int i;
     75 	for (i = 0; i < cnt; i++) {
     76 		buf[index+cnt-1-i] = value % 256;
     77 		value = value / 256;
     78 	}
     79 }
     80 
     81 u_long
     82 mopFileGetLX(buf, index, cnt)
     83 	u_char	*buf;
     84 	int	index, cnt;
     85 {
     86 	u_long ret = 0;
     87 	int i;
     88 
     89 	for (i = 0; i < cnt; i++) {
     90 		ret = ret*256 + buf[index+cnt-1-i];
     91 	}
     92 
     93 	return(ret);
     94 }
     95 
     96 u_long
     97 mopFileGetBX(buf, index, cnt)
     98 	u_char	*buf;
     99 	int	index, cnt;
    100 {
    101 	u_long ret = 0;
    102 	int i;
    103 
    104 	for (i = 0; i < cnt; i++) {
    105 		ret = ret*256 + buf[index+i];
    106 	}
    107 
    108 	return(ret);
    109 }
    110 
    111 void
    112 mopFileSwapX(buf, index, cnt)
    113 	u_char	*buf;
    114 	int	index, cnt;
    115 {
    116 	int i;
    117 	u_char c;
    118 
    119 	for (i = 0; i < (cnt / 2); i++) {
    120 		c = buf[index+i];
    121 		buf[index+i] = buf[index+cnt-1-i];
    122 		buf[index+cnt-1-i] = c;
    123 	}
    124 
    125 }
    126 
    127 int
    128 CheckMopFile(fd)
    129 	int	fd;
    130 {
    131 	u_char	header[512];
    132 	short	image_type;
    133 
    134 	if (read(fd, header, 512) != 512)
    135 		return(-1);
    136 
    137 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    138 
    139 	image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
    140 			       header[IHD_W_ALIAS]);
    141 
    142 	switch(image_type) {
    143 		case IHD_C_NATIVE:		/* Native mode image (VAX)   */
    144 		case IHD_C_RSX:			/* RSX image produced by TKB */
    145 		case IHD_C_BPA:			/* BASIC plus analog         */
    146 		case IHD_C_ALIAS:		/* Alias		     */
    147 		case IHD_C_CLI:			/* Image is CLI		     */
    148 		case IHD_C_PMAX:		/* PMAX system image	     */
    149 		case IHD_C_ALPHA:		/* ALPHA system image	     */
    150 			break;
    151 		default:
    152 			return(-1);
    153 	}
    154 
    155 	return(0);
    156 }
    157 
    158 int
    159 GetMopFileInfo(fd, load, xfr)
    160 	int	fd;
    161 	u_long	*load, *xfr;
    162 {
    163 	u_char	header[512];
    164 	short	image_type;
    165 	u_long	load_addr, xfr_addr, isd, iha, hbcnt, isize;
    166 
    167 	if (read(fd, header, 512) != 512)
    168 		return(-1);
    169 
    170 	image_type = (u_short)(header[IHD_W_ALIAS+1]*256 +
    171 			       header[IHD_W_ALIAS]);
    172 
    173 	switch(image_type) {
    174 		case IHD_C_NATIVE:		/* Native mode image (VAX)   */
    175 			isd = (header[IHD_W_SIZE+1]*256 +
    176 			       header[IHD_W_SIZE]);
    177 			iha = (header[IHD_W_ACTIVOFF+1]*256 +
    178 			       header[IHD_W_ACTIVOFF]);
    179 			hbcnt = (header[IHD_B_HDRBLKCNT]);
    180 			isize = (header[isd+ISD_W_PAGCNT+1]*256 +
    181 				 header[isd+ISD_W_PAGCNT]) * 512;
    182 			load_addr = ((header[isd+ISD_V_VPN+1]*256 +
    183 				      header[isd+ISD_V_VPN]) & ISD_M_VPN)
    184 					* 512;
    185 			xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
    186 				    header[iha+IHA_L_TFRADR1+2]*0x10000 +
    187 				    header[iha+IHA_L_TFRADR1+1]*0x100 +
    188 				    header[iha+IHA_L_TFRADR1]) & 0x7fffffff;
    189 #ifdef INFO
    190 			printf("Native Image (VAX)\n");
    191 			printf("Header Block Count: %d\n",hbcnt);
    192 			printf("Image Size:         %08x\n",isize);
    193 			printf("Load Address:       %08x\n",load_addr);
    194 			printf("Transfer Address:   %08x\n",xfr_addr);
    195 #endif
    196 			break;
    197 		case IHD_C_RSX:			/* RSX image produced by TKB */
    198 			hbcnt = header[L_BBLK+1]*256 + header[L_BBLK];
    199 			isize = (header[L_BLDZ+1]*256 + header[L_BLDZ]) * 64;
    200 			load_addr = header[L_BSA+1]*256 + header[L_BSA];
    201 			xfr_addr  = header[L_BXFR+1]*256 + header[L_BXFR];
    202 #ifdef INFO
    203 			printf("RSX Image\n");
    204 			printf("Header Block Count: %d\n",hbcnt);
    205 			printf("Image Size:         %08x\n",isize);
    206 			printf("Load Address:       %08x\n",load_addr);
    207 			printf("Transfer Address:   %08x\n",xfr_addr);
    208 #endif
    209 			break;
    210 		case IHD_C_BPA:			/* BASIC plus analog         */
    211 #ifdef INFO
    212 			printf("BASIC-Plus Image, not supported\n");
    213 #endif
    214 			return(-1);
    215 			break;
    216 		case IHD_C_ALIAS:		/* Alias		     */
    217 #ifdef INFO
    218 			printf("Alias, not supported\n");
    219 #endif
    220 			return(-1);
    221 			break;
    222 		case IHD_C_CLI:			/* Image is CLI		     */
    223 #ifdef INFO
    224 			printf("CLI, not supported\n");
    225 #endif
    226 			return(-1);
    227 			break;
    228 		case IHD_C_PMAX:		/* PMAX system image	     */
    229 			isd = (header[IHD_W_SIZE+1]*256 +
    230 			       header[IHD_W_SIZE]);
    231 			iha = (header[IHD_W_ACTIVOFF+1]*256 +
    232 			       header[IHD_W_ACTIVOFF]);
    233 			hbcnt = (header[IHD_B_HDRBLKCNT]);
    234 			isize = (header[isd+ISD_W_PAGCNT+1]*256 +
    235 				 header[isd+ISD_W_PAGCNT]) * 512;
    236 			load_addr = (header[isd+ISD_V_VPN+1]*256 +
    237 				     header[isd+ISD_V_VPN]) * 512;
    238 			xfr_addr = (header[iha+IHA_L_TFRADR1+3]*0x1000000 +
    239 				    header[iha+IHA_L_TFRADR1+2]*0x10000 +
    240 				    header[iha+IHA_L_TFRADR1+1]*0x100 +
    241 				    header[iha+IHA_L_TFRADR1]);
    242 #ifdef INFO
    243 			printf("PMAX Image \n");
    244 			printf("Header Block Count: %d\n",hbcnt);
    245 			printf("Image Size:         %08x\n",isize);
    246 			printf("Load Address:       %08x\n",load_addr);
    247 			printf("Transfer Address:   %08x\n",xfr_addr);
    248 #endif
    249 			break;
    250 		case IHD_C_ALPHA:		/* ALPHA system image	     */
    251 			isd = (header[EIHD_L_ISDOFF+3]*0x1000000 +
    252 			       header[EIHD_L_ISDOFF+2]*0x10000 +
    253 			       header[EIHD_L_ISDOFF+1]*0x100 +
    254 			       header[EIHD_L_ISDOFF]);
    255 			hbcnt = (header[EIHD_L_HDRBLKCNT+3]*0x1000000 +
    256 				 header[EIHD_L_HDRBLKCNT+2]*0x10000 +
    257 				 header[EIHD_L_HDRBLKCNT+1]*0x100 +
    258 				 header[EIHD_L_HDRBLKCNT]);
    259 			isize = (header[isd+EISD_L_SECSIZE+3]*0x1000000 +
    260 				 header[isd+EISD_L_SECSIZE+2]*0x10000 +
    261 				 header[isd+EISD_L_SECSIZE+1]*0x100 +
    262 				 header[isd+EISD_L_SECSIZE]);
    263 			load_addr = 0;
    264 			xfr_addr = 0;
    265 #ifdef INFO
    266 			printf("Alpha Image \n");
    267 			printf("Header Block Count: %d\n",hbcnt);
    268 			printf("Image Size:         %08x\n",isize);
    269 			printf("Load Address:       %08x\n",load_addr);
    270 			printf("Transfer Address:   %08x\n",xfr_addr);
    271 #endif
    272 			break;
    273 		default:
    274 #ifdef INFO
    275 			printf("Unknown Image (%d)\n",image_type);
    276 #endif
    277 			return(-1);
    278 	}
    279 
    280 	if (load != NULL) {
    281 		*load = load_addr;
    282 	}
    283 
    284 	if (xfr != NULL) {
    285 		*xfr  = xfr_addr;
    286 	}
    287 
    288 	return(0);
    289 }
    290 
    291 #ifndef NOAOUT
    292 int
    293 getMID(old_mid,new_mid)
    294 	int	old_mid, new_mid;
    295 {
    296 	int	mid;
    297 
    298 	mid = old_mid;
    299 
    300 	switch (new_mid) {
    301 	case MID_I386:
    302 		mid = MID_I386;
    303 		break;
    304 #ifdef MID_M68K
    305 	case MID_M68K:
    306 		mid = MID_M68K;
    307 		break;
    308 #endif
    309 #ifdef MID_M68K4K
    310 	case MID_M68K4K:
    311 		mid = MID_M68K4K;
    312 		break;
    313 #endif
    314 #ifdef MID_NS32532
    315 	case MID_NS32532:
    316 		mid = MID_NS32532;
    317 		break;
    318 #endif
    319 /*###323 [cc] for each function it appears in.)%%%*/
    320 /*###323 [cc] (Each undeclared identifier is reported only once%%%*/
    321 /*###323 [cc] `MID_SPARC' undeclared (first use this function)%%%*/
    322 	case MID_SPARC:
    323 		mid = MID_SPARC;
    324 		break;
    325 #ifdef MID_PMAX
    326 	case MID_PMAX:
    327 		mid = MID_PMAX;
    328 		break;
    329 #endif
    330 #ifdef MID_VAX
    331 	case MID_VAX:
    332 		mid = MID_VAX;
    333 		break;
    334 #endif
    335 #ifdef MID_ALPHA
    336 	case MID_ALPHA:
    337 		mid = MID_ALPHA;
    338 		break;
    339 #endif
    340 #ifdef MID_MIPS
    341 	case MID_MIPS:
    342 		mid = MID_MIPS;
    343 		break;
    344 #endif
    345 #ifdef MID_ARM6
    346 	case MID_ARM6:
    347 		mid = MID_ARM6;
    348 		break;
    349 #endif
    350 	default:
    351 /*###352 [cc] syntax error before `}'%%%*/
    352 	}
    353 
    354 	return(mid);
    355 }
    356 
    357 int
    358 getCLBYTES(mid)
    359 	int	mid;
    360 {
    361 	int	clbytes;
    362 
    363 	switch (mid) {
    364 #ifdef MID_VAX
    365 	case MID_VAX:
    366 		clbytes = 1024;
    367 		break;
    368 #endif
    369 	case MID_I386:
    370 #ifdef MID_M68K4K
    371 	case MID_M68K4K:
    372 #endif
    373 #ifdef MID_NS32532
    374 	case MID_NS32532:
    375 #endif
    376 	case MID_SPARC:				/* It might be 8192 */
    377 #ifdef MID_PMAX
    378 	case MID_PMAX:
    379 #endif
    380 #ifdef MID_MIPS
    381 	case MID_MIPS:
    382 #endif
    383 #ifdef MID_ARM6
    384 	case MID_ARM6:
    385 #endif
    386 		clbytes = 4096;
    387 		break;
    388 #ifdef MID_M68K
    389 	case MID_M68K:
    390 #endif
    391 #ifdef MID_ALPHA
    392 	case MID_ALPHA:
    393 #endif
    394 #if defined(MID_M68K) || defined(MID_ALPHA)
    395 		clbytes = 8192;
    396 		break;
    397 #endif
    398 	default:
    399 		clbytes = 0;
    400 	}
    401 
    402 	return(clbytes);
    403 }
    404 #endif
    405 
    406 /*###406 [cc] syntax error before `int'%%%*/
    407 int
    408 CheckAOutFile(fd)
    409 	int	fd;
    410 {
    411 #ifdef NOAOUT
    412 	return(-1);
    413 #else
    414 	struct exec ex, ex_swap;
    415 	int	mid = -1;
    416 
    417 /*###416 [cc] `fd' undeclared (first use this function)%%%*/
    418 	if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
    419 		return(-1);
    420 
    421 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    422 
    423 	if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
    424 		return(-1);
    425 
    426 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    427 
    428 	mid = getMID(mid, N_GETMID (ex));
    429 
    430 	if (mid == -1) {
    431 		mid = getMID(mid, N_GETMID (ex_swap));
    432 	}
    433 
    434 	if (mid != -1) {
    435 		return(0);
    436 	} else {
    437 		return(-1);
    438 	}
    439 #endif NOAOUT
    440 }
    441 
    442 /*###440 [cc] syntax error before `int'%%%*/
    443 int
    444 GetAOutFileInfo(fd, load, xfr, a_text, a_text_fill,
    445 		a_data, a_data_fill, a_bss, a_bss_fill, aout)
    446 	int	fd, *aout;
    447 	u_long	*load, *xfr, *a_text, *a_text_fill;
    448 	u_long	*a_data, *a_data_fill, *a_bss, *a_bss_fill;
    449 {
    450 #ifdef NOAOUT
    451 	return(-1);
    452 #else
    453 	struct exec ex, ex_swap;
    454 	int	mid = -1;
    455 	u_long	magic, clbytes, clofset;
    456 
    457 	if (read(fd, (char *)&ex, sizeof(ex)) != sizeof(ex))
    458 		return(-1);
    459 
    460 	(void)lseek(fd, (off_t) 0, SEEK_SET);
    461 
    462 	if (read(fd, (char *)&ex_swap, sizeof(ex_swap)) != sizeof(ex_swap))
    463 		return(-1);
    464 
    465 	mopFileSwapX((u_char *)&ex_swap, 0, 4);
    466 
    467 	mid = getMID(mid, N_GETMID (ex));
    468 
    469 	if (mid == -1) {
    470 		mid = getMID(mid, N_GETMID (ex_swap));
    471 		if (mid != -1) {
    472 			mopFileSwapX((u_char *)&ex, 0, 4);
    473 		}
    474 	}
    475 
    476 	if (mid == -1) {
    477 		return(-1);
    478 	}
    479 
    480 	if (N_BADMAG (ex)) {
    481 		return(-1);
    482 	}
    483 
    484 	switch (mid) {
    485 	case MID_I386:
    486 #ifdef MID_NS32532
    487 	case MID_NS32532:
    488 #endif
    489 #ifdef MID_PMAX
    490 	case MID_PMAX:
    491 #endif
    492 #ifdef MID_VAX
    493 	case MID_VAX:
    494 #endif
    495 #ifdef MID_ALPHA
    496 	case MID_ALPHA:
    497 #endif
    498 #ifdef MID_ARM6
    499 	case MID_ARM6:
    500 #endif
    501 		ex.a_text  = mopFileGetLX((u_char *)&ex_swap,  4, 4);
    502 		ex.a_data  = mopFileGetLX((u_char *)&ex_swap,  8, 4);
    503 		ex.a_bss   = mopFileGetLX((u_char *)&ex_swap, 12, 4);
    504 		ex.a_syms  = mopFileGetLX((u_char *)&ex_swap, 16, 4);
    505 		ex.a_entry = mopFileGetLX((u_char *)&ex_swap, 20, 4);
    506 		ex.a_trsize= mopFileGetLX((u_char *)&ex_swap, 24, 4);
    507 		ex.a_drsize= mopFileGetLX((u_char *)&ex_swap, 28, 4);
    508 		break;
    509 #ifdef MID_M68K
    510 	case MID_M68K:
    511 #endif
    512 #ifdef MID_M68K4K
    513 	case MID_M68K4K:
    514 #endif
    515 	case MID_SPARC:
    516 #ifdef MID_MIPS
    517 	case MID_MIPS:
    518 #endif
    519 		ex.a_text  = mopFileGetBX((u_char *)&ex_swap,  4, 4);
    520 		ex.a_data  = mopFileGetBX((u_char *)&ex_swap,  8, 4);
    521 		ex.a_bss   = mopFileGetBX((u_char *)&ex_swap, 12, 4);
    522 		ex.a_syms  = mopFileGetBX((u_char *)&ex_swap, 16, 4);
    523 		ex.a_entry = mopFileGetBX((u_char *)&ex_swap, 20, 4);
    524 		ex.a_trsize= mopFileGetBX((u_char *)&ex_swap, 24, 4);
    525 		ex.a_drsize= mopFileGetBX((u_char *)&ex_swap, 28, 4);
    526 		break;
    527 	default:
    528 /*###525 [cc] syntax error before `}'%%%*/
    529 	}
    530 
    531 #ifdef INFO
    532 	printf("a.out image (");
    533 	switch (N_GETMID (ex)) {
    534 	case MID_I386:
    535 		printf("i386");
    536 		break;
    537 #ifdef MID_M68K
    538 	case MID_M68K:
    539 		printf("m68k");
    540 		break;
    541 #endif
    542 #ifdef MID_M68K4K
    543 	case MID_M68K4K:
    544 		printf("m68k 4k");
    545 		break;
    546 #endif
    547 #ifdef MID_NS32532
    548 	case MID_NS32532:
    549 		printf("pc532");
    550 		break;
    551 #endif
    552 	case MID_SPARC:
    553 		printf("sparc");
    554 		break;
    555 #ifdef MID_PMAX
    556 	case MID_PMAX:
    557 		printf("pmax");
    558 		break;
    559 #endif
    560 #ifdef MID_VAX
    561 	case MID_VAX:
    562 		printf("vax");
    563 		break;
    564 #endif
    565 #ifdef MID_ALPHA
    566 	case MID_ALPHA:
    567 		printf("alpha");
    568 		break;
    569 #endif
    570 #ifdef MID_MIPS
    571 	case MID_MIPS:
    572 		printf("mips");
    573 		break;
    574 #endif
    575 #ifdef MID_ARM6
    576 	case MID_ARM6:
    577 		printf("arm32");
    578 		break;
    579 #endif
    580 	default:
    581 	}
    582 	printf(") Magic: ");
    583 	switch (N_GETMAGIC (ex)) {
    584 	case OMAGIC:
    585 		printf("OMAGIC");
    586 		break;
    587 	case NMAGIC:
    588 		printf("NMAGIC");
    589 		break;
    590 	case ZMAGIC:
    591 		printf("ZMAGIC");
    592 		break;
    593 	case QMAGIC:
    594 		printf("QMAGIC");
    595 		break;
    596 	default:
    597 		printf("Unknown %d",N_GETMAGIC (ex));
    598 	}
    599 	printf("\n");
    600 	printf("Size of text:       %08x\n",ex.a_text);
    601 	printf("Size of data:       %08x\n",ex.a_data);
    602 	printf("Size of bss:        %08x\n",ex.a_bss);
    603 	printf("Size of symbol tab: %08x\n",ex.a_syms);
    604 	printf("Transfer Address:   %08x\n",ex.a_entry);
    605 	printf("Size of reloc text: %08x\n",ex.a_trsize);
    606 	printf("Size of reloc data: %08x\n",ex.a_drsize);
    607 #endif
    608 	magic = N_GETMAGIC (ex);
    609 	clbytes = getCLBYTES(mid);
    610 	clofset = clbytes - 1;
    611 
    612 /*###608 [cc] `load' undeclared (first use this function)%%%*/
    613 	if (load != NULL) {
    614 		*load   = 0;
    615 	}
    616 
    617 /*###612 [cc] `xfr' undeclared (first use this function)%%%*/
    618 	if (xfr != NULL) {
    619 		*xfr    = ex.a_entry;
    620 	}
    621 
    622 /*###616 [cc] `a_text' undeclared (first use this function)%%%*/
    623 	if (a_text != NULL) {
    624 		*a_text = ex.a_text;
    625 	}
    626 
    627 /*###620 [cc] `a_text_fill' undeclared (first use this function)%%%*/
    628 	if (a_text_fill != NULL) {
    629 		if (magic == ZMAGIC || magic == NMAGIC) {
    630 			*a_text_fill = clbytes - (ex.a_text & clofset);
    631 			if (*a_text_fill == clbytes) {
    632 				*a_text_fill = 0;
    633 			}
    634 		} else {
    635 			*a_text_fill = 0;
    636 	        }
    637 	}
    638 
    639 /*###631 [cc] `a_data' undeclared (first use this function)%%%*/
    640 	if (a_data != NULL) {
    641 		*a_data = ex.a_data;
    642 	}
    643 
    644 /*###635 [cc] `a_data_fill' undeclared (first use this function)%%%*/
    645 	if (a_data_fill != NULL) {
    646 		if (magic == ZMAGIC || magic == NMAGIC) {
    647 			*a_data_fill = clbytes - (ex.a_data & clofset);
    648 			if (*a_data_fill == clbytes) {
    649 				*a_data_fill = 0;
    650 			}
    651 		} else {
    652 			*a_data_fill = 0;
    653 	        }
    654 	}
    655 
    656 /*###646 [cc] `a_bss' undeclared (first use this function)%%%*/
    657 	if (a_bss != NULL) {
    658 		*a_bss  = ex.a_bss;
    659 	}
    660 
    661 /*###650 [cc] `a_bss_fill' undeclared (first use this function)%%%*/
    662 	if (a_bss_fill != NULL) {
    663 		if (magic == ZMAGIC || magic == NMAGIC) {
    664 			*a_bss_fill = clbytes - (ex.a_bss & clofset);
    665 			if (*a_bss_fill == clbytes) {
    666 				*a_bss_fill = 0;
    667 			}
    668 		} else {
    669 			*a_bss_fill = clbytes -
    670 				((ex.a_text+ex.a_data+ex.a_bss) & clofset);
    671 			if (*a_text_fill == clbytes) {
    672 				*a_text_fill = 0;
    673 			}
    674 	        }
    675 	}
    676 
    677 /*###665 [cc] `aout' undeclared (first use this function)%%%*/
    678 	if (aout != NULL) {
    679 		*aout = mid;
    680 	}
    681 
    682 	return(0);
    683 #endif NOAOUT
    684 }
    685 
    686 /*###673 [cc] syntax error before `int'%%%*/
    687 int
    688 GetFileInfo(fd, load, xfr, aout,
    689 	    a_text, a_text_fill, a_data, a_data_fill, a_bss, a_bss_fill)
    690 	int	fd, *aout;
    691 	u_long	*load, *xfr, *a_text, *a_text_fill;
    692 	u_long	*a_data, *a_data_fill, *a_bss, *a_bss_fill;
    693 {
    694 	int	err;
    695 
    696 	err = CheckAOutFile(fd);
    697 
    698 	if (err == 0) {
    699 		err = GetAOutFileInfo(fd, load, xfr,
    700 				      a_text, a_text_fill,
    701 				      a_data, a_data_fill,
    702 				      a_bss, a_bss_fill,
    703 				      aout);
    704 		if (err != 0) {
    705 			return(-1);
    706 		}
    707 	} else {
    708 		err = CheckMopFile(fd);
    709 
    710 		if (err == 0) {
    711 			err = GetMopFileInfo(fd, load, xfr);
    712 			if (err != 0) {
    713 				return(-1);
    714 			}
    715 			*aout = -1;
    716 		} else {
    717 			return(-1);
    718 		}
    719 	}
    720 
    721 	return(0);
    722 }
    723 
    724 ssize_t
    725 /*###711 [cc] syntax error before `mopFileRead'%%%*/
    726 mopFileRead(dlslot, buf)
    727 	struct dllist *dlslot;
    728 	u_char	*buf;
    729 {
    730 	ssize_t len, outlen;
    731 	int	bsz;
    732 	long	pos, notdone, total;
    733 
    734 /*###719 [cc] `dlslot' undeclared (first use this function)%%%*/
    735 	if (dlslot->aout == -1) {
    736 /*###720 [cc] `buf' undeclared (first use this function)%%%*/
    737 		len = read(dlslot->ldfd,buf,dlslot->dl_bsz);
    738 	} else {
    739 		bsz = dlslot->dl_bsz;
    740 		pos = dlslot->a_lseek;
    741 		len = 0;
    742 
    743 		total = dlslot->a_text;
    744 
    745 		if (pos < total) {
    746 			notdone = total - pos;
    747 			if (notdone <= bsz) {
    748 /*###731 [cc] subscripted value is neither array nor pointer%%%*/
    749 				outlen = read(dlslot->ldfd,&buf[len],notdone);
    750 			} else {
    751 /*###733 [cc] subscripted value is neither array nor pointer%%%*/
    752 				outlen = read(dlslot->ldfd,&buf[len],bsz);
    753 			}
    754 			len = len + outlen;
    755 			pos = pos + outlen;
    756 			bsz = bsz - outlen;
    757 		}
    758 
    759 		total = total + dlslot->a_text_fill;
    760 
    761 		if ((bsz > 0) && (pos < total)) {
    762 			notdone = total - pos;
    763 			if (notdone <= bsz) {
    764 				outlen = notdone;
    765 			} else {
    766 				outlen = bsz;
    767 			}
    768 /*###749 [cc] subscripted value is neither array nor pointer%%%*/
    769 			bzero(&buf[len],outlen);
    770 			len = len + outlen;
    771 			pos = pos + outlen;
    772 			bsz = bsz - outlen;
    773 		}
    774 
    775 		total = total + dlslot->a_data;
    776 
    777 		if ((bsz > 0) && (pos < total)) {
    778 			notdone = total - pos;
    779 			if (notdone <= bsz) {
    780 /*###760 [cc] subscripted value is neither array nor pointer%%%*/
    781 				outlen = read(dlslot->ldfd,&buf[len],notdone);
    782 			} else {
    783 /*###762 [cc] subscripted value is neither array nor pointer%%%*/
    784 				outlen = read(dlslot->ldfd,&buf[len],bsz);
    785 			}
    786 			len = len + outlen;
    787 			pos = pos + outlen;
    788 			bsz = bsz - outlen;
    789 		}
    790 
    791 		total = total + dlslot->a_data_fill;
    792 
    793 		if ((bsz > 0) && (pos < total)) {
    794 			notdone = total - pos;
    795 			if (notdone <= bsz) {
    796 				outlen = notdone;
    797 			} else {
    798 				outlen = bsz;
    799 			}
    800 /*###778 [cc] subscripted value is neither array nor pointer%%%*/
    801 			bzero(&buf[len],outlen);
    802 			len = len + outlen;
    803 			pos = pos + outlen;
    804 			bsz = bsz - outlen;
    805 		}
    806 
    807 		total = total + dlslot->a_bss;
    808 
    809 		if ((bsz > 0) && (pos < total)) {
    810 			notdone = total - pos;
    811 			if (notdone <= bsz) {
    812 				outlen = notdone;
    813 			} else {
    814 				outlen = bsz;
    815 			}
    816 /*###793 [cc] subscripted value is neither array nor pointer%%%*/
    817 			bzero(&buf[len],outlen);
    818 			len = len + outlen;
    819 			pos = pos + outlen;
    820 			bsz = bsz - outlen;
    821 		}
    822 
    823 		total = total + dlslot->a_bss_fill;
    824 
    825 		if ((bsz > 0) && (pos < total)) {
    826 			notdone = total - pos;
    827 			if (notdone <= bsz) {
    828 				outlen = notdone;
    829 			} else {
    830 				outlen = bsz;
    831 			}
    832 /*###808 [cc] subscripted value is neither array nor pointer%%%*/
    833 			bzero(&buf[len],outlen);
    834 			len = len + outlen;
    835 			pos = pos + outlen;
    836 			bsz = bsz - outlen;
    837 		}
    838 
    839 		dlslot->a_lseek = pos;
    840 
    841 	}
    842 
    843 	return(len);
    844 }
    845 /*###820 [cc] syntax error at end of input%%%*/
    846