Debian Codegraph @

terps/tads/tads2/trcolor.c

raw symbols SCIP
1 #ifdef RCSID
2 static char RCSid[] =
3 "$Header: d:/cvsroot/tads/TADS2/TRCOLOR.C,v 1.2 1999/05/17 02:52:13 MJRoberts Exp $";
4 #endif
5
6 /*
7 * Copyright (c) 1993, 2002 Michael J. Roberts. All Rights Reserved.
8 *
9 * Please see the accompanying license file, LICENSE.TXT, for information
10 * on using and copying this software.
11 */
12 /*
13 Name
14 trcolor.c - set TADS Run-time color scheme
15 Function
16 This is a little tool that lets the user interactively specify the
17 color scheme used by the runtime.
18 Notes
19 This program creates or modifies a file called TRCOLOR.DAT in the current
20 directory. This file is read by the runtime at startup to set the color
21 scheme.
22
23 This tool is DOS-specific - it uses the DOS oss-layer display routines
24 directly (these routines are not part of any portable interface and
25 exist only on DOS and some derivative ports that use the DOS os-layer
26 implementation).
27 Modified
28 04/06/93 MJRoberts - Creation
29 */
30
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
34
35 #ifndef DJGPP
36 #include <dos.h>
37 #include <conio.h>
38 #include <bios.h>
39 #endif /* DJGPP */
40
41 #include "os.h"
42
43 #define TRUE 1
44 #define FALSE 0
45
46 int usebios = 1;
47 char *scrbase = (char *)0xb8000000;
48
49 /* color box location */
50 #define CYOFS 6
51 #define CXOFS 48
52
53 /* title location */
54 #define TYOFS 8
55 #define TXOFS 17
56
57 /* title normal/highlight color */
58 #define TNORMAL 7
59 #define THILITE 0x70
60
61 /* number of colors */
62 #define COLORCNT 3
63
64 static void hilite(int cur, int flag)
65 {
66 ossdsp((cur / 16) + CYOFS, (cur % 16) + CXOFS,
67 cur + (flag ? 128 : 0), flag ? "X" : "+");
68 }
69
70 static void hilitetitle(int num, char *text, int color, int flag)
71 {
72 ossdsp(TYOFS + num*2, TXOFS - 3, TNORMAL, flag ? ">>" : " ");
73 ossdsp(TYOFS + num*2, TXOFS, color, text);
74 ossdsp(TYOFS + num*2, TXOFS + strlen(text) + 1, TNORMAL,
75 flag ? "<<" : " ");
76 }
77
78
79 int main(int argc, char **argv)
80 {
81 FILE *fp;
82 int i;
83 static char *title[] = { "Normal Text", "Bold Text", "Status Line" };
84 int colors[COLORCNT];
85 int cur;
86
87 /* initialize the console */
88 oss_con_init();
89
90 /* use a different default color scheme for monochrome */
91 if (ossmon())
92 colors[2] = 0x70;
93 else
94 colors[2] = 23;
95 colors[0] = 7;
96 colors[1] = 15;
97
98 /* read existing trcolor.dat if present */
99 if (fp = fopen("trcolor.dat", "r"))
100 {
101 for (i = 0 ; i < COLORCNT ; ++i)
102 {
103 char buf[128];
104
105 fgets(buf, sizeof(buf), fp);
106 colors[i] = atoi(buf);
107 }
108 fclose(fp);
109 }
110
111 /* set up the screen */
112 ossclr(0, 0, 25, 80, 0);
113 ossdsp(3, 8, TNORMAL,
114 "TADS Runtime Color Setup - Copyright (c) 1993, 2007 "
115 "Michael J. Roberts"); /* copyright-date-string */
116 for (i = 0 ; i < 128 ; ++i)
117 ossdsp((i / 16) + CYOFS, (i % 16) + CXOFS, i, "+");
118 for (i = 0 ; i < COLORCNT ; ++i)
119 hilitetitle(i, title[i], colors[i], i == 0);
120
121 /* show instructions */
122 ossdsp(16, 17, TNORMAL, "Use Tab and Shift-Tab to select text types.");
123 ossdsp(17, 17, TNORMAL, "Use cursor arrows to change colors.");
124 ossdsp(18, 17, TNORMAL, "Press S to save changes and exit.");
125 ossdsp(19, 17, TNORMAL, "Press Esc or Q to quit without saving changes.");
126
127 /* hilite current color */
128 hilite(colors[0], TRUE);
129
130 for (cur = 0 ;; )
131 {
132 ossloc(0, 0);
133 switch(getch())
134 {
135 case 0:
136 switch(getch())
137 {
138 case 0115: /* right arrow */
139 hilite(colors[cur], FALSE);
140 if (++colors[cur] >= 128) colors[cur] = 0;
141 hilite(colors[cur], TRUE);
142 hilitetitle(cur, title[cur], colors[cur], TRUE);
143 break;
144
145 case 0113: /* left arrow */
146 hilite(colors[cur], FALSE);
147 if (--colors[cur] <= 0) colors[cur] = 127;
148 hilite(colors[cur], TRUE);
149 hilitetitle(cur, title[cur], colors[cur], TRUE);
150 break;
151
152 case 0120: /* down arrow */
153 hilite(colors[cur], FALSE);
154 if ((colors[cur] += 16) >= 128) colors[cur] -= 128;
155 hilite(colors[cur], TRUE);
156 hilitetitle(cur, title[cur], colors[cur], TRUE);
157 break;
158
159 case 0110: /* up arrow */
160 hilite(colors[cur], FALSE);
161 if ((colors[cur] -= 16) <= 0) colors[cur] += 128;
162 hilite(colors[cur], TRUE);
163 hilitetitle(cur, title[cur], colors[cur], TRUE);
164 break;
165
166 case 15: /* backtab */
167 /* unhilite current color */
168 hilitetitle(cur, title[cur], colors[cur], FALSE);
169 hilite(colors[cur], FALSE);
170
171 /* select new color and hilite it */
172 if (--cur < 0) cur = COLORCNT - 1;
173 hilitetitle(cur, title[cur], colors[cur], TRUE);
174 hilite(colors[cur], TRUE);
175 break;
176 }
177 break;
178
179 case 9:
180 /* unhilite current color */
181 hilitetitle(cur, title[cur], colors[cur], FALSE);
182 hilite(colors[cur], FALSE);
183
184 /* select new color and hilite it */
185 if (++cur >= COLORCNT) cur = 0;
186 hilitetitle(cur, title[cur], colors[cur], TRUE);
187 hilite(colors[cur], TRUE);
188 break;
189
190 case 27:
191 case 'q':
192 case 'Q':
193 ossloc(24, 0);
194 oss_con_uninit();
195 printf("\n\nNo changes saved.\n");
196 exit(0);
197
198 case 's':
199 case 'S':
200 ossloc(24, 0);
201 printf("\n\n");
202 if (!(fp = fopen("trcolor.dat", "w")))
203 {
204 oss_con_uninit();
205 printf("Error - unable to create TRCOLOR.DAT\n");
206 exit(1);
207 }
208
209 for (i = 0 ; i < COLORCNT ; ++i)
210 fprintf(fp, "%d\n", colors[i]);
211 fclose(fp);
212
213 oss_con_uninit();
214 printf("TRCOLOR.DAT successfully updated!\n");
215 exit(0);
216 }
217 }
218
219 return 0;
220 }