GnuCOBOL  2.0
A free COBOL compiler
termio.c File Reference
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <errno.h>
#include <time.h>
#include "libcob.h"
#include "coblocal.h"
Include dependency graph for termio.c:

Go to the source code of this file.

Macros

#define COB_LIB_EXPIMP
 

Functions

static void display_numeric (cob_field *f, FILE *fp)
 
static void pretty_display_numeric (cob_field *f, FILE *fp)
 
static void display_alnum (cob_field *f, FILE *fp)
 
static void display_common (cob_field *f, FILE *fp)
 
void cob_display (const int to_stderr, const int newline, const int varcnt,...)
 
void cob_accept (cob_field *f)
 
void cob_init_termio (cob_global *lptr, cob_settings *sptr)
 

Variables

static cob_globalcobglobptr
 
static cob_settingscobsetptr
 
static const unsigned short bin_digits []
 
static const cob_field_attr const_alpha_attr
 

Macro Definition Documentation

#define COB_LIB_EXPIMP

Definition at line 36 of file termio.c.

Function Documentation

void cob_accept ( cob_field f)

Definition at line 283 of file termio.c.

References cob_field::attr, COB_EC_IMP_ACCEPT, cob_field_accept(), COB_FIELD_IS_NUMERIC, COB_FIELD_TYPE, COB_MEDIUM_MAX, COB_MODULE_PTR, cob_move(), __cob_global::cob_screen_initialized, COB_SCREEN_PROMPT, cob_set_exception(), cob_set_int(), COB_TERM_BUFF, COB_TYPE_NUMERIC_DISPLAY, const_alpha_attr, cob_field::data, NULL, cob_field::size, and unlikely.

284 {
285  unsigned char *p;
286  size_t size;
287  int ipchr;
288  cob_field temp;
289 
292  NULL, NULL, NULL, NULL,
294  return;
295  }
296  if (COB_MODULE_PTR->crt_status) {
297  if (COB_FIELD_IS_NUMERIC (COB_MODULE_PTR->crt_status)) {
298  cob_set_int (COB_MODULE_PTR->crt_status, 0);
299  } else {
300  memset (COB_MODULE_PTR->crt_status->data, '0', (size_t)4);
301  }
302  }
303  /* extension: ACCEPT OMITTED */
304  if (unlikely(!f)) {
305  for (; ; ) {
306  ipchr = getchar ();
307  if (ipchr == '\n' || ipchr == EOF) {
308  break;
309  }
310  }
311  return;
312  }
313  p = COB_TERM_BUFF;
314  temp.data = p;
315  temp.attr = &const_alpha_attr;
316  size = 0;
317  /* Read a line */
318  for (; size < COB_MEDIUM_MAX; ) {
319  ipchr = getchar ();
320  if (unlikely(ipchr == EOF)) {
322  if (!size) {
323  size = 1;
324  p[0] = ' ';
325  p[1] = 0;
326  }
327  break;
328  } else if (ipchr == '\n') {
329  break;
330  }
331  p[size++] = (char) ipchr;
332  }
333  temp.size = size;
335  if (temp.size > f->size) {
336  temp.size = f->size;
337  }
338  }
339  cob_move (&temp, f);
340 }
static const cob_field_attr const_alpha_attr
Definition: termio.c:49
#define COB_TERM_BUFF
Definition: coblocal.h:186
#define COB_FIELD_IS_NUMERIC(f)
Definition: common.h:674
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
#define COB_FIELD_TYPE(f)
Definition: common.h:662
unsigned char * data
Definition: common.h:952
void cob_field_accept(cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, const int)
Definition: screenio.c:2353
#define unlikely(x)
Definition: common.h:437
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
void cob_set_exception(const int id)
Definition: common.c:1212
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
void cob_set_int(cob_field *, const int)
Definition: move.c:1612
#define COB_MODULE_PTR
Definition: coblocal.h:185
static cob_global * cobglobptr
Definition: termio.c:43
#define COB_SCREEN_PROMPT
Definition: common.h:914
unsigned int cob_screen_initialized
Definition: common.h:1208
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
#define COB_MEDIUM_MAX
Definition: common.h:549

Here is the call graph for this function:

void cob_display ( const int  to_stderr,
const int  newline,
const int  varcnt,
  ... 
)

Definition at line 238 of file termio.c.

References COB_DISP_TO_STDERR, cob_field_display(), COB_SCREEN_EMULATE_NL, __cob_global::cob_screen_initialized, cob_u32_t, display_common(), NULL, and unlikely.

Referenced by cobxref_(), GCic_(), and get__reserved__lists_().

239 {
240  FILE *fp;
241  cob_field *f;
242  int i;
243  int nlattr;
244  cob_u32_t disp_redirect;
245  va_list args;
246 
247  disp_redirect = 0;
248  if (to_stderr) {
249  fp = stderr;
250  } else {
251  fp = stdout;
253  if (!COB_DISP_TO_STDERR) {
254  disp_redirect = 1;
255  } else {
256  fp = stderr;
257  }
258  }
259  }
260 
261  nlattr = newline ? COB_SCREEN_EMULATE_NL : 0;
262  va_start (args, varcnt);
263  for (i = 0; i < varcnt; ++i) {
264  f = va_arg (args, cob_field *);
265  if (unlikely(disp_redirect)) {
267  NULL, NULL, nlattr);
268  } else {
269  display_common (f, fp);
270  }
271  }
272  va_end (args);
273 
274  if (newline && !disp_redirect) {
275  putc ('\n', fp);
276  fflush (fp);
277  }
278 }
#define cob_u32_t
Definition: common.h:31
#define COB_SCREEN_EMULATE_NL
Definition: common.h:922
#define unlikely(x)
Definition: common.h:437
void cob_field_display(cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, cob_field *, const int)
Definition: screenio.c:2341
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
static void display_common(cob_field *f, FILE *fp)
Definition: termio.c:167
static cob_global * cobglobptr
Definition: termio.c:43
unsigned int cob_screen_initialized
Definition: common.h:1208
#define COB_DISP_TO_STDERR
Definition: coblocal.h:191

Here is the call graph for this function:

Here is the caller graph for this function:

void cob_init_termio ( cob_global lptr,
cob_settings sptr 
)

Definition at line 343 of file termio.c.

Referenced by cob_init().

344 {
345  cobglobptr = lptr;
346  cobsetptr = sptr;
347 }
static cob_settings * cobsetptr
Definition: termio.c:44
static cob_global * cobglobptr
Definition: termio.c:43

Here is the caller graph for this function:

static void display_alnum ( cob_field f,
FILE *  fp 
)
static

Definition at line 157 of file termio.c.

References cob_field::data, and cob_field::size.

Referenced by display_common().

158 {
159  size_t i;
160 
161  for (i = 0; i < f->size; ++i) {
162  putc (f->data[i], fp);
163  }
164 }
unsigned char * data
Definition: common.h:952
size_t size
Definition: common.h:951

Here is the caller graph for this function:

static void display_common ( cob_field f,
FILE *  fp 
)
static

Definition at line 167 of file termio.c.

References cob_field::attr, bin_digits, COB_FIELD_IS_NUMERIC, COB_FIELD_IS_POINTER, COB_FIELD_REAL_BINARY, COB_FIELD_TYPE, COB_MODULE_PTR, cob_print_ieeedec(), cob_print_realbin(), COB_TYPE_NUMERIC_BINARY, COB_TYPE_NUMERIC_DOUBLE, COB_TYPE_NUMERIC_FLOAT, COB_TYPE_NUMERIC_FP_DEC128, COB_TYPE_NUMERIC_FP_DEC64, cob_field::data, cob_field_attr::digits, display_alnum(), display_numeric(), pretty_display_numeric(), and cob_field::size.

Referenced by cob_display().

168 {
169  unsigned char *p;
170  union {
171  double f1doub;
172  float f1float;
173  } un;
174  int n;
175 #if 0 /* RXWRXW - Print bin */
176  cob_field temp;
177  cob_field_attr attr;
178 #endif
179 
180  if (f->size == 0) {
181  return;
182  }
183  switch (COB_FIELD_TYPE (f)) {
185  memcpy (&un.f1doub, f->data, sizeof (double));
186  fprintf (fp, "%-.16G", un.f1doub);
187  return;
189  memcpy (&un.f1float, f->data, sizeof (float));
190  fprintf (fp, "%-.8G", (double)un.f1float);
191  return;
194  cob_print_ieeedec (f, fp);
195  return;
196  default:
197  break;
198  }
199  if (COB_FIELD_IS_POINTER (f)) {
200  fprintf (fp, "0x");
201 #ifdef WORDS_BIGENDIAN
202  p = f->data;
203  for (n = 0; n < sizeof(void *); ++n, ++p) {
204 #else
205  p = f->data + sizeof(void *) - 1;
206  for (n = sizeof(void *) - 1; n >= 0; --n, --p) {
207 #endif
208  fprintf (fp, "%x%x", *p >> 4, *p & 0xF);
209  }
210  return;
211  } else if (COB_FIELD_REAL_BINARY(f) ||
213  !COB_MODULE_PTR->flag_pretty_display)) {
214  cob_print_realbin (f, fp, bin_digits[f->size]);
215  return;
216 #if 0 /* RXWRXW - print bin */
217  } else if (COB_FIELD_TYPE(f) == COB_TYPE_NUMERIC_BINARY &&
218  !COB_MODULE_PTR->flag_pretty_display) {
219  attr = *f->attr;
220  temp = *f;
221  attr.digits = bin_digits[f->size];
222  temp.attr = &attr;
223  display_numeric (&temp, fp);
224  return;
225 #endif
226  } else if (COB_FIELD_IS_NUMERIC (f)) {
227  if (COB_MODULE_PTR->flag_pretty_display) {
228  pretty_display_numeric (f, fp);
229  } else {
230  display_numeric (f, fp);
231  }
232  return;
233  }
234  display_alnum (f, fp);
235 }
static const unsigned short bin_digits[]
Definition: termio.c:46
#define COB_FIELD_IS_NUMERIC(f)
Definition: common.h:674
#define COB_FIELD_TYPE(f)
Definition: common.h:662
void cob_print_realbin(const cob_field *, FILE *, const int)
Definition: numeric.c:1676
unsigned char * data
Definition: common.h:952
static void pretty_display_numeric(cob_field *f, FILE *fp)
Definition: termio.c:90
#define COB_TYPE_NUMERIC_FP_DEC64
Definition: common.h:613
#define COB_TYPE_NUMERIC_FLOAT
Definition: common.h:610
#define COB_FIELD_REAL_BINARY(f)
Definition: common.h:649
#define COB_TYPE_NUMERIC_BINARY
Definition: common.h:608
#define COB_MODULE_PTR
Definition: coblocal.h:185
void cob_print_ieeedec(const cob_field *, FILE *)
Definition: numeric.c:1647
unsigned short digits
Definition: common.h:942
static void display_numeric(cob_field *f, FILE *fp)
Definition: termio.c:55
size_t size
Definition: common.h:951
#define COB_TYPE_NUMERIC_DOUBLE
Definition: common.h:611
const cob_field_attr * attr
Definition: common.h:953
#define COB_TYPE_NUMERIC_FP_DEC128
Definition: common.h:614
static void display_alnum(cob_field *f, FILE *fp)
Definition: termio.c:157
#define COB_FIELD_IS_POINTER(f)
Definition: common.h:650

Here is the call graph for this function:

Here is the caller graph for this function:

static void display_numeric ( cob_field f,
FILE *  fp 
)
static

Definition at line 55 of file termio.c.

References _, cob_field::attr, COB_ATTR_INIT, COB_FIELD_DIGITS, COB_FIELD_HAVE_SIGN, COB_FIELD_SCALE, COB_FIELD_SIGN_LEADING, COB_FIELD_TYPE, COB_FLAG_HAVE_SIGN, COB_FLAG_SIGN_LEADING, COB_FLAG_SIGN_SEPARATE, COB_MEDIUM_MAX, cob_move(), COB_TERM_BUFF, COB_TYPE_NUMERIC_DISPLAY, cob_field::data, cob_field_attr::flags, NULL, and cob_field::size.

Referenced by display_common().

56 {
57  int i;
58  unsigned short digits;
59  signed short scale;
60  int size;
61  cob_field_attr attr;
62  cob_field temp;
63 
64  digits = COB_FIELD_DIGITS (f);
65  scale = COB_FIELD_SCALE (f);
66  size = digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0);
67  if (size >= COB_MEDIUM_MAX) {
68  fputs (_("(Not representable)"), fp);
69  return;
70  }
71  COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, digits, scale, 0, NULL);
72  temp.size = size;
73  temp.data = COB_TERM_BUFF;
74  temp.attr = &attr;
75  if (COB_FIELD_HAVE_SIGN (f)) {
77  if (COB_FIELD_SIGN_LEADING (f) ||
80  }
81  }
82 
83  cob_move (f, &temp);
84  for (i = 0; i < size; ++i) {
85  putc (temp.data[i], fp);
86  }
87 }
#define COB_FIELD_SCALE(f)
Definition: common.h:664
#define COB_TERM_BUFF
Definition: coblocal.h:186
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
#define COB_FIELD_TYPE(f)
Definition: common.h:662
#define COB_ATTR_INIT(u, v, x, y, z)
Definition: coblocal.h:150
unsigned short flags
Definition: common.h:944
unsigned char * data
Definition: common.h:952
#define COB_FLAG_HAVE_SIGN
Definition: common.h:630
#define _(s)
Definition: cobcrun.c:59
EC ARGUMENT EC EC BOUND EC BOUND EC BOUND EC BOUND TABLE EC DATA EC DATA EC DATA PTR NULL
Definition: exception.def:95
#define COB_FLAG_SIGN_LEADING
Definition: common.h:632
#define COB_FLAG_SIGN_SEPARATE
Definition: common.h:631
#define COB_TYPE_NUMERIC_DISPLAY
Definition: common.h:607
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
#define COB_FIELD_HAVE_SIGN(f)
Definition: common.h:643
#define COB_FIELD_DIGITS(f)
Definition: common.h:663
#define COB_MEDIUM_MAX
Definition: common.h:549
#define COB_FIELD_SIGN_LEADING(f)
Definition: common.h:645

Here is the call graph for this function:

Here is the caller graph for this function:

static void pretty_display_numeric ( cob_field f,
FILE *  fp 
)
static

Definition at line 90 of file termio.c.

References _, cob_field::attr, COB_ATTR_INIT, COB_FIELD_DIGITS, COB_FIELD_HAVE_SIGN, COB_FIELD_SCALE, COB_MEDIUM_MAX, COB_MODULE_PTR, cob_move(), COB_TERM_BUFF, COB_TYPE_NUMERIC_EDITED, cob_field::data, and cob_field::size.

Referenced by display_common().

91 {
92  unsigned char *p;
93  unsigned char *q;
94  int i;
95  unsigned short digits;
96  signed short scale;
97  int size;
98  cob_field_attr attr;
99  cob_field temp;
100  unsigned char pic[32];
101 
102  digits = COB_FIELD_DIGITS (f);
103  scale = COB_FIELD_SCALE (f);
104  size = (digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0)
105  + (scale > 0 ? 1 : 0));
106  if (size > COB_MEDIUM_MAX) {
107  fputs (_("(Not representable)"), fp);
108  return;
109  }
110  q = COB_TERM_BUFF;
111  temp.size = size;
112  temp.data = q;
113  temp.attr = &attr;
114  COB_ATTR_INIT (COB_TYPE_NUMERIC_EDITED, digits, scale, 0,
115  (const char *)pic);
116  p = pic;
117 #if 0 /* RXWRXW - memset */
118  memset (pic, 0, sizeof (pic));
119  memset (q, 0, 256);
120 #endif
121  if (COB_FIELD_HAVE_SIGN (f)) {
122  *p++ = '+';
123  i = 1;
124  memcpy (p, (unsigned char *)&i, sizeof(int));
125  p += sizeof(int);
126  }
127  if (scale > 0) {
128  i = digits - scale;
129  if (i > 0 ) {
130  *p++ = '9';
131  memcpy (p, (unsigned char *)&i, sizeof(int));
132  p += sizeof(int);
133  }
134  *p++ = COB_MODULE_PTR->decimal_point;
135  i = 1;
136  memcpy (p, (unsigned char *)&i, sizeof(int));
137  p += sizeof(int);
138  *p++ = '9';
139  i = scale;
140  memcpy (p, (unsigned char *)&i, sizeof(int));
141  p += sizeof(int);
142  } else {
143  *p++ = '9';
144  i = digits;
145  memcpy (p, (unsigned char *)&i, sizeof(int));
146  p += sizeof(int);
147  }
148  *p = 0;
149 
150  cob_move (f, &temp);
151  for (i = 0; i < size; ++i) {
152  putc (q[i], fp);
153  }
154 }
#define COB_FIELD_SCALE(f)
Definition: common.h:664
#define COB_TERM_BUFF
Definition: coblocal.h:186
void cob_move(cob_field *, cob_field *)
Definition: move.c:1170
#define COB_ATTR_INIT(u, v, x, y, z)
Definition: coblocal.h:150
unsigned char * data
Definition: common.h:952
#define _(s)
Definition: cobcrun.c:59
#define COB_MODULE_PTR
Definition: coblocal.h:185
size_t size
Definition: common.h:951
const cob_field_attr * attr
Definition: common.h:953
#define COB_FIELD_HAVE_SIGN(f)
Definition: common.h:643
#define COB_FIELD_DIGITS(f)
Definition: common.h:663
#define COB_TYPE_NUMERIC_EDITED
Definition: common.h:619
#define COB_MEDIUM_MAX
Definition: common.h:549

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const unsigned short bin_digits[]
static
Initial value:
=
{ 1, 3, 5, 8, 10, 13, 15, 17, 20 }

Definition at line 46 of file termio.c.

Referenced by display_common().

cob_global* cobglobptr
static

Definition at line 43 of file termio.c.

cob_settings* cobsetptr
static

Definition at line 44 of file termio.c.

const cob_field_attr const_alpha_attr
static
Initial value:
=
{COB_TYPE_ALPHANUMERIC, 0, 0, 0, ((void*)0) }
#define COB_TYPE_ALPHANUMERIC
Definition: common.h:621

Definition at line 49 of file termio.c.

Referenced by cob_accept().