📄 textpro.c
字号:
/* has indicated an exit from the help tree. *//* *//* For usage see external documentation. *//******************************************************************************/#if CLP_HELPgloble VOID HelpFunction() { int status; /*Return code from the lookup routines */ FILE *fp; /*Pointer in to the help file stream */ struct topics *main_topic, /*Pointer to the first requested topic */ *tptr; /*Used in deallocating the topic list */ char buf[256], /*Buffer for storing input strings from the help file */ *menu[1]; /*Buffer for the name of the current main topic */#if ! WINDOW_INTERFACE char termbuf[2]; /*Buffer for storing the terminators of a scroll */ int line_cnt; /*Line count used for scrolling purposes */#endif if (HELP_INIT == CLIPS_FALSE) { if (help_file == NULL) { help_file = (char *) gm2((int) strlen(HELP_DEFAULT) + 1); strcpy(help_file,HELP_DEFAULT); } PrintCLIPS(WDIALOG,"Loading help file entries from "); PrintCLIPS(WDIALOG,help_file); PrintCLIPS(WDIALOG,".\nPlease wait...\n"); status = TextLookupFetch(help_file,buf,256); if (status == 0) { PrintErrorID("TEXTPRO",1,CLIPS_FALSE); PrintCLIPS(WERROR,"Unable to access help file.\n"); PrintCLIPS(WERROR,buf); PrintCLIPS(WERROR,"\n"); return; } else { /* ================================================================ Enables logical name "whelp" as the destination for all help I/O ================================================================ */ AddRouter("whelp",10,RecognizeHelpRouters,HelpPrint, HelpGetc,HelpUngetc,NULL); HELP_INIT = CLIPS_TRUE; } } ActivateRouter("whelp"); /* ==================================================================== The root node of the help-tree is MAIN (see external documentation.) Add this node to the front of the initial topic request list given by the user on the CLIPS top level command line. ==================================================================== */ main_topic = (struct topics *) gm2 ((int) sizeof(struct topics)); strcpy(main_topic->name,"MAIN"); main_topic->next = GetCommandLineTopics(); main_topic->end_list = NULL; PrintCLIPS("whelp","\n"); /*============================*/ /*Process user topic requests */ /*============================*/ do { fp = FindTopicInEntries(help_file,main_topic,menu,&status); if (status == NO_FILE) { PrintErrorID("TEXTPRO",1,CLIPS_FALSE); PrintCLIPS(WERROR,"Unable to access help file.\n"); break; } if (status == EXIT) break; if (status == NO_TOPIC) { if (fp == NULL) { /*===================================================*/ /*The lookup routines return the file location of the*/ /*current main topic if the requested topic is not */ /*found. The help-tree has one root: MAIN (see */ /*external docs). This topic should always be */ /*available. Thus, if the topic was not found and */ /*there is no current menu, the help-file has been */ /*tampered with and should be corrected. */ /*===================================================*/ PrintCLIPS("whelp","Root entry \"MAIN\" not found in "); PrintCLIPS("whelp",help_file); PrintCLIPS("whelp",".\nSee external documentation.\n"); break; } PrintCLIPS("whelp","\nSorry, no information available.\n\n"); } if (status != BRANCH_UP) {#if ! WINDOW_INTERFACE line_cnt = 0;#endif /*======================================================*/ /*Print lines from the information entry stopping after */ /*every screenful of lines. The user at that point has */ /*the option to continue or abort the entry to continue */ /*at the current menu level. */ /*======================================================*/ while (grab_string(fp,buf,256) != NULL) {#if ! WINDOW_INTERFACE if (line_cnt >= (SCREEN_LN + 1)) { PrintCLIPS("whelp","PRESS <RETURN> FOR MORE. "); PrintCLIPS("whelp","PRESS <A>,<RETURN> TO ABORT."); CLIPSInputCount = 0; do { termbuf[0] = (char) GetcCLIPS("whelp"); if (termbuf[0] != LNFEED) { if (termbuf[0] == 'a') termbuf[0] = 'A'; if (termbuf[0] != '\b') CLIPSInputCount++; else if (CLIPSInputCount != 0) CLIPSInputCount--; termbuf[1] = (char) GetcCLIPS("whelp"); } } while ((termbuf[0] != LNFEED) && (termbuf[0] != 'A')); CLIPSInputCount = -1; line_cnt = 0; if (termbuf[0] == 'A') { fclose(fp); break; } } line_cnt++;#endif PrintCLIPS("whelp",buf); } } else if (fp != NULL) /*==========================================================*/ /*If the user branched-up the help-tree, don't reprint that */ /*menu. However, the help file still needs to be closed. */ /*==========================================================*/ fclose(fp); main_topic = AskForNewHelpTopic(main_topic,menu); if (HaltExecution) { while (status != EXIT) if ((fp = GetEntries(help_file,menu,NULL,&status)) != NULL) fclose(fp); } } while (status != EXIT); DeactivateRouter("whelp"); /*========================================================*/ /*Release any space used by the user's topic request list */ /*========================================================*/ while (main_topic != NULL) { tptr = main_topic; main_topic = main_topic->next; rm((VOID *) tptr,(int) sizeof(struct topics)); } }/***************************************************************************//*FUNCTION HelpPathFunction : (CLIPS function help-path) *//* Input : Via the CLIPS "stack", the name of the new help entries file, *//* or no input. *//* Output : This function redefines the lookup file for the help facility. *//* If no argument is given, it displays the current file name. *//***************************************************************************/globle VOID HelpPathFunction() { char *help_name; DATA_OBJECT arg_ptr; if (RtnArgCount() == 0) { PrintCLIPS(WDIALOG,"The current help entries file is "); if (help_file != NULL) PrintCLIPS(WDIALOG,help_file); else PrintCLIPS(WDIALOG,HELP_DEFAULT); PrintCLIPS(WDIALOG,"\n"); } else { if (help_file != NULL) { if (HELP_INIT == CLIPS_TRUE) { PrintCLIPS(WDIALOG,"Releasing help entries from file "); PrintCLIPS(WDIALOG,help_file); PrintCLIPS(WDIALOG,"...\n"); TextLookupToss(help_file); DeleteRouter("whelp"); HELP_INIT = CLIPS_FALSE; } rm((VOID *) help_file,(int) strlen(help_file) + 1); } if (ArgTypeCheck("help-path",1,SYMBOL_OR_STRING,&arg_ptr) == CLIPS_FALSE) return; help_name = DOToString(arg_ptr); help_file = (char *) gm2((int) strlen(help_name) + 1); strcpy(help_file,help_name); PrintCLIPS(WDIALOG,"Help entries file reset to "); PrintCLIPS(WDIALOG,help_name); PrintCLIPS(WDIALOG,"\n"); } }#endif#if CLP_TEXTPRO/***************************************************************************//*FUNCTION FetchCommand : (CLIPS function fetch) *//* Input : Name of the file to be stored in the lookup table - passed via *//* the CLIPS "stack" and result buffer *//* Output : This function loads a file into the internal lookup table and *//* returns a (float) boolean flag indicating failure or success. *//***************************************************************************/globle VOID FetchCommand(result) DATA_OBJECT *result; { char file[NAMESIZE], /*File name */ buf[NAMESIZE]; /*Error message buffer */ int load_ct; /*Number of entries loaded */ DATA_OBJECT arg_ptr; result->type = SYMBOL; result->value = CLIPSFalseSymbol; if (ArgTypeCheck("fetch",1,SYMBOL_OR_STRING,&arg_ptr) == CLIPS_FALSE) return; strcpy(file,DOToString(arg_ptr)); load_ct = TextLookupFetch(file,buf,NAMESIZE); if (load_ct == 0) { PrintErrorID("TEXTPRO",2,CLIPS_FALSE); PrintCLIPS(WERROR,"Unable to load file.\n"); if (buf[0] != NULLCHAR) PrintCLIPS(WERROR,buf); else PrintCLIPS(WERROR,"No entries found."); PrintCLIPS(WERROR,"\n"); return; } result->type = INTEGER; result->value = (VOID *) AddLong((long) load_ct); }/******************************************************************************//*FUNCTION PrintRegionCommand : (CLIPS function print-region) *//* Input : Via the CLIPS "stack", logical name for the output, the name of the*//* file to be accessed, and the name of the topic(s) to be looked up. *//* Output : This function accesses a previously loaded file and prints the *//* information of the topic entry requested to the screen. The tree *//* structure must currently be at the correct level in order for the *//* topic to be accessed. To branch down the tree, each topic in the *//* path to the one desired must be named. Multiple arguments are *//* allowed as in the help facility (see the external documentation.) *//* To branch up the tree, the special topic character `^' must be *//* specified for each upwards branch. Giving no topic name will *//* cause a single branch-up in the tree. The `?' character given at *//* the end of a path will return the current main topic menu. *//* *//* For usage, see the external documentation. *//******************************************************************************/globle int PrintRegionCommand() { struct topics *params, /*Lookup file and list of topic requests */ *tptr; /*Used in deallocating the parameter list */ char buf[256]; /*Buffer for the topic entry strings */ FILE *fp; /*Stream for the input file */ char *menu[1]; /*Buffer for the current menu name */ int status, /*Lookup status return code */ com_code; /*Completion flag */ params = GetCommandLineTopics(); fp = FindTopicInEntries(params->next->name,params->next->next,menu,&status); if ((status != NO_FILE) && (status != NO_TOPIC) && (status != EXIT)) { if (strcmp(params->name,"t") == 0) strcpy(params->name,"stdout"); PrintCLIPS(params->name,"\n"); while (grab_string(fp,buf,256) != NULL) PrintCLIPS(params->name,buf); com_code = CLIPS_TRUE; } else { /* ================================================================== On NO_TOPIC results, the file is left open to point to the current menu. This used as a check by the Help System. In the case of print-region, however, we need to always make sure the file is closed. ================================================================== */ if (fp != NULL) fclose(fp); com_code = CLIPS_FALSE; } /* ======================================================= Release any space used by the user's topic request list ======================================================= */ while (params != NULL) { tptr = params; params = params->next; rm((VOID *) tptr,(int) sizeof(struct topics)); } return(com_code); }/***************************************************************************//*FUNCTION TossCommand : (CLIPS function toss) *//* Input : Name of the file to be deleted from the lookup table (passed via*//* the CLIPS "stack") *//* Output : This function deletes the named file from the lookup table and *//* returns a (float) boolean flag indicating failure or success. *//***************************************************************************/globle int TossCommand() { char *file; /*Name of the file */ DATA_OBJECT arg_ptr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -