📄 asn_read.c
字号:
}
if (*token != '(') syntax(function_w);
*c++ = '(';
for (tmp = 1; c < &itemname[BSIZE] && get_token(fd, token, (char)0); )
{
if (c[-1] != '(' && *token != ')') *c++ = ' ';
c = cat(c, token);
if (*token == '(') tmp++;
else if (*token == ')' && !(--tmp)) break;
}
if (*token != ')') syntax(function_w);
}
else if (!strcmp(token, implicit_w))
{
explicit &= ~1;
if (*subclass && (ntbp = find_name(subclass)) &&
ntbp->name)
{
if (type < 0) type = ntbp->type;
else if (ntbp->type != -1)
type |= (ntbp->type & ASN_CONSTRUCTED);
}
}
else if (!strcmp(token, in_w))
{
if (!*definer) syntax(token);
if (!get_token(fd, inclass, '(')) syntax(definer);
}
else if (!strcmp(token, of_w)) syntax(token);
else if (!strcmp(token, optional_w)) option |= ASN_OPTIONAL_FLAG;
else if (!strcmp(token, size_w)) get_size(fd, token, &min, &max, parent);
else if (!strcmp(token, table_w))
{
if (!get_token(fd, tablename, '{')) syntax(table_w);
if (*tablename < 'A' || *tablename > 'Z') syntax(tablename);
option |= ASN_TABLE_FLAG;
}
else if (!strcmp(token, tags_w));
else if (*token == '[')
{
tmp = get_tag(fd, token);
if (tag >= 0) tag |= tmp;
else tag = tmp;
}
else if (*token == '(')
{
if ((flags & ASN_ENUM_FLAG))
{
if (!get_token(fd, token, (char)0)) syntax(itemname);
if (*token >= '0' && *token <= '9')
for (c = token, tag = 0; *c; tag = (tag * 10) + *c++ - '0');
else
{
tag = find_ub(token);
add_child(token, parent, 0, (ulong)-1, 0);
}
if (!get_token(fd, token, (char)0)) syntax(itemname);
}
else get_paren(fd, token, &min, &max, parent);
}
else if ((tmp = (int)find_type(token)) != ASN_NOTYPE)
{
if ((flags & ASN_TABLE_FLAG) && (*subclass || type > 0))
append_subclasses(token);
else if (*subclass) syntax(token);
if (type < 0) type = (ulong)tmp;
else if ((explicit & 1)) subtype = tmp;
else if (tmp > 0) type |= (tmp & ASN_CONSTRUCTED);
get_expected(fd, tmp, token);
}
else if ((*token >= '0' && *token <= '9') || (idp = find_id(token)) ||
is_ub(token))
{
if (*token > '9')
{
if (idp) cat(token, idp->val);
else
{
add_name(token, -1, 0); /* keep it off the 'Defined but not
used' list */
sprintf(token, "%d", find_ub(token));
}
}
if ((flags & ASN_TABLE_FLAG)) cvt_number(numstring, token);
else if ((flags & ASN_ENUM_FLAG))
cat(cat(itemname, "e"), token);
idp = (struct id_table *)0;
}
else if ((*token >= 'A' && *token <= 'Z') || *token == '*')
{
if ((flags & ASN_TABLE_FLAG))
{
if (!strcmp(token, "NONE")) cat(token, "AsnNone");
if (*subclass || type > 0) append_subclasses(token);
else option |= set_name_option(subclass, token);
}
else if (type > 0 || *subclass) syntax(token);
else option |= set_name_option(subclass, token);
}
else if (*token >= 'a' && *token <= 'z')
{
if ((flags & ASN_TABLE_FLAG)) array++;
if (*itemname) warn(12, token);
else cat(itemname, token);
}
if (!get_token(fd, token, (char)0)) return -1;
}
if (*definer && !*inclass) cat(inclass, classname);
return 0;
}
static void append_subclasses(uchar *name)
{
struct alt_subclass *altscp;
if (!alt_subclassp)
{
if (!(alt_subclassp = altscp =
(struct alt_subclass *)calloc(sizeof(struct alt_subclass), 1)))
fatal(7, (char *)0);
}
else
{
for(altscp = alt_subclassp; *(altscp->name) && altscp->next; altscp =
altscp->next);
if (*(altscp->name))
{
if (!(altscp->next =
(struct alt_subclass *)calloc(sizeof(struct alt_subclass), 1)))
fatal(7, (char *)0);
altscp = altscp->next;
}
}
cat(altscp->name, name);
if (*altscp->name == '*') *altscp->name = '_';
}
void cvt_number(char *to, char *from)
{
char *c;
int base, val, val2;
for (c = from; *c && *c != '.'; c++);
if (*c == '.')
{
for (val = 0; *from && *from != '.' && *from >= '0' && *from <= '9';
val = (val * 10) + *from++ - '0');
val *= 40;
if (*from != '.') syntax(from);
for(from++, val2 = 0; *from && *from != '.' && *from >= '0' && *from <= '9';
val2 = (val2 * 10) + *from++ - '0');
if (*from && *from != '.') syntax(from);
c += putobjid((c = to), (val + val2), 0);
if (*from) from++;
while(*from)
{
for (val = 0; *from && *from != '.' && *from >= '0' && *from <= '9';
val = (val * 10) + *from++ - '0');
c += putobjid(c, val, 0);
if (*from)
{
if (*from != '.') syntax(from);
from++;
}
}
}
else if (*from == '0' && (from[1] == 'x' || from[1] == 'X'))
{
for (from += 2, c = to; *from; )
{
if (*from >= 'a') *from -= 0x20;
if (*from >= 'A') *from -= 7;
val = *from++ - '0';
if (*from)
{
if (*from >= 'a') *from -= 0x20;
if (*from >= 'A') *from -= 7;
val = (val << 4) + *from++ - '0';
}
c += putoct(c, val);
}
}
else
{
if (*from != '0') base = 10;
else base = 8;
for(val = 0, c = to; *from; val = (val * base) + *from++ - '0');
c += putoct(c, val);
}
}
static void do_components(int fd, void(*func)())
{
/**
Function: Handles COMPONENTS OF in an item
Procedure:
1. IF no next token OR it's not 'OF' OR no next token OR item is not in table
OR it's imported, syntax error
IF no function
Add token as a child of classname
Return
Save current file position
2. Go to where item starts
Read tokens until '{' is found
3. Call function
Go back to saved place in file
Keep reading until ',' or '}'
**/
struct name_table *ntbp;
long pos;
if (lseek(fd, 0L, 1) < real_start) return;
if (!get_token(fd, token, (char)0) || /* step 1 */
strcmp(token, of_w) ||
!get_token(fd, token, (char)0)) syntax(components_w);
if (!func)
{
add_child(token, add_name(classname, (long)0, 0), 0, (long)-1, 0);
*itemname = 'x'; /* to make the test for no itemname fail */
return;
}
if (!(ntbp = find_name(token))->name || !*ntbp->name || ntbp->pos < 0)
syntax(components_w);
pos = lseek(fd, 0L, 1);
curr_pos = lseek(fd, ntbp->pos, 0); /* step 2 */
for (*token = 0; get_token(fd, token, '(') && *token != '{'; );
if (*token != '{') syntax(components_w);
state = SUB_ITEM;
if (func) func(fd); /* step 3 */
curr_pos = lseek(fd, pos, 0);
state = IN_ITEM;
for (*token = 0; *token != ',' && *token != '}'; get_token(fd, token, '('));
end_item();
}
void end_definition()
{
*classname = *prevname = *path = *numstring = 0;
state = GLOBAL;
array = flags = 0;
end_item();
}
void end_item()
{
struct alt_subclass *altscp;
tag = type = subtype = -1;
classcount = min = max = option = 0;
*itemname = *subclass = *defaultname = *defined_by = (char)0;
if ((explicit & 2)) explicit = 3;
else explicit = 0;
for (altscp = alt_subclassp; altscp; altscp = altscp->next)
{
*(altscp->name) = 0;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -