-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshoogi2.c
executable file
·1581 lines (1325 loc) · 36.2 KB
/
shoogi2.c
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
#include "shoogi.h"
#ifdef CRIPPLED_TOUPPER
unsigned int mytoupper(c)
unsigned int c;
{
if(((c) >= 'a') && ((c) <= 'z')) { return(c-('a'-'A')); }
else { return(c); }
}
unsigned int mytolower(c)
unsigned int c;
{
if(((c) >= 'A') && ((c) <= 'Z')) { return(c+('a'-'A')); }
else { return(c); }
}
#endif
int takefirstword(result,buf)
char *result;
char *buf;
{
char *p;
p = skip_blankos(buf);
if(!*p)
{
*buf = '\0';
return(0);
}
while(*p && !isspace(*p)) { *result++ = *p++; }
*result = '\0'; /* Terminate the result string. */
strcpy(buf,p); /* Copy the rest of buf to beginning. */
return(1);
}
char *getfirstword(result,buf)
char *result;
char *buf;
{
char *p;
p = skip_blankos(buf);
if(!*p)
{
return(NULL);
}
while(*p && !isspace(*p)) { *result++ = *p++; }
*result = '\0'; /* Terminate the result string. */
return(p); /* Return rest of the buf. */
}
/* This takes a command line in bar and divides it to pieces which are
put to null terminated vector foo. (Like argv argument of main).
Returns the count of them. (Like argc).
*/
int hack_to_pieces(foo,bar)
register char **foo,*bar;
{
register int count=0;
/* Okay, this would be nice if there would be a separate space allocated
for the strings in foo:
while(*(bar = skip_blankos(bar)))
{
while(*bar && !isspace(*bar)) { **foo++ = *bar++; }
(* I hope that the following line is equal to **foo = '\0'; foo++; *)
*(*foo++) = '\0';
count++;
}
*/
/* Instead, we use the space in the bar, and overwrite the
first blankos after non-blank-segements with ending zeros: */
while(*(bar = skip_blankos(bar)))
{
count++;
/* Set elements of foo to point to first non-blank-char: */
*foo++ = bar;
while(*bar && !isspace(*bar)) { bar++; } /* Skip the non-blanks */
if(!*bar) { break; } /* If bar finished. */
*bar++ = '\0';
}
*foo = NULL;
return(count);
}
/* This concatenates the command line back together, starting from
argument arg, and returns the resulting string (beginning from
argument arg), or NULL if first arg is NULL.
All string end zeros (except of the last one) are replaced by blankos,
so if there were tabs instead between words, then result is not exactly
the same as original command line.
*/
char *reconstruct_cmdline(arg)
register char **arg;
{
register char *p;
char *s;
if(!*arg) { return(NULL); }
s = *arg;
while(*(arg+1))
{ /* Find the end of each argument word: */
for(p=*arg; *p; p++) ;
*p = ' '; /* And replace it by blanko. */
arg++;
}
return(s);
}
char *skip_blankos(s)
register char *s;
{ /* On some rotten systems is* macros don't work correctly with '\0' ! */
while(*s && isspace(*s)) { s++; }
return(s);
}
char *nuke_newline(s)
char *s;
{
char *p;
p = (s + strlen(s)); /* Get pointer pointing to the terminator zero. */
/* If length of s was greater than zero, and there's newline as last
character, then remove it: */
if((p > s) && (*--p == '\n')) { *p = '\0'; }
/* If there's also CR, then nuke it too: (Can happen with Turbo-C) */
if((p > s) && (*--p == '\r')) { *p = '\0'; }
return(s);
}
/* Convert string s to uppercase: */
char *conv_upper(s)
register char *s;
{
char *orgs;
orgs = s;
while(*s = toupper(*s)) { s++; }
return(orgs);
}
/* Convert string s so that scandinavian dotted letters {, } and |
are replaced by corresponding letters without dots and rings
*/
char *conv_scands(s)
register char *s;
{
unsigned char c;
char *orgs;
orgs = s;
while(c = *s)
{
switch(c)
{ /* A with dots and A with ring: */
case '[': case ']': { c = 'A'; break; }
case '{': case '}': { c = 'a'; break; }
case '\\': { c = 'O'; break; } /* O with dots. */
case '|': { c = 'o'; break; }
case '^': { c = 'U'; break; } /* U with dots. */
case '~': { c = 'u'; break; }
default: { /* c = c; */ }
}
*s++ = c;
}
return(orgs);
}
#ifdef This_is_fancy_but_we_dont_need_it_now
char *getcardinalsuffix(n)
MYINT n;
{
switch(n)
{
case 1: { return("st"); } /* First */
case 2: { return("nd"); } /* Second */
case 3: { return("rd"); } /* Third */
default: { return("th"); } /* Fourth */
}
}
#endif
int pertospc(s)
char *s;
{
register char *p;
register int count=0;
/* Change all periods to spaces: */
p = s;
while((p = strchr(p,'.'))) { *p++ = ' '; count++; }
return(count);
}
int spctoper(s)
char *s;
{
register char *p;
register int count=0;
/* Change all spaces to periods: */
p = s;
while((p = strchr(p,' '))) { *p++ = '.'; count++; }
return(count);
}
char *mystrdup(s)
char *s;
{
register char *t;
if(!(t = ((char *) malloc(strlen(s)+1))))
{
errlog((E1,
"**Internal error in mystrdup: memory exhausted, s=%u:\n%s\n",
strlen(s),s));
ertzu_exit(101);
}
strcpy(t,s); /* Copy string to new location. */
return(t);
}
/*
This copies to buffer z (and returns it) the date and time in form:
10-MAY-92,20:20:22
*/
char *get_timebuf()
{
char *ctime();
long tloc;
register char *p;
static char z[21];
time(&tloc); /* Get the time to tloc. */
p = ctime(&tloc); /* Convert it to ascii, standard unix form. */
/* Then convert that to our own format: */
z[0] = p[8]; /* Day of month. */
z[1] = p[9];
z[2] = '-';
z[3] = p[4]; /* Month. */
z[4] = toupper(p[5]);
z[5] = toupper(p[6]);
z[6] = '-';
p[24] = '\0';
strcpy((z+7),(p+22)); /* Year, 2 digits. */
z[9] = ',';
p[19] = '\0';
strcpy((z+10),(p+11)); /* Time, 8 characters. */
/* Substitute zero for blank in day of month: */
if(*z == ' ') { *z = '0'; }
return(z);
}
int numberp(s)
char *s;
{
while(*s) { if(!isdigit(*s++)) { return(0); } }
return(1);
}
/* This returns 1 if beginning of s1 is equivalent to s2. */
int cutstrequ(s1,s2)
register char *s1,*s2;
{
int len,result;
char savec;
len = strlen(s2);
if(strlen(s1) < len) { return(0); } /* If s1 shorter than s2. */
savec = s1[len];
s1[len] = '\0';
result = strcmp(s1,s2);
s1[len] = savec;
return(!result);
}
/*
Pattern can contain following characters:
? Matches one character which can be anything.
* Matches zero or more of any characters.
< Start of the "group-expression", which contains some chars,
and must end in >
If first char after < is ^ then its semantics are negated.
If first char after < or ^ is > then it's not understood yet as end
delimiter.
Examples:
<abc> Matches any of the letters a, b and c.
<^0123456789> Matches anything, except digits.
<>> Matches >
<^>> Matches anything except >
@ Matches character last matched to ? or group-expression.
For example ?*@ matches to all strings which begin with same
character they end.
However, if pattern starts with @ then it sets the group
start & end characters, e.g. pattern: @{tuu<ba{123}pasuuna
matches to anything which begins tuu<ba then after that is
1, 2 or 3 and after that pasuuna.
Any other characters match just to themselves.
Note that unix-like [0-9] (corresponding to <0123456789>) is not
implemented yet.
*/
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE !FALSE
#endif
char GROUP_BEG_CHAR = '<';
char GROUP_END_CHAR = '>';
unsigned char *string_org;
unsigned char last_matched=0;
/* Check whether pattern and string match, and returns 0 if they not.
If they match then return integer whose high byte is the last character
matched to ? or <> expression (if any), and whose low byte is
index +2 to string, to that point which matched to the first
non-* and non-? expression.
Note that value of last_matched is updated in double-recursive
function, although it is static variable.
Intuitively, this should cause some problems, but I haven't yet
discovered any pattern which would match incorrectly.
*/
int wildcard(pattern,string)
unsigned char *pattern,*string;
{
unsigned int wild_aux();
unsigned int i;
char negate_flag;
last_matched = 0;
string_org = string;
#ifdef COMMENTED_OUT
if(*pattern == '@') /* Set group-expression delimiter characters. */
{ /* Set GROUP_BEG_CHAR to be char after @, and if it is not '\0' */
if(GROUP_BEG_CHAR = *++pattern) { pattern++; } /* then skip it also. */
GROUP_END_CHAR = get_end_delimiter(GROUP_BEG_CHAR);
}
#endif
if(*pattern == '!')
{
negate_flag = 1; pattern++;
}
else { negate_flag = 0; }
i = wild_aux(pattern,string,1);
if(negate_flag) { i = !i; }
return(i ? ((last_matched << 8)|i) : 0);
}
unsigned int wild_aux(pattern,string,fnwc)
unsigned char *pattern,*string;
unsigned int fnwc; /* First Non-WildCard index */
{
loop:
if(!*pattern && !*string) /* if BOTH are in the end */
{ return(fnwc); }
/* Asterisk may match emptiness at the end of string: */
if((*pattern == '*') && !*string)
{ pattern++; goto loop; }
if(!*pattern || !*string) return(FALSE); /* If only OTHER is in the end */
if(*pattern == GROUP_BEG_CHAR)
{
if(group_match(&pattern,&string)) { goto jalava; }
else { return(FALSE); }
}
if(*pattern == '?') /* Question-mark in pattern ? */
{ pattern++; last_matched = *string++; goto loop; }
if((*pattern == '@') && last_matched)
{
if(*string == last_matched) { goto silava; }
else { goto sulava; }
}
if(*pattern == '*')
{
unsigned int muu,kuu;
/* Save the value of last_matched at this level... */
kuu = last_matched; /* if next level of recursion fucks it up. */
if(muu = wild_aux(pattern,string+1,fnwc)) { return(muu); }
last_matched = kuu; /* Restore value of last_matched at this level */
return(wild_aux(pattern+1,string,fnwc));
#ifdef VANHA_PASKA
/* It (*) matches several chars?: */
return(wild_aux(pattern,string+1,fnwc)
|| /* Matches one character: (not really necessary)
wild_aux(pattern+1,string+1,fnwc)
|| */ /* Or it matches 0 characters? */
wild_aux(pattern+1,string,fnwc));
#endif
}
else sulava: if(*pattern == *string) /* Same characters ? */
{
silava:
pattern++; string++;
jalava:
if(fnwc == 1) { fnwc = ((string - string_org)+1); }
goto loop;
}
else { return(FALSE); }
}
int group_match(pat_adr,str_adr)
unsigned char **pat_adr,**str_adr;
{
register unsigned char *pat;
register unsigned char c,positive_flag;
/* Take current char. from string, and advance string by one: */
c = *(*str_adr)++;
pat = (*pat_adr)+1; /* Skip group beginning char */
/* positive_flag is on if there is no negation-sign (^) in the beginning: */
if(*pat == '^') { positive_flag = 0; pat++; }
else { positive_flag = 1; }
while(*pat)
{
if(*pat == c) /* If found c from the pattern. */
{ /* If group ending char not found, then return false: */
if(!(pat = (unsigned char *) strchr((pat+1),GROUP_END_CHAR)))
{ return(FALSE); }
else
{
/* Set pattern to point one after group_end_char: */
nakki: *pat_adr = (pat+1);
if(positive_flag) /* Set last_matched char. */
{ last_matched = c; }
return(positive_flag);
}
}
if(*++pat == GROUP_END_CHAR)
{
/* If there was negation-sign (^) in the beginning, meaning that
positive_flag was 0, then set it to 1, and jump to nakki
to return true result. Because we are here it means that
c doesn't match to group, so if ^ in the beginning, then
return true.
*/ /* He he hee hee hee, some sick code again: */
positive_flag = !positive_flag;
goto nakki;
}
}
return(FALSE); /* If no group_ending_character */
}
GIDLIST consgl(gid,color,lista)
MYINT gid;
int color;
GIDLIST lista;
{
register GIDLIST z;
if(!(z = ((GIDLIST) malloc(sizeof(struct gid_list)))))
{
errlog((E1,
"**Internal error: cons(%lu,%d,lista): memory exhausted!\n",gid,color));
ertzu_exit(101);
}
z->gid = gid;
z->color = color;
z->next = lista;
return(z);
}
freegidlist(lista)
register GIDLIST lista;
{
register GIDLIST cdr_of_lista;
while(lista)
{
cdr_of_lista = cdr(lista);
free(lista);
lista = cdr_of_lista;
}
}
HELP()
{
FILE *fp;
MYINT linecount;
int arg_i,level,lev,i;
char nonstop=0;
char c;
char buf[MAXBUF+3];
/* Convert arguments to uppercase first: */
for(arg_i=1; *(cmds+arg_i); ) { conv_upper(*(cmds+arg_i++)); }
arg_i=1;
linecount = _morelines_;
if((cmdcnt > 1) && strequ(*(cmds+1),"-N"))
{
arg_i++;
cmdcnt--;
nonstop=1;
}
if(cmdcnt < 2) /* If no topic specified then list HELP HELP */
{
*(cmds+arg_i) = "HELP";
*(cmds+arg_i+1) = NULL;
cmdcnt++;
}
if(!(fp = myfopen(HELPFILE,"r")))
{ return(0); }
if(strequ(*(cmds+arg_i),"*"))
{ help_star(fp,nonstop); return(1); }
while(fgets(buf,MAXBUF,fp))
{
alku:
if((*buf == '-') && (level = match_topic(buf,arg_i)))
{
if(!nonstop && !--linecount)
{
c = tolower(more("--More-- <y,n,<space>,<cr>,q>"));
if(c == 'n') { linecount= _morelines_; continue; }
else if(c == 'q') { break; }
else if((c == ' ') || (c == 'y')) { linecount = _morelines_; }
else { linecount = 1; }
}
for(i=level; i--; ) { pout((" ")); } /* Print dashes (-) */
pout((buf+level)); /* as blanks. */
while(fgets(buf,MAXBUF,fp))
{
if((level >= (lev = getlevel(buf))) && lev)
{ goto alku; } /* If new topic which is superior to this. */
if(!nonstop && !--linecount)
{
c = tolower(more("--More-- <y,n,<space>,<cr>,q>"));
if(c == 'n') { linecount = _morelines_; break; }
else if(c == 'q') { goto ulos; }
else if((c == ' ') || (c == 'y')) { linecount = _morelines_; }
else { linecount = 1; }
}
if((*buf == '\f') && !nonstop) /* If CTRL-L encountered, */
{ /* Then ask more for next line, if not exited before that */
linecount=1;
}
for(i=lev; i--; ) { pout((" ")); }
pout((buf+lev));
}
}
}
ulos:
fclose(fp);
return(1);
}
help_star(fp,nonstop)
FILE *fp;
int nonstop;
{
MYINT linecount;
int i,level;
char *s;
char buf[MAXBUF+3];
linecount = _morelines_;
while(fgets(buf,MAXBUF,fp))
{
if(level = getlevel(buf))
{
s = skip_blankos(buf+level);
if(!s) { continue; }
if(!nonstop && !--linecount)
{
char c;
c = tolower(more("--More-- <y,n,<space>,<cr>,q>"));
if((c == 'n') || (c == 'q')) { break; }
else if((c == ' ') || (c == 'y')) { linecount = _morelines_; }
else { linecount = 1; }
}
for(i=level; i--; ) { pout((" ")); }
pout((s));
}
}
fclose(fp);
}
int match_topic(s,arg_i)
register char *s;
int arg_i;
{
register char *next;
int level,matched=0;
level = getlevel(s);
conv_upper(s);
s = skip_blankos(s+level);
while(s && *s)
{
if(next = strchr(s,','))
{ *next = '\0'; }
matched = match1_aux(s,arg_i);
if(next) { *next = ','; s = skip_blankos(next+1); }
else { s = NULL; }
if(matched) { return(level); }
}
return(0);
}
int match1_aux(s,arg_i)
register char *s;
register int arg_i;
{
char wordbuf[MAXBUF+3];
/* Loop so long as there is words in s: */
do
{
if(!*(cmds+arg_i)) { break; }
if(match2_aux(s,arg_i)) { return(1); }
} while((s = getfirstword(wordbuf,s)));
return(0);
}
int match2_aux(s,arg_i)
char *s;
register int arg_i;
{
char wordbuf[MAXBUF+3];
/* Loop through command line arguments: */
while(*(cmds+arg_i))
{
/* However, if no more words in s, then it's false: */
if(!(s = getfirstword(wordbuf,s))) { return(0); }
/* Or if differing word found: */
if(!strequ(*(cmds+arg_i),wordbuf)) { return(0); }
arg_i++;
}
return(1);
}
int getlevel(s)
register char *s;
{
register int level=0;
while(*s++ == '-') { level++; }
return(level);
}
int morefile(filename,nonstop)
char *filename;
int nonstop;
{
MYINT linecount;
FILE *fp;
char buf[MAXBUF+3];
if(!(fp = myfopen(filename,"Sr")))
{ return(0); }
linecount = _morelines_;
while(fgets(buf,MAXBUF,fp))
{
if(!nonstop && !--linecount)
{
char c;
c = tolower(more("--More-- <y,n,<space>,<cr>,q>"));
if((c == 'n') || (c == 'q')) { break; }
else if((c == ' ') || (c == 'y')) { linecount = _morelines_; }
else { linecount = 1; }
}
pout((buf));
}
fclose(fp);
return(1);
}
int ynq_aux(prompt,attr)
char *prompt;
int attr;
{
int c,sig;
/* First check if any new signals have been received: */
looop:
if(sig = _sig_received_)
{
_sig_received_ = 0;
pout(("\n"));
switch(sig)
{
case SIGINT:
{
pout(("?Please use the command QUIT for quitting!\n"));
break;
}
/* case SIG_GAME_STARTED: */
case SIG_GAME_FINISHED: { readgidlist(); }
/* case SIG_MESSAGE_SENT: { checkmessages(); } */
case SIG_MOVE_MADE: { checkmessages(); checknewmoves(0); }
}
}
#ifdef CURSES
if(attr) { attron(attr); }
pout((prompt));
if(attr) { attroff(attr); }
/* Some curses functions: */
cbreak(); /* Return character immediately, without waiting CR. */
noecho(); /* Do not echo it. */
/* When waiting for input signals are acknowledged immediately: */
_sig_immediately_ = 1;
if(_sig_received_) { _sig_immediately_ = 0; goto looop; }
c = getch(); /* Get the character. */
_sig_immediately_ = 0;
if(c == EOF) { goto looop; }
echo(); /* Then put echo, and */
nocbreak(); /* cooked mode back. */
/* fout((OB,"Debugging: c = %u.\n",c)); */
if(!attr) { pout(("\n")); }
return(c);
#else
if(attr) { fout((OB,"\033[%dm",attr)); }
pout((prompt));
if(attr) { fout((OB,"\033[0m")); } /* Clear video modes. */
/* When waiting for input signals are acknowledged immediately: */
_sig_immediately_ = 1;
if(_sig_received_) { _sig_immediately_ = 0; goto looop; }
c = getch(); /* Get the character. */
_sig_immediately_ = 0;
if(c == EOF) { goto looop; }
if(!attr) { pout(("\n")); } /* Some ugly kludge I guess? */
return(c);
/* When waiting for input signals are acknowledged immediately:
(some old code, commented out):
_sig_immediately_ = 1;
if(_sig_received_) { _sig_immediately_ = 0; goto looop; }
if(!fgets(input_buf,MAXBUF,input))
{
_sig_immediately_ = 0;
if(feof(input)) { return(0); }
goto looop;
}
_sig_immediately_ = 0;
return(tolower(*input_buf));
*/
#endif
}
int more(prompt)
char *prompt;
{
int len;
char c;
char blankos[MAXBUF+3];
#ifdef CURSES
c = ynq_aux(prompt,A_REVERSE);
memset(blankos,' ',(len = strlen(prompt)));
blankos[len] = '\0'; /* And terminate. */
fout((OB,"\r%s\r",blankos)); /* Overwrite the prompt string. */
#else
/* c = ynq(prompt); Old code, replaced by this: */
c = ynq_aux(prompt,ANSI_REVERSE);
memset(blankos,' ',(len = strlen(prompt)));
blankos[len] = '\0'; /* And terminate. */
fout((OB,"\r%s\r",blankos)); /* Overwrite the prompt string. */
#endif
return(c);
}
print_err(s,to_user_too)
char *s;
int to_user_too;
{
if(to_user_too) { pout((s)); }
fprintf(err_fp,"%s %lu %s %d %lu %lu %lu %lu %s",
get_timebuf(),_ownplid_,_ownname_,_owncolor_,_gid_,_movesmade_,
_blackplid_,_whiteplid_,
s);
fflush(err_fp);
}
init_screen()
{
#ifdef CURSES
int i;
initscr(); /* For curses. */
start_color();
scrollok(stdscr,TRUE);
idlok(stdscr,TRUE);
_morelines_ = LINES-1; /* LINES is curses variable. */
for(i=COLOR_BLACK; i <= COLOR_WHITE; i++)
{ /* Initialize eight color pairs, so that background color is
always black (zero): */
init_pair((i+1),i,0);
}
#endif
}
end_screen()
{
#ifdef CURSES
endwin(); /* For curses. */
#endif
}
/* Like fseek, but with error checking: */
int myfseek(fp,offset,origin,funname)
FILE *fp;
register long offset;
register int origin;
char *funname;
{
int fseek();
register int result;
if(result = fseek(fp,offset,origin))
{
errlog((E1,
"**Internal error in myfseek(fp,%ld,%d,%s) -> %d, errno=%d\n",
offset,origin,funname,result,errno));
ertzu_exit(101);
}
return(result);
}
myrewind(fp,funname)
FILE *fp;
char *funname;
{
int status;
if((status = fseek(fp,0L,0))) /* Try to rewind fp to beginning. */
{
errlog((E1,
"**Internal error in myrewind (called from %s): fseek=%d errno=%d\n",
funname,status,errno));
ertzu_exit(101);
}
}
int myunlink(filename,funname)
char *filename,*funname;
{
int status;
filename = get_whole_filename(filename);
if((status = unlink(filename))) /* Try to delete filename. */
{
errlog((E1,
"**Internal error in myunlink(%s,%s)=%d errno=%d\n",
filename,funname,status,errno));
}
return(status);
}
FILE *myfopen(filename,mode)
char *filename,*mode;
{
FILE *fp;
char silent=0;
#ifdef TURBOC
char newmode[11];
strcpy(newmode,mode);
strcat(newmode,"b"); /* Turbo-C wants that b as binary mode. */
mode = newmode;
#endif
filename = get_whole_filename(filename);
if(toupper(*mode) == 'S')
{
silent=1;
mode++;
}
if(!(fp = fopen(filename,mode)))
{
if(!silent)
{
errlog((E1,"**Can't open file %s with the mode \"%s\" !\n",
filename,mode));
}
return(NULL);
}
else { return(fp); }
}
#ifdef NOF_LOCK
FILE *lockfopen(char *filename,char *mode)
{ return(myfopen(filename,(isupper(*mode) ? (mode+1) : mode))); }
int lockfclose(FILE *fp) { return(fclose(fp)); }
#else
FILE *lockfopen(filename,mode)
char *filename,*mode;
{
int i;
char silent=0,dont_sleep=0;
FILE *fp;
#ifdef TURBOC
char newmode[11];
strcpy(newmode,mode);
strcat(newmode,"b"); /* Turbo-C wants that b as binary mode. */
mode = newmode;