Exemplo n.º 1
0
void c4_HandlerSeq::DetachFromStorage(bool full_)
{
    if (_persist != 0) {
        int limit = full_ ? 0 : NumFields();

        // get rid of all handlers which might do I/O
        for (int c = NumHandlers(); --c >= 0;) {
            c4_Handler &h = NthHandler(c);

            // all nested fields are detached recursively
            if (IsNested(c))
                for (int r = 0; r < NumRows(); ++r)
                    if (h.HasSubview(r)) {
                        SubEntry(c, r).DetachFromStorage(full_);
                    }

            if (c >= limit) {
                if (h.IsPersistent()) {
                    delete  &h;
                    _handlers.RemoveAt(c);
                    ClearCache();
                }
            }
        }

        if (full_) {
            //UnmappedAll();
            _persist = 0;
        }
    }
}
Exemplo n.º 2
0
void c4_HandlerSeq::DetermineSpaceUsage()
{
    for (int c = 0; c < NumFields(); ++c)
        if (IsNested(c)) {
            c4_Handler &h = NthHandler(c);
            for (int r = 0; r < NumRows(); ++r)
                if (h.HasSubview(r)) {
                    SubEntry(c, r).DetermineSpaceUsage();
                }
        }
}
Exemplo n.º 3
0
void c4_HandlerSeq::Restructure(c4_Field &field_, bool remove_)
{
    //d4_assert(_field != 0);

    // all nested fields must be set up, before we shuffle them around
    for (int k = 0; k < NumHandlers(); ++k)
        if (IsNested(k)) {
            c4_Handler &h = NthHandler(k);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    SubEntry(k, n);
                }
        }

    for (int i = 0; i < field_.NumSubFields(); ++i) {
        c4_Field &nf = field_.SubField(i);
        c4_Property prop(nf.Type(), nf.Name());

        int n = PropIndex(prop.GetId());
        if (n == i) {
            continue;
        }

        if (n < 0) {
            _handlers.InsertAt(i, f4_CreateFormat(prop,  *this));
            NthHandler(i).Define(NumRows(), 0);
        } else {
            // move the handler to the front
            d4_assert(n > i);
            _handlers.InsertAt(i, _handlers.GetAt(n));
            _handlers.RemoveAt(++n);
        }

        ClearCache(); // we mess with the order of handler, keep clearing it

        d4_assert(PropIndex(prop.GetId()) == i);
    }

    c4_Field *ofld = _field;
    // special case if we're "restructuring a view out of persistence", see below

    _field = remove_ ? 0 : &field_;

    // let handler do additional init once all have been prepared
    //for (int n = 0; n < NumHandlers(); ++n)
    //    NthHandler(n).Define(NumRows(), 0);

    const char *desc = "[]";
    c4_Field temp(desc);

    // all nested fields are restructured recursively
    for (int j = 0; j < NumHandlers(); ++j)
        if (IsNested(j)) {
            c4_Handler &h = NthHandler(j);
            for (int n = 0; n < NumRows(); ++n)
                if (h.HasSubview(n)) {
                    c4_HandlerSeq &seq = SubEntry(j, n);
                    if (j < NumFields()) {
                        seq.Restructure(field_.SubField(j), false);
                    } else if (seq._field != 0) {
                        seq.Restructure(temp, true);
                    }
                }
        }

    if (_parent == this) {
        delete ofld;
    }
    // the root table owns its field structure tree
}
Exemplo n.º 4
0
UBOOL FillIdentityElement_EM
    (LPVOID       lpMemRes,                     // Ptr to result global memory
     APLNELM      aplNELMRes,                   // Result NELM
     APLSTYPE     aplTypeRes,                   // Result storage type
     LPPL_YYSTYPE lpYYFcnStrLft,                // Ptr to left operand function strand
     LPTOKEN      lptkLftArg,                   // Ptr to left arg token
     LPPL_YYSTYPE lpYYFcnStrRht,                // Ptr to right operand function strand (may be NULL if Scan)
     LPTOKEN      lptkRhtArg)                   // Ptr to right arg token

