File: UI.c

package info (click to toggle)
floater 1.2b1-6
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 1,612 kB
  • ctags: 1,822
  • sloc: ansic: 16,755; tcl: 4,034; sh: 1,291; makefile: 129
file content (1294 lines) | stat: -rw-r--r-- 39,648 bytes parent folder | download
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
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
/* Copyright (c) 1996--1999 Geoff Pike. */
/* All rights reserved. */

/* Floater 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. */

/* This software is provided "as is" and comes with absolutely no */
/* warranties.  Geoff Pike is not liable for damages under any */
/* circumstances.  Support is not provided.  Use at your own risk. */

/* Personal, non-commercial use is allowed.  Attempting to make money */
/* from Floater or products or code derived from Floater is not allowed */
/* without prior written consent from Geoff Pike.  Anything that remotely */
/* involves commercialism, including (but not limited to) systems that */
/* show advertisements while being used and systems that collect */
/* information on users that is later sold or traded require prior */
/* written consent from Geoff Pike. */
#include "floater.h"
#include "tickler.h"
#include "comm.h"
#include "deal.h"
#include "br.h"

bool myturntoact = FALSE;

char *vulnames[4] = {"EW vul.", "None vul.", "Both vul.", "NS vul."};
char *passnames[3] = {"Pass Left", "Pass Right", "No Pass"};

extern int state;
extern bool tablehostmode;
extern char *northname, *southname, *eastname, *westname;
extern char *curhandID;

#define startshowtricktimer() TclDo("startshowtricktimer")

#define needAuctionUpdate() \
    (atob(TclGet("needAuctionUpdate")) ? \
     (TclSet("needAuctionUpdate", "0"), TRUE) : FALSE)

#define TUIclearmatrix() { textrefresh(); TclDo("erasebidplay all"); }
#define TUIdelayedclearmatrix() { textrefresh(); TclDo("delayedclearmatrix"); }
#define GUIclearmatrix() TclDo("erasebidplay all")
#define GUIdelayedclearmatrix() TclDo("after 5000 erasebidplay all")
#define UIclearmatrix() { if (hasWindows) { GUIclearmatrix(); } \
  else { TUIclearmatrix(); } }
#define UIdelayedclearmatrix() { if (hasWindows) { GUIdelayedclearmatrix(); } \
  else { TUIdelayedclearmatrix(); } }
#define TUIredrawmatrixcards()
#define GUIredrawmatrixcards() TclDo("redrawmatrixcards")
#define UIredrawmatrixcards() { if (hasWindows) { GUIredrawmatrixcards(); } \
  else { TUIredrawmatrixcards(); } }

#define force_update() \
	{ if (hasWindows) TclDo("update idletasks"); else textrefresh(); }

#define startMyTurnTimer() (hasWindows ? TclDo("startMyTurnTimer") : 0)
#define stopMyTurnTimer() (hasWindows ? TclDo("stopMyTurnTimer") : 0)

#define removecardfromhand(play) TclDo2("removecardfromhand ", (play))
#define togglepassedcard(play) TclDo3("catch {togglepassedcard ", (play), "}")

#define nodeal() \
	TclDo("fulldeal {} {} {} {} {} {} {} {} {} {} {} {} {} {} {} {}")
#define noauction() UIauction(FALSE, FALSE, FALSE)

/* clear the frames/labels showing the auction */
#define newauction() TclDo("newauction")

/* Hide the auction after this many cards have been played. */
#define HIDE_AUCTION 4

/* If negative, hide auction after HIDE_AUCTION cards; otherwise hide
   auction this many seconds after the final pass. */
float auction_hide_time; /* initial value taken from Tcl var of same name */
static bool auction_hide_time_inited = FALSE;
#define init_auction_hide_time()				\
    ((auction_hide_time = atof(TclGet("auction_hide_time"))),	\
     (auction_hide_time_inited = TRUE))

void UIwrongpassword(void)
{
  status("Wrong password"); /*here*/
}

void UInameinuse(void)
{
  status("That name is not available; you are not logged in; please try again"); /*here*/
}

/****************************************************************************/

void GUIinsertTalk(char *s)
{
  assert(hasWindows);
  TclDo3(".cmd.talk insert end {", s, "}");
}

void GUIinsertCmd(char *s)
{
  assert(hasWindows);
  TclDo3(".cmd.cmdline insert end {", s, "}");
}

/*****************************************************************************
Drawing the auction, the hands, and on and on
*****************************************************************************/

/* a `column', e.g. declarercolumn, is an integer from 0 to 3:
   3 means me, 0 means lho, 1 means partner, 2 means rho */

/* a `seat' is an integer meaning North, South, East, or West
   (see deal.h -- North is 0, East is 1, ... ) */

bool spec = FALSE;
static int disnumplayers;
semistatic bool kibitzing1 = FALSE; /* are we kibitzing one person only? */
semistatic int kibitzingseat; /* the one person we are kibitzing */

semistatic char displayhandID[100] = {'\0'}; /* the hand we're watching */
semistatic char displayhandname[100] = {'\0'}; /* the hand we're watching */
semistatic char statushandvul[100] = {'\0'}; /* the vulnerability */
semistatic char statusscore[100] = {'\0'}; /* the state of the score */
semistatic char statushanddlr[100] = {'\0'}; /* the dealer */

semistatic char displayhandastate[1000]; /* state of the auction */
semistatic char displayhandpstate[200]; /* state of the play */
semistatic char displayhandpassstate[100]; /* state of the pass at hearts */
semistatic int displaypov = -1; /* point of view---what seat is drawn at the bottom */

#if 0
static int displayhandtrick; /* what trick we're looking at */
static int displayhandround; /* what round of the auction we're looking at */
#endif

semistatic bool displaydoubledummy = FALSE;
semistatic int displayhandscoring;

/* the hand we're displaying---if not NULL at least one hand is being shown */
semistatic int *displaydeck = NULL;

static bool displayinghearts = FALSE;
static bool displayingrubber = FALSE;
semistatic int dealercolumn = -1; /* in the display of the auction */
semistatic int displaycalls;
semistatic int displayplays;
semistatic bool displayseated = FALSE;
semistatic bool displayshowbuttonbar = FALSE;
semistatic char statustolead[100] = {'\0'};
semistatic char statuscontract[100] = {'\0'};
semistatic char statusresult[100] = {'\0'};
semistatic char statusclaim[100] = {'\0'};
semistatic char displaycontract[100] = {'\0'};
semistatic char displaytrickswon[100] = {'\0'};
semistatic int leadercolumn = -1; /* who led this trick (by column) */
semistatic int declarercolumn = -1; /* who is declarer (by column) */
semistatic int displaytrump = -1;
semistatic bool displayhandisover = FALSE;

/* rubber bridge stuff */
static bool disnsvul, disewvul;
static int disnstotal, disewtotal, disnsbelowline, disewbelowline;

/* hearts stuff */
static int nscore, escore, sscore;

/* are we keeping up to date with what's going on at the table? */
bool caughtup = TRUE;

#define southcards(b) ((b) ? handto4str(displaydeck, South) : "{} {} {} {} ")
#define northcards(b) ((b) ? handto4str(displaydeck, North) : "{} {} {} {} ")
#define eastcards(b) ((b) ? handto4str(displaydeck, East) : "{} {} {} {} ")
#define westcards(b) ((b) ? (disnumplayers == 3 ? "{} {} {} {2} " : \
			     handto4str(displaydeck, West)) : "{} {} {} {} ")

/* enter "spectator" mode */
void UIspec(void)
{
  if (seated && declarercolumn != 1) {
    errormsg("Players can't enter spectator mode (except dummy)");
#if DBGu
    errormsg2("declarercolumn = ", itoa(declarercolumn));
#endif
    return;
  }
  spec = TRUE;
}

/* what's on the status line? */
static char *statusline(void)
{
  if (hasWindows) 
    return TclDo(".stat configure -text");
  else
    return TclGet("statusline");
}

void UItablehost(void)
{
  extern int newscoremethod; /* from br.c */

  if (hasWindows) {
    dTclDo5("menus_tablehost ", tablehostmode ? "1 " : "0 ",
	    ((newscoremethod >= 0) ?
	     scoringmethods[newscoremethod].scoringname :
	     ((scoremethod >= 0) ?
	      scoringmethods[scoremethod].scoringname :
	      "x")),
	    " ", new_competitive ? "Competitive" : "Noncompetitive");
  }
}

void UIstate(int state)
{
  if (hasWindows)
    if (state == CONNECTED) {
      TclDo("activate_table_menus 1");
      if (tablehostmode) UItablehost();
    } else TclDo("activate_table_menus 0");
}

/****************************************************************************
UItogglepasscard(), UIpassset(), and UIheartshandover() are for hearts.
****************************************************************************/

/* Toggle screen highlight that indicates whether a card is in the pass set. */
void UItogglepassedcard(char *p)
{
  char t[] = {p[0], ' ', p[1], '\0'};
  togglepassedcard(t);
}

/* Update the passset on the status line. */
void UIpassset(char *t)
{
  char *s = upcase(t);

  switch (strlen(s)) {
  case 6:
    sprintf(statustolead, "Pass set: %c%c %c%c %c%c",
	    s[0], s[1], s[2], s[3], s[4], s[5]);
    break;
  case 4:
    sprintf(statustolead, "Pass set: %c%c %c%c",
	    s[0], s[1], s[2], s[3]);
    break;
  case 2:
    sprintf(statustolead, "Pass set: %c%c",
	    s[0], s[1]);
    break;
  case 0:
    sprintf(statustolead, "");
    break;
  default:
    assert(0);
  }
}

/* Remove the pass direction for the status line and update the scores. */
void UIheartshandover(int ns, int es, int ss)
{
  strcpy(statushandvul, "");
  sprintf(statusscore, "N: %d; E: %d; S: %d",
	  nscore = ns, escore = es, sscore = ss);
}
/****************************************************************************/

void UIsetstatusline(void)
{
  extern char *bridgestatus; /* from br.c */
  char connstat[200] = { '\0' };
#ifdef SERVER
  static bool inited = FALSE;
#endif

  /* If we're at a table, the status line and info line will info
     about the current hand, etc.  Otherwise, do what is below. */
  switch (state) {
  case LIMBO:
    strcpy(connstat, tablehostmode ? "Hosting" : "Not at a table");
    break;
  case DISCONNECTING:
    strcpy(connstat, "Disconnecting...");
    break;
  case CONNECTED:
    if (streq(statusline(), "") || bridgestatus == NULL ||
	strlen(bridgestatus) == 0) {
#ifdef LOGINSERVER
      strcpy(connstat, "Login server");
      if (!inited) {
	TclDo("catch {wm title . {login server}}");
	TclDo("catch {wm iconname . {Login server}}");
	inited = TRUE;
      }
#endif
#ifdef RESULTSERVER
      strcpy(connstat, "Result server");
      if (!inited) {
	TclDo("catch {wm title . {result server}}");
	TclDo("catch {wm iconname . {Result server}}");
	inited = TRUE;
      }
#endif
#ifdef PSEUDOMAILER
      strcpy(connstat, "Pseudomailer");
      if (!inited) {
	TclDo("catch {wm title . {pseudomailer}}");
	TclDo("catch {wm iconname . {pseudomailer}}");
	inited = TRUE;
      }
#endif
#ifndef SERVER
      strcpy(connstat, tablehostmode ? "Hosting" : "Connected");
#endif
    }
  }

#if !SILENT
  if (!hasWindows) {
    update_statusbar();
    draw_on_matrix_screen();
    TclDo3("connstat {", connstat, "}");
    TclDo3("displayhandname {", displayhandname, "}");
    TclDo3("statushandvul {", statushandvul, "}");
    if (!displayinghearts) {
      TclDo3("statushanddlr {", statushanddlr, "}");
      TclDo3("statuscontract {", statuscontract, "}");
    }
    TclDo3("statustolead {", statustolead, "}");
    TclDo3("displaytrickswon {", displaytrickswon, "}");
    TclDo3("statusclaim {", statusclaim, "}");
    TclDo3("statusresult {", statusresult, "}");
    TclDo3("statusscore {", statusscore, "}");
    move_to_curyx();
  } else {
#define appendifexists(s)				\
    {							\
      if (strlen(connstat) > 0 && strlen(s) > 0)	\
	strcat(connstat, "; ");				\
      strcat(connstat, s);				\
    }
						      
    appendifexists(displayhandname);
    appendifexists(statushandvul);
    if (!displayinghearts) {
      appendifexists(statushanddlr);
      appendifexists(statuscontract);
    }
    setstatusline(connstat);
    connstat[0] = '\0';
    appendifexists(statusscore);
    appendifexists(statustolead);
    appendifexists(displaytrickswon);
    appendifexists(statusclaim);
    appendifexists(statusresult);
    {
      char *temp = display_of_previous_trick();

      if (strexists(temp)) appendifexists(temp);
    }
    setinfoline(connstat);
#undef appendifexists
  }
#endif /* !SILENT */
}

static void snafflesuit(int *hand, int suit, char *dest)
{
  int i;

  i = 0;
  while (i < cardsperhand && whatsuit(hand[i]) > suit) i++;
  while (i < cardsperhand && whatsuit(hand[i]) == suit) {
/*
   extern bool cardmember(char *card, char *cards);
   char card[3];
    sprintf(card, "%c%c", tolower(suit_to_char(suit)),
	    tolower(card_to_char[whatcard(hand[i])])); 
    if (!cardmember(card, displayhandpstate)) 
*/
    *dest++ = card_to_char[whatcard(hand[i])];
    i++;
  }
  *dest = '\0';
}

/* convert a hand into something of the form "{AKQJ} {AKQJ} {AKQJ} {4} " */
static char *handto4str(int *deck, int player)
{
  char s[100];
  int i;

  s[0] = '\0';
  SUITLOOP(i) {
    sprintf(s + strlen(s), "{");
    snafflesuit(deck + cardsperhand * player, i, s + strlen(s));
    sprintf(s + strlen(s), "} ");
  }
  return TEMPCOPY(s);
}

/* Updates (global) displayhandpassstate and returns whether redisplay
   is necessary (i.e., whether the hands have been changed by the pass). */
static bool UIupdatepass(char *passstate, int pov)
{
  bool change = !streq(passstate, displayhandpassstate);

  if (displaydeck == NULL || !change) return FALSE;

#if DEBUGHEARTS
  DEBUG(status5("UIupdatepass ", passstate, " (change=", itoa(change), ")"));
#endif

  if (change) STRCPY(displayhandpassstate, passstate);
	
  if (passisover(displayhandpassstate, hcol_to_seat(dealercolumn, pov))) {
    adjusthands(passstate, hcol_to_seat(dealercolumn, pov), displaydeck);
    return TRUE;
  }

  return FALSE;

  /*
  updatepassstate(displayhandpassstate, passstate);
  reportpassstatus(displayhandpassstate);
  */
}

/* dd is whether to show all four hands */
/* cards in played are not shown */
/* pass is the hearts pass, if applicable */
static void UIshowdeal(int pov, bool dd, int dummycol,
		       char *played, char *pass)
{
  bool ed, wd, sd, nd;

  if (hasWindows) UIpatientcursor();
  if (displayinghearts || seated || kibitzing1 || dd || dummycol >= 0)
    if (displaydeck == NULL && strlen(displayhandID) > 0) {
      displaydeck = (int *) salloc(sizeof(int) * 52);
#if DBGu
      status2("Display handID=", displayhandID);
      status2("Display seed=", TclDo3("gset handseed(", displayhandID, ")"));
#endif
      setseed(TclDo3("gset handseed(", displayhandID, ")"));
      deal(displaydeck, 0, 0, 0, 0, disnumplayers * cardsperhand);
      if (displayinghearts) UIupdatepass(pass, pov);
      sortdeal(displaydeck, disnumplayers * cardsperhand, cardsperhand);
    }

  nd = sd = ed = wd = dd;
  if (!dd && (dummycol >= 0) && !displayinghearts)
    switch (bcol_to_seat(dummycol, pov)) {
    case South: sd = TRUE; break;
    case North: nd = TRUE; break;
    case West:  wd = TRUE; break;
    case East:  ed = TRUE; break;
    default: assert(0);
    }

  if (displaydeck != NULL && (!displayinghearts || seated || dd || kibitzing1))
    switch (pov) {
    case South:
      if (displayinghearts && seated && myseat == West) 
	TclDo5("fulldeal ", southcards(sd),
	       westcards(TRUE), northcards(nd), eastcards(ed));
      else 
	TclDo5("fulldeal ", southcards(sd || seated || kibitzing1),
	       westcards(wd), northcards(nd), eastcards(ed));
      break;
    case North:
      TclDo5("fulldeal ", northcards(nd || seated || kibitzing1), eastcards(ed),
	     southcards(sd), westcards(wd));
      break;
    case East:
      TclDo5("fulldeal ", eastcards(ed || seated || kibitzing1), southcards(sd),
	     westcards(wd), northcards(nd));
      break;
    case West:
      TclDo5("fulldeal ", westcards(wd || seated || kibitzing1), northcards(nd),
	     eastcards(ed), southcards(sd));
      break;
    default:
      assert(0);
    } else {
      nodeal();
      goto done;
    }

  if (played != NULL) {
    int i;
    char s[4];
    
    for (i = strlen(played) - 2; i >= 0; i -= 2) {
      sprintf(s, "%c %c", played[i], played[i+1]);
      removecardfromhand(s);
    }
    UIredrawmatrixcards();
  }
done:
  if (dd) force_update();
  if (hasWindows) UInormalcursor();
}

#define col_to_name(col, pov) outputname(col_to_fullname((col), (pov)))
static char *col_to_fullname(int column, int pov)
{
  switch (col_to_seat(column, pov, displayinghearts)) {
  case South: return strexists(southname) ? southname : "(South)";
  case North: return strexists(northname) ? northname : "(North)";
  case East: return strexists(eastname) ? eastname : "(East)";
  case West: return strexists(westname) ? westname : "(West)";
  default: assert(0);
  }
}

#define seat_to_name(seat) outputname(seat_to_fullname(seat))
static char *seat_to_fullname(int seat)
{
  switch (seat) {
  case South: return strexists(southname) ? southname : "(South)";
  case North: return strexists(northname) ? northname : "(North)";
  case East: return strexists(eastname) ? eastname : "(East)";
  case West: return strexists(westname) ? westname : "(West)";
  default: assert(0);
  }
}

/*BUG: assumes current northname is the north player for hand being displayed*/
static void UIshowplayernames(int pov)
{
#if DBGu
  DEBUG(status2("UIshowplayernames ", itoa(pov)));
#endif
  switch(pov) {
  case South:
  default:
    TclDo3("setname self S {", seat_to_name(South), "}");
    TclDo3("setname lho W {", seat_to_name(West), "}");
    TclDo3("setname pard N {", seat_to_name(North), "}");
    TclDo3("setname rho E {", seat_to_name(East), "}");
    break;
  case North:
    TclDo3("setname pard S {", seat_to_name(South), "}");
    TclDo3("setname rho W {", seat_to_name(West), "}");
    TclDo3("setname self N {", seat_to_name(North), "}");
    TclDo3("setname lho E {", seat_to_name(East), "}");
    break;
  case East:
    TclDo3("setname lho S {", seat_to_name(South), "}");
    TclDo3("setname pard W {", seat_to_name(West), "}");
    TclDo3("setname rho N {", seat_to_name(North), "}");
    TclDo3("setname self E {", seat_to_name(East), "}");
    break;
  case West:
    TclDo3("setname rho S {", seat_to_name(South), "}");
    TclDo3("setname self W {", seat_to_name(West), "}");
    TclDo3("setname lho N {", seat_to_name(North), "}");
    TclDo3("setname pard E {", seat_to_name(East), "}");
    break;
  }
}

static void UIupdatepov(int pov, bool dd, int dummycol)
{
  if (displayinghearts) {
    if (pov == West) pov = South;
#if DEBUGHEARTS
    status7("UIupdatepov(pov=", itoa(pov),
	    ", dd=", itoa(dd), ", dummycol=", itoa(dummycol), ")");
#endif
  }

  displaydoubledummy = dd;
  displaypov = pov;

  UIshowdeal(pov, dd, dummycol, displayhandpstate, displayhandpassstate);
  UIshowplayernames(pov);
}

static void showmatrixbid(int where, char *bid)
{
  {
    int i = 0;
    
    while (isspace(bid[i])) i++;
    assert(isin(bid[i], "12345670?"));
    i++;
    while (isspace(bid[i])) i++;
    assert(isin(tolower(bid[i]), "xprcdhsn?"));
  }

  switch (where) {
  case 0:
    TclDo2("showbid lho ", bid);
    break;
  case 1:
    TclDo2("showbid pard ", bid);
    break;
  case 2:
    TclDo2("showbid rho ", bid);
    break;
  case 3:
    TclDo2("showbid self ", bid);
    break;
  default:
    assert(0);
  }
}

static void showmatrixplay(int where, char *play, int pov)
{
  if (!isin('?', play)) removecardfromhand(play);
    
  {
    int i = 0;
    
    while (isspace(play[i])) i++;
    assert(isin(play[i], "cdhsCDHS?"));
    i++;
    while (isspace(play[i])) i++;
    assert(isin(play[i], "AKQJTakqjt23456789?"));
  }

  if (displayinghearts) switch (where) {
    /* West doesn't exist in hearts, so North's RHO is South
       (and South's LHO is North)  */
  case 0:
    if (pov == South) TclDo2("showplay pard ", play);
    else TclDo2("showplay lho ", play);
    break;
  case 1:
    if (pov == North) TclDo2("showplay pard ", play);
    else TclDo2("showplay rho ", play);
    break;
  case 2:
    TclDo2("showplay self ", play);
    break;
  case 3:
    /* BUG here? */
    break;
  default:
    assert(0);
  } else switch (where) {
  case 0:
    TclDo2("showplay lho ", play);
    break;
  case 1:
    TclDo2("showplay pard ", play);
    break;
  case 2:
    TclDo2("showplay rho ", play);
    break;
  case 3:
    TclDo2("showplay self ", play);
    break;
  default:
    assert(0);
  }
}

/* first arg is whether to show the auction at all; second is whether to
   include the buttonbar */
static void UIauction(bool display, bool showbuttonbar, bool hideMatrix)
{
  static bool displayed = FALSE;
  bool matrixHidden = hasWindows && !atob(TclGet("matrix_showing"));

#if DBGu
  if (hasWindows) {
    char s[1000];

    sprintf(s, "UIauction(%d => %d, %d => %d, %d => %d)",
	    (int)display,
	    (int)(display &&
		  !atob(TclDo3("uplevel #0 {info exists hide_auction(",
			       displayhandID, ")}"))),
	    (int)showbuttonbar,
	    (int)(showbuttonbar && atob(TclGet("bidButtons_"))),
	    (int)hideMatrix,
	    (int)(hideMatrix && atob(TclGet("hideMatrix_"))));
    status(s);
  }
#endif

  if (hasWindows) {
    display = display && !atob(TclDo3("uplevel #0 {info exists hide_auction(",
				      displayhandID, ")}"));
    showbuttonbar = showbuttonbar && atob(TclGet("bidButtons_"));
    hideMatrix = hideMatrix && atob(TclGet("hideMatrix_"));
  }

  if (display == displayed && showbuttonbar == displayshowbuttonbar
      && hideMatrix == matrixHidden) return;

  if (hasWindows) UIpatientcursor();

  /* The below had been protected by "if (displayed != display)" but a
     mystery bug with the auction not getting packed on the GUI popped
     up, and the cost of a redundant showauction is low on GUI.  (On
     TUI, redundant showauction erases the auction, oddly enough.) */
  if (hasWindows || (displayed != display))
    if ((displayed = display)) 
      TclDo("showauction 1");
    else
      TclDo("showauction 0");
  
  if (hasWindows) {
    TclDo("pack prop .play true");
    if (showbuttonbar != displayshowbuttonbar)
      if ((displayshowbuttonbar = showbuttonbar))
	TclDo("pack .auction.bb -before .auction.l");
      else
	TclDo("pack forget .auction.bb");

    if (hideMatrix != matrixHidden)
      if ((matrixHidden = hideMatrix))
	TclDo("showMatrix 0");
      else
	TclDo("showMatrix 1");

    UInormalcursor();
  }
}


static char *auctionframe(char *frame, int col, int line)
{
  if (!hasWindows) {
    sprintf(frame, "%d %d", col, line);
  } else {
    sprintf(frame, ".auction.r.%d.%d", col, line);
    TclDo5("catch {destroy ", frame, "}; pack [frame ", frame, "]");
  }
  return frame;
}

static void UIauctionstartup(int pov)
{
  int i;
  char frame[100], cmd[200];

  if (dealercolumn < 0) {
    dealercolumn = bseat_to_col(DEALNO_TO_DEALER(atoi(displayhandID)), pov);
#if DBGu
    DEBUG(status4("pov=", itoa(pov), " dealercol=", itoa(dealercolumn)));
#endif
  }

  if (displaycalls == 0) {
    newauction();
    UIclearmatrix();
    for (i=0; i<dealercolumn; i++) { 
      auctionframe(frame, i, 0);
      sprintf(cmd, "drawbid %s - -", frame);
      TclDo(cmd);
    }
  }
}

/* draw a question mark to show whose call it is */
static void UIdisplaywhosecall(int pov)
{
  int line, column;
  char frame[100];

  if (auctionisover(displayhandastate)) {
    sleep(125);
    return;
  }
  UIauctionstartup(pov);
  line = (displaycalls + dealercolumn) / 4;
  column = (displaycalls + dealercolumn) % 4;
  auctionframe(frame, column, line);
  TclDo3("drawbid ", frame, " ? ?");
  showmatrixbid(column, "? ?");
}

/* the global displaycalls is the call to display */
static void UIdisplaycall(char *auction, int pov)
{
  int call = displaycalls;
  char cmd[100], frame[50];
  int line, column;

#if DBGu
  {
    char foo[1000];

    sprintf(foo, "%c%c; dealercol=%d, pov=%d", auction[call*2],
	    auction[call*2+1], dealercolumn, pov);
    DEBUG(status2("Display call ", foo));
  }
#endif

  UIauctionstartup(pov);

  line = (call + dealercolumn) / 4;
  column = (call + dealercolumn) % 4;
  auctionframe(frame, column, line);
  switch (auction[call * 2 + 1]) {
  case 'r':
    sprintf(cmd, "drawbid %s 0 xx", frame);
    break;
  case 'p':
  case 'x':
    sprintf(cmd, "drawbid %s 0 %c", frame, auction[call * 2 + 1]);
    break;
  default:
    assert(isdigit(auction[call * 2]));
    sprintf(cmd, "drawbid %s %c %c", frame, auction[call * 2],
	    auction[call * 2 + 1]);
    break;
  }
  showmatrixbid(column, cmd + strlen(cmd) - 4); 
  TclDo(cmd);
#if DBGu
  DEBUG(status(cmd));
#endif

  displaycalls++;
}


/* Draw a question mark to show whose play it is.  If we're between tricks,
   update status bar to show who's lead it is. */
static void UIdisplaywhoseplay(char *auction, char *pstate, char *passstate,
			       int pov)
{
  int column, played;

  if (playisover(auction, pstate) ||
      (displayinghearts &&
       !passisover(passstate, hcol_to_seat(dealercolumn, pov)))) {
    statustolead[0] = '\0';
    return;
  }
  if (((played = numcards(pstate)) % disnumplayers) == 0) {
    sprintf(statustolead, "%s's lead", col_to_name(leadercolumn, pov));
    startshowtricktimer();
    if (played > 0) return;
  } else statustolead[0] = '\0';
  column = (displayplays + leadercolumn) % 4; /* ??? disnumplayers? */
  if (displayinghearts) {
    int np = disnumplayers;
    column = hseat_to_col(((displayplays % np) + hcol_to_seat(leadercolumn, pov)) % np, pov);
  }
  showmatrixplay(column, "? ?", pov);
}

/* Display dummy, except if I am dummy (or I am kibitzing dummy) then
   display declarer's hand. */
static void UIdisplaydummy(int pov)
{
  int dummycol = ((declarercolumn == 1 && seated) ? 1 : (declarercolumn ^ 2));

  if (/* (kibitzing1 && kibitzingseat == col_to_seat(dummycol, pov)) || */
      displaydoubledummy) return;
  UIshowdeal(pov, FALSE, dummycol, displayhandpstate, NULL);
  UIshowplayernames(pov);
}

/* the global displayplays is the play to display */
static void UIdisplayplay(char *pstate, int pov)
{
  int play = displayplays;
  int column;
  char card[100];

#if DBGu
  {
    char foo[10];

    sprintf(foo, "%c%c", pstate[play*2], pstate[play*2+1]);
    DEBUG(status2("Display play ", foo));
  }
#endif

  if (!displayinghearts && displayplays == 0) UIdisplaydummy(pov);
  /* if not a claim, it's a card, so let's display it */
  if (pstate[play*2] != '!') {
    column = (play + leadercolumn) % 4;
    if (displayinghearts) {
      int np = disnumplayers;
      column = hseat_to_col(((displayplays % np) +
			     hcol_to_seat(leadercolumn, pov)) % np, pov);
    }
    sprintf(card, "%c %c", pstate[play*2], pstate[play*2+1]);
    showmatrixplay(column, card, pov);
  }
  displayplays++;
}


static void UIsummarizeauction(char *auction, int pov)
{
  if (declarercolumn >= 0 && !displayinghearts)
    sprintf(statuscontract, "%s by %s", displaycontract,
	    col_to_name(declarercolumn, pov));
  else /* passed out */
    sprintf(statuscontract, "%s", displaycontract);
}

static void UIupdateauction(char *auction, char *pstate, int pov, bool seated)
{
  int calls;
  bool change = !streq(auction, displayhandastate);

  if (change) STRCPY(displayhandastate, auction);

  if (auctionisover(auction)) {
    UIsummarizeauction(auction, pov);
    UIauction((numcards(pstate) < HIDE_AUCTION), FALSE, (numcards(pstate) == 0));
    if (!change) return;
    calls = numcalls(auction);
    while (displaycalls < calls) UIdisplaycall(auction, pov);
    if (hasWindows) {
      if (!auction_hide_time_inited) init_auction_hide_time();
      if (auction_hide_time >= 0) {
	char s[1000];
	sprintf(s,
		"after [expr round(1000.0 * %f)] {"
		"  gset hide_auction(%s) 1;"
		"  gset needAuctionUpdate 1;"
		"}",
		auction_hide_time, displayhandID);
	TclDo(s);
      }
    }
    return;
  }
    
  UIauction(TRUE, seated, TRUE);
  calls = numcalls(auction);
  while (displaycalls < calls) UIdisplaycall(auction, pov);
  UIdisplaywhosecall(pov);
}

static void UIupdatetrickswon(char *pstate, int pov)
{
  int decl, def, we, they;

  computetrickswon(pstate, 1000, displaytrump, declarercolumn,
		   &decl, &def);
  if (declarercolumn == 1 || declarercolumn == 3) {
    we = decl;
    they = def;
  } else {
    we = def;
    they = decl;
  }
  if (seated) sprintf(displaytrickswon, "Tricks won: %d; lost: %d", we, they);
  else sprintf(displaytrickswon, "Tricks won (%s): %d; (%s): %d",
	       ((pov == South || pov == North) ? "NS" : "EW"), we,
	       ((pov == South || pov == North) ? "EW" : "NS"), they);
}

/* update the status of the play; also, when 1st card is played, show dummy */
/*  (or before 1st card is played, show dummy and declarer their two hands) */
static void UIupdateplay(char *auction, char *pstate, char *passstate, int pov)
{
  int plays;

  /* to prevent the display of dummy from happening multiple times */
  static char *lastdisplayhandID = NULL;
  static int lastpov = -99;

  /* note the addition of !passisover to the if statement below.  hearts*/
  STRCPY(displayhandpstate, pstate);
  if (strlen(pstate) == 0) 
    if (!auctionisover(displayhandastate) ||
	(displayinghearts &&
	 !passisover(displayhandpassstate, hcol_to_seat(dealercolumn, pov))))
      return;
    else if (!safestreq(lastdisplayhandID, displayhandID) || lastpov != pov) {
      reset(lastdisplayhandID);
      lastdisplayhandID = STRDUP(displayhandID);
      lastpov = pov;
      UIclearmatrix();
      DEBUG(status2("Time to display dummy; declarercolumn=",
		    itoa(declarercolumn))); 
      if (declarercolumn == 1 || declarercolumn == 3) UIdisplaydummy(pov);
    }
  
  plays = numcards(pstate);
  while (displayplays < plays) {
    /* assert(displayplays < plays); */
    if (displayplays % disnumplayers == 0) {
      if (displayinghearts) {
	int leaderseat = computeleader(pstate, displayplays,
				       displaytrump, -1, TRUE);
	leadercolumn = hseat_to_col(leaderseat, pov);
#if DEBUGHEARTS
	DEBUG(status6("displayplays=", itoa(displayplays),
		      " leaderseat=", itoa(leaderseat),
		      " leadercolumn=", itoa(leadercolumn)));
#endif
	
      } else leadercolumn = computeleader(pstate, displayplays,
					  displaytrump, declarercolumn,
					  FALSE);
      UIclearmatrix();
    }
    assert(displayplays < plays);
    UIdisplayplay(pstate, pov);
    if (displayplays == 49 && !displayinghearts && !isin('!', pstate))
      display_final_trick(displayhandID, pstate);
  }
  if (displayplays % disnumplayers == 0) {
    if (displayinghearts) {
      int leaderseat = computeleader(pstate, displayplays,
				     displaytrump, -1, TRUE);
      leadercolumn = hseat_to_col(leaderseat, pov);
    } else 
      leadercolumn = computeleader(pstate, displayplays,
				    displaytrump, declarercolumn, FALSE);
  }
  if (!displayinghearts) UIupdatetrickswon(pstate, pov);
  UIdisplaywhoseplay(auction, pstate, passstate, pov);
}

/* the workhorse */
void UIupdate(void)
{
  int pov, dummycolumn = -1;
  char *astate, *pstate, *passstate;
  bool povchange, seatedchange;
  bool updateall = FALSE;
  extern bool claiming;
  extern int curclaimtricks;
  static bool expectingNULL = TRUE; /* are we expecting curhandID is NULL? */
  static bool expecting_myturntoact = FALSE;

  DISALLOW_REENTRY();
  draw_on_matrix_screen();

  /* beep if it is now my turn to act, but it wasn't last time through here */
  if (myturntoact && !expecting_myturntoact) {
    expecting_myturntoact = TRUE;
    if (beepatmyturn()) UIbeep();
    startMyTurnTimer();
  } else if (!myturntoact && expecting_myturntoact) {
    expecting_myturntoact = FALSE;
    stopMyTurnTimer();
  }

  if (curhandID == NULL) {
    /* clear _everything_ */
    spec = FALSE;
    if (!expectingNULL) {
      expectingNULL = TRUE;
      nodeal();
      noauction();
      UIclearmatrix();
      statustolead[0] = statusclaim[0] = statusresult[0] = statuscontract[0] =
	displaycontract[0] = displaytrickswon[0] = statushandvul[0] =
	statushanddlr[0] = displayhandID[0] = displayhandname[0] =
	statusscore[0] = '\0';
    }
    goto done;
  }
  if (seated) pov = myseat; else pov = South;
  if (kibitzing1) pov = kibitzingseat;
  if (displayinghearts && pov == West) pov = South;
  if (strlen(displayhandID) == 0 ||
      (curhandID != NULL && !streq(curhandID, displayhandID) && caughtup)) {
/*    newauction();*/
    spec = FALSE;
    displayhandisover = FALSE;
    if (curhandID == NULL || strlen(curhandID) == 0) goto done;
    strcpy(displayhandID, curhandID);
    strcpy(displayhandname, TclDo3("gset handname(", curhandID, ")"));
    status2("Displaying hand ", displayhandname);
    UIclearmatrix();
    reset(displaydeck);
    displayhandscoring = atoi(TclDo3("gset handscoring(", curhandID, ")"));
    displayinghearts = ishearts(displayhandscoring);
    displayingrubber = isrubber(displayhandscoring);
    disnumplayers = displayinghearts ? 3 : 4; /* assumes 3-handed hearts */
    if (displayinghearts)
      parseheartsgstate(TclDo3("gset handgstate(", curhandID, ")"),
			&nscore, &escore, &sscore);
    if (displayingrubber)
      parserubbergstate(TclDo3("gset handgstate(", curhandID, ")"),
			&disnsvul, &disewvul,
			&disnstotal, &disewtotal,
			&disnsbelowline, &disewbelowline);
    if (displayingrubber) {
      int vul = disewvul ? (disnsvul ? Both : EW) : (disnsvul ? NS : Nonevul);

      strcpy(statushandvul, vulnames[vul]);
      sprintf(statusscore, "NS: %d/%d; EW: %d/%d",
	      disnstotal - disnsbelowline, disnsbelowline,
	      disewtotal - disewbelowline, disewbelowline);
      sprintf(statushanddlr, "%c dealt",
	      seat_to_char(DEALNO_TO_DEALER(atoi(displayhandID))));
    } else if (displayinghearts) {
      sprintf(statusscore, "N: %d; E: %d; S: %d",
	      nscore, escore, sscore);
      strcpy(statushandvul,
	     passnames[DEALNO_TO_DEALER(atoi(displayhandID))]);
    } else {
      /* duplicate bridge */
      statusscore[0] = '\0';
      strcpy(statushandvul, vulnames[ONEB(atoi(curhandID) - 1)]);
      sprintf(statushanddlr, "%c dealt",
	      seat_to_char(DEALNO_TO_DEALER(atoi(displayhandID))));
    }

    displayhandastate[0] = displayhandpstate[0] =
      displayhandpassstate[0]= '\0';
    statustolead[0] = statusclaim[0] = statusresult[0] = statuscontract[0] =
      displaycontract[0] = displaytrickswon[0] = '\0';
    dealercolumn = declarercolumn = -1;
    displayplays = 0;
    displaycalls = 0;
    displaypov = -1;
    displaytrump = -1;
    updateall = TRUE;
  }
  if (caughtup) {
    bool oppclaim; /* whether claim in progress should make all 4 hands vis. */

    if (dealercolumn < 0) {
      dealercolumn = seat_to_col(DEALNO_TO_DEALER(atoi(displayhandID)), pov,
				 displayinghearts);
#if DBGu
      DEBUG(status4("pov=", itoa(pov), " dealercol=", itoa(dealercolumn)));
#endif
    }
    if (claiming) 
      sprintf(statusclaim, "Claiming %d tricks total", curclaimtricks);
    else statusclaim[0] = '\0';
    povchange = (pov != displaypov);
    if (povchange) displaycalls = 0; /* need to redisplay whole auction */
    seatedchange = (displayseated != seated);
    if (auctionisover(displayhandastate) &&
	(displaytrump < 0 || povchange || updateall))
      computecontract(displayhandastate, dealercolumn,
		      displaycontract, &declarercolumn, &displaytrump);
    dummycolumn = (declarercolumn >= 0) ? ((declarercolumn + 2) % 4) : -1;
    oppclaim = claiming && (declarercolumn <= 0 || declarercolumn == 2);
    if (updateall || povchange || displaydoubledummy != (spec || oppclaim))
      UIupdatepov(pov, (spec || oppclaim), dummycolumn);
    astate = TclDo3("gset handastate(", displayhandID, ")");
    pstate = TclDo3("gset handpstate(", displayhandID, ")");
    passstate = TclDo3("gset handpassstate(", displayhandID, ")");
#if 0
    status2("UIupdate() with pass state=", passstate);
#endif
    if (seatedchange || povchange || updateall || needAuctionUpdate() ||
	(strlen(displayhandpstate) != strlen(pstate) &&
	 numcards(pstate) >= HIDE_AUCTION) ||
	!streq(displayhandastate, astate)) {
      if (displayinghearts) UIauction(FALSE, FALSE, FALSE);
      else {
	UIupdateauction(astate, pstate, pov, seated);
	if (auctionisover(displayhandastate) &&
	    (displaytrump < 0 || povchange || updateall))
	  computecontract(displayhandastate, dealercolumn,
			  displaycontract, &declarercolumn, &displaytrump);
	dummycolumn = (declarercolumn >= 0) ? ((declarercolumn + 2) % 4) : -1;
	if (updateall || povchange || displaydoubledummy != (spec || oppclaim))
	  UIupdatepov(pov, (spec || oppclaim), dummycolumn);
      }
    }

    if (displayinghearts && UIupdatepass(passstate, pov)) updateall = TRUE;

    if (seatedchange || povchange || updateall)
      UIupdatepov(pov, (spec || oppclaim), dummycolumn);

  /* note the addition of !passisover to the if statement below.  hearts*/
    if (seatedchange || povchange || updateall || 
	(auctionisover(astate) && 
	 (!displayinghearts ||
	  passisover(passstate, hcol_to_seat(dealercolumn, pov)))) ||
	!streq(displayhandpstate, pstate))
      UIupdateplay(astate, pstate, passstate, pov);
    displayseated = seated;
    if (playisover(astate, pstate) && !displayhandisover) {
      int restricks, respoints;
      bool vulp;
      int vul, declarerseat;
      int unused = 0;

      no_spectators(displayhandID);
      displayhandisover = TRUE;
      statustolead[0] = '\0';
  
      declarerseat = col_to_seat(declarercolumn, pov, displayinghearts);
      vul = displayingrubber ?
	(disewvul ? (disnsvul ? Both : EW) : (disnsvul ? NS : Nonevul)) :
	ONEB(atoi(displayhandID) - 1);
      vulp =
	(vul == Both ||
	 ((declarerseat == North || declarerseat == South) && vul == NS) || 
	 ((declarerseat == East || declarerseat == West) && vul == EW));
      computeresult(displaycontract, pstate, declarerseat,
		    vulp, &restricks, &respoints,
		    displayingrubber ? &unused : NULL);
      if ((declarercolumn & 1) == 0) respoints = -respoints;
      if (!displayinghearts) {
	if (restricks < 0)
	  sprintf(statusresult, "Down %d, %d", -restricks, respoints);
	else if (restricks > 0)
	  sprintf(statusresult, "Made %d, %d", restricks, respoints);
	else
	  sprintf(statusresult, "Passed out");
#if DEBUGBR
	if (restricks != 0) {
	  char s[1000];
	
	  sprintf(s, "%s by %s (%s), %s", displaycontract,
		  col_to_name(declarercolumn, pov), vulp ? "v" : "nv",
		  statusresult);
	  status(s);
	}
#endif
      }

      /* display all 52 cards to everyone */
      UIshowdeal(pov, TRUE, -1, NULL, displayhandpassstate);
      UIshowplayernames(pov);
      /* UIdelayedclearmatrix(); */
    }
  }
  expectingNULL = FALSE;
 done:
  if (!hasWindows)
    needrefresh = TRUE;
  ALLOW_REENTRY();
  return;
}

