/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred."
 *
 */
/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

/*
 * Copyright  (c) 1985 AT&T
 *	All Rights Reserved
 */

#ident	"$Header: obj_to_par.c 1.2 89/10/10 $@(#)vm.oh:src/oh/obj_to_par.c	1.2"

#include <stdio.h>
#include <string.h>
#include "but.h"
#include "tsys.h"
#include "typetab.h"
#include "ifuncdefs.h"
#include "partabdefs.h"
#include "optabdefs.h"

/* Obj_to_parts should be used instead of obj_to_opt in those executables
 * that do not need access to the object operations table.  It only
 * reads the global flags and parts information for an object.
 */

/* The No_operations flag is set to TRUE if the externally read object
 * has not had its operations read.
 */
bool No_operations;

struct opt_entry *
obj_to_parts(objtype)
char *objtype;
{
	register int i;
	FILE *fp;
	extern struct opt_entry Partab[MAX_TYPES];

	for (i = 0; i < MAX_TYPES && Partab[i].objtype; i++) {
		if (strcmp(objtype, Partab[i].objtype) == 0 )
			return(Partab + i);
	}

	/* read in the external object table for this object, but
	 * only read in the parts information.
	 */

	if ((fp = fopen(externoot(objtype), "r")) == NULL)
		return(NULL);

	if (read_parts(fp, objtype) == O_FAIL) {
#ifdef _DEBUG
		_debug(stderr, "External Object not found\n");
#endif
		fclose(fp);
		return(NULL);
	} else {
#ifdef _DEBUG
		_debug(stderr, "External Object %s found\n", objtype);
#endif
		No_operations = TRUE;
		fclose(fp);
		return(Partab + MAX_TYPES - 1);
	}
}
