00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "setup.h"
00024
00025 #if EMACS_EDITOR && ! RUN_TIME
00026
00027 #define _EDTERM_SOURCE_
00028 #include "ed.h"
00029
00030 #include <stdlib.h>
00031
00032 #if ANSI
00033 static void ansimove(int,int);
00034 static void ansieeol(void);
00035 static void ansieeop(void);
00036 static void ansibeep(void);
00037 static void ansiparm(int);
00038 static void ansiopen(void);
00039 #endif
00040
00041 #if VT52
00042 static void vt52move(int,int);
00043 static void vt52eeol(void);
00044 static void vt52eeop(void);
00045 static void vt52beep(void);
00046 static void vt52parm(int);
00047 static void vt52open(void);
00048 #endif
00049
00050 #if IBM_PC
00051 static void pc_open(void);
00052 static int scinit(int);
00053 static int getboard(void);
00054 static int pc_getc(void);
00055 static void pc_putc(int);
00056 static void pc_move(int,int);
00057 static void pc_eeol(void);
00058 static void pc_eeop(void);
00059 static void pc_beep(void);
00060 #endif
00061
00062 #if TERMCAP
00063 #include <termcap.h>
00064
00065
00066
00067
00068
00069
00070 static void tcapmove(int,int);
00071 static void tcapeeol(void);
00072 static void tcapeeop(void);
00073 static void tcapbeep(void);
00074 static void tcapopen(void);
00075 static void putpad(char *);
00076 #endif
00077
00078
00079
00080
00081
00082
00083 #if ANSI
00084
00085
00086
00087
00088
00089
00090
00091 #define NROW 23
00092 #define NCOL 77
00093 #define BEL 0x07
00094 #define ESC 0x1B
00095
00096
00097
00098
00099
00100 TERM term = {
00101 NROW-1,
00102 NCOL,
00103 ansiopen,
00104 ttclose,
00105 ttgetc,
00106 ttputc,
00107 ttflush,
00108 ansimove,
00109 ansieeol,
00110 ansieeop,
00111 ansibeep
00112 };
00113
00114 static void ansimove(
00115 int row,
00116 int col)
00117 {
00118 ttputc(ESC);
00119 ttputc('[');
00120 ansiparm(row+1);
00121 ttputc(';');
00122 ansiparm(col+1);
00123 ttputc('H');
00124 }
00125
00126 static void ansieeol()
00127 {
00128 ttputc(ESC);
00129 ttputc('[');
00130 ttputc('K');
00131 }
00132
00133 static void ansieeop()
00134 {
00135 ttputc(ESC);
00136 ttputc('[');
00137 ttputc('J');
00138 }
00139
00140 static void ansibeep()
00141 {
00142 ttputc(BEL);
00143 ttflush();
00144 }
00145
00146 static void ansiparm(
00147 int n)
00148 {
00149 register int q;
00150
00151 q = n/10;
00152 if (q != 0)
00153 ansiparm(q);
00154 ttputc((n%10) + '0');
00155 }
00156
00157 static void ansiopen()
00158 {
00159 #if UNIX_7 || UNIX_V || LINUX || DARWIN
00160 register char *cp;
00161
00162 if ((cp = getenv("TERM")) == NULL) {
00163 puts("Shell variable TERM not defined!");
00164 exit(1);
00165 }
00166 if (strcmp(cp, "vt100") != 0) {
00167 puts("Terminal type not 'vt100'!");
00168 exit(1);
00169 }
00170 #endif
00171 ttopen();
00172 }
00173
00174 #endif
00175
00176
00177
00178
00179
00180
00181 #if VT52
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 #define NROW 24
00194 #define NCOL 80
00195 #define BIAS 0x20
00196 #define ESC 0x1B
00197 #define BEL 0x07
00198
00199
00200
00201
00202
00203
00204 globle TERM term = {
00205 NROW-1,
00206 NCOL,
00207 vt52open,
00208 ttclose,
00209 ttgetc,
00210 ttputc,
00211 ttflush,
00212 vt52move,
00213 vt52eeol,
00214 vt52eeop,
00215 vt52beep
00216 };
00217
00218 static void vt52move(
00219 int row,
00220 int col)
00221 {
00222 ttputc(ESC);
00223 ttputc('Y');
00224 ttputc(row+BIAS);
00225 ttputc(col+BIAS);
00226 }
00227
00228 static void vt52eeol()
00229 {
00230 ttputc(ESC);
00231 ttputc('K');
00232 }
00233
00234 static void vt52eeop()
00235 {
00236 ttputc(ESC);
00237 ttputc('J');
00238 }
00239
00240 static void vt52beep()
00241 {
00242 #ifdef BEL
00243 ttputc(BEL);
00244 ttflush();
00245 #endif
00246 }
00247
00248 static void vt52open()
00249 {
00250 #if UNIX_7 || UNIX_V || LINUX || DARWIN
00251 register char *cp;
00252
00253 if ((cp = getenv("TERM")) == NULL) {
00254 puts("Shell variable TERM not defined!");
00255 exit(1);
00256 }
00257 if (strcmp(cp, "vt52") != 0 && strcmp(cp, "z19") != 0) {
00258 puts("Terminal type not 'vt52'or 'z19' !");
00259 exit(1);
00260 }
00261 #endif
00262 ttopen();
00263 }
00264
00265 #endif
00266
00267
00268
00269
00270
00271
00272 #if IBM_PC
00273
00274
00275
00276
00277 #if WIN_MVC || WIN_BTC || WIN_GCC
00278 #include <dos.h>
00279
00280 #if WIN_MVC || WIN_GCC
00281 #include <conio.h>
00282 #endif
00283
00284 #define NROW 25
00285 #define NCOL 80
00286 #define BEL 0x07
00287 #define ESC 0x1B
00288 #define SPACE 32
00289
00290 #define SCADC 0xb8000000L
00291 #define SCADM 0xb0000000L
00292
00293 #define MONOCRSR 0x0B0D
00294 #define CGACRSR 0x0607
00295
00296 #define CDCGA 0
00297 #define CDMONO 1
00298 #define CDSENSE 9
00299
00300 #define NDRIVE 3
00301
00302
00303
00304
00305
00306
00307 globle TERM term = {
00308 NROW-1,
00309 NCOL,
00310 pc_open,
00311 ttclose,
00312 pc_getc,
00313 pc_putc,
00314 ttflush,
00315 pc_move,
00316 pc_eeol,
00317 pc_eeop,
00318 pc_beep
00319 };
00320
00321 static int dtype = -1;
00322
00323 static long scadd;
00324 static int *scptr[NROW];
00325 static unsigned int sline[NCOL];
00326
00327 static union REGS rg;
00328
00329 static void pc_open()
00330 {
00331 scinit(CDSENSE);
00332 ttopen();
00333 }
00334
00335 static int scinit(
00336
00337 int type)
00338
00339 {
00340 union {
00341 long laddr;
00342 int *paddr;
00343 } addr;
00344 int i;
00345
00346
00347 if (type == CDSENSE)
00348 type = getboard();
00349
00350
00351 if (dtype == type)
00352 return(TRUE);
00353
00354 switch (type) {
00355 case CDMONO:
00356 scadd = SCADM;
00357 break;
00358
00359 case CDCGA:
00360 scadd = SCADC;
00361 break;
00362
00363 }
00364 dtype = type;
00365
00366
00367 for (i = 0; i < NROW; i++) {
00368 addr.laddr = scadd + (long)(NCOL * i * 2);
00369 scptr[i] = addr.paddr;
00370 }
00371 return(TRUE);
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 static int getboard()
00387 {
00388 int type;
00389
00390 type = CDCGA;
00391 int86(0x11, &rg, &rg);
00392 if ((((rg.x.ax >> 4) & 3) == 3))
00393 type = CDMONO;
00394 return(type);
00395 }
00396
00397 static int pc_getc()
00398 {
00399 int intrpt = 22;
00400
00401 rg.h.al = 0;
00402 rg.h.ah = 0;
00403
00404 int86(intrpt, &rg, &rg);
00405
00406 if(rg.h.al != 0)
00407 return(rg.h.al);
00408 else {
00409 switch(rg.h.ah) {
00410 case 3 :
00411 return(COTL_AT_SIGN);
00412 case 71 :
00413 return(HOME_KEY);
00414 case 72 :
00415 return(UP_ARROW);
00416 case 73 :
00417 return(PGUP_KEY);
00418 case 75 :
00419 return(LEFT_ARROW);
00420 case 77 :
00421 return(RIGHT_ARROW);
00422 case 79 :
00423 return(END_KEY);
00424 case 80 :
00425 return(DOWN_ARROW);
00426 case 81 :
00427 return(PGDN_KEY);
00428 case 115 :
00429 return(COTL_LEFT_ARROW);
00430 case 116 :
00431 return(COTL_RIGHT_ARROW);
00432 default :
00433 return(BADKEY);
00434 }
00435 }
00436 }
00437
00438 static void pc_putc(
00439 int c)
00440 {
00441 rg.h.ah = 14;
00442 rg.h.al = (unsigned char) c;
00443 rg.h.bh = 0;
00444 rg.h.bl = 0x07;
00445 int86(0x10, &rg, &rg);
00446 }
00447
00448 static void pc_move(
00449 int row,
00450 int col)
00451 {
00452 rg.h.ah = 2;
00453 rg.h.dl = (unsigned char) col;
00454 rg.h.dh = (unsigned char) row;
00455 rg.h.bh = 0;
00456 int86(0x10, &rg, &rg);
00457 }
00458
00459 static void pc_eeol()
00460 {
00461 unsigned int attr;
00462 unsigned int *lnptr;
00463 int i;
00464 int ccol;
00465 int crow;
00466
00467
00468 rg.h.ah = 3;
00469 rg.h.bh = 0;
00470 int86(0x10, &rg, &rg);
00471 ccol = rg.h.dl;
00472 crow = rg.h.dh;
00473
00474
00475 attr = 0x0700;
00476 lnptr = &sline[0];
00477 for (i=0; i < term.t_ncol; i++)
00478 *lnptr++ = SPACE | attr;
00479
00480 if (dtype == CDCGA) {
00481
00482 while ((inp(0x3da) & 8))
00483 ;
00484
00485
00486 while ((inp(0x3da) & 8) == 0)
00487 ;
00488 }
00489
00490
00491 memmove(scptr[crow]+ccol, &sline[0], (term.t_ncol-ccol)*2);
00492 }
00493
00494 static void pc_eeop()
00495 {
00496 int attr;
00497
00498 rg.h.ah = 6;
00499 rg.h.al = 0;
00500 rg.x.cx = 0;
00501 rg.x.dx = (term.t_nrow << 8) | (term.t_ncol - 1);
00502
00503 attr = 0x07;
00504 rg.h.bh = (unsigned char) attr;
00505 int86(0x10, &rg, &rg);
00506 }
00507
00508 static void pc_beep()
00509 {
00510 pc_putc(BEL);
00511 ttflush();
00512 }
00513
00514 #endif
00515 #endif
00516
00517
00518
00519
00520
00521
00522
00523 #if TERMCAP
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533 #define NROW 24
00534 #define NCOL 80
00535 #define BEL 0x07
00536 #define ESC 0x1B
00537
00538 #define TCAPSLEN 315
00539
00540 static char tcapbuf[TCAPSLEN];
00541 static char
00542 *CM,
00543 *CE,
00544
00545 *CD;
00546
00547
00548 globle TERM term = {
00549 NROW-1,
00550 NCOL,
00551 tcapopen,
00552 ttclose,
00553 ttgetc,
00554 ttputc,
00555 ttflush,
00556 tcapmove,
00557 tcapeeol,
00558 tcapeeop,
00559 tcapbeep
00560 };
00561
00562 static void tcapopen()
00563 {
00564 char *t, *p;
00565 char tcbuf[1024];
00566 char *tv_stype;
00567 char err_str[72];
00568
00569 if ((tv_stype = getenv("TERM")) == NULL)
00570 {
00571 puts("Environment variable TERM not defined!");
00572 exit(1);
00573 }
00574
00575 if((tgetent(tcbuf, tv_stype)) != 1)
00576 {
00577 gensprintf(err_str, "Unknown terminal type %s!", tv_stype);
00578 puts(err_str);
00579 exit(1);
00580 }
00581
00582 p = tcapbuf;
00583 t = tgetstr("pc", &p);
00584 if(t)
00585 PC = *t;
00586
00587 CD = tgetstr("cd", &p);
00588 CM = tgetstr("cm", &p);
00589 CE = tgetstr("ce", &p);
00590 UP = tgetstr("up", &p);
00591
00592 if(CD == NULL || CM == NULL || CE == NULL || UP == NULL)
00593 {
00594 puts("Incomplete termcap entry\n");
00595 exit(1);
00596 }
00597
00598 if (p >= &tcapbuf[TCAPSLEN])
00599 {
00600 puts("Terminal description too big!\n");
00601 exit(1);
00602 }
00603 ttopen();
00604 }
00605
00606 static void tcapmove(
00607 int row,
00608 int col)
00609 {
00610 putpad(tgoto(CM, col, row));
00611 }
00612
00613 static void tcapeeol()
00614 {
00615 putpad(CE);
00616 }
00617
00618 static void tcapeeop()
00619 {
00620 putpad(CD);
00621 }
00622
00623 static void tcapbeep()
00624 {
00625 ttputc(BEL);
00626 }
00627
00628 static void putpad(
00629 char *str)
00630 {
00631 tputs(str, 1, (int (*)(int)) ttputc);
00632 }
00633
00634 #endif
00635
00636 #endif