File: io-curses.c

package info (click to toggle)
oleo 1.6-16
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,640 kB
  • ctags: 3,139
  • sloc: ansic: 39,221; yacc: 1,737; sh: 362; makefile: 88
file content (1004 lines) | stat: -rw-r--r-- 18,839 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
/*	Copyright (C) 1992, 1993 Free Software Foundation, Inc.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this software; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "proto.h"
#include "funcdef.h"
#include <stdio.h>
#include <curses.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
#undef NULL
#include "sysdef.h"
#include "global.h"
#include "cell.h"
#include "cmd.h"
#include "line.h"
#include "io-generic.h"
#include "io-edit.h"
#include "io-term.h"
#include "io-abstract.h"
#include "io-utils.h"
#include "lists.h"
#include "regions.h"
#include "window.h"
#include "key.h"
#include "input.h"
#include "info.h"

#define MIN_WIN_HEIGHT	(cwin->flags&WIN_EDGES ? 2 : 1)
#define MIN_WIN_WIDTH	(cwin->flags&WIN_EDGES ? 6 : 1)

static int redrew = 0;
static int textout = 0;
static int term_cursor_claimed = 0;

static void move_cursor_to (struct window *, CELLREF, CELLREF, int);


static int
curses_metric (char * str, int len)
{
  return len;
}

static struct input_view input_view
  = {0, curses_metric, curses_metric, 0, 0, 0, 0, 0, 0, 0, 0, 0};

static void
_io_redraw_input (void)
{
  int pos;
  int row = (input_view.current_info ? 0 : input);

  if (input_view.info_redraw_needed)
    {
      input_view.info_redraw_needed = 0;
      io_repaint ();
      return;
    }

  if (input_view.redraw_needed == NO_REDRAW)
    return;

  if (input_view.redraw_needed == FULL_REDRAW)
    {
      /* Redraw	the prompt. */ 
      move (row, 0);
      if (input_view.expanded_keymap_prompt)
	{
	  addstr (input_view.expanded_keymap_prompt);
	  clrtoeol ();
	  input_view.redraw_needed = NO_REDRAW;
	  return;
	}
      if (input_view.prompt_wid)
	addstr (input_view.prompt);
      pos = input_view.visibility_begin;
    }
  else
    {
      pos = input_view.redraw_needed;
      move (row,
	    input_view.prompt_wid + pos - input_view.visibility_begin);
    }
    
  if (   input_view.input_area
      && (input_view.visibility_end >= input_view.visibility_begin)
      && (input_view.visibility_begin < strlen (input_view.input_area->buf)))
    {
      int x;
      for (x = pos; x <= input_view.visibility_end; ++x)
	addch (input_view.input_area->buf[x]);
    }
  clrtoeol ();
  input_view.redraw_needed = NO_REDRAW;
}


#undef MIN
#define MIN(A,B) (((A) < (B)) ? (A) : (B))

void
redraw_info (void)
{
  if (!input_view.current_info)
    return;
  {
    int ipos = input_view.info_pos;
    int stop = MIN (input_view.current_info->len, scr_lines - 1 + ipos);
    while (ipos < stop)
      {
	move (1 + ipos - input_view.info_pos, 0);
	addstr (input_view.current_info->text[ipos]);
	clrtoeol ();
	++ipos;
      }
  }
  _io_redraw_input ();
}


static void
_io_fix_input (void)
{
  iv_fix_input (&input_view);
}

static void
_io_move_cursor (void)
{
  iv_move_cursor (&input_view);
}

static void
_io_erase (int len)
{
  iv_erase (&input_view, len);
}

static void
_io_insert (int len)
{
  iv_insert (&input_view, len);
}
	   
static void
_io_over (char * str, int len)
{
  iv_over (&input_view, len);
}





static void 
_io_display_cell_cursor (void)
{
  int cell_cursor_row;
  int cell_cursor_col;
  int cc;
  int rr;
  int cwid;
  int n;
  int x, y;

  if (input_view.current_info)
    return;

  if (   (curow < cwin->screen.lr)
      || (cucol < cwin->screen.lc)
      || (curow > cwin->screen.hr)
      || (cucol > cwin->screen.hc))
    return;

  getyx (stdscr, y, x);
  cell_cursor_col = cwin->win_over;
  for (cc = cwin->screen.lc; cc < cucol; cc++)
    cell_cursor_col += get_width (cc);
  cell_cursor_row = cwin->win_down;
  for (rr = cwin->screen.lr; rr < curow; rr++)
    cell_cursor_row += get_height (rr);
  cwid = get_width (cucol);
  if (cwid > cwin->numc)
    cwid = cwin->numc;
  move (cell_cursor_row, cell_cursor_col);
  standout ();
  for (n = cwid; n; n--)
#ifdef A_STANDOUT
    addch (inch () | A_STANDOUT);
#else
    addch (inch ());
#endif
  standend ();
  move (y, x);
}

static void 
_io_hide_cell_cursor (void)
{
  int cc;
  int rr;
  int cell_cursor_row;
  int cell_cursor_col;
  int cwid;
  int n;
  int x, y;

  if (input_view.current_info)
    return;
  if (   (curow < cwin->screen.lr)
      || (cucol < cwin->screen.lc)
      || (curow > cwin->screen.hr)
      || (cucol > cwin->screen.hc))
    return;
  getyx (stdscr, y, x);
  cell_cursor_col = cwin->win_over;
  for (cc = cwin->screen.lc; cc < cucol; cc++)
    cell_cursor_col += get_width (cc);
  cell_cursor_row = cwin->win_down;
  for (rr = cwin->screen.lr; rr < curow; rr++)
    cell_cursor_row += get_height (rr);
  cwid = get_width (cucol);
  if (cwid > cwin->numc)
    cwid = cwin->numc;
  move (cell_cursor_row, cell_cursor_col);
  for (n = cwid; n; n--)
#ifdef A_STANDOUT
    addch (inch () & ~A_STANDOUT);
#else
    addch (inch ());
#endif
  move (y, x);
}



/* Functions, etc for dealing with cell contents being displayed
	on top of other cells. */

struct slops
{
  int s_alloc, s_used;
  struct s
    {
      CELLREF row, clo, chi;
    } s_b[1];
};

static void 
flush_slops (VOIDSTAR where)
{
  struct slops *s;

  s = where;
  if (s)
    s->s_used = 0;
}

static int 
find_slop (VOIDSTAR where, CELLREF r, CELLREF c, CELLREF *cclp, CELLREF *cchp)
{
  int n;
  struct slops *s;

  s = where;
  if (!s)
    return 0;
  for (n = 0; n < s->s_used; n++)
    {
      if (s->s_b[n].row == r && s->s_b[n].clo <= c && s->s_b[n].chi >= c)
	{
	  *cclp = s->s_b[n].clo;
	  *cchp = s->s_b[n].chi;
	  return 1;
	}
    }
  return 0;
}

static void 
kill_slop (VOIDSTAR where, CELLREF r, CELLREF clo, CELLREF chi)
{
  int n;
  struct slops *s;

  s = where;
  for (n = 0; n < s->s_used; n++)
    {
      if (s->s_b[n].row == r && s->s_b[n].clo == clo && s->s_b[n].chi == chi)
	{
	  --(s->s_used);
	  s->s_b[n] = s->s_b[s->s_used];
	  return;
	}
    }
}

static void 
set_slop (VOIDSTAR *wherep, CELLREF r, CELLREF clo, CELLREF chi)
{
  int n;
  struct slops **sp;

  sp = (struct slops **) wherep;
  if (!*sp)
    {
      (*sp) = ck_malloc (sizeof (struct slops) + 2 * sizeof (struct s));
      (*sp)->s_alloc = 2;
      (*sp)->s_used = 1;
      n = 0;
    }
  else
    {
      n = (*sp)->s_used++;
      if ((*sp)->s_alloc == n)
	{
	  (*sp)->s_alloc = n * 2;
	  (*sp) = ck_realloc ((*sp), sizeof (struct slops) + n * 2 * sizeof (struct s));
	}
    }
  (*sp)->s_b[n].row = r;
  (*sp)->s_b[n].clo = clo;
  (*sp)->s_b[n].chi = chi;
}

static void 
change_slop (VOIDSTAR where,
	     CELLREF r, CELLREF olo, CELLREF ohi, CELLREF lo, CELLREF hi)
{
  int n;
  struct slops *s;

  s = where;
  for (n = 0; n < s->s_used; n++)
    {
      if (s->s_b[n].row == r && s->s_b[n].clo == olo && s->s_b[n].chi == ohi)
	{
	  s->s_b[n].clo = lo;
	  s->s_b[n].chi = hi;
	  return;
	}
    }
}


static void 
_io_open_display (void)
{
  initscr ();
  scrollok (stdscr, 0);
#ifdef HAVE_CBREAK
  cbreak ();
#else
  crmode ();
#endif
  raw ();
  noecho ();
  nonl ();
  /* Must be after initscr() */
  io_init_windows (LINES, COLS - 1, 1, 2, 1, 1, 1, 1);
  info_rows = 1;
  print_width = COLS;		/* Make ascii print width == terminal width. */
}

void
cont_curses(void)
{
#ifdef HAVE_CBREAK
  cbreak ();
#else
  crmode ();
#endif
  raw ();
  noecho ();
  nonl ();
}


void
stop_curses(void)
{
#ifdef HAVE_CBREAK
  nocbreak ();
#else
  nocrmode ();
#endif
  noraw ();
  echo ();
  nl ();
  io_redisp ();
}

static void 
_io_cellize_cursor (void)
{
}

static void 
_io_inputize_cursor (void)
{
}

static void 
_io_redisp (void)
{
  if (!term_cursor_claimed)
    {
      _io_redraw_input ();
      if (!(input_view.current_info || input_active ||
	    input_view.expanded_keymap_prompt))
	move_cursor_to (cwin, curow, cucol, 0);
      else
	move ((input_view.current_info ? 0 : input), 
	      input_view.prompt_wid + input_view.input_cursor -
	      input_view.visibility_begin); 
    }
  {
    struct rng * rng = &cwin->screen;
    if (   (curow > rng->hr)
	|| (curow < rng->lr)
	|| (cucol > rng->hc)
	|| (cucol < rng->lc))
      io_recenter_cur_win ();
  }
  refresh ();
}

static void 
_io_repaint_win (struct window *win)
{
  io_repaint ();
}

static void 
_io_repaint (void)
{
  CELLREF cc, rr;
  int n, n1;
  CELL *cp;
  struct window *win;

  clear ();
  io_fix_input ();
  redrew++;
  if (input_view.current_info)
    {
      redraw_info ();
      input_view.redraw_needed = FULL_REDRAW;
      _io_redraw_input ();
      return;
    }

  for (win = wins; win < &wins[nwin]; win++)
    {
      if (win->lh_wid)
	{
	  move (win->win_down - 1, win->win_over - win->lh_wid);
	  printw ("#%*d ", win->lh_wid - 2, 1 + win - wins);
	  if (win->flags & WIN_EDGE_REV)
	    standout ();
	  cc = win->screen.lc;
	  do
	    {
	      n = get_width (cc);
	      if (n > win->numc)
		n = win->numc;
	      if (n > 1)
		{
		  char *ptr;
		  char buf[30];

		  if (a0)
		    ptr = col_to_str (cc);
		  else
		    {
		      sprintf (buf, "C%u", cc);
		      ptr = buf;
		    }
		  --n;
		  n1 = strlen (ptr);
		  if (n < n1)
		    printw ("%.*s ", n, "###############");
		  else
		    {
		      n1 = (n - n1) / 2;
		      printw ("%*s%-*s ", n1, "", n - n1, ptr);
		    }
		}
	      else if (n == 1)
		addstr ("#");
	    }
	  while (cc++ < win->screen.hc);

	  rr = win->screen.lr;
	  n = win->win_down;
	  do
	    {
	      n1 = get_height (rr);
	      if (n1)
		{
		  move (n, win->win_over - win->lh_wid);
		  if (a0)
		    printw ("%-*d ", win->lh_wid - 1, rr);
		  else
		    printw ("R%-*d", win->lh_wid - 1, rr);
		  n += n1;
		}
	    }
	  while (rr++ < win->screen.hr);

	  if (win->flags & WIN_EDGE_REV)
	    standend ();
	}
      flush_slops (win->win_slops);
      find_cells_in_range (&(win->screen));
      while (cp = next_row_col_in_range (&rr, &cc))
	if (GET_TYP (cp))
	  io_pr_cell_win (win, rr, cc, cp);
    }
  if (!(cp = find_cell (curow, cucol)) || !GET_TYP (cp))
    io_display_cell_cursor ();
  input_view.redraw_needed = FULL_REDRAW;
  _io_redraw_input ();
  io_update_status ();
}

static void 
_io_close_display (void)
{
  clear ();
  refresh ();
  (void) endwin ();
}

static int 
_io_input_avail (void)
{
  return (FD_ISSET (0, &read_pending_fd_set)
	  || FD_ISSET (0, &exception_pending_fd_set));
}

static void 
_io_scan_for_input (int block)
{
  /* This function only exists because X kbd events don't generate */
  /* SIGIO. Under curses, the SIGIO hander does the work of this */
  /* function. */
}

static void 
_io_wait_for_input (void)
{
  pause ();
}

static int 
_io_read_kbd (volatile char *buf, int size)
{
  int r = read (0, buf, size);
  FD_CLR (0, &read_pending_fd_set);
  FD_CLR (0, &exception_pending_fd_set);
  return r;
}


#if defined(SIGIO)


static void 
_io_nodelay (int delayp)
{
  panic ("Trying to curses nodelay on a system with SIGIO.");
}

#else

static void 
_io_nodelay (int delayp)
{
  nodelay (stdscr, delayp);
}

#endif

static int 
_io_getch (void)
{
  char ch;
  return ((io_read_kbd (&ch, 1) != 1)
	  ? EOF
	  : ch);
}


static int 
_io_get_chr (char *prompt)
{
  int x;
  mvaddstr (input, 0, prompt);
  clrtoeol ();
  topclear = 2;
  refresh ();
  ++term_cursor_claimed;
  x = get_chr ();
  --term_cursor_claimed;
  return x;
}

#define BUFFER 10

static void 
local_putchar (int ch)
{
  (void) putc (ch, stdout);
  /* (void)putchar(ch); */
}

static void
local_puts (char *s)
{
   (void) tputs (s, 1, (int (*)()) local_putchar);
}

static void 
_io_bell (void)
{
#ifndef HAVE_GETCAP
  putchar ('\007');
#else
  static char *vb;
  static int called = 0;

  if (!called)
    {
      called++;
      vb = getcap ("vb");
    }
  if (vb)
    {
      local_puts (vb);
    }
  else
    {
      local_putchar ('\007');
    }
#endif
}


static void
move_cursor_to (struct window *win, CELLREF r, CELLREF c, int dn)
{
  int cc;
  int cell_cursor_col;
  int rr;
  int cell_cursor_row;
  
  cell_cursor_col = win->win_over;
  for (cc = win->screen.lc; cc < c; cc++)
    cell_cursor_col += get_width (cc);
  cell_cursor_row = win->win_down + dn;
  for (rr = win->screen.lr; rr < r; rr++)
    cell_cursor_row += get_height (rr);
  move (cell_cursor_row, cell_cursor_col);
}

