| 1 |
/* @(#)tvhelp.c 19.1 (ES0-DMD) 02/25/03 13:58:15 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 30 |
|
| 31 |
.TYPE Module |
| 32 |
.IDENTIFICATION tvhelp.c |
| 33 |
.AUTHOR Francois Ochsenbein [ESO-IPG] |
| 34 |
.LANGUAGE C |
| 35 |
.KEYWORDS On-line editing facilities |
| 36 |
.ENVIRONMENT TermWindows |
| 37 |
.COMMENTS This module contains routines to show the Help Window. |
| 38 |
\begin{TeX} |
| 39 |
\\ |
| 40 |
The Help Window displays the Available Control Characters. |
| 41 |
\end{TeX} |
| 42 |
|
| 43 |
.VERSION 3.0 20-Apr-1988: Creation for MIDAS usage |
| 44 |
----------------------------------------------------------------------------*/ |
| 45 |
|
| 46 |
#define DEBUG 0 /* For debugging only */ |
| 47 |
|
| 48 |
#define PM_LEVEL LEVEL_TV |
| 49 |
|
| 50 |
#define TW_import 0 /* Do not use macro window definitions */ |
| 51 |
#define TW_STRUCT 0 /* Do not use window Structures */ |
| 52 |
#include <twset.h> |
| 53 |
|
| 54 |
MID_EXTERN TERM *terms; |
| 55 |
|
| 56 |
#if DEBUG |
| 57 |
#define ENTER_DEBUG(x) ENTER(x) |
| 58 |
#define EXIT_DEBUG(x) EXIT(x) |
| 59 |
#else |
| 60 |
#define ENTER_DEBUG(x) |
| 61 |
#define EXIT_DEBUG(x) return(x) |
| 62 |
#endif |
| 63 |
|
| 64 |
MID_STATIC ACHAR *help_text = NULL_PTR(ACHAR); |
| 65 |
MID_STATIC int hlines = 0; |
| 66 |
static int J; /* Width of help text */ |
| 67 |
|
| 68 |
#define hcols 27 |
| 69 |
|
| 70 |
MID_RSTATIC char *Explanations[] = { |
| 71 |
NULL_PTR(char), /* TW_cc_NONE 0 */ |
| 72 |
"Interrupt", /* TW_cc_INT 1 */ |
| 73 |
"Emergency Stop", /* TW_cc_QUIT 2 */ |
| 74 |
"Exit (EOF)", /* TW_cc_EOF 3 */ |
| 75 |
"Show Help", /* TW_cc_HELP 4 */ |
| 76 |
"Refresh Input", /* TW_cc_REFR 5 */ |
| 77 |
"Switch Insert/Replace", /* TW_cc_MODE 6 */ |
| 78 |
"Escape (raw)", /* TW_cc_RAW 7 */ |
| 79 |
"Return", /* TW_cc_RET 8 */ |
| 80 |
"Move Up", /* TW_cc_UP (9+_UP_)*/ |
| 81 |
"Move Down", /* TW_cc_DOWN (9+_DOWN_)*/ |
| 82 |
"Move Left <==", /* TW_cc_LEFT (9+_LEFT_)*/ |
| 83 |
"Move Right ==>", /* TW_cc_RIGHT (9+_RIGHT_)*/ |
| 84 |
"Move Home", /* TW_cc_HOME (9+_HOME_)*/ |
| 85 |
"Move to End_of_Line", /* TW_cc_EOL 14 */ |
| 86 |
"Move to Next Word", /* TW_cc_NW 15 */ |
| 87 |
"Erase Previous Char", /* TW_cc_DELC 16 */ |
| 88 |
"Erase Previous Word", /* TW_cc_DELW 17 */ |
| 89 |
"Erase to End_of_line", /* TW_cc_DELE 18 */ |
| 90 |
"Erase Whole" /* TW_cc_DELL 19 */ |
| 91 |
}; |
| 92 |
|
| 93 |
/* MONITOR(TVHELP); */ /* CG. status is here innecessary */ |
| 94 |
|
| 95 |
|
| 96 |
/*========================================================================== |
| 97 |
* Create |
| 98 |
*==========================================================================*/ |
| 99 |
static int Create() |
| 100 |
/*+++ |
| 101 |
.PURPOSE Open and Create the Standard Help Text |
| 102 |
.RETURNS OK / NOK |
| 103 |
.REMARKS |
| 104 |
---*/ |
| 105 |
{ |
| 106 |
char *p; |
| 107 |
ACHAR *pa; |
| 108 |
int i, j, k, cols_per_line; |
| 109 |
MID_STATIC char cta[5] = " ^ "; |
| 110 |
|
| 111 |
ENTER("Create"); |
| 112 |
|
| 113 |
/* status = NOK; */ |
| 114 |
if (help_text) EXIT(OK); |
| 115 |
|
| 116 |
/* Compute Required Lines/cols */ |
| 117 |
|
| 118 |
cols_per_line = (terms->dim[1] - 1) / hcols; |
| 119 |
for (i = sizeof(terms->tc), hlines = 0, j = 0; --i >=0; ) |
| 120 |
{ if_not (terms->tc[i]) continue; |
| 121 |
if (terms->tc[i] == TW_cc_RET) continue; |
| 122 |
if (--j <= 0) hlines++, j = cols_per_line; |
| 123 |
} |
| 124 |
terms->standout &= ~ChangedControl; |
| 125 |
|
| 126 |
/* Allocate Memory to Helps Text */ |
| 127 |
|
| 128 |
J = 1 + (hcols * cols_per_line); |
| 129 |
if_not(help_text = MEM_GET(ACHAR, (hlines+2)*J)) FINISH; |
| 130 |
/* status = OK; */ |
| 131 |
|
| 132 |
/* Fill with Graphic Characters and Blanks */ |
| 133 |
|
| 134 |
for (i = hlines*J, pa = help_text+J; --i >=0; pa++) *pa = ' '; |
| 135 |
|
| 136 |
k = J * (hlines+1); /* Write 1st + last lines */ |
| 137 |
for (j = J, pa = help_text; --j >=0; pa++) |
| 138 |
*pa = GraphicAchar(_HORIZONTAL_), *(pa+k) = *pa; |
| 139 |
for (i = hlines; --i >= 0; pa++) |
| 140 |
{ *pa = GraphicAchar(_VERTICAL_); |
| 141 |
for (j = cols_per_line; --j >=0; ) |
| 142 |
{ pa += hcols; |
| 143 |
*pa = GraphicAchar(_VERTICAL_); |
| 144 |
} |
| 145 |
} |
| 146 |
pa = help_text, *pa = Agraphic | CornerChar(_UPLEFT_); |
| 147 |
pa += J-1, *(pa++) = Agraphic | CornerChar(_UPRIGHT_); |
| 148 |
pa += hlines*J, *pa = Agraphic | CornerChar(_DOWNLEFT_); |
| 149 |
pa += J-1, *pa = Agraphic | CornerChar(_DOWNRIGHT_); |
| 150 |
|
| 151 |
k = J * (hlines+1); /* Write 1st + last lines Tees */ |
| 152 |
for (j = cols_per_line-1, pa = help_text+hcols; --j >=0; pa += hcols) |
| 153 |
*pa = Agraphic | TeeChar(_UP_), *(pa+k) = Agraphic | TeeChar(_DOWN_); |
| 154 |
|
| 155 |
/* Edit the lines */ |
| 156 |
|
| 157 |
for (i = 0, k = 0; i < sizeof(terms->tc); i++) |
| 158 |
{ if_not(terms->tc[i]) continue; |
| 159 |
if (terms->tc[i] == TW_cc_RET) continue; |
| 160 |
pa = help_text + ((k%hlines)+1)*J + (k/hlines)*hcols; |
| 161 |
k++; |
| 162 |
if (i >= 32) p = "Del "; |
| 163 |
else /* Issue Control Character */ |
| 164 |
cta[2] = '@' + i, p = cta; |
| 165 |
for (j = 4; --j >= 0; p++) *++pa = _BOLD_<<8 | *p; |
| 166 |
p = Explanations[terms->tc[i]]; |
| 167 |
for (j = strlen(p); --j >= 0; p++) *++pa = *p; |
| 168 |
} |
| 169 |
|
| 170 |
FIN: |
| 171 |
EXIT(OK); |
| 172 |
} |
| 173 |
|
| 174 |
/*========================================================================== |
| 175 |
* tv_helps |
| 176 |
*==========================================================================*/ |
| 177 |
int tv_help() |
| 178 |
/*+++ |
| 179 |
.PURPOSE Edit the Help Window |
| 180 |
.RETURNS OK |
| 181 |
.REMARKS |
| 182 |
---*/ |
| 183 |
{ |
| 184 |
int i; |
| 185 |
ACHAR *pa; |
| 186 |
static short int pos[2]; |
| 187 |
unsigned char old_attr; |
| 188 |
|
| 189 |
ENTER("tv_helps"); |
| 190 |
|
| 191 |
/* Check if Controls were not changed */ |
| 192 |
if ( (terms->standout & ChangedControl)) |
| 193 |
MEM_FREE(help_text), help_text = NULL_PTR(ACHAR); |
| 194 |
|
| 195 |
if_not(help_text) |
| 196 |
if_not(Create()) EXIT(NOK); /* Creation Failed ... */ |
| 197 |
|
| 198 |
/* Edit on Terminal */ |
| 199 |
|
| 200 |
old_attr = terms->attr; |
| 201 |
GetCursor(pos); |
| 202 |
if (pos[1]) NewLine(); |
| 203 |
|
| 204 |
for (i = hlines+2, pa = help_text; --i >=0; pa += J) |
| 205 |
WriteAchars(pa, J), NewLine(); |
| 206 |
SetAttr(old_attr); |
| 207 |
|
| 208 |
EXIT(OK); |
| 209 |
} |
| 210 |
|