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

📄 gen-dec.c

📁 asn.1 compiler
💻 C
📖 第 1 页 / 共 5 页
字号:
static voidPrintCBerDecoderPrototype PARAMS ((hdr, td),    FILE *hdr _AND_    TypeDef *td){    CTDI *ctdi;    ctdi =  td->cTypeDefInfo;    fprintf (hdr,"void B%sContent PROTO ((%s b, %s tagId%d, %s elmtLen%d, %s *v, %s *bytesDecoded, %s env));\n", ctdi->decodeRoutineName, bufTypeNameG, tagTypeNameG, FIRST_LEVEL-1, lenTypeNameG, FIRST_LEVEL-1, ctdi->cTypeName,lenTypeNameG, envTypeNameG);}  /*  PrintCBerDecoderPrototype *//* * Prints declarations of decode routine for the given type def */static voidPrintCBerDecoderDeclaration PARAMS ((src,td),    FILE *src _AND_    TypeDef *td){    CTDI *ctdi;    ctdi =  td->cTypeDefInfo;    fprintf (src,"void\n");    fprintf (src,"B%sContent PARAMS ((b, tagId%d, elmtLen%d, v, bytesDecoded, env),\n", ctdi->decodeRoutineName, FIRST_LEVEL -1,  FIRST_LEVEL -1);    fprintf (src,"%s b _AND_\n", bufTypeNameG);    fprintf (src,"%s tagId%d _AND_\n", tagTypeNameG, FIRST_LEVEL -1);    fprintf (src,"%s elmtLen%d _AND_\n", lenTypeNameG, FIRST_LEVEL -1);    fprintf (src,"%s *v _AND_\n", ctdi->cTypeName);    fprintf (src,"%s *bytesDecoded _AND_\n", lenTypeNameG);    fprintf (src,"%s env)\n", envTypeNameG);}  /*  PrintCBerDecoderDeclaration *//* * makes a define for type refs or primitive type renaming * EG: * TypeX ::= INTEGER --> #define BerDecodeTypeX(b,v) BerDecodeInteger(b,v) * TypeX ::= TypeY --> #define BerDecodeTypeX(b,v) BerDecodeTypeY(b,v) */static voidPrintCBerDecoderDefine PARAMS ((hdr, td),    FILE *hdr _AND_    TypeDef *td){    fprintf(hdr, "#define B%sContent B%sContent", td->cTypeDefInfo->decodeRoutineName, td->type->cTypeRefInfo->decodeRoutineName);/*    fprintf(hdr, "#define B%sContent( b, tagId, elmtLen, v, bytesDecoded, env)  ", td->cTypeDefInfo->decodeRoutineName);    fprintf (hdr, "B%sContent (b, tagId, elmtLen, v, bytesDecoded, env)", td->type->cTypeRefInfo->decodeRoutineName);*/}  /*  PrintCBerDecoderDefine *//* * used to figure out local variables to declare */static intRecCountVariableLevels PARAMS ((t),    Type *t){    CTRI *ctri;    int maxLevels = 0;    NamedType *e;    TagList *tl;    int tagCount;    int typeCount;    void *tmp;    enum BasicTypeChoiceId typeId;    ctri = t->cTypeRefInfo;    typeId = GetBuiltinType (t);    /* embedded struct/choices aren't really an issue any more */    if ((ctri->cTypeId == C_STRUCT) ||        (ctri->cTypeId == C_CHOICE))    {        maxLevels = 1;        tagCount = CountTags (t);        tmp = (void*)CURR_LIST_NODE (t->basicType->a.set);        FOR_EACH_LIST_ELMT (e, t->basicType->a.set)        {            if ((e->type == NULL) || (e->type->cTypeRefInfo == NULL))                continue;            typeCount = RecCountVariableLevels (e->type);            if (typeCount > maxLevels)                maxLevels = typeCount;        }        SET_CURR_LIST_NODE (t->basicType->a.set, tmp);        return maxLevels + tagCount;    }    else if (ctri->cTypeId == C_LIST)    {        return CountTags (t) +RecCountVariableLevels (t->basicType->a.setOf);    }    else if (typeId == BASICTYPE_CHOICE)        return CountTags (t) +1;    else if ((typeId == BASICTYPE_ANY) || (typeId == BASICTYPE_ANYDEFINEDBY))        return CountTags (t) +1;    else        return CountTags (t);}  /* RecCountVariableLevels *//* * returns the number of variable contexts needed for * decoding the contents of this type.  Does not consider tags on this type. */static intCountVariableLevels PARAMS ((t),    Type *t){    CTRI *ctri;    int maxLevels = 0;    NamedType *e;    TagList *tl;    int tagCount;    int typeCount;    void *tmp;    ctri =  t->cTypeRefInfo;    if ((ctri->cTypeId == C_STRUCT) ||        (ctri->cTypeId == C_CHOICE))    {        maxLevels = 1;        tmp = (void*)CURR_LIST_NODE (t->basicType->a.set);        FOR_EACH_LIST_ELMT (e, t->basicType->a.set)        {            if ((e->type == NULL) || (e->type->cTypeRefInfo == NULL))                continue;            typeCount = RecCountVariableLevels (e->type);            /* add extra level since must decode key tag in choice */            if (GetBuiltinType (e->type) == BASICTYPE_CHOICE)                typeCount++;            if (typeCount > maxLevels)                maxLevels = typeCount;        }        SET_CURR_LIST_NODE (t->basicType->a.set, tmp);        return maxLevels;    }    else if (ctri->cTypeId == C_LIST)        return RecCountVariableLevels (t->basicType->a.setOf);    else if ((ctri->cTypeId == C_ANY) ||             (ctri->cTypeId == C_ANYDEFINEDBY))        return 1;    else        return 0;}  /* CountVariableLevels *//* * prints local vars for constructed types (set/seq/choice) */static voidPrintCBerDecoderLocals PARAMS ((src,td),    FILE *src _AND_    TypeDef *td){    int levels;    int i;    levels = CountVariableLevels (td->type);    fprintf (src, "    int seqDone = FALSE;\n");    for (i = 0; i < levels; i++)    {        fprintf (src, "    %s totalElmtsLen%d = 0;\n", lenTypeNameG, i + FIRST_LEVEL);        fprintf (src, "    %s elmtLen%d;\n", lenTypeNameG, i + FIRST_LEVEL);        fprintf (src, "    %s tagId%d;\n", tagTypeNameG, i + FIRST_LEVEL);        if (i == 0)            fprintf (src, "    int mandatoryElmtCount%d = 0;\n", i + FIRST_LEVEL);    }}  /*  PrintCBerDecoderLocals *//* * given the Type *(t) of an elmt in a set/seq/choice/list, * prints decoding code. *   elmtVarName is string ptr ref to field being decoded *     eg "(&personnelRecord.name)" *   stoleChoiceTags is as returned by GetTags * * elmtLevel - last elmtLen# var that is valid/used (has a len) * totalLevel - totalElmtsLen# to be used for running total of dec bytes * tagIdLevel - last tagId# var that is valid/used (contains a tag) */static voidPrintCBerElmtDecodeCode PARAMS ((src, td, parent, t, elmtLevel, totalLevel, tagLevel, parentVarName, elmtVarName, stoleChoiceTags),    FILE *src _AND_    TypeDef *td _AND_    Type *parent _AND_    Type *t _AND_    int elmtLevel _AND_    int totalLevel _AND_    int tagLevel _AND_    char *parentVarName _AND_    char *elmtVarName _AND_    int stoleChoiceTags){    CTRI *ctri;    Type *tmpType;    char idVarRef[MAX_VAR_REF];    NamedType *idNamedType;    enum BasicTypeChoiceId tmpTypeId;    ctri =  t->cTypeRefInfo;    /* check if meant to be encoded */    if (!ctri->isEncDec)        return;    tmpType = GetType (t);    if (tmpType->basicType->choiceId == BASICTYPE_ANY)    {        fprintf (src,"/* ANY - Fix Me ! */\n");        fprintf (src,"    SetAnyTypeBy???(%s, ???);\n", elmtVarName);        fprintf (src,"    B%s (b, %s, &%s%d, env);\n", ctri->decodeRoutineName, elmtVarName, decodedLenVarNameG, totalLevel);    }    else if (tmpType->basicType->choiceId == BASICTYPE_ANYDEFINEDBY)    {        /* get type of 'defining' field (int/enum/oid)*/        idNamedType = t->basicType->a.anyDefinedBy->link;        tmpTypeId = GetBuiltinType (idNamedType->type);        if (tmpTypeId == BASICTYPE_OID)        {            MakeVarPtrRef (genDecCRulesG, td, parent, idNamedType->type, parentVarName, idVarRef);            fprintf (src, "    SetAnyTypeByOid (%s, %s);\n", elmtVarName, idVarRef);        }        else        {            /* want to ref int by value not ptr */            MakeVarValueRef (genDecCRulesG, td, parent, idNamedType->type, parentVarName, idVarRef);            fprintf (src, "    SetAnyTypeByInt (%s, %s);\n", elmtVarName, idVarRef);        }        fprintf (src,"    B%s (b, %s, &%s%d, env);\n", ctri->decodeRoutineName, elmtVarName, decodedLenVarNameG, totalLevel);    }    else switch (ctri->cTypeId)    {        case C_LIB:        case C_TYPEREF:            /*             * choices and octet/bit str types need tagId argument             */            if ((tmpType->basicType->choiceId == BASICTYPE_CHOICE) &&                !stoleChoiceTags)            {                /*                 * strip off top tag of choice in not already done                 * since choice decoders assume you are passing in                 * their top tag                 */                fprintf (src, "    %s%d = BDecTag (b, &%s%d, env);\n", tagIdVarNameG, ++tagLevel, decodedLenVarNameG, totalLevel);                fprintf (src, "    %s%d = BDecLen (b, &%s%d, env);\n", itemLenVarNameG, ++elmtLevel, decodedLenVarNameG, totalLevel);            }            fprintf (src,"    B%sContent (b, %s%d, %s%d, %s, &%s%d, env);\n", ctri->decodeRoutineName, tagIdVarNameG, tagLevel, itemLenVarNameG, elmtLevel, elmtVarName, decodedLenVarNameG, totalLevel);	    /* From ftp://ftp.cs.ubc.ca/pub/local/src/snacc/bugs-in-1.1 */	    if ((tmpType->basicType->choiceId == BASICTYPE_CHOICE)		    && !stoleChoiceTags)	    {		fprintf(src,"    if (elmtLen%d == INDEFINITE_LEN)\n", elmtLevel-1);		fprintf(src,"        BDecEoc(b, &totalElmtsLen%d, env);\n", totalLevel);	    }        break;        /*         * NOTE: the CHOICE, STRUCT and LIST switch clauses won't         * fire due to the current 'normalization'         * (see normalize.c)         */        case C_CHOICE:                /*                 * strip off top tag of choice in not already done                 * since choice decoders assume you are passing in                 * their top tag                 */            if (!stoleChoiceTags)            {                fprintf (src, "    %s%d = BDecTag (b, &%s%d, env);\n\n", tagIdVarNameG, ++tagLevel, decodedLenVarNameG, totalLevel);                fprintf (src, "    %s%d = BDecLen (b, &%s%d, env);\n", itemLenVarNameG, ++elmtLevel, decodedLenVarNameG, totalLevel);            }            PrintCBerChoiceDecodeCode (src, td, t, elmtLevel, totalLevel+1, tagLevel, elmtVarName);        break;        case C_STRUCT:            if (t->basicType->choiceId == BASICTYPE_SET)                PrintCBerSetDecodeCode (src, td, t, t->basicType->a.set, elmtLevel, totalLevel+1, tagLevel, elmtVarName);            else            {                PrintCBerSeqDecodeCode (src, td, t, t->basicType->a.sequence, elmtLevel,totalLevel+1, tagLevel, elmtVarName);                fprintf (src,"    seqDone = FALSE;\n");            }            fprintf (src,"             %s%d += %s%d;\n", decodedLenVarNameG, totalLevel, decodedLenVarNameG, totalLevel+1);        break;        case C_LIST:            PrintCBerListDecoderCode (src, td, t,  elmtLevel, totalLevel+1, tagLevel, elmtVarName);            fprintf (src,"\n\n");            fprintf (src,"             %s%d += %s%d;\n", decodedLenVarNameG, totalLevel, decodedLenVarNameG, totalLevel+1);        break;        case C_NO_TYPE:            break;        default:            fprintf (stderr,"PrintCBerElmtDecodeCode: ERROR - unknown c type id\n");        break;    }} /* PrintCBerElmtDecodeCode *//* * Prints code for decoding the elmts of SET */static voidPrintCBerSetDecodeCode PARAMS ((src, td, parent, elmts, elmtLevel, totalLevel, tagLevel, varName),    FILE *src _AND_    TypeDef *td _AND_    Type *parent _AND_    NamedTypeList *elmts _AND_    int elmtLevel _AND_    int totalLevel _AND_    int tagLevel _AND_    char *varName){    NamedType *e;    CTRI *ctri;

⌨️ 快捷键说明

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