⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 asn_pproc.c

📁 ASN.1语法解析代码
💻 C
📖 第 1 页 / 共 3 页
字号:
brackets = parens = signflag = 0;
loctype = -1;
*table = *itemname = 0;
do
    {
    if (!strcmp(token, encrypted_w)) encr_xform(fd, token);
    if (!strcmp(token, signed_w))
	{
	signflag |= ASN_FILLED_FLAG;
	get_token(fd, token, (char)0);
	}
    else if (!strcmp(token, table_w))
	{
	if (signflag)
	    {
	    get_token(fd, table, (char)0);
	    *token = 0;
	    }
	}
    else if (*token == '{' || !strcmp(token, of_w))             /* step 2 */
	{
	if ((*token == 'O' || fd) && *linendp > linebuf)
	    {
	    fprintf(str, linebuf);
	    *(*linendp = linebuf) = 0;
	    }
	if (*token == 'O')
	    {
	    if (*activep) putout(str, of_w);
	    if (!get_token(fd, token, (char)0)) syntax(of_w);
	    if ((tmp = find_type(token)) != ASN_NOTYPE)
		get_expected(fd, tmp, token);
	    if (tmp >= ASN_APPL_SPEC)
		{
		if (*activep) putout(str, token);
		*token = 0;
		state = GLOBAL;
		}
	    else     /* have a universal type */
		{
		state = GLOBAL;
		if (!get_token(fd, itemname, (char)0)) syntax(of_w);
		if (*itemname == '{')
		    {
		    cat(itemname, token);
		    for (c = &itemname[1]; *c > ' '; *c++ |= 0x20);
		    cat(cat(c, "In"), classname);
		    if (*activep)
			{
			fprintf(str, "%s\n\n", itemname);
			fprintf(str, sub_opener, itemname, token);
			}
		    cat(classname, itemname);
		    *itemname = *token = 0;
		    return IN_ITEM;
		    }
		else
		    {
		    if (*activep) fprintf(str, "%s\n", token);
		    cat(token, itemname);
		    }
		*itemname = 0;
		}
	    }
	else if (fd)
	    {
	    if (*activep) putout(str, token);
	    if (*activep < 2)
		{
		for(*token = 0; *token != '}'; )
		    {
		    if (!get_token(fd, token, '{')) fatal(14, token);
		    }
		if (*activep) fprintf(str, "}\n\n");
		*classname = 0;
		state = GLOBAL;
		}
	    *token = 0;
	    }
	if (*activep && !fd)
	    {
	    if (glob_type < 0 && *linendp > linebuf)
		{
		fprintf(str, linebuf);
		*(*linendp = linebuf) = 0;
		}
	    if (signflag)
		{
		fprintf(str, tobesigned, classname);
		fprintf(str, algsig, (*table)? classname: "");
		if (*table) fprintf(str, tabledef, classname, table);
		fprintf(str, objtobesigned, classname);
		strcat(classname, "ToBeSigned");
		}
	    }
	if (state != GLOBAL) state = IN_ITEM;
	else fflush(str);
	signflag = 0;
	*table = 0;
	}
    else if (*token == '(') parens++;                           /* step 3 */
    else if (*token == '[') brackets++;
    else if (*token == ')' || *token == ']')
	{
	if ((*token == ')' && !parens--) ||
	    (*token == ']' && !brackets--)) syntax(token);
	}
    else if (*token >= '0' && *token <= '9' && !parens && !brackets)
	{
	for (c = token, tmp = 0; *c >= '0' && *c <= '9';
	    tmp = (tmp * 10) + *c++ - '0');
	if (*activep) add_ub(classname, tmp);
	state = GLOBAL;
	*token = *classname = *(*linendp = linebuf) = 0;
	}
    else if ((tmp = find_type(token)) != ASN_NOTYPE)
	{
	get_expected(fd, (loctype = tmp), token);
	if (!fd) add_name(classname, loctype, 0);
	}
    else if ((*token > '9' || *token == '*') && !isreserved(token))
	{
	if (*subclass || loctype >= 0)
	    {
	    state = GLOBAL;
	    if (loctype >= 0 && (loctype & ASN_CONSTRUCTED))
		syntax(find_typestring(loctype));
	    }
	else cat(subclass, (*token == '*')? &token[1]: token);
	}
    if (*classname >= 'A' && *classname <= 'Z')             /* step 4 */
        {
    	if (state == GLOBAL)
	    {
	    if (*activep)
		{
        	if (*linendp > linebuf) fprintf(str, "%s\n", linebuf);
		if (fd && *token >= 'A' && *token <= 'Z')
		    add_import_item(imtbp, token);
                putout(str, "\n");
    		if (*subclass || loctype >= 0) putout(str, "\n");
		}
	    }
	else
	    {
            if (*activep)
		{
		if ((*linendp = cat(cat(*linendp,token),
                    ((*token == '{')? "\n    ": " "))) >= elinebuf)
                    syntax(linebuf);
		if (*activep > 0 && !strcmp(token, choice_w)) *activep = 2;
		}
	    *token = 0;
	    }
	}
    else *token = 0;
    }
while (state == IN_DEFINITION && pre_proc_get_token(fd, str, linebuf));
return state;
}

static int pre_proc_item(int fd, FILE *str, char *linebuf, char **linendp,
    char *elinebuf, int *activep, int in_sub, long glob_type)
{
/**
1. IF token is ENCRYPTED, call encrypted transformation
   IF token is COMPONENTS
	Append next token
	Make sure that token is OF
   ELSE IF token is FUNCTION, put all up through last ')' into token
   ELSE IF token is SIGNED
        Set signed flag
        IF next token is a tag
	    Save it
        ELSE
	    Make the Signedclass name in token (for this item) and in
                classname (for the substr)
	    IF not imported
                IF don't have the name yet, add it to the table
		ELSE cancel the signed flag to prevent output
   ELSE IF token is TABLE
        IF signed flag set
           Get table name
           Clear token
   ELSE IF token is DEFAULT
	Put it out
	IF next token is '{'
	    IF next token isn't '}', syntax error
	    Put EMPTY in token
   ELSE IF token is '{' OR OF
        Delete SET/SEQUENCE from line
	IF token is OF
	    Get next token and its expected sequel
	    IF no itemname, prepend one to linebuf
	IF there's no namebuf
	    IF there's no itemname
		Form one from loctype's class name
		Form itemnameInClassname
		Put that in linebuf
	    ELSE form itemnameInClassname
	    Capitalize it
	    Append it to linebuf
        IF no sub-file, make one
        ELSE use existing sub-file
	Get appropriate subclass name
	IF token was '{'
	    Print sub-opener to sub-file
	    Call pre_proc for rest of definition
	ELSE IF active
	    IF 2nd token is SET OR SEQUENCE OR CHOICE
		Form 2ndtokenInItemnameInClassname
		Set loctag to new value
		Print OF opener with itemnameInClassname, subclass,
		    OF, 2ndtokenInItemnameInClassname
            ELSE print the OF opener with itemnameInClassname,
		    subclass, OF, 2ndtoken
	Clear token
   ELSE IF token is ',' or '}'
        IF tag is BITSTRING, append BIT STRING to line
        IF signed flag is set
	    IF no sub-file, make one
	    ELSE use existing sub-file
            Put out signedname and signeddef lines
	    IF had a tag, put out tagclass line
	    ELSE put out thatword line
	    Put out algsig line
	    IF have table, put out tabledef lines
	    Clear signed flag and table name
	IF class is capitalized, append token to line
	Print line
	IF at end of items, set state to GLOBAL & print another \n
   ELSE IF no tag AND token is a known constructed type
	Set loctag
   ELSE IF no itemname AND (token is lower case OR numeric
        If alpha, copy token to itemname
	IF global type is OBJECT IDENTIFIER, add class to id_area
   IF classname is upper case AND have a token AND it's NOT \n
        Append token to line
	IF doing an import of a choice, add name of token to list of
	    imports, so its definition will be included
   IF state is GLOBAL (reached end of items)
	Put out another linefeed
        IF have subfile
            Read it in and out
            Close it
	IF this isn't top level, return
   Clear token
**/
FILE *substr = (FILE *)0;
char *b, *c, locclass[128], namebuf[128], subname[128], table[128];
int signflag, parens, tmp, locstate = IN_ITEM;
struct id_table *cidp, *pidp;
ulong loctag;
long loctype;
struct name_table *ntbp;
signflag = parens = loctag = 0;
*locclass = *namebuf = *subname = *table = 0;
do
    {
    if (!strcmp(token, encrypted_w)) encr_xform(fd, token);
    if (!strcmp(token, components_w))
	{
	for (b = token; *b; b++);
	*b++ = ' ';
	if (!get_token(fd, b, (char)0)) fatal(14, linebuf);
	if (strcmp(b, of_w)) syntax(b);
	}
    else if (!strcmp(token, function_w))
        {
        for(c = token; *c; c++);
        for (*c++ = ' ', parens = 0; c < &token[BSIZE] &&
            get_token(fd, c, (char)0); *c++ = ' ', *c = 0)
    	    {
            if (*c == '(') parens++;
    	    else if (*c == ')' && !(--parens)) break;
    	    while (*c) c++;
     	     }
        }
    else if (!strcmp(token, signed_w))
	{
	signflag |= ASN_FILLED_FLAG;
	get_token(fd, subclass, (char)0);
	if ((tmp = find_type(subclass)) != ASN_NOTYPE)
	    {
	    loctag = tmp;
	    *token = 0;
	    }
	else
	    {
	    if (*subclass != '*') strcat(strcpy(token, "Signed"), subclass);
	    else strcat(strcpy(token, "*Signed"), &subclass[1]);
	    strcpy(classname, (*token == '*')? &token[1]: token);
	    if (!fd)
		{
		if (!(ntbp = find_name(token))->name) add_name(token, -1, 0);
		else signflag = 0;
		}
	    }
	}
    else if (!strcmp(token, table_w))
	{
	if (signflag)
	    {
	    get_token(fd, table, (char)0);
	    *token = 0;
	    }
	}
    else if (!strcmp(token, default_w))
	{
	if ((*linendp = cat(cat(*linendp, token), " ")) >= elinebuf)
	    syntax(linebuf);
	if (!get_token(fd, token, '(')) syntax(classname);
	if (*token == '{')
	    {
	    if (!get_token(fd, token, '(') || *token != '}')
		syntax(classname);
	    cat(token, empty_w);
	    }
	}
    else if (*token == '{' || (loctag && !strcmp(token, of_w)))
				/* note: loctag is used for seq/set, but */
	{                       /* loctype is for object of OF */
	for(b = linebuf; *b; b++);
	for(c = find_typestring(loctag); b > linebuf && *b != '{'; )
	    {
	    while(b > linebuf && *(--b) <= ' ');
	    while(b > linebuf && b[-1] > ' ') b--;
	    if (!wdcmp(c, b))
		{
		for(c = b; *c > ' '; c++);
		while (*c && *c <= ' ') c++;
		if ((*linendp = cat(b, c)) >= elinebuf) syntax(linebuf);
		break;
		}
	    }
	if (*token == 'O')
	    {
	    if (!get_token(fd, &token[1], '(')) syntax(of_w);
	    if ((tmp = find_type(&token[1])))
		get_expected(fd, (loctype = tmp), &token[1]);
	    if (!*itemname)
		{
		*strcpy(itemname, &token[1]) |= 0x20;
		cat(namebuf, linebuf);
		if ((*linendp = cat(cat(cat(linebuf, itemname), " "),
		    namebuf)) >= elinebuf) syntax(linebuf);
		}
	    }
	if (!*namebuf)
	    {
	    if (!*itemname)
		{
		if ((*token == 'O' && (loctype < 0 || loctype >= ASN_APPL_SPEC))
                   || (*token != 'O' && !loctag)) syntax(token);
		cat(itemname, &find_class(((*token == 'O')? loctype:
                    loctag))[3]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -