home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / PROCWRKB.ZIP / BENCH1.ZIP / HELP / CALLHELP.C next >
Encoding:
C/C++ Source or Header  |  1990-08-07  |  4.5 KB  |  198 lines

  1. /* ==( help/callhelp.c )== */
  2. /* ----------------------------------------------- */
  3. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  4. /* Modification to this source is not supported    */
  5. /* by Vestronix Inc.                               */
  6. /*            All Rights Reserved                  */
  7. /* ----------------------------------------------- */
  8. /* Written   JPK  26-Sep-88                        */
  9. /* Modified  Geo  12-Dec-89  See comments below    */
  10. /* ----------------------------------------------- */
  11. /* %W%  (%H% %T%) */
  12.  
  13. /*
  14.  *  Modifications
  15.  *
  16.  *  12-Dec-89  Geo - V2 version with variable lines
  17.  *  25-Oct-89  Geo - 1.32 Merge
  18.  *
  19.  *
  20. */
  21. # include <stdio.h>
  22. # include <bench.h>
  23. # include <fileio.h>
  24.  
  25. # define NOTINHERE
  26. #  include "help.h"
  27. # undef NOTINHERE
  28.  
  29. /* Contains help interface routine call_help() */
  30.  
  31. /* global variables used to work with current help node */
  32. struct help_hdr h_header;
  33. struct help_ndx h_ndx;
  34. struct help_ndx h_tdx;
  35. struct help_part h_part;
  36.  
  37. char h_file[128];
  38. int h_num;
  39. FILE * hfptr;
  40. int nfd = -1;
  41.  
  42. char HlpNotFound[] = "Help message not found, Create it ?";
  43. char HlpBusy[]     = "Help file is busy...\n      Retry?";
  44. # ifdef HDEBUG
  45. char BldNdxFail[] = "openhelp(): build_help_ndxfile failed";
  46. # endif
  47.  
  48. /*
  49.  * name        : call_help
  50.  *
  51.  * synopsis    : int call_help(file, helpnum)
  52.  *              char * file;            help file
  53.  *              int helpnum;            help number
  54.  *
  55.  *  Provides the interface for users to use the help facilities.  The user
  56.  *  specifies a help file and help node number.  If the file exists and the
  57.  *  help node exists then it is displayed.  If the help node does not exit
  58.  *  a message is to that effect is displayed along with a prompt to press
  59.  *  ENTER.  If the user instead presses F2 , the help node will be created
  60.  *  and initialize.  If the help file does not exist, it is created and
  61.  *  then the help node is treated as if it does not exist
  62.  *
  63.  * return    : TRUE if successful, FALSE if not
  64. */
  65.  
  66. int call_help(file, helpnum)
  67.     char    * file;
  68.     int    helpnum;
  69. {
  70.     char * dot;
  71.     int *save_curr_whandle = 0; /* Added Geo */
  72.     int hand2 = 0; /* Added Geo */
  73.  
  74.     if (helpnum <= 0)
  75.         return(FALSE);
  76.  
  77.     /* initialize the global variables */
  78.     h_num = helpnum;
  79.     h_part.pos = 1;
  80.  
  81.     /* copy the file and delete any extension that may be on it */
  82.     (void) strcpy(h_file, file);
  83.     stripext(h_file);
  84.  
  85.     /* open the help files */
  86.     if (openhelp(h_file, helpnum) == FALSE)
  87.     {
  88.         /* open and create has failed so abort with error code */
  89.         return(FALSE);
  90.     }
  91.  
  92.     /* index number does not exist */
  93.     if (check_index(helpnum) == FALSE)
  94.     {
  95.         if (warning(-1, HlpNotFound))
  96.         {
  97.             if (check_index(helpnum) == FALSE)
  98.             {
  99.                 if (create_node(helpnum) == FALSE)
  100.                     return(FALSE);
  101.             }
  102.         }
  103.         else
  104.         {
  105.             /* doesn't want to create it, so clean up and abort */
  106.             close_help_files();
  107.             return(FALSE);
  108.         }
  109.     }
  110.     /* read in the requested index */
  111.     while (lock_index(helpnum, RLOK) == FALSE)
  112.     {
  113.         if (!warning(-1, HlpBusy))
  114.         {
  115.             close_help_files();
  116.             return(FALSE);
  117.         }
  118.         flushscr();
  119.     }
  120.     if (read_index(helpnum) == FALSE) /* Read failed?!?!?! */
  121.     {
  122.         lock_index(helpnum, ULOK);
  123.         close_help_files();
  124.         return(FALSE);
  125.     }
  126.  
  127.     /* read in the help header */
  128.     if (read_hdr(&h_ndx) == FALSE)
  129.     {
  130.         /* header read failed so clean up and abort */
  131.         lock_index(helpnum, ULOK);
  132.         close_help_files();
  133.         return(FALSE);
  134.     }
  135.  
  136.     /* everything else is done, set up index for read and display */
  137.     open_help_ndxfile();
  138.     if (build_help_ndxfile(helpnum) == FALSE)
  139.     {
  140. # ifdef HDEBUG
  141.         errmsg(BldNdxFail);
  142. # endif
  143.         return(FALSE);
  144.     }
  145.  
  146.     /*
  147.      * Bind to current window
  148.     */
  149.     if (winptr->handle == (int *)0)
  150.         winptr->handle = &hand2;
  151.  
  152.     save_curr_whandle = winptr->handle;
  153.  
  154.     /* read and display the help text */
  155.     display_help(&h_header);
  156.  
  157.     lock_index(helpnum, ULOK);
  158.     close_help_files();
  159.  
  160.     /*
  161.      * restore window control
  162.     */
  163.     if (!sel_w(save_curr_whandle))
  164.         fprintf(stderr, "\ncallhelp(): cannot reselect original window\n");
  165.     if (save_curr_whandle == &hand2)
  166.         winptr->handle = (int *)0;
  167.  
  168.     return(TRUE);
  169. }
  170.  
  171.  
  172. void close_help_files()
  173. {
  174.     char tmp_ndxfile[128];
  175.     char *envptr;
  176.     char pidstr[10];
  177.  
  178.     (void) fclose(hfptr);
  179.     closef(nfd);
  180.     nfd = -1;
  181.     close_help_ndxfile();
  182.  
  183.     envptr = getenv("TMP");
  184.     if (envptr == NULL)
  185.         getcwd(tmp_ndxfile, 127);
  186.     else
  187.         strcpy(tmp_ndxfile, envptr);
  188.     addslash(tmp_ndxfile);
  189. # ifdef __WATCOMC__
  190.     sprintf(pidstr, "%04X.tdx", 0x1234);
  191. # else
  192.     sprintf(pidstr, "%04X.tdx", getpid());
  193. # endif
  194.     strcat(tmp_ndxfile, pidstr);
  195.     unlink(tmp_ndxfile);
  196. }
  197.  
  198.