{
    GLBSYM  hGlbSym;                            // Result
    APLUINT uRes;                               // Loop counter

    // Get the identity element
    hGlbSym =
      GetIdentityElement_EM (lpYYFcnStrLft,     // Ptr to left operand function strand
                             lptkLftArg,        // Ptr to left arg token
                             lpYYFcnStrRht,     // Ptr to right operand function strand (may be NULL if Scan)
                             lptkRhtArg);       // Ptr to right arg token
    // Check for errors
    if (hGlbSym.hGlb EQ NULL)
        return FALSE;

    // Split cases based upon the ptr type bits
    switch (GetPtrTypeDir (hGlbSym.hGlb))
    {
        case PTRTYPE_STCONST:
            // The identity element is a simple scalar

            // Split cases based upon the result storage type
            switch (aplTypeRes)
            {
                case ARRAY_BOOL:
                case ARRAY_INT:
                case ARRAY_CHAR:
                case ARRAY_FLOAT:
                    // Split cases based upon the identity element immediate type
                    switch (hGlbSym.lpSym->stFlags.ImmType)
                    {
                        case IMMTYPE_BOOL:
                            // If it's a Boolean != 0, save in the result
                            if (hGlbSym.lpSym->stData.stBoolean)
                                // Fill the result with all 1s
                                FillMemory (lpMemRes, (APLU3264) RoundUpBitsToBytes (aplNELMRes), 0xFF);
                            break;

                        case IMMTYPE_INT:
                            // If it's an integer != 0, save in the result
                            if (hGlbSym.lpSym->stData.stInteger)
                            while (aplNELMRes--)
                                *((LPAPLINT) lpMemRes)++ = hGlbSym.lpSym->stData.stInteger;
                            break;

                        case IMMTYPE_FLOAT:
                            // If it's a float != 0, save in the result
                            if (hGlbSym.lpSym->stData.stFloat)
                            while (aplNELMRes--)
                                *((LPAPLFLOAT) lpMemRes)++ = hGlbSym.lpSym->stData.stFloat;
                            break;

                        case IMMTYPE_CHAR:
                            while (aplNELMRes--)
                                *((LPAPLCHAR) lpMemRes)++ = hGlbSym.lpSym->stData.stChar;
                            break;

                        defstop
                            break;
                    } // End SWITCH

                    break;

                case ARRAY_NESTED:
                    // If the result is empty, ...
                    if (IsEmpty (aplNELMRes))
                    {
                        LPPERTABDATA lpMemPTD;      // Ptr to PerTabData global memory

                        // Get ptr to PerTabData global memory
                        lpMemPTD = GetMemPTD ();

                        // If the identity element is numeric, ...
                        if (IsImmNum (hGlbSym.lpSym->stFlags.ImmType))
                            // Save the prototype of the identity element in the result
                            *((LPAPLNESTED) lpMemRes)++ = lpMemPTD->lphtsGLB->steZero;
                        else
                            // Save the prototype of the identity element in the result
                            *((LPAPLNESTED) lpMemRes)++ = lpMemPTD->lphtsGLB->steBlank;
                    } else
                    {
                        // Save the identity element in the result
                        *((LPAPLNESTED) lpMemRes)++ = hGlbSym.hGlb;
                        for (uRes = 1; uRes < aplNELMRes; uRes++)
                            *((LPAPLNESTED) lpMemRes)++ = CopySymGlbDir_PTB (hGlbSym.hGlb);
                    } // End IF/ELSE

                    break;

                case ARRAY_APA:
                case ARRAY_HETERO:
                defstop
                    break;
            } // End SWITCH

            break;

        case PTRTYPE_HGLOBAL:
            // The identity element is a global

            Assert (IsNested (aplTypeRes));

            // If the result is empty, ...
            if (IsEmpty (aplNELMRes))
            {
                HGLOBAL hGlbPro;        // Prototype global memory handle

                // Make the prototype
                hGlbPro =
                  MakeMonPrototype_EM_PTB (hGlbSym.hGlb,            // Proto arg handle
                                          &lpYYFcnStrLft->tkToken,  // Ptr to function token
                                           MP_CHARS);               // CHARs allowed
                // We no longer need this storage
                FreeResultGlobalVar (hGlbSym.hGlb); hGlbSym.hGlb = NULL;

                // Check for error
                if (hGlbPro EQ NULL)
                    return FALSE;

                // Save the prototype of the identity element in the result
                *((LPAPLNESTED) lpMemRes)++ = hGlbPro;
            } else
            {
                *((LPAPLNESTED) lpMemRes)++ = hGlbSym.hGlb;
                for (uRes = 1; uRes < aplNELMRes; uRes++)
                    *((LPAPLNESTED) lpMemRes)++ = CopySymGlbDir_PTB (hGlbSym.hGlb);
            } // End IF/ELSE

            break;

        defstop
            break;
    } // End IF/SWITCH

    return TRUE;
} // End FillIdentityElement_EM
Exemplo n.º 5
0
LPPL_YYSTYPE SysFnMonFX_EM_YY
    (LPTOKEN lptkFunc,              // Ptr to function token
     LPTOKEN lptkRhtArg,            // Ptr to right arg token
     LPTOKEN lptkAxis)              // Ptr to axis token (may be NULL)