static void
_io_update_status (void)
{
  CELL *cp;
  char *dec;
  char *ptr;
  static char hmbuf[40];
  int wid;
  int plen;
  int dlen;
  int yy, xx;
  
  if (!user_status || input_view.current_info)
    return;
  getyx (stdscr, yy, xx);
  move (status, 0);
  wid = COLS - 2;
  
  if (mkrow != NON_ROW)
    {
      struct rng r;
      
      addch ('*');
      --wid;
      set_rng (&r, curow, cucol, mkrow, mkcol);
      ptr = range_name (&r);
    }
  else
    ptr = cell_name (curow, cucol);
  
  addstr (ptr);
  wid -= strlen (ptr);
  
  if (how_many != 1)
    {
      sprintf (hmbuf, " {%d}", how_many);
      addstr (hmbuf);
      wid -= strlen (hmbuf);
    }
  
  if ((cp = find_cell (curow, cucol)) && cp->cell_formula)
    {
      dec = decomp (curow, cucol, cp);
      dlen = strlen (dec);
    }
  else
    {
      dec = 0;
      dlen = 0;
    }
  
  ptr = cell_value_string (curow, cucol);
  plen = strlen (ptr);
  
  if (dec)
    {
      wid -= 4;
      if (dlen + plen > wid)
	{
	  if (plen + 3 > wid)
	    printw (" %.*s... [...]", wid - 6, ptr);
	  else
	    printw (" %s [%.*s...]", ptr, wid - plen - 3, dec);
	}
      else
	printw (" %s [%s]", ptr, dec);
      decomp_free ();
    }
  else if (plen)
    {
      --wid;
      if (plen > wid)
	printw (" %.*s...", wid - 3, ptr);
      else
	printw (" %s", ptr);
    }
  
  clrtoeol ();
  move (yy, xx);
}

extern int auto_recalc;

static void
_io_clear_input_before (void)
{
  textout = 0;
  if (topclear == 2)
    {
      move (input, 0);
      clrtoeol ();
      topclear = 0;
    }
  move (0, 0);
}

static void
_io_clear_input_after (void)
{
  if (topclear)
    {
      move (input, 0);
      clrtoeol ();
      topclear = 0;
    }
}


