File:  [CSRG BSD Unix] / 43BSDReno / contrib / isode-beta / pepsy / pass2.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:56 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD43reno
BSD 4.3reno

/* pass2.c */

#ifndef	lint
static char *rcsid = "$Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/pepsy/pass2.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $";
#endif

/* 
 * $Header: /var/lib/cvsd/repos/CSRG/43BSDReno/contrib/isode-beta/pepsy/pass2.c,v 1.1.1.1 2018/04/24 16:12:56 root Exp $
 *
 *
 * $Log: pass2.c,v $
 * Revision 1.1.1.1  2018/04/24 16:12:56  root
 * BSD 4.3reno
 *
 * Revision 7.2  90/07/27  08:49:22  mrose
 * update
 * 
 * Revision 7.1  90/07/01  20:00:32  mrose
 * update
 * 
 */

/*
 *				  NOTICE
 *
 *    Acquisition, use, and distribution of this module and related
 *    materials are subject to the restrictions of a license agreement.
 *    Consult the Preface in the User's Manual for the full terms of
 *    this agreement.
 *
 */


#include <stdio.h>
#include <ctype.h>
#include "pepsydefs.h"
#include "pass2.h"
#include "mine.h"
#include "sym.h"

extern int doexternals;
extern int sflag;

#if 0
extern int hflag;
extern int bwidth;

#endif
extern char *eval;

#if 0
extern char *yyprefix;

#endif
extern int Aflag;
extern SY mysymbols;
extern char *modsym();
extern char *my_strcat();
extern char *notidtoid();

FILE   *fptab, *ffopen();

peri_pass2()
{

    int     nentries;
    int     encflag = 1, decflag = 1, prntflag = 1;
    char   *buf, *inc, *tab, *act;
    SY      sy;
    YP      yp;
    FILE   *fph, *fphh, *fpe, *fpd, *fpp;
    FILE   *fpa;

    if (!sflag)
	(void) fflush(stderr);

    if (bflag) {
	register int i, j;

	i = 2, j = 10;
	for (sy = mysymbols; sy; sy = sy->sy_next)
	    if (!(sy->sy_type->yp_flags & YP_IMPORTED))
		if (++i >= j)
		    j *= 10;
    }
    if (strcmp(mymodule, "UNIV"))
	(void) lookup_module("UNIV", NULLOID);

    fph = ffopen(my_strcat(mymodule, HFILE1));
    inc = my_strcat (mymodule, HFILE2);
    (void) fprintf (fph, "#ifndef\tPEPYPATH\n");
    (void) fprintf (fph, "#include <isode/pepsy/%s>\n", inc);
    (void) fprintf (fph, "#else\n");
    (void) fprintf (fph, "#include \"%s\"\n", inc);
    (void) fprintf (fph, "#endif\n\n\n");

#ifdef ACT_CODE
    act = my_strcat(mymodule, ACTIONDEFS);

    fpe = ffopen(my_strcat(mymodule, ENCFILENAME));
    file_header(fpe, act);
    fpd = ffopen(my_strcat(mymodule, DECFILENAME));
    file_header(fpd, act);
    fpp = ffopen(my_strcat(mymodule, PRNTFILENAME));
    file_header(fpp, act);
    fpa = ffopen(act);
#endif
    tab = notidtoid(mymodule);
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	eval = sy->sy_name;
	yp = sy->sy_type;

	if (sy->sy_module == NULLCP)
	    yyerror("no module name associated with symbol");
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (strcmp(sy->sy_module, mymodule)) {
	    fprintf(stderr, "mymodule unsuitable for module name e.g %s and %s(mymodule)\n", sy->sy_module, mymodule);
	    exit(1);
	}
	if (yp->yp_direction & YP_ENCODER || Aflag) {
	    buf = modsym (sy -> sy_module, sy -> sy_name, yyencdflt);
	    fprintf(fph, "#define %s", buf);
	    fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
	    fprintf(fph, "    %s(%s%s, ", ENCFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	    fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
	    fprintf(fph, "pe, top, len, buffer, (char *) parm)\n\n");
#ifdef ACT_CODE
	    if (encflag) {
		fprintf(fpe, "%s%s", ENC_FNCNAME, tab);
		open_func(fpe);
		encflag--;
	    }
#endif
	    if (bflag)
		init_new_file();
	    if (bflag)
		end_file();
	}
	if (yp->yp_direction & YP_DECODER || Aflag) {
	    buf = modsym (sy -> sy_module, sy -> sy_name, yydecdflt);
	    if (bflag)
		init_new_file();
	    fprintf(fph, "#define %s", buf);
	    fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
	    fprintf(fph, "    %s(%s%s, ", DECFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	    fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
	    fprintf(fph, "pe, top, len, buffer, (char **) parm)\n\n");
#if ACT_CODE
	    if (decflag) {
		fprintf(fpd, "%s%s", DEC_FNCNAME, tab);
		open_func(fpd);
		decflag--;
	    }
#endif
	    if (bflag)
		end_file();
	}
	if (yp->yp_direction & YP_PRINTER || Aflag) {
	    buf = modsym (sy -> sy_module, sy -> sy_name, yyprfdflt);
	    if (bflag)
		init_new_file();
	    fprintf(fph, "#define %s", buf);
	    fprintf(fph, "(pe, top, len, buffer, parm) \\\n");
	    fprintf(fph, "    %s(%s%s, ", PRNTFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	    fprintf(fph, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
#if 0	
	     /* no parm arguement to prnt_f now */
	     fprintf(fph, "pe, top, len, buffer, (char *) parm)\n"); 
#endif
	    fprintf(fph, "pe, top, len, buffer)\n");
	    fprintf(fph, "#define %s_P", buf);
	    fprintf(fph, "    %s%s, ", PREFIX,
		    proc_name(sy->sy_name, 1));
	    fprintf(fph, "&%s%s%s\n\n", PREFIX, tab, MODTYP_SUFFIX);
#ifdef  ACT_CODE
	    if (prntflag) {
		fprintf(fpp, "%s%s", PRNT_FNCNAME, tab);
		open_func(fpp);
		prntflag--;
	    }
#endif
	    if (bflag)
		end_file();
	}
	if (!bflag && ferror(stdout))
	    myyerror("write error - %s", sys_errname(errno));
    }

#ifdef	ACT_CODE
    if (!encflag) {
	close_func(fpe);
    }
    if (!decflag) {
	close_func(fpd);
    }
    if (!prntflag) {
	close_func(fpp);
    }
#endif

    close(fph);
#ifdef	ACT_CODE
    close(fpe);
    close(fpd);
    close(fpp);
    close(fpa);
#endif

    fptab = ffopen(my_strcat(mymodule, TBLNAME));

    /* Only need two files <stdio.h> and our types file which includes
     * everything else we need
     * Assumption. types file in the same directory as the _tables
     */
    fprintf(fptab, "#include <stdio.h>\n");
    fprintf(fptab, "#include \"%s%s\"\n\n", mymodule, GENTYPES);


#if 0
    {
#define NFILES	 5
	char *files[NFILES];
	char buf[BUFSIZ];
	int	last = 0;	/* next free slot in files */

	strncpy(buf, mymodule, BUFSIZ);
	strncat(buf, GENTYPES, BUFSIZ);

	files[last++] = buf;
	files[last++] = inc;
	files[last++] = (char *)0;

	fprintf(fptab, "#include <stdio.h>\n");
	doincl(fptab, files);

#undef NFILES
    }

	/* already done in our types.h file */
    proc_extmod(fptab);	/* process the external modules here as well */
#endif

#if 0
    fprintf(fptab, "#include \"%s%s\"\n", mymodule, GENTYPES);
    fprintf(fptab, "#include \"%s\"\n", inc);
#endif
#ifdef ACT_CODE
    fprintf(fptab, "#include \"%s\"\n", act);
#endif
    /*
     * loop through and generate all the default values definitions
     */
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	yp = sy->sy_type;
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (yp->yp_direction & (YP_ENCODER | YP_DECODER | YP_PRINTER)
	    || Aflag) {
	    gen_dflts(sy->sy_type, sy->sy_name);
	}
    }
    fprintf(fptab, "\n#define OFFSET(t,f)\t((int ) &(((t *)0)->f))\n\n");
    nentries = 0;
    head = NULL;
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	yp = sy->sy_type;
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (yp->yp_direction & YP_ENCODER || Aflag) {
	    nentries++;
	    gen_enctbl(sy);
	}
    }
    head = NULL;
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	yp = sy->sy_type;
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (yp->yp_direction & YP_DECODER || Aflag)
	    gen_dectbl(sy);
    }

    head = NULL;
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	yp = sy->sy_type;
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (yp->yp_direction & YP_PRINTER || Aflag)
	    gen_prnttbl(sy);
    }

    fphh = ffopen(inc);
    fprintf(fphh, "\nextern modtyp	%s%s%s;\n",
	    PREFIX, tab, MODTYP_SUFFIX);
    out_final_defs(fphh);
    close(fphh);

    gen_tpe();
    gen_modtype(tab, nentries, encflag, decflag, prntflag);

