📄 asn_pproc.c
字号:
*itemname |= 0x20;
mk_in_name(namebuf, itemname, classname);
if ((*linendp = cat(cat(*linendp, namebuf), " ")) >= elinebuf)
syntax(linebuf);
}
else mk_in_name(namebuf, itemname, classname);
*namebuf &= ~0x20;
if ((*linendp = cat(cat(*linendp, namebuf), " ")) >= elinebuf)
syntax(linebuf);
}
if (!substr) substr = make_substr();
if (!loctag) c = choice_w;
else if (loctag == ASN_BITSTRING) c = "BIT STRING";
else c = find_typestring(loctag);
if (*token == '{')
{
if (!signflag) fprintf(substr, sub_opener, namebuf, c);
else
{
fprintf(substr, signed_sub_opener, namebuf, c);
fprintf(substr, tobesigned, namebuf);
fprintf(substr, algsig, (*table)? namebuf: "");
if (*table) fprintf(substr, tabledef, namebuf, table);
fprintf(substr, objtobesigned, namebuf);
fprintf(substr, " {\n");
signflag = 0;
}
*token = 0;
cat(locclass, classname);
cat(classname, namebuf);
locstate = state;
pre_proc(fd, substr, 1);
state = locstate;
cat(classname, locclass);
}
else if (*activep)
{
if (*token == 'O' && (tmp & ASN_CONSTRUCTED))
{
mk_in_name(subname, &(find_class(tmp))[3], namebuf);
loctag = tmp;
fprintf(substr, of_opener, namebuf, c, of_w, subname);
cat(namebuf, subname);
}
else fprintf(substr, of_opener, namebuf, c, of_w, &token[1]);
}
*token = 0;
}
else if (*token == ',' || *token == '}')
{
if (signflag && *activep)
{
if (!substr) substr = make_substr();
putout(substr, classname);
fprintf(substr, signeddef);
if (loctag) fprintf(substr, tagclass, find_class(loctag));
else
{
c = (*subclass == '*')? &subclass[1]: subclass;
*c |= 0x20;
fprintf(substr, thatword, c, &classname[6]);
}
fprintf(substr, algsig, (*table)? classname: "");
if (*table) fprintf(substr, tabledef, classname, table);
}
if (*classname <= 'Z' && (*linendp = cat(*linendp, token)) >= elinebuf)
syntax(linebuf);
if (*activep) fprintf(str, " %s\n", linebuf);
if (*token == '}')
{
state = GLOBAL;
*token = *classname = *(*linendp = linebuf) = 0;
if (in_sub || get_token(fd, token, (char)0)) fprintf(str, "\n");
*activep = 1;
}
else *token = 0;
loctag = signflag = 0;
*(*linendp = linebuf) = *table = *subclass = *itemname = *namebuf = 0;
}
else if ((tmp = find_type(token)) > 0 && (tmp <
ASN_APPL_SPEC || tmp == ASN_CHOICE))
get_expected(fd, (loctag = tmp), token);
else if (!*itemname && ((*token >= 'a' && *token <= 'z') ||
(*token >= 'A' && *token <= 'Z') ||
(*token >= '0' && *token <= '9')))
{
if (*token > '9') cat(itemname, token);
if (glob_type == ASN_OBJ_ID && *activep)
{
for (b = linebuf; *b && *b != '{'; b++);
cidp = add_id(classname);
if (*token > '9')
{
for (pidp = (struct id_table *)id_area.area; pidp->name &&
strcmp(itemname, pidp->name); pidp++);
if (!pidp->name || !*pidp->name) fatal(18, itemname);
if (!get_token(fd, token, '(')) syntax(token);
c = pidp->val;
}
else c = "";
while (get_token(fd, linebuf, (char)0) && *linebuf != '}');
if (*linebuf != '}') fatal(14, linebuf);
if (!(cidp->val = calloc(strlen(c) + 2 +
strlen(token), 1))) fatal(7, (char *)0);
if (*c) cat(cat(cat(cidp->val, pidp->val), "."), token);
else cat(cidp->val, token);
state = GLOBAL;
*(*linendp = linebuf) = *classname = *token = 0;
}
}
if (*classname && *classname <= 'Z' && *token)
{
if (*token != '\n')
{
if ((*linendp = cat(cat(*linendp, token), " ")) >= elinebuf)
syntax(linebuf);
if (*activep > 1) add_import_item(imtbp, token);
}
*token = 0;
}
if (state == GLOBAL)
{
if (substr)
{
if (*linendp > linebuf) fatal(24, "pre-processor");
if (*activep) putout(str, "\n");
fseek(substr, 0L, 0);
while (*activep && fgets(linebuf, (elinebuf - linebuf), substr))
fputs(linebuf, str);
*linebuf = 0;
fclose(substr);
substr = (FILE *)0;
fflush(str);
}
loctype = -1;
}
}
while (state != GLOBAL && pre_proc_get_token(fd, str, linebuf));
if (state != GLOBAL) fatal(14, linebuf);
return state;
}
static struct import_table *add_import_item(struct import_table *timtbp,
char *itemname)
{
/**
Function: Adds an item to the import table
Inputs: Pointer to current element in import table. IF this is null, add
another element to table and use that
Outputs: import_item is added to the current element in table
Returns: Pointer to current element
Procedure:
1. IF no current element, get the next one in the table
ELSE append another item at the end of the chaun
2. Put the name in that new item
Return the element pointer
**/
char *c;
struct import_item *itemp = &timtbp->item;
/* step 1 */
if (!timtbp)
{
timtbp = (struct import_table *)expand_area(&import_area);
itemp= &timtbp->item;
}
else if (itemp->module)
{
while (itemp->next) itemp = itemp->next;
if (!(itemp->next =
(struct import_item *)calloc(sizeof(struct import_item), 1)))
fatal(7, (char *)0);
itemp = itemp->next;
}
/* step 2 */
for (c = itemname; *c; c++);
if (!(itemp->module = calloc((&c[1] - itemname), 1))) fatal(7, (char *)0);
cat(itemp->module, itemname);
return timtbp;
}
static void encr_xform(int fd, char *loctoken)
{
/**
Procedure:
1. Get next token (to discard)
IF it's a known type, get its expected sequel
Put BIT STRING into token
**/
long tmp;
if (!get_token(fd, loctoken, (char)0)) syntax(encrypted_w);
if ((tmp = find_type(loctoken)) != ASN_NOTYPE)
get_expected(fd, tmp, loctoken);
cat(loctoken, "BIT STRING");
}
static void free_imports()
{
struct import_table *timtbp, *eimtbp;
struct import_item *itemp, *nitemp;
for (timtbp = (struct import_table *)import_area.area,
eimtbp = &timtbp[import_area.next]; timtbp && timtbp < eimtbp; timtbp++)
{
for (itemp = timtbp->item.next; itemp; itemp = nitemp)
{
nitemp = itemp->next;
free(itemp->module);
free((char *)itemp);
}
free(timtbp->name);
}
free(import_area.area);
}
static void get_exports(int fd)
{
/**
Function: Reads the export list and checks the items
Procedure:
1. Add the exported items to the name table
2. IF in an imported file
Check that all items being imported are on the export list
3. IF any item on the export list is not being imported
Delete it (this is safe since no children have yet been tabulated)
**/
struct name_table *ntbp, *bntbp, *entbp, *lntbp;
struct import_item *itemp; /* step 1 */
int start = name_area.next;
for (*token = 0; get_token(fd, token, (char)0) && *token != ';' ; )
{
if (*token > ' ' && *token != ',')
add_name(token, (long)-1, ASN_EXPORT_FLAG);
}
bntbp = &((struct name_table *)name_area.area)[start];
entbp = &((struct name_table *)name_area.area)[name_area.next - 1];
if (imtbp && imtbp->name) /* step 2 */
{
for (itemp = &imtbp->item; itemp; itemp = itemp->next)
{
for (ntbp = bntbp; ntbp <= entbp && strcmp(ntbp->name, itemp->module);
ntbp++);
if (ntbp > entbp)
{
cat(classname, imports_w);
warn(21, itemp->module);
}
}
for (ntbp = bntbp; ntbp <= entbp; ) /* step 3 */
{
for (itemp = &imtbp->item; itemp && strcmp(ntbp->name, itemp->module);
itemp = itemp->next);
if (!itemp)
{
free(ntbp->name);
lntbp = &((struct name_table *)name_area.area)[--name_area.next];
memcpy((char *)ntbp, (char *)&ntbp[1], ((lntbp - ntbp) *
sizeof(struct name_table)));
memset((char *)entbp--, 0, sizeof(struct name_table));
}
else ntbp++;
}
}
}
static void get_fnames(int fd)
{
/**
Function: Builds import table
Procedure:
1. Start where the import table leaves off
Get the first token
DO
DO
IF token is not ',' AND token hasn't already been done
IF there's no entry for this file in import table,
Make one for it
Start at first item
Add the module name to the entry
WHILE next token is not ';' AND it's not FROM
IF token is ';' OR module name is not next OR 'IN' is not next OR
Syntax error
Get the file name
Put it into the import table
IF next token is not ';'
Go to next import table entry
WHILE token is not ';'
**/
struct import_table *timtbp = (struct import_table *)0;
char *c;
if (get_token(fd, token, (char)0)) while(*token != ';')
{
do
{
if (*token != ',' && !was_imported(token))
timtbp = add_import_item(timtbp, token);
if (!get_token(fd, token, (char)0)) break; /* error msg later */
}
while (*token != ';' && strcmp(token, from_w));
if (*token == ';' ||
!get_token(fd, token, (char)0) || /* module name */
*token == ';' || !get_token(fd, token, (char)0) ||
strcmp(token, in_w) || !get_token(fd, token, (char)0) ||
*token == ';') syntax(token);
if (timtbp && timtbp->item.module)
{
for (c = token; *c; c++);
if (!(timtbp->name = calloc((&c[1] - token), 1))) fatal(7, (char *)0);
cat(timtbp->name, token);
import_area.next++;
timtbp = (struct import_table *)0;
}
if (!get_token(fd, token, (char)0)) fatal(14, "before semicolon");
}
while (*token != ';');
if (*token != ';') fatal(14, token);
*token = 0;
if (timtbp && !timtbp->name) syntax(token);
}
static int is_imported(char *name)
{
struct import_item *itemp;
for(itemp = &imtbp->item; itemp && strcmp(name, itemp->module);
itemp = itemp->next);
return (itemp != (struct import_item *)0);
}
static int was_imported(char *name)
{
struct import_table *timtbp, *eimtbp;
struct import_item *itemp;
for (timtbp = (struct import_table *)import_area.area,
eimtbp = &timtbp[import_area.next]; timtbp && timtbp < eimtbp; timtbp++)
{
for (itemp = &timtbp->item; itemp && strcmp(token, itemp->module);
itemp = itemp->next);
if (itemp) return 1;
}
return 0;
}
static FILE *make_substr()
{
char fname[12];
FILE *nstr = mk_tempfile(fname, "temp file");
unlink(fname);
return nstr;
}
static void putout(FILE* str, char *msg)
{
fputs(msg, str);
if (*msg > ' ') fputs(" ", str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -