home *** CD-ROM | disk | FTP | other *** search
- ===================================================================
- RCS file: /s/usr2/K/repo/tools/cmu-snmp/snmplib/parse.c,v
- retrieving revision 1.1
- diff -c -r1.1 parse.c
- *** /tmp/,RCSt1a22340 Tue Sep 24 20:22:59 1991
- --- parse.c Thu Sep 19 06:18:15 1991
- ***************
- *** 1,3 ****
- --- 1,4 ----
- + /* $Id: parse.c,v 1.3 91/09/19 06:18:33 phil Exp $ */
- /***********************************************************
- Copyright 1989 by Carnegie Mellon University
-
- ***************
- *** 69,74 ****
- --- 70,80 ----
- #define RECOMMENDED 26
- #define PUNCT 27
- #define EQUALS 28
- + #define DESCRIPTION 29
- + #define QUOTESTRING 30
- + #define INDEX 31
- + #define DEFVAL 32
- + #define DEPRECATED 33
-
- struct tok {
- char *name; /* token name */
- ***************
- *** 113,121 ****
- --- 119,132 ----
- { "{", sizeof ("{")-1, PUNCT },
- { "}", sizeof ("}")-1, PUNCT },
- { "::=", sizeof ("::=")-1, EQUALS },
- + { "DESCRIPTION", sizeof ("DESCRIPTION")-1, DESCRIPTION },
- + { "INDEX", sizeof ("INDEX")-1, INDEX },
- + { "DEFVAL", sizeof ("DEFVAL")-1, DEFVAL },
- + { "deprecated", sizeof ("deprecated")-1, DEPRECATED },
- { NULL }
- };
-
- +
- #define HASHSIZE 32
- #define BUCKET(x) (x & 0x01F)
-
- ***************
- *** 341,347 ****
- {
- register int count;
- int type;
- ! char token[64], label[32];
- register char *cp, *tp;
-
- if ((type = get_token(fp, token)) != PUNCT){
- --- 352,358 ----
- {
- register int count;
- int type;
- ! char token[MAXTOKEN], label[MAXLABEL];
- register char *cp, *tp;
-
- if ((type = get_token(fp, token)) != PUNCT){
- ***************
- *** 430,436 ****
- char *name;
- {
- int type;
- ! char token[64];
- register int count;
- register struct subid *op, *nop;
- int length;
- --- 441,447 ----
- char *name;
- {
- int type;
- ! char token[MAXTOKEN];
- register int count;
- register struct subid *op, *nop;
- int length;
- ***************
- *** 516,526 ****
- FILE *fp;
- {
- int type;
- ! char token[64];
-
- type = get_token(fp, token);
- if (type != SEQUENCE){
- ! print_error("Not a sequence", (char *)NULL); /* should we handle this */
- return NULL;
- }
- while((type = get_token(fp, token)) != NULL){
- --- 527,537 ----
- FILE *fp;
- {
- int type;
- ! char token[MAXTOKEN];
-
- type = get_token(fp, token);
- if (type != SEQUENCE){
- ! type = get_token(fp, token);
- return NULL;
- }
- while((type = get_token(fp, token)) != NULL){
- ***************
- *** 543,554 ****
- char *name;
- {
- register int type;
- ! char token[64];
- int count, length;
- struct subid oid[16];
- ! char syntax[32];
- int nexttype;
- ! char nexttoken[64];
- register struct node *np;
- register struct enum_list *ep;
- register char *cp;
- --- 554,565 ----
- char *name;
- {
- register int type;
- ! char token[MAXTOKEN];
- int count, length;
- struct subid oid[16];
- ! char syntax[MAXTOKEN];
- int nexttype;
- ! char nexttoken[MAXTOKEN];
- register struct node *np;
- register struct enum_list *ep;
- register char *cp;
- ***************
- *** 706,717 ****
- return 0;
- }
- type = get_token(fp, token);
- ! if (type != MANDATORY && type != OPTIONAL && type != OBSOLETE && type != RECOMMENDED){
- print_error("Bad status", token);
- free_node(np);
- return 0;
- }
- type = get_token(fp, token);
- if (type != EQUALS){
- print_error("Bad format", token);
- free_node(np);
- --- 717,760 ----
- return 0;
- }
- type = get_token(fp, token);
- ! if (type != MANDATORY && type != OPTIONAL && type != OBSOLETE && type != RECOMMENDED && type != DEPRECATED){
- print_error("Bad status", token);
- free_node(np);
- return 0;
- }
- type = get_token(fp, token);
- + /*
- + * Optional parts of the OBJECT-TYPE macro
- + */
- + while (type != EQUALS) {
- + int breakFlag = 0;
- + switch (type) {
- + case DESCRIPTION:
- + type = get_token(fp, token);
- + if (type != QUOTESTRING) {
- + print_error("Bad DESCRIPTION", token);
- + free_node(np);
- + return 0;
- + }
- + break;
- +
- + case INDEX:
- + case DEFVAL:
- + if (tossObjectIdentifier(fp, token) != OBJID) {
- + print_error("Bad Object Identifier", token);
- + free_node(np);
- + return 0;
- + }
- + break;
- +
- + default:
- + print_error("Bad format of optional clauses", token);
- + free_node(np);
- + return 0;
- + break;
- + }
- + type = get_token(fp, token);
- + }
- if (type != EQUALS){
- print_error("Bad format", token);
- free_node(np);
- ***************
- *** 721,727 ****
- if (length > 1 && length <= 16){
- /* just take the last pair in the oid list */
- if (oid[length - 2].label)
- ! strncpy(np->parent, oid[length - 2].label, 32);
- strcpy(np->label, name);
- if (oid[length - 1].subid != -1)
- np->subid = oid[length - 1].subid;
- --- 764,770 ----
- if (length > 1 && length <= 16){
- /* just take the last pair in the oid list */
- if (oid[length - 2].label)
- ! strncpy(np->parent, oid[length - 2].label, MAXLABEL);
- strcpy(np->label, name);
- if (oid[length - 1].subid != -1)
- np->subid = oid[length - 1].subid;
- ***************
- *** 750,757 ****
- parse(fp)
- FILE *fp;
- {
- ! char token[64];
- ! char name[32];
- int type = 1;
- struct node *np, *root = NULL;
-
- --- 793,800 ----
- parse(fp)
- FILE *fp;
- {
- ! char token[MAXTOKEN];
- ! char name[MAXLABEL];
- int type = 1;
- struct node *np, *root = NULL;
-
- ***************
- *** 766,772 ****
- print_error(token, "is a reserved word");
- return NULL;
- }
- ! strncpy(name, token, 32);
- type = get_token(fp, token);
- if (type == OBJTYPE){
- if (root == NULL){
- --- 809,815 ----
- print_error(token, "is a reserved word");
- return NULL;
- }
- ! strncpy(name, token, MAXTOKEN);
- type = get_token(fp, token);
- if (type == OBJTYPE){
- if (root == NULL){
- ***************
- *** 806,811 ****
- --- 849,859 ----
- np = np->next;
- } else if (type == EQUALS){
- type = parse_asntype(fp);
- + if (type != NULL) {
- + /* equivalenced type: DdpAddress :== OCTET STRING */
- + /* What to do? */
- + }
- +
- } else if (type == NULL){
- break;
- } else {
- ***************
- *** 813,818 ****
- --- 861,867 ----
- return NULL;
- }
- }
- +
- #ifdef TEST
- {
- struct enum_list *ep;
- ***************
- *** 854,859 ****
- --- 903,910 ----
- ch = getc(fp);
- if (ch == '\n')
- Line++;
- + else if (ch == '"')
- + return parseQuoteString(fp, token);
- }
- if (ch == -1)
- return NULL;
- ***************
- *** 900,905 ****
- --- 951,1028 ----
-
- } while ((ch = getc(fp)) != -1);
- return NULL;
- + }
- +
- + static int
- + parseQuoteString(fp, token)
- + register FILE *fp;
- + register char *token;
- + {
- + static char last = ' ';
- + register int ch;
- + register char *cp = token;
- + register int hash = 0;
- + register struct tok *tp;
- +
- + ch = ' ';
- +
- + while(ch != -1) {
- + ch = getc(fp);
- + cp++;
- +
- + if (ch == '\n')
- + Line++;
- + else if (ch == '"') {
- + return QUOTESTRING;
- + }
- + }
- + if (ch == -1) {
- + last = ch;
- + *cp = '\0';
- + return NULL;
- + }
- + }
- +
- + /*
- + * This routine parses a string like { blah blah blah } and returns OBJID if
- + * it is well formed, and NULL if not.
- + */
- + static int
- + tossObjectIdentifier(fp, token)
- + register FILE *fp;
- + register char *token;
- + {
- + static char last = ' ';
- + register int ch;
- + register char *cp = token;
- + register int hash = 0;
- + register struct tok *tp;
- +
- +
- + ch = last;
- + /* skip all white space */
- + while(isspace(ch) && ch != -1){
- + ch = getc(fp);
- + if (ch == '\n')
- + Line++;
- + }
- + if (ch != '{')
- + return NULL;
- +
- + while(ch != -1) {
- + ch = getc(fp);
- + cp++;
- +
- + if (ch == '\n')
- + Line++;
- + else if (ch == '}')
- + return OBJID;
- + }
- + if (ch == -1){
- + last = ch;
- + *cp = '\0';
- + return NULL;
- + }
- }
-
- struct tree *
-