Jspice3
textdisp.c File Reference
#include "spice.h"
#include "hlpdefs.h"
Include dependency graph for textdisp.c:

Go to the source code of this file.

Functions

static void putline ()
 
static int putstuff ()
 
bool hlp_tdisplay (topic *top)
 
toplinkhlp_thandle (topic **parent)
 
void hlp_tkillwin (topic *top)
 
static void putline (char *s)
 
static int putstuff (toplink *tl, int base)
 

Variables

static topiccurtop
 
static bool quitflag
 
FILE * cp_in
 
FILE * cp_out
 
FILE * cp_err
 
bool out_isatty
 

Function Documentation

bool hlp_tdisplay ( topic top)

Definition at line 27 of file textdisp.c.

30 {
31  wordlist *wl;
32  int i = 0;
33  char *xx;
34 
35  curtop = top;
36 
37  out_init();
38  out_printf("\n");
39  if (cp_out == stdout) {
40  fprintf(cp_out," ");
41  fflush(cp_out);
42  cprint(15,top->title);
43  out_printf("\n");
44  }
45  else
46  out_printf("%s\n",top->title);
47  for (wl = top->text; wl; wl = wl->wl_next)
48  putline(wl->wl_word);
49  if (top->subtopics) {
50  xx = "Sub-Topics:";
51  if (cp_out == stdout) {
52  fprintf(cp_out," ");
53  fflush(cp_out);
54  cprint(15,xx);
55  out_printf("\n");
56  }
57  else
58  out_printf("%s\n",xx);
59  i = putstuff(top->subtopics, 0);
60  out_printf("\n");
61  }
62  if (top->seealso) {
63  xx = "See Also:";
64  if (cp_out == stdout) {
65  fprintf(cp_out," ");
66  fflush(cp_out);
67  cprint(15,xx);
68  out_printf("\n");
69  }
70  else
71  out_printf("%s\n",xx);
72  (void) putstuff(top->seealso, i);
73  out_printf("\n");
74  }
75  if (!top->subtopics && !top->seealso)
76  out_printf("\n");
77  return (true);
78 }
void out_printf()
static int putstuff()
toplink * seealso
Definition: hlpdefs.h:54
wordlist * text
Definition: hlpdefs.h:51
FILE * cp_out
Definition: help.c:101
toplink * subtopics
Definition: hlpdefs.h:53
Definition: library.c:18
static void putline()
static topic * curtop
Definition: textdisp.c:11
Definition: cpstd.h:21
char * title
Definition: hlpdefs.h:49
struct wordlist * wl_next
Definition: cpstd.h:23
char * wl_word
Definition: cpstd.h:22
void cprint(int clr, char *buf)
Definition: cprint.c:14
void out_init()
Definition: output.c:128
toplink* hlp_thandle ( topic **  parent)

Definition at line 82 of file textdisp.c.

85 {
86  char buf[BSIZE_SP], *s;
87  char *mesg;
88  toplink *tl;
89  int num;
90 
91  quitflag = false;
92  if (!curtop) {
93  *parent = NULL;
94  return (NULL);
95  }
96 
97  if (SCEDactive()) {
98  mesg =
99  ((curtop->subtopics || curtop->seealso) ? "Selection? " : NULL);
100  }
101  else
102  mesg = "Selection (`?' for help): ";
103 
104  for (;;) {
105  if (!SCEDfgets(buf,sizeof(buf),cp_in,mesg)) {
106  quitflag = true;
107  *parent = NULL;
108  return (NULL);
109  }
110 
111  for (s = buf; *s && isspace(*s); s++)
112  ;
113  switch (*s) {
114  case '?':
115  fprintf(cp_out,
116 "\nType the number of a sub-topic or see also, or one of:\n\
117 \tr\tReprint the current topic\n\
118 \tp or CR\tReturn to the previous topic\n\
119 \tq\tQuit help\n\
120 \t?\tPrint this message\n\n");
121  continue;
122 
123  case 'r':
124  {
125  char *ss;
126  FILE *tmp;
127  bool ttytmp;
128 
129  if ((ss = strchr(s,'\n')) != NULL)
130  *ss = '\0';
131 
132  if ((ss = strchr(s,'>')) == NULL) {
133  (void) hlp_tdisplay(curtop);
134  continue;
135  }
136  tmp = cp_out;
137  ss++;
138  if (*ss == '>') {
139  ss++;
140  cp_out = fopen(ss,"a");
141  }
142  else
143  cp_out = fopen(ss,"w");
144  if (cp_out) {
145  ttytmp = out_isatty;
146  out_isatty = isatty(fileno(cp_out));
147  (void) hlp_tdisplay(curtop);
148  out_isatty = ttytmp;
149  (void) fclose(cp_out);
150  }
151  else
152  perror(ss);
153  cp_out = tmp;
154  continue;
155  }
156 
157  case 'q':
158  quitflag = true;
159  *parent = NULL;
160  return (NULL);
161 
162  case 'p':
163  case '\0':
164  case '\n':
165  case '\r':
166  *parent = curtop;
167  return (NULL);
168  }
169  if (!isdigit(*s)) {
170  fprintf(cp_err, "Invalid command\n");
171  continue;
172  }
173  num = atoi(s);
174  if (num <= 0) {
175  fprintf(cp_err, "Bad choice.\n");
176  continue;
177  }
178  for (tl = curtop->subtopics; tl; tl = tl->next)
179  if (--num == 0)
180  break;
181  if (num) {
182  for (tl = curtop->seealso; tl; tl = tl->next)
183  if (--num == 0)
184  break;
185  }
186  if (num) {
187  fprintf(cp_err, "Bad choice.\n");
188  continue;
189  }
190  *parent = curtop;
191  return (tl);
192  }
193 }
static char buf[MAXPROMPT]
Definition: arg.c:18
bool out_isatty
Definition: output.c:45
#define BSIZE_SP
Definition: misc.h:19
Definition: outitf.c:1049
Definition: cddefs.h:119
toplink * seealso
Definition: hlpdefs.h:54
FILE * cp_out
Definition: help.c:101
toplink * subtopics
Definition: hlpdefs.h:53
#define NULL
Definition: spdefs.h:121
char * SCEDfgets(char *s, int n, FILE *fp, char *prompt)
Definition: scedstub.c:41
void perror()
static topic * curtop
Definition: textdisp.c:11
FILE * cp_in
Definition: help.c:101
bool hlp_tdisplay(topic *top)
Definition: textdisp.c:27
enum Active SCEDactive()
Definition: scedstub.c:63
FILE * cp_err
Definition: help.c:101
static bool quitflag
Definition: textdisp.c:12
void hlp_tkillwin ( topic top)