#if 0
    write_ph_file();
    print_list();
#endif

   gen_lint(fptab);

   fclose(fptab);
}

gen_enctbl(sy)
SY      sy;
{
    fprintf(fptab, "static tpe %s%s[] = {\n", ETABLE, proc_name(sy->sy_name, 0));
    fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n");
    gen_enctbl_rest(sy->sy_type, sy->sy_name);
    fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n");
    fprintf(fptab, "\t};\n");
    fprintf(fptab, "\n");
}

gen_dectbl(sy)
SY      sy;
{
    fprintf(fptab, "static tpe %s%s[] = {\n", DTABLE, proc_name(sy->sy_name, 0));
    fprintf(fptab, "\t{ PE_START, 0, 0, 0 },\n");
    gen_dectbl_rest(sy->sy_type, sy->sy_name);
    fprintf(fptab, "\t{ PE_END, 0, 0, 0 }\n");
    fprintf(fptab, "\t};\n");
    fprintf(fptab, "\n");
}


gen_prnttbl(sy)
SY      sy;
{
    fprintf(fptab, "static ptpe %s%s[] = {\n", PTABLE, proc_name(sy->sy_name, 0));
    fprintf(fptab, "\t{ PE_START, 0, 0, 0, \"%s\" },\n", sy->sy_name);
    gen_prnttbl_rest(sy->sy_type, sy->sy_name);
    fprintf(fptab, "\t{ PE_END, 0, 0, 0, NULL }\n");
    fprintf(fptab, "\t};\n");
    fprintf(fptab, "\n");
}


gen_enctbl_rest(yp, id)
YP      yp;
char   *id;
{
    int     i;

    i = tenc_typ(yp, id, NULL);
}

gen_dectbl_rest(yp, id)
YP      yp;
char   *id;
{
    int     i;

    i = tdec_typ(yp, id, NULL);
}

gen_prnttbl_rest(yp, id)
YP      yp;
char   *id;
{
    int     i;

    i = tprnt_typ(yp, id, NULL);
}


/*
 * define the tpe index tables and the pointer table
 */
