:template
/* # @(#) /44 1.7 12/19/95 14:48:55 [7/30/96 15:08:20] */

/*
 *   COMPONENT_NAME: some
 *
 *   ORIGINS: 27
 *
 *
 *   10H9767, 25H7912  (C) COPYRIGHT International Business Machines Corp. 1992,1996 
 *   All Rights Reserved
 *   Licensed Materials - Property of IBM
 *   US Government Users Restricted Rights - Use, duplication or
 *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

/*
 *         File:    emit<classSourceFileStem>.<cppext>
 *       Author:    SOMObjects Emitter Framework
 *     Contents:    Generic framework emitter for <className>.
 *         Date:    <timeStamp>.
 */

#include \<scentry.xh\>
#include \<scmodule.xh\>
#include \<emitlib.h\>
#include "<classSourceFileStem>.xh"

#define SYMBOLS_FILE   "<classSourceFileStem>.efw"

SOMEXTERN FILE *emit(char *file, Entry * cls, Stab * stab)
{
    FILE *fp;
    FILE *deffile;
    SOMTClassEntryC *oCls;
    SOMTModuleEntryC *mod;
    <className> *emitter;
    SOMTTemplateOutputC *t;

    /* if this is a class, rather than a module: */
    if (cls->type == SOMTClassE) {

        fp = somtopenEmitFile(file, "<classSourceFileStem>");
        oCls = (SOMTClassEntryC *) somtGetObjectWrapper(cls);
        emitter = new <className>();
        emitter->_set_somtTargetFile(fp);
        emitter->_set_somtTargetClass(oCls);
	emitter->_set_somtEmitterName("<classSourceFileStem>");
        t = emitter->_get_somtTemplate();
        t->_set_somtCommentStyle(somtCPPE);
        if (deffile = emitter->somtOpenSymbolsFile(SYMBOLS_FILE, "r")) {
            t->somtReadSectionDefinitions(deffile);
            somtfclose(deffile);
        }
        else {
            fprintf(stderr, "Cannot open Symbols file \\" %s \\".\\n", 
			     SYMBOLS_FILE);
            exit(-1);
        }
        emitter->somtGenerateSections();
	delete emitter;
	delete oCls;

        return (fp);
    }
    else if (cls->type == SOMTModuleE) {

        fp = somtopenEmitFile(file, "<classSourceFileStem>");
	mod = (SOMTModuleEntryC *) somtGetObjectWrapper(cls);
        emitter = new <className>();
        emitter->_set_somtTargetFile(fp);
        emitter->_set_somtTargetModule(mod);
        t = emitter->_get_somtTemplate();
        t->_set_somtCommentStyle(somtCPPE);
        if (deffile = emitter->somtOpenSymbolsFile(SYMBOLS_FILE, "r")) {
            t->somtReadSectionDefinitions(deffile);
            somtfclose(deffile);
        }
        else {
            fprintf(stderr, "Cannot open Symbols file \\" %s \\".\\n", 
			     SYMBOLS_FILE);
            exit(-1);
        }
        emitter->somtGenerateSections();
        delete emitter;
	delete mod;

        return (fp);
    }

    else return ((FILE *) NULL);
}