Definition at line 198 of file textdisp.c.

201 {
202  if (curtop)
203  curtop = curtop->parent;
204  if (curtop && !quitflag)
205  (void) hlp_tdisplay(curtop);
206  return;
207 }
struct topic * parent
Definition: hlpdefs.h:57
static topic * curtop
Definition: textdisp.c:11
bool hlp_tdisplay(topic *top)
Definition: textdisp.c:27
static bool quitflag
Definition: textdisp.c:12
static void putline ( )
static
static void putline ( char *  s)
static

Definition at line 212 of file textdisp.c.

216 {
217  char buf[BSIZE_SP];
218  int i = 0;
219 
220  while (*s) {
221  if (((*s == '\033') && s[1]) ||
222  ((*s == '_') && (s[1] == '\b')))
223  s += 2;
224  else
225  buf[i++] = *s++;
226  }
227  buf[i] = '\0';
228  out_printf("%s\n", buf);
229  return;
230 }
static char buf[MAXPROMPT]
Definition: arg.c:18
#define BSIZE_SP
Definition: misc.h:19
void out_printf()
Definition: cddefs.h:119
static int putstuff ( )
static
static int putstuff ( toplink tl,
int  base 
)
static

Definition at line 234 of file textdisp.c.

241 {
242  int width, maxwidth = 0, ncols, nrows, nbuts = 0, i, j, k;
243  toplink *tt;
244 
245  if (SCEDactive())
246  width = 72;
247  else
248  out_winsize(&width,NULL);
249  width -= 4;
250  for (tt = tl; tt; tt = tt->next) {
251  if (strlen(tt->description) + 5 > maxwidth)
252  maxwidth = strlen(tt->description) + 5;
253  nbuts++;
254  }
255  ncols = width / maxwidth;
256  if (!ncols) {
257  fprintf(stderr, "Help, button too big!!\n");
258  return (0);
259  }
260  if (ncols > nbuts)
261  ncols = nbuts;
262  maxwidth = width / ncols;
263  nrows = nbuts / ncols;
264  if (nrows * ncols < nbuts)
265  nrows++;
266 
267  for (i = 0; i < nrows; i++) {
268  for (tt = tl, j = 0; j < i; j++, tt = tt->next)
269  ;
270  for (j = 0; j < ncols; j++) {
271  if (tt)
272  out_printf("%2d) %-*s ", base + j * nrows + i +
273  1, maxwidth - 5, tt->description);
274  for (k = 0; k < nrows; k++)
275  if (tt)
276  tt = tt->next;
277 
278  }
279  out_printf("\n");
280  }
281  return (nbuts);
282 }
void out_printf()
Definition: xforms.c:16
#define NULL
Definition: spdefs.h:121
void out_winsize()
enum Active SCEDactive()
Definition: scedstub.c:63

Variable Documentation

FILE * cp_err

Definition at line 101 of file help.c.

FILE* cp_in

Definition at line 101 of file help.c.

FILE * cp_out

Definition at line 101 of file help.c.

topic* curtop
static

Definition at line 11 of file textdisp.c.

bool out_isatty

Definition at line 45 of file output.c.

bool quitflag
static

Definition at line 12 of file textdisp.c.