static void
_io_pr_cell_win (struct window *win, CELLREF r, CELLREF c, CELL *cp)
{
  int glowing;
  int lenstr;
  int j;
  int wid, wwid;
  int hgt;
  char *ptr;
  int yy, xx;
  
  if (input_view.current_info)
    return;

  wid = get_width (c);
  if (!wid)
    return;
  if (wid > win->numc)
    wid = win->numc;
  hgt = get_height (r);
  if (!hgt)
    return;
  if (hgt > win->numr)
    hgt = win->numr;
  
  getyx (stdscr, yy, xx);
  glowing = (r == curow && c == cucol && win == cwin);
  ptr = print_cell (cp);
  move_cursor_to (win, r, c, 0);
  if (glowing)
    standout ();
  j = GET_JST (cp);
  if (j == JST_DEF)
    j = default_jst;
  lenstr = strlen (ptr);
  
  if (lenstr <= wid - 1)
    {
      CELLREF ccl, cch;
      
      if (j == JST_LFT)
	printw ("%-*.*s", wid, wid - 1, ptr);
      else if (j == JST_RGT)
	printw ("%*.*s ", wid - 1, wid - 1, ptr);
      else if (j == JST_CNT)
	{
	  wwid = (wid - 1) - lenstr;
	  printw ("%*s%*s ", (wwid + 1) / 2 + lenstr, ptr, wwid / 2, "");
	}
#ifdef TEST
      else
	panic ("Unknown justification");
#endif
      if (glowing)
	standend ();
      
      if (lenstr == 0 && c > win->screen.lc
	  && find_slop (win->win_slops, r, c - 1, &ccl, &cch))
	{
	  CELLREF ccdl, ccdh;
	  
	  if (find_slop (win->win_slops, r, c, &ccdl, &ccdh) && ccdl == c)
	    {
	      kill_slop (win->win_slops, r, ccdl, ccdh);
	      for (; ccdh != ccdl; --ccdh)
		if (ccdh != c && (wwid = get_width (ccdh)))
		  {
		    move_cursor_to (win, r, ccdh, 0);
		    printw ("%*s", wwid, "");
		  }
	    }
	  kill_slop (win->win_slops, r, ccl, cch);
	  io_pr_cell (r, ccl, find_cell (r, ccl));
	}
      else if (find_slop (win->win_slops, r, c, &ccl, &cch))
	{
	  kill_slop (win->win_slops, r, ccl, cch);
	  for (; cch != ccl; --cch)
	    if (cch != c && (wwid = get_width (cch)))
	      {
		move_cursor_to (win, r, cch, 0);
		printw ("%*s", wwid, "");
	      }
	  io_pr_cell (r, ccl, find_cell (r, ccl));
	}
    }
  else
    {
      CELLREF cc = c;
      CELL *ccp;
      CELLREF ccl, cch;
      
      for (wwid = wid; lenstr > wwid - 1; wwid += get_width (cc))
	{
	  if (++cc > win->screen.hc
	      || ((ccp = find_cell (r, cc))
		  && GET_TYP (ccp)
		  && (GET_FMT (ccp) != FMT_HID
		      || (GET_FMT (ccp) == FMT_DEF
			  && default_fmt != FMT_HID))))
	    {
	      --cc;
	      break;
	    }
	}
      
      if (lenstr > wwid - 1)
	if (GET_TYP (cp) == TYP_FLT)
	  ptr = adjust_prc (ptr, cp, wwid - 1, wid - 1, j);
	else if (GET_TYP (cp) == TYP_INT)
	  ptr = (char *) numb_oflo;
      
      if (wwid == 1)
	{
	  addch (' ');
	  if (glowing)
	    standend ();
	}
      else if (wwid == wid)
	{
	  printw ("%-*.*s ", wwid - 1, wwid - 1, ptr);
	  if (glowing)
	    standend ();
	}
      else if (glowing)
	{
	  printw ("%.*s", wid, ptr);
	  standend ();
	  printw ("%-*.*s ", wwid - wid - 1, wwid - wid - 1, ptr + wid);
	}
      else if (r == curow && (cucol > c && cucol <= cc))
	{
	  CELLREF ctmp;
	  int w_left;
	  int w_here;
	  
	  w_left = wid;
	  for (ctmp = c + 1; ctmp < cucol; ctmp++)
	    w_left += get_width (ctmp);
	  printw ("%.*s", w_left, ptr);
	  standout ();
	  w_here = get_width (cucol);
	  if (wwid > w_left + w_here)
	    {
	      printw ("%-*.*s", w_here, w_here, ptr + w_left);
	      standend ();
	      printw ("%-*.*s ",
		      wwid - (w_left + w_here) - 1, wwid - (w_left + w_here) - 1,
		      ptr + w_left + w_here);
	    }
	  else
	    {
	      printw ("%-*.*s", w_here, w_here - 1, ptr + w_left);
	      standend ();
	    }
	}
      else
	printw ("%-*.*s ", wwid - 1, wwid - 1, ptr);
      
      if (find_slop (win->win_slops, r, c, &ccl, &cch))
	{
	  change_slop (win->win_slops, r, ccl, cch, c, cc);
	  for (; cch > cc; --cch)
	    if (wwid = get_width (cch))
	      {
		move_cursor_to (win, r, cch, 0);
		printw ("%*s", wwid, "");
	      }
	  for (cch = c - 1; cch > ccl; --cch)
	    if (wwid = get_width (cch))
	      {
		move_cursor_to (win, r, cch, 0);
		printw ("%*s", wwid, "");
	      }
	  if (ccl != c)
	    io_pr_cell (r, ccl, find_cell (r, ccl));
	}
      else
	set_slop ((VOIDSTAR *) (&(win->win_slops)), r, c, cc);
    }
  if ((hgt > 1) && display_formula_mode)
    {
      move_cursor_to (win, r, c, 1);
      ptr = decomp (r, c, cp);
      printw ("%.*s ", wid - 1, ptr);
      decomp_free ();
    }
  if (glowing)
    io_update_status ();
  move (yy, xx);
}



static void
_io_flush (void)
{
  refresh ();
}




void
tty_graphics (void)
{

  FD_SET (0, &read_fd_set);
  FD_SET (0, &exception_fd_set);
  IO_SETUP;
}