gen_tpe()
{
    SY      sy;

    fprintf(fptab, "static tpe *etabl[] = {\n");
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	if (sy->sy_type->yp_flags & YP_IMPORTED)
	    continue;
	if (sy->sy_type->yp_direction & YP_ENCODER || Aflag)
	    fprintf(fptab, "\t%s%s,\n", ETABLE, proc_name(sy->sy_name, 0));
    }
    fprintf(fptab, "\t};\n\n");

    fprintf(fptab, "static tpe *dtabl[] = {\n");
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	if (sy->sy_type->yp_flags & YP_IMPORTED)
	    continue;
	if (sy->sy_type->yp_direction & YP_DECODER || Aflag)
	    fprintf(fptab, "\t%s%s,\n", DTABLE, proc_name(sy->sy_name, 0));
    }
    fprintf(fptab, "\t};\n\n");

    fprintf(fptab, "static ptpe *ptabl[] = {\n");
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	if (sy->sy_type->yp_flags & YP_IMPORTED)
	    continue;
	if (sy->sy_type->yp_direction & YP_PRINTER || Aflag)
	    fprintf(fptab, "\t%s%s,\n", PTABLE, proc_name(sy->sy_name, 0));
    }
    fprintf(fptab, "\t};\n\n");

    /* produce pointer table */
    dump_ptrtab(fptab);
}

/*
 * output the module structure for this module
 */
gen_modtype(tab, no, f1, f2, f3)
char   *tab;
int     no;
int     f1, f2, f3;
{
    if (!f1)
	fprintf(fptab, "extern PE\t%s%s();\n", ENC_FNCNAME, tab);
    if (!f2)
	fprintf(fptab, "extern PE\t%s%s();\n", DEC_FNCNAME, tab);
    if (!f3)
	fprintf(fptab, "extern PE\t%s%s();\n", PRNT_FNCNAME, tab);
    fprintf(fptab, "\n");
    fprintf(fptab, "modtyp %s%s%s = {\n", PREFIX, tab, MODTYP_SUFFIX);
    fprintf(fptab, "\t\"%s\",\n", mymodule);	/* name */
    fprintf(fptab, "\t%d,\n", no);		/* number of entries */
					/* coding tables */
    fprintf(fptab, "\tetabl,\n");
    fprintf(fptab, "\tdtabl,\n");
    fprintf(fptab, "\tptabl,\n");
					/* action tables - may disappear */
    fprintf(fptab, "\t0,\n");	/* no action code */
    fprintf(fptab, "\t0,\n");
    fprintf(fptab, "\t0,\n");

    fprintf(fptab, "\t%s%s%s,\n", PREFIX, PTR_TABNAME, tab);
    fprintf(fptab, "\t};\n\n");
}

/*
 * open a file called name
 */
FILE   *
ffopen(name)
char   *name;
{
    FILE   *fp;

    if ((fp = fopen(name, "w")) == NULL) {
	fprintf(stderr, "Can't create the file %s", name);
	exit(1);
    }
    return fp;
}

#ifdef ACT_CODE
/*
 * output the file prologue to the file specified by fp
 */
file_header(fp, act)
FILE   *fp;
char   *act;
{
    fprintf(fp, "#include %s\n", PSAP_DOT_H);
    fprintf(fp, "#include \"%s\"\n", INCFILE1);
    fprintf(fp, "#include \"%s\"\n", act);
    fprintf(fp, "#include \"%s%s\"\n\n", mymodule, GENTYPES);
    fprintf(fp, "#ifndef PEPYPARM\n");
    fprintf(fp, "#define PEPYPARM char *\n");
    fprintf(fp, "#endif\n");
    fprintf(fp, "extern PEPYPARM NullParm;\n\n");
}

#endif

/*
 * output the function prologue to the file specified by fp
 */
open_func(fp)
FILE   *fp;
{

    fprintf(fp, "(pe, parm, p, mod)\n");
    fprintf(fp, "PE\tpe;\n");
    fprintf(fp, "PEPYPARM\tparm;\n");
    fprintf(fp, "tpe\t*p;\n");
    fprintf(fp, "modtyp\t*mod;\n");
    fprintf(fp, "{\n");
    /* action 0 ???? */
    fprintf(fp, "\tswitch (p->pe_ucode) {\n");
}

/*
 * output the function epilogue to the file specified by fp
 */
close_func(fp)
FILE   *fp;
{
    fprintf(fp, "\t\tdefault:\n");
    fprintf(fp, "\t\t\tbreak;\n");
    fprintf(fp, "\t}\n");
    fprintf(fp, "\treturn OK;\n}\n\n");
}

/*
 * print the table id_table
 */
print_table()
{
    int     i;
    id_entry *t;

    for (i = 0; i < TABLESIZE; i++) {
	for (t = id_table[i]; t != NULL; t = t->next)
	    printf("%s(%d) -->   ", t->r_value, t->def_value);
	if (id_table[i] != NULL)
	    printf("NULL -- %d\n", i);
    }
}

static struct univ_typ univ_tab[] = {
    {"EXTERNAL", "struct	type_UNIV_EXTERNAL	*", "EXTERNAL", 8, 0,
    "UNIV", UNF_EXTMOD, YP_UNDF, },
    {"GeneralString", "struct	qbuf	*", "OCTETSTRING", 27, 0,
    "UNIV", 0, YP_OCT, },
    {"GeneralisedTime", "struct	qbuf	*", "OCTETSTRING", 24, 0,
    "UNIV", 0, YP_OCT, },
    {"GeneralizedTime", "struct	qbuf	*", "OCTETSTRING", 24, 0,
    "UNIV", 0, YP_OCT, },
    {"GraphicString", "struct	qbuf	*", "OCTETSTRING", 25, 0,
    "UNIV", 0, YP_OCT, },
    {"IA5String", "struct	qbuf	*", "OCTETSTRING", 22, 0,
    "UNIV", 0, YP_OCT, },
    {"ISO646String", "struct	qbuf	*", "OCTETSTRING", 26, 0,
    "UNIV", 0, YP_OCT, },
    {"NumericString", "struct	qbuf	*", "OCTETSTRING", 18, 0,
    "UNIV", 0, YP_OCT, },
    {"PrintableString", "struct	qbuf	*", "OCTETSTRING", 19, 0,
    "UNIV", 0, YP_OCT, },
    {"TeletexString", "struct	qbuf	*", "OCTETSTRING", 20, 0,
    "UNIV", 0, YP_OCT, },
    {"T61String", "struct	qbuf	*", "OCTETSTRING", 20, 0,
    "UNIV", 0, YP_OCT, },
    {"UTCTime", "struct	qbuf	*", "OCTETSTRING", 23, 0,
    "UNIV", 0, YP_OCT, },
    {"UniversalTime", "struct	qbuf	*", "OCTETSTRING", 23, 0,
    "UNIV", 0, YP_OCT, },
    {"VideotexString", "struct	qbuf	*", "OCTETSTRING", 21, 0,
    "UNIV", 0, YP_OCT, },
    {"VisibleString", "struct	qbuf	*", "OCTETSTRING", 26, 0,
    "UNIV", 0, YP_OCT, },
};

extern struct univ_typ *simptyp();

/*
 * Determine wether the type name matches one of the Universal types
 * which are to be treated specially. If so return a pointer to the
 * data structure which contains the parameters describing how it
 * should be processed
 */
struct univ_typ *
univtyp(name)
char   *name;
{
    int     low, high, i;
    struct univ_typ *p;

    low = 0;
    high = NENTRIES(univ_tab) - 1;
    while (low <= high) {
	p = univ_tab + (low + high) / 2;
	if ((i = scmp(name, p->univ_name)) == 0)
	    return (p);
	if (low == high)
	    return (NULL);
	if (i < 0)
	    high = p - univ_tab - 1;
	else
	    low = p - univ_tab + 1;
    }

#if OPTIMISED
    if ((p = simptyp(name)) == NULL)
	return (p);
#endif

    return (NULL);
}

/*
 * Compare two strings returning a number representing the character
 * where they differ or 0 if are the same - I wrote this because I
 * couldn't trust strcmp to work the same way between numbers and
 * letters everywhere. longer strings are greater shorter strings
 * numbers are greater then all letters lower case are greater then
 * upper case There must be a better way !
 */
