1
/*===========================================================================
2
Copyright (C) 1989-2009 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 Massachusetss Ave, Cambridge,
19
Corresponding 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
===========================================================================*/
28
/*+++++++++++++++++++++++++
32
.CATEGORY User interface
33
.ENVIRONMENT TermWindows
34
.AUTHOR Alan Richmond, Francois Ochsenbein
36
Here are Input Functions. These may apply on Fields,
38
.VERSION 1.0 09-Jun-1989 Extracted from Proteus
39
.VERSION 1.1 24-Jul-1989 Interrupt can be used to leave a field unchanged
44
#define PM_LEVEL LEVEL_TF
46
#define PASCAL_DEF 0 /* Don't include Pascalisation */
48
#include <stesodef.h> /* Standard definitions */
49
#include <tform.h> /* for form values */
50
#include <str.h> /* String utilities */
53
extern int tx_display();
55
extern int ta_ret(), ta_error();
57
extern int tv_dim(), tv_supply(), tv_where(), tv_bell();
59
extern int tw_fill(), tw_attr(), tw_uattr(), tw_r(), tw_goto(), tw_rule();
60
extern int tw_st(), tw_uflag(), tw_chars(), tw_copw(), tw_flags();
61
extern int tw_uw(), tw_write(), tw_il(), tw_clear(), tw_dc();
62
extern int tw_nl(), tw_upw(), tw_uc(), tw_mvc(), tw_copy();
63
extern int tw_mrule(), tw_cus(), tw_gc2(), tw_close(), tw_cur();
64
extern int tw_home(), tw_tra(), tw_wa(), tw_agoto(), tw_mods();
65
extern int tw_cline(), tw_stopin(), tw_ms2(), tw_wf(), tw_awhere();
66
extern int tw_getc(), tw_helps();
68
extern int pm_enter(), pm_iexit(), pm_tr2(), pm_ed_i();
69
extern int pm_trace();
71
extern int eh_put1(), eh_clear(), eh_ed_as();
73
extern int tff_goto(), tff_convert(), tff_edit(), tff_display();
74
extern int tff_putnote(), tff_move(), tff_oshow();
76
extern int tf_update(), tf_show(), tf_active(), tf_opwd();
77
extern int tf_oshow(), tf_oclear(), tf_oset(), tf_opwd(), tf_nshow();
80
#define ShowError() DisplayError(NULL_PTR(char))
81
#define ClearError() ERR_CLEAR(),DisplayError(NULL_PTR(char))
83
#define FINISH goto FIN
85
static TFORM *theform; /* Shared with Value / Check */
86
static WINDOW *thewindow; /* Shared with Value / Check */
87
static TFIELD *field; /* Shared with Value / Check */
89
static char check_pic; /* Flag to check number vs pic */
90
static unsigned short option; /* Option Flag */
91
static char *thestring = NULL_PTR(char);
92
static short thestring_size;
93
static char *saved = NULL_PTR(char);
94
static ACHAR init_attr = ' ';
95
static TF_CHECK thecheck_fct;
97
/*======================================================================*/
98
/* Internal Routines */
99
/*======================================================================*/
100
static int prolog(form)
102
.PURPOSE Set the static values theform field thewindow
103
.REMARKS Used in cunjunction with Mods2
104
.RETURNS OK (input is correct) / NOK (Bad input)
106
TFORM *form; /* IN: The Form Concerned */
109
tff_goto(theform, theform->ifield);
110
field = theform->fields + theform->ifield; /* Current Field */
111
thewindow = NULL_WINDOW;
112
if (ischarField(field)) thewindow = field->value.window;
113
if(thewindow) thewindow->pos = 0;
114
else thewindow = theform->window;
116
SetStopping(thewindow, _NORMAL_, "["); /* Stop when Escape */
121
/*======================================================================*/
122
static int check(w, str, size)
124
.PURPOSE Check Function for Input in Fields.
125
.REMARKS Used in cunjunction with Mods2
126
.RETURNS OK (input is correct) / NOK (Bad input)
128
WINDOW *w; /* IN: The Window */
129
char *str; /* MOD: What the user typed */
130
int size; /* IN: Size of str buffer */
135
ClearError(); /* Clear Any Error Message */
137
/* First Check with Picture */
141
if (strcomp(str, saved) == 0) /* No Modif */
144
field->options |= _FIELD_MODIFIED;
146
{ if ((status = tff_convert(field, str))) /* Correct */
150
ERR_ED_STRING("Template is: ", field->picture);
156
/* Check with All Functions */
158
if (status && thecheck_fct)
160
old_attr = w->attr_init; /* The init attribute was changed ... */
161
w->attr_init = init_attr;
162
if_not(status = (*thecheck_fct)(theform, str, size))
163
{ if(ERR_GET()) ShowError(), Bell();
166
tf_update(theform); /* Derive Values */
167
w->attr_init = old_attr;
174
/*==========================================================================*/
177
.PURPOSE Allow user to modify the displayed field.
179
.RETURNS The status (see Mods2).
184
init_attr = thewindow->attr_init;
185
if (option & _FIELD_NOECHO)
186
DeactiveWindow(thewindow); /* Non-Echo field: don't display */
187
else ActiveWindow(thewindow);
189
if (thestring) /* Get Complete Text */
191
stripspaces(thestring); /* Remove Trailing Spaces */
192
SetAttr(thewindow, field->attr);
193
saved = MEM_EXP(char, saved, ABSOLUTE(thestring_size));
194
strcopy(saved, thestring);
195
if (check_pic) /* Only for tff_get */
196
thewindow->attr_init = thewindow->attr,
197
SetAttr(thewindow, _NORMAL_);
198
status = Mods2(thewindow, thestring, thestring_size, check);
199
if (check_pic) /* Only for tff_get */
200
thewindow->attr_init = init_attr,
201
thewindow->attr = init_attr;
202
if (status == _INTERRUPT_) strcopy(thestring, saved);
204
else status = GetKey2(thewindow);
206
if (option & _FIELD_NOECHO) ActiveWindow(thewindow);
211
/*==========================================================================*/
212
static int default_action(form)
214
.PURPOSE Default Action to be executed if user didn't specify one.
215
.REMARKS Issues ERROR message with field name
216
.RETURNS NOK (Unknwon Field) / _EOF_ (QUIT field)
217
--------------------*/
224
field = form->fields + form->ifield;
226
/* Look for standard name:
231
if (stucomp(field->name, "EXIT") == 0) status = _EOF_;
232
if (stucomp(field->name, "QUIT") == 0) status = _EOF_;
235
ERR_ED_STRING("Ask to execute action: ", field->name);
240
/*==========================================================================*/
243
.PURPOSE Input of One Field.
245
--------------------*/
246
TFORM *form; /* MOD: The Form concerned */
255
if(isactionField(field)) thestring = NULL_PTR(char),
257
option |= _FIELD_NOECHO;
260
thestring = field->string, thestring_size = field->string_size;
262
option = field->options;
263
thecheck_fct = theform->check_fct;
269
if_not(isactionField(field)) /* Fill with Blanks */
271
len = strlen(field->string);
272
p = field->string + len;
273
len = field->string_size - 1 - len; /* Blanks to add */
274
strfill(p, len, ' ');
280
/*==========================================================================*/
281
int tff_mods (form, str, size, check_fct)
283
.PURPOSE Input in One Field.
285
--------------------*/
286
TFORM *form; /* MOD: The Form concerned */
287
char *str; /* MOD: The text to be modified by the user */
288
int size; /* IN: Size of the above */
289
TF_CHECK check_fct; /* IN: Check Function */
291
int status, old_attr, old_pos;
297
thestring = str; thestring_size = -size; /* FOR STRETCH */
298
check_pic = 0; option = 0;
299
thecheck_fct = check_fct;
301
status = DeactiveWindow(thewindow);
302
old_attr = SetAttr(thewindow, field->attr);
303
if (field->string_size)
304
Fill(thewindow, ' ', field->string_size - 1);
308
stripspaces(thestring);
309
old_pos = GetPosition(thewindow);
310
tff_display(form, thestring);
311
SetAttr(thewindow, old_attr);
312
SetPosition(thewindow, old_pos);
317
/*==========================================================================*/
318
int tff_nget(form, check_fct)
320
.PURPOSE Input of One Note
322
--------------------*/
323
TFORM *form; /* MOD: The Form concerned */
324
TF_CHECK check_fct; /* IN: Check Function */
333
if (field->note) strncopy(note, sizeof(note), field->note);
336
status = tff_mods(form, note, sizeof(note), check_fct);
337
if (status >= 0) tff_putnote(form, note);
342
/*==========================================================================*/
345
.PURPOSE Move in Form with Keys, get data typed in keys, Until EOF (^Z)
346
or Special Keys (eg PF keys)
347
.RETURNS _EOF_ (Quit) / 0 (Normally Terminated) / _INTERRUPT_ / Other (See Mods2)
348
--------------------*/
349
TFORM *form; /* MOD: The Form concerned */
351
int status, old_active;
356
/* ClearError(); /. Clear Any Error Message */
357
tf_show(form); /* Write the Correct Fields */
358
old_active = tf_active(form, 1); /* Be sure the Form is Active.. */
360
for (status = 0; status >= 0; ) /* For Ever Among Fields */
362
status = tff_get(form);
364
if (status == _EOF_) /* End */
366
if (theform->check_fct)
368
tf_update(theform); /* Derive Values */
369
theform->avalue = NULL_PTR(int);
370
if_not((*theform->check_fct)(theform, NULL_PTR(char), 0))
371
{ if(ERR_GET()) {ShowError(), Bell(); continue; }
378
if (status == 0) /* Normal CR */
380
if (isactionField(field))
381
{ if_not(fct = field->value.action) fct = default_action;
382
status = (*fct)(theform);
383
if (ERR_GET()) ShowError(), Bell();
386
status = _ARROW(_RIGHT_);
388
if (is_ARROW(status)) tff_move(form, status|0x10), status = 0;
392
tf_active(form, old_active); /* Reset Active Status */
396
/*==========================================================================*/
397
int tf_oget (form, mask, ifset)
399
.PURPOSE Input of Options
401
.REMARKS Non-echo fields can't be set...
402
--------------------*/
403
TFORM *form; /* MOD: The Form concerned */
404
int mask; /* IN: Mask to select option */
405
int ifset; /* IN: How to display Selected */
407
int status, old_active;
408
WINDOW *old_help_window;
409
static WINDOW *help_window = NULL_WINDOW;
410
static char cc[] = {'@', ' ', 'A', 'C', 'Q',
411
TW_cc_EOF, TW_cc_INT, TW_cc_HELP, TW_cc_UP, TW_cc_DOWN,
412
TW_cc_LEFT, TW_cc_RIGHT, TW_cc_NONE};
413
static char *explain[sizeof(cc)-1] = {
414
"Select", "Clear", "Select ALL", "Clear ALL", "Quit ",
416
char achar, do_show, do_arrow;
421
ClearError(); /* Clear Any Error Message */
424
ispwd = mask&_FIELD_NOECHO;
425
if_not(ispwd) tf_opwd(theform, mask);
428
help_window = OpenHelpWindow("How to Select",0, -25, cc, explain);
430
CursorTo(help_window, 0, 2); Write(help_window,&achar, 1);
432
old_help_window = AttachHelpWindow(theform->window, help_window);
434
old_active = tf_active(form, 0); /* Be sure the Form is NOT Active..*/
435
tf_oshow(form, mask, ifset); /* Write the Correct Fields */
437
do_show = 1; /* 1 means Show Complete Form */
440
while(1) /* For Ever Among Fields */
443
{ if_not(ispwd) tf_opwd(theform, mask);
444
do_show = 0, tf_oshow(form, mask, ifset);
448
tff_goto(theform, theform->ifield);
449
field = theform->fields + theform->ifield; /* Current Field */
451
if (!ispwd) while (field->options & _FIELD_NOECHO)
453
if (theform->ifield == 0) achar = _RIGHT_;
454
if (theform->ifield == (theform->nfields - 1))
456
tff_move(theform, achar);
457
field = theform->fields + theform->ifield;
460
TouchWindow(theform->window);
462
switch(status = GetKey(theform->window, &achar))
463
{ case _EOF_: FINISH;
464
case _STANDARD_: achar = toupper(achar);
465
if (achar == 'Q') FINISH;
466
if (achar == '\r') do_arrow = 1, achar = _RIGHT_;
467
else if (achar == 'C') do_show = 1, tf_oclear(theform, mask);
468
else if (achar == 'A') do_show = 1, tf_oset (theform, mask);
469
else if (achar == ' ') do_show = 2, field->options &= ~mask,
470
do_arrow = 1, achar = _RIGHT_;
471
else if (achar == ifset)do_show = 2, field->options |= mask,
472
do_arrow = 1, achar = _RIGHT_;
475
case _ARROW_: do_arrow = 1;
479
if (do_show == 2) do_show = 0, tff_oshow(theform, mask, ifset);
480
if (do_arrow) tff_move(theform, achar);
484
tf_active(form, old_active); /* Reset Active Status */
485
RemoveHelpWindow(theform->window);
486
AttachHelpWindow(theform->window, old_help_window);
490
/*==========================================================================*/
491
int tf_nget (form, fct)
493
.PURPOSE Move in Form to get Notes.
495
--------------------*/
496
TFORM *form; /* MOD: The Form concerned */
497
TF_CHECK fct; /* IN: The Check Function(form,str,size)*/
499
int status, old_active;
503
/* ClearError(); /. Clear Any Error Message */
504
tf_nshow(form); /* Write the Correct Notes */
505
old_active = tf_active(form, 1); /* Be sure the Form is Active.. */
507
while(1) /* For Ever Among Fields */
509
status = tff_nget(form, fct);
510
if (status < 0) break;
511
if (status == 0) /* Normal CR */
512
status = _ARROW(_RIGHT_);
514
if (is_ARROW(status)) tff_move(form, status);
517
/* Check with All Functions */
519
if ((status < 0) && (fct))
521
form->avalue = NULL_PTR(int);
522
if_not(status = (*fct)(form, NULL_PTR(char), 0))
526
tf_active(form, old_active); /* Reset Active Status */