home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / src / vmshelp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  4.0 KB  |  132 lines

  1.  
  2. /* vms_get_help.c */
  3.  
  4. #include <stdio.h>
  5. #include <descrip.h>
  6.  
  7. /* Not all systems have this (GCC) so I am not using it. */
  8. /* #include <hlpdef.h> */
  9. #define HLP$M_PROMPT 1
  10. #define HLP$M_LIBLIST 16
  11.  
  12. #include "slang.h"
  13. #include "buffer.h"
  14. #include "ins.h"
  15.  
  16. /*    Need to pass strings by descriptor to LBR$OUTPUT_HELP;    */        
  17. /*    string descriptors in SYS$LIBRARY:DESCRIP.H.        */
  18.  
  19.  
  20. /*    Change definition of $DESCRIPTOR macro. In descrip.h,    */
  21. /*    sizeof(string)-1 used, but sizeof() bites on strings    */
  22. /*    with spaces, or with '$'. That means that the filename    */
  23. /*    might be truncated (i.e., 'SYS$HELP:HELPLIB.OLB'    */
  24. /*    becomes 'SYS'). Ditto the topic (i.e., 'SET HOST /LOG'    */
  25. /*    becomes 'SET').                        */
  26.  
  27. #define $STR_DESC(name,string) struct dsc$descriptor_s name = \
  28.              { strlen(string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string }
  29.  
  30.  
  31. /*--------------------------------------------------------------*/
  32. /*                                */
  33. /*    vms_get_help: call the librarian utility to get help    */
  34. /*                                */
  35. /*    input:                            */
  36. /*    char helpfile  - name of the help file to use        */
  37. /*    char helptopic - name of topic to use initially        */
  38. /*             (Since HLP$M_PROMPT is set, user will    */
  39. /*              get interactive prompting once in.)    */
  40. /*    returns:                        */
  41. /*    int           - 0 for failure, 1 for success        */
  42. /*                                */
  43. /*    Translated from a FORTRAN subroutine. That subroutine    */
  44. /*    was gutted from several of J.W. Pflugrath's routines    */
  45. /*    for I/O, et cetera.                    */
  46. /*                                */
  47. /*    Jim Clifton    Brandeis University            */
  48. /*    J.W. Pflugrath    Cold Spring Harbor Laboratory        */
  49. /*                                */
  50. /*--------------------------------------------------------------*/
  51.  
  52. int vms_get_help(char *helpfile, char *helptopic)
  53. {
  54.    int LBR$OUTPUT_HELP(), output_help_to_buf(), input_new_helptopic();
  55.    int istat;
  56.    unsigned int flags;
  57.    $STR_DESC(topnam,helptopic);
  58.    $STR_DESC(filnam,helpfile);
  59.  
  60.    
  61.    flags = HLP$M_PROMPT;
  62.  
  63.    istat = LBR$OUTPUT_HELP(&output_help_to_buf,
  64.                0,  /* output width 0 is 80 */
  65.                &topnam,  /* topic */
  66.                &filnam, /* lib file */
  67.                &flags,
  68.                /* Also try:
  69.                            M_LIBLIST
  70.                            M_HELP */
  71.                &input_new_helptopic);
  72.    if (istat != 1) return 0;
  73.    return 1;
  74. }
  75.  
  76.  
  77. /*----------------------------------------------------------------------*/
  78. /*                                    */
  79. /*    Here we mimic the syntax of LIB$PUT_OUTPUT            */
  80. /*                                    */
  81. /* VMS system procedures (including the RTL) pass strings by        */
  82. /* descriptor. That's what LBR$OUTPUT_HELP expects (demands!). This     */
  83. /* routine (and the next) just function to integrate LBR$OUTPUT_HELP    */
  84. /* I/O into jed I/O.                            */
  85. /*                                    */
  86. /*    Jim Clifton    Brandeis University                */
  87. /*                                    */
  88. /*----------------------------------------------------------------------*/
  89.  
  90. int output_help_to_buf(struct dsc$descriptor_s *string)
  91. {
  92.    ins_chars((unsigned char *) string->dsc$a_pointer, string->dsc$w_length);
  93.    newline ();
  94.    return(1);    /* should add codes that LIB$PUT_OUTPUT can return */
  95. }
  96.  
  97.  
  98. /*----------------------------------------------------------------------*/
  99. /*                                    */
  100. /*    Mimic the syntax of LIB$GET_INPUT()                */
  101. /*                                    */
  102. /* Note that the first 2 characters of the LBR$OUTPUT_HELP prompt are    */
  103. /* "^M^J", so we send read_from_minibuffer the address of the 3rd char.    */
  104. /*                                    */
  105. /*    Jim Clifton    Brandeis University                */
  106. /*                                    */
  107. /*----------------------------------------------------------------------*/
  108.  
  109. int input_new_helptopic(struct dsc$descriptor_s *newtopic,
  110.             struct dsc$descriptor_s *prompt,
  111.             unsigned int *len_newtopic)
  112. {
  113.    char *newtop, promp[80];
  114.    int dofree = 0;
  115.     
  116.    strncpy(promp,prompt->dsc$a_pointer,prompt->dsc$w_length);
  117.    promp[prompt->dsc$w_length] = 0;
  118.  
  119.    if (!SLang_run_hooks("vms_help_newtopic", promp + 2, NULL)
  120.        || SLang_pop_string(&newtop, &dofree)) newtop = "";
  121.    
  122.    strcpy(newtopic->dsc$a_pointer,newtop);
  123.    len_newtopic = newtopic->dsc$w_length = strlen(newtop);
  124.    newtopic->dsc$b_dtype = DSC$K_DTYPE_T;
  125.    newtopic->dsc$b_class = DSC$K_CLASS_S;
  126.  
  127.    if (dofree == 1) SLFREE(newtop);
  128.    
  129.    return(1);    /* should add codes that LIB$GET_INPUT can return */
  130. }
  131.  
  132.