{
    LPPERTABDATA      lpMemPTD;                 // Ptr to PerTabData global memory
    HGLOBAL           hGlbRes = NULL;           // Result global memory handle
    LPVOID            lpMemRes;                 // Ptr to result global memory
    APLSTYPE          aplTypeRht,               // Right arg storage type
                      aplTypeItmRht;            // Right arg item storage type
    APLNELM           aplNELMRht;               // Right arg NELM
    APLRANK           aplRankItmRht;            // Right arg item rank
    APLUINT           uRht;                     // Loop counter
    HGLOBAL           hGlbItmRht;               // Right arg item global memory handle
    LPVARARRAY_HEADER lpMemHdrRht = NULL,       // Ptr to right arg header
                      lpMemHdrItmRht = NULL,    // ...    right item arg ...
                      lpMemHdrRes = NULL;       // ...    result    ...
    LPAPLCHAR         lpMemRht;                 // Ptr to right arg global memory
    LPPL_YYSTYPE      lpYYRes = NULL;           // Ptr to the result
    APLLONGEST        aplLongestItmRht;         // Right arg item immediate value
    IMM_TYPES         immTypeItmRht;            // Right arg item immediate type
    SF_FCNS           SF_Fcns = {0};            // Common struc for SaveFunctionCom
    FX_PARAMS         FX_Params = {0};          // Local struc for  ...
    AFODETECT_STR     afoDetectStr = {0};       // Local struc for AfoDetect

    // Get ptr to PerTabData global memory
    lpMemPTD = GetMemPTD ();

    // In case we're called by )IN, zap the error line #
    lpMemPTD->uErrLine = NEG1U;

    // Get the attributes (Type, NELM, and Rank)
    //   of the right arg
    AttrsOfToken (lptkRhtArg, &aplTypeRht, &aplNELMRht, &FX_Params.aplRankRht, &FX_Params.aplColsRht);

    // Check for empty right arg
    if (IsEmpty (aplNELMRht))
        goto RIGHT_DOMAIN_EXIT;

    // Get right arg's global ptrs
    FX_Params.aplLongestRht = GetGlbPtrs_LOCK (lptkRhtArg, &FX_Params.hGlbRht, &lpMemHdrRht);

    // If it's an immediate, ...
    if (lpMemHdrRht EQ NULL)
        // Point to the data
        lpMemRht = (LPAPLCHAR) &FX_Params.aplLongestRht;
    else
        // Skip over the header to the data
        lpMemRht = VarArrayDataFmBase (lpMemHdrRht);

    // Allocate the initial AFOLINE_STR
    afoDetectStr.hGlbLineStr =
      GlobalAlloc (GHND, AFOLINESTR_INIT * sizeof (AFOLINE_STR));

    // Check for error
    if (afoDetectStr.hGlbLineStr EQ NULL)
        goto WSFULL_EXIT;
    // Save in local params
    afoDetectStr.uLineStrCnt  = AFOLINESTR_INIT;
    afoDetectStr.lpafoLineStr = GlobalLock (afoDetectStr.hGlbLineStr);

    // Fill in common values
    SF_Fcns.bDisplayErr = FALSE;            // DO NOT Display Errors
////SF_Fcns.bRet        =                   // Filled in by SaveFunctionCom
////SF_Fcns.uErrLine    =                   // ...
////SF_Fcns.lpSymName   =                   // ...
    SF_Fcns.lptkFunc    = lptkFunc;         // Ptr to function token
    SF_Fcns.bMakeAFX    =
    SF_Fcns.bAFO        = (lpMemRht NE NULL) && AfoDetect (lpMemRht, &afoDetectStr);
    SF_Fcns.LclParams   = &FX_Params;
    SF_Fcns.sfTypes     = SFTYPES_FX;       // Caller type

    // Copy to local params
    FX_Params.lpafoDetectStr = &afoDetectStr;

    // Check for AFO function name
    if (!CheckAfoFcnName (&SF_Fcns, lpMemRht))
        goto SYMTAB_FULL_EXIT;

    // Check for RIGHT RANK/DOMAIN ERRORs
    switch (FX_Params.aplRankRht)
    {
        case 0:                     // Right arg scalar
        case 1:                     // ...       vector
            // Fill in common values
            FX_Params.aplRowsRht = 1;

            if (IsNested (aplTypeRht))
            {
                // Fill in common values
                FX_Params.aplRowsRht = aplNELMRht;

                // Ensure that each item is a char scalar/vector
                for (uRht = 0; uRht < aplNELMRht; uRht++)
                {
                    // Get the next value from the right arg
                    GetNextValueMem (lpMemRht,              // Ptr to right arg global memory
                                     aplTypeRht,            // Right arg storage type
                                     aplNELMRht,            // Right arg NELM
                                     uRht,                  // Right arg index
                                    &hGlbItmRht,            // Right arg item LPSYMENTRY or HGLOBAL (may be NULL)
                                    &aplLongestItmRht,      // Ptr to right arg immediate value
                                    &immTypeItmRht);        // Ptr to right arg immediate type
                    // If the right arg item is an array, ...
                    if (hGlbItmRht NE NULL)
                    {
                        // Get the right arg item global attrs
                        AttrsOfGlb (hGlbItmRht, &aplTypeItmRht, NULL, &aplRankItmRht, NULL);

                        // Ensure the item is a scalar/vector
                        if (IsMultiRank (aplRankItmRht))
                            goto RIGHT_RANK_EXIT;

                        // If this is the function header, ensure that it's not all blank
                        if (uRht EQ 0)
                        {
                            LPVARARRAY_HEADER lpMemHdtrItmRht = NULL;   // Ptr to item header
                            LPAPLCHAR         lpMemItmRht;              // Ptr to right arg item global memory
                            APLNELM           aplNELMItmRht;            // Right arg item NELM

                            // Lock the memory to get a ptr to it
                            lpMemHdrItmRht = MyGlobalLockVar (hGlbItmRht);

                            // Get the array NELM
#define lpHeader        lpMemHdrItmRht
                            aplNELMItmRht = lpHeader->NELM;

                            // Skip over the header to the data
                            lpMemItmRht = VarArrayDataFmBase (lpMemHdrItmRht);
#undef  lpHeader
                            // Check for all blanks
                            for (; aplNELMItmRht; aplNELMItmRht--)
                            if (lpMemItmRht[aplNELMItmRht - 1] NE L' ')
                                break;

                            // We no longer need this ptr
                            MyGlobalUnlock (hGlbItmRht); lpMemHdrItmRht = NULL;

                            if (IsEmpty (aplNELMItmRht))
                                goto RIGHT_DOMAIN_EXIT;
                        } // End IF

                        // Ensure the item is simple char
                        if (!IsSimpleChar (aplTypeItmRht))
                            goto RIGHT_DOMAIN_EXIT;
                    } else
                    {
                        // The right arg item is an immediate scalar

                        // If this is the function header, ensure that it's not empty
                        if (uRht EQ 0
                         && ((APLCHAR) FX_Params.aplLongestRht) EQ L' ')
                            goto RIGHT_DOMAIN_EXIT;

                        // Ensure the item is simple char
                        if (!IsImmChr (immTypeItmRht))
                            goto RIGHT_DOMAIN_EXIT;
                    } // End IF/ELSE
                } // End FOR

                // We no longer need this ptr
                MyGlobalUnlock (FX_Params.hGlbRht); lpMemHdrRht = NULL;

                // Fill in common values
                SF_Fcns.SF_LineLen      = SF_LineLenN;      // Ptr to line length function
                SF_Fcns.SF_ReadLine     = SF_ReadLineN;     // Ptr to read line function
                SF_Fcns.SF_IsLineCont   = SF_IsLineContN;   // Ptr to Is Line Continued function
                SF_Fcns.SF_NumPhyLines  = SF_NumPhyLinesN;  // Ptr to get # physical lines function
                SF_Fcns.SF_NumLogLines  = SF_NumLogLinesN;  // Ptr to get # logical  ...
                SF_Fcns.SF_CreationTime = SF_CreationTimeN; // Ptr to get function creation time
                SF_Fcns.SF_LastModTime  = SF_LastModTimeN;  // Ptr to get function last modification time
                SF_Fcns.SF_UndoBuffer   = SF_UndoBufferN;   // Ptr to get function Undo Buffer global memory handle
            } else
            if (IsSimpleChar (aplTypeRht))
            {
                // Simple character scalar or vector

                // Check for DOMAIN ERROR
                if (IsEmpty (aplNELMRht))
                    goto RIGHT_DOMAIN_EXIT;

                // Fill in common values
                SF_Fcns.SF_LineLen      = SF_LineLenSV;     // Ptr to line length function
                SF_Fcns.SF_ReadLine     = SF_ReadLineSV;    // Ptr to read line function
                SF_Fcns.SF_IsLineCont   = SF_IsLineContSV;  // Ptr to Is Line Continued function
                SF_Fcns.SF_NumPhyLines  = SF_NumPhyLinesSV; // Ptr to get # physical lines function
                SF_Fcns.SF_NumLogLines  = SF_NumLogLinesSV; // Ptr to get # logical  ...
                SF_Fcns.SF_CreationTime = SF_CreationTimeSV;// Ptr to get function creation time
                SF_Fcns.SF_LastModTime  = SF_LastModTimeSV; // Ptr to get function last modification time
                SF_Fcns.SF_UndoBuffer   = SF_UndoBufferSV;  // Ptr to get function Undo Buffer global memory handle
            } else
                goto RIGHT_DOMAIN_EXIT;

            break;

        case 2:                     // Right arg matrix
            if (!IsSimpleChar (aplTypeRht))
                goto RIGHT_DOMAIN_EXIT;

            // Fill in common values
            if (FX_Params.aplColsRht NE 0)
                FX_Params.aplRowsRht = aplNELMRht / FX_Params.aplColsRht;
            // If it's an AFO, ...
            if (SF_Fcns.bAFO)
            {
                SF_Fcns.SF_LineLen      = SF_LineLenSV;         // Ptr to line length function
                SF_Fcns.SF_ReadLine     = SF_ReadLineSV;        // Ptr to read line function
                SF_Fcns.SF_NumPhyLines  = SF_NumPhyLinesSV;     // Ptr to # physical lines function
                SF_Fcns.SF_NumLogLines  = SF_NumLogLinesSV;     // Ptr to # logical  ...
                SF_Fcns.SF_IsLineCont   = SF_IsLineContSV;      // Ptr to Is Line Continued function
            } else
            {
                SF_Fcns.SF_LineLen      = SF_LineLenM;          // Ptr to line length function
                SF_Fcns.SF_ReadLine     = SF_ReadLineM;         // Ptr to read line function
                SF_Fcns.SF_NumPhyLines  = SF_NumPhyLinesM;      // Ptr to # physical lines function
                SF_Fcns.SF_NumLogLines  = SF_NumLogLinesM;      // Ptr to # logical  ...
                SF_Fcns.SF_IsLineCont   = SF_IsLineContM;       // Ptr to Is Line Continued function
            } // End IF/ELSE

            SF_Fcns.SF_CreationTime = SF_CreationTimeM;     // Ptr to get function creation time
            SF_Fcns.SF_LastModTime  = SF_LastModTimeM;      // Ptr to get function last modification time
            SF_Fcns.SF_UndoBuffer   = SF_UndoBufferM;       // Ptr to get function Undo Buffer global memory handle

            break;

        default:                    // Right arg rank > 2
            goto RIGHT_RANK_EXIT;
    } // End SWITCH

    // Call common routine
    if (SaveFunctionCom (NULL, &SF_Fcns))
    {
        HGLOBAL   htGlbName;        // Function name global memory handle
        LPAPLCHAR lpMemName;        // Ptr to function name global memory
        UINT      uNameLen;         // Function name length
        APLUINT   ByteRes;          // # bytes in the result

        // The function fix succeeded -- return the function name as the result

        // Get the function name global memory handle
        htGlbName = SF_Fcns.lpSymName->stHshEntry->htGlbName;

        // Lock the memory to get a ptr to it
        lpMemName = MyGlobalLockWsz (htGlbName);

        // Get the length
        uNameLen = lstrlenW (lpMemName);

        //***************************************************************
        // Calculate space needed for the result
        //***************************************************************
        ByteRes = CalcArraySize (ARRAY_CHAR, uNameLen, 1);

        //***************************************************************
        // Check for overflow
        //***************************************************************
        if (ByteRes NE (APLU3264) ByteRes)
            goto WSFULL_EXIT;

        //***************************************************************
        // Now we can allocate the storage for the result
        //***************************************************************
        hGlbRes = DbgGlobalAlloc (GHND, (APLU3264) ByteRes);
        if (hGlbRes EQ NULL)
            goto WSFULL_EXIT;

        // Lock the memory to get a ptr to it
        lpMemHdrRes = MyGlobalLock000 (hGlbRes);

#define lpHeader        lpMemHdrRes
        // Fill in the header
        lpHeader->Sig.nature = VARARRAY_HEADER_SIGNATURE;
        lpHeader->ArrType    = ARRAY_CHAR;
////////lpHeader->PermNdx    = PERMNDX_NONE;    // Already zero from GHND
////////lpHeader->SysVar     = FALSE;           // Already zero from GHND
        lpHeader->RefCnt     = 1;
        lpHeader->NELM       = uNameLen;
        lpHeader->Rank       = 1;
#undef  lpHeader

        // Fill in the result's dimension
        *VarArrayBaseToDim (lpMemHdrRes) = uNameLen;

        // Skip over the header and dimensions to the data
        lpMemRes = VarArrayDataFmBase (lpMemHdrRes);

        // Copy the function name to the result
        CopyMemoryW (lpMemRes, lpMemName, uNameLen);

        // We no longer need this ptr
        MyGlobalUnlock (htGlbName); lpMemName = NULL;

        // Allocate a new YYRes
        lpYYRes = YYAlloc ();

        // Fill in the result token
        lpYYRes->tkToken.tkFlags.TknType   = TKT_VARARRAY;
////////lpYYRes->tkToken.tkFlags.ImmType   = IMMTYPE_ERROR; // Already zero from YYAlloc
        lpYYRes->tkToken.tkFlags.NoDisplay = TRUE;
        lpYYRes->tkToken.tkData.tkGlbData  = MakePtrTypeGlb (hGlbRes);
        lpYYRes->tkToken.tkCharIndex       = lptkFunc->tkCharIndex;
    } else
    {
        // The function fix failed.

        // If the error line # is NEG1U, there is an error message, so return NULL.
        if (SF_Fcns.uErrLine EQ NEG1U)
            goto ERROR_EXIT;

        // Otherwise, return the error line # as an integer scalar (origin-sensitive)

        // Allocate a new YYRes
        lpYYRes = YYAlloc ();

        // Fill in the result token
        lpYYRes->tkToken.tkFlags.TknType   = TKT_VARIMMED;
        lpYYRes->tkToken.tkFlags.ImmType   = IMMTYPE_INT;
////////lpYYRes->tkToken.tkFlags.NoDisplay = FALSE;         // Already zero from YYAlloc
        lpYYRes->tkToken.tkData.tkInteger  = GetQuadIO () + SF_Fcns.uErrLine;
        lpYYRes->tkToken.tkCharIndex       = lptkFunc->tkCharIndex;

        // In case we're called by )IN, save the error line # for later use
        lpMemPTD->uErrLine = SF_Fcns.uErrLine;
    } // End IF/ELSE

    goto NORMAL_EXIT;

RIGHT_DOMAIN_EXIT:
    ErrorMessageIndirectToken (ERRMSG_DOMAIN_ERROR APPEND_NAME,
                               lptkRhtArg);
    goto ERROR_EXIT;

RIGHT_RANK_EXIT:
    ErrorMessageIndirectToken (ERRMSG_RANK_ERROR APPEND_NAME,
                               lptkRhtArg);
    goto ERROR_EXIT;

WSFULL_EXIT:
    ErrorMessageIndirectToken (ERRMSG_WS_FULL APPEND_NAME,
                               lptkFunc);
    goto ERROR_EXIT;

SYMTAB_FULL_EXIT:
    ErrorMessageIndirectToken (ERRMSG_SYMBOL_TABLE_FULL APPEND_NAME,
                               lptkFunc);
    goto ERROR_EXIT;

ERROR_EXIT:
    if (hGlbRes NE NULL)
    {
        if (lpMemHdrRes NE NULL)
        {
            // We no longer need this ptr
            MyGlobalUnlock (hGlbRes); lpMemHdrRes = NULL;
        } // End IF

        // We no longer need this storage
        FreeResultGlobalIncompleteVar (hGlbRes); hGlbRes = NULL;
    } // End IF
NORMAL_EXIT:
    if (FX_Params.hGlbRht NE NULL && lpMemHdrRht NE NULL)
    {
        // We no longer need this ptr
        MyGlobalUnlock (FX_Params.hGlbRht); lpMemHdrRht = NULL;
    } // End IF

    if (hGlbRes NE NULL && lpMemHdrRes NE NULL)
    {
        // We no longer need this ptr
        MyGlobalUnlock (hGlbRes); lpMemHdrRes = NULL;
    } // End IF

    if (afoDetectStr.hGlbLineStr NE NULL)
    {
        if (afoDetectStr.lpafoLineStr NE NULL)
        {
            // We no longer need this ptr
            GlobalUnlock (afoDetectStr.hGlbLineStr); afoDetectStr.lpafoLineStr = NULL;
        } // End IF

        // We no longer need this storage
        GlobalFree (afoDetectStr.hGlbLineStr); afoDetectStr.hGlbLineStr = NULL;
    } // End IF

    return lpYYRes;
} // End SysFnMon_FX_EM_YY
Exemplo n.º 6
0
DWORD ReadHeader(FILE *f, int depth, DWORD max_size)
{
    struct
    {
        DWORD type;
        DWORD size;
    } header;

    DWORD size = 0;

    if (fread(&header, 1, sizeof(header), f) == sizeof(header))
    {
        size = header.size & 0x7FFFFFFF;

        char *chunk_type = lookup(header.type, size);
        indent = depth * 3;
        fprintf(outf, "%s%08X %s [%d]\n", Indent(), header.type, chunk_type, size);
        indent = depth * 3 + 9;

        if (size > 4*1024*1024)
        {
            printf("*ERROR* header is exceedingly big!\n");
        }
        else if (depth > 10)
        {
            printf("*ERROR* nested too deep!\n");
        }
        else if (size + sizeof(header) > max_size)
        {
            printf("*ERROR* structure size exceeds container!\n");
        }
        else
        {
            if (IsNested(header.type))
            {
                long remaining = size;
                while (remaining > 0)
                {
                    DWORD bytes_read = ReadHeader(f, depth + 1, remaining) + sizeof(header);
                    remaining -= bytes_read;
                }
            }
            else
            {
                BYTE *data = new BYTE[size];
                fread(data, size, 1, f);
                ProcessChunk(header.type, data, size);
                delete data;
            }
        }
    }
    else
    {
        if (depth > 0)
        {
            printf("*ERROR* fread failed\n");
        }
    }

    return (size);
}
Exemplo n.º 7
0
int main(int argc, char* argv[])
{
    WIN32_FIND_DATA fdata = {NULL};
    filename = fdata.cFileName;
    count = 0;

    outf = fopen("C:\\MSI\\JOBS\\BETC\\ChunkTypes\\output.txt", "w");
    // outf = fopen("K:\\Perzonal\\fun\\FL\\ChunkTypes\\output.txt", "w");
    if (!outf)
    {
        printf("*ERROR* Unable to open output.txt\n");
        return 1;
    }

    SetCurrentDirectory("K:\\Perzonal\\fun\\enb\\EB1\\Data\\client\\mixfiles\\Art\\");
//    SetCurrentDirectory("K:\\Perzonal\\fun\\enb\\mixfiles\\Art\\");
//    SetCurrentDirectory("K:\\Perzonal\\fun\\enb\\EB1\\EBCONFIG\\");

    HANDLE h = FindFirstFile("*.w3d", &fdata);

    /*
    do
    {
        ProcessFile(filename);
    } while (FindNextFile(h, &fdata));
    */

    ProcessFile("defender.w3d");
    ProcessFile("enforcer.w3d");
    ProcessFile("explorer.w3d");
    ProcessFile("privateer.w3d");
    ProcessFile("scout.w3d");
    ProcessFile("seeker.w3d");
    ProcessFile("sentinel.w3d");
    ProcessFile("tradesman.w3d");
    ProcessFile("warrior.w3d");

    printf("total count=%d\n", count);

    fprintf(outf, "total count=%d\n", count);

    fprintf(outf, "fixed size:\n");

    struct chunk_types_S *p = chunk_table;

    while (p->type != 0xFFFFFFFF)
    {
        if ((p->count > 0) &&
            (!IsNested(p->type)) &&
            (p->min_size == p->max_size))
        {
            fprintf(outf, "%08X, %s, %d, %d, %d\n",
                p->type, p->text, p->count, p->min_size, p->max_size);
        }
        p++;
    }

    fprintf(outf, "\nvariable size:\n");

    p = chunk_table;

    while (p->type != 0xFFFFFFFF)
    {
        if ((p->count > 0) &&
            (!IsNested(p->type)) &&
            (p->min_size != p->max_size))
        {
            fprintf(outf, "%08X, %s, %d, %d, %d\n",
                p->type, p->text, p->count, p->min_size, p->max_size);
        }
        p++;
    }

    fprintf(outf, "\nnested\n");

    p = chunk_table;

    while (p->type != 0xFFFFFFFF)
    {
        if ((p->count > 0) &&
            (IsNested(p->type)))
        {
            fprintf(outf, "%08X, %s, %d, %d, %d\n",
                p->type, p->text, p->count, p->min_size, p->max_size);
        }
        p++;
    }

	fclose(outf);

    return 0;
}