scmp(s1, s2)
char   *s1, *s2;
{
    while (*s1 == *s2 && *s2)
	s1++, s2++;
    if (*s1 == '\0' && *s2 == '\0')
	return (0);
    if (*s1 == '\0')
	return (-1);
    if (*s2 == '\0')
	return (1);
    if (isalpha(*s1) && isalpha(*s2)) {
	if (isupper(*s1) && isupper(*s2))
	    return (*s1 - *s2);
	if (islower(*s1) && islower(*s1))
	    return (*s1 - *s2);
	if (isupper(*s1))
	    return (-1);
	if (islower(*s1))
	    return (1);
    }
    if (isdigit(*s1) && isdigit(*s2))
	return (*s1 - *s2);
    if (isdigit(*s1))
	return (1);
    if (isdigit(*s2))
	return (-1);
    return (*s1 - *s2);
}

/*
 * lookup a symbol and return a pointer to it
 */
SY
syfind(name)
char   *name;
{
    SY      sy;

    for (sy = mysymbols; sy; sy = sy->sy_next) {
	if (sy->sy_type->yp_flags & YP_IMPORTED)
	    continue;
	if (strcmp(name, sy->sy_name) == 0)
	    return (sy);
    }
    return (NULL);
}
/*
 * determine if the symbol is a simple type that is optimised
 */
