The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
WindIO.c
Go to the documentation of this file.
1 /************************************************************************/
2 /**
3 
4  \file WindIO.c
5 
6  \version V1.5
7  \date 07.07.14
8  \brief Windowing I/O for various systems
9 
10  \copyright (c) UCL / Dr. Andrew C. R. Martin 1992-2014
11  \author Dr. Andrew C. R. Martin
12  \par
13  Institute of Structural & Molecular Biology,
14  University College London,
15  Gower Street,
16  London.
17  WC1E 6BT.
18  \par
19  andrew@bioinf.org.uk
20  andrew.martin@ucl.ac.uk
21 
22 **************************************************************************
23 
24  This code is NOT IN THE PUBLIC DOMAIN, but it may be copied
25  according to the conditions laid out in the accompanying file
26  COPYING.DOC.
27 
28  The code may be modified as required, but any modifications must be
29  documented so that the person responsible can be identified.
30 
31  The code may not be sold commercially or included as part of a
32  commercial product except as described in the file COPYING.DOC.
33 
34 **************************************************************************
35 
36  Description:
37  ============
38 
39 
40 **************************************************************************
41 
42  Usage:
43  ======
44 
45 **************************************************************************
46 
47  Revision History:
48  =================
49 - V0.4 25.09.92 Original test version
50 - V1.0 11.03.94 Various tidying up for release
51  Added RePrompt() and WindowMode()
52 - V1.1 15.03.94 Added sInteractive and modified logic with sWindowMode
53 - V1.2 18.03.94 Bug fix in WindowInteractive(). Includes SysDefs.h
54 - V1.3 18.10.95 Moved Yorn() here from general.c
55 - V1.4 01.02.01 Changed gets() to fgets()
56 - V1.5 07.07.14 Use bl prefix for functions By: CTP
57 
58 
59 *************************************************************************/
60 /* Doxygen
61  -------
62  #GROUP General Programming
63  #SUBGROUP Text window handling - experimental
64  #FUNCTION blScreen()
65  Writes information to the screen. Handles any windows as appropriate.
66 
67  #FUNCTION blPrompt()
68  Sets a prompt for input. If windowing is on, this simply sets the
69  prompt variable (the actual prompt is issued by the GetKybdString()
70  function). If no windowing is used, the actual string is printed.
71  If the prompt ends with a . it is simply printed; if not, a > is
72  appended.
73 
74  #FUNCTION blRePrompt()
75  Reissue the current prompt. Only has any effect when windowing is not
76  in use. Normally only used by ReadBufferedFile() and
77  ProbeBufferedFile() to re-issue prompts while eating blank lines.
78 
79  #FUNCTION blGetKybdString()
80  Reads a string from the keyboard
81 
82  #FUNCTION blPagingOn()
83  Switches on screen paging.
84 
85  #FUNCTION blPagingOff()
86  Switches off screen paging.
87 
88  #FUNCTION blWindowMode()
89  Switch window mode on or off.
90 
91  #FUNCTION blWindowInteractive()
92  Switch interactive mode on or off.
93  If switched off, calls WindowMode(FALSE) to switch off windowing
94 
95  #FUNCTION blYorN()
96  Get a yes or no response from the keyboard
97 */
98 /************************************************************************/
99 /* Definition of windowing type. If nothing defined, simple screen I/O
100  will be used.
101 */
102 /* #define CURSES */ /* Curses windowing */
103 /* #define AMIGA_WINDOWS */ /* Amiga windowing */
104 
105 /************************************************************************/
106 /* Includes
107 */
108 #include <stdio.h>
109 #include <string.h>
110 
111 #include "SysDefs.h"
112 #include "WindIO.h"
113 
114 /************************************************************************/
115 /* Defines and macros
116 */
117 #if defined(CURSES) || defined(AMIGA_WINDOWS)
118 # define WINDOWING
119 #endif
120 
121 /************************************************************************/
122 /* Globals
123 */
124 static char sPromptString[40];
125 static int sLineCount = 0;
126 static BOOL sDoPaging = FALSE,
127  sWindowMode = FALSE,
128  sInteractive = TRUE;
129 
130 /************************************************************************/
131 /* Prototypes
132 */
133 
134 /************************************************************************/
135 /*>blScreen(char *string)
136  ----------------------
137 *//**
138 
139  \param[in] *string String to write on window
140 
141  Writes information to the screen. Handles any windows as appropriate.
142 
143 - 25.09.92 Original
144 - 02.10.92 Added CURSES support
145 - 05.10.92 Added AMIGA_WINDOWS support
146 - 07.10.92 Added paging support
147 - 11.03.94 Added check on sWindowMode
148 - 14.03.94 Changed this to check on sInteractive
149  Changed check on WINDOWING to sWindowMode
150 - 01.02.01 Added maxlen parameter
151 - 15.02.01 oops! removed maxlen parameter, value of 80 should have gone
152  into GetKybdString()
153 - 07.07.14 Use bl prefix for functions By: CTP
154 */
155 void blScreen(char *string)
156 {
157  if(sDoPaging && sInteractive)
158  {
159  if(strchr(string,'\n'))
160  {
161  if(sLineCount++ > 18)
162  {
163  char dummy[80];
164 
165  sLineCount = 0;
166 
167  if(!sWindowMode)
168  printf("\n");
169 
170  blPrompt("More...");
171  blGetKybdString(dummy, 80);
172  }
173  }
174  }
175 
176 #ifndef WINDOWING
177  printf("%s",string);
178 #else
179  if(sWindowMode)
180  {
181 # ifdef AMIGA_WINDOWS
182  WriteMessageNR(string);
183 # endif
184 # ifdef CURSES
185  outputstring(string);
186 # endif
187  }
188  else
189  {
190  printf("%s",string);
191  }
192 #endif
193 
194  return;
195 }
196 
197 /************************************************************************/
198 /*>blPrompt(char *string)
199  ----------------------
200 *//**
201 
202  \param[in] *string Prompt string
203 
204  Sets a prompt for input. If windowing is on, this simply sets the
205  prompt variable (the actual prompt is issued by the GetKybdString()
206  function). If no windowing is used, the actual string is printed.
207  If the prompt ends with a . it is simply printed; if not, a > is
208  appended.
209 
210 - 25.09.92 Original
211 - 02.10.92 Added CURSES support
212 - 05.10.92 Added AMIGA_WINDOWS support
213 - 11.03.94 Modified to save prompt string even if not windowing
214 - 15.03.94 Now sets up string and just calls RePrompt()
215 - 07.07.14 Use bl prefix for functions By: CTP
216 */
217 void blPrompt(char *string)
218 {
219  if(string[strlen(string)-1] == '.')
220  sprintf(sPromptString,"%s ",string);
221  else
222  sprintf(sPromptString,"%s> ",string);
223 
224  blRePrompt();
225 }
226 
227 /************************************************************************/
228 /*>void blRePrompt(void)
229  ---------------------
230 *//**
231 
232  Reissue the current prompt. Only has any effect when windowing is not
233  in use. Normally only used by ReadBufferedFile() and
234  ProbeBufferedFile() to re-issue prompts while eating blank lines.
235 
236 - 10.03.94 Original By: ACRM
237 - 15.03.94 Changed to work whenever we're not windowing and are
238  interactive
239 - 07.07.14 Use bl prefix for functions By: CTP
240 */
241 void blRePrompt(void)
242 {
243  if(!sWindowMode && sInteractive)
244  {
245  printf("%s",sPromptString);
246  fflush(stdout);
247  }
248 }
249 
250 /************************************************************************/
251 /*>void blGetKybdString(char *string, int maxlen)
252  ----------------------------------------------
253 *//**
254 
255  Reads a string from the keyboard
256 
257 - 02.10.92 Original
258 - 05.10.92 Added AMIGA_WINDOWS support
259 - 15.03.94 Added check on sWindowMode
260 - 01.02.01 Added maxlen parameter and changed gets() to fgets()
261 - 07.07.14 Use bl prefix for functions By: CTP
262 */
263 void blGetKybdString(char *string, int maxlen)
264 {
265  if(sWindowMode)
266  {
267 #ifdef AMIGA_WINDOWS
268  ReadKybd(sPromptString,string,79);
269 #endif
270 
271 #ifdef CURSES
272  GetCursesString(sPromptString, string);
273 #endif
274 
275 #ifndef WINDOWING
276  fgets(string,maxlen,stdin);
277 #endif
278  }
279  else
280  {
281  fgets(string,maxlen,stdin);
282  }
283 }
284 
285 /************************************************************************/
286 /*>void blPagingOn(void)
287  ---------------------
288 *//**
289 
290  Switches on screen paging.
291 
292 - 07.10.92 Original
293 - 07.07.14 Use bl prefix for functions By: CTP
294 */
295 void blPagingOn(void)
296 {
297  sLineCount = 0;
298  sDoPaging = TRUE;
299 }
300 
301 /************************************************************************/
302 /*>void blPagingOff(void)
303  ----------------------
304 *//**
305 
306  Switches off screen paging.
307 
308 - 07.10.92 Original
309 - 07.07.14 Use bl prefix for functions By: CTP
310 */
311 void blPagingOff(void)
312 {
313  sDoPaging = FALSE;
314 }
315 
316 /************************************************************************/
317 /*>void blWindowMode(BOOL mode)
318  ----------------------------
319 *//**
320 
321  \param[in] mode TRUE: Use windowing
322  FALSE: Output normally (default)
323 
324  Switch window mode on or off.
325 
326 - 11.03.94 Original By: ACRM
327 - 15.03.94 Added check on WINDOWING
328 - 07.07.14 Use bl prefix for functions By: CTP
329 */
330 void blWindowMode(BOOL mode)
331 {
332 #ifdef WINDOWING
333  sWindowMode = mode;
334 #else
335  sWindowMode = FALSE;
336 #endif
337 }
338 
339 /************************************************************************/
340 /*>void blWindowInteractive(BOOL mode)
341  -----------------------------------
342 *//**
343 
344  \param[in] mode TRUE: Is interactive (default)
345  FALSE: Not interactive
346 
347  Switch interactive mode on or off.
348  If switched off, calls WindowMode(FALSE) to switch off windowing
349 
350 - 15.03.94 Original By: ACRM
351 - 17.03.94 Set sInteractive not sWindowMode!
352 - 07.07.14 Use bl prefix for functions By: CTP
353 */
355 {
356  sInteractive = mode;
357 
358  if(!mode) blWindowMode(FALSE);
359 }
360 
361 
362 /************************************************************************/
363 /*>int blYorN(char deflt)
364  ----------------------
365 *//**
366 
367  \param[in] *deflt Default response ('y' or 'n') if return is
368  pressed without a letter or an invalid letter
369  is given
370  \return 0 if the user responds with N or n
371  1 if the user responds with Y or y
372  2 if the user responds with A or a
373  3 if the user responds with Q or q
374 
375  Get a yes or no response from the keyboard
376 
377  A default ('y' or 'n') is supplied in the function call and hitting
378  <return> or supplying any invalid character will result in the
379  default being used.
380 
381  The routine will work correctly with any response which starts with
382  the right letter (e.g. Yes, Yeah, yellow(!), no, Never, etc.)
383 
384 - 18.06.93 Original By: ACRM
385 - 01.02.01 Added maxlen parameter to GetKybdString()
386 - 07.07.14 Use bl prefix for functions By: CTP
387 */
388 int blYorN(char deflt)
389 {
390  char buffer[80],
391  response;
392  int i;
393 
394  blGetKybdString(buffer, 20);
395  response = buffer[0];
396 
397  if((response != 'Y') && (response != 'y') &&
398  (response != 'N') && (response != 'n') &&
399  (response != 'A') && (response != 'a') &&
400  (response != 'Q') && (response != 'q'))
401  {
402  response = deflt;
403  }
404 
405  switch(response)
406  {
407  case 'Y':
408  case 'y':
409  i = 1;
410  break;
411  case 'N':
412  case 'n':
413  i = 0;
414  break;
415  case 'A':
416  case 'a':
417  i = 2;
418  break;
419  case 'Q':
420  case 'q':
421  i = 3;
422  break;
423  default: /* Should never occur */
424  i=0;
425  break;
426  }
427 
428  return(i);
429 }
430 
431 
void blScreen(char *string)
Definition: WindIO.c:155
void blRePrompt(void)
Definition: WindIO.c:241
short BOOL
Definition: SysDefs.h:64
Header for window/normal interface routines.
void blGetKybdString(char *string, int maxlen)
Definition: WindIO.c:263
#define FALSE
Definition: macros.h:223
void blPagingOn(void)
Definition: WindIO.c:295
#define TRUE
Definition: macros.h:219
void blPrompt(char *string)
Definition: WindIO.c:217
System-type variable type definitions.
int blYorN(char deflt)
Definition: WindIO.c:388
void blWindowInteractive(BOOL mode)
Definition: WindIO.c:354
void blPagingOff(void)
Definition: WindIO.c:311
void blWindowMode(BOOL mode)
Definition: WindIO.c:330