Menu

Errors loading external .CLP files

2018-08-06
2018-08-15
  • mfenske17363

    mfenske17363 - 2018-08-06

    Working through my .CLP file loads this morning I kept receiving generic load error messages "Could not load file XXXX.CLP." After tracing through the issue I observed the following:
    1. I put a break point at the start of the Load (CLIPSNET_Environment.cpp - Environment::Load)
    if (ebFileName->Length)
    {
    pin_ptr<byte> pbFileName = &ebFileName[0];
    if (m_Env->Load((char *) pbFileName) == 0)
    {
    CaptureEnd(commandCapture,false);
    throw gcnew System::IO::FileNotFoundException(
    "Could not load file '" + fileName + "'.",
    fileName);
    }
    }
    2. Which calls down into Clipscpplib.cpp (CLIPSCPPEnv::Load)
    int CLIPSCPPEnv::Load(
    char *theFile)
    {</byte>

    ifndef CLIPS_DLL_WRAPPER

    return ::Load(theEnv,theFile);

    else

    return __Load(theEnv,theFile);

    endif

    }

    1. Which returns the value of the Load call in cstrcpsr.c (Load). Load returns LE_NO_ERROR because noErrorsDetected is set to 1.

    SetLoadInProgress(theEnv,true);
    noErrorsDetected = LoadConstructsFromLogicalName(theEnv,(char *) theFile);
    SetLoadInProgress(theEnv,false);

    SetParsingFileName(theEnv,oldParsingFileName);
    DeleteString(theEnv,oldParsingFileName);

    SetWarningFileName(theEnv,NULL);
    SetErrorFileName(theEnv,NULL);

    SetFastLoad(theEnv,NULL);

    /=================/
    / Close the file. /
    /=================/

    GenClose(theEnv,theFile);

    /=================================================/
    / If no errors occurred during the load, return /
    / LE_NO_ERROR, otherwise return LE_PARSING_ERROR. /
    /=================================================/

    if (noErrorsDetected)
    { return LE_NO_ERROR; }

    return LE_PARSING_ERROR;
    }

    1. LE_NO_ERROR is an enum who’s value is 0

    typedef enum
    {
    LE_NO_ERROR = 0,
    LE_OPEN_FILE_ERROR,
    LE_PARSING_ERROR,
    } LoadError;

    1. The check back in Environment::Load throws an error if the return is 0 (LE_NO_ERROR). I modified the condiftional to throw an error when the return is non-zero (LE_OPEN_FILE_ERROR, LE_PARSING_ERROR).

      if (ebFileName->Length)
      {
      pin_ptr<byte> pbFileName = &ebFileName[0];
      if (m_Env->Load((char *) pbFileName) != 0)
      {
      CaptureEnd(commandCapture,false);
      throw gcnew System::IO::FileNotFoundException(
      "Could not load file '" + fileName + "'.",
      fileName);
      }
      }</byte>

    I get the feeling that I am not seeing something here that I should. Is this a correct solution for my problem or am I missing something?

    Thanks for any help!

     
  • Gary Riley

    Gary Riley - 2018-08-15

    Apologies for the long delay. Your solution is correct.

     

Log in to post a comment.