~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/tw3/libsrc/tfget.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1989-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++++++++++++++++++
 
29
.TYPE           Module
 
30
.NAME           tfget.c
 
31
.LANGUAGE       C
 
32
.CATEGORY       User interface
 
33
.ENVIRONMENT    TermWindows
 
34
.AUTHOR         Alan Richmond, Francois Ochsenbein 
 
35
.COMMENTS
 
36
       Here are Input Functions. These may apply on Fields,
 
37
       or Notes.
 
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
 
40
 
 
41
 090902         last modif
 
42
-------------------*/
 
43
 
 
44
#define PM_LEVEL        LEVEL_TF
 
45
 
 
46
#define  PASCAL_DEF     0       /* Don't include Pascalisation  */
 
47
 
 
48
#include <stesodef.h>   /* Standard definitions */
 
49
#include <tform.h>      /* for form values      */
 
50
#include <str.h>        /* String utilities     */
 
51
 
 
52
 
 
53
extern int tx_display();
 
54
 
 
55
extern int ta_ret(), ta_error();
 
56
 
 
57
extern int tv_dim(), tv_supply(), tv_where(), tv_bell();
 
58
 
 
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();
 
67
 
 
68
extern int pm_enter(), pm_iexit(), pm_tr2(), pm_ed_i();
 
69
extern int pm_trace();
 
70
 
 
71
extern int eh_put1(), eh_clear(), eh_ed_as();
 
72
 
 
73
extern int tff_goto(), tff_convert(), tff_edit(), tff_display();
 
74
extern int tff_putnote(), tff_move(), tff_oshow();
 
75
 
 
76
extern int tf_update(), tf_show(), tf_active(), tf_opwd();
 
77
extern int tf_oshow(), tf_oclear(), tf_oset(), tf_opwd(), tf_nshow();
 
78
 
 
79
 
 
80
#define ShowError()     DisplayError(NULL_PTR(char))
 
81
#define ClearError()    ERR_CLEAR(),DisplayError(NULL_PTR(char))
 
82
 
 
83
#define FINISH  goto FIN
 
84
 
 
85
static  TFORM   *theform;       /* Shared with Value / Check    */
 
86
static  WINDOW  *thewindow;     /* Shared with Value / Check    */
 
87
static  TFIELD  *field;         /* Shared with Value / Check    */
 
88
 
 
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;
 
96
 
 
97
/*======================================================================*/
 
98
/*                      Internal Routines                               */
 
99
/*======================================================================*/
 
100
static int prolog(form)
 
101
/*+++++++
 
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)
 
105
---------*/
 
106
        TFORM   *form;  /* IN: The Form Concerned       */
 
107
{
 
108
  theform = form;
 
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;
 
115
 
 
116
  SetStopping(thewindow, _NORMAL_, "[");        /* Stop when Escape */
 
117
 
 
118
  return(OK);
 
119
}
 
120
        
 
121
/*======================================================================*/
 
122
static int check(w, str, size)
 
123
/*+++++++
 
124
.PURPOSE Check Function for Input in Fields.
 
125
.REMARKS Used in cunjunction with Mods2
 
126
.RETURNS OK (input is correct) / NOK (Bad input)
 
127
---------*/
 
128
        WINDOW  *w;     /* IN: The Window       */
 
129
        char    *str;   /* MOD: What the user typed     */
 
130
        int     size;   /* IN: Size of str buffer       */
 
131
{
 
132
        int     status;
 
133
        ACHAR   old_attr;
 
134
        
 
135
  ClearError();                 /* Clear Any Error Message */
 
136
 
 
137
                /* First Check with Picture     */
 
138
 
 
139
  status = OK;
 
140
  
 
141
  if (strcomp(str, saved) == 0) /* No Modif     */
 
142
        FINISH;
 
143
  
 
144
  field->options |= _FIELD_MODIFIED;
 
145
  if (check_pic)
 
146
  {     if ((status = tff_convert(field, str))) /* Correct      */
 
147
                tff_edit(field);
 
148
        else
 
149
        {
 
150
                ERR_ED_STRING("Template is: ", field->picture);
 
151
                ShowError(), Bell();
 
152
                status = NOK;
 
153
        }
 
154
  }
 
155
 
 
156
                /* Check with All Functions     */
 
157
  
 
158
  if (status && thecheck_fct)
 
159
  {
 
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();  
 
164
                else            status = OK;
 
165
        }
 
166
        tf_update(theform);     /* Derive Values */
 
167
        w->attr_init = old_attr;
 
168
  }
 
169
           
 
170
  FIN:
 
171
  return(status);
 
172
}
 
173
 
 
174
/*==========================================================================*/
 
175
static int Value ()
 
176
/*+++++++++++
 
177
.PURPOSE Allow user to modify the displayed field.
 
178
.REMARKS 
 
179
.RETURNS The status (see Mods2).
 
180
-------------*/
 
181
{
 
182
        int     status;
 
183
 
 
184
  init_attr = thewindow->attr_init;
 
185
  if (option & _FIELD_NOECHO)
 
186
        DeactiveWindow(thewindow);      /* Non-Echo field: don't display */
 
187
  else  ActiveWindow(thewindow);
 
188
 
 
189
  if (thestring)                        /* Get Complete Text    */
 
190
  {
 
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);
 
203
  }
 
204
  else  status = GetKey2(thewindow);
 
205
 
 
206
  if (option & _FIELD_NOECHO)   ActiveWindow(thewindow);
 
207
 
 
208
  return(status);
 
209
}
 
210
 
 
211
/*==========================================================================*/
 
212
static int default_action(form)
 
213
/*+++++++++++++++++
 
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
--------------------*/
 
218
        TFORM   *form;
 
219
{
 
220
        TFIELD  *field;
 
221
        int     status;
 
222
 
 
223
  status = NOK;
 
224
  field = form->fields + form->ifield;
 
225
  
 
226
        /* Look for standard name:
 
227
                EXIT  return _EOF_
 
228
                Other return NOK
 
229
         */
 
230
 
 
231
  if (stucomp(field->name, "EXIT") == 0)        status = _EOF_;
 
232
  if (stucomp(field->name, "QUIT") == 0)        status = _EOF_;
 
233
         
 
234
  if (status == NOK)
 
235
        ERR_ED_STRING("Ask to execute action: ", field->name);
 
236
  
 
237
  return(status);
 
238
}
 
239
 
 
240
/*==========================================================================*/
 
241
int tff_get (form)
 
242
/*+++++++++++++++++
 
243
.PURPOSE Input of One Field.
 
244
.RETURNS See Mods2
 
245
--------------------*/
 
246
        TFORM   *form;  /* MOD: The Form concerned      */
 
247
{
 
248
        int     len, status;
 
249
        char    *p;
 
250
 
 
251
  ENTER("tff_get");
 
252
        
 
253
  prolog(form);
 
254
  
 
255
  if(isactionField(field))      thestring = NULL_PTR(char),
 
256
                                thestring_size = 0,
 
257
                                option |= _FIELD_NOECHO;
 
258
  else
 
259
  {
 
260
        thestring = field->string, thestring_size = field->string_size;
 
261
        check_pic = 1;
 
262
        option = field->options;
 
263
        thecheck_fct = theform->check_fct;
 
264
  }
 
265
 
 
266
  status = Value();
 
267
 
 
268
 
 
269
  if_not(isactionField(field))          /* Fill with Blanks */
 
270
  {
 
271
        len = strlen(field->string);
 
272
        p   = field->string + len;
 
273
        len = field->string_size - 1 - len;     /* Blanks to add */
 
274
        strfill(p, len, ' ');
 
275
  }
 
276
 
 
277
  EXIT (status);
 
278
}
 
279
 
 
280
/*==========================================================================*/
 
281
int tff_mods (form, str, size, check_fct)
 
