📄 asn_hdr.c
字号:
if ((*dup_ansrp & ASN_OF_FLAG))
{
if (*subclass)
{
if (!*itemname)
*strcpy(itemname, subclass) |= 0x20;
}
if (subtype >= 0)
{
if (!*subclass) cat(itemname, array_w);
cat(subclass, get_derivation(ASN_DUPED_FLAG, subtype));
subtype = -1;
}
print_item(itemname, subclass, subtype, 0);
}
else if ((option & ASN_POINTER_FLAG))
fprintf(outstr, ptr_ops, &subclass[1], &subclass[1],
&subclass[1], &subclass[1]);
else
{
cat(itemname, classname);
*itemname |= 0x20;
print_item(itemname, c, type,
(option & ~(ASN_OF_FLAG)));
}
print_end(*dup_ansrp, 0);
}
}
}
if (state == IN_DEFINITION) return 0;
end_item();
return 1;
}
static int hdr_item(int fd, int dup_ansr, int numdefineds)
{
/**
1. IF the object is a TABLE
IF not last item, break out of case
Print table body & finale
Seek back to after TABLE
Set state to IN_DEFINITION
Append "Defined" to classname
ELSE IF object is a FUNCTION, print itemname as function definition
ELSE
2. IF object is a table, set type and subclass type from table
IF it's a DEFINED BY, make the subclass name
IF have a universal type AND a subclass, clear the type
IF no itemname
Make a lower case name from :
IF have a valid type, from last part of class anme
ELSE IF no subclass, dummy name
ELSE subclass
3. IF have subclass AND the actual type is universal primitive AND
it's not TABLE OR ENUM
IF no type so far, use type from replacement object
ELSE if no subtype so far, use type from " "
IF no subclass AND no type AND not ENUM, use "AsnNone" for subclass
Print the item with name, class and options
4. IF token is not a '}' (non-last item) do end_item
ELSE IF not doing any table stuff
IF not in COMPONENTS OF, print the finale
Return 0
ELSE (end of class for table or defined-by)
Set state to IN_DEFINITION
IF doing a defined item
Print the finale
IF that's the last defined set, return 0
ELSE bump up the name
ELSE
Print the table entry, constructor and finale
Set the DEFINED flag to make the defined class(es)
Get the table entry for the table
FOR each parent table (the derived ones), print the class definition
Set up for doing the defined class(es)
Go back to the start of the table definition
Return 1
**/
char *b, *c;
static int thisdefined;
int definee, tmp;
struct name_table *ntbp;
static struct name_table *ntablep, *ptbp;
struct parent *parentp;
if ((flags & (ASN_TABLE_FLAG | ASN_DEFINED_FLAG)) == ASN_TABLE_FLAG)
{
c = 0;
if (!*numstring) c = "numeric field";
else if (!*itemname) c = "item name";
if (c) fatal(20, c);
}
else if (type == ASN_FUNCTION)
fprintf(outstr, func_line, itemname);
else
{
/* step 2 */
if ((option & ASN_TABLE_FLAG))
{
type = -1;
mk_in_name(subclass, tablename, classname);
}
if (*defined_by)
{
ntbp = find_name(defined_by);
definee = ntbp - (struct name_table *)name_area.area;
if (!(b = find_child(defined_by)) ||
!(c = find_child(b))) fatal(19, defined_by);
ntbp = find_name(b);
b = cat(cat(subclass, c), "Defined");
for (parentp = &ntbp->parent, tmp = 0; parentp &&
parentp->index != definee; tmp++,
parentp = parentp->next);
if ((tmp -= 1) > 0) b[-1] += tmp;
*defined_by = 0;
}
if ((flags & ASN_DEFINED_FLAG) && thisdefined > 1)
set_alt_subtype(ntablep, thisdefined);
else if (type >= 0 && type < ASN_APPL_SPEC && *subclass) type = -1;
if (!*itemname)
{
if (type >= 0) c = &find_class(type)[3];
else if (!*subclass) c = "no_item";
else c = subclass;
*strcpy(itemname, c) |= 0x20;
}
/* step 3 */
if (*subclass && (ntbp = replace_name(subclass)) &&
ntbp->type < ASN_CONSTRUCTED &&
!(ntbp->flags & (ASN_TABLE_FLAG | ASN_ENUM_FLAG)))
{
if (type < 0) type = ntbp->type;
else if (subtype < 0) subtype = ntbp->type;
}
if (!*subclass && type < 0 && !(flags & ASN_ENUM_FLAG))
cat(subclass, "AsnNone");
print_item(itemname, subclass, type, option);
}
/* step 4 */
if (*token != '}') end_item(); /* not last */
else if (!(flags & ASN_TABLE_FLAG))
{ /* i.e. last but not TABLE or DEFINED BY */
if (state != SUB_ITEM) print_end(dup_ansr, 1); /* i.e. not in components */
return 0;
}
else
{
state = IN_DEFINITION;
if (flags & ASN_DEFINED_FLAG)
{
print_end(dup_ansr, 1);
if (thisdefined++ >= numdefineds) return 0;
else (classname[strlen(classname) - 1])++;
}
else
{
fprintf(outstr, table_line, array);
fprintf(outstr, constructor, classname, classname, classname);
fprintf(outstr, finale);
flags |= ASN_DEFINED_FLAG;
thisdefined = 1;
ntablep = find_name(classname);
for (parentp = &ntablep->parent; parentp; parentp = parentp->next)
{
if (parentp->index < 0) continue;
ptbp = &((struct name_table *)name_area.area)[parentp->index];
fprintf(outstr, opener, ptbp->name, classname);
if (ptbp->type == ASN_INTEGER || type == ASN_ENUMERATED)
fprintf(outstr, assign_num);
else if (ptbp->type == ASN_OBJ_ID) fprintf(outstr, assign_char);
fprintf(outstr, constructor, ptbp->name, ptbp->name, ptbp->name);
fprintf(outstr, finale);
}
strcat(classname, "Defined");
}
lseek(fd, tablepos, 0);
}
return 1;
}
static char *get_derivation(int dup_ansr, long loctype)
{
/**
Function: Determines name of proper class from which derived
Input: Bit mask from test_dup()
Output: Pointer to name
Procedure:
1. Get a tentative type:
IF there's a type, use that
ELSE IF this is a pointer, use "AsnPtr"
ELSE use "AsnObj"
2. IF it's just DUPED, use the proper type of "Asn*Array"
ELSE IF (it's OF OR DUPED) AND (it's a SET OR SEQUENCE)
IF it's both OF AND DUPED, use "AsnArrayOfSe*sOf"
ELSE IF it's POINTER AND OF, use "AsnPtrSe*Of"
ELSE IF it's POINTER ADN DUPED,
ELSE use "AsnSe*Of"
3. Return answer
**/
#define NUM_ASSIGN 1
#define CHAR_ASSIGN 2
static char derived_from[40], assign_table[] = "0110202000100000002222112";
char *c;
/* step 1 */
if (loctype >= 0) c = find_class(loctype);
else if ((option & ASN_POINTER_FLAG)) c = "AsnPtr";
else if (*subclass) c = subclass;
else c = "AsnObj";
/* step 2 */
if (dup_ansr == ASN_DUPED_FLAG) /* dup alone */
{
if (loctype >= sizeof(assign_table) || assign_table[loctype] == '0')
c = "AsnArray";
else if ((assign_table[loctype] & CHAR_ASSIGN)) c = "AsnStringArray";
else if ((assign_table[loctype] & NUM_ASSIGN)) c = "AsnNumericArray";
}
else if ((dup_ansr & ~ASN_POINTER_FLAG) &&
(loctype == ASN_SEQUENCE || loctype == ASN_SET))
{
if (dup_ansr == (ASN_OF_FLAG | ASN_DUPED_FLAG)) /* both */
cat(cat(cat(derived_from, "AsnArrayOf"), &c[3]), "sOf");
else if (dup_ansr == (ASN_POINTER_FLAG | ASN_OF_FLAG)) /* *Of */
cat(cat(derived_from, c), "Of");
else if (dup_ansr == (ASN_POINTER_FLAG | ASN_DUPED_FLAG))
cat(cat(cat(derived_from, "AsnPtrArray"), &c[3]), "Of");
else cat(cat(derived_from, c), "Of"); /* plain OF */
c = derived_from;
}
return c;
}
static void print_end(int dup_ansr, int mode)
{
if ((dup_ansr & ASN_DUPED_FLAG)) fprintf(outstr, index_op, classname);
if (mode || type < 0 || *subclass) fprintf(outstr, constructor, classname,
classname, classname);
fprintf(outstr, finale);
}
static void print_item(char *itemname, char *classname, long type,
int option)
{
/**
Procedure:
1. IF there's a type
IF can find the class name for it
Use that
IF option has the OF bit, append "Of" to class name
ELSE use classname as the class
2. Print the item with class and item names
**/
char buf[16], *c = classname;
if (!*c) c = "AsnObj";
else if (*itemname == '*') c++;
if (type >= 0 && type != ASN_CHOICE)
{
if (!(c = find_class(type))) c = classname;
else if ((option & ASN_OF_FLAG))
{
cat(cat(buf, c), "Of");
c = buf;
}
}
fprintf(outstr, any_item, c, itemname);
}
static void set_alt_subtype(struct name_table *ctbp, int thisdefined)
{
struct parent *parentp;
struct alt_subclass *altscp;
struct name_table *ptbp;
int tmp;
ulong ttype;
ctbp = &((struct name_table *)name_area.area)[ctbp->parent.index];
for (altscp = alt_subclassp, parentp = &ctbp->parent, tmp = 1;
tmp < thisdefined && altscp; parentp = parentp->next)
{
ptbp = &((struct name_table *)name_area.area)[parentp->index];
if ((ptbp->flags & ASN_DEFINED_FLAG))
{
if (++tmp >= thisdefined) break;
altscp = altscp->next;
}
}
*subclass = 0;
type = -1;
if ((ttype = find_type(altscp->name)) == ASN_NOTYPE)
cat(subclass, altscp->name);
else type = ttype;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -