Example #1
0
CDFstatus QuitCDF (char *why, Int32 offset, int size, int num, void *value1,
		   void *value2, Logical debug)
{
  
  if (debug) {
    char text[151], texta[41];
    text[0] = NUL;
    strcpyX (text, why, 150);
    if (offset >= 0) {
      snprintf (texta, (size_t) sizeof(texta),
                " (@%ld) ", (long) offset);
      strcatX (text, texta, 150);
    }
    if (strlen(why) < 150) {
      if (num == 2) { /* Two argument values to show. */
        if (size == 4) { /* Each one is a 4-byte int type. */
                         /* Each int is up to 10 digits + sign. */
          char text2[2 * 11 + 6 + 1];
          text2[0] = NUL;
          snprintf (text2, (size_t) sizeof(text2),
		    "(%ld vs %ld)", (long) *(int *)value1,
                    (long) *(int *)value2);
          strcatX (text, text2, 150);
        } else { /* Both are strings. */
          char *text2;
          size_t len = strlen ((char *) value1) + strlen ((char *) value2) + 
                       6 + 1;
          text2 = (char *) cdf_AllocateMemory (len, NULL);
          if (text2 != NULL) {
            text2[0] = NUL;
            snprintf (text2, len, "(%s vs %s)", (char *)value1, (char *)value2);
            strcatX (text, text2, 150);
            cdf_FreeMemory (text2, NULL);
          }
        }
      } else { /* Only one argument value to show. */
        if (size == 4) { /* Each int is up to 10 digits + sign. */
          char text2[11 + 2 + 1];
          text2[0] = NUL;
          snprintf (text2, (size_t) sizeof(text2),
		    "(%ld)", (long) *(int *)value1);
          strcatX (text, text2, 150);
        } else {
          char *text2;
          size_t len = strlen ((char *) value1) + 2 + 1;
          text2 = (char *) cdf_AllocateMemory (len, NULL);
          if (text2 != NULL) {
            text2[0] = NUL;
            snprintf (text2, len, "(%s)", (char *)value1);
            strcatX (text, text2, 150);
            cdf_FreeMemory (text2, NULL);
          }
        }
      }
    }
    printf ("ERROR...%s\n", text);
  }
  return CV2C;
}
Example #2
0
CDFstatus ValidateAttributeLinks (struct CDFstruct *CDF, vFILE *fp,
                                  Logical debug)
{
    CDFstatus status;
    OFF_T offset, nextADR, AgrEDRhead, AzEDRhead;
    Int32 num, numgrEntries, maxgrEntry, numzEntries, maxzEntry, scope;
    int ix, *visit;

    visit = (int *) cdf_AllocateMemory (GDR.NumAttr * sizeof(Int32), NULL);
    if (visit == NULL) return BAD_MALLOC;
    for (ix = 0; ix < GDR.NumAttr; ++ix)
        visit[ix] = 0;
    offset = GDR.ADRhead;
    for (ix = 0; ix < GDR.NumAttr; ++ix) {
        status = ValidateADR (CDF, fp, offset, debug);
        if (status != CDF_OK) {
            cdf_FreeMemory (visit, NULL);
            return status;
        }
        status = ReadADR64 (fp, offset,
                            ADR_NUM, &num,
                            ADR_ADRNEXT, &nextADR,
                            ADR_AgrEDRHEAD, &AgrEDRhead,
                            ADR_NgrENTRIES, &numgrEntries,
                            ADR_MAXgrENTRY, &maxgrEntry,
                            ADR_AzEDRHEAD, &AzEDRhead,
                            ADR_NzENTRIES, &numzEntries,
                            ADR_MAXzENTRY, &maxzEntry,
                            ADR_NULL);
        if (numgrEntries > 0) {
            status = ValidateAttributeEntryLink (CDF, fp, num, FALSE, AgrEDRhead,
                                                 numgrEntries, maxgrEntry, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        if (numzEntries > 0) {
            status = ValidateAttributeEntryLink (CDF, fp, num, TRUE, AzEDRhead,
                                                 numzEntries, maxzEntry, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        visit[num] = 1;
        offset = nextADR;
    }
    for (ix = 0; ix < GDR.NumAttr; ++ix) {
        if (visit[ix] == 0) {
            cdf_FreeMemory (visit, NULL);
            return QuitCDF ("CDF: an attribute unreachable in attribute link: ",
                            4, 1, &ix, 0, debug);
        }
    }
    cdf_FreeMemory (visit, NULL);
    return CDF_OK;
}
Example #3
0
CDFstatus ValidateAttributeEntryLink (struct CDFstruct *CDF, vFILE *fp,
                                      Int32 num, Logical zEntry, OFF_T EDRhead,
                                      Int32 numEntries, Int32 maxEntry,
                                      Logical debug)
{
    CDFstatus status;
    OFF_T offset, nextAEDR;
    Int32 entryNum, lastNum, *visits;
    int ix, iy;

    offset = EDRhead;
    lastNum = 0;
    visits = (Int32 *) cdf_AllocateMemory (numEntries * sizeof(Int32), NULL);
    if (visits == NULL) return BAD_MALLOC;
    for (ix = 0; ix < numEntries; ++ix)
        visits[ix] = 0;
    ix = 0;
    while (offset != 0) {
        status = ValidateAEDR (CDF, fp, offset, num, maxEntry, zEntry, debug);
        if (status != CDF_OK) {
            cdf_FreeMemory (visits, NULL);
            return status;
        }
        status = ReadAEDR64 (fp, offset,
                             AEDR_NUM, &entryNum,
                             AEDR_AEDRNEXT, &nextAEDR,
                             AEDR_NULL);
        if (ix > 0) {
            for (iy = 0; iy < ix; ++iy) {
                if (visits[iy] == entryNum) {
                    cdf_FreeMemory (visits, NULL);
                    return QuitCDF ("CDF: entry number is repeating in an attribute entry link: ",
                                    4, 1, &entryNum, 0, debug);
                }
            }
        }
        if (ix == (int) numEntries) {
            cdf_FreeMemory (visits, NULL);
            return QuitCDF ("CDF: number of entries is more than maximum in an attribute entry link: ",
                            4, 1, &ix, 0, debug);
        }
        visits[ix] = entryNum;
        ++ix;
        if (lastNum < entryNum) lastNum = entryNum;
        offset = nextAEDR;
    }
    if (lastNum != maxEntry) {
        cdf_FreeMemory (visits, NULL);
        return QuitCDF ("CDF: last entry number is not the maximum entry number in  an attribute entry link: ",
                        4, 2, &lastNum, &maxEntry, debug);
    }
    cdf_FreeMemory (visits, NULL);
    return CDF_OK;
}
Example #4
0
static CDFstatus QuitCDF (char *why, OFF_T offset, int isize, int num,
                          void *value1,void *value2, Logical debug)
{

    if (debug) {
        char text[151], texta[41];
        text[0] = NUL;
        strcpyX (text, why, 150);
        if (offset >= 0) {
#if !defined(win32) && !defined(__MINGW32__)
            snprintf (texta, (size_t) sizeof(texta),
                      " (@%lld) ", offset);
#else
            snprintf (texta, (size_t) sizeof(texta),
                      " (@%I64d) ", offset);
#endif
            strcatX (text, texta, 150);
        }
        if (strlen(why) < 150) {
            if (num == 2) { /* Two argument values to show. */
                if (isize == 4) { /* Each one is a 4-byte int type. */
                    /* Each int is up to 10 digits + sign. */
                    char text2[2 * 11 + 6 + 1];
                    text2[0] = (char) NUL;
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%ld vs %ld)", (long) *(int *)value1,
                              (long) *(int *)value2);
                    strcatX (text, text2, 150);
                } else if (isize == 8) { /* Each one is a 8-byte long long type. */
                    /* Each long long is up to 19 digits + sign. */
                    char text2[2 * 20 + 6 + 1];
                    text2[0] = (char) NUL;
#if !defined(win32) && !defined(__MINGW32__)
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%lld vs %lld)", *(OFF_T *)value1, *(OFF_T *)value2);
#else
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%I64d vs %I64d)", *(OFF_T *)value1, *(OFF_T *)value2);
#endif
                    strcatX (text, text2, 150);
                } else { /* Each one is a string. */
                    char *text2;
                    size_t len = strlen ((char *) value1) + strlen ((char *) value2) + 6
                                 + 1;
                    text2 = (char *) cdf_AllocateMemory (len, NULL);
                    if (text2 != NULL) {
                        text2[0] = (char) NUL;
                        snprintf (text2, len, "(%s vs %s)", (char *)value1, (char *)value2);
                        strcatX (text, text2, 150);
                        cdf_FreeMemory (text2, NULL);
                    }
                }
            } else { /* Only one argument value to show. */
                if (isize == 4) { /* 4 extra chars are for 2 " ", "(", and ")". */
                    char text2[11 + 2 + 1];
                    text2[0] = (char) NUL;
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%ld)", (long) *(int *)value1);
                    strcatX (text, text2, 150);
                } else if (isize == 8) {
                    char text2[20 + 2 + 1];
                    text2[0] = (char) NUL;
#if !defined(win32) && !defined(__MINGW32__)
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%lld)", *(OFF_T *)value1);
#else
                    snprintf (text2, (size_t) sizeof(text2),
                              "(%I64d)", *(OFF_T *)value1);
#endif
                    strcatX (text, text2, 150);
                } else {
                    char *text2;
                    size_t len = strlen ((char *) value1)  + 2 + 1;
                    text2 = (char *) cdf_AllocateMemory (len, NULL);
                    if (text2 != NULL) {
                        text2[0] = (char) NUL;
                        snprintf (text2, len, "(%s)", (char *)value1);
                        strcatX (text, text2, 150);
                        cdf_FreeMemory (text2, NULL);
                    }
                }
            }
        }
        printf ("ERROR...%s\n", text);
    }
    return CV3C;
}
Example #5
0
static CDFstatus ValidateVariableLinks (struct CDFstruct *CDF, vFILE *fp,
                                        Logical zVar, Logical debug)
{
    CDFstatus status;
    OFF_T offset, headVXR, tailVXR, nextVXR, nextVDR, cprOffset;
    Int32 num, lastRec, flags;
    int ix, numVars, *visit;

    numVars = (zVar ? GDR.NzVars : GDR.NrVars);
    visit = (int *) cdf_AllocateMemory(numVars * sizeof(Int32), NULL);
    for (ix = 0; ix < numVars; ++ix) visit[ix] = 0;
    offset = (zVar ? GDR.zVDRhead : GDR.rVDRhead);
    for (ix = 0; ix < numVars; ++ix) {
        status = ValidateVDR (CDF, fp, offset, zVar, debug);
        if (status != CDF_OK) {
            cdf_FreeMemory (visit, NULL);
            return status;
        }
        status = ReadVDR64 (CDF, fp, offset, zVar,
                            VDR_NUM, &num,
                            VDR_FLAGS, &flags,
                            VDR_MAXREC, &lastRec,
                            VDR_VDRNEXT, &nextVDR,
                            VDR_CPRorSPR, &cprOffset,
                            VDR_VXRHEAD, &headVXR,
                            VDR_VXRTAIL, &tailVXR,
                            VDR_NULL);
        if (CDF->singleFile && lastRec > -1) {
            status = ValidateVariableValueLinks (CDF, fp, lastRec, headVXR, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        if (VARcompressionBITset(flags)) {
            status = ValidateCPR (fp, cprOffset, debug);
            if (status != CDF_OK) {
                cdf_FreeMemory (visit, NULL);
                return status;
            }
        }
        visit[num] = 1;
        offset = nextVDR;
    }

    for (ix = 0; ix < numVars; ++ix) {
        if (visit[ix] == 0) {
            cdf_FreeMemory (visit, NULL);
            if (zVar)
                return QuitCDF ("CDF: a zVariable unreachable in the variable chain: ", (OFF_T) -1,
                                4, 1, &ix, 0, debug);
            else
                return QuitCDF ("CDF: a rVariable unreachable in the variable chain: ", (OFF_T) -1,
                                4, 1, &ix, 0, debug);
        }
    }
    cdf_FreeMemory (visit, NULL);
    if (offset != 0) {
        status = ReadVDR64 (CDF, fp, offset, zVar,
                            VDR_NUM, &num,
                            VDR_VDRNEXT, &nextVDR,
                            VDR_NULL);
        if (status == CDF_OK) {
            if (num >= numVars) {
                if (zVar)
                    return QuitCDF ("CDF(VDR): a zVariable unreachable in the variable chain: ", offset,
                                    4, 1, &num, 0, debug);
                else
                    return QuitCDF ("CDF(VDR): a rVariable unreachable in the variable chain: ", offset,
                                    4, 1, &num, 0, debug);
            } else {
                if (zVar)
                    return QuitCDF ("CDF(VDR): a zVariable is repeated in the variable chain: ", offset,
                                    4, 1, &num, 0, debug);
                else
                    return QuitCDF ("CDF(VDR): a rVariable unreachable in the variable chain: ", offset,
                                    4, 1, &num, 0, debug);
            }
        }
    }
    return CDF_OK;
}