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