1
/*===========================================================================
2
Copyright (C) 1995-2005 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
32
.VERSION 0.0 17-Mar-1989: First design
33
.VERSION 1.1 24-Nov-1989: Corrected (FO)
34
.VERSION 1.2 12-Feb-1990: Row boundary checking. JDP.
35
Check if several commands are given, to speed up
36
.VERSION 1.3 28-Oct-1990: Just patch for new version.
37
.AUTHOR Daniel Ponz, Francois Ochsenbein
38
.CATEGORY Table Editor
39
.COMMENTS Just here Field i/o
40
*** The provisional implementation assumes the functions
41
ClearError() removes error text, if any
42
ShowError(text) shows error text
44
NEXTCOL returned for `asking to move to next (right) col'
45
PREVCOL returned for `asking to move to previous (left) col'
46
HOMECOL returned for `asking to move to first (left) col'
47
BAD_KEY returned for unknown key
48
.ENVIRONMENT MIDAS, TermWindows
53
------------------------------------------------------------------------*/
55
#include <tw.h> /* Window system */
56
#include <ok.h> /* Just OK / NOK definitions */
57
#include <macrogen.h> /* General purpose macros, e.g. MAX */
58
#include <str.h> /* General string handling */
64
#include <proto_tbl.h>
69
#define MAXEDT_ELEMENT 255 /* Maximal size for getting a single
71
static char buffer[MAXEDT_ELEMENT+1];
72
static char buf_er[MAXEDT_ELEMENT+1];
74
static double variable[(MAXEDT_ELEMENT+7)/8];
77
/*========================================================================*/
80
.PURPOSE Compute the current column from cursor position
82
.REMARKS Should be a general function ? should thecol be external
83
(known to all edt functions) ?
89
GetCursor(data_subwindow, cursor_pos);
92
for (j=0; col1 > FMT[j].LAST; j++) ;
98
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99
.PURPOSE Convert from Binary (in variable) to str
100
.REMARKS Used in cunjunction with ModsWithCheck
101
.RETURNS OK=1 (str is correct) / NOK=0 (Bad char)
102
------------------------------------------------------------------------*/
103
char *str; /* OUT: Edited number */
105
return (TCEEDC(edt_tid, (char *)variable, FMT[thecol].colno, str));
108
static int Convert(str)
109
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110
.PURPOSE Convert from Char to Binary
111
.REMARKS Used in conjunction with ModsWithCheck
112
.RETURNS 0 (NULL) / -1 (error) / positive number if OK
113
------------------------------------------------------------------------*/
114
char *str; /* IN: String to Convert */
118
status = TCETRC(edt_tid, (char *)variable, FMT[thecol].colno, str);
119
if (status) status = -1; /* Error */
124
/*========================================================================*/
125
static int check(w, str, size)
127
.PURPOSE Check Function for Input of an Element
128
.REMARKS Used in cunjunction with ModsWithCheck
129
.RETURNS OK=1 (input is correct) / NOK=0 (Bad input)
130
.METHOD Convert str to Binary (if not a char string!), tne convert back.
132
WINDOW *w; /* IN: The Window */
133
char *str; /* MOD: What the user typed */
134
int size; /* IN: Size of str buffer */
136
char temp[MAXEDT_ELEMENT+80];
138
int cur_col, cur_row;
141
if (strcomp(buf_er,str) == 0) status = -2;
142
if (status == -1) status = Convert(str);
145
ShowError(">>> Format Error"), Bell();
147
else { /* Correct Entry. Modify underlying table */
148
SetAttr(w, _NORMAL_); /* Will be redisplayed correctly */
149
if (status >= 0) { /* A modification of the value ... */
150
GetCursor(data_subwindow, cursor_pos);
151
cur_col = edt_column[compute_col()];
152
cur_row = edt_row[cursor_pos[0]];
153
if (cur_row <= 0 || cur_row > edt_narow) {
154
status = NOK; /* check row boundaries */
155
ShowError(" Limit of the table ");
159
if (status == 0) { /* NULL value */
160
sprintf(temp,"Delete row %d, column %d",
162
TCEDEL(edt_tid, cur_row, cur_col);
165
sprintf(temp,"Rewrite row %d, column %d, element %s ",
166
cur_row, cur_col, str);
167
TCEWRC(edt_tid, cur_row, cur_col, str);
171
if (status > 0) Edit(str); /* Converts back using Format */
172
SetAttr(w, _NORMAL_); /* Will be redisplayed correctly */
179
/*========================================================================*/
182
.PURPOSE Edit any table element. What the user entered is checked.
183
**** Note: EnableArrows(data_subwindow) and EnableKeypad(data_subwindow)
184
is in effect (normally called after OpenWindow)
185
.RETURNS The action hit by the user. Can be just Return.
186
.REMARKS Process here only one element.
190
int lencol; /* Width of the current column */
191
int key_group; /* The group of keys (_KEYPAD_, etc) */
192
char key_hit; /* Explanation within key_group */
193
int key1, key2; /* input key(s) */
197
thecol = compute_col(); /* Just know the index in FMT tables */
199
lencol = FMT[thecol].LAST - FMT[thecol].FIRST;
200
lencol = MIN(lencol, sizeof(buffer)-1);
202
/* The acquisistion of the contents of the current column
203
* is made via TranslateWindow. Is there a better solution ? */
205
/* Suppress cursor mouvements echo */
206
DeactiveWindow(data_subwindow);
208
CursorTo(data_subwindow, cursor_pos[0], FMT[thecol].FIRST);
209
TranslateWindow(data_subwindow, buffer, lencol);
210
buffer[lencol] = '\0';
211
for (i = lencol-1; i >= 0 && buffer[i] == ' '; buffer[i--] = '\0') ;
212
oscopy(buf_er,buffer,lencol+1);
215
SetAttr(data_subwindow, _REVERSE_);
217
/* Before asking for the input, check if some command
218
* was already typed in. Useless to repaint the screen... */
221
key_group = GetChar(&key_hit);
222
if ( (key_group == _STANDARD_) && isprint(key_hit)) {
226
if (key_hit == '\r') key_hit = EOS;
228
goto Execute_User_Input;
231
/* Ready now for Input. Buffer contains a copy of the
232
* element (in Character). It will be redisplayed in Reverse */
235
ActiveWindow(data_subwindow);
237
key_group = ModsWithCheck(data_subwindow, buffer, lencol+1, check);
240
SetAttr(data_subwindow, _NORMAL_);
242
/* The result of Mods may be:
243
* _INTERRUPT_ : take the original (no modif)
244
* _STANDARD_ : terminated by the Carriage Return
245
* 0 : We must look what was exactly the key via GetKey
246
* Other : A special key was hit as the FIRST input
252
ShowError("***INTERRUPT*** Hit Return");
253
oscopy(buffer,buf_er,lencol+1);
255
case _STANDARD_: if (buffer[0] && iscntrl(buffer[0]))
256
{key_hit = buffer[0], buffer[0] = EOS; break;}
258
case 0: key_group = GetKey(data_subwindow, &key_hit);
261
default: key_hit = buffer[0], buffer[0] = EOS;
265
if (key_group == _EOF_) return(COMMAND);
266
if (key_group == _STANDARD_) key_group = 0;
267
key1 = key_group<<8 | key_hit;
271
switch(tk_check(key1))
273
case 0: return (BAD_KEY); /* Doesn't map to an action */
275
case 2: key_group = GetKey(data_subwindow, &key_hit);
276
key2 = key_group<<8 | key_hit;
278
case 1: return (tk_exec(key1, key2));
284
/*========================================================================*/
287
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
295
Status 0 OK - save table; -1 NOK - no save the table
296
------------------------------------------------------------------*/
299
int iend, old_direction, old_state;
302
/* iteration on input */;
304
TCOGET("display_errors", &old_err); /* Don't Display */
305
TCOSET("display_errors", 0); /* Don't Display */
306
while ((edt_action = edt_edfield()) != TERMINATE)
309
/* decide upon main actions */
310
switch (edt_action) {
313
GetCursor(data_subwindow, cursor_pos);
314
thecol = compute_col();
315
if ((thecol+1 >= edt_nc) && (edt_column[edt_nc-1] >= edt_ncol))
316
{ /* Must go to First Column, next line */
317
if (cursor_pos[0]+1 >= data_lines) /* Must scroll */
318
{ old_direction = edt_advance;
320
iend = edt_row[edt_nr-1];
321
if (++iend > edt_narow) /* End of Table */
324
{ old_state = DeactiveWindow(editor_window);
325
CursorHome(data_subwindow),
326
cursor_pos[0] = cursor_pos[1] = 0;
327
if (edt_column[0] > 1) edt_leftpage();
329
CursorDown(data_subwindow, iend - edt_row[0]);
330
if (old_state) ActiveWindow(editor_window);
332
edt_advance = old_direction;
334
else /* I don't have to scroll. However, verify */
335
{ if (edt_column[0] > 1) edt_leftpage();
341
case INTERRUPT : return (-1);
342
case BAD_KEY: edt_badkey(); break;
343
case NEXTCOL: edt_nextcol(); break;
344
case COMMAND: edt_command();
345
if (edt_action == TERMINATE) return (0);
349
TCOSET("display_errors", old_err); /* Reset at its previous value */