282
/*+++++++++++++++++
 
283
.PURPOSE Input in One Field.
 
284
.RETURNS See Mods2
 
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           */
 
290
{
 
291
        int     status, old_attr, old_pos;
 
292
 
 
293
  ENTER("tff_mods");
 
294
        
 
295
  prolog(form);
 
296
  
 
297
  thestring = str;      thestring_size = -size; /* FOR STRETCH */
 
298
  check_pic = 0;        option = 0;
 
299
  thecheck_fct = check_fct;
 
300
 
 
301
  status = DeactiveWindow(thewindow);
 
302
  old_attr = SetAttr(thewindow, field->attr);
 
303
  if (field->string_size)       
 
304
        Fill(thewindow, ' ', field->string_size - 1);
 
305
 
 
306
  status = Value();
 
307
  
 
308
  stripspaces(thestring);
 
309
  old_pos = GetPosition(thewindow);
 
310
  tff_display(form, thestring);
 
311
  SetAttr(thewindow, old_attr);
 
312
  SetPosition(thewindow, old_pos);
 
313
 
 
314
  EXIT (status);
 
315
}
 
316
 
 
317
/*==========================================================================*/
 
318
int tff_nget(form, check_fct)
 
319
/*+++++++++++++++++
 
320
.PURPOSE Input of One Note
 
321
.RETURNS See Mods2
 
322
--------------------*/
 
323
        TFORM   *form;  /* MOD: The Form concerned      */
 
324
        TF_CHECK check_fct;     /* IN: Check Function   */
 
325
{
 
326
        char    note[256];
 
327
        int     status;
 
328
 
 
329
  ENTER("tff_nget");
 
330
  
 
331
  prolog(form);
 
332
  
 
333
  if (field->note)      strncopy(note, sizeof(note), field->note);
 
334
  else                  note[0]   = EOS;
 
335
 
 
336
  status = tff_mods(form, note, sizeof(note), check_fct);
 
337
  if (status >= 0)      tff_putnote(form, note);
 
338
  
 
339
  EXIT(status);
 
340
}
 
341
  
 
342
/*==========================================================================*/
 
343
int tf_get (form)
 
344
/*+++++++++++++++++
 
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      */
 
350
{
 
351
        int     status, old_active;
 
352
        TF_FCT  fct;
 
353
 
 
354
  ENTER("tf_get");      
 
355
        
 
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.. */
 
359
 
 
360
  for (status = 0; status >= 0; )       /* For Ever Among Fields */
 
361
  {
 
362
        status = tff_get(form);
 
363
 
 
364
        if (status == _EOF_)            /* End */
 
365
        {
 
366
                if (theform->check_fct)
 
367
                {
 
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; }
 
372
                        }
 
373
                }
 
374
                status = 0;
 
375
                break;
 
376
        }
 
377
 
 
378
        if (status == 0)                /* Normal CR    */
 
379
        {
 
380
                if (isactionField(field))       
 
381
                {       if_not(fct = field->value.action) fct = default_action;
 
382
                        status = (*fct)(theform);
 
383
                        if (ERR_GET())  ShowError(), Bell();  
 
384
                        continue;
 
385
                }
 
386
                status = _ARROW(_RIGHT_);
 
387
        }
 
388
        if (is_ARROW(status))   tff_move(form, status|0x10), status = 0;
 
389
  }
 
390
 
 
391
           
 
392
  tf_active(form, old_active);  /* Reset Active Status  */
 
393
  EXIT (status);
 
394
}
 
395
 
 
396
/*==========================================================================*/
 
397
int tf_oget (form, mask, ifset)
 
398
/*+++++++++++++++++
 
399
.PURPOSE Input of Options
 
400
.RETURNS OK
 
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  */
 
406
{
 
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 ", 
 
415
                NULL_PTR(char)  };
 
416
        char    achar, do_show, do_arrow;
 
417
        short   ispwd;
 
418
 
 
419
  ENTER("tf_oget");
 
420
        
 
421
  ClearError();                 /* Clear Any Error Message      */
 
