示例#1
0
int
cob_cmp (cob_field *f1, cob_field *f2)
{
	cob_field	temp;
	cob_field_attr	attr;
	unsigned char	buff[48];

	if (COB_FIELD_IS_NUMERIC (f1) && COB_FIELD_IS_NUMERIC (f2)) {
		return cob_numeric_cmp (f1, f2);
	}
	if (COB_FIELD_TYPE (f2) == COB_TYPE_ALPHANUMERIC_ALL) {
		if (f2 == &cob_zero && COB_FIELD_IS_NUMERIC (f1)) {
			return cob_cmp_int (f1, 0);
		} else if (f2->size == 1) {
			return cob_cmp_char (f1, f2->data[0]);
		} else {
			return cob_cmp_all (f1, f2);
		}
	} else if (COB_FIELD_TYPE (f1) == COB_TYPE_ALPHANUMERIC_ALL) {
		if (f1 == &cob_zero && COB_FIELD_IS_NUMERIC (f2)) {
			return -cob_cmp_int (f2, 0);
		} else if (f1->size == 1) {
			return -cob_cmp_char (f2, f1->data[0]);
		} else {
			return -cob_cmp_all (f2, f1);
		}
	} else {
		if (COB_FIELD_IS_NUMERIC (f1)
		    && COB_FIELD_TYPE (f1) != COB_TYPE_NUMERIC_DISPLAY) {
			temp.size = COB_FIELD_DIGITS(f1);
			temp.data = buff;
			temp.attr = &attr;
			attr = *f1->attr;
			attr.type = COB_TYPE_NUMERIC_DISPLAY;
			attr.flags &= ~COB_FLAG_HAVE_SIGN;
			cob_move (f1, &temp);
			f1 = &temp;
		}
		if (COB_FIELD_IS_NUMERIC (f2)
		    && COB_FIELD_TYPE (f2) != COB_TYPE_NUMERIC_DISPLAY) {
			temp.size = COB_FIELD_DIGITS(f2);
			temp.data = buff;
			temp.attr = &attr;
			attr = *f2->attr;
			attr.type = COB_TYPE_NUMERIC_DISPLAY;
			attr.flags &= ~COB_FLAG_HAVE_SIGN;
			cob_move (f2, &temp);
			f2 = &temp;
		}
		return cob_cmp_alnum (f1, f2);
	}
}
示例#2
0
static void
display_numeric (cob_field *f, FILE *fp)
{
	int		i;
	int		digits;
	int		scale;
	int		size;
	cob_field_attr	attr;
	cob_field	temp;
	unsigned char	data[128];

	digits = COB_FIELD_DIGITS (f);
	scale = COB_FIELD_SCALE (f);
	size = digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0);
	COB_ATTR_INIT (COB_TYPE_NUMERIC_DISPLAY, digits, scale, 0, NULL);
	temp.size = size;
	temp.data = data;
	temp.attr = &attr;
	if (COB_FIELD_HAVE_SIGN (f)) {
		attr.flags = COB_FLAG_HAVE_SIGN | COB_FLAG_SIGN_SEPARATE;
		if (COB_FIELD_SIGN_LEADING (f)
		    || COB_FIELD_TYPE (f) == COB_TYPE_NUMERIC_BINARY) {
			attr.flags |= COB_FLAG_SIGN_LEADING;
		}
	}

	cob_move (f, &temp);
	for (i = 0; i < size; i++) {
		putc (data[i], fp);
	}
}
示例#3
0
void
cob_accept (cob_field *f)
{
	size_t		size;
	cob_field_attr	attr;
	cob_field	temp;
	unsigned char	buff[COB_MEDIUM_BUFF];

	if (isatty (fileno (stdin))) {
		/* terminal input */
		temp.data = buff;
		temp.attr = &attr;
		COB_ATTR_INIT (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL);
		/* read a line */
		fgets ((char *)buff, COB_MEDIUM_BUFF, stdin);
		temp.size = strlen ((char *)buff) - 1;

		/* move it to the field */
		cob_move (&temp, f);
	} else {
		/* non-terminal input */
		fgets ((char *)buff, COB_MEDIUM_BUFF, stdin);
		size = strlen ((char *)buff) - 1;
		if (size > f->size) {
			size = f->size;
		}
		memcpy (f->data, buff, size);
		memset (f->data + size, ' ', f->size - size);
	}
}
示例#4
0
文件: strings.c 项目: ps8v9/tmp
static void
cob_str_memcpy (cob_field *dst, unsigned char *src, const int size)
{
	cob_field	temp;

	temp.size = size;
	temp.data = src;
	temp.attr = &const_alpha_attr;
	cob_move (&temp, dst);
}
示例#5
0
void
cob_memcpy (cob_field *dst, unsigned char *src, const int size)
{
	cob_field	temp;
	cob_field_attr	attr;

	COB_ATTR_INIT (COB_TYPE_ALPHANUMERIC, 0, 0, 0, NULL);
	temp.size = size;
	temp.data = src;
	temp.attr = &attr;
	cob_move (&temp, dst);
}
示例#6
0
void
cob_accept_arg_number (cob_field *f)
{
	int		n = cob_argc - 1;
	cob_field_attr	attr;
	cob_field	temp;

	temp.size = 4;
	temp.data = (unsigned char *)&n;
	temp.attr = &attr;
	COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0, 0, NULL);
	cob_move (&temp, f);
}
示例#7
0
void
cob_display_arg_number (cob_field *f)
{
	int		n;
	cob_field_attr	attr;
	cob_field	temp;

	temp.size = 4;
	temp.data = (unsigned char *)&n;
	temp.attr = &attr;
	COB_ATTR_INIT (COB_TYPE_NUMERIC_BINARY, 9, 0, 0, NULL);
	cob_move (f, &temp);
	if (n < 0 || n >= cob_argc) {
		cob_set_exception (COB_EC_IMP_DISPLAY);
		return;
	}
	current_arg = n;
}
示例#8
0
static void
pretty_display_numeric (cob_field *f, FILE *fp)
{
	unsigned char	*p;
	int		i;
	int		digits;
	int		scale;
	int		size;
	cob_field_attr	attr;
	cob_field	temp;
	unsigned char	pic[64];
	unsigned char	data[256];

/* RXW
	if (COB_FIELD_TYPE(f) == COB_TYPE_NUMERIC_BINARY) {
		digits = bin_digits[f->size];
	} else {
*/
		digits = COB_FIELD_DIGITS (f);
/* RXW
	}
*/
	scale = COB_FIELD_SCALE (f);
	size = (digits + (COB_FIELD_HAVE_SIGN (f) ? 1 : 0)
		+ (scale > 0 ? 1 : 0));
	p = pic;
	temp.size = size;
	temp.data = data;
	temp.attr = &attr;
	COB_ATTR_INIT (COB_TYPE_NUMERIC_EDITED, digits, scale, 0, (char *)pic);
	memset (pic, 0, sizeof (pic));
	memset (data, 0, sizeof (data));
	if (COB_FIELD_HAVE_SIGN (f)) {
		*p++ = '+';
		i = 1;
		memcpy (p, (unsigned char *)&i, sizeof(int));
		p += sizeof(int);
	}
	if (scale > 0) {
		*p++ = '9';
		i = digits - scale;
		memcpy (p, (unsigned char *)&i, sizeof(int));
		p += sizeof(int);
		*p++ = cob_current_module->decimal_point;
		i = 1;
		memcpy (p, (unsigned char *)&i, sizeof(int));
		p += sizeof(int);
		*p++ = '9';
		i = scale;
		memcpy (p, (unsigned char *)&i, sizeof(int));
		p += sizeof(int);
	} else {
		*p++ = '9';
		i = digits;
		memcpy (p, (unsigned char *)&i, sizeof(int));
		p += sizeof(int);
	}

	cob_move (f, &temp);
	for (i = 0; i < size; i++) {
		putc (data[i], fp);
	}
}
示例#9
0
static int
ORBITS_ (const int entry)
{
  /* Local variables */
  #include "orbits.c.l.h"

  static int initialized = 0;
  static cob_field *cob_user_parameters[COB_MAX_FIELD_PARAMS];
  static struct cob_module module = { NULL, NULL, NULL, NULL, cob_user_parameters, 0, '.', '$', ',', 1, 1, 1, 0 };

  /* Start of function code */

  /* CANCEL callback handling */
  if (unlikely(entry < 0)) {
  	if (!initialized) {
  		return 0;
  	}
  	cob_close (h_ENTRADA, 0, NULL);
  	cob_close (h_SORTIDA, 0, NULL);
  	mpz_clear (d0.value);
  	d0.scale = 0;
  	mpz_clear (d1.value);
  	d1.scale = 0;
  	mpz_clear (d2.value);
  	d2.scale = 0;
  	mpz_clear (d3.value);
  	d3.scale = 0;
  	mpz_clear (d4.value);
  	d4.scale = 0;
  	initialized = 0;
  	return 0;
  }

  /* Initialize frame stack */
  frame_ptr = &frame_stack[0];
  frame_ptr->perform_through = 0;

  /* Push module stack */
  module.next = cob_current_module;
  cob_current_module = &module;

  /* Initialize program */
  if (unlikely(initialized == 0))
    {
      if (!cob_initialized) {
        cob_fatal_error (COB_FERROR_INITIALIZED);
      }
      cob_check_version (COB_SOURCE_FILE, COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
      /* Initialize decimal numbers */
      cob_decimal_init (&d0);
      cob_decimal_init (&d1);
      cob_decimal_init (&d2);
      cob_decimal_init (&d3);
      cob_decimal_init (&d4);

      (*(int *) (b_1)) = 0;

      if (!h_ENTRADA)
      {
        h_ENTRADA = cob_malloc (sizeof(cob_file));
      }
      h_ENTRADA->select_name = (const char *)"ENTRADA";
      h_ENTRADA->file_status = h_ENTRADA_status;
      memset (h_ENTRADA_status, '0', 2);
      h_ENTRADA->assign = &c_1;
      h_ENTRADA->record = &f_14;
      h_ENTRADA->record_size = NULL;
      h_ENTRADA->record_min = 0;
      h_ENTRADA->record_max = 33;
      h_ENTRADA->nkeys = 0;
      h_ENTRADA->keys = NULL;
      h_ENTRADA->file = NULL;
      h_ENTRADA->organization = 1;
      h_ENTRADA->access_mode = 1;
      h_ENTRADA->lock_mode = 0;
      h_ENTRADA->open_mode = 0;
      h_ENTRADA->flag_optional = 0;
      h_ENTRADA->last_open_mode = 0;
      h_ENTRADA->special = 0;
      h_ENTRADA->flag_nonexistent = 0;
      h_ENTRADA->flag_end_of_file = 0;
      h_ENTRADA->flag_begin_of_file = 0;
      h_ENTRADA->flag_first_read = 0;
      h_ENTRADA->flag_read_done = 0;
      h_ENTRADA->flag_select_features = 0;
      h_ENTRADA->flag_needs_nl = 0;
      h_ENTRADA->flag_needs_top = 0;
      h_ENTRADA->file_version = 0;
      if (!h_SORTIDA)
      {
        h_SORTIDA = cob_malloc (sizeof(cob_file));
      }
      h_SORTIDA->select_name = (const char *)"SORTIDA";
      h_SORTIDA->file_status = h_SORTIDA_status;
      memset (h_SORTIDA_status, '0', 2);
      h_SORTIDA->assign = &c_2;
      h_SORTIDA->record = &f_16;
      h_SORTIDA->record_size = NULL;
      h_SORTIDA->record_min = 0;
      h_SORTIDA->record_max = 80;
      h_SORTIDA->nkeys = 0;
      h_SORTIDA->keys = NULL;
      h_SORTIDA->file = NULL;
      h_SORTIDA->organization = 1;
      h_SORTIDA->access_mode = 1;
      h_SORTIDA->lock_mode = 0;
      h_SORTIDA->open_mode = 0;
      h_SORTIDA->flag_optional = 0;
      h_SORTIDA->last_open_mode = 0;
      h_SORTIDA->special = 0;
      h_SORTIDA->flag_nonexistent = 0;
      h_SORTIDA->flag_end_of_file = 0;
      h_SORTIDA->flag_begin_of_file = 0;
      h_SORTIDA->flag_first_read = 0;
      h_SORTIDA->flag_read_done = 0;
      h_SORTIDA->flag_select_features = 0;
      h_SORTIDA->flag_needs_nl = 0;
      h_SORTIDA->flag_needs_top = 0;
      h_SORTIDA->file_version = 0;

      initialized = 1;
    }

  /* Allocate LOCAL storage */
  b_17 = cob_malloc (24);
  b_21 = cob_malloc (24);
  b_25 = cob_malloc (24);
  b_29 = cob_malloc (24);
  b_33 = cob_malloc (24);
  b_37 = cob_malloc (24);
  b_41 = cob_malloc (24);
  b_45 = cob_malloc (8);
  b_46 = cob_malloc (4);
  b_47 = cob_malloc (8);
  b_48 = cob_malloc (8);
  b_49 = cob_malloc (8);
  b_50 = cob_malloc (8);
  b_51 = cob_malloc (8);
  b_52 = cob_malloc (4);
  b_53 = cob_malloc (1);
  b_55 = cob_malloc (56);
  b_61 = cob_malloc (56);
  b_67 = cob_malloc (56);

  /* Initialialize LOCAL storage */
  {double temp = 0.0; memcpy (b_17, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_17 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_17 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_21, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_21 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_21 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_25, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_25 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_25 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_29, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_29 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_29 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_33, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_33 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_33 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_37, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_37 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_37 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_41, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_41 + 8, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_41 + 16, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_45, (char *)&temp, sizeof(temp));}
  memset (b_46, 0, 4);
  {double temp = 0.0; memcpy (b_47, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_48, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_49, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_50, (char *)&temp, sizeof(temp));}
  {double temp = 0.0; memcpy (b_51, (char *)&temp, sizeof(temp));}
  memset (b_52, 0, 4);
  *(unsigned char *)(b_53) = 32;
  memcpy (b_55, "X", 1);
  memset (b_55 + 1, 32, 17);
  *(unsigned char *)(b_55 + 18) = 32;
  memcpy (b_55 + 19, "Y", 1);
  memset (b_55 + 19 + 1, 32, 17);
  *(unsigned char *)(b_55 + 37) = 32;
  memcpy (b_55 + 38, "Z", 1);
  memset (b_55 + 38 + 1, 32, 17);
  memset (b_61, 61, 18);
  *(unsigned char *)(b_61 + 18) = 32;
  memset (b_61 + 19, 61, 18);
  *(unsigned char *)(b_61 + 37) = 32;
  memset (b_61 + 38, 61, 18);
  memset (b_67, 48, 18);
  *(unsigned char *)(b_67 + 18) = 32;
  memset (b_67 + 19, 48, 18);
  *(unsigned char *)(b_67 + 37) = 32;
  memset (b_67 + 38, 48, 18);

  cob_save_call_params = cob_call_params;

  /* Entry dispatch */
  goto l_2;

  /* PROCEDURE DIVISION */

  /* Entry ORBITS */

  l_2:;

  /* MAIN SECTION */

  /* BEGIN */

  /* orbits.cob:97: DISPLAY */
  {
    cob_display (0, 1, 1, &c_3);
  }
  /* orbits.cob:98: MOVE */
  {
    cob_move (&c_4, (f_45.data = b_45, &f_45));
  }
  /* orbits.cob:99: OPEN */
  {
    cob_exception_code = 0;
    {
      cob_open (h_ENTRADA, 1, 0, NULL);
    }
    if (unlikely(cob_exception_code != 0))
      {
        /* PERFORM Default Error Handler */
        frame_ptr++;
        frame_ptr->perform_through = 1;
        frame_ptr->return_address = &&l_14;
        goto l_1;
        l_14:
        frame_ptr--;
      }
  }
示例#10
0
void
cob_unstring_into (cob_field *dst, cob_field *dlm, cob_field *cnt)
{
	unsigned char	*p;
	unsigned char	*dp;
	unsigned char	*s;
	unsigned char	*dlm_data;
	unsigned char	*start;
	size_t		dlm_size = 0;
	int		i;
	int		srsize;
	int		dlsize;
	int		match_size = 0;
	int		brkpt = 0;

	if (cob_exception_code) {
		return;
	}

	if (unstring_offset >= (int)unstring_src->size) {
		return;
	}

	start = unstring_src->data + unstring_offset;
	dlm_data = NULL;
	if (unstring_ndlms == 0) {
		match_size = cob_min_int ((int)COB_FIELD_SIZE (dst),
					  (int)unstring_src->size - unstring_offset);
		cob_memcpy (dst, start, match_size);
		unstring_offset += match_size;
	} else {

		srsize = (int) unstring_src->size;
		s = unstring_src->data + srsize;
		for (p = start; p < s; p++) {
			for (i = 0; i < unstring_ndlms; i++) {
				dlsize = (int) dlm_list[i].uns_dlm.size;
				dp = dlm_list[i].uns_dlm.data;
				if (p + dlsize > s) {
					continue;
				}
				if (!memcmp (p, dp, (size_t)dlsize)) {
					match_size = (int)(p - start);
					cob_memcpy (dst, start, match_size);
					unstring_offset += match_size + dlsize;
					dlm_data = dp;
					dlm_size = dlsize;
					if (dlm_list[i].uns_all) {
						for (p += dlsize; p < s; p += dlsize) {
							if (p + dlsize > s) {
								break;
							}
							if (memcmp (p, dp, (size_t)dlsize)) {
								break;
							}
							unstring_offset += dlsize;
						}
					}
					brkpt = 1;
					break;
				}
			}
#ifdef	I18N_UTF8
			/* I18N_UTF8: No offset arrangement needed also in NATIONAL. */
#else /*!I18N_UTF8*/
			if (COB_FIELD_TYPE (unstring_src) == COB_TYPE_NATIONAL ||
			    COB_FIELD_TYPE (unstring_src) == COB_TYPE_NATIONAL_EDITED) {
				p++;
			}
#endif /*I18N_UTF8*/
			if (brkpt) {
				break;
			}
		}
		if (!brkpt) {
			/* no match */
			match_size = (int)(unstring_src->size - unstring_offset);
			cob_memcpy (dst, start, match_size);
			unstring_offset = (int) unstring_src->size;
			dlm_data = NULL;
		}
	}
	unstring_count++;

	if (dlm) {
		if (dlm_data) {
			cob_memcpy (dlm, dlm_data, (int) dlm_size);
		} else if (COB_FIELD_IS_NUMERIC (dlm)) {
			cob_move (&cob_zero, dlm);
		} else {
			cob_move (&cob_space, dlm);
		}
	}

#ifdef	I18N_UTF8
	/* I18N_UTF8: No offset arrangement needed also in NATIONAL. */
#else /*!I18N_UTF8*/
	if (COB_FIELD_TYPE (unstring_src) == COB_TYPE_NATIONAL ||
	    COB_FIELD_TYPE (unstring_src) == COB_TYPE_NATIONAL_EDITED) {
		match_size /= 2;
	}
#endif /*I18N_UTF8*/

	if (cnt) {
		cob_set_int (cnt, match_size);
	}
}
示例#11
0
void
cob_field_accept (cob_field *f, cob_field *line, cob_field *column,
		  cob_field *fgc, cob_field *bgc, cob_field *scroll,
		  const int attr)
{
	unsigned char	*p;
	unsigned char	*p2; 
	size_t		count;
	int		keyp;
	int		fret;
	int		sline;
	int		scolumn;
	int		cline;
	int		ccolumn;
	int		rightpos;
	int		ateof;
	int		move_char;
	int		prompt_char; 

	/* Initialize the screen. */ 
	if (!cob_screen_initialized) {
		cob_screen_init ();
	}
		
	if (scroll) {
		keyp = cob_get_int (scroll);
		if (attr & COB_SCREEN_SCROLL_DOWN) {
			keyp = -keyp;
		}
		scrollok (stdscr, 1);
		scrl (keyp);
		scrollok (stdscr, 0);
		refresh ();
	}
	cob_exception_code = 0;
	/* Start line and column. */ 
	get_line_column (line, column, &sline, &scolumn);
	move (sline, scolumn);
	cob_screen_attr (fgc, bgc, attr);
	/* Prompt characters. */ 
	p = f->data;
	for (count = 0; count < f->size; count++) {
		if (attr & COB_SCREEN_SECURE) {
			addch ('*');
		} else if (attr & COB_SCREEN_UPDATE) {
			fret = *p++;
			addch ((unsigned int)fret);
		} else if (COB_FIELD_IS_NUMERIC (f)) {
			addch ('0'); 
		} else if (attr & COB_SCREEN_PROMPT) {
			addch ('_');
		} else {
			addch (' ');
		}
	}
	move (sline, scolumn);
	/* Initialize field. */ 
	if (!(attr & COB_SCREEN_UPDATE)) {
		if (COB_FIELD_IS_NUMERIC (f)) {
			cob_move (&cob_zero, f);
		} else {
			memset (f->data, ' ', f->size);
		}
	}

	fret = 0;
	ateof = 0;
	rightpos = scolumn + f->size - 1; 
	p = f->data;
	/* Get characters from keyboard, processing each one. */ 
	for (; ;) {
		/* Get current line, column. */
		getyx (stdscr, cline, ccolumn); 
		/* Trailing prompts. */ 
		if (COB_FIELD_IS_NUMERIC (f)) {
		  prompt_char = '0';
		} else if (attr & COB_SCREEN_PROMPT) {
		  prompt_char = '_';
		} else {
		  prompt_char = ' ';
		}
		for (count = rightpos; count > scolumn - 1; count--) {
		    /* Get character */ 
		    p2 = f->data + count - scolumn;
		    move_char = *p2; 
		    /* Field prompts. */ 
		    if (COB_FIELD_IS_NUMERIC (f)) {
		      /* Numeric prompt zeros. */ 
		      if (move_char == '0') {
			move (cline, count);
			addch (prompt_char); 
		      } else {
			/* Switch to remove prompts from within field. */
			if (attr & COB_SCREEN_SECURE) {
			  prompt_char = '*';
			} else {
			  prompt_char = '0'; 
			}  
		      }
		    } else {
		      /* Alpha prompts. */ 
		      if (move_char == ' ') {
			move (cline, count);
			addch (prompt_char); 
		      } else {
			/* Switch to remove prompts from within field. */
			if (attr & COB_SCREEN_SECURE) {
			  prompt_char = '*';
			} else {
			  prompt_char = ' '; 
			} 
		      }
		    }
		}
		/* Cursor to current column. */ 
		move (cline, ccolumn);
		/* Refresh screen. */ 
		refresh ();
		errno = 0;
		/* Get a character. */
		keyp = getch ();
		/* Key error. */ 
		if (keyp == ERR) {
			fret = 8001;
			goto field_return;
		}
		/* Function keys F1 through F64 */
		if (keyp > KEY_F0 && keyp < KEY_F(65)) {
			fret = 1000 + keyp - KEY_F0;
			goto field_return;
		}

		cob_convert_key (&keyp, 1U);
		if (keyp <= 0) {
			(void)flushinp ();
			beep ();
			continue;
		}
		
		switch (keyp) {
		case KEY_ENTER:
			goto field_return;
		case KEY_PPAGE:
			/* Page up. */ 
			fret = 2001;
			goto field_return;
		case KEY_NPAGE:
			/* Page down. */ 
			fret = 2002;
			goto field_return;
		case KEY_UP:
			/* Up arrow. */ 
			fret = 2003;
			goto field_return;
		case KEY_DOWN:
			/* Down arrow. */ 
			fret = 2004;
			goto field_return;
		case KEY_PRINT:
			/* Print key. */ 
			/* pdcurses not returning this ? */
			fret = 2006;
			goto field_return;
		case 033:
			/* Escape key. */ 
			fret = 2005;
			goto field_return;
		case KEY_STAB:
			/* Tab key. */
			fret = 2007;
			goto field_return;
		case KEY_BTAB:
			/* Back tab key. */ 
			fret = 2008;
			goto field_return; 
		default:
			break;
		}

		getyx (stdscr, cline, ccolumn);
		switch (keyp) {
		case KEY_IC: 
			/* Insert key toggle.  If off turn on, if on turn off. */ 
			if (insert_mode == 0) {
				insert_mode = 1;     /* on */
				/* to do, needs vertical bar cursor */
				/* this doesn't seem to work */ 
				count = curs_set(1); 
			} else {
				insert_mode = 0;     /* off */ 
				/* to do, needs square cursor */ 
				/* this doesn't seem to work */ 
				count = curs_set(2); 
			}
			continue;
		case KEY_DC:
			/* Delete key. */ 
			/* Delete character, move remainder left. */ 
			for (count = ccolumn; count < rightpos; count++) {
				/* Get character one position to right. */
				p2 = f->data + count - scolumn + 1;
				move_char = *p2;
				/* Move the character left. */ 
				p2 = f->data + count - scolumn;
				*p2 = move_char; 
				/* Update screen with moved character. */ 
				move (cline, count); 
				if (attr & COB_SCREEN_SECURE) {
					addch ('*');
				} else {
					addch (move_char); 
				} 
			}
			/* Put space as the right most character. */ 
			p2 = f->data + f->size - 1;  
			if (COB_FIELD_IS_NUMERIC (f)) {
				*p2 = '0';
			} else { 
				*p2 = ' ';
			}
			/* Put cursor back to original position. */ 
			move (cline, ccolumn); 
			continue;
		case KEY_BACKSPACE:
			/* Backspace key. */ 
			if (ccolumn > scolumn) {
			    /* Shift remainder left with cursor. */
			    for (count = ccolumn; count < rightpos + 1; count++) {
				/* Get character. */
				p2 = f->data + count - scolumn ;
				move_char = *p2;
				/* Move the character left. */ 
				p2 = f->data + count - scolumn - 1;
				*p2 = move_char; 
				/* Update screen with moved character. */ 
				move (cline, count - 1); 
				if (attr & COB_SCREEN_SECURE) {
				    addch ('*');
				} else {
				    addch (move_char); 
				} 
			    }
			    /* Put space as the right most character. */ 
			    p2 = f->data + f->size - 1;  
			    if (COB_FIELD_IS_NUMERIC (f)) {
			      *p2 = '0';
			    } else {
			      *p2 = ' ';
			    }
			    /* Move cursor left one from current. */ 
			    ccolumn--;
			    move (cline, ccolumn); 
			    p--; 
			}    
			ateof = 0; 
			continue; 
		case KEY_HOME:
			/* Home key, move to start of field. */
			move (sline, scolumn);
			p = f->data;
			ateof = 0;
			continue;
		case KEY_END:
			/* End key. */ 
			/* Prepare for empty field. */
			ccolumn = scolumn; 
			move_char = ' '; 
			/* Find non blank from right. */ 
			for (count = rightpos; count >= scolumn; count--) { 
				/* Get character */ 
				p2 = f->data + count - scolumn;
				move_char = *p2; 
				/* Non blank stop. */ 
				if (move_char != ' ') {
					ccolumn = count; 
					count = scolumn;
				}
			} 
			/* Cursor to first blank after. */ 
			if (move_char != ' ' && ccolumn != rightpos) {
				ccolumn++; 
			} 
			move (cline, ccolumn); 
			p = f->data + ccolumn - scolumn; 
			ateof = 0;
			continue;
		case KEY_LEFT:
			/* Left arrow. */ 
			if (ccolumn > scolumn) {
				ccolumn--;
				move (cline, ccolumn);
				p = f->data + ccolumn - scolumn;
				continue;
			}
			continue;
		case KEY_RIGHT:
			/* Right arrow. */ 
			if (ccolumn < rightpos) {
				ccolumn++;
				move (cline, ccolumn);
				p = f->data + ccolumn - scolumn;
				continue;
			}
			continue;
		default:
			break;
		}
		
		/* Printable character. */ 
		if (keyp > 037 && keyp < (int)A_CHARTEXT) {
			/* Numeric field check. */
			if (COB_FIELD_IS_NUMERIC (f)) {
				if (keyp < '0' || keyp > '9') {
					beep ();
					continue;
				}
			}
			/* Insert character. */ 
			if (insert_mode == 1) {
				/* Move remainder to the right. */ 
				for (count = rightpos; count > ccolumn - 1; count--) { 
					/* Get character */ 
					p2 = f->data + count - scolumn - 1;
					move_char = *p2; 
					/* Move character one right. */ 
					p2 = f->data + count - scolumn;
					*p2 = move_char;
					/* Update screen with moved character. */ 
					if (count > scolumn) { 
						move (cline, count); 
						if (move_char != ' ') {
							if (attr & COB_SCREEN_SECURE) {
								addch ('*');
							} else {
								addch (move_char); 
							}
						}  
					}  
				}
				move (cline, ccolumn); 
			}
			*p = (unsigned char)keyp;
			/* Display character or '*' if secure. */ 
			if (attr & COB_SCREEN_SECURE) {
				addch ('*');
			} else {
				addch ((unsigned int)keyp);
			}
			if (ccolumn == rightpos) {
				/* Auto-skip at end of field. */
				if (attr & COB_SCREEN_AUTO) {
					break;
				}
				move (cline, ccolumn);
				if (ateof) {
					beep ();
				} else {
					ateof = 1;
				}
			} else {
				p++;
			}
			continue;
		}
		beep ();
	}
field_return:
	refresh ();
	cob_check_pos_status (fret);
}