home *** CD-ROM | disk | FTP | other *** search
- /* ==( help/callhelp.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written JPK 26-Sep-88 */
- /* Modified Geo 12-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 12-Dec-89 Geo - V2 version with variable lines
- * 25-Oct-89 Geo - 1.32 Merge
- *
- *
- */
- # include <stdio.h>
- # include <bench.h>
- # include <fileio.h>
-
- # define NOTINHERE
- # include "help.h"
- # undef NOTINHERE
-
- /* Contains help interface routine call_help() */
-
- /* global variables used to work with current help node */
- struct help_hdr h_header;
- struct help_ndx h_ndx;
- struct help_ndx h_tdx;
- struct help_part h_part;
-
- char h_file[128];
- int h_num;
- FILE * hfptr;
- int nfd = -1;
-
- char HlpNotFound[] = "Help message not found, Create it ?";
- char HlpBusy[] = "Help file is busy...\n Retry?";
- # ifdef HDEBUG
- char BldNdxFail[] = "openhelp(): build_help_ndxfile failed";
- # endif
-
- /*
- * name : call_help
- *
- * synopsis : int call_help(file, helpnum)
- * char * file; help file
- * int helpnum; help number
- *
- * Provides the interface for users to use the help facilities. The user
- * specifies a help file and help node number. If the file exists and the
- * help node exists then it is displayed. If the help node does not exit
- * a message is to that effect is displayed along with a prompt to press
- * ENTER. If the user instead presses F2 , the help node will be created
- * and initialize. If the help file does not exist, it is created and
- * then the help node is treated as if it does not exist
- *
- * return : TRUE if successful, FALSE if not
- */
-
- int call_help(file, helpnum)
- char * file;
- int helpnum;
- {
- char * dot;
- int *save_curr_whandle = 0; /* Added Geo */
- int hand2 = 0; /* Added Geo */
-
- if (helpnum <= 0)
- return(FALSE);
-
- /* initialize the global variables */
- h_num = helpnum;
- h_part.pos = 1;
-
- /* copy the file and delete any extension that may be on it */
- (void) strcpy(h_file, file);
- stripext(h_file);
-
- /* open the help files */
- if (openhelp(h_file, helpnum) == FALSE)
- {
- /* open and create has failed so abort with error code */
- return(FALSE);
- }
-
- /* index number does not exist */
- if (check_index(helpnum) == FALSE)
- {
- if (warning(-1, HlpNotFound))
- {
- if (check_index(helpnum) == FALSE)
- {
- if (create_node(helpnum) == FALSE)
- return(FALSE);
- }
- }
- else
- {
- /* doesn't want to create it, so clean up and abort */
- close_help_files();
- return(FALSE);
- }
- }
- /* read in the requested index */
- while (lock_index(helpnum, RLOK) == FALSE)
- {
- if (!warning(-1, HlpBusy))
- {
- close_help_files();
- return(FALSE);
- }
- flushscr();
- }
- if (read_index(helpnum) == FALSE) /* Read failed?!?!?! */
- {
- lock_index(helpnum, ULOK);
- close_help_files();
- return(FALSE);
- }
-
- /* read in the help header */
- if (read_hdr(&h_ndx) == FALSE)
- {
- /* header read failed so clean up and abort */
- lock_index(helpnum, ULOK);
- close_help_files();
- return(FALSE);
- }
-
- /* everything else is done, set up index for read and display */
- open_help_ndxfile();
- if (build_help_ndxfile(helpnum) == FALSE)
- {
- # ifdef HDEBUG
- errmsg(BldNdxFail);
- # endif
- return(FALSE);
- }
-
- /*
- * Bind to current window
- */
- if (winptr->handle == (int *)0)
- winptr->handle = &hand2;
-
- save_curr_whandle = winptr->handle;
-
- /* read and display the help text */
- display_help(&h_header);
-
- lock_index(helpnum, ULOK);
- close_help_files();
-
- /*
- * restore window control
- */
- if (!sel_w(save_curr_whandle))
- fprintf(stderr, "\ncallhelp(): cannot reselect original window\n");
- if (save_curr_whandle == &hand2)
- winptr->handle = (int *)0;
-
- return(TRUE);
- }
-
-
- void close_help_files()
- {
- char tmp_ndxfile[128];
- char *envptr;
- char pidstr[10];
-
- (void) fclose(hfptr);
- closef(nfd);
- nfd = -1;
- close_help_ndxfile();
-
- envptr = getenv("TMP");
- if (envptr == NULL)
- getcwd(tmp_ndxfile, 127);
- else
- strcpy(tmp_ndxfile, envptr);
- addslash(tmp_ndxfile);
- # ifdef __WATCOMC__
- sprintf(pidstr, "%04X.tdx", 0x1234);
- # else
- sprintf(pidstr, "%04X.tdx", getpid());
- # endif
- strcat(tmp_ndxfile, pidstr);
- unlink(tmp_ndxfile);
- }
-
-