📄 prntutil.c
字号:
/*******************************************************/
/* "C" Language Integrated Production System */
/* */
/* CLIPS Version 6.24 07/01/05 */
/* */
/* PRINT UTILITY MODULE */
/*******************************************************/
/*************************************************************/
/* Purpose: Utility routines for printing various items */
/* and messages. */
/* */
/* Principal Programmer(s): */
/* Gary D. Riley */
/* */
/* Contributing Programmer(s): */
/* Brian L. Donnell */
/* */
/* Revision History: */
/* */
/* 6.24: Link error occurs for the SlotExistError */
/* function when OBJECT_SYSTEM is set to 0 in */
/* setup.h. DR0865 */
/* */
/* Added DataObjectToString function. */
/* */
/* Added SlotExistError function. */
/* */
/*************************************************************/
#define _PRNTUTIL_SOURCE_
#include <stdio.h>
#define _STDIO_INCLUDED_
#include <string.h>
#include "setup.h"
#include "constant.h"
#include "envrnmnt.h"
#include "symbol.h"
#include "utility.h"
#include "evaluatn.h"
#include "argacces.h"
#include "router.h"
#include "multifun.h"
#include "factmngr.h"
#include "inscom.h"
#include "insmngr.h"
#include "memalloc.h"
#include "prntutil.h"
/*****************************************************/
/* InitializePrintUtilityData: Allocates environment */
/* data for print utility routines. */
/*****************************************************/
globle void InitializePrintUtilityData(
void *theEnv)
{
AllocateEnvironmentData(theEnv,PRINT_UTILITY_DATA,sizeof(struct printUtilityData),NULL);
}
/***********************************************************/
/* PrintInChunks: Prints a string in chunks to accomodate */
/* systems which have a limit on the maximum size of a */
/* string which can be printed. */
/***********************************************************/
globle void PrintInChunks(
void *theEnv,
char *logicalName,
char *bigString)
{
char tc, *subString;
subString = bigString;
if (subString == NULL) return;
while (((int) strlen(subString)) > 500)
{
if (EvaluationData(theEnv)->HaltExecution) return;
tc = subString[500];
subString[500] = EOS;
EnvPrintRouter(theEnv,logicalName,subString);
subString[500] = tc;
subString += 500;
}
EnvPrintRouter(theEnv,logicalName,subString);
}
/************************************************************/
/* PrintFloat: Controls printout of floating point numbers. */
/************************************************************/
globle void PrintFloat(
void *theEnv,
char *fileid,
double number)
{
char *theString;
theString = FloatToString(theEnv,number);
EnvPrintRouter(theEnv,fileid,theString);
}
/****************************************************/
/* PrintLongInteger: Controls printout of integers. */
/****************************************************/
globle void PrintLongInteger(
void *theEnv,
char *logicalName,
long int number)
{
char printBuffer[32];
sprintf(printBuffer,"%ld",number);
EnvPrintRouter(theEnv,logicalName,printBuffer);
}
/**************************************/
/* PrintAtom: Prints an atomic value. */
/**************************************/
globle void PrintAtom(
void *theEnv,
char *logicalName,
int type,
void *value)
{
char buffer[20];
switch (type)
{
case FLOAT:
PrintFloat(theEnv,logicalName,ValueToDouble(value));
break;
case INTEGER:
PrintLongInteger(theEnv,logicalName,ValueToLong(value));
break;
case SYMBOL:
EnvPrintRouter(theEnv,logicalName,ValueToString(value));
break;
case STRING:
if (PrintUtilityData(theEnv)->PreserveEscapedCharacters)
{ EnvPrintRouter(theEnv,logicalName,StringPrintForm(theEnv,ValueToString(value))); }
else
{
EnvPrintRouter(theEnv,logicalName,"\"");
EnvPrintRouter(theEnv,logicalName,ValueToString(value));
EnvPrintRouter(theEnv,logicalName,"\"");
}
break;
case EXTERNAL_ADDRESS:
if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\"");
EnvPrintRouter(theEnv,logicalName,"<Pointer-");
sprintf(buffer,"%p",value);
EnvPrintRouter(theEnv,logicalName,buffer);
EnvPrintRouter(theEnv,logicalName,">");
if (PrintUtilityData(theEnv)->AddressesToStrings) EnvPrintRouter(theEnv,logicalName,"\"");
break;
#if OBJECT_SYSTEM
case INSTANCE_NAME:
EnvPrintRouter(theEnv,logicalName,"[");
EnvPrintRouter(theEnv,logicalName,ValueToString(value));
EnvPrintRouter(theEnv,logicalName,"]");
break;
#endif
case RVOID:
break;
default:
if (EvaluationData(theEnv)->PrimitivesArray[type] == NULL) break;
if (EvaluationData(theEnv)->PrimitivesArray[type]->longPrintFunction == NULL)
{
EnvPrintRouter(theEnv,logicalName,"<unknown atom type>");
break;
}
(*EvaluationData(theEnv)->PrimitivesArray[type]->longPrintFunction)(theEnv,logicalName,value);
break;
}
}
/**********************************************************/
/* PrintTally: Prints a tally count indicating the number */
/* of items that have been displayed. Used by functions */
/* such as list-defrules. */
/**********************************************************/
globle void PrintTally(
void *theEnv,
char *logicalName,
long count,
char *singular,
char *plural)
{
if (count == 0) return;
EnvPrintRouter(theEnv,logicalName,"For a total of ");
PrintLongInteger(theEnv,logicalName,count);
EnvPrintRouter(theEnv,logicalName," ");
if (count == 1) EnvPrintRouter(theEnv,logicalName,singular);
else EnvPrintRouter(theEnv,logicalName,plural);
EnvPrintRouter(theEnv,logicalName,".\n");
}
/********************************************/
/* PrintErrorID: Prints the module name and */
/* error ID for an error message. */
/********************************************/
globle void PrintErrorID(
void *theEnv,
char *module,
int errorID,
int printCR)
{
if (printCR) EnvPrintRouter(theEnv,WERROR,"\n");
EnvPrintRouter(theEnv,WERROR,"[");
EnvPrintRouter(theEnv,WERROR,module);
PrintLongInteger(theEnv,WERROR,(long int) errorID);
EnvPrintRouter(theEnv,WERROR,"] ");
}
/**********************************************/
/* PrintWarningID: Prints the module name and */
/* warning ID for a warning message. */
/**********************************************/
globle void PrintWarningID(
void *theEnv,
char *module,
int warningID,
int printCR)
{
if (printCR) EnvPrintRouter(theEnv,WWARNING,"\n");
EnvPrintRouter(theEnv,WWARNING,"[");
EnvPrintRouter(theEnv,WWARNING,module);
PrintLongInteger(theEnv,WWARNING,(long int) warningID);
EnvPrintRouter(theEnv,WWARNING,"] WARNING: ");
}
/***************************************************/
/* CantFindItemErrorMessage: Generic error message */
/* when an "item" can not be found. */
/***************************************************/
globle void CantFindItemErrorMessage(
void *theEnv,
char *itemType,
char *itemName)
{
PrintErrorID(theEnv,"PRNTUTIL",1,FALSE);
EnvPrintRouter(theEnv,WERROR,"Unable to find ");
EnvPrintRouter(theEnv,WERROR,itemType);
EnvPrintRouter(theEnv,WERROR," ");
EnvPrintRouter(theEnv,WERROR,itemName);
EnvPrintRouter(theEnv,WERROR,".\n");
}
/*****************************************************/
/* CantFindItemInFunctionErrorMessage: Generic error */
/* message when an "item" can not be found. */
/*****************************************************/
globle void CantFindItemInFunctionErrorMessage(
void *theEnv,
char *itemType,
char *itemName,
char *func)
{
PrintErrorID(theEnv,"PRNTUTIL",1,FALSE);
EnvPrintRouter(theEnv,WERROR,"Unable to find ");
EnvPrintRouter(theEnv,WERROR,itemType);
EnvPrintRouter(theEnv,WERROR," ");
EnvPrintRouter(theEnv,WERROR,itemName);
EnvPrintRouter(theEnv,WERROR," in function ");
EnvPrintRouter(theEnv,WERROR,func);
EnvPrintRouter(theEnv,WERROR,".\n");
}
/*****************************************************/
/* CantDeleteItemErrorMessage: Generic error message */
/* when an "item" can not be deleted. */
/*****************************************************/
globle void CantDeleteItemErrorMessage(
void *theEnv,
char *itemType,
char *itemName)
{
PrintErrorID(theEnv,"PRNTUTIL",4,FALSE);
EnvPrintRouter(theEnv,WERROR,"Unable to delete ");
EnvPrintRouter(theEnv,WERROR,itemType);
EnvPrintRouter(theEnv,WERROR," ");
EnvPrintRouter(theEnv,WERROR,itemName);
EnvPrintRouter(theEnv,WERROR,".\n");
}
/****************************************************/
/* AlreadyParsedErrorMessage: Generic error message */
/* when an "item" has already been parsed. */
/****************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -