/* posy.c - PEPY optional structure-generator (yacc-based) */
How to do smarter DEFAULT determination for the other types and NULLs
Perhaps pull-up primitive IDentifiers
Abort a CHOICE encoding if the structure is empty
1. LANGUAGE SIMPLIFICATIONS:
Pull-up uni-member SEQUENCEs/SETs/CHOICEs
Unique tags to avoid conflicts for internal structures (-h1 option)
SEQUENCE/SET OF Type should have Type be an ID for nicer naming
static char *rcsid
= "$Header: /f/osi/pepy/RCS/posy.c,v 7.6 91/02/22 09:35:13 mrose Interim $";
* $Header: /f/osi/pepy/RCS/posy.c,v 7.6 91/02/22 09:35:13 mrose Interim $
* Revision 7.6 91/02/22 09:35:13 mrose
* Revision 7.5 90/10/17 11:51:24 mrose
* Revision 7.4 90/09/07 17:35:09 mrose
* Revision 7.3 90/02/23 17:50:09 mrose
* Revision 7.2 90/02/19 13:09:35 mrose
* Revision 7.1 90/01/11 18:37:05 mrose
* Revision 7.0 89/11/23 22:11:59 mrose
* 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
#define SVAL(s) ((s) ? (s) : "")
#define PARVAL(s) ((s) ? (s) : "parm")
int Cflag
= 0; /* posy */
int Pflag
= 0; /* pepy compat ... */
char *bflag
= NULL
; /* .. */
char *module_actions
= NULL
;
#define hflag (options[0])
#define Hflag (options[1])
#define h2flag (options[2])
static int options
[NOPTIONS
];
static char *eval
= NULLCP
;
OID mymoduleid
= NULLOID
;
static char modulename
[BUFSIZ
];
int yysection
= YP_DECODER
;
char *yyencpref
= "encode";
char *yydecpref
= "decode";
char *yyprfpref
= "print";
char *yyencdflt
= "encode";
char *yydecdflt
= "decode";
char *yyprfdflt
= "print";
static char *classes
[] = {
"", "BOOLEAN", "INTEGER", "INTEGER", "BIT STRING", "BIT STRING",
"OCTET STRING", "NULL", "SEQUENCE", "SEQUENCE OF", "SEQUENCE", "SET",
"SET OF", "SET", "CHOICE", "ANY", "OBJECT IDENTIFIER", "", "ENUMERATED",
static char autogen
[BUFSIZ
];
static char sysout
[BUFSIZ
];
static char sysdef
[BUFSIZ
];
static char sysact
[BUFSIZ
];
static MD mymodules
= NULLMD
;
static SY mysymbols
= NULLSY
;
char *gensym (), *modsym (), *array ();
SY
new_symbol (), add_symbol ();
static double val2real ();
static void prime_default ();
dp
= pepyversion
+ strlen ("pepy ");
fprintf (stderr
, "posy %s\n", dp
);
sysout
[0] = sysdef
[0] = sysact
[0] = NULL
;
for (argc
--, argv
++; argc
> 0; argc
--, argv
++) {
if (strcmp (cp
, "-a") == 0) {
if (strcmp (cp
, "-d") == 0) {
if (strcmp (cp
, "-f") == 0) {
if (strncmp (cp
, "-h", 2) == 0) {
if (sscanf (cp
+ 2, "%d", &i
) != 1 || i
>= NOPTIONS
)
if (strcmp (cp
, "-m") == 0) {
if (strcmp (cp
, "-o") == 0) {
fprintf (stderr
, "too many output files\n");
if ((cp
= *argv
) == NULL
|| (*cp
== '-' && cp
[1] != NULL
))
(void) strcpy (sysout
, cp
);
if (strcmp (cp
, "-s") == 0) {
"usage: posy [-a] [-d] [-f] [-Hh] [-o newmodule.py] [-s] module.py\n");
switch (pepydebug
= (cp
= getenv ("POSYTEST")) && *cp
? atoi (cp
) : 0) {
if (*sysin
&& freopen (sysin
, "r", stdin
) == NULL
) {
fprintf (stderr
, "unable to read "), perror (sysin
);
if (strcmp (sysout
, "-") == 0)
if (*sysout
&& freopen (sysout
, "w", stdout
) == NULL
) {
fprintf (stderr
, "unable to write "), perror (sysout
);
if (cp
= index (dp
, ')')) {
for (cp
++; *cp
!= ' '; cp
++)
(void) sprintf (autogen
, "posy %*.*s", cp
- dp
, cp
- dp
, dp
);
printf ("-- automatically generated by %s, do not edit!\n\n", autogen
);
exit (yyparse ()); /* NOTREACHED */
_asprintf (buffer
, NULLCP
, ap
);
(void) sprintf (buffer2
, "Warning: %s", buffer
);
fprintf (stderr
, "\n"), linepos
= 0;
fprintf (stderr
, "type %s: ", eval
);
fprintf (stderr
, "line %d: ", yylineno
);
fprintf (stderr
, "%s\n", s
);
fprintf (stderr
, "last token read was \"%s\"\n", yytext
);
_asprintf (buffer
, NULLCP
, ap
);
static pyyerror (va_alist
)
_asprintf (buffer
, NULLCP
, ap
);
static pyyerror (yp
, fmt
)
fprintf (stderr
, "\n"), linepos
= 0;
static int nameoutput
= 0;
static int outputlinelen
= 79;
fprintf (stderr
, "\n\n");
fprintf (stderr
, "%s", mymodule
);
nameoutput
= (linepos
= strlen (mymodule
)) + 1;
fprintf (stderr
, " types:");
if (linepos
!= nameoutput
)
if (len
+ linepos
+ 1 > outputlinelen
)
fprintf (stderr
, "\n%*s", linepos
= nameoutput
, "");
fprintf (stderr
, " "), linepos
++;
fprintf (stderr
, "%s", s
);
printf ("%s ", mymodule
);
printf ("%s ", oidprint(mymoduleid
));
printf ("DEFINITIONS ::=\n\n");
pass1_type (encpref
, decpref
, prfpref
, mod
, id
, yp
)
if (lookup_type (mod
, id
)) /* no duplicate entries, please... */
fprintf (stderr
, "\n"), linepos
= 0;
fprintf (stderr
, "%s.%s\n", mod
? mod
: mymodule
, id
);
fprintf (stderr
, "--------\n");
if (!(yp
-> yp_flags
& YP_IMPORTED
))
sy
= new_symbol (encpref
, decpref
, prfpref
, mod
, id
, yp
);
mysymbols
= add_symbol (mysymbols
, sy
);
modsym_aux (mymodule
, modulename
);
(void) sprintf (sysdef
, "%s-types.h", mymodule
);
if ((fdef
= fopen (sysdef
, "w")) == NULL
)
myyerror ("unable to write %s", sysdef
);
fprintf (fdef
, "/* automatically generated by %s, do not edit! */\n\n",
fprintf (fdef
, "#ifndef\t_module_%s_defined_\n", modulename
);
fprintf (fdef
, "#define\t_module_%s_defined_\n\n", modulename
);
fprintf (fdef
, "#ifndef PEPYPATH\n");
fprintf (fdef
, "#include <isode/psap.h>\n");
if (strcmp (mymodule
, "UNIV"))
fprintf (fdef
, "#include <isode/pepy/UNIV-types.h>\n");
fprintf (fdef
, "#else\n");
fprintf (fdef
, "#include \"psap.h\"\n");
if (strcmp (mymodule
, "UNIV"))
fprintf (fdef
, "#include \"../pepy/UNIV-types.h\"\n");
fprintf (fdef
, "#endif\n");
(void) sprintf (sysact
, "%s-types.tmp", mymodule
);
if ((fact
= fopen (sysact
, "w+")) == NULL
)
myyerror ("unable to write %s", sysact
);
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (sy
-> sy_module
== NULLCP
)
yyerror ("no module name associated with symbol");
if (yp
-> yp_flags
& YP_IMPORTED
)
if (ferror (stdout
) || ferror (fdef
) || (fflag
&& ferror (fact
)))
myyerror ("write error - %s", sys_errname (errno
));
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (yp
-> yp_flags
& YP_IMPORTED
)
do_struct1 (yp
, eval
, NULLCP
);
if (ferror (stdout
) || ferror (fdef
) || (fflag
&& ferror (fact
)))
myyerror ("write error - %s", sys_errname (errno
));
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (yp
-> yp_flags
& YP_IMPORTED
)
do_struct2 (yp
, eval
, NULLCP
);
if (ferror (stdout
) || ferror (fdef
) || (fflag
&& ferror (fact
)))
myyerror ("write error - %s", sys_errname (errno
));
printf ("%%{\n#include <stdio.h>\n#include \"%s\"\n%%}\n", sysdef
);
printf ("\nPREFIXES %s %s %s\n", yyencdflt
, yydecdflt
, yyprfdflt
);
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (sy
-> sy_module
== NULLCP
)
yyerror ("no module name associated with symbol");
if (yp
-> yp_flags
& YP_IMPORTED
)
printf ("\nENCODER %s\n", yyencpref
);
printf ("\n%s", sy
-> sy_name
);
printf (" [[P struct %s *]]",
modsym (mymodule
, sy
-> sy_name
, "type"));
if (yp
-> yp_declexp
|| yp
-> yp_type
)
do_type0 (yp
, YP_ENCODER
);
do_type0 (yp
, YP_ENCODER
);
do_type0 (yp
, YP_ENCODER
);
do_type1 (yp
, 1, (yp
-> yp_flags
& YP_TAG
) ? 1 : 2, eval
, "parm",
if (ferror (stdout
) || ferror (fdef
) || (fflag
&& ferror (fact
)))
myyerror ("write error - %s", sys_errname (errno
));
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (sy
-> sy_module
== NULLCP
)
yyerror ("no module name associated with symbol");
if (yp
-> yp_flags
& YP_IMPORTED
)
printf ("\nDECODER %s\n", yydecpref
);
printf ("\n%s", sy
-> sy_name
);
printf (" [[P struct %s **]]",
modsym (mymodule
, sy
-> sy_name
, "type"));
if (yp
-> yp_declexp
|| yp
-> yp_type
)
do_type0 (yp
, YP_DECODER
);
do_type0 (yp
, YP_DECODER
);
modsym (mymodule
, sy
-> sy_name
, "type"), 1);
if (hflag
&& y
-> yp_type
&& !y
-> yp_type
-> yp_next
) {
modsym (mymodule
, sy
-> sy_name
, "type"), 1);
do_type1 (yp
, 1, (yp
-> yp_flags
& YP_TAG
) ? 1 : 2, eval
, "(*parm)",
if (ferror (stdout
) || ferror (fdef
) || (fflag
&& ferror (fact
)))
myyerror ("write error - %s", sys_errname (errno
));
(void) fseek (fact
, 0L, 0);
while ((c
= getc (fact
)) != EOF
)
fprintf (fdef
, "#endif\n");
if (ferror (stdout
) || ferror (fdef
))
myyerror ("write error - %s", sys_errname (errno
));
static do_struct0 (yp
, id
)
do_struct0 (yp
-> yp_type
, id
);
choice_pullup (yp
, yp
-> yp_code
== YP_CHOICE
? CH_FULLY
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
)
&& strcmp (yp
-> yp_module
, mymodule
)
&& !lookup_module (yp
-> yp_module
))
fprintf (fdef
, "#include \"%s-types.h\"\n", yp
-> yp_module
);
static do_struct1 (yp
, id
, pullup
)
fprintf (fdef
, "#define\t%s\tPElement\n",
modsym (mymodule
, id
, "type"));
if (yp
-> yp_code
== YP_BITLIST
) {
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
if ((j
= val2int (yv
)) < 0)
pyyerror (yp
, "invalid bit number in BIT STRING");
if (i
< sizeof (int) * 8) { /* NBBY */
fprintf (fdef
, "#define\t%s\t\"\\020",
modsym (mymodule
, eval
, "bits"));
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
if (yv
-> yv_flags
& YV_NAMED
)
fprintf (fdef
, "\\0%o%s",
val2int (yv
) + 1, yv
-> yv_named
);
fprintf (fdef
, "\\0%oBIT%d",
val2int (yv
) + 1, val2int (yv
));
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
) {
modsym_aux (yv
-> yv_named
, buf1
);
fprintf (fdef
, "#define\t%s_%s\t%d\n",
modsym (mymodule
, eval
, "bit"),
fprintf (fdef
, "#define\t%s\tpe_free\n",
modsym (mymodule
, id
, "free"));
fprintf (fdef
, "#define\t%s\tqbuf\n",
modsym (mymodule
, id
, "type"));
fprintf (fdef
, "#define\t%s\tqb_free\n",
modsym (mymodule
, id
, "free"));
fprintf (fdef
, "#define\t%s\tOIDentifier\n",
modsym (mymodule
, id
, "type"));
fprintf (fdef
, "#define\t%s\toid_free\n",
modsym (mymodule
, id
, "free"));
fprintf (fdef
, "#define\t%s\t",
modsym (mymodule
, id
, "type"));
modsym (yp
-> yp_module
, yp
-> yp_identifier
, "type"));
fprintf (fdef
, "#define\t%s\t",
modsym (mymodule
, id
, "free"));
modsym (yp
-> yp_module
, yp
-> yp_identifier
, "free"));
if (hflag
&& (y
= yp
-> yp_type
) && !y
-> yp_next
) {
do_struct1 (y
, id
, tags
[yp
-> yp_code
]);
static do_struct2 (yp
, id
, pullup
)
int flg
= (yp
-> yp_code
== YP_SEQTYPE
|| yp
-> yp_code
== YP_SETTYPE
);
if (hflag
&& (y
= yp
-> yp_type
) && !y
-> yp_next
) {
do_struct2 (y
, id
, tags
[yp
-> yp_code
]);
fprintf (fdef
, "struct %s {\n", modsym (mymodule
, id
, "type"));
fprintf (fact
, "\n%s (arg)\n", modsym (mymodule
, id
, "free"));
fprintf (fact
, "struct %s *arg;\n{\n",
modsym (mymodule
, id
, "type"));
fprintf (fact
, " struct %s *parm = arg;\n",
modsym (mymodule
, id
, "type"));
fprintf (fact
, " int\tn_parm;\n");
fprintf (fact
, "\n if (parm == NULL)\n\treturn;\n\n");
posy (yp
, 1, 1, "parm", id
, "parm", flg
&& h2flag
);
fprintf (fdef
, "int\t%s ();\n", modsym (mymodule
, id
, "free"));
if (yp
-> yp_code
!= YP_SEQTYPE
&&
yp
-> yp_code
!= YP_SETTYPE
)
fprintf (fact
, "\n free ((char *) arg);");
static int type0_brackets
;
static do_type0 (yp
, direction
)
type0_brackets
= type0_bit
= 0;
do_type0_aux (yp
, direction
);
static do_type0_aux (yp
, direction
)
if (type0_brackets
++ == 0)
printf ("\tstruct %s *%s%s;\n", yp
-> yp_declexp
,
direction
== YP_DECODER
? "*" : "", yp
-> yp_declexp
);
if (type0_brackets
++ == 0)
printf ("\tint n_%s = 0;\n", yp
-> yp_declexp
?
yp
-> yp_declexp
: "parm");
do_type0_aux (yp
-> yp_type
, direction
);
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
)
do_type0_aux (y
, direction
);
if (direction
== YP_ENCODER
) {
if (type0_brackets
++ == 0)
printf ("\tchar *bit_parm;\n");
static do_type1 (yp
, top
, level
, id
, var
, action2
, direction
)
printf ("%*s", level
* 4, "");
if (yp
-> yp_flags
& YP_ID
) {
printf ("%s", yp
-> yp_id
);
if (!(yp
-> yp_flags
& YP_TAG
))
printf ("\n%*s", ++level
* 4, "");
if (yp
-> yp_flags
& YP_TAG
) {
printf ("[%s%d]\n", classes
[yt
-> yt_class
], val2int (yt
-> yt_value
));
printf ("%*s", level
* 4, "");
if (yp
-> yp_flags
& YP_OPTIONAL
&& yp
-> yp_varexp
) {
if ((ep
= index (yp
-> yp_varexp
, ' ')) == NULL
)
yyerror ("Bug in varexp!");
(void) sprintf (varbuf
, "%*.*s", ep
- yp
-> yp_varexp
,
ep
- yp
-> yp_varexp
, yp
-> yp_varexp
);
if ((yp
-> yp_flags
& (YP_OPTIONAL
|YP_DEFAULT
)) &&
direction
== YP_DECODER
) {
if (!top
&& !(yp
-> yp_flags
& (YP_ID
| YP_TAG
)))
printf ("dummy-for-default\n%*s", ++level
* 4, "");
if (yp
-> yp_flags
& YP_OPTIONAL
)
printf ("%%{ %s -> optionals |= %s; %%}\n%*s",
varbuf
, yp
-> yp_optcontrol
, level
* 4, "");
printf ("%%{ %s%s = %d; %%}\n%*s",
var
, SVAL (yp
-> yp_varexp
),
val2int (yp
-> yp_default
) ? 1 : 0, level
* 4, "");
if ((yp
-> yp_flags
& (YP_OPTIONAL
|YP_DEFAULT
)) &&
direction
== YP_DECODER
) {
if (!top
&& !(yp
-> yp_flags
& (YP_ID
| YP_TAG
)))
printf ("dummy-for-default\n%*s", ++level
* 4, "");
if (yp
-> yp_flags
& YP_OPTIONAL
)
printf ("%%{ %s -> optionals |= %s; %%}\n%*s",
varbuf
, yp
-> yp_optcontrol
, level
* 4, "");
printf ("%%{ %s%s = %d; %%}\n%*s",
var
, SVAL (yp
-> yp_varexp
),
val2int (yp
-> yp_default
), level
* 4, "");
if ((yp
-> yp_flags
& (YP_OPTIONAL
|YP_DEFAULT
)) &&
direction
== YP_DECODER
) {
if (!top
&& !(yp
-> yp_flags
& (YP_ID
| YP_TAG
)))
printf ("dummy-for-default\n%*s", ++level
* 4, "");
if (yp
-> yp_flags
& YP_OPTIONAL
)
printf ("%%{ %s -> optionals |= %s; %%}\n%*s",
varbuf
, yp
-> yp_optcontrol
, level
* 4, "");
printf ("%%{ %s%s = %d; %%}\n%*s",
var
, SVAL (yp
-> yp_varexp
), dfl2int (yp
),
if ((yp
-> yp_flags
& (YP_OPTIONAL
|YP_DEFAULT
)) &&
direction
== YP_DECODER
) {
if (!top
&& !(yp
-> yp_flags
& (YP_ID
| YP_TAG
)))
printf ("dummy-for-default\n%*s", ++level
* 4, "");
if (yp
-> yp_flags
& YP_OPTIONAL
)
printf ("%%{ %s -> optionals |= %s; %%}\n%*s",
varbuf
, yp
-> yp_optcontrol
, level
* 4, "");
printf ("%%{ %s%s = %g; %%}\n%*s",
var
, SVAL (yp
-> yp_varexp
),
val2real (yp
-> yp_default
), level
* 4, "");
if ((yp
-> yp_flags
& YP_OPTIONAL
) && direction
== YP_DECODER
) {
if (!top
&& !(yp
-> yp_flags
& (YP_ID
| YP_TAG
)))
printf ("dummy-for-default\n%*s", ++level
* 4, "");
printf ("%%{ %s -> optionals |= %s; %%}\n%*s",
varbuf
, yp
-> yp_optcontrol
, level
* 4, "");
if ((yp
-> yp_flags
& (YP_TAG
| YP_IMPLICIT
)) == (YP_TAG
| YP_IMPLICIT
))
if (yp
-> yp_flags
& YP_BOUND
)
printf ("%s < ", yp
-> yp_bound
);
if (yp
-> yp_flags
& YP_COMPONENTS
)
printf ("COMPONENTS OF ");
if (yp
-> yp_flags
& YP_ENCRYPTED
)
printf (top
? "\n%*s[[b %s -> %s ]]" : "\n%*s[[b %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf (top
? "\n%*s[[i %s -> %s ]]" : "\n%*s[[i %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
if (yp
-> yp_code
== YP_ENUMLIST
)
printf (top
? "\n%*s[[i %s -> %s ]]\n%*s{\n"
: "\n%*s[[i %s%s ]]\n%*s{\n",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
),
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
printf ("%*s%s(%d)%s\n", level
* 4, "", yv
-> yv_named
,
val2int (yv
), yv
-> yv_next
? "," : "");
printf ("%*s}", level
* 4, "");
printf ("\n%*s[[x bit_parm = bitstr2strb (%s%s, &len) $ len]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf ("\n%*s%%{\n%*sfree (bit_parm);\n", level
* 4, "",
printf ("%*s%s\n", (level
+ 1) * 4, "", action2
);
printf ("%*s%%}\n", level
* 4, "");
balloc (yp
, var
, action2
, level
);
printf ("\n%*s[[x bit_parm = bitstr2strb (%s%s, &len) $ len]]\n%*s{\n",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
),
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
printf ("%*s%s(%d)%s\n", level
* 4, "", yv
-> yv_named
,
val2int (yv
), yv
-> yv_next
? "," : "");
printf ("%*s}", level
* 4, "");
balloc (yp
, var
, action2
, level
);
printf ("\n%*s%%{\n%*sfree (bit_parm);\n", level
* 4, "",
printf ("%*s%s\n", (level
+ 1) * 4, "", action2
);
printf ("%*s%%}\n", level
* 4, "");
printf ("\n%*s[[q %s%s ]]", level
* 4, "",
var
, SVAL (yp
-> yp_varexp
));
printf ("\n%*s[[q %s%s ]]", level
* 4, "",
var
, SVAL (yp
-> yp_varexp
));
printf (top
? "\n%*s[[r %s -> %s ]]" : "\n%*s[[r %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf ("%s", tags
[yp
-> yp_code
]);
printf ("\n%*s[[a %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
ep
= yp
-> yp_code
!= YP_SETTYPE
? "element" : "member";
printf ("%s\n", tags
[yp
-> yp_code
]);
if ((y
= yp
-> yp_type
) -> yp_declexp
) {
printf ("%*s%%{ %s = %s; %%}\n",
(level
+ 1) * 4, "", y
-> yp_declexp
,
printf ("%*s<<n_parm = 0; ", (level
+ 1) * 4, "");
printf ("n_parm < parm -> nelem; n_parm++>>\n");
printf ("%*s<<n_%s = 0;\n%*sn_%s < %s -> nelem;\n",
(level
+ 1) * 4, "", yp
-> yp_declexp
,
(level
+ 3) * 4, "", yp
-> yp_declexp
,
(level
+ 3) * 4, "", yp
-> yp_declexp
);
printf ("%*s<<; parm; parm = parm -> next>>\n",
printf ("%*s<<%s = %s%s;\n%*s%s;\n%*s%s = %s -> next>>\n",
(level
+ 1) * 4, "", yp
-> yp_declexp
,
var
, SVAL (yp
-> yp_varexp
),
(level
+ 3) * 4, "", yp
-> yp_declexp
,
(level
+ 3) * 4, "", yp
-> yp_declexp
,
xalloc (y
, 0, level
+ 2, y
-> yp_declexp
,
xalloc (yp
, 0, level
+ 1,
top
? "parm" : yp
-> yp_declexp
,
top
? modsym (mymodule
, eval
, "type")
do_type1 (yp
-> yp_type
, 0, level
+ 1, ep
, "", NULLCP
, direction
);
printf ("\n%*s%%{ ", (level
+ 1) * 4, "");
printf ("n_%s++;", top
? "parm" : yp
-> yp_declexp
);
if ((yp
-> yp_type
) && (yp
-> yp_type
-> yp_declexp
))
printf(" %s ++;", yp
-> yp_type
-> yp_declexp
);
printf ("parm = &((*parm) -> next);");
printf ("%s = &((*%s) -> next);",
yp
-> yp_declexp
, yp
-> yp_declexp
);
ep
= yp
-> yp_code
!= YP_SETLIST
? "element" : "member";
printf ("%s", tags
[yp
-> yp_code
]);
printf ("\n%*s%%{\n", (level
+ 1) * 4, "");
if (direction
== YP_DECODER
)
xalloc (yp
, 1, level
+ 2, yp
-> yp_declexp
,
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
y
-> yp_declexp
, y
-> yp_varexp
);
printf ("%*s%s = &(%s);\n",
y
-> yp_declexp
, y
-> yp_varexp
);
if (direction
== YP_DECODER
&&
y
-> yp_flags
& YP_DEFAULT
) {
prime_default (y
, level
+ 2);
printf ("%*s%%}\n%*s{\n", (level
+ 1) * 4, "",
if (!hflag
|| !(y
= yp
-> yp_type
) || y
-> yp_next
) {
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
level
+ ((y
-> yp_flags
& (YP_ID
| YP_TAG
)) ? 1 : 2),
ep
, var
, NULLCP
, direction
);
printf ("%s\n", y
-> yp_next
? ",\n" : "");
printf ("%*s}", level
* 4, "");
if (!hflag
|| !(y
= yp
-> yp_type
) || y
-> yp_next
)
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
)
printf ("\n%*s%%{\n", (level
+ 1) * 4, "");
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
)
printf ("%*s%s = %s;\n", (level
+ 2) * 4, "",
y
-> yp_declexp
, y
-> yp_varexp
);
printf ("%*s%%}\n%*s", (level
+ 1) * 4, "",
(level
+ 1) * 4 - 1, "" );
printf (" <<parm -> offset>>");
printf (" <<%s -> offset>>",
printf (i
? "\n%*s{\n" : " {\n", level
* 4, "");
xalloc (yp
, 0, level
+ 1, yp
-> yp_declexp
,
printf ("%*s{\n", level
* 4, "");
if (direction
== YP_DECODER
) {
(void) sprintf (cp
= buffer
, "(*(%s)) -> offset = ",
top
? "parm" : yp
-> yp_declexp
);
if (!hflag
|| !(y
= yp
-> yp_type
) || y
-> yp_next
)
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
(void) sprintf (cp
, "%s;", y
-> yp_offset
);
do_type1 (y
, top
, level
+ 1, "choice", var
,
cp
? buffer
: NULLCP
, direction
);
printf ("%s\n", y
-> yp_next
? ",\n" : "");
printf ("%*s}", level
* 4, "");
printf ("OBJECT IDENTIFIER");
printf ("\n%*s[[O %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
if (yp
-> yp_module
&& strcmp (yp
-> yp_module
, mymodule
))
printf ("%s.", yp
-> yp_module
);
printf ("%s", yp
-> yp_identifier
);
printf ("\n%*s[[p %s%s ]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf ("\n%*s[[p &(%s%s)]]",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
myyerror ("unknown type: %d", yp
-> yp_code
);
if (direction
== YP_ENCODER
)
if (direction
== YP_DECODER
)
printf ("\n%*s%%{ %s %%}", level
* 4, "", action2
);
if (yp
-> yp_flags
& YP_OPTIONAL
) {
printf ("\n%*sOPTIONAL", level
* 4, "");
if (direction
== YP_ENCODER
)
printf (" <<%s -> optionals & %s >>",
varbuf
, yp
-> yp_optcontrol
);
printf (" <<%s%s>>", var
, SVAL (yp
-> yp_varexp
));
if (yp
-> yp_flags
& YP_DEFAULT
) {
printf ("\n%*sDEFAULT ", level
* 4, "");
val2prf (yp
-> yp_default
, level
+ 2);
if (direction
== YP_ENCODER
)
val2int (yp
-> yp_default
) ? "!" : "",
var
, SVAL (yp
-> yp_varexp
));
printf (" <<%s%s != %d>>", var
, SVAL (yp
-> yp_varexp
),
printf (" << %s%s != %g >>",
var
, SVAL (yp
-> yp_varexp
),
val2real (yp
-> yp_default
));
printf (" <<%s%s>>", var
, SVAL (yp
-> yp_varexp
));
if (direction
== YP_ENCODER
&& (cp
= index (yp
-> yp_varexp
, ' '))
&& strncmp (cp
+ 1, "-> ", 3) == 0) {
(void) sprintf (buffer
, "(*%s) -> %s", yp
-> yp_varexp
, cp
+ 4);
yp
-> yp_varexp
= new_string (buffer
);
static YP
lookup_type (mod
, id
)
for (sy
= mysymbols
; sy
; sy
= sy
-> sy_next
) {
if (strcmp (sy
-> sy_module
, mod
))
if (strcmp (sy
-> sy_module
, mymodule
)
&& strcmp (sy
-> sy_module
, "UNIV"))
if (strcmp (sy
-> sy_name
, id
) == 0)
static posy (yp
, top
, level
, id
, val
, var
, arrayflg
)
(void) strcpy (bp
= buf2
, var
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*schar %s;\n", level
* 4, "",
yp
-> yp_varexp
= new_string (buf2
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sinteger %s;\n", level
* 4, "",
yp
-> yp_varexp
= new_string (buf2
);
if (yp
-> yp_code
== YP_INT
)
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
) {
modsym_aux (yv
-> yv_named
, buf1
);
fprintf (fdef
, "#define\t%s_%s\t%d\n",
modsym (mymodule
, top
? eval
: id
, "int"),
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sPE %s;\n", level
* 4, "",
fprintf (fact
, "%*sif (%s)\n", level
* 4, "", buf2
);
"%*spe_free (%s),\n%*s%s = NULLPE;\n",
(level
+ 1) * 4, "", buf2
,
(level
+ 2) * 4, "", buf2
);
yp
-> yp_varexp
= new_string (buf2
);
if (yp
-> yp_code
!= YP_BITLIST
)
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
if ((j
= val2int (yv
)) < 0)
pyyerror (yp
, "invalid bit number in BIT STRING");
if (i
< sizeof (int) * 8) { /* NBBY */
fprintf (fdef
, "#define\t%s\t\"\\020",
modsym (mymodule
, top
? eval
: id
, "bits"));
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
)
if (yv
-> yv_flags
& YV_NAMED
)
fprintf (fdef
, "\\0%o%s",
val2int (yv
) + 1, yv
-> yv_named
);
fprintf (fdef
, "\\0%oBIT%d",
val2int (yv
) + 1, val2int (yv
));
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
) {
modsym_aux (yv
-> yv_named
, buf1
);
fprintf (fdef
, "#define\t%s_%s\t%d\n",
modsym (mymodule
, top
? eval
: id
, "bit"),
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sdouble %s;\n", level
* 4, "",
yp
-> yp_varexp
= new_string (buf2
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sstruct qbuf *%s;\n", level
* 4, "",
fprintf (fact
, "%*sif (%s)\n", level
* 4, "", buf2
);
"%*sqb_free (%s),\n%*s%s = NULL;\n",
(level
+ 1) * 4, "", buf2
,
(level
+ 2) * 4, "", buf2
);
yp
-> yp_varexp
= new_string (buf2
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*schar %s;\n", level
* 4, "",
if (yp
-> yp_flags
& YP_OPTIONAL
)
yp
-> yp_varexp
= new_string (buf2
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sPE %s;\n", level
* 4, "",
fprintf (fact
, "%*sif (%s)\n", level
* 4, "", buf2
);
"%*spe_free (%s),\n%*s%s = NULLPE;\n",
(level
+ 1) * 4, "", buf2
,
(level
+ 2) * 4, "", buf2
);
yp
-> yp_varexp
= new_string (buf2
);
ep
= yp
-> yp_code
!= YP_SETTYPE
? "element" : "member";
if ((cp
= rindex (buf2
, ' ')) && *++cp
) {
if ((dp
= rindex (cp
, '.')) && *++dp
)
(void) sprintf (dp
= buf1
, "%*.*s",
cp
- buf2
, cp
- buf2
, buf2
);
(void) strcpy (buf1
, buf2
);
newid
= yp
-> yp_ptrname
? yp
-> yp_ptrname
: id
;
fprintf (fdef
, "%*sint\tnelem;\n", level
* 4, "");
id
= yp
-> yp_structname
;
id
= gensym (ep
, NULLCP
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sstruct %s {\n", level
* 4, "", id
);
fprintf (fdef
, "%*sint\tnelem;\n", (level
+ 1) * 4, "");
(void) strcpy (dp
, newid
);
(void) strcpy (bp
= buf2
, id
);
yp
-> yp_declexp
= new_string (id
);
(void) strcpy (dp
, newid
);
yp
-> yp_varexp
= new_string (buf1
);
if ((y
= yp
-> yp_type
) -> yp_code
== YP_IDEFINED
&& hflag
) {
modsym_aux (y
-> yp_identifier
, cp
= buf3
);
(void) sprintf (cp
, "[n_%s]", PARVAL (yp
->yp_declexp
));
cp
= gensym (ep
, h2flag
? PARVAL(yp
->yp_declexp
) : NULLCP
);
cp
= gensym (ep
, NULLCP
);
(void) sprintf (bp
, " -> %s", cp
);
fprintf (fact
, "%*s{\n", level
* 4, "");
fprintf (fact
, "%*sint n_%s;\n",
level
* 4, "", PARVAL (yp
->yp_declexp
));
fprintf (fact
, "%*sstruct %s *%s = %s;\n\n",
level
* 4, "", id
, id
, var
);
fprintf (fact
, "%*sstruct %s *%s;\n\n",
fprintf (fact
, "%*sfor (n_%s = 0;\n",
level
* 4, "", PARVAL(yp
-> yp_declexp
));
fprintf (fact
, "%*sn_%s < %s -> nelem;\n",
(level
+ 2) * 4, "", PARVAL(yp
->yp_declexp
), id
);
fprintf (fact
, "%*sn_%s++) {\n",
(level
+ 2) * 4, "", PARVAL(yp
->yp_declexp
));
"%*sfor (%s = %s; %s;) {\n",
level
* 4, "", id
, buf1
, id
);
fprintf (fact
, "%*sstruct %s *f_%s = %s -> next;\n\n",
top
? modsym (mymodule
, val
, "type") : id
,
posy (y
, 0, level
, cp
, ep
, buf2
, h2flag
);
if (y
-> yp_code
!= YP_IDEFINED
)
fprintf (fdef
, "\n%*sstruct %s *next;\n", level
* 4, "",
top
? modsym (mymodule
, val
, "type") : id
);
(void) strcpy (bp
= buf2
, var
);
fprintf (fact
, "\n%*sif (%s)\n%*sfree ((char *) %s);",
(level
+ 2) * 4, "", id
);
fprintf (fact
, "\n%*s%s = f_%s;", (level
+ 1) * 4, "",
fprintf (fact
, "\n%*s}\n", level
* 4, "");
fprintf (fact
, "\n%*s%s = NULL;\n",
fprintf (fact
, "\n%*s%s = NULL;\n",
level
* 4, "", yp
-> yp_varexp
);
fprintf (fact
, "%*s}\n", level
* 4, "");
fprintf (fdef
, "%*s} *%s;\n", level
* 4, "",
ep
= yp
-> yp_code
!= YP_SETLIST
? "element" : "member";
if ((cp
= rindex (buf2
, ' ')) && *++cp
) {
if ((dp
= rindex (cp
, '.')) && *++dp
)
(void) sprintf (dp
= buf1
, "%*.*s",
cp
- buf2
, cp
- buf2
, buf2
);
(void) strcpy (buf1
, buf2
);
newid
= yp
-> yp_ptrname
? yp
-> yp_ptrname
: id
;
id
= yp
-> yp_structname
;
id
= gensym (ep
, NULLCP
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sstruct %s {\n", level
* 4, "", id
);
(void) strcpy (dp
, newid
);
fprintf (fact
, "%*sif (%s) {\n",
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
fprintf (fact
, "%*sstruct %s *%s = %s;\n\n",
(level
+ 1) * 4, "", id
, id
, buf1
);
(void) strcpy (bp
= buf2
, id
);
yp
-> yp_declexp
= new_string (id
);
(void) strcpy (dp
, newid
);
yp
-> yp_varexp
= new_string (buf1
);
for (y
= yp
-> yp_type
, i
= 0; y
; y
= y
-> yp_next
) {
if (y
-> yp_flags
& YP_OPTIONAL
)
fprintf (fdef
, "%*sint optionals;\n",
if (y
-> yp_flags
& YP_ID
)
modsym_aux (y
-> yp_id
, cp
= buf1
);
cp
= gensym (ep
, NULLCP
);
(void) strcpy (buf1
, cp
);
(void) sprintf (obuf
, "%s_%s",
fprintf (fdef
, "#define\t%s (0%08o)\n", obuf
,
y
-> yp_optcontrol
= new_string (obuf
);
y
-> yp_flags
|= YP_OPTCONTROL
;
if (i
>= 8 * sizeof (int))
yyerror ("too many optionals in structure");
if (i
> 0) fprintf (fdef
, "\n");
for (y
= yp
-> yp_type
, i
= 1; y
; y
= y
-> yp_next
, i
++) {
if (y
-> yp_flags
& YP_ID
)
modsym_aux (y
-> yp_id
, cp
= buf1
);
cp
= gensym (ep
, NULLCP
);
(void) sprintf (bp
, " -> %s", cp
);
posy (y
, 0, level
, cp
, ep
, buf2
, 0);
if (!(y
-> yp_flags
& YP_ID
))
fprintf (fdef
, "%*schar dummy;\n", level
* 4, "");
(void) strcpy (bp
= buf2
, var
);
fprintf (fact
, "\n%*sif (%s)\n%*sfree ((char *) %s);\n%*s%s = NULL;\n",
(level
+ 1) * 4, "", yp
-> yp_varexp
,
(level
+ 2) * 4, "", yp
-> yp_varexp
,
(level
+ 1) * 4, "", yp
-> yp_varexp
);
fprintf (fact
, "%*s}\n", level
* 4, "");
fprintf (fdef
, "%*s} *%s;\n", level
* 4, "",
if ((cp
= rindex (buf2
, ' ')) && *++cp
) {
if ((dp
= rindex (cp
, '.')) && *++dp
)
(void) sprintf (dp
= buf1
, "%*.*s",
cp
- buf2
, cp
- buf2
, buf2
);
(void) strcpy (buf1
, buf2
);
newid
= yp
-> yp_ptrname
? yp
-> yp_ptrname
: id
;
id
= yp
-> yp_structname
;
id
= gensym ("choice", NULLCP
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sstruct %s {\n", level
* 4, "", id
);
(void) strcpy (dp
, newid
);
fprintf (fact
, "%*sif (%s) {\n%*sstruct %s *%s = %s;\n\n",
(level
+ 1) * 4, "", id
, id
, buf1
);
(void) strcpy (bp
= buf2
, id
);
yp
-> yp_declexp
= new_string (id
);
(void) strcpy (dp
, newid
);
yp
-> yp_varexp
= new_string (buf1
);
fprintf (fdef
, "%*sint offset;\n", level
* 4, "");
fprintf (fact
, "%*sswitch (%s -> offset) {\n",
cp
= modsym (mymodule
, val
, "type");
(void) sprintf (ep
= buf1
, "%s_", cp
);
for (y
= yp
-> yp_type
, i
= 1; y
; y
= y
-> yp_next
, i
++) {
if (y
-> yp_flags
& YP_ID
)
modsym_aux (y
-> yp_id
, ep
);
(void) sprintf (ep
, "%d", i
);
y
-> yp_offset
= new_string (buf1
);
fprintf (fdef
, "#define\t%s\t%d\n", y
-> yp_offset
, i
);
fprintf (fdef
, "\n%*sunion {\n", level
* 4, "");
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
if (y
-> yp_flags
& YP_ID
)
modsym_aux (y
-> yp_id
, cp
= buf1
);
cp
= gensym ("choice", NULLCP
);
fprintf (fact
, "%*scase %s:\n", level
* 4, "",
(void) sprintf (bp
, " -> un.%s", cp
);
posy (y
, 0, level
, cp
, "choice", buf2
, 0);
fprintf (fact
, "%*sbreak;\n", level
* 4, "");
if (!(y
-> yp_flags
& YP_ID
))
fprintf (fdef
, "%*s} un;\n", level
* 4, "");
fprintf (fact
, "%*s}\n", level
* 4, "");
(void) strcpy (bp
= buf2
, var
);
fprintf (fact
, "\n%*sif (%s)\n%*sfree ((char *) %s);\n%*s%s = NULL;\n",
(level
+ 1) * 4, "", yp
-> yp_varexp
,
(level
+ 2) * 4, "", yp
-> yp_varexp
,
(level
+ 1) * 4, "", yp
-> yp_varexp
);
fprintf (fact
, "%*s}\n", level
* 4, "");
fprintf (fdef
, "%*s} *%s;\n", level
* 4, "",
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sOID %s;\n", level
* 4, "",
fprintf (fact
, "%*sif (%s)\n", level
* 4, "", buf2
);
"%*soid_free (%s),\n%*s%s = NULLOID;\n",
(level
+ 1) * 4, "", buf2
,
(level
+ 2) * 4, "", buf2
);
yp
-> yp_varexp
= new_string (buf2
);
printag (yp
, level
+ 4, NULLCP
);
fprintf (fdef
, "%*sstruct %s *%s;\n", level
* 4, "",
modsym (yp
-> yp_module
, yp
-> yp_identifier
, "type"),
fprintf (fact
, "%*sif (%s)\n", level
* 4, "", buf2
);
"%*s%s (%s),\n%*s%s = NULL;\n",
modsym (yp
-> yp_module
, yp
-> yp_identifier
, "free"),
buf2
, (level
+ 2) * 4, "", buf2
);
yp
-> yp_varexp
= new_string (buf2
);
myyerror ("unknown type: %d", yp
-> yp_code
);
static printag (yp
, level
, pullup
)
fprintf (fdef
, "%*s/* ", level
* 4, "");
if (yp
-> yp_module
&& strcmp (yp
-> yp_module
, mymodule
))
fprintf (fdef
, "%s.", yp
-> yp_module
);
fprintf (fdef
, "%s", yp
-> yp_identifier
);
fprintf (fdef
, "%s", tags
[yp
-> yp_code
]);
fprintf (fdef
, " pulled up from %s", pullup
);
static xalloc (yp
, top
, level
, arg
, type
, brackets
)
if (hflag
&& !arg
&& !type
)
if (brackets
&& !didone
) {
printf ("%*s%%{\n", level
* 4, "");
if (h2flag
&& (yp
-> yp_code
== YP_SEQTYPE
||
yp
-> yp_code
== YP_SETTYPE
)) {
printf ("%*s{\n%*sPE xx_pe = prim2%s ($$);\n\n",
level
* 4, "", (level
+1) * 4, "",
yp
-> yp_code
== YP_SEQTYPE
? "seq" : "set");
printf ("%*sn_%s = xx_pe -> pe_cardinal > 0 ",
(level
+ 1) * 4, "", arg
);
printf ("? xx_pe -> pe_cardinal : 0;\n%*s}\n", level
* 4, "");
printf ("%*sif ((*(%s) = (struct %s *)\n",
level
* 4, "", arg
, type
);
printf ("%*scalloc (1 + (unsigned) n_%s, sizeof **(%s)",
(level
+ 2) * 4, "", arg
, arg
);
printf (")) == ((struct %s *) 0)) {\n", type
);
printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n",
printf ("%*sreturn NOTOK;\n%*s}\n", (level
+ 1) * 4, "",
printf ("%*s(*%s) -> nelem = n_%s;\n", level
* 4, "", arg
, arg
);
printf ("%*sn_%s = 0;\n", level
* 4, "", arg
);
printf ("%*sif ((*(%s) = (struct %s *)\n",
level
* 4, "", arg
, type
);
printf ("%*scalloc (1, sizeof **(%s))) == ((struct %s *) 0)) {\n",
(level
+ 2) * 4, "", arg
, type
);
printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n",
printf ("%*sreturn NOTOK;\n%*s}\n", (level
+ 1) * 4, "",
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
)
if (h2flag
&& (yp
-> yp_code
== YP_SETLIST
||
yp
-> yp_code
== YP_SEQLIST
)) {
/* include allocation here - no chance later */
if (brackets
&& !didone
) {
printf ("%*s%%{\n", level
* 4, "");
printf ("%*s%s = &(%s);\n", level
* 4, "",
xalloc (y
, top
, level
, y
-> yp_declexp
,
if (brackets
&& !didone
) {
printf ("%*s%%{\n", level
* 4, "");
printf ("%*s%s = &(%s);\n",
level
* 4, "", y
-> yp_declexp
,
if (brackets
&& didone
) {
printf ("%*s%%}\n", level
* 4, "");
static balloc (yp
, var
, action2
, level
)
printf ("\n%*s%%{\n", level
* 4, "");
printf ("%*sif ((%s%s = prim2bit (pe_cpy ($$))) == NULLPE) {\n",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", (level
+ 1) * 4, "");
printf ("%*sreturn NOTOK;\n%*s}\n", (level
+ 1) * 4, "", level
* 4, "");
printf ("\n%*s%s\n", level
* 4, "", action2
);
printf ("%*s%%}", level
* 4, "");
static qalloc (yp
, var
, action2
, level
)
printf ("\n%*s%%{\n", level
* 4, "");
printf ("%*sif ((%s%s = str2qb ($$, $$_len, 1)) == ((struct qbuf *) 0)) {\n",
level
* 4, "", var
, SVAL (yp
-> yp_varexp
));
printf ("%*sadvise (NULLCP, \"%%s\", PEPY_ERR_NOMEM);\n", (level
+ 1) * 4, "");
printf ("%*sreturn NOTOK;\n%*s}\n", (level
+ 1) * 4, "", level
* 4, "");
printf ("\n%*s%s\n", level
* 4, "", action2
);
printf ("%*s%%}", level
* 4, "");
static choice_pullup (yp
, partial
)
for (x
= &yp
-> yp_type
; y
= *x
; x
= &y
-> yp_next
) {
if (y
-> yp_flags
& (YP_TAG
| YP_BOUND
))
if ((z
= lookup_type (y
-> yp_module
, y
-> yp_identifier
))
|| z
-> yp_code
!= YP_CHOICE
)
choice_pullup (z2
= copy_type (z
), CH_FULLY
);
choice_pullup (z2
= copy_type (y
), CH_FULLY
);
z2
-> yp_next
= y
-> yp_next
;
for (z1
= &z
-> yp_next
; z2
= *z1
; z1
= &z2
-> yp_next
)
static components_pullup (yp
)
for (x
= &yp
-> yp_type
; y
= *x
; x
= &y
-> yp_next
) {
if (!(y
-> yp_flags
& YP_COMPONENTS
))
if ((z
= lookup_type (y
-> yp_module
, y
-> yp_identifier
))
warning ("COMPONENTS OF target \"%s\" is undefined",
if (yp
-> yp_code
!= z
-> yp_code
) {
warning ("COMPONENTS OF target \"%s\" is wrong type, should be %s",
y
-> yp_code
== YP_IDEFINED
? y
-> yp_identifier
: y
-> yp_id
? y
-> yp_id
yp
-> yp_code
== YP_SEQLIST
? "SEQUENCE" : "SET");
if (z
-> yp_type
== NULLYP
)
components_pullup (z
= copy_type (z
));
for (x
= &z
-> yp_type
; z1
= *x
; x
= &z1
-> yp_next
)
yyerror ("need an integer, not a string");
yyerror ("haven't written symbol table for values yet");
yyerror ("need an integer, not NULL");
myyerror ("unknown value: %d", yv
-> yv_code
);
static double val2real (yv
)
yyerror ("need an integer, not a string");
yyerror ("haven't written symbol table for values yet");
yyerror ("need an integer, not NULL");
myyerror ("unknown value: %d", yv
-> yv_code
);
static val2prf (yv
, level
)
if (yv
-> yv_flags
& YV_ID
)
printf ("%s ", yv
-> yv_id
);
if (yv
-> yv_flags
& YV_TYPE
) /* will this REALLY work??? */
do_type1 (yv
-> yv_type
, 0, level
, NULLCP
, NULLCP
, NULLCP
, NULL
);
printf (yv
-> yv_number
? "TRUE" : "FALSE");
printf ("%s", yv
-> yv_named
);
printf ("%d", yv
-> yv_number
);
dump_real (yv
-> yv_real
);
printf ("\"%s\"", yv
-> yv_string
);
printf ("%s.", yv
-> yv_module
);
printf ("%s", yv
-> yv_identifier
);
for (y
= yv
-> yv_idlist
; y
; y
= y
-> yv_next
) {
printf (y
-> yv_next
? ", " : " ");
myyerror ("unknown value: %d", yv
-> yv_code
);
cp
= ecvt (r
, 20, &decpt
, &sign
);
(void) strcpy (sbuf
, cp
); /* cp gets overwritten by printf */
printf ("{ %s%s, 10, %d }", sign
? "-" : "", sbuf
,
(void) sprintf (sbuf
, "%.19e", r
);
if (dp
[1] != '.' || (cp
= index (dp
, 'e')) == NULL
) {
printf ("{ 0, 10, 0 } -- %s --", sbuf
);
printf ("{ %s%c%s, 10, %d }",
sp
, *dp
, dp
+ 2, atoi (cp
) - strlen (dp
+ 2));
yyerror ("need an integer, not a string");
yyerror ("need an integer, not a real");
for (y
= yp
-> yp_value
; y
; y
= y
-> yv_next
)
if (y
-> yv_code
== YV_NUMBER
&& (y
-> yv_flags
& YV_NAMED
)
&& strcmp (yv
-> yv_identifier
, y
-> yv_named
) == 0)
yyerror ("haven't written symbol table for values yet");
yyerror ("need an integer, not NULL");
myyerror ("unknown value: %d", yv
-> yv_code
);
fprintf (stderr
, "%*scode=0x%x flags=%s direction=0x%x\n", level
* 4, "",
yp
-> yp_code
, sprintb (yp
-> yp_flags
, YPBITS
),
"%*sintexp=\"%s\" strexp=\"%s\" prfexp=0%o declexp=\"%s\" varexp=\"%s\"\n",
level
* 4, "", yp
-> yp_intexp
, yp
-> yp_strexp
, yp
-> yp_prfexp
,
yp
-> yp_declexp
, yp
-> yp_varexp
);
fprintf (stderr
, "%*sparameter type=\"%s\"\n", level
* 4, "",
fprintf (stderr
, "%*saction0 at line %d=\"%s\"\n", level
* 4, "",
yp
-> yp_act0_lineno
, yp
-> yp_action0
);
fprintf (stderr
, "%*saction05 at line %d=\"%s\"\n", level
* 4, "",
yp
-> yp_act05_lineno
, yp
-> yp_action05
);
fprintf (stderr
, "%*saction1 at line %d=\"%s\"\n", level
* 4, "",
yp
-> yp_act1_lineno
, yp
-> yp_action1
);
fprintf (stderr
, "%*saction2 at line %d=\"%s\"\n", level
* 4, "",
yp
-> yp_act2_lineno
, yp
-> yp_action2
);
fprintf (stderr
, "%*saction3 at line %d=\"%s\"\n", level
* 4, "",
yp
-> yp_act3_lineno
, yp
-> yp_action3
);
if (yp
-> yp_flags
& YP_TAG
) {
fprintf (stderr
, "%*stag class=0x%x value=0x%x\n", level
* 4, "",
yp
-> yp_tag
-> yt_class
, yp
-> yp_tag
-> yt_value
);
print_value (yp
-> yp_tag
-> yt_value
, level
+ 1);
if (yp
-> yp_flags
& YP_DEFAULT
) {
fprintf (stderr
, "%*sdefault=0x%x\n", level
* 4, "", yp
-> yp_default
);
print_value (yp
-> yp_default
, level
+ 1);
if (yp
-> yp_flags
& YP_ID
)
fprintf (stderr
, "%*sid=\"%s\"\n", level
* 4, "", yp
-> yp_id
);
if (yp
-> yp_flags
& YP_BOUND
)
fprintf (stderr
, "%*sbound=\"%s\"\n", level
* 4, "", yp
-> yp_bound
);
fprintf (stderr
, "%*soffset=\"%s\"\n", level
* 4, "", yp
-> yp_offset
);
fprintf (stderr
, "%*svalue=0x%x\n", level
* 4, "", yp
-> yp_value
);
for (yv
= yp
-> yp_value
; yv
; yv
= yv
-> yv_next
) {
print_value (yv
, level
+ 1);
fprintf (stderr
, "%*s----\n", (level
+ 1) * 4, "");
fprintf (stderr
, "%*stype=0x%x\n", level
* 4, "", yp
-> yp_type
);
for (y
= yp
-> yp_type
; y
; y
= y
-> yp_next
) {
print_type (y
, level
+ 1);
fprintf (stderr
, "%*s----\n", (level
+ 1) * 4, "");
fprintf (stderr
, "%*smodule=\"%s\" identifier=\"%s\"\n",
level
* 4, "", yp
-> yp_module
? yp
-> yp_module
: "",
static print_value (yv
, level
)
fprintf (stderr
, "%*scode=0x%x flags=%s\n", level
* 4, "",
yv
-> yv_code
, sprintb (yv
-> yv_flags
, YVBITS
));
fprintf (stderr
, "%*saction at line %d=\"%s\"\n", level
* 4, "",
yv
-> yv_act_lineno
, yv
-> yv_action
);
if (yv
-> yv_flags
& YV_ID
)
fprintf (stderr
, "%*sid=\"%s\"\n", level
* 4, "", yv
-> yv_id
);
if (yv
-> yv_flags
& YV_NAMED
)
fprintf (stderr
, "%*snamed=\"%s\"\n", level
* 4, "", yv
-> yv_named
);
if (yv
-> yv_flags
& YV_TYPE
) {
fprintf (stderr
, "%*stype=0x%x\n", level
* 4, "", yv
-> yv_type
);
print_type (yv
-> yv_type
, level
+ 1);
fprintf (stderr
, "%*snumber=0x%x\n", level
* 4, "",
fprintf (stderr
, "%*sstring=\"%s\"\n", level
* 4, "",
if (yv
-> yv_flags
& YV_BOUND
)
fprintf (stderr
, "%*smodule=\"%s\" identifier=\"%s\"\n",
level
* 4, "", yv
-> yv_module
, yv
-> yv_identifier
);
fprintf (stderr
, "%*sbound identifier=\"%s\"\n",
level
* 4, "", yv
-> yv_identifier
);
for (y
= yv
-> yv_idlist
; y
; y
= y
-> yv_next
) {
print_value (y
, level
+ 1);
fprintf (stderr
, "%*s----\n", (level
+ 1) * 4, "");
static SY
new_symbol (encpref
, decpref
, prfpref
, mod
, id
, type
)
if ((sy
= (SY
) calloc (1, sizeof *sy
)) == NULLSY
)
yyerror ("out of memory");
sy
-> sy_encpref
= encpref
;
sy
-> sy_decpref
= decpref
;
sy
-> sy_prfpref
= prfpref
;
static SY
add_symbol (s1
, s2
)
for (sy
= s1
; sy
-> sy_next
; sy
= sy
-> sy_next
)
static MD
lookup_module (module
)
for (md
= mymodules
; md
; md
= md
-> md_next
)
if (strcmp (md
-> md_module
, module
) == 0)
if ((md
= (MD
) calloc (1, sizeof *md
)) == NULLMD
)
yyerror ("out of memory");
md
-> md_module
= new_string (module
);
md
-> md_next
= mymodules
;
if ((yp
= (YP
) calloc (1, sizeof *yp
)) == NULLYP
)
yyerror ("out of memory");
for (yp
= y
; yp
-> yp_next
; yp
= yp
-> yp_next
)
y
= new_type (yp
-> yp_code
);
y
-> yp_direction
= yp
-> yp_direction
;
y
-> yp_module
= new_string (yp
-> yp_module
);
y
-> yp_identifier
= new_string (yp
-> yp_identifier
);
y
-> yp_modid
= oid_cpy (yp
-> yp_modid
);
y
-> yp_type
= copy_type (yp
-> yp_type
);
y
-> yp_value
= copy_value (yp
-> yp_value
);
y
-> yp_intexp
= yp
-> yp_intexp
;
y
-> yp_strexp
= yp
-> yp_strexp
;
y
-> yp_prfexp
= yp
-> yp_prfexp
;
y
-> yp_declexp
= yp
-> yp_declexp
;
y
-> yp_varexp
= yp
-> yp_varexp
;
y
-> yp_structname
= new_string (yp
-> yp_structname
);
y
-> yp_ptrname
= new_string (yp
-> yp_ptrname
);
y
-> yp_param_type
= new_string (yp
-> yp_param_type
);
y
-> yp_action0
= new_string (yp
-> yp_action0
);
y
-> yp_act0_lineno
= yp
-> yp_act0_lineno
;
y
-> yp_action05
= new_string (yp
-> yp_action05
);
y
-> yp_act05_lineno
= yp
-> yp_act05_lineno
;
y
-> yp_action1
= new_string (yp
-> yp_action1
);
y
-> yp_act1_lineno
= yp
-> yp_act1_lineno
;
y
-> yp_action2
= new_string (yp
-> yp_action2
);
y
-> yp_act2_lineno
= yp
-> yp_act2_lineno
;
y
-> yp_action3
= new_string (yp
-> yp_action3
);
y
-> yp_act3_lineno
= yp
-> yp_act3_lineno
;
y
-> yp_flags
= yp
-> yp_flags
;
if (yp
-> yp_flags
& YP_DEFAULT
)
y
-> yp_default
= copy_value (yp
-> yp_default
);
if (yp
-> yp_flags
& YP_ID
)
y
-> yp_id
= new_string (yp
-> yp_id
);
if (yp
-> yp_flags
& YP_TAG
)
y
-> yp_tag
= copy_tag (yp
-> yp_tag
);
if (yp
-> yp_flags
& YP_BOUND
)
y
-> yp_bound
= new_string (yp
-> yp_bound
);
if (yp
-> yp_flags
& YP_PARMVAL
)
y
-> yp_parm
= new_string (yp
-> yp_parm
);
if (yp
-> yp_flags
& YP_CONTROLLED
)
y
-> yp_control
= new_string (yp
-> yp_control
);
if (yp
-> yp_flags
& YP_OPTCONTROL
)
y
-> yp_optcontrol
= new_string (yp
-> yp_optcontrol
);
y
-> yp_offset
= new_string (yp
-> yp_offset
);
y
-> yp_next
= copy_type (yp
-> yp_next
);
if ((yv
= (YV
) calloc (1, sizeof *yv
)) == NULLYV
)
yyerror ("out of memory");
for (yv
= y
; yv
-> yv_next
; yv
= yv
-> yv_next
)
y
= new_value (yv
-> yv_code
);
y
-> yv_flags
= yv
-> yv_flags
;
y
-> yv_action
= new_string (yv
-> yv_action
);
y
-> yv_act_lineno
= yv
-> yv_act_lineno
;
if (yv
-> yv_flags
& YV_ID
)
y
-> yv_id
= new_string (yv
-> yv_id
);
if (yv
-> yv_flags
& YV_NAMED
)
y
-> yv_named
= new_string (yv
-> yv_named
);
if (yv
-> yv_flags
& YV_TYPE
)
y
-> yv_type
= copy_type (yv
-> yv_type
);
y
-> yv_number
= yv
-> yv_number
;
y
-> yv_string
= new_string (yv
-> yv_string
);
y
-> yv_module
= new_string (yv
-> yv_module
);
y
-> yv_identifier
= new_string (yv
-> yv_identifier
);
y
-> yv_idlist
= copy_value (yv
-> yv_idlist
);
y
-> yv_next
= copy_value (yv
-> yv_next
);
if ((yt
= (YT
) calloc (1, sizeof *yt
)) == NULLYT
)
yyerror ("out of memory");
y
= new_tag (yt
-> yt_class
);
y
-> yt_value
= copy_value (yt
-> yt_value
);
if ((p
= malloc ((unsigned) (strlen (s
) + 1))) == NULLCP
)
yyerror ("out of memory");
"IA5String", PE_CLASS_UNIV
, PE_DEFN_IA5S
,
"ISO646String", PE_CLASS_UNIV
, PE_DEFN_IA5S
,
"NumericString", PE_CLASS_UNIV
, PE_DEFN_NUMS
,
"PrintableString", PE_CLASS_UNIV
, PE_DEFN_PRTS
,
"T61String", PE_CLASS_UNIV
, PE_DEFN_T61S
,
"TeletexString", PE_CLASS_UNIV
, PE_DEFN_T61S
,
"VideotexString", PE_CLASS_UNIV
, PE_DEFN_VTXS
,
"GeneralizedTime", PE_CLASS_UNIV
, PE_DEFN_GENT
,
"GeneralisedTime", PE_CLASS_UNIV
, PE_DEFN_GENT
,
"UTCTime", PE_CLASS_UNIV
, PE_DEFN_UTCT
,
"UniversalTime", PE_CLASS_UNIV
, PE_DEFN_UTCT
,
"GraphicString", PE_CLASS_UNIV
, PE_DEFN_GFXS
,
"VisibleString", PE_CLASS_UNIV
, PE_DEFN_VISS
,
"GeneralString", PE_CLASS_UNIV
, PE_DEFN_GENS
,
"EXTERNAL", PE_CLASS_UNIV
, PE_CONS_EXTN
,
"ObjectDescriptor", PE_CLASS_UNIV
, PE_PRIM_ODE
,
static char *modsym (module
, id
, prefix
)
register struct triple
*t
;
static char buffer
[BUFSIZ
];
for (t
= triples
; t
-> t_name
; t
++)
if (strcmp (t
-> t_name
, id
) == 0) {
modsym_aux (prefix
, buf1
);
modsym_aux (module
? module
: mymodule
, buf2
);
(void) sprintf (buffer
, "%s_%s_%s", buf1
, buf2
, buf3
);
(void) sprintf (buffer
, "%s_%s", buf2
, buf3
);
static modsym_aux (name
, bp
)
static char *gensym (s
, a
)
myyerror ("unknown gensym argument \"%s\"", s
);
(void) sprintf (buffer
, "%s_%s_%d[n_%s]", s
, modulename
, i
, a
);
(void) sprintf (buffer
, "%s_%s_%d", s
, modulename
, i
);
if ((p
= malloc ((unsigned) (strlen (buffer
) + 11))) == NULLCP
)
yyerror ("out of memory");
(void) strcpy (p
, buffer
);
/* pepy compatible routines - you know how it is ... */
static char *array (s
, flg
)
if (p
= index (s
, '[')) {
(void) sprintf (buf
, "%*.*s[1]", p
- s
, p
- s
, s
);
static void prime_default (yp
, level
)
printf ("%*s%s = %d;\n", level
* 4, "",
val2int (yp
-> yp_default
) ? 1 : 0);
printf ("%*s%s = %d;\n", level
* 4, "",
SVAL (yp
-> yp_varexp
), val2int (yp
-> yp_default
));
printf ("%*s%s = %d;\n", level
* 4, "",
SVAL (yp
-> yp_varexp
), dfl2int (yp
));
printf ("%*s%s = %g;\n", level
* 4, "",
val2real (yp
-> yp_default
));