422
  theform = form;
 
423
  
 
424
  ispwd = mask&_FIELD_NOECHO;
 
425
  if_not(ispwd) tf_opwd(theform, mask);
 
426
  
 
427
  if_not(help_window)   
 
428
        help_window = OpenHelpWindow("How to Select",0, -25, cc, explain);
 
429
  achar = ifset;
 
430
  CursorTo(help_window, 0, 2); Write(help_window,&achar, 1);
 
431
 
 
432
  old_help_window = AttachHelpWindow(theform->window, help_window);
 
433
  
 
434
  old_active = tf_active(form, 0);      /* Be sure the Form is NOT Active..*/
 
435
  tf_oshow(form, mask, ifset);          /* Write the Correct Fields     */
 
436
 
 
437
  do_show = 1;                          /* 1 means Show Complete Form   */
 
438
  achar   = _RIGHT_;
 
439
 
 
440
  while(1)      /* For Ever Among Fields */
 
441
  {
 
442
        if(do_show)
 
443
        {       if_not(ispwd)   tf_opwd(theform, mask);
 
444
                do_show = 0, tf_oshow(form, mask, ifset);
 
445
        }
 
446
        do_arrow = 0;
 
447
 
 
448
        tff_goto(theform, theform->ifield);
 
449
        field = theform->fields + theform->ifield;      /* Current Field   */
 
450
 
 
451
        if (!ispwd)     while (field->options & _FIELD_NOECHO)
 
452
        {       Bell();
 
453
                if (theform->ifield == 0)       achar = _RIGHT_;
 
454
                if (theform->ifield == (theform->nfields - 1)) 
 
455
                                                achar = _LEFT_;
 
456
                tff_move(theform, achar);
 
457
                field = theform->fields + theform->ifield;
 
458
        }
 
459
 
 
460
        TouchWindow(theform->window);
 
461
 
 
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_;
 
473
                else    Bell();
 
474
                break;
 
475
          case _ARROW_:                 do_arrow = 1;
 
476
                break;
 
477
          default:                      Bell();
 
478
        }
 
479
        if (do_show == 2)       do_show = 0, tff_oshow(theform, mask, ifset);
 
480
        if (do_arrow)           tff_move(theform, achar);
 
481
  }
 
482
 
 
483
  FIN:
 
484
  tf_active(form, old_active);  /* Reset Active Status  */
 
485
  RemoveHelpWindow(theform->window);
 
486
  AttachHelpWindow(theform->window, old_help_window);
 
487
  EXIT (OK);
 
488
}
 
489
 
 
490
/*==========================================================================*/
 
491
int tf_nget (form, fct)
 
492
/*+++++++++++++++++
 
493
.PURPOSE Move in Form to get Notes.
 
494
.RETURNS See Mods2
 
495
--------------------*/
 
496
        TFORM   *form;  /* MOD: The Form concerned      */
 
497
        TF_CHECK fct;   /* IN: The Check Function(form,str,size)*/
 
498
{
 
499
        int     status, old_active;
 
500
 
 
501
  ENTER("tf_nget");     
 
502
        
 
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.. */
 
506
 
 
507
  while(1)      /* For Ever Among Fields */
 
508
  {
 
509
        status = tff_nget(form, fct);
 
510
        if (status < 0) break;
 
511
        if (status == 0)                /* Normal CR    */
 
512
                status = _ARROW(_RIGHT_);
 
513
 
 
514
        if (is_ARROW(status))   tff_move(form, status);
 
515
  }
 
516
 
 
517
                /* Check with All Functions     */
 
518
  
 
519
  if ((status < 0) && (fct))
 
520
  {
 
521
        form->avalue = NULL_PTR(int);
 
522
        if_not(status = (*fct)(form, NULL_PTR(char), 0))
 
523
                ShowError(), Bell();
 
524
  }
 
525
           
 
526
  tf_active(form, old_active);  /* Reset Active Status  */
 
527
  EXIT (status);
 
528
}
 
529