:template
/* @(#) somc/gen_emit.efs 2.7 7/14/95 12:05:40 [7/30/96 14:44:56] */

/*
 *   COMPONENT_NAME: some
 *
 *   ORIGINS: 27
 *
 *
 *   10H9767, 10H9769  (C) COPYRIGHT International Business Machines Corp. 1992,1994
 *   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>.c
 *       Author:    SOMObjects Emitter Framework
 *     Contents:    Generic framework emitter for <className>.
 *         Date:    <timeStamp>.
 */

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

#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 = <className>New();
        __set_somtTargetFile(emitter, fp);
        __set_somtTargetClass(emitter, oCls);
	__set_somtEmitterName(emitter, "<classSourceFileStem>");
        t = __get_somtTemplate(emitter);
        __set_somtCommentStyle(t, somtCPPE);
        if (deffile = _somtOpenSymbolsFile(emitter, SYMBOLS_FILE, "r")) {
            _somtReadSectionDefinitions(t, deffile);
            somtfclose(deffile);
        }
        else {
            fprintf(stderr, "Cannot open Symbols file \\" %s \\".\\n", 
			     SYMBOLS_FILE);
            exit(-1);
        }
        _somtGenerateSections(emitter);
        _somFree(emitter);
	_somFree(oCls);

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

        fp = somtopenEmitFile(file, "<classSourceFileStem>");
	mod = (SOMTModuleEntryC *) somtGetObjectWrapper(cls);
        emitter = <className>New();
        __set_somtTargetFile(emitter, fp);
        __set_somtTargetModule(emitter, mod);
        t = __get_somtTemplate(emitter);
        __set_somtCommentStyle(t, somtCPPE);
        if (deffile = _somtOpenSymbolsFile(emitter, SYMBOLS_FILE, "r")) {
            _somtReadSectionDefinitions(t, deffile);
            somtfclose(deffile);
        }
        else {
            fprintf(stderr, "Cannot open Symbols file \\" %s \\".\\n", 
			     SYMBOLS_FILE);
            exit(-1);
        }
        _somtGenerateSections(emitter);
        _somFree(emitter);
        _somFree(mod);

        return (fp);
    }

    else return ((FILE *) NULL);
}