struct univ_typ *
simptyp(yp)
YP      yp;
{
    struct univ_typ *p;
    YP      y;

    static struct univ_typ bitstring =
    {"Bitstring", "struct	PElement	*", "BITSTRING", 3, 0},
            octetstring =
    {"GeneralString", "struct	qbuf	*", "OCTETSTRING", 4, 0},
            oid =
    {"Object Identifier", "struct	OIDentifier	*", "OBJIDENT", 6, 0},
            obj =
    {"Module", "struct	OIDentifier	*",
    "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 27, 0};

#define MSTRING 30		/* number of Xs in the above string */

    switch (yp->yp_code) {
    case YP_BIT:
    case YP_BITLIST:
	return (&bitstring);

    case YP_SEQ:
    case YP_SET:
    case YP_ANY:
	return (&bitstring);

    case YP_OCT:
	return (&octetstring);

    case YP_OID:
	return (&oid);

    case YP_IDEFINED:
	strncpy(p->univ_tab, yp->yp_identifier, MSTRING);
	return (&obj);


    case YP_SEQLIST:
    case YP_SETLIST:
    case YP_CHOICE:
#if 0
	if (hflag && (y = yp->yp_type) && !y->yp_next) {
	    ferr(1, "simtyp: -h flag not implemented\n");
	    return (NULL);
	}
#endif

    default:
	return (NULL);
    }
}

/*
 * Generate function definitions for all the macros so that lint
 * can type check all thier uses
 */
gen_lint(fp)
FILE	*fp;
{
    char   *buf, *tab; 
    SY      sy;
    YP      yp;

    fprintf(fp, "\n#ifdef\tlint\n");
    tab = notidtoid(mymodule);
    for (sy = mysymbols; sy; sy = sy->sy_next) {
	eval = sy->sy_name;
	yp = sy->sy_type;

	if (sy->sy_module == NULLCP)
	    yyerror("no module name associated with symbol");
	if (yp->yp_flags & YP_IMPORTED)
	    continue;
	if (strcmp(sy->sy_module, mymodule)) {
	    fprintf(stderr,
	      "mymodule unsuitable for module name e.g %s and %s(mymodule)\n",
	      sy->sy_module, mymodule);
	    exit(1);
	}
	/* Encoding routine */
	buf = modsym (sy -> sy_module, sy -> sy_name, yyencdflt);
	fprintf(fp, "\n#undef %s\n", buf);
	fprintf(fp, "int	%s", buf);
	fprintf(fp, "(pe, top, len, buffer, parm)\n");
	fprintf(fp, "PE	*pe;\n");
	fprintf(fp, "int	top,\n\tlen;\n");
	fprintf(fp, "char	buffer;\n");
	fprintf(fp, "struct %s	parm;\n",
	    modsym(sy->sy_module, sy->sy_name, "type"));
	fprintf(fp, "{\n  return (%s(%s%s, ",
	    ENCFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
	fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");

	/* Decoding routine */
	buf = modsym (sy -> sy_module, sy -> sy_name, yydecdflt);
	fprintf(fp, "\n#undef %s\n", buf);
	fprintf(fp, "int	%s", buf);
	fprintf(fp, "(pe, top, len, buffer, parm)\n");
	fprintf(fp, "PE	pe;\n");
	fprintf(fp, "int	top,\n\t*len;\n");
	fprintf(fp, "char	*buffer;\n");
	fprintf(fp, "struct %s	parm;\n",
	    modsym(sy->sy_module, sy->sy_name, "type"));
	fprintf(fp, "{\n  return (%s(%s%s, ",
	    DECFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
	fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");


	/* Printing routine */
	buf = modsym (sy -> sy_module, sy -> sy_name, yyprfdflt);
	fprintf(fp, "\n#undef %s\n", buf);
	fprintf(fp, "int	%s", buf);
	fprintf(fp, "(pe, top, len, buffer, parm)\n");
	fprintf(fp, "PE	pe;\n");
	fprintf(fp, "int	top,\n\t*len;\n");
	fprintf(fp, "char	*buffer;\n");
	fprintf(fp, "struct %s	parm;\n",
	    modsym(sy->sy_module, sy->sy_name, "type"));
	fprintf(fp, "{\n  return (%s(%s%s, ",
	    PRNTFNCNAME, PREFIX, proc_name(sy->sy_name, 1));
	fprintf(fp, "&%s%s%s, ", PREFIX, tab, MODTYP_SUFFIX);
	fprintf(fp, "pe, top, len, buffer, (char *) parm)\n}\n");

	if (ferror(fp))
	    myyerror("write error - %s", sys_errname(errno));
    }
    fprintf(fp, "\n#endif\t/* lint */\n");
}

/*
 * pointer table support routines
 */
static char	*ptr_tab[MAXPTRS];	/* reference of the pointer */
static int	ptr_cnt = 0;

/*
 * add the given pointer to the pointer table and return its index
 */
addptr(p)
char	*p;
{
    int	ind;
    register int i;
    register char *s;

    /*
     * try to eliminate common pointers by returning a ponter if it matches
     * previously
     */
    for (i = 0; i < ptr_cnt; i++)
	if (strcmp(p, ptr_tab[i]) == 0)
	     return (i);

    if (ptr_cnt >= MAXPTRS) {
	fprintf(stderr, "\npointer table overflow %d\n", ptr_cnt);
	exit(1);
    }

    if ((s = malloc ((unsigned) (strlen (p) + 1))) == NULLCP) {
	fprintf(stderr, "\naddptr:out of memory\n");
	exit(1);
    }
    (void) strcpy (s, p);

    ptr_tab[ind = ptr_cnt++] = s;

    return (ind);
}


dump_ptrtab(fp)
FILE	*fp;
{
    char	*tab;
    int		i;

    tab = notidtoid(mymodule);

    fprintf(fp, "\n/* Pointer table %d entries */\n", ptr_cnt);
    fprintf(fp, "static caddr_t %s%s%s[] = {\n", PREFIX, PTR_TABNAME, tab);

    for (i = 0; i < ptr_cnt; i++)
	fprintf(fp, "    (caddr_t ) %s,\n", ptr_tab[i]);
    
    if (ptr_cnt <= 0)
	fprintf(fp, "    (caddr_t ) 0,\n");	/* for fussy C compilers */

    fprintf(fp, "};\n");
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.