Пример #1
0
globle struct fact *FindIndexedFact(
  long int factIndexSought)
  {
   struct fact *theFact;

   for (theFact = (struct fact *) GetNextFact(NULL);
        theFact != NULL;
        theFact = (struct fact *) GetNextFact(theFact))
     {
      if (theFact->factIndex == factIndexSought)
        { return(theFact); }
     }

   return(NULL);
  }
Пример #2
0
static int ClearFactsReady()
  {
   /*====================================*/
   /* Initialize the fact index to zero. */
   /*====================================*/

   NextFactIndex = 0L;

   /*======================================*/
   /* Remove all facts from the fact list. */
   /*======================================*/

   RemoveAllFacts();

   /*==============================================*/
   /* If for some reason there are any facts still */
   /* remaining, don't continue with the clear.    */
   /*==============================================*/

   if (GetNextFact(NULL) != NULL) return(FALSE);

   /*=============================*/
   /* Return TRUE to indicate the */
   /* clear command can continue. */
   /*=============================*/

   return(TRUE);
  }
Пример #3
0
//Look through the facts from the previous CLIPS run and determine
//	the screen name for the next run.
int UpdateScreenName(void)
{
	struct fact * factptr;
	char szCurrFact[FACT_BUFFER_SIZE + 1];
	char *pStart, *pEnd;

	char szCurrentScreen[] = "(ScreenName ";
	char szNextScreenINI[MAX_SCREEN_NAME_SIZE + 1];

	//Start at first fact.
	factptr = GetNextFact(NULL);
	while(factptr)
	{
		//Look for ScreenName, copy to g_szScreenName if found and get out
		memset(szCurrFact, '\0', FACT_BUFFER_SIZE + 1);
		GetFactPPForm(szCurrFact, FACT_BUFFER_SIZE, factptr);
		pStart = strchr(szCurrFact, '(');
		if(strstr(pStart, szCurrentScreen) != NULL)	//Got the screen name
		{
			pStart = strchr(pStart, ' ');	//Get past (ScreenName
			pStart++;						//Get past space
			pStart = strchr(pStart, ' ');	//Get past (ScrnName
			pStart++;
			pEnd = strstr(pStart, "))");
			*pEnd = NULL;
			strcpy(g_szScreenName, pStart);
			return(0);
		}

		//Next fact
		factptr = GetNextFact(factptr);
	}

	//If we get here, that means that No ScreenName fact was asserted
	//   and we must check to see if there is a screen specified in WebCLIPS.INI
	GetWebCLIPSSettings(
		g_szScreenName,				// section name
		"NextScreenName",			// entry name
		"",							// default value
		szNextScreenINI,			// return value
		sizeof(szNextScreenINI),	// max length
		g_szWebCLIPSINI
		);

	//If there is an entry, copy it to g_szScreenName and assert a fact
	//	reflecting the new ScreenName
	if(strlen(szNextScreenINI) > 0)
	{
		strcpy(g_szScreenName, szNextScreenINI);
		memset(szCurrFact, '\0', FACT_BUFFER_SIZE + 1);
		strcpy(szCurrFact, "(ScreenName (ScrnName ");
		strcat(szCurrFact, g_szScreenName);
		strcat(szCurrFact, "))");
		if(AssertString(szCurrFact) == NULL)
		{
			ProcessErrorCode("NAVG0001", szCurrFact, 'n', 'n');
			return(-1);
		}
	}

	return(0);
}
Пример #4
0
//Function to write all facts as hidden <INPUT> items, if desired.
int PreserveFactState(char *szPrevScreen)
{
	struct fact * factptr;
	char szCurrFact[FACT_BUFFER_SIZE + 1];
	char *pStart;

	int bPreserveFactsUsingTags = FALSE, bPreserveFactsUsingDisk = FALSE;
	int bPreserveFactsUsingCookie = FALSE, bResult;
	char szKeepFacts[7], *szFileName;
	FILE *fp;

	//Determine if *previous* screen wants to preserve ALL facts for
	//	further processing.
	GetWebCLIPSSettings(
		szPrevScreen,				// section name
		"PreserveFacts",			// entry name
		"no",						// default value
		szKeepFacts,				// return value
		sizeof(szKeepFacts),		// max length
		g_szWebCLIPSINI
		);

	//Set bPreserveFact flags appropriately
	if(strcasecmp(szKeepFacts, "yes") == 0)
	{
		bPreserveFactsUsingTags = TRUE;
	}

	if(strcasecmp(szKeepFacts, "disk") == 0 ||
	   strcasecmp(szKeepFacts, "cookie") == 0)
	{
		//We are preserving facts for just this session
		if(strcasecmp(szKeepFacts, "disk") == 0)
		{
			bPreserveFactsUsingDisk = TRUE;

			//Generate unique filename
			bResult = GenerateTempFileName(&szFileName);
			if(bResult == FALSE)
			{
				ProcessErrorCode("PSRV0001", NULL, 'y', 'n');
				return(-1);
			}
		}

		//We are preserving facts across sessions
		if(strcasecmp(szKeepFacts, "cookie") == 0)
		{
			bPreserveFactsUsingCookie = TRUE;
			szFileName = g_szSaveCookiesFile;
		}

		//Open the file
		if((fp = fopen(szFileName, "wb")) == NULL)
		{
			free(szFileName);
			ProcessErrorCode("PSRV0002", szFileName, 'y', 'y');
			return(-1);
		}
	}

	//For each fact preserve it in the appropriate manner
	factptr = GetNextFact(NULL);
	while(factptr)
	{
		memset(szCurrFact, '\0', FACT_BUFFER_SIZE + 1);
		GetFactPPForm(szCurrFact, FACT_BUFFER_SIZE, factptr);

		pStart = strchr(szCurrFact, '(');
		//Skip (initial-fact)
		if(strcmp(szCurrFact, "(initial-fact)") == 0)
		{
			factptr = GetNextFact(factptr);
			continue;
		}

		//Whether or not fact preservation is desired, the "ScreenName"
		//	fact must be kept so WebCLIPS knows what to do next time.
		if(strstr(pStart, "(ScreenName ") != NULL) //ScreenName found!
		{
			printf("<INPUT TYPE=\"hidden\" NAME=\"fact\" VALUE=\"%s\">\n", pStart);
			factptr = GetNextFact(factptr);
			continue;
		}

		//If fact preservation is desired and the facts are to be
		//	preserved using <hidden> HTML tags then, the keep the fact.
		if(bPreserveFactsUsingTags == TRUE)
		{
			printf("<INPUT TYPE=\"hidden\" NAME=\"fact\" VALUE=\"");
			PrintURLEncode(pStart);
			printf("\">\n");
			factptr = GetNextFact(factptr);
			continue;
		}

		//If we want to save facts using disk then write the fact to
		//	to the file.
		if(bPreserveFactsUsingDisk == TRUE ||
		   bPreserveFactsUsingCookie == TRUE)
		{
			fprintf(fp, "%s\n", pStart);
			factptr = GetNextFact(factptr);
			continue;
		}

		factptr = GetNextFact(factptr);
	} // while(factptr)

	//Close the file, format <hidden> tag with filename
	if(bPreserveFactsUsingDisk == TRUE)
	{
		//Write out a <hidden> tag containing the filename for the next
		//	program
		printf("<INPUT type=\"hidden\" name=\"WC_SavedFacts\" value=\"%s\">", szFileName);
		free(szFileName); //Free up space from GenerateTempFileName()
		fclose(fp);
	}

	//Close the file
	if(bPreserveFactsUsingCookie == TRUE)
	{
		fclose(fp);
	}

	return(0);
}