2
* Copyright (C) 1997-2008 Michael Madore
4
* This file is part of TN5250.
6
* TN5250 is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; either version 2.1, or (at your option)
11
* TN5250 is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU Lesser General Public License for more details.
16
* You should have received a copy of the GNU Lesser General Public License
17
* along with this software; see the file COPYING. If not, write to
18
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
* Boston, MA 02111-1307 USA
23
#include "tn5250-private.h"
26
/****f* lib5250/tn5250_field_new
30
* ret = tn5250_field_new (w);
37
tn5250_field_new (int w)
39
Tn5250Field *This = tn5250_new (Tn5250Field, 1);
44
memset (This, 0, sizeof (Tn5250Field));
51
/****f* lib5250/tn5250_field_copy
55
* ret = tn5250_field_copy (This);
57
* Tn5250Field * This -
62
tn5250_field_copy (Tn5250Field * This)
64
Tn5250Field *fld = tn5250_new (Tn5250Field, 1);
69
memcpy (fld, This, sizeof (Tn5250Field));
72
fld->script_slot = NULL;
77
/****f* lib5250/tn5250_field_destroy
79
* tn5250_field_destroy
81
* tn5250_field_destroy (This);
83
* Tn5250Field * This -
88
tn5250_field_destroy (Tn5250Field * This)
95
/****f* lib5250/tn5250_field_dump
99
* tn5250_field_dump (This);
101
* Tn5250Field * This -
106
tn5250_field_dump (Tn5250Field * This)
108
Tn5250Uint16 ffw = This->FFW;
110
TN5250_LOG (("tn5250_field_dump: ffw flags = "));
111
if ((ffw & TN5250_FIELD_BYPASS) != 0)
113
TN5250_LOG (("bypass "));
115
if ((ffw & TN5250_FIELD_DUP_ENABLE) != 0)
117
TN5250_LOG (("dup-enable "));
119
if ((ffw & TN5250_FIELD_MODIFIED) != 0)
121
TN5250_LOG (("mdt "));
123
if ((ffw & TN5250_FIELD_AUTO_ENTER) != 0)
125
TN5250_LOG (("auto-enter"));
127
if ((ffw & TN5250_FIELD_FER) != 0)
129
TN5250_LOG (("fer "));
131
if ((ffw & TN5250_FIELD_MONOCASE) != 0)
133
TN5250_LOG (("monocase "));
135
if ((ffw & TN5250_FIELD_MANDATORY) != 0)
137
TN5250_LOG (("mandatory "));
140
TN5250_LOG (("\ntn5250_field_dump: fcw flags = "));
141
if (This->resequence != 0)
143
TN5250_LOG (("Entry field resequencing: %d ", This->resequence));
147
TN5250_LOG (("Magnetic stripe reader entry field "));
151
TN5250_LOG (("Selector light pen or cursor select field "));
153
if (This->magandlight)
155
TN5250_LOG (("Magnetic stripe reader and selector light pen entry field "));
157
if (This->lightandattn)
159
TN5250_LOG (("Selector light pen and selectable attention entry field "));
161
if (This->ideographiconly)
163
TN5250_LOG (("Ideographic-only entry field "));
165
if (This->ideographicdatatype)
167
TN5250_LOG (("Ideographic data type entry field "));
169
if (This->ideographiceither)
171
TN5250_LOG (("Ideographic-either entry field "));
173
if (This->ideographicopen)
175
TN5250_LOG (("Ideographic-open entry field "));
177
if (This->transparency != 0)
179
TN5250_LOG (("Transparency entry field: %d ", This->transparency));
181
if (This->forwardedge)
183
TN5250_LOG (("Forward edge trigger entry field "));
185
if (This->continuous)
187
TN5250_LOG (("continuous "));
189
if (tn5250_field_is_continued_first (This))
191
TN5250_LOG (("(first) "));
193
if (tn5250_field_is_continued_middle (This))
195
TN5250_LOG (("(middle) "));
197
if (tn5250_field_is_continued_last (This))
199
TN5250_LOG (("(last) "));
203
TN5250_LOG (("wordwrap "));
205
if (This->nextfieldprogressionid != 0)
207
TN5250_LOG (("cursor progression: %d ", This->nextfieldprogressionid));
209
if ((int) This->highlightentryattr != 0)
211
TN5250_LOG (("Highlighted entry field: %x ", This->highlightentryattr));
213
if ((int) This->pointeraid != 0)
215
TN5250_LOG (("Pointer device selection entry field: %x ", This->pointeraid));
217
if (This->selfcheckmod11)
219
TN5250_LOG (("Self-check modulus 11 entry field "));
221
if (This->selfcheckmod10)
223
TN5250_LOG (("Self-check modulus 10 entry field "));
226
TN5250_LOG (("\ntn5250_field_dump: type = %s\n",
227
tn5250_field_description (This)));
228
TN5250_LOG (("tn5250_field_dump: adjust = %s\ntn5250_field_dump: data = ",
229
tn5250_field_adjust_description (This)));
235
/****f* lib5250/tn5250_field_hit_test
237
* tn5250_field_hit_test
239
* ret = tn5250_field_hit_test (This, y, x);
241
* Tn5250Field * This -
245
* Determine if the screen position at row ``y'', column ``x'' is contained
246
* within this field. (A hit-test, in other words.)
249
tn5250_field_hit_test (Tn5250Field * This, int y, int x)
251
int pos = (y * This->w) + x;
252
return (pos >= tn5250_field_start_pos (This)
253
&& pos <= tn5250_field_end_pos (This));
257
/****f* lib5250/tn5250_field_start_pos
259
* tn5250_field_start_pos
261
* ret = tn5250_field_start_pos (This);
263
* Tn5250Field * This -
265
* Figure out the starting address of this field.
268
tn5250_field_start_pos (Tn5250Field * This)
270
return This->start_row * This->w + This->start_col;
274
/****f* lib5250/tn5250_field_end_pos
276
* tn5250_field_end_pos
278
* ret = tn5250_field_end_pos (This);
280
* Tn5250Field * This -
282
* Figure out the ending address of this field.
285
tn5250_field_end_pos (Tn5250Field * This)
287
return tn5250_field_start_pos (This) + tn5250_field_length (This) - 1;
291
/****f* lib5250/tn5250_field_end_row
293
* tn5250_field_end_row
295
* ret = tn5250_field_end_row (This);
297
* Tn5250Field * This -
299
* Figure out the ending row of this field.
302
tn5250_field_end_row (Tn5250Field * This)
304
return tn5250_field_end_pos (This) / This->w;
308
/****f* lib5250/tn5250_field_end_col
310
* tn5250_field_end_col
312
* ret = tn5250_field_end_col (This);
314
* Tn5250Field * This -
316
* Figure out the ending column of this field.
319
tn5250_field_end_col (Tn5250Field * This)
321
return tn5250_field_end_pos (This) % This->w;
325
/****f* lib5250/tn5250_field_description
327
* tn5250_field_description
329
* ret = tn5250_field_description (This);
331
* Tn5250Field * This -
333
* Get a description of this field.
336
tn5250_field_description (Tn5250Field * This)
338
switch (This->FFW & TN5250_FIELD_FIELD_MASK)
340
case TN5250_FIELD_ALPHA_SHIFT:
341
return "Alpha Shift";
342
case TN5250_FIELD_DUP_ENABLE:
343
return "Dup Enabled";
344
case TN5250_FIELD_ALPHA_ONLY:
346
case TN5250_FIELD_NUM_SHIFT:
347
return "Numeric Shift";
348
case TN5250_FIELD_NUM_ONLY:
349
return "Numeric Only";
350
case TN5250_FIELD_KATA_SHIFT:
352
case TN5250_FIELD_DIGIT_ONLY:
353
return "Digits Only";
354
case TN5250_FIELD_MAG_READER:
355
return "Mag Reader I/O Field";
356
case TN5250_FIELD_SIGNED_NUM:
357
return "Signed Numeric";
364
/****f* lib5250/tn5250_field_adjust_description
366
* tn5250_field_adjust_description
368
* ret = tn5250_field_adjust_description (This);
370
* Tn5250Field * This -
372
* Get a description of the mandatory fill mode for this field.
375
tn5250_field_adjust_description (Tn5250Field * This)
377
switch (This->FFW & TN5250_FIELD_MAND_FILL_MASK)
379
case TN5250_FIELD_NO_ADJUST:
381
case TN5250_FIELD_MF_RESERVED_1:
383
case TN5250_FIELD_MF_RESERVED_2:
385
case TN5250_FIELD_MF_RESERVED_3:
387
case TN5250_FIELD_MF_RESERVED_4:
389
case TN5250_FIELD_RIGHT_ZERO:
390
return "Right Adjust, Zero Fill";
391
case TN5250_FIELD_RIGHT_BLANK:
392
return "Right Adjust, Blank Fill";
393
case TN5250_FIELD_MANDATORY_FILL:
394
return "Mandatory Fill";
401
/****f* lib5250/tn5250_field_count_left
403
* tn5250_field_count_left
405
* ret = tn5250_field_count_left (This, y, x);
407
* Tn5250Field * This -
411
* Return the number of characters in the this field which
412
* are to the left of the specified cursor position. Used
413
* as an index to insert data when the user types.
416
tn5250_field_count_left (Tn5250Field * This, int y, int x)
420
pos = (y * This->w + x);
421
pos -= tn5250_field_start_pos (This);
423
TN5250_ASSERT (tn5250_field_hit_test (This, y, x));
424
TN5250_ASSERT (pos >= 0);
425
TN5250_ASSERT (pos < tn5250_field_length (This));
431
/****f* lib5250/tn5250_field_count_right
433
* tn5250_field_count_right
435
* ret = tn5250_field_count_right (This, y, x);
437
* Tn5250Field * This -
441
* This returns the number of characters in the specified field
442
* which are to the right of the specified cursor position.
445
tn5250_field_count_right (Tn5250Field * This, int y, int x)
447
TN5250_ASSERT (tn5250_field_hit_test (This, y, x));
448
return tn5250_field_end_pos (This) - (y * This->w + x);
452
/****f* lib5250/tn5250_field_valid_char
454
* tn5250_field_valid_char
456
* ret = tn5250_field_valid_char (field, ch);
458
* Tn5250Field * field -
462
* Determine if the supplied character is a valid data character
463
* for this field, and return system reference code for errors (SRC)
466
tn5250_field_valid_char (Tn5250Field * field, int ch, int *src)
468
TN5250_LOG (("HandleKey: fieldtype = %d; char = '%c'.\n",
469
tn5250_field_type (field), ch));
471
*src = TN5250_KBDSRC_NONE;
473
switch (tn5250_field_type (field))
475
case TN5250_FIELD_ALPHA_SHIFT:
478
case TN5250_FIELD_ALPHA_ONLY:
479
if (!(isalpha (ch) || ch == ',' || ch == '.' || ch == '-' || ch == ' '))
481
*src = TN5250_KBDSRC_ALPHAONLY;
486
case TN5250_FIELD_NUM_SHIFT:
489
case TN5250_FIELD_NUM_ONLY:
490
if (!(isdigit (ch) || ch == ',' || ch == '.' || ch == '-' || ch == ' '))
492
*src = TN5250_KBDSRC_NUMONLY;
497
case TN5250_FIELD_KATA_SHIFT:
498
TN5250_LOG (("KATAKANA not implemented.\n"));
501
case TN5250_FIELD_DIGIT_ONLY:
504
*src = TN5250_KBDSRC_ONLY09;
509
case TN5250_FIELD_MAG_READER:
510
*src = TN5250_KBDSRC_DATA_DISALLOWED;
513
case TN5250_FIELD_SIGNED_NUM:
516
*src = TN5250_KBDSRC_ONLY09;
525
/****f* lib5250/tn5250_field_set_mdt
527
* tn5250_field_set_mdt
529
* tn5250_field_set_mdt (This);
531
* Tn5250Field * This -
533
* Set the MDT flag for this field and for the table which owns it.
536
tn5250_field_set_mdt (Tn5250Field * This)
538
TN5250_ASSERT (This->table != NULL);
540
/* Taken from tn5250j
541
* get the first field of a continued edit field if it is continued
543
if ((This->continuous) && !tn5250_field_is_continued_first (This))
547
for (iter = This->prev;
548
(iter->continuous && !tn5250_field_is_continued_first (iter));
551
TN5250_ASSERT (iter->continuous);
554
tn5250_field_set_mdt (iter);
555
tn5250_dbuffer_set_mdt (iter->table);
559
This->FFW |= TN5250_FIELD_MODIFIED;
560
tn5250_dbuffer_set_mdt (This->table);
566
/****f* lib5250/tn5250_field_list_destroy
568
* tn5250_field_list_destroy
570
* ret = tn5250_field_list_destroy (list);
572
* Tn5250Field * list -
574
* Destroy all fields in a field list.
577
tn5250_field_list_destroy (Tn5250Field * list)
579
Tn5250Field *iter, *next;
581
if ((iter = list) != NULL)
587
tn5250_field_destroy (iter);
590
while (iter != list);
597
/****f* lib5250/tn5250_field_list_add
599
* tn5250_field_list_add
601
* ret = tn5250_field_list_add (list, node);
603
* Tn5250Field * list -
604
* Tn5250Field * node -
606
* Add a field to the end of a list of fields.
609
tn5250_field_list_add (Tn5250Field * list, Tn5250Field * node)
611
node->prev = node->next = NULL;
615
node->next = node->prev = node;
619
node->prev = list->prev;
620
node->prev->next = node;
621
node->next->prev = node;
626
/****f* lib5250/tn5250_field_list_remove
628
* tn5250_field_list_remove
630
* ret = tn5250_field_list_remove (list, node);
632
* Tn5250Field * list -
633
* Tn5250Field * node -
635
* Remove a field from a list of fields.
638
tn5250_field_list_remove (Tn5250Field * list, Tn5250Field * node)
644
if (list->next == list && list == node)
646
node->next = node->prev = NULL;
654
node->next->prev = node->prev;
655
node->prev->next = node->next;
656
node->prev = node->next = NULL;
661
/****f* lib5250/tn5250_field_list_find_by_id
663
* tn5250_field_list_find_by_id
665
* ret = tn5250_field_list_find_by_id (list, id);
667
* Tn5250Field * list -
670
* Find a field by its numeric id.
673
tn5250_field_list_find_by_id (Tn5250Field * list, int id)
677
if ((iter = list) != NULL)
685
while (iter != list);
691
/****f* lib5250/tn5250_field_list_copy
693
* tn5250_field_list_copy
695
* ret = tn5250_field_list_copy (This);
697
* Tn5250Field * This -
699
* Copy all fields in a list to another list.
702
tn5250_field_list_copy (Tn5250Field * This)
704
Tn5250Field *new_list = NULL, *iter, *new_field;
705
if ((iter = This) != NULL)
709
new_field = tn5250_field_copy (iter);
710
if (new_field != NULL)
712
new_list = tn5250_field_list_add (new_list, new_field);
716
while (iter != This);