/* which is North, South, East, or West */
void UIplayergone(int which)
{
  if ((curhandID == NULL && caughtup) ||
      (curhandID != NULL && streq(displayhandID, curhandID)))
    UIshowplayernames(displaypov);
}

/* ch is one of N, S, E, W */
void UIsit(char *name, char ch, int myseat)
{
  int newpov;

#if DBGu
  DEBUG(status5("UIsit(", name, " ", itoa(myseat), ")"));
#endif

  if (hasWindows) {
    extern bool claiming;
    extern int curdeclarer;

    UIpatientcursor();
    TclDo2("activate_seated_menus ", itoa(seated));
    TclDo2("menus_declaring ", itoa(declaring()));
    if (claiming) {
      if (declaring()) TclDo("menus_declclaim");
      else if (defending()) TclDo("menus_defclaim");
    }
  }

  if (myseat == Noseat && !kibitzing1 && strlen(displayhandpstate) == 0) {
    reset(displaydeck);
    nodeal();
  }
  if (!(displaypov == myseat ||
	(myseat == Noseat && displaypov == South && !kibitzing1) ||
	(kibitzing1 && displaypov == kibitzingseat))) {
    dealercolumn = declarercolumn = -1;
    displayplays = 0;
    displaycalls = 0;
    displaypov = -1;
    displayhandpassstate[0] = '\0'; /* for hearts */
  }

  newpov = (myseat >= 0) ? myseat :
    (kibitzing1 ? kibitzingseat : South);
  
  if ((curhandID == NULL && caughtup) ||
      (curhandID != NULL && displayhandID != NULL &&
       streq(displayhandID, curhandID)))
    UIshowplayernames(newpov);
  if (!hasWindows) {
    char s[100];
    
    sprintf(s, "textseated %c %c", seated ? '1' : '0', seat_to_char(newpov));
    TclDo(s);
  }
  if (hasWindows) UInormalcursor();
}