📄 textpro.c
字号:
/*================================*/ /*Subtopic - branch down the tree */ /*================================*/ else if (enode->level > parent->level) if (parent->type == MENU) { enode->parent = parent; parent->child = enode; } else { rm((VOID *) enode,(int) sizeof(struct entries)); fclose(fp); TextLookupToss(file); if (bufsize >= 60) sprintf(errbuf, "Line %d : Non-menu entries cannot have subtopics.", line_ct); return(CLIPS_FALSE); } /*====================================*/ /*Brother-topic -- same level in tree */ /*====================================*/ else if (enode->level == parent->level) { enode->parent = parent->parent; enode->next = parent->next; parent->next = enode; } /*==========================================================*/ /*Topic is unrelated to previous topic - branch up the tree */ /*==========================================================*/ else { if (parent != NULL) p_flag = 1; else p_flag = 0; while (p_flag > 0) { parent = parent->parent; if (parent != NULL) if (enode->level < parent->level) p_flag = 1; else p_flag = 0; else p_flag = 0; } if (parent != NULL) /*========*/ /*Subtopic*/ /*========*/ if (parent->level < enode->level) { enode->parent = parent; enode->next = parent->child; parent->child = enode; } /*=============*/ /*Brother-topic*/ /*=============*/ else { enode->parent = parent->parent; enode->next = parent->next; parent->next = enode; } /*=========*/ /*Root Node*/ /*=========*/ else { enode->parent = NULL; enode->next = lnode->topics; lnode->topics = enode; } } parent = enode; return(CLIPS_TRUE); }/******************************************************************************//*FUNCTION LOOKUP : *//* Input : 1) name of entry-topic file to be used for reference *//* 2) caller allocated buffer to contain the main topic name *//* 3) name of the entry-topic to be found *//* 4) caller allocated buffer to store the return status *//* Output : 1) offset from the beginning of the entry-topic file stream to the*//* beginning of the requested topic (-1 if the topic not found) *//* 2) status code stored in caller's buffer indicating the result of *//* the lookup : NO_FILE, NO_TOPIC, BRANCH_UP, BRANCH_DOWN, EXIT, *//* or NORMAL. *//* *//* Notes : 1) If NULL is given as an entry-topic, the lookup routine branches *//* up one level in the tree (status BRANCH_UP). If the current *//* level of the tree is already the root, all paths are set to NULL*//* (status EXIT). *//* 2) If an entry-topic is not found, the file position of the current*//* main topic (or menu) is returned (status NO_TOPIC). *//******************************************************************************/static long int LookupEntry(file,menu,name,code) char *file, **menu, *name; int *code; { struct lists *lptr; /*Local pointers used to move through the tree*/ struct entries *eptr; int l_flag, e_flag; /*Flags used in looping to find entry-topics*/ /*===============================*/ /*Find named file in lookup list */ /*===============================*/ lptr = headings; if (lptr != NULL) if (strcmp(lptr->file,file) != 0) l_flag = 1; else l_flag = 0; else l_flag = 0; while (l_flag > 0) { lptr = lptr->next; if (lptr != NULL) if (strcmp(lptr->file,file) != 0) l_flag = 1; else l_flag = 0; else l_flag = 0; } if (lptr == NULL) { *code = NO_FILE; return(-1); } /*==================================================================*/ /*If entry-topic was NULL, branch up one-level in the tree, or exit */ /*the tree if already at the root. */ /*==================================================================*/ if (name == NULL) { if (lptr->curr_menu == NULL) { *code = EXIT; return(-1); } else { if (lptr->curr_menu->parent == NULL) { *code = EXIT; lptr->curr_menu = NULL; *menu = NULL; return(-1); } lptr->curr_menu = lptr->curr_menu->parent; *code = BRANCH_UP; *menu = lptr->curr_menu->name; return(lptr->curr_menu->offset); } } /*========================================*/ /*Find the topic in the file's topic tree */ /*========================================*/ upper(name); if (lptr->curr_menu != NULL) eptr = lptr->curr_menu->child; else eptr = lptr->topics; if (eptr != NULL) if (findstr(eptr->name,name) == 0) e_flag = 0; else e_flag = 1; else e_flag = 0; while (e_flag > 0) { eptr = eptr->next; if (eptr != NULL) if (findstr(eptr->name,name) == 0) e_flag = 0; else e_flag = 1; else e_flag = 0; } /*===================================================================*/ /*If the topic was not found, return the position of the current menu*/ /*===================================================================*/ if (eptr == NULL) { *code = NO_TOPIC; if (lptr->curr_menu != NULL) { *menu = lptr->curr_menu->name; return(lptr->curr_menu->offset); } return(-1); } /*===============================================================*/ /*If the requested topic has children, branch down to its level. */ /*===============================================================*/ if (eptr->type == MENU) { *code = BRANCH_DOWN; lptr->curr_menu = eptr; } else *code = NORMAL; if (lptr->curr_menu != NULL) *menu = lptr->curr_menu->name; return(eptr->offset); }/******************************************************************************//*FUNCTION TOSS : *//* Input : 1) entry-topic address *//* Output : This function recursively deletes a node and all child nodes *//******************************************************************************/static VOID TossFunction(eptr) struct entries *eptr; { struct entries *prev; while (eptr != NULL) { if (eptr->child != NULL) TossFunction(eptr->child); prev = eptr; eptr = eptr->next; rm((VOID *) prev,(int) sizeof(struct entries)); } }/****************************************************************************//****************************************************************************//* CLIPS TEXT PROCESSING FUNCTIONS *//* *//* The functions contained in this file can be called from CLIPS to handle *//* external file referencing and accessing. FetchCommand() loads a file *//* onto an internal run-time lookup table, TossCommand() removes the file, *//* PrintRegionCommand accesses the loaded file to display a requested *//* entry, and HelpFunction() provides an on-line help facility for CLIPS *//* using the external help data file specified in the header file CLIPS.H. *//* For information on the format of the data file(s) required, see the *//* internal documentation in LOOKUP.C and the external documentation. *//* *//* For usage of these functions, see the external documentation. *//****************************************************************************//****************************************************************************/#define SCREEN_LN 22 /*Typical terminal screen length -- 22 lines*/ /*Used for scrolling in the help facility *//*==========================================*//*Topic node for help facility's query list *//*==========================================*/struct topics { char name[NAMESIZE]; /*Name of the node */ struct topics *end_list; /*Pointer to end of query list */ struct topics *next; /*Pointer to next topic in the list*/ };#if CLP_HELPstatic int HELP_INIT = CLIPS_FALSE; /*Flag used to indicate help file load status*/#endif/******************************************************************************//*============================================================================*//* FUNCTION DECLARATIONS *//*============================================================================*//******************************************************************************/#if ANSI_COMPILER#if CLP_HELPstatic int RecognizeHelpRouters(char *);static int HelpPrint(char *,char *);static int HelpGetc(char *);static int HelpUngetc(int,char *);static struct topics *AskForNewHelpTopic(struct topics *,char **);#endifstatic struct topics *GetCommandLineTopics(void);static FILE *FindTopicInEntries(char *,struct topics *,char **,int *);#else#if CLP_HELPstatic int RecognizeHelpRouters();static int HelpPrint();static int HelpGetc();static int HelpUngetc();static struct topics *AskForNewHelpTopic();#endifstatic struct topics *GetCommandLineTopics();static FILE *FindTopicInEntries();#endif#if CLP_HELPgloble char *help_file = NULL;#endif/******************************************************************************//*============================================================================*//* EXTERNAL ACCESS FUNCTIONS *//*============================================================================*//******************************************************************************//******************************************************************************//*FUNCTION HelpFunction : (CLIPS function help) *//* Input : Multiple or no topic requests may be passed to the help facility *//* from the top level of CLIPS via a "stack" accessed by the CLIPS *//* system routines num_args() and rstring(). *//* Output : This function loads the help file specified in CLIPS.H into a *//* a hierarchical tree structure using the routines of LOOKUP.C. *//* It then queries the user for topics, and, using the LOOKUP *//* routines, branches through the tree, displaying information where *//* appropriate. The function returns control to CLIPS once the user */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -