Project

General

Profile

mined-unifdef.diff

mined unifdef patch - bcallah, 04/26/2018 08:32 PM

View differences:

bin/mined/mined.h
38 38
 *				Mined.h					  *
39 39
 *========================================================================*/
40 40

  
41
#define INTEL	1
42
#define CHIP	INTEL
43
#define ASSUME_CONS25
44
#define ASSUME_XTERM
45

  
46 41
#include <sys/types.h>
47 42
#include <fcntl.h>
48 43
#include <stdlib.h>
49 44
#include <unistd.h>
50 45
#include <limits.h>
51 46

  
52
#ifndef YMAX
53
#ifdef UNIX
54
#include <stdio.h>
55
#undef putchar
56
#undef getchar
57
#undef NULL
58
#undef EOF
59
extern char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
60
#define YMAX		49
61
#else
62 47
#define YMAX		24		/* Maximum y coordinate starting at 0 */
63 48
/* Escape sequences. */
64 49
extern const char *enter_string;	/* String printed on entering mined */
......
68 53
extern const char *pos_string;		/* Absolute cursor positioning */
69 54
#define X_PLUS	' '		/* To be added to x for cursor sequence */
70 55
#define Y_PLUS	' '		/* To be added to y for cursor sequence */
71
#endif /* UNIX */
72 56

  
73 57
#define XMAX		79		/* Maximum x coordinate starting at 0*/
74 58
#define SCREENMAX	(YMAX - 1)	/* Number of lines displayed */
......
94 78

  
95 79
#define STD_OUT	 	1		/* File descriptor for terminal */
96 80

  
97
#if (CHIP == INTEL)
98
#define MEMORY_SIZE	(50 * 1024)	/* Size of data space to malloc */
99
#endif
100

  
101 81
#define REPORT	2			/* Report change of lines on # lines */
102 82

  
103 83
typedef int FLAG;
......
277 257
 */
278 258
#define get_shift(cnt)		((cnt) & DUMMY_MASK)
279 259

  
280
#endif /* YMAX */
281

  
282 260
/* mined1.c */
283 261

  
284 262
void	 FS(int);
bin/mined/mined1.c
487 487

  
488 488
/* Free old linked list, initialize global variables and load new file */
489 489
  initialize();
490
#ifdef UNIX
491
  tputs(CL, 0, _putchar);
492
#else
493 490
  string_print (enter_string);
494
#endif /* UNIX */
495 491
  load_file(new_file[0] == '\0' ? NIL_PTR : new_file);
496 492
}
497 493

  
......
654 650
	clear_status ();
655 651
  set_cursor(0, ymax);
656 652
  if (revfl == ON) {		/* Print rev. start sequence */
657
#ifdef UNIX
658
	tputs(SO, 0, _putchar);
659
#else
660 653
	string_print(rev_video);
661
#endif /* UNIX */
662 654
	stat_visible = TRUE;
663 655
  }
664 656
  else				/* Used as clear_status() */
......
670 662
	ret = input(inbuf, statfl);
671 663

  
672 664
  /* Print normal video */
673
#ifdef UNIX
674
  tputs(SE, 0, _putchar);
675
  tputs(CE, 0, _putchar);
676
#else
677 665
  string_print(normal_video);
678 666
  string_print(blank_line);	/* Clear the rest of the line */
679
#endif /* UNIX */
680 667
  if (inbuf != NIL_PTR)
681 668
	set_cursor(0, ymax);
682 669
  else
......
901 888
void
902 889
set_cursor(int nx, int ny)
903 890
{
904
#ifdef UNIX
905
  tputs(tgoto(CM, nx, ny), 0, _putchar);
906
#else
907 891
  char text_buf[10];
908 892

  
909 893
  build_string(text_buf, pos_string, ny+1, nx+1);
910 894
  string_print(text_buf);
911
#endif /* UNIX */
912 895
}
913 896

  
914 897
/*
......
928 911
int
929 912
getchar(void)
930 913
{
931
#ifdef UNIX
932
  return (_getchar() & 0377);
933
#else
934 914
  char c;
935 915

  
936 916
  if (read(input_fd, &c, 1) != 1 && quit == FALSE)
937 917
	panic("Can't read one char from fd #0");
938 918

  
939 919
  return c & 0377;
940
#endif /* UNIX */
941 920
}
942 921

  
943 922
/*
......
967 946
/* Print the blank lines (if any) */
968 947
  if (loading == FALSE) {
969 948
	while (count-- >= 0) {
970
#ifdef UNIX
971
		tputs(CE, 0, _putchar);
972
#else
973 949
		string_print(blank_line);
974
#endif /* UNIX */
975 950
		putchar('\n');
976 951
	}
977 952
  }
......
1038 1013
	}
1039 1014
	else {
1040 1015
		if (*textp >= '\01' && *textp <= '\037') {
1041
#ifdef UNIX
1042
			tputs(SO, 0, _putchar);
1043
#else
1044 1016
			string_print (rev_video);
1045
#endif /* UNIX */
1046 1017
			putchar(*textp++ + '\100');
1047
#ifdef UNIX
1048
			tputs(SE, 0, _putchar);
1049
#else
1050 1018
			string_print (normal_video);
1051
#endif /* UNIX */
1052 1019
		}
1053 1020
		else
1054 1021
			putchar(*textp++);
......
1062 1029

  
1063 1030
/* Clear the rest of the line is clear_line is TRUE */
1064 1031
  if (clear_line == TRUE) {
1065
#ifdef	UNIX
1066
	tputs(CE, 0, _putchar);
1067
#else
1068 1032
	string_print(blank_line);
1069
#endif /* UNIX */
1070 1033
	putchar('\n');
1071 1034
  }
1072 1035
}
......
1079 1042
{
1080 1043
  if (out_count <= 0)		/* There is nothing to flush */
1081 1044
	return FINE;
1082
#ifdef UNIX
1083
  if (fd == STD_OUT) {
1084
	printf("%.*s", out_count, screen);
1085
	_flush();
1086
  }
1087
  else
1088
#endif /* UNIX */
1089 1045
  if (write(fd, screen, out_count) != out_count) {
1090 1046
	bad_write(fd);
1091 1047
	return ERRORS;
......
1141 1097
  set_cursor(0, ymax);
1142 1098
  putchar('\n');
1143 1099
  flush();
1144
#ifdef UNIX
1145
  abort();
1146
#else
1147 1100
  exit(1);
1148
#endif /* UNIX */
1149 1101
}
1150 1102

  
1151 1103
#define UNDEF	_POSIX_VDISABLE
......
1190 1142
void
1191 1143
panic(const char *message)
1192 1144
{
1193
#ifdef UNIX
1194
  tputs(CL, 0, _putchar);
1195
  build_string(text_buffer, "%s\nError code %d\n", message, errno);
1196
#else
1197 1145
  build_string(text_buffer, "%s%s\nError code %d\n", enter_string, message, errno);
1198
#endif /* UNIX */
1199 1146
  write(STD_OUT, text_buffer, length_of(text_buffer));
1200 1147

  
1201 1148
  if (loading == FALSE)
......
1204 1151
	unlink(yank_file);
1205 1152
  raw_mode(OFF);
1206 1153

  
1207
#ifdef UNIX
1208
  abort();
1209
#else
1210 1154
  exit(1);
1211
#endif /* UNIX */
1212 1155
}
1213 1156

  
1214 1157
void *
......
1280 1223
char text_buffer[MAX_CHARS];	/* Buffer for modifying text */
1281 1224

  
1282 1225
/* Escape sequences. */
1283
#ifdef UNIX
1284
char *CE, *VS, *SO, *SE, *CL, *AL, *CM;
1285
#else
1286 1226
const char	*enter_string = "\033[H\033[J";	/* String printed on entering mined */
1287 1227
const char	*pos_string = "\033[%d;%dH";	/* Absolute cursor position */
1288 1228
const char	*rev_scroll = "\033M";		/* String for reverse scrolling */
1289 1229
const char	*rev_video = "\033[7m";		/* String for starting reverse video */
1290 1230
const char	*normal_video = "\033[m";	/* String for leaving reverse video */
1291 1231
const char	*blank_line = "\033[K";		/* Clear line to end */
1292
#endif /* UNIX */
1293 1232

  
1294 1233
/*
1295 1234
 * Yank variables.
......
1474 1413
  int index;		/* Index in key table */
1475 1414
  struct winsize winsize;
1476 1415

  
1477
#ifdef UNIX
1478
  get_term();
1479
  tputs(VS, 0, _putchar);
1480
  tputs(CL, 0, _putchar);
1481
#else
1482 1416
  string_print(enter_string);			/* Hello world */
1483
#endif /* UNIX */
1484 1417
  if (ioctl(STD_OUT, TIOCGWINSZ, &winsize) == 0 && winsize.ws_row != 0) {
1485 1418
	ymax = winsize.ws_row - 1;
1486 1419
	screenmax = ymax - 1;
......
1538 1471
RD(int u __unused)
1539 1472
{
1540 1473
/* Clear screen */
1541
#ifdef UNIX
1542
  tputs(VS, 0, _putchar);
1543
  tputs(CL, 0, _putchar);
1544
#else
1545 1474
  string_print(enter_string);
1546
#endif /* UNIX */
1547 1475

  
1548 1476
/* Print first page */
1549 1477
  display(0, 0, top_line, last_y);
1550 1478

  
1551 1479
/* Clear last line */
1552 1480
  set_cursor(0, ymax);
1553
#ifdef UNIX
1554
  tputs(CE, 0, _putchar);
1555
#else
1556 1481
  string_print(blank_line);
1557
#endif /* UNIX */
1558 1482
  move_to(x, y);
1559 1483
}
1560 1484

  
......
1586 1510
static void
1587 1511
(*escfunc(int c))(int)
1588 1512
{
1589
#if (CHIP == M68000)
1590
#ifndef COMPAT
1591
  int ch;
1592
#endif
1593
#endif
1594 1513
  if (c == '[') {
1595 1514
	/* Start of ASCII escape sequence. */
1596 1515
	c = getchar();
1597
#if (CHIP == M68000)
1598
#ifndef COMPAT
1599
	if ((c >= '0') && (c <= '9')) ch = getchar();
1600
	/* ch is either a tilde or a second digit */
1601
#endif
1602
#endif
1603 1516
	switch (c) {
1604 1517
	case 'H': return(HO);
1605 1518
	case 'A': return(UP);
1606 1519
	case 'B': return(DN);
1607 1520
	case 'C': return(RT);
1608 1521
	case 'D': return(LF);
1609
#if (CHIP == M68000)
1610
#ifndef COMPAT
1611
	/* F1 = ESC [ 1 ~ */
1612
	/* F2 = ESC [ 2 ~ */
1613
	/* F3 = ESC [ 3 ~ */
1614
	/* F4 = ESC [ 4 ~ */
1615
	/* F5 = ESC [ 5 ~ */
1616
	/* F6 = ESC [ 6 ~ */
1617
	/* F7 = ESC [ 17 ~ */
1618
	/* F8 = ESC [ 18 ~ */
1619
	case '1':
1620
		  switch (ch) {
1621
		  case '~': return(SF);
1622
		  case '7': getchar(); return(MA);
1623
		  case '8': getchar(); return(CTL);
1624
                  }
1625
	case '2': return(SR);
1626
	case '3': return(PD);
1627
	case '4': return(PU);
1628
	case '5': return(FS);
1629
	case '6': return(EF);
1630
#endif
1631
#endif
1632
#if (CHIP == INTEL)
1633
#ifdef ASSUME_CONS25
1634 1522
	case 'G': return(PD);
1635 1523
	case 'I': return(PU);
1636 1524
	case 'F': return(EF);
......
1646 1534
	case 'P': return(GR);
1647 1535
	/* Shift-F4 - line replace */
1648 1536
	case 'b': return(LR);
1649
#else
1650
	case 'G': return(FS);
1651
	case 'S': return(SR);
1652
	case 'T': return(SF);
1653
	case 'U': return(PD);
1654
	case 'V': return(PU);
1655
	case 'Y': return(EF);
1656
#endif
1657
#endif
1658 1537
	}
1659 1538
	return(I);
1660 1539
  }
1661
#ifdef ASSUME_XTERM
1662 1540
  if (c == 'O') {
1663 1541
	/* Start of ASCII function key escape sequence. */
1664 1542
	switch (getchar()) {
......
1673 1551
		break;
1674 1552
	}
1675 1553
    }
1676
#endif
1677
#if (CHIP == M68000)
1678
#ifdef COMPAT
1679
  if (c == 'O') {
1680
	/* Start of ASCII function key escape sequence. */
1681
	switch (getchar()) {
1682
	case 'P': return(SF);
1683
	case 'Q': return(SR);
1684
	case 'R': return(PD);
1685
	case 'S': return(PU);
1686
	case 'T': return(FS);
1687
	case 'U': return(EF);
1688
	case 'V': return(MA);
1689
	case 'W': return(CTL);
1690
	}
1691
    }
1692
#endif
1693
#endif
1694 1554
  return(I);
1695 1555
}
1696 1556

  
......
1944 1804
		case '\b' :		/* Erase previous char */
1945 1805
			if (ptr > inbuf) {
1946 1806
				ptr--;
1947
#ifdef UNIX
1948
				tputs(SE, 0, _putchar);
1949
#else
1950 1807
				string_print(normal_video);
1951
#endif /* UNIX */
1952 1808
				if (is_tab(*ptr))
1953 1809
					string_print(" \b\b\b  \b\b");
1954 1810
				else
1955 1811
					string_print(" \b\b \b");
1956
#ifdef UNIX
1957
				tputs(SO, 0, _putchar);
1958
#else
1959 1812
				string_print(rev_video);
1960
#endif /* UNIX */
1961 1813
				string_print(" \b");
1962 1814
				*ptr = '\0';
1963 1815
			}
......
2001 1853
  }
2002 1854
  return ret;
2003 1855
}
2004

  
2005
/*  ========================================================================  *
2006
 *				UNIX I/O Routines			      *
2007
 *  ========================================================================  */
2008

  
2009
#ifdef UNIX
2010
#undef putchar
2011

  
2012
int
2013
_getchar(void)
2014
{
2015
  char c;
2016

  
2017
  if (read(input_fd, &c, 1) != 1 && quit == FALSE)
2018
	panic ("Cannot read 1 byte from input");
2019
  return c & 0377;
2020
}
2021

  
2022
void
2023
_flush(void)
2024
{
2025
  fflush(stdout);
2026
}
2027

  
2028
void
2029
_putchar(char c)
2030
{
2031
  write_char(STD_OUT, c);
2032
}
2033

  
2034
void
2035
get_term(void)
2036
{
2037
  static char termbuf[50];
2038
  char *loc = termbuf;
2039
  char entry[1024];
2040

  
2041
  if (tgetent(entry, getenv("TERM")) <= 0) {
2042
	printf("Unknown terminal.\n");
2043
	exit(1);
2044
  }
2045

  
2046
  AL = tgetstr("al", &loc);
2047
  CE = tgetstr("ce", &loc);
2048
  VS = tgetstr("vs", &loc);
2049
  CL = tgetstr("cl", &loc);
2050
  SO = tgetstr("so", &loc);
2051
  SE = tgetstr("se", &loc);
2052
  CM = tgetstr("cm", &loc);
2053
  ymax = tgetnum("li") - 1;
2054
  screenmax = ymax - 1;
2055

  
2056
  if (!CE || !SO || !SE || !CL || !AL || !CM) {
2057
	printf("Sorry, no mined on this type of terminal\n");
2058
	exit(1);
2059
  }
2060
}
2061
#endif /* UNIX */
bin/mined/mined2.c
251 251
  	if (reverse_scroll() == ERRORS)
252 252
  		break;			/* Top of file reached */
253 253
  set_cursor(0, ymax);			/* Erase very bottom line */
254
#ifdef UNIX
255
  tputs(CE, 0, _putchar);
256
#else
257 254
  string_print(blank_line);
258
#endif /* UNIX */
259 255
  if (y + i > screenmax)			/* line no longer on screen */
260 256
  	move_to(0, screenmax >> 1);
261 257
  else
......
305 301

  
306 302
  reverse_scroll();
307 303
  set_cursor(0, ymax);		/* Erase very bottom line */
308
#ifdef UNIX
309
  tputs(CE, 0, _putchar);
310
#else
311 304
  string_print(blank_line);
312
#endif /* UNIX */
313 305
  move_to(x, (y == screenmax) ? screenmax : y + 1);
314 306
}
315 307

  
......
362 354

  
363 355
/* Perform the scroll */
364 356
  set_cursor(0, 0);
365
#ifdef UNIX
366
  tputs(AL, 0, _putchar);
367
#else
368 357
  string_print(rev_scroll);
369
#endif /* UNIX */
370 358
  set_cursor(0, 0);
371 359
  line_print(top_line);
372 360