:template
/* # @(#) /44 1.9 6/7/96 16:14:31 [12/22/96 21:24:38] */

/*
 *   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 * SOMLINK emitSL(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 = somtopenEmitFileSL(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);
            somtfcloseSL(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 = somtopenEmitFileSL(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);
            somtfcloseSL(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);
}
