File: asc_unix.inc

package info (click to toggle)
mgt 2.31-7
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 460 kB
  • ctags: 582
  • sloc: ansic: 4,852; sh: 411; pascal: 329; makefile: 88; csh: 3
file content (207 lines) | stat: -rw-r--r-- 4,523 bytes parent folder | download | duplicates (6)
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
/* "mgt" Copyright (c) 1991 Shodan  */


#include <curses.h>

char chars[] = "#O=+-.+|-++++";
#define doredraw() clearok(stdscr, TRUE), refresh(),clearok(stdscr, FALSE)

#define openwin() win=subwin(stdscr,WINHIGH+1,WINWIDE+1,WINTOP,WINLEFT)
/* ,wclear(win) */
#define fixcursor()
#define specialKeysEdit(c) (c)
#define closewin() delwin(win)
#define getKey getch
#define getKeyIdle getch
#define getKeyLine getch
#define getKeyScore getch
#define specialHelp()
#define preserveScreen() WINDOW *wi;wi=newwin(0,0,0,0);overwrite(stdscr,wi);touchwin(stdscr)
#define restoreScreen() overwrite(wi,stdscr);refresh();delwin(wi)

/* #define saveRegion(x1,y1,dx,dy) { WINDOW *ww;
 * ww=subwin(stdscr,dy,dx,y1,x1);wi=newwin(dy,dx,y1,x1);overwrite(ww,wi);delwin(
 * ww);} #define restoreRegion(x1,y1,dx,dy)
 * overwrite(wi,stdscr);refresh();delwin(wi) */

#define saveRegion(a,b,c,d) wi=newwin(0,0,0,0);overwrite(stdscr,wi);touchwin(stdscr)
#define restoreRegion(a,b,c,d) restoreScreen()
#define dopris() printw(" %c %c: %d %c    %c %c: %d %c ", a, chars[(int)\
          CHAR_BLACK], prisoners[0], b, c, \
	  chars[(int) CHAR_WHITE], prisoners[1], d)
#define mainwin()
#define unmainwin()

static char getKeyEdit()
{
   char c;
   c = getch();
   if (!edvi && (c == ESC)) {
      c = 128 | getch();
   }
   if (c == '\333') {		/* ('[' | 128) */
      c = getch();
      if (c == 'A')
	 c = edcmds[EDUP];
      if (c == 'B')
	 c = edcmds[EDDOWN];
      if (c == 'C')
	 c = edcmds[EDRIGHT];
      if (c == 'D')
	 c = edcmds[EDLEFT];
   }
   return c;
}

static void drawPrisoners()
{
   extern int ispl;
   char a, b, c, d;
   if (curPlayer == t_Black) {
      a = ispl ? '}' : '>';
      b = ispl ? '{' : '<';
      c = d = ' ';
   } else {
      a = b = ' ';
      c = ispl ? '}' : '>';
      d = ispl ? '{' : '<';
   }
   move(23, 50);
   printw("%c %c: %d %c    %c %c: %d %c ", a, chars[(int)
					      CHAR_BLACK], prisoners[0], b, c,
	  chars[(int) CHAR_WHITE], prisoners[1], d);
   clrtoeol();
}



static void initAscii()
{
   fixkeys();
   fixedkeys();
   initscr();
   noecho();
   crmode();
}



static void plotMarkAscii(b, i, j)
pBoard b;
int i, j;
{
   void drawPiece();
   piece p;
   p = boardGet(b, i, j);
   inverseFlag = !inverseFlag;

   drawPiece(i, j, (p == P_NOTHING ? boardPiece(i, j) :
		    (p == P_BLACK ? chars[(int) CHAR_BLACK] :
		     chars[(int) CHAR_WHITE])));
   inverseFlag = !inverseFlag;
}

static int xpos(win)
WINDOW *win;
{
   int x, y;
   getyx(win, y, x);
   return x;
}


static int ypos(win)
WINDOW *win;
{
   int y, x;
   getyx(win, y, x);
   return y;
}


static command specialKeysIdle(c)
char c;
{
   return (command) 0;
}

static void set_inverse()
{

   if (inverseFlag)
      standout();
}

static void unset_inverse()
{
   standend();
}



static void drawPiece(i, j, c)
int i, j;
char c;
{
   move(TOP + j, LEFT + 2 * i);
   set_inverse();
   addch(c);
   unset_inverse();
}


static void initBoardAscii()
{
   int i, j;

   clear();
   if (inverseFlag) {
      set_inverse();
      for (i = LEFT + 1; i < LEFT + boardsize * 2 - 2; i += 2)
	 for (j = TOP; j < TOP + boardsize; j++)
	    mvaddch(j, i, ' ');
      unset_inverse();
   }
   for (i = boardsize; i--;) {
      /* left */
      move(TOP + i, LEFT - 3);
      printw("%2d", boardsize - i);
      set_inverse();
      addch(chars[(int) CHAR_VERT]);

      /* right */
      move(TOP + i, LEFT + boardsize * 2 - 1);
      addch(chars[(int) CHAR_VERT]);
      unset_inverse();
      printw("%2d", boardsize - i);
      /* printw("%2d%c", boardsize - i, chars[(int) CHAR_VERT]); */

      /* top */
      move(TOP - 2, LEFT + i * 2);
      addch(xAxisChars[i]);
      move(TOP - 1, LEFT + i * 2 - 1);
      set_inverse();
      printw("%c%c", chars[(int) CHAR_HORIZ], chars[(int) CHAR_HORIZ]);

      /* bottom */
      move(TOP + boardsize, LEFT + i * 2 - 1);
      printw("%c%c", chars[(int) CHAR_HORIZ], chars[(int) CHAR_HORIZ]);
      unset_inverse();
      move(TOP + boardsize + 1, LEFT + i * 2);
      addch(xAxisChars[i]);
      for (j = boardsize; j--;)
	 drawPiece(i, j, boardPiece(i, j));
   }
   set_inverse();
   move(TOP - 1, LEFT - 1);
   addch(chars[(int) CHAR_UPLEFT]);
   move(TOP - 1, LEFT + boardsize * 2 - 1);
   addch(chars[(int) CHAR_UPRIGHT]);
   move(TOP + boardsize, LEFT - 1);
   addch(chars[(int) CHAR_DOWNLEFT]);
   move(TOP + boardsize, LEFT + boardsize * 2 - 1);
   addch(chars[(int) CHAR_DOWNRIGHT]);
   unset_inverse();
   mvaddstr(COMMAND_Y, COMMAND_X, helpMsg);
   printstatus(name_buf);
}