LIB.T
上传用户:jnzhq888
上传日期:2007-01-18
资源大小:51694k
文件大小:969k
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcpy.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07700 /*
- 07701 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07702 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07703 */
- 07704 /* $Header: strcpy.c,v 1.2 90/05/31 18:33:13 ceriel Exp $ */
- 07705
- 07706 #include <string.h>
- 07707
- 07708 char *
- 07709 strcpy(char *ret, register const char *s2)
- 07710 {
- 07711 register char *s1 = ret;
- 07712
- 07713 while (*s1++ = *s2++)
- 07714 /* EMPTY */ ;
- 07715
- 07716 return ret;
- 07717 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strcspn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07800 /*
- 07801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07803 */
- 07804 /* $Header: strcspn.c,v 1.2 89/12/18 16:01:42 eck Exp $ */
- 07805
- 07806 #include <string.h>
- 07807
- 07808 size_t
- 07809 strcspn(const char *string, const char *notin)
- 07810 {
- 07811 register const char *s1, *s2;
- 07812
- 07813 for (s1 = string; *s1; s1++) {
- 07814 for(s2 = notin; *s2 != *s1 && *s2; s2++)
- 07815 /* EMPTY */ ;
- 07816 if (*s2)
- 07817 break;
- 07818 }
- 07819 return s1 - string;
- 07820 }
- .Ep 64 src/lib/ansi/strerror.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strerror.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 07900 /*
- 07901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 07902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 07903 */
- 07904 /* $Header: strerror.c,v 1.3 90/08/28 13:53:31 eck Exp $ */
- 07905
- 07906 #include <string.h>
- 07907
- 07908 /*
- 07909 * I don't know why, but X3J11 says that strerror() should be in declared
- 07910 * in <string.h>. That is why the function is defined here.
- 07911 */
- 07912 char *
- 07913 strerror(register int errnum)
- 07914 {
- 07915 extern const char *_sys_errlist[];
- 07916 extern const int _sys_nerr;
- 07917
- 07918 if (errnum < 0 || errnum >= _sys_nerr)
- 07919 return "unknown error";
- 07920 return (char *)_sys_errlist[errnum];
- 07921 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strftime.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08000 /*
- 08001 * strftime - convert a structure to a string, controlled by an argument
- 08002 */
- 08003 /* $Header: strftime.c,v 1.3 91/04/22 13:21:03 ceriel Exp $ */
- 08004
- 08005 #include <time.h>
- 08006 #include "loc_time.h"
- 08007
- 08008 /* The width can be -1 in both s_prnt() as in u_prnt(). This
- 08009 * indicates that as many characters as needed should be printed.
- 08010 */
- 08011 static char *
- 08012 s_prnt(char *s, size_t maxsize, const char *str, int width)
- 08013 {
- 08014 while (width > 0 || (width < 0 && *str)) {
- 08015 if (!maxsize) break;
- 08016 *s++ = *str++;
- 08017 maxsize--;
- 08018 width--;
- 08019 }
- 08020 return s;
- 08021 }
-
- 08023 static char *
- 08024 u_prnt(char *s, size_t maxsize, unsigned val, int width)
- .Op 65 src/lib/ansi/strftime.c
- 08025 {
- 08026 int c;
- 08027
- 08028 c = val % 10;
- 08029 val = val / 10;
- 08030 if (--width > 0 || (width < 0 && val != 0))
- 08031 s = u_prnt(s, (maxsize ? maxsize - 1 : 0), val, width);
- 08032 if (maxsize) *s++ = c + '0';
- 08033 return s;
- 08034 }
-
- 08036 size_t
- 08037 strftime(char *s, size_t maxsize,
- 08038 const char *format, const struct tm *timeptr)
- 08039 {
- 08040 size_t n;
- 08041 char *firsts, *olds;
- 08042
- 08043 if (!format) return 0;
- 08044
- 08045 _tzset(); /* for %Z conversion */
- 08046 firsts = s;
- 08047 while (maxsize && *format) {
- 08048 while (maxsize && *format && *format != '%') {
- 08049 *s++ = *format++;
- 08050 maxsize--;
- 08051 }
- 08052 if (!maxsize || !*format) break;
- 08053 format++;
- 08054
- 08055 olds = s;
- 08056 switch (*format++) {
- 08057 case 'a':
- 08058 s = s_prnt(s, maxsize,
- 08059 _days[timeptr->tm_wday], ABB_LEN);
- 08060 maxsize -= s - olds;
- 08061 break;
- 08062 case 'A':
- 08063 s = s_prnt(s, maxsize, _days[timeptr->tm_wday], -1);
- 08064 maxsize -= s - olds;
- 08065 break;
- 08066 case 'b':
- 08067 s = s_prnt(s, maxsize,
- 08068 _months[timeptr->tm_mon], ABB_LEN);
- 08069 maxsize -= s - olds;
- 08070 break;
- 08071 case 'B':
- 08072 s = s_prnt(s, maxsize, _months[timeptr->tm_mon], -1);
- 08073 maxsize -= s - olds;
- 08074 break;
- 08075 case 'c':
- 08076 n = strftime(s, maxsize,
- 08077 "%a %b %d %H:%M:%S %Y", timeptr);
- 08078 if (n) maxsize -= n;
- 08079 else maxsize = 0;
- 08080 s += n;
- 08081 break;
- 08082 case 'd':
- 08083 s = u_prnt(s, maxsize, timeptr->tm_mday, 2);
- 08084 maxsize -= s - olds;
- .Ep 66 src/lib/ansi/strftime.c
- 08085 break;
- 08086 case 'H':
- 08087 s = u_prnt(s, maxsize, timeptr->tm_hour, 2);
- 08088 maxsize -= s - olds;
- 08089 break;
- 08090 case 'I':
- 08091 s = u_prnt(s, maxsize,
- 08092 (timeptr->tm_hour + 11) % 12 + 1, 2);
- 08093 maxsize -= s - olds;
- 08094 break;
- 08095 case 'j':
- 08096 s = u_prnt(s, maxsize, timeptr->tm_yday + 1, 3);
- 08097 maxsize -= s - olds;
- 08098 break;
- 08099 case 'm':
- 08100 s = u_prnt(s, maxsize, timeptr->tm_mon + 1, 2);
- 08101 maxsize -= s - olds;
- 08102 break;
- 08103 case 'M':
- 08104 s = u_prnt(s, maxsize, timeptr->tm_min, 2);
- 08105 maxsize -= s - olds;
- 08106 break;
- 08107 case 'p':
- 08108 s = s_prnt(s, maxsize,
- 08109 (timeptr->tm_hour < 12) ? "AM" : "PM", 2);
- 08110 maxsize -= s - olds;
- 08111 break;
- 08112 case 'S':
- 08113 s = u_prnt(s, maxsize, timeptr->tm_sec, 2);
- 08114 maxsize -= s - olds;
- 08115 break;
- 08116 case 'U':
- 08117 s = u_prnt(s, maxsize, /* ??? */
- 08118 (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7, 2);
- 08119 maxsize -= s - olds;
- 08120 break;
- 08121 case 'w':
- 08122 s = u_prnt(s, maxsize, timeptr->tm_wday, 1);
- 08123 maxsize -= s - olds;
- 08124 break;
- 08125 case 'W':
- 08126 s = u_prnt(s, maxsize, /* ??? */
- 08127 (timeptr->tm_yday+7-(timeptr->tm_wday+6)%7)/7,2);
- 08128 maxsize -= s - olds;
- 08129 break;
- 08130 case 'x':
- 08131 n = strftime(s, maxsize, "%a %b %d %Y", timeptr);
- 08132 if (n) maxsize -= n;
- 08133 else maxsize = 0;
- 08134 s += n;
- 08135 break;
- 08136 case 'X':
- 08137 n = strftime(s, maxsize, "%H:%M:%S", timeptr);
- 08138 if (n) maxsize -= n;
- 08139 else maxsize = 0;
- 08140 s += n;
- 08141 break;
- 08142 case 'y':
- 08143 s = u_prnt(s, maxsize, timeptr->tm_year % 100, 2);
- 08144 maxsize -= s - olds;
- .Op 67 src/lib/ansi/strftime.c
- 08145 break;
- 08146 case 'Y':
- 08147 s = u_prnt(s, maxsize, timeptr->tm_year + YEAR0, -1);
- 08148 maxsize -= s - olds;
- 08149 break;
- 08150 case 'Z':
- 08151 s = s_prnt(s, maxsize,
- 08152 _tzname[(timeptr->tm_isdst > 0)], -1);
- 08153 maxsize -= s - olds;
- 08154 break;
- 08155 case '%':
- 08156 *s++ = '%';
- 08157 maxsize--;
- 08158 break;
- 08159 default:
- 08160 /* A conversion error. Leave the loop. */
- 08161 while (*format) format++;
- 08162 break;
- 08163 }
- 08164
- 08165 }
- 08166 if (maxsize) {
- 08167 *s = ' ';
- 08168 return s - firsts;
- 08169 }
- 08170 return 0; /* The buffer is full */
- 08171 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strlen.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08200 /*
- 08201 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08202 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08203 */
- 08204 /* $Header: strlen.c,v 1.4 90/08/28 13:53:42 eck Exp $ */
- 08205
- 08206 #include <string.h>
- 08207
- 08208 size_t
- 08209 strlen(const char *org)
- 08210 {
- 08211 register const char *s = org;
- 08212
- 08213 while (*s++)
- 08214 /* EMPTY */ ;
- 08215
- 08216 return --s - org;
- 08217 }
- .Ep 68 src/lib/ansi/strncat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strncat.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08300 /*
- 08301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08303 */
- 08304 /* $Header: strncat.c,v 1.3 90/08/28 13:53:54 eck Exp $ */
- 08305
- 08306 #include <string.h>
- 08307
- 08308 char *
- 08309 strncat(char *ret, register const char *s2, size_t n)
- 08310 {
- 08311 register char *s1 = ret;
- 08312
- 08313 if (n > 0) {
- 08314 while (*s1++)
- 08315 /* EMPTY */ ;
- 08316 s1--;
- 08317 while (*s1++ = *s2++) {
- 08318 if (--n > 0) continue;
- 08319 *s1 = ' ';
- 08320 break;
- 08321 }
- 08322 return ret;
- 08323 } else return s1;
- 08324 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strncmp.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08400 /*
- 08401 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08402 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08403 */
- 08404 /* $Id: strncmp.c,v 1.4 1994/06/24 11:57:04 ceriel Exp $ */
- 08405
- 08406 #include <string.h>
- 08407
- 08408 int
- 08409 strncmp(register const char *s1, register const char *s2, register size_t n)
- 08410 {
- 08411 if (n) {
- 08412 do {
- 08413 if (*s1 != *s2++)
- 08414 break;
- 08415 if (*s1++ == ' ')
- 08416 return 0;
- 08417 } while (--n > 0);
- 08418 if (n > 0) {
- 08419 if (*s1 == ' ') return -1;
- .Op 69 src/lib/ansi/strncmp.c
- 08420 if (*--s2 == ' ') return 1;
- 08421 return (unsigned char) *s1 - (unsigned char) *s2;
- 08422 }
- 08423 }
- 08424 return 0;
- 08425 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strncpy.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08500 /*
- 08501 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08502 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08503 */
- 08504 /* $Header: strncpy.c,v 1.3 90/08/28 13:54:11 eck Exp $ */
- 08505
- 08506 #include <string.h>
- 08507
- 08508 char *
- 08509 strncpy(char *ret, register const char *s2, register size_t n)
- 08510 {
- 08511 register char *s1 = ret;
- 08512
- 08513 if (n>0) {
- 08514 while((*s1++ = *s2++) && --n > 0)
- 08515 /* EMPTY */ ;
- 08516 if ((*--s2 == ' ') && --n > 0) {
- 08517 do {
- 08518 *s1++ = ' ';
- 08519 } while(--n > 0);
- 08520 }
- 08521 }
- 08522 return ret;
- 08523 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strpbrk.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08600 /*
- 08601 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08602 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08603 */
- 08604 /* $Header: strpbrk.c,v 1.2 89/12/18 16:02:21 eck Exp $ */
- 08605
- 08606 #include <string.h>
- 08607
- 08608 char *
- 08609 strpbrk(register const char *string, register const char *brk)
- 08610 {
- 08611 register const char *s1;
- 08612
- 08613 while (*string) {
- 08614 for (s1 = brk; *s1 && *s1 != *string; s1++)
- .Ep 70 src/lib/ansi/strpbrk.c
- 08615 /* EMPTY */ ;
- 08616 if (*s1)
- 08617 return (char *)string;
- 08618 string++;
- 08619 }
- 08620 return (char *)NULL;
- 08621 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strrchr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08700 /*
- 08701 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08702 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08703 */
- 08704 /* $Header: strrchr.c,v 1.3 90/08/28 13:54:21 eck Exp $ */
- 08705
- 08706 #include <string.h>
- 08707
- 08708 char *
- 08709 strrchr(register const char *s, int c)
- 08710 {
- 08711 register const char *result = NULL;
- 08712
- 08713 c = (char) c;
- 08714
- 08715 do {
- 08716 if (c == *s)
- 08717 result = s;
- 08718 } while (*s++ != ' ');
- 08719
- 08720 return (char *)result;
- 08721 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strspn.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08800 /*
- 08801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08803 */
- 08804 /* $Header: strspn.c,v 1.1 89/05/11 10:09:09 eck Exp $ */
- 08805
- 08806 #include <string.h>
- 08807
- 08808 size_t
- 08809 strspn(const char *string, const char *in)
- 08810 {
- 08811 register const char *s1, *s2;
- 08812
- 08813 for (s1 = string; *s1; s1++) {
- 08814 for (s2 = in; *s2 && *s2 != *s1; s2++)
- .Op 71 src/lib/ansi/strspn.c
- 08815 /* EMPTY */ ;
- 08816 if (*s2 == ' ')
- 08817 break;
- 08818 }
- 08819 return s1 - string;
- 08820 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strstr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 08900 /*
- 08901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 08902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 08903 */
- 08904 /* $Header: strstr.c,v 1.3 90/08/28 13:54:28 eck Exp $ */
- 08905
- 08906 #include <string.h>
- 08907
- 08908 char *
- 08909 strstr(register const char *s, register const char *wanted)
- 08910 {
- 08911 register const size_t len = strlen(wanted);
- 08912
- 08913 if (len == 0) return (char *)s;
- 08914 while (*s != *wanted || strncmp(s, wanted, len))
- 08915 if (*s++ == ' ')
- 08916 return (char *)NULL;
- 08917 return (char *)s;
- 08918 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strtok.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09000 /*
- 09001 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09002 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09003 */
- 09004 /* $Header: strtok.c,v 1.2 90/08/28 13:54:38 eck Exp $ */
- 09005
- 09006 #include <string.h>
- 09007
- 09008 char *
- 09009 strtok(register char *string, const char *separators)
- 09010 {
- 09011 register char *s1, *s2;
- 09012 static char *savestring;
- 09013
- 09014 if (string == NULL) {
- 09015 string = savestring;
- 09016 if (string == NULL) return (char *)NULL;
- 09017 }
- 09018
- 09019 s1 = string + strspn(string, separators);
- .Ep 72 src/lib/ansi/strtok.c
- 09020 if (*s1 == ' ') {
- 09021 savestring = NULL;
- 09022 return (char *)NULL;
- 09023 }
- 09024
- 09025 s2 = strpbrk(s1, separators);
- 09026 if (s2 != NULL)
- 09027 *s2++ = ' ';
- 09028 savestring = s2;
- 09029 return s1;
- 09030 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strtol.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09100 /*
- 09101 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09102 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09103 */
- 09104 /* $Header: strtol.c,v 1.4 90/05/11 15:22:19 eck Exp $ */
- 09105
- 09106 #include <ctype.h>
- 09107 #include <errno.h>
- 09108 #include <limits.h>
- 09109 #include <stdlib.h>
- 09110
- 09111 static unsigned long
- 09112 string2long(register const char *nptr, char **endptr,
- 09113 int base, int is_signed);
- 09114
- 09115 long int
- 09116 strtol(register const char *nptr, char **endptr, int base)
- 09117 {
- 09118 return (signed long)string2long(nptr, endptr, base, 1);
- 09119 }
-
- 09121 unsigned long int
- 09122 strtoul(register const char *nptr, char **endptr, int base)
- 09123 {
- 09124 return (unsigned long)string2long(nptr, endptr, base, 0);
- 09125 }
-
- 09127 #define between(a, c, z) ((unsigned) ((c) - (a)) <= (unsigned) ((z) - (a)))
- 09128
- 09129 static unsigned long
- 09130 string2long(register const char *nptr, char ** const endptr,
- 09131 int base, int is_signed)
- 09132 {
- 09133 register unsigned int v;
- 09134 register unsigned long val = 0;
- 09135 register int c;
- 09136 int ovfl = 0, sign = 1;
- 09137 const char *startnptr = nptr, *nrstart;
- 09138
- 09139 if (endptr) *endptr = (char *)nptr;
- .Op 73 src/lib/ansi/strtol.c
- 09140 while (isspace(*nptr)) nptr++;
- 09141 c = *nptr;
- 09142
- 09143 if (c == '-' || c == '+') {
- 09144 if (c == '-') sign = -1;
- 09145 nptr++;
- 09146 }
- 09147 nrstart = nptr; /* start of the number */
- 09148
- 09149 /* When base is 0, the syntax determines the actual base */
- 09150 if (base == 0)
- 09151 if (*nptr == '0')
- 09152 if (*++nptr == 'x' || *nptr == 'X') {
- 09153 base = 16;
- 09154 nptr++;
- 09155 }
- 09156 else base = 8;
- 09157 else base = 10;
- 09158 else if (base==16 && *nptr=='0' && (*++nptr =='x' || *nptr =='X'))
- 09159 nptr++;
- 09160
- 09161 for (;;) {
- 09162 c = *nptr;
- 09163 if (between('0', c, '9')) {
- 09164 v = c - '0';
- 09165 } else
- 09166 if (between('a', c, 'z')) {
- 09167 v = c - 'a' + 0xa;
- 09168 } else
- 09169 if (between('A', c, 'Z')) {
- 09170 v = c - 'A' + 0xA;
- 09171 } else {
- 09172 break;
- 09173 }
- 09174 if (v >= base) break;
- 09175 if (val > (ULONG_MAX - v) / base) ovfl++;
- 09176 val = (val * base) + v;
- 09177 nptr++;
- 09178 }
- 09179 if (endptr) {
- 09180 if (nrstart == nptr) *endptr = (char *)startnptr;
- 09181 else *endptr = (char *)nptr;
- 09182 }
- 09183
- 09184 if (!ovfl) {
- 09185 /* Overflow is only possible when converting a signed long. */
- 09186 if (is_signed
- 09187 && ( (sign < 0 && val > -(unsigned long)LONG_MIN)
- 09188 || (sign > 0 && val > LONG_MAX)))
- 09189 ovfl++;
- 09190 }
- 09191
- 09192 if (ovfl) {
- 09193 errno = ERANGE;
- 09194 if (is_signed)
- 09195 if (sign < 0) return LONG_MIN;
- 09196 else return LONG_MAX;
- 09197 else return ULONG_MAX;
- 09198 }
- 09199 return (long) sign * val;
- .Ep 74 src/lib/ansi/strtol.c
- 09200 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/strxfrm.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09300 /*
- 09301 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09302 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09303 */
- 09304 /* $Header: strxfrm.c,v 1.4 90/08/28 13:54:46 eck Exp $ */
- 09305
- 09306 #include <string.h>
- 09307
- 09308 size_t
- 09309 strxfrm(register char *s1, register const char *save, register size_t n)
- 09310 {
- 09311 register const char *s2 = save;
- 09312
- 09313 while (*s2) {
- 09314 if (n > 1) {
- 09315 n--;
- 09316 *s1++ = *s2++;
- 09317 } else
- 09318 s2++;
- 09319 }
- 09320 if (n > 0)
- 09321 *s1++ = ' ';
- 09322 return s2 - save;
- 09323 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/system.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09400 /*
- 09401 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09402 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09403 */
- 09404 /* $Header: system.c,v 1.4 90/11/22 13:59:54 eck Exp $ */
- 09405
- 09406 #if defined(_POSIX_SOURCE)
- 09407 #include <sys/types.h>
- 09408 #endif
- 09409 #include <stdlib.h>
- 09410 #include <signal.h>
- 09411
- 09412 extern pid_t _fork(void);
- 09413 extern pid_t _wait(int *);
- 09414 extern void _exit(int);
- 09415 extern void _execve(const char *path, const char ** argv, const char ** envp);
- 09416 extern int _close(int);
- 09417
- 09418 #define FAIL 127
- 09419
- .Op 75 src/lib/ansi/system.c
- 09420 extern const char **_penvp;
- 09421 static const char *exec_tab[] = {
- 09422 "sh", /* argv[0] */
- 09423 "-c", /* argument to the shell */
- 09424 NULL, /* to be filled with user command */
- 09425 NULL /* terminating NULL */
- 09426 };
- 09427
- 09428 int
- 09429 system(const char *str)
- 09430 {
- 09431 int pid, exitstatus, waitval;
- 09432 int i;
- 09433
- 09434 if ((pid = _fork()) < 0) return str ? -1 : 0;
- 09435
- 09436 if (pid == 0) {
- 09437 for (i = 3; i <= 20; i++)
- 09438 _close(i);
- 09439 if (!str) str = "cd ."; /* just testing for a shell */
- 09440 exec_tab[2] = str; /* fill in command */
- 09441 _execve("/bin/sh", exec_tab, _penvp);
- 09442 /* get here if execve fails ... */
- 09443 _exit(FAIL); /* see manual page */
- 09444 }
- 09445 while ((waitval = _wait(&exitstatus)) != pid) {
- 09446 if (waitval == -1) break;
- 09447 }
- 09448 if (waitval == -1) {
- 09449 /* no child ??? or maybe interrupted ??? */
- 09450 exitstatus = -1;
- 09451 }
- 09452 if (!str) {
- 09453 if (exitstatus == FAIL << 8) /* execve() failed */
- 09454 exitstatus = 0;
- 09455 else exitstatus = 1; /* /bin/sh exists */
- 09456 }
- 09457 return exitstatus;
- 09458 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/tolower.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09500 #include <ctype.h>
- 09501
- 09502 int tolower(int c) {
- 09503 return isupper(c) ? c - 'A' + 'a' : c ;
- 09504 }
- .Ep 76 src/lib/ansi/toupper.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/toupper.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09600 #include <ctype.h>
- 09601
- 09602 int toupper(int c) {
- 09603 return islower(c) ? c - 'a' + 'A' : c ;
- 09604 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/tzset.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09700 /*
- 09701 * tzset - set timezone information
- 09702 */
- 09703 /* $Header: tzset.c,v 1.3 91/04/22 13:21:11 ceriel Exp $ */
- 09704
- 09705 /* This function is present for System V && POSIX */
- 09706
- 09707 #include <time.h>
- 09708 #include "loc_time.h"
- 09709
- 09710 void
- 09711 tzset(void)
- 09712 {
- 09713 _tzset(); /* does the job */
- 09714 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/wcstombs.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09800 /*
- 09801 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09802 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09803 */
- 09804 /* $Header: wcstombs.c,v 1.3 90/03/28 16:37:07 eck Exp $ */
- 09805
- 09806 #include <stdlib.h>
- 09807 #include <locale.h>
- 09808 #include <limits.h>
- 09809
- 09810 size_t
- 09811 wcstombs(register char *s, register const wchar_t *pwcs, size_t n)
- 09812 {
- 09813 register int i = n;
- 09814
- .Op 77 src/lib/ansi/wcstombs.c
- 09815 while (--i >= 0) {
- 09816 if (!(*s++ = *pwcs++))
- 09817 break;
- 09818 }
- 09819 return n - i - 1;
- 09820 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/ansi/wctomb.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 09900 /*
- 09901 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
- 09902 * See the copyright notice in the ACK home directory, in the file "Copyright".
- 09903 */
- 09904 /* $Header: wctomb.c,v 1.4 91/01/15 11:55:33 ceriel Exp $ */
- 09905
- 09906 #include <stdlib.h>
- 09907 #include <limits.h>
- 09908
- 09909 int
- 09910 /* was: wctomb(char *s, wchar_t wchar)
- 09911 * This conflicts with prototype, so it was changed to:
- 09912 */
- 09913 wctomb(char *s, wchar_t wchar)
- 09914 {
- 09915 if (!s) return 0; /* no state dependent codings */
- 09916
- 09917 *s = wchar;
- 09918 return 1;
- 09919 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/curspriv.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10000 /* Constants */
- 10001 #define _SUBWIN 1 /* window is a subwindow */
- 10002 #define _ENDLINE 2 /* last winline is last screen line */
- 10003 #define _FULLWIN 4 /* window fills screen */
- 10004 #define _SCROLLWIN 8 /* window lwr rgt is screen lwr rgt */
- 10005
- 10006 #define _NO_CHANGE -1 /* flags line edge unchanged */
- 10007 #define _BREAKCHAR 0x03 /* ^C character */
- 10008 #define _DCCHAR 0x08 /* Delete Char char (BS) */
- 10009 #define _DLCHAR 0x1b /* Delete Line char (ESC) */
- 10010 #define _GOCHAR 0x11 /* ^Q character */
- 10011 #define _PRINTCHAR 0x10 /* ^P character */
- 10012 #define _STOPCHAR 0x13 /* ^S character */
- 10013 #define NUNGETCH 10 /* max # chars to ungetch() */
- 10014
- .Ep 78 src/lib/curses/curspriv.h
- 10015 #define max(a,b) (((a) > (b)) ? (a) : (b))
- 10016 #define min(a,b) (((a) < (b)) ? (a) : (b))
- 10017
- 10018 /* Character mask definitions. */
- 10019 #define CHR_MSK ((int) 0x00ff) /* ASCIIZ character mask */
- 10020 #define ATR_MSK ((int) 0xff00) /* attribute mask */
- 10021 #define ATR_NRM ((int) 0x0000) /* no special attributes */
- 10022
- 10023 /* Type declarations. */
- 10024
- 10025 typedef struct {
- 10026 WINDOW *tmpwin; /* window used for updates */
- 10027 int cursrow; /* position of physical cursor */
- 10028 int curscol;
- 10029 bool rawmode;
- 10030 bool cbrkmode;
- 10031 bool echoit;
- 10032 } cursv;
- 10033
- 10034 /* External variables */
- 10035 extern cursv _cursvar; /* curses variables */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/beep.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10100 #include <curses.h>
- 10101 #include "curspriv.h"
- 10102 #include <termcap.h>
- 10103
- 10104 extern char *bl, *vb;
- 10105
- 10106 /* Beep() sounds the terminal bell. */
- 10107 void beep()
- 10108 {
- 10109 if (bl)
- 10110 tputs(bl, 1, outc);
- 10111 else if (vb)
- 10112 tputs(vb, 1, outc);
- 10113 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/charpick.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10200 #include <curses.h>
- 10201 #include "curspriv.h"
- 10202
- 10203 /****************************************************************/
- 10204 /* Winch(win) returns the character at the current position in */
- 10205 /* Window 'win'. */
- 10206 /****************************************************************/
- 10207
- 10208 int winch(win)
- 10209 WINDOW *win;
- .Op 79 src/lib/curses/charpick.c
- 10210 {
- 10211 return((win->_line[win->_cury][win->_curx]) & 0xff);
- 10212 } /* winch */
- 10213
- 10214 /****************************************************************/
- 10215 /* Mvinch() moves the stdscr cursor to a new position, then */
- 10216 /* Returns the character at that position. */
- 10217 /****************************************************************/
- 10218
- 10219 int mvinch(y, x)
- 10220 int y;
- 10221 int x;
- 10222 {
- 10223 if (wmove(stdscr, y, x) == ERR) return(ERR);
- 10224 return((stdscr->_line[stdscr->_cury][stdscr->_curx]) & 0xff);
- 10225 }
-
- 10227 /****************************************************************/
- 10228 /* Mvwinch() moves the cursor of window 'win' to a new posi- */
- 10229 /* Tion, then returns the character at that position. */
- 10230 /****************************************************************/
- 10231
- 10232 int mvwinch(win, y, x)
- 10233 WINDOW *win;
- 10234 int y;
- 10235 int x;
- 10236 {
- 10237 if (wmove(win, y, x) == ERR) return(ERR);
- 10238 return((win->_line[win->_cury][win->_curx]) & 0xff);
- 10239 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/curs_set.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10300 #include <curses.h>
- 10301 #include "curspriv.h"
- 10302 #include <termcap.h>
- 10303
- 10304 extern char *vi, *ve, *vs;
- 10305
- 10306 /* Sets cursor visibility to unvisible=0; normal visible=1 or very good
- 10307 * visible=2.
- 10308 */
- 10309 void curs_set(visibility)
- 10310 int visibility;
- 10311 {
- 10312 switch (visibility) {
- 10313 case 0:
- 10314 if (vi) tputs(vi, 1, outc);
- 10315 break;
- 10316 case 1:
- 10317 if (ve) tputs(ve, 1, outc);
- 10318 break;
- 10319 case 2:
- .Ep 80 src/lib/curses/curs_set.c
- 10320 if (vs)
- 10321 tputs(vs, 1, outc);
- 10322 else if (ve)
- 10323 tputs(ve, 1, outc);
- 10324 }
- 10325 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/cursesio.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10400 #include <stdlib.h>
- 10401 #include <termcap.h>
- 10402 #include <sys/types.h>
- 10403 #include <sys/ioctl.h>
- 10404 #include <curses.h>
- 10405 #include "curspriv.h"
- 10406
- 10407 struct termios _orig_tty, _tty;
- 10408 cursv _cursvar;
- 10409
- 10410 WINDOW *stdscr, *curscr;
- 10411 int LINES, COLS;
- 10412 bool NONL;
- 10413
- 10414 char termcap[1024]; /* termcap buffer */
- 10415 char tc[200]; /* area to hold string capabilities */
- 10416 char *ttytype; /* terminal type from env */
- 10417 char *arp; /* pointer for use in tgetstr */
- 10418 char *cp; /* character pointer */
- 10419
- 10420 char *cl; /* clear screen capability */
- 10421 char *cm; /* cursor motion capability */
- 10422 char *so; /* start standout capability */
- 10423 char *se; /* end standout capability */
- 10424 char *mr; /* start of reverse */
- 10425 char *me; /* revert to normal */
- 10426 char *mb; /* start of blink */
- 10427 char *md; /* start of bold */
- 10428 char *us; /* start of underscore */
- 10429 char *ue; /* end of underscore */
- 10430 char *vi; /* cursor invisible */
- 10431 char *ve; /* cursor normal */
- 10432 char *vs; /* cursor good visible */
- 10433 char *as; /* alternative charset start */
- 10434 char *ae; /* alternative charset end */
- 10435 char *bl; /* ring the bell */
- 10436 char *vb; /* visual bell */
- 10437
- 10438 /* fatal - report error and die. Never returns */
- 10439 void fatal(s)
- 10440 char *s;
- 10441 {
- 10442 (void) fprintf(stderr, "curses: %sn", s);
- 10443 exit(1);
- 10444 }
- .Op 81 src/lib/curses/cursesio.c
-
- 10446 /* Outc - call putchar, necessary because putchar is a macro. */
- 10447 void outc(c)
- 10448 int c;
- 10449 {
- 10450 putchar(c);
- 10451 }
-
- 10453 /* Move cursor to r,c */
- 10454 void poscur(r, c)
- 10455 int r, c;
- 10456 {
- 10457 tputs(tgoto(cm, c, r), 1, outc);
- 10458 }
-
- 10460 /* Clear the screen */
- 10461 void clrscr()
- 10462 {
- 10463 tputs(cl, 1, outc);
- 10464 }
-
- 10466 /* This are terminal independent characters which can be used in curses */
- 10467
- 10468 unsigned int ACS_ULCORNER;
- 10469 unsigned int ACS_LLCORNER;
- 10470 unsigned int ACS_URCORNER;
- 10471 unsigned int ACS_LRCORNER;
- 10472 unsigned int ACS_RTEE;
- 10473 unsigned int ACS_LTEE;
- 10474 unsigned int ACS_BTEE;
- 10475 unsigned int ACS_TTEE;
- 10476 unsigned int ACS_HLINE;
- 10477 unsigned int ACS_VLINE;
- 10478 unsigned int ACS_PLUS;
- 10479 unsigned int ACS_S1;
- 10480 unsigned int ACS_S9;
- 10481 unsigned int ACS_DIAMOND;
- 10482 unsigned int ACS_CKBOARD;
- 10483 unsigned int ACS_DEGREE;
- 10484 unsigned int ACS_PLMINUS;
- 10485 unsigned int ACS_BULLET;
- 10486 unsigned int ACS_LARROW;
- 10487 unsigned int ACS_RARROW;
- 10488 unsigned int ACS_DARROW;
- 10489 unsigned int ACS_UARROW;
- 10490 unsigned int ACS_BOARD;
- 10491 unsigned int ACS_LANTERN;
- 10492 unsigned int ACS_BLOCK;
- 10493
- 10494 /* These defines describe the full set of grafic block characters which
- 10495 * can be defined via termcap.
- 10496 */
- 10497
- 10498 #define RIGHTARROW 0
- 10499 #define LEFTARROW 1
- 10500 #define DOWNARROW 2
- 10501 #define UPARROW 3
- 10502 #define FULLSQUARE 4
- 10503 #define GREYSQUARE 5
- 10504 #define EMPTYSQUARE 6
- .Ep 82 src/lib/curses/cursesio.c
- 10505 #define LATERN 7
- 10506 #define DIAMOND 8
- 10507 #define DEGREE 9
- 10508 #define PLUSMINUS 10
- 10509 #define DOWNRIGHT 11
- 10510 #define UPRIGHT 12
- 10511 #define UPLEFT 13
- 10512 #define DOWNLEFT 14
- 10513 #define CROSS 15
- 10514 #define UPLINE 16
- 10515 #define UPMIDLINE 17
- 10516 #define MIDLINE 18
- 10517 #define DOMIDLINE 19
- 10518 #define DOWNLINE 20
- 10519 #define TEELEFT 21
- 10520 #define TEERIGHT 22
- 10521 #define TEEHEAD 23
- 10522 #define TEENORMAL 24
- 10523 #define VERTLINE 25
- 10524 #define PARAGRAPH 26
- 10525
- 10526 unsigned int _cursgraftable[27] =
- 10527 {
- 10528 '>', '<', 'v', '^', '#', ':', ' ', '#', '+', ''', '#', '+', '+',
- 10529 '+', '+', '+', '-', ' ', '-', ' ', '_', '+', '+', '+', '+', '|'
- 10530 };
- 10531 char _cursident[28] = "+,.-0ahI'fgjklmnopqrstuvwx~";
- 10532
- 10533 int setterm(type)
- 10534 char *type;
- 10535 {
- 10536 unsigned char *ac;
- 10537 int i;
- 10538 #ifdef TIOCGWINSZ
- 10539 struct winsize wsize;
- 10540 #endif
- 10541
- 10542 if (tgetent(termcap, type) != 1) return ERR;
- 10543
- 10544 #ifdef TIOCGWINSZ
- 10545 if (ioctl(0, TIOCGWINSZ, &wsize) == 0) {
- 10546 LINES = wsize.ws_row != 0 ? wsize.ws_row : tgetnum("li");
- 10547 COLS = wsize.ws_col != 0 ? wsize.ws_col : tgetnum("co");
- 10548 } else {
- 10549 #endif
- 10550 LINES = tgetnum("li");
- 10551 COLS = tgetnum("co");
- 10552 #ifdef TIOCGWINSZ
- 10553 }
- 10554 #endif
- 10555 arp = tc;
- 10556 cl = tgetstr("cl", &arp);
- 10557 so = tgetstr("so", &arp);
- 10558 se = tgetstr("se", &arp);
- 10559 cm = tgetstr("cm", &arp);
- 10560 mr = tgetstr("mr", &arp);
- 10561 me = tgetstr("me", &arp);
- 10562 mb = tgetstr("mb", &arp);
- 10563 md = tgetstr("md", &arp);
- 10564 us = tgetstr("us", &arp);
- .Op 83 src/lib/curses/cursesio.c
- 10565 ue = tgetstr("ue", &arp);
- 10566 vi = tgetstr("vi", &arp);
- 10567 ve = tgetstr("ve", &arp);
- 10568 vs = tgetstr("vs", &arp);
- 10569 as = tgetstr("as", &arp);
- 10570 ae = tgetstr("ae", &arp);
- 10571 ac = (unsigned char *) tgetstr("ac", &arp);
- 10572 bl = tgetstr("bl", &arp);
- 10573 vb = tgetstr("vb", &arp);
- 10574
- 10575 if (ac) {
- 10576 while (*ac) {
- 10577 i = 0;
- 10578 while (*ac != _cursident[i]) i++;
- 10579 _cursgraftable[i] = *++ac | A_ALTCHARSET;
- 10580 ac++;
- 10581 }
- 10582 }
- 10583
- 10584 ACS_ULCORNER = _cursgraftable[UPLEFT];
- 10585 ACS_LLCORNER = _cursgraftable[DOWNLEFT];
- 10586 ACS_URCORNER = _cursgraftable[UPRIGHT];
- 10587 ACS_LRCORNER = _cursgraftable[DOWNRIGHT];
- 10588 ACS_RTEE = _cursgraftable[TEERIGHT];
- 10589 ACS_LTEE = _cursgraftable[TEELEFT];
- 10590 ACS_BTEE = _cursgraftable[TEEHEAD];
- 10591 ACS_TTEE = _cursgraftable[TEENORMAL];
- 10592 ACS_HLINE = _cursgraftable[MIDLINE];
- 10593 ACS_VLINE = _cursgraftable[VERTLINE];
- 10594 ACS_PLUS = _cursgraftable[CROSS];
- 10595 ACS_S1 = _cursgraftable[UPLINE];
- 10596 ACS_S9 = _cursgraftable[DOWNLINE];
- 10597 ACS_DIAMOND = _cursgraftable[DIAMOND];
- 10598 ACS_CKBOARD = _cursgraftable[GREYSQUARE];
- 10599 ACS_DEGREE = _cursgraftable[DEGREE];
- 10600 ACS_PLMINUS = _cursgraftable[PLUSMINUS];
- 10601 ACS_BULLET = 'o'; /* where the hell is a bullet defined in
- 10602 * termcap ??? */
- 10603 ACS_LARROW = _cursgraftable[LEFTARROW];
- 10604 ACS_RARROW = _cursgraftable[RIGHTARROW];
- 10605 ACS_DARROW = _cursgraftable[DOWNARROW];
- 10606 ACS_UARROW = _cursgraftable[UPARROW];
- 10607 ACS_BOARD = _cursgraftable[EMPTYSQUARE];
- 10608 ACS_LANTERN = _cursgraftable[LATERN];
- 10609 ACS_BLOCK = _cursgraftable[FULLSQUARE];
- 10610 /* Wow, I got it! */
- 10611 return OK;
- 10612 }
-
- 10614 void gettmode()
- 10615 {
- 10616 tcgetattr(0, &_orig_tty);
- 10617 tcgetattr(0, &_tty);
- 10618 _cursvar.echoit = (_tty.c_lflag & ECHO) != 0;
- 10619 _cursvar.rawmode = (_tty.c_lflag & (ICANON|ISIG)) == 0;
- 10620 _cursvar.cbrkmode = (_tty.c_lflag & (ICANON|ISIG)) == ISIG;
- 10621 NONL = (_tty.c_iflag & ICRNL) != 0;
- 10622 }
- .Ep 84 src/lib/curses/endwin.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/endwin.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10700 #include <curses.h>
- 10701 #include "curspriv.h"
- 10702 #include <termcap.h>
- 10703
- 10704 int endwin()
- 10705 {
- 10706 extern char *me;
- 10707
- 10708 curs_set(1);
- 10709 poscur(LINES - 1, 0);
- 10710 refresh();
- 10711 tputs(me, 1, outc);
- 10712 delwin(stdscr);
- 10713 delwin(curscr);
- 10714 delwin(_cursvar.tmpwin);
- 10715 resetty();
- 10716 return(OK);
- 10717 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/flash.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10800 #include <curses.h>
- 10801 #include "curspriv.h"
- 10802 #include <termcap.h>
- 10803
- 10804 extern char *bl, *vb;
- 10805
- 10806 /* Flash() flashes the terminal screen. */
- 10807 void flash()
- 10808 {
- 10809 if (vb)
- 10810 tputs(vb, 1, outc);
- 10811 else if (bl)
- 10812 tputs(bl, 1, outc);
- 10813 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/initscr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 10900 /* initscr.c - initialize the curses library */
- 10901
- 10902 #include <stdlib.h>
- 10903 #include <curses.h>
- 10904 #include "curspriv.h"
- 10905
- 10906 WINDOW *initscr()
- 10907 {
- 10908 char *term;
- 10909
- .Op 85 src/lib/curses/initscr.c
- 10910 if ((term = getenv("TERM")) == NULL) return NULL;
- 10911 setterm(term);
- 10912 gettmode();
- 10913 if ((_cursvar.tmpwin = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
- 10914 if ((curscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
- 10915 if ((stdscr = newwin(LINES, COLS, 0, 0)) == NULL) return NULL;
- 10916 clearok(curscr, TRUE);
- 10917 return(stdscr);
- 10918 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/longname.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11000 #include <curses.h>
- 11001 #include "curspriv.h"
- 11002
- 11003 /****************************************************************/
- 11004 /* Longname() returns a pointer to a string describing the */
- 11005 /* User terminal. */
- 11006 /****************************************************************/
- 11007
- 11008 char *longname()
- 11009 {
- 11010 return("not implemented");
- 11011 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/move.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11100 #include <curses.h>
- 11101 #include "curspriv.h"
- 11102
- 11103 /****************************************************************/
- 11104 /* Wmove() moves the cursor in window 'win' to position (x,y). */
- 11105 /****************************************************************/
- 11106
- 11107 int wmove(win, y, x)
- 11108 WINDOW *win;
- 11109 int y;
- 11110 int x;
- 11111 {
- 11112 if ((x<0) || (x>win->_maxx) || (y<win->_regtop) || (y>win->_regbottom))
- 11113 return(ERR);
- 11114 win->_curx = x;
- 11115 win->_cury = y;
- 11116 return(OK);
- 11117 }
- .Ep 86 src/lib/curses/mvcursor.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/mvcursor.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11200 #include <curses.h>
- 11201 #include "curspriv.h"
- 11202
- 11203 /****************************************************************/
- 11204 /* Mvcur(oldy,oldx,newy,newx) the display cursor to <newy,newx> */
- 11205 /****************************************************************/
- 11206
- 11207 int mvcur(oldy, oldx, newy, newx)
- 11208 int oldy;
- 11209 int oldx;
- 11210 int newy;
- 11211 int newx;
- 11212 {
- 11213 if ((newy >= LINES) || (newx >= COLS) || (newy < 0) || (newx < 0))
- 11214 return(ERR);
- 11215 poscur(newy, newx);
- 11216 _cursvar.cursrow = newy;
- 11217 _cursvar.curscol = newx;
- 11218 return(OK);
- 11219 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/newwin.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11300 #include <stdlib.h>
- 11301 #include <curses.h>
- 11302 #include "curspriv.h"
- 11303
- 11304 /****************************************************************/
- 11305 /* Makenew() allocates all data for a new window except the */
- 11306 /* Actual lines themselves. */
- 11307 /****************************************************************/
- 11308
- 11309 _PROTOTYPE(static WINDOW *makenew, (int nlines, int ncols, int begy,int begx));
- 11310
- 11311 static WINDOW *makenew(num_lines, num_columns, begy, begx)
- 11312 int num_lines, num_columns, begy, begx;
- 11313 {
- 11314 int i;
- 11315 WINDOW *win;
- 11316
- 11317 /* Allocate the window structure itself */
- 11318 if ((win = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
- 11319 return((WINDOW *) ERR);
- 11320
- 11321 /* Allocate the line pointer array */
- 11322 if ((win->_line = (int **) calloc(num_lines, sizeof(int *))) == NULL) {
- 11323 free(win);
- 11324 return((WINDOW *) ERR);
- .Op 87 src/lib/curses/newwin.c
- 11325 }
- 11326
- 11327 /* Allocate the minchng and maxchng arrays */
- 11328 if ((win->_minchng = (int *) calloc(num_lines, sizeof(int))) == NULL) {
- 11329 free(win);
- 11330 free(win->_line);
- 11331 return((WINDOW *) ERR);
- 11332 }
- 11333 if ((win->_maxchng = (int *) calloc(num_lines, sizeof(int))) == NULL) {
- 11334 free(win);
- 11335 free(win->_line);
- 11336 free(win->_minchng);
- 11337 return((WINDOW *) ERR);
- 11338 }
- 11339
- 11340 /* Initialize window variables */
- 11341 win->_curx = 0;
- 11342 win->_cury = 0;
- 11343 win->_maxy = num_lines - 1;
- 11344 win->_maxx = num_columns - 1;
- 11345 win->_begy = begy;
- 11346 win->_begx = begx;
- 11347 win->_flags = 0;
- 11348 win->_attrs = ATR_NRM;
- 11349 win->_tabsize = 8;
- 11350 win->_clear = FALSE;
- 11351 win->_leave = FALSE;
- 11352 win->_scroll = FALSE;
- 11353 win->_nodelay = FALSE;
- 11354 win->_keypad = FALSE;
- 11355 win->_regtop = 0;
- 11356 win->_regbottom = num_lines - 1;
- 11357
- 11358 /* Init to say window unchanged */
- 11359 for (i = 0; i < num_lines; i++) {
- 11360 win->_minchng[i] = 0;
- 11361 win->_maxchng[i] = num_columns - 1;
- 11362 }
- 11363
- 11364 /* Set flags for window properties */
- 11365 if ((begy + num_lines) == LINES) {
- 11366 win->_flags |= _ENDLINE;
- 11367 if ((begx == 0) && (num_columns == COLS) && (begy == 0))
- 11368 win->_flags |= _FULLWIN;
- 11369 } /* if */
- 11370 if (((begy + num_lines) == LINES) && ((begx + num_columns) == COLS))
- 11371 win->_flags |= _SCROLLWIN;
- 11372 return(win);
- 11373 }
-
-
- 11376 /****************************************************************/
- 11377 /* Newwin() creates a new window with size num_lines * num_co- */
- 11378 /* Lumns, and origin begx,begy relative to the SCREEN. Special */
- 11379 /* Case: if num_lines and/or num_columns is 0, the remainder of */
- 11380 /* The screen is used. */
- 11381 /****************************************************************/
- 11382 WINDOW *newwin(num_lines, num_columns, begy, begx)
- 11383 int num_lines, num_columns, begy, begx;
- 11384 {
- .Ep 88 src/lib/curses/newwin.c
- 11385 WINDOW *win;
- 11386 int *ptr;
- 11387 int i, j;
- 11388
- 11389 if (num_lines == 0) num_lines = LINES - begy;
- 11390 if (num_columns == 0) num_columns = COLS - begx;
- 11391 if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR)
- 11392 return((WINDOW *) ERR);
- 11393 for (i = 0; i < num_lines; i++) { /* make and clear the lines */
- 11394 if ((win->_line[i] = (int *)calloc(num_columns, sizeof(int))) == NULL){
- 11395 for (j = 0; j < i; j++) /* if error, free all the data */
- 11396 free(win->_line[j]);
- 11397 free(win->_minchng);
- 11398 free(win->_maxchng);
- 11399 free(win->_line);
- 11400 free(win);
- 11401 return((WINDOW *) ERR);
- 11402 } else {
- 11403 for (ptr = win->_line[i]; ptr < win->_line[i] + num_columns;)
- 11404 *ptr++ = ' ' | ATR_NRM;
- 11405 }
- 11406 }
- 11407 return(win);
- 11408 }
-
-
- 11411 /****************************************************************/
- 11412 /* Subwin() creates a sub-window in the 'orig' window, with */
- 11413 /* Size num_lines * num_columns, and with origin begx, begy */
- 11414 /* Relative to the SCREEN. Special case: if num_lines and/or */
- 11415 /* Num_columns is 0, the remainder of the original window is */
- 11416 /* Used. The subwindow uses the original window's line buffers */
- 11417 /* To store it's own lines. */
- 11418 /****************************************************************/
- 11419 WINDOW *subwin(orig, num_lines, num_columns, begy, begx)
- 11420 WINDOW *orig;
- 11421 int num_lines, num_columns, begy, begx;
- 11422 {
- 11423 WINDOW *win;
- 11424 int i, j, k;
- 11425
- 11426 /* Make sure window fits inside the original one */
- 11427 if (begy < orig->_begy || begx < orig->_begx ||
- 11428 (begy + num_lines) > (orig->_begy + orig->_maxy) ||
- 11429 (begx + num_columns) > (orig->_begx + orig->_maxx) )
- 11430 return((WINDOW *) ERR);
- 11431
- 11432 if (num_lines == 0) num_lines = orig->_maxy - (begy - orig->_begy);
- 11433 if (num_columns == 0) num_columns = orig->_maxx - (begx - orig->_begx);
- 11434 if ((win = makenew(num_lines, num_columns, begy, begx)) == (WINDOW *) ERR)
- 11435 return((WINDOW *) ERR);
- 11436
- 11437 /* Set line pointers the same as in the original window */
- 11438 j = begy - orig->_begy;
- 11439 k = begx - orig->_begx;
- 11440 for (i = 0; i < num_lines; i++) win->_line[i] = (orig->_line[j++]) + k;
- 11441 win->_flags |= _SUBWIN;
- 11442 return(win);
- 11443 }
- .Op 89 src/lib/curses/options.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/options.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11500 #include <curses.h>
- 11501 #include "curspriv.h"
- 11502
- 11503 static bool hasold = FALSE; /* for remembering old cursor type */
- 11504 static int oldmode;
- 11505
- 11506 /****************************************************************/
- 11507 /* Idlok() is used to set flag for using the terminal insert/ */
- 11508 /* Delete line capabilities. This is not relevant for the PC */
- 11509 /* Version of curses, and thus nothing is done. */
- 11510 /****************************************************************/
- 11511 void idlok(win, flag)
- 11512 WINDOW *win;
- 11513 bool flag;
- 11514 {
- 11515 }
-
- 11517 /****************************************************************/
- 11518 /* Clearok() marks window 'win' to cause screen clearing and */
- 11519 /* Redraw the next time a refresh is done. */
- 11520 /****************************************************************/
- 11521 void clearok(win, flag)
- 11522 WINDOW *win;
- 11523 bool flag;
- 11524 {
- 11525 if (win == curscr)
- 11526 _cursvar.tmpwin->_clear = flag;
- 11527 else
- 11528 win->_clear = flag;
- 11529 }
-
- 11531 /****************************************************************/
- 11532 /* Leaveok() marks window 'win' to allow the update routines */
- 11533 /* To leave the hardware cursor where it happens to be at the */
- 11534 /* End of update. Usually used in combination with cursoff(). */
- 11535 /****************************************************************/
- 11536
- 11537 void leaveok(win, flag)
- 11538 WINDOW *win;
- 11539 bool flag;
- 11540 {
- 11541 win->_leave = flag;
- 11542 }
-
- 11544 /****************************************************************/
- 11545 /* Scrollok() marks window 'win' to allow the scrolling region */
- 11546 /* Of it to actually scroll. */
- 11547 /****************************************************************/
- 11548 void scrollok(win, flag)
- 11549 WINDOW *win;
- 11550 bool flag;
- 11551 {
- 11552 win->_scroll = flag;
- 11553 }
-
- .Ep 90 src/lib/curses/options.c
- 11555 /****************************************************************/
- 11556 /* Nodelay() marks the window to make character input non- */
- 11557 /* Waiting, i.e. if there is no character to get, -1 will be */
- 11558 /* Returned. */
- 11559 /****************************************************************/
- 11560 void nodelay(win, flag)
- 11561 WINDOW *win;
- 11562 bool flag;
- 11563 {
- 11564 win->_nodelay = flag;
- 11565 }
-
- 11567 /****************************************************************/
- 11568 /* Keypad() marks window 'win' to use the special keypad mode. */
- 11569 /****************************************************************/
- 11570 void keypad(win, flag)
- 11571 WINDOW *win;
- 11572 bool flag;
- 11573 {
- 11574 win->_keypad = flag;
- 11575 }
-
- 11577 /****************************************************************/
- 11578 /* Meta() allows use of any alternate character set allowed by */
- 11579 /* The terminal. We always allow this on the PC, so this one */
- 11580 /* Does nothing. */
- 11581 /****************************************************************/
- 11582 void meta(win, flag)
- 11583 WINDOW *win;
- 11584 bool flag;
- 11585 {
- 11586 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/overlay.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11600 /****************************************************************/
- 11601 /* Overlay() and overwrite() functions of the PCcurses package */
- 11602 /* */
- 11603 /****************************************************************/
- 11604 /* This version of curses is based on ncurses, a curses version */
- 11605 /* Originally written by Pavel Curtis at Cornell University. */
- 11606 /* I have made substantial changes to make it run on IBM PC's, */
- 11607 /* And therefore consider myself free to make it public domain. */
- 11608 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 11609 /****************************************************************/
- 11610 /* 1.0: Release: 870515 */
- 11611 /****************************************************************/
- 11612 /* Modified to run under the MINIX operating system by Don Cope */
- 11613 /* These changes are also released into the public domain. */
- 11614 /* 900906 */
- 11615 /****************************************************************/
- 11616
- 11617 #include <curses.h>
- 11618 #include "curspriv.h"
- 11619
- .Op 91 src/lib/curses/overlay.c
- 11620 /****************************************************************/
- 11621 /* Overlay() overwrites 'win1' upon 'win2', with origins alig- */
- 11622 /* Ned. Overlay is transparent; blanks from 'win1' are not */
- 11623 /* Copied to 'win2'. */
- 11624 /****************************************************************/
- 11625 void overlay(win1, win2)
- 11626 WINDOW *win1, *win2;
- 11627 {
- 11628 int *minchng;
- 11629 int *maxchng;
- 11630 int *w1ptr;
- 11631 int *w2ptr;
- 11632 int attrs;
- 11633 int col;
- 11634 int line;
- 11635 int last_line;
- 11636 int last_col;
- 11637
- 11638 last_col = min(win1->_maxx, win2->_maxx);
- 11639 last_line = min(win1->_maxy, win2->_maxy);
- 11640 attrs = win2->_attrs & ATR_MSK;
- 11641 minchng = win2->_minchng;
- 11642 maxchng = win2->_maxchng;
- 11643
- 11644 for (line = 0; line <= last_line; line++) {
- 11645 register short fc, lc = 0;
- 11646 w1ptr = win1->_line[line];
- 11647 w2ptr = win2->_line[line];
- 11648 fc = _NO_CHANGE;
- 11649 for (col = 0; col <= last_col; col++) {
- 11650 if ((*w1ptr & CHR_MSK) != ' ') {
- 11651 *w2ptr = (*w1ptr & CHR_MSK) | attrs;
- 11652 if (fc == _NO_CHANGE) fc = col;
- 11653 lc = col;
- 11654 }
- 11655 w1ptr++;
- 11656 w2ptr++;
- 11657 }
- 11658
- 11659 if (*minchng == _NO_CHANGE) {
- 11660 *minchng = fc;
- 11661 *maxchng = lc;
- 11662 } else if (fc != _NO_CHANGE) {
- 11663 if (fc < *minchng) *minchng = fc;
- 11664 if (lc > *maxchng) *maxchng = lc;
- 11665 }
- 11666 minchng++;
- 11667 maxchng++;
- 11668 } /* for */
- 11669 } /* overlay */
- 11670
- 11671 /****************************************************************/
- 11672 /* Overwrite() overwrites 'win1' upon 'win2', with origins */
- 11673 /* Aligned. Overwrite is non-transparent; blanks from 'win1' */
- 11674 /* Are copied to 'win2'. */
- 11675 /****************************************************************/
- 11676 void overwrite(win1, win2)
- 11677 WINDOW *win1, *win2;
- 11678 {
- 11679 int *minchng;
- .Ep 92 src/lib/curses/overlay.c
- 11680 int *maxchng;
- 11681 int *w1ptr;
- 11682 int *w2ptr;
- 11683 int attrs;
- 11684 int col;
- 11685 int line;
- 11686 int last_line;
- 11687 int last_col;
- 11688
- 11689 last_col = min(win1->_maxx, win2->_maxx);
- 11690 last_line = min(win1->_maxy, win2->_maxy);
- 11691 attrs = win2->_attrs & ATR_MSK;
- 11692 minchng = win2->_minchng;
- 11693 maxchng = win2->_maxchng;
- 11694
- 11695 for (line = 0; line <= last_line; line++) {
- 11696 register short fc, lc = 0;
- 11697
- 11698 w1ptr = win1->_line[line];
- 11699 w2ptr = win2->_line[line];
- 11700 fc = _NO_CHANGE;
- 11701
- 11702 for (col = 0; col <= last_col; col++) {
- 11703 if ((*w1ptr & CHR_MSK) != (*w2ptr & CHR_MSK)) {
- 11704 *w2ptr = (*w1ptr & CHR_MSK) | attrs;
- 11705
- 11706 if (fc == _NO_CHANGE) fc = col;
- 11707 lc = col;
- 11708 }
- 11709 w1ptr++;
- 11710 w2ptr++;
- 11711 } /* for */
- 11712
- 11713 if (*minchng == _NO_CHANGE) {
- 11714 *minchng = fc;
- 11715 *maxchng = lc;
- 11716 } else if (fc != _NO_CHANGE) {
- 11717 if (fc < *minchng) *minchng = fc;
- 11718 if (lc > *maxchng) *maxchng = lc;
- 11719 }
- 11720 minchng++;
- 11721 maxchng++;
- 11722 }
- 11723 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/prntscan.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 11800 #include <string.h>
- 11801 #include <curses.h>
- 11802 #include "curspriv.h"
- 11803
- 11804 static char printscanbuf[513]; /* buffer used during I/O */
- 11805
- 11806 /****************************************************************/
- 11807 /* Wprintw(win,fmt,args) does a printf() in window 'win'. */
- 11808 /****************************************************************/
- 11809 int wprintw(WINDOW *win, const char *fmt, ...)
- .Op 93 src/lib/curses/prntscan.c
- 11810 {
- 11811 va_list args;
- 11812
- 11813 va_start(args, fmt);
- 11814 vsprintf(printscanbuf, fmt, args);
- 11815 if (waddstr(win, printscanbuf) == ERR) return(ERR);
- 11816 return(strlen(printscanbuf));
- 11817 }
-
- 11819 /****************************************************************/
- 11820 /* Printw(fmt,args) does a printf() in stdscr. */
- 11821 /****************************************************************/
- 11822 int printw(const char *fmt, ...)
- 11823 {
- 11824 va_list args;
- 11825
- 11826 va_start(args, fmt);
- 11827 vsprintf(printscanbuf, fmt, args);
- 11828 if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
- 11829 return(strlen(printscanbuf));
- 11830 } /* printw */
- 11831
- 11832 /****************************************************************/
- 11833 /* Mvprintw(fmt,args) moves the stdscr cursor to a new posi- */
- 11834 /* tion, then does a printf() in stdscr. */
- 11835 /****************************************************************/
- 11836 int mvprintw(int y, int x, const char *fmt, ...)
- 11837 {
- 11838 va_list args;
- 11839
- 11840 va_start(args, fmt);
- 11841 if (wmove(stdscr, y, x) == ERR) return(ERR);
- 11842 vsprintf(printscanbuf, fmt, args);
- 11843 if (waddstr(stdscr, printscanbuf) == ERR) return(ERR);
- 11844 return(strlen(printscanbuf));
- 11845 }
-
- 11847 /****************************************************************/
- 11848 /* Mvwprintw(win,fmt,args) moves the window 'win's cursor to */
- 11849 /* A new position, then does a printf() in window 'win'. */
- 11850 /****************************************************************/
- 11851 int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...)
- 11852 {
- 11853 va_list args;
- 11854
- 11855 va_start(args, fmt);
- 11856 if (wmove(win, y, x) == ERR) return(ERR);
- 11857 vsprintf(printscanbuf, fmt, args);
- 11858 if (waddstr(win, printscanbuf) == ERR) return(ERR);
- 11859 return(strlen(printscanbuf));
- 11860 } /* mvwprintw */
- 11861
- 11862 /****************************************************************/
- 11863 /* Wscanw(win,fmt,args) gets a string via window 'win', then */
- 11864 /* Scans the string using format 'fmt' to extract the values */
- 11865 /* And put them in the variables pointed to the arguments. */
- 11866 /****************************************************************/
- 11867 int wscanw(WINDOW *win, const char *fmt, ...)
- 11868 {
- 11869 va_list args;
- .Ep 94 src/lib/curses/prntscan.c
- 11870
- 11871 va_start(args, fmt);
- 11872 wrefresh(win); /* set cursor */
- 11873 if (wgetstr(win, printscanbuf) == ERR) /* get string */
- 11874 return(ERR);
- 11875 return(vsscanf(printscanbuf, fmt, args));
- 11876 } /* wscanw */
- 11877
- 11878 /****************************************************************/
- 11879 /* Scanw(fmt,args) gets a string via stdscr, then scans the */
- 11880 /* String using format 'fmt' to extract the values and put them */
- 11881 /* In the variables pointed to the arguments. */
- 11882 /****************************************************************/
- 11883 int scanw(const char *fmt, ...)
- 11884 {
- 11885 va_list args;
- 11886
- 11887 va_start(args, fmt);
- 11888 wrefresh(stdscr); /* set cursor */
- 11889 if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
- 11890 return(ERR);
- 11891 return(vsscanf(printscanbuf, fmt, args));
- 11892 } /* scanw */
- 11893
- 11894 /****************************************************************/
- 11895 /* Mvscanw(y,x,fmt,args) moves stdscr's cursor to a new posi- */
- 11896 /* Tion, then gets a string via stdscr and scans the string */
- 11897 /* Using format 'fmt' to extract the values and put them in the */
- 11898 /* Variables pointed to the arguments. */
- 11899 /****************************************************************/
- 11900 int mvscanw(int y, int x, const char *fmt, ...)
- 11901 {
- 11902 va_list args;
- 11903
- 11904 va_start(args, fmt);
- 11905 if (wmove(stdscr, y, x) == ERR) return(ERR);
- 11906 wrefresh(stdscr); /* set cursor */
- 11907 if (wgetstr(stdscr, printscanbuf) == ERR) /* get string */
- 11908 return(ERR);
- 11909 return(vsscanf(printscanbuf, fmt, args));
- 11910 } /* mvscanw */
- 11911
- 11912 /****************************************************************/
- 11913 /* Mvwscanw(win,y,x,fmt,args) moves window 'win's cursor to a */
- 11914 /* New position, then gets a string via 'win' and scans the */
- 11915 /* String using format 'fmt' to extract the values and put them */
- 11916 /* In the variables pointed to the arguments. */
- 11917 /****************************************************************/
- 11918 int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...)
- 11919 {
- 11920 va_list args;
- 11921
- 11922 va_start(args, fmt);
- 11923 if (wmove(win, y, x) == ERR) return(ERR);
- 11924 wrefresh(win); /* set cursor */
- 11925 if (wgetstr(win, printscanbuf) == ERR) /* get string */
- 11926 return(ERR);
- 11927 return(vsscanf(printscanbuf, fmt, args));
- 11928 } /* mvwscanw */
- .Op 95 src/lib/curses/refresh.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/refresh.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12000 /* refresh.c */
- 12001
- 12002 #include <curses.h>
- 12003 #include "curspriv.h"
- 12004
- 12005 /* Wrefresh() updates window win's area of the physical screen. */
- 12006 void wrefresh(win)
- 12007 WINDOW *win;
- 12008 {
- 12009 if (win == curscr)
- 12010 curscr->_clear = TRUE;
- 12011 else
- 12012 wnoutrefresh(win);
- 12013 doupdate();
- 12014 }
-
- 12016 /****************************************************************/
- 12017 /* Wnoutrefresh() updates the image of the desired screen, */
- 12018 /* Without doing physical update (copies window win's image to */
- 12019 /* The _cursvar.tmpwin window, which is hidden from the user). */
- 12020 /****************************************************************/
- 12021
- 12022 void wnoutrefresh(win)
- 12023 register WINDOW *win;
- 12024 {
- 12025 register int *dst; /* start destination in temp window */
- 12026 register int *end; /* end destination in temp window */
- 12027 register int *src; /* source in user window */
- 12028 register int first; /* first changed char on line */
- 12029 register int last; /* last changed char on line */
- 12030 WINDOW *nscr;
- 12031 int begy; /* window's place on screen */
- 12032 int begx;
- 12033 int i;
- 12034 int j;
- 12035
- 12036 nscr = _cursvar.tmpwin;
- 12037 begy = win->_begy;
- 12038 begx = win->_begx;
- 12039
- 12040 for (i = 0, j = begy; i <= win->_maxy; i++, j++) {
- 12041 if (win->_minchng[i] != _NO_CHANGE) {
- 12042 first = win->_minchng[i];
- 12043 last = win->_maxchng[i];
- 12044 dst = &(nscr->_line[j][begx + first]);
- 12045 end = &(nscr->_line[j][begx + last]);
- 12046 src = &(win->_line[i][first]);
- 12047
- 12048 while (dst <= end) /* copy user line to temp window */
- 12049 *dst++ = *src++;
- 12050
- 12051 first += begx; /* nscr's min/max change positions */
- 12052 last += begx;
- 12053
- 12054 if ((nscr->_minchng[j] == _NO_CHANGE) || (nscr->_minchng[j] > first))
- .Ep 96 src/lib/curses/refresh.c
- 12055 nscr->_minchng[j] = first;
- 12056 if (last > nscr->_maxchng[j]) nscr->_maxchng[j] = last;
- 12057
- 12058 win->_minchng[i] = _NO_CHANGE; /* updated now */
- 12059 } /* if */
- 12060 win->_maxchng[i] = _NO_CHANGE; /* updated now */
- 12061 } /* for */
- 12062
- 12063 if (win->_clear) {
- 12064 win->_clear = FALSE;
- 12065 nscr->_clear = TRUE;
- 12066 } /* if */
- 12067 if (!win->_leave) {
- 12068 nscr->_cury = win->_cury + begy;
- 12069 nscr->_curx = win->_curx + begx;
- 12070 } /* if */
- 12071 } /* wnoutrefresh */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/scrreg.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12100 /****************************************************************/
- 12101 /* Wsetscrreg() routine of the PCcurses package */
- 12102 /* */
- 12103 /****************************************************************/
- 12104 /* This version of curses is based on ncurses, a curses version */
- 12105 /* Originally written by Pavel Curtis at Cornell University. */
- 12106 /* I have made substantial changes to make it run on IBM PC's, */
- 12107 /* And therefore consider myself free to make it public domain. */
- 12108 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 12109 /****************************************************************/
- 12110 /* 1.0: Release: 870515 */
- 12111 /****************************************************************/
- 12112 /* Modified to run under the MINIX operating system by Don Cope */
- 12113 /* These changes are also released into the public domain. */
- 12114 /* 900906 */
- 12115 /****************************************************************/
- 12116
- 12117 #include <curses.h>
- 12118 #include "curspriv.h"
- 12119
- 12120 /****************************************************************/
- 12121 /* Wsetscrreg() set the scrolling region of window 'win' to in- */
- 12122 /* Clude all lines between 'top' and 'bottom'. */
- 12123 /****************************************************************/
- 12124
- 12125 int wsetscrreg(win, top, bottom)
- 12126 WINDOW *win;
- 12127 int top;
- 12128 int bottom;
- 12129 {
- 12130 if ((0 <= top) &&
- 12131 (top <= win->_cury)
- 12132 &&
- 12133 (win->_cury <= bottom)
- 12134 &&
- .Op 97 src/lib/curses/scrreg.c
- 12135 (bottom <= win->_maxy)
- 12136 ) {
- 12137 win->_regtop = top;
- 12138 win->_regbottom = bottom;
- 12139 return(OK);
- 12140 }
- 12141
- 12142 /* If */
- 12143 else
- 12144 return(ERR);
- 12145 } /* wsetscrreg */
- 12146
- 12147 /****************************************************************/
- 12148 /* Setscrreg() set the scrolling region of stdscr to include */
- 12149 /* All lines between 'top' and 'bottom'. */
- 12150 /****************************************************************/
- 12151
- 12152 int setscrreg(top, bottom)
- 12153 int top;
- 12154 int bottom;
- 12155 {
- 12156 return(wsetscrreg(stdscr, top, bottom));
- 12157 } /* setscrreg */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/setterm.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12200 #include <curses.h>
- 12201 #include "curspriv.h"
- 12202
- 12203 _PROTOTYPE( static void ttysetflags, (void) );
- 12204
- 12205 static void ttysetflags()
- 12206 {
- 12207 _tty.c_iflag |= ICRNL | IXON;
- 12208 _tty.c_oflag |= OPOST | ONLCR;
- 12209 _tty.c_lflag |= ECHO | ICANON | IEXTEN | ISIG;
- 12210
- 12211 if (_cursvar.rawmode) {
- 12212 _tty.c_iflag &= ~(ICRNL | IXON);
- 12213 _tty.c_oflag &= ~(OPOST);
- 12214 _tty.c_lflag &= ~(ICANON | IEXTEN | ISIG);
- 12215 }
- 12216 if (_cursvar.cbrkmode) {
- 12217 _tty.c_lflag &= ~(ICANON);
- 12218 }
- 12219 if (!_cursvar.echoit) {
- 12220 _tty.c_lflag &= ~(ECHO | ECHONL);
- 12221 }
- 12222 if (NONL) {
- 12223 _tty.c_iflag &= ~(ICRNL);
- 12224 _tty.c_oflag &= ~(ONLCR);
- 12225 }
- 12226 tcsetattr(0, TCSANOW, &_tty);
- 12227 } /* ttysetflags */
- 12228
- 12229 void raw()
- .Ep 98 src/lib/curses/setterm.c
- 12230 {
- 12231 _cursvar.rawmode = TRUE;
- 12232 ttysetflags();
- 12233 } /* raw */
- 12234
- 12235 void noraw()
- 12236 {
- 12237 _cursvar.rawmode = FALSE;
- 12238 ttysetflags();
- 12239 } /* noraw */
- 12240
- 12241 void echo()
- 12242 {
- 12243 _cursvar.echoit = TRUE;
- 12244 ttysetflags();
- 12245 }
-
- 12247 void noecho()
- 12248 {
- 12249 _cursvar.echoit = FALSE;
- 12250 ttysetflags();
- 12251 }
-
- 12253 void nl()
- 12254 {
- 12255 NONL = FALSE;
- 12256 ttysetflags();
- 12257 } /* nl */
- 12258
- 12259 void nonl()
- 12260 {
- 12261 NONL = TRUE;
- 12262 ttysetflags();
- 12263 } /* nonl */
- 12264
- 12265 void cbreak()
- 12266 {
- 12267 _cursvar.cbrkmode = TRUE;
- 12268 ttysetflags();
- 12269 } /* cbreak */
- 12270
- 12271 void nocbreak()
- 12272 {
- 12273 _cursvar.cbrkmode = FALSE;
- 12274 ttysetflags();
- 12275 } /* nocbreak */
- .Op 99 src/lib/curses/tabsize.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/tabsize.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12300 /****************************************************************/
- 12301 /* Tabsize() routines of the PCcurses package */
- 12302 /* */
- 12303 /****************************************************************/
- 12304 /* This version of curses is based on ncurses, a curses version */
- 12305 /* Originally written by Pavel Curtis at Cornell University. */
- 12306 /* I have made substantial changes to make it run on IBM PC's, */
- 12307 /* And therefore consider myself free to make it public domain. */
- 12308 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 12309 /****************************************************************/
- 12310 /* 1.0: Release: 870515 */
- 12311 /****************************************************************/
- 12312 /* Modified to run under the MINIX operating system by Don Cope */
- 12313 /* These changes are also released into the public domain. */
- 12314 /* 900906 */
- 12315 /****************************************************************/
- 12316
- 12317 #include <curses.h>
- 12318 #include "curspriv.h"
- 12319
- 12320 /****************************************************************/
- 12321 /* Wtabsize(win,ts) sets the tabsize of window 'win' to 'ts', */
- 12322 /* And returns the original value. */
- 12323 /****************************************************************/
- 12324
- 12325 int wtabsize(win, ts)
- 12326 WINDOW *win;
- 12327 int ts;
- 12328 {
- 12329 int origval;
- 12330
- 12331 origval = win->_tabsize;
- 12332 win->_tabsize = ts;
- 12333 return(origval);
- 12334 } /* wtabsize */
- 12335
- 12336 /****************************************************************/
- 12337 /* Tabsize(ts) sets the tabsize of stdscr to 'ts', and returns */
- 12338 /* The original value. */
- 12339 /****************************************************************/
- 12340
- 12341 int tabsize(ts)
- 12342 int ts;
- 12343 {
- 12344 int origval;
- 12345
- 12346 origval = stdscr->_tabsize;
- 12347 stdscr->_tabsize = ts;
- 12348 return(origval);
- 12349 } /* tabsize */
- .Ep 100 src/lib/curses/termmisc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/termmisc.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12400 #include <curses.h>
- 12401 #include "curspriv.h"
- 12402
- 12403 /* Static variables or saving terminal modes */
- 12404
- 12405 int fixterm()
- 12406 {
- 12407 return(OK);
- 12408 } /* fixterm */
- 12409
- 12410 int resetterm()
- 12411 {
- 12412 return(OK);
- 12413 }
-
- 12415 int saveoldterm()
- 12416 {
- 12417 return(OK);
- 12418 } /* saveoldterm */
- 12419
- 12420 int saveterm()
- 12421 {
- 12422 return(OK);
- 12423 } /* saveterm */
- 12424
- 12425 int baudrate()
- 12426 {
- 12427 return(19200);
- 12428 } /* baudrate */
- 12429
- 12430 /****************************************************************/
- 12431 /* Erasechar(), killchar() returns std MSDOS erase chars. */
- 12432 /****************************************************************/
- 12433
- 12434 int erasechar()
- 12435 {
- 12436 return(_DCCHAR); /* character delete char */
- 12437 } /* erasechar */
- 12438
- 12439 int killchar()
- 12440 {
- 12441 return(_DLCHAR); /* line delete char */
- 12442 } /* killchar */
- 12443
- 12444 /****************************************************************/
- 12445 /* Savetty() and resetty() saves and restores the terminal I/O */
- 12446 /* Settings. */
- 12447 /****************************************************************/
- 12448
- 12449 int savetty()
- 12450 {
- 12451 return(OK);
- 12452 } /* savetty */
- 12453
- 12454 /****************************************************************/
- .Op 101 src/lib/curses/termmisc.c
- 12455 /* Setupterm() sets up the terminal. On a PC, it is always suc- */
- 12456 /* Cessful, and returns 1. */
- 12457 /****************************************************************/
- 12458
- 12459 int setupterm()
- 12460 {
- 12461 return(1);
- 12462 } /* setupterm */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/unctrl.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12500 /****************************************************************/
- 12501 /* Unctrl() routines of the PCcurses package */
- 12502 /* */
- 12503 /****************************************************************/
- 12504 /* This version of curses is based on ncurses, a curses version */
- 12505 /* Originally written by Pavel Curtis at Cornell University. */
- 12506 /* I have made substantial changes to make it run on IBM PC's, */
- 12507 /* And therefore consider myself free to make it public domain. */
- 12508 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 12509 /****************************************************************/
- 12510 /* 1.0: Release: 870515 */
- 12511 /****************************************************************/
- 12512 /* Modified to run under the MINIX operating system by Don Cope */
- 12513 /* These changes are also released into the public domain. */
- 12514 /* 900906 */
- 12515 /****************************************************************/
- 12516
- 12517 #include <curses.h>
- 12518 #include "curspriv.h"
- 12519
- 12520 static char strbuf[3] = {0, 0, 0};
- 12521
- 12522 /****************************************************************/
- 12523 /* Unctrl() returns a char pointer to a string corresponding to */
- 12524 /* Argument character 'c'. */
- 12525 /****************************************************************/
- 12526
- 12527 char *unctrl(c)
- 12528 char c;
- 12529 {
- 12530 int ic = c;
- 12531 ic &= 0xff;
- 12532
- 12533 if ((ic >= ' ') && (ic != 0x7f)) { /* normal characters */
- 12534 strbuf[0] = ic;
- 12535 strbuf[1] = ' ';
- 12536 return(strbuf);
- 12537 } /* if */
- 12538 strbuf[0] = '^'; /* '^' prefix */
- 12539 if (c == 0x7f) /* DEL */
- 12540 strbuf[1] = '?';
- 12541 else /* other control */
- 12542 strbuf[1] = ic + '@';
- 12543 return(strbuf);
- 12544 } /* unctrl */
- .Ep 102 src/lib/curses/update.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/update.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12600 #include <curses.h>
- 12601 #include "curspriv.h"
- 12602 #include <termcap.h>
- 12603
- 12604 static WINDOW *twin; /* used by many routines */
- 12605
- 12606 /****************************************************************/
- 12607 /* Gotoxy() moves the physical cursor to the desired address on */
- 12608 /* The screen. We don't optimize here - on a PC, it takes more */
- 12609 /* Time to optimize than to do things directly. */
- 12610 /****************************************************************/
- 12611
- 12612 _PROTOTYPE(static void gotoxy, (int row, int col ));
- 12613 _PROTOTYPE(static void newattr, (int ch ));
- 12614 _PROTOTYPE(static void Putchar, (int ch ));
- 12615 _PROTOTYPE(static void clrupdate, (WINDOW *scr ));
- 12616 _PROTOTYPE(static void transformline, (int lineno ));
- 12617
- 12618 static void gotoxy(row, col)
- 12619 int row, col;
- 12620 {
- 12621 poscur(row, col);
- 12622 _cursvar.cursrow = row;
- 12623 _cursvar.curscol = col;
- 12624 }
-
- 12626 /* Update attributes */
- 12627 static void newattr(ch)
- 12628 int ch;
- 12629 {
- 12630 extern char *me, *as, *ae, *mb, *md, *mr, *so, *us;
- 12631 static int lastattr = 0;
- 12632
- 12633 if (lastattr != (ch &= ATR_MSK)) {
- 12634 lastattr = ch;
- 12635
- 12636 tputs(me, 1, outc);
- 12637 if (ae) tputs(ae, 1, outc);
- 12638
- 12639 if (ch & A_ALTCHARSET)
- 12640 if (as) tputs(as, 1, outc);
- 12641 if (ch & A_BLINK) tputs(mb, 1, outc);
- 12642 if (ch & A_BOLD) tputs(md, 1, outc);
- 12643 if (ch & A_REVERSE) tputs(mr, 1, outc);
- 12644 if (ch & A_STANDOUT) tputs(so, 1, outc);
- 12645 if (ch & A_UNDERLINE) tputs(us, 1, outc);
- 12646 }
- 12647 }
-
- 12649 /* Putchar() writes a character, with attributes, to the physical
- 12650 screen, but avoids writing to the lower right screen position.
- 12651 Should it care about am?
- 12652 */
- 12653
- 12654 /* Output char with attribute */
- .Op 103 src/lib/curses/update.c
- 12655 static void Putchar(ch)
- 12656 int ch;
- 12657 {
- 12658 if ((_cursvar.cursrow < LINES) || (_cursvar.curscol < COLS)) {
- 12659 newattr(ch);
- 12660 putchar(ch);
- 12661 }
- 12662 }
-
- 12664 /****************************************************************/
- 12665 /* Clrupdate(scr) updates the screen by clearing it and then */
- 12666 /* Redraw it in it's entirety. */
- 12667 /****************************************************************/
- 12668
- 12669 static void clrupdate(scr)
- 12670 WINDOW *scr;
- 12671 {
- 12672 register int *src;
- 12673 register int *dst;
- 12674 register int i;
- 12675 register int j;
- 12676 WINDOW *w;
- 12677
- 12678 w = curscr;
- 12679
- 12680 if (scr != w) { /* copy scr to curscr */
- 12681 for (i = 0; i < LINES; i++) {
- 12682 src = scr->_line[i];
- 12683 dst = w->_line[i];
- 12684 for (j = 0; j < COLS; j++) *dst++ = *src++;
- 12685 } /* for */
- 12686 } /* if */
- 12687 newattr(scr->_attrs);
- 12688 clrscr();
- 12689 scr->_clear = FALSE;
- 12690 for (i = 0; i < LINES; i++) { /* update physical screen */
- 12691 src = w->_line[i];
- 12692 j = 0;
- 12693 while (j < COLS) {
- 12694 if (*src != (' ' | ATR_NRM)) {
- 12695 gotoxy(i, j);
- 12696 while (j < COLS && (*src != (' ' | ATR_NRM))) {
- 12697 Putchar(*src++);
- 12698 j++;
- 12699 }
- 12700 } else {
- 12701 src++;
- 12702 j++;
- 12703 }
- 12704 } /* for */
- 12705 } /* for */
- 12706 fflush(stdout);
- 12707 } /* clrupdate */
- 12708
- 12709 /****************************************************************/
- 12710 /* Transformline() updates the given physical line to look */
- 12711 /* Like the corresponding line in _cursvar.tmpwin. */
- 12712 /****************************************************************/
- 12713
- 12714 static void transformline(lineno)
- .Ep 104 src/lib/curses/update.c
- 12715 register int lineno;
- 12716 {
- 12717 register int *dstp;
- 12718 register int *srcp;
- 12719 register int dstc;
- 12720 register int srcc;
- 12721 int x;
- 12722 int endx;
- 12723
- 12724 x = twin->_minchng[lineno];
- 12725 endx = twin->_maxchng[lineno];
- 12726 dstp = curscr->_line[lineno] + x;
- 12727 srcp = twin->_line[lineno] + x;
- 12728
- 12729 while (x <= endx) {
- 12730 if ((*dstp != *srcp) || (dstc != srcc)) {
- 12731 gotoxy(lineno, x);
- 12732 while (x <= endx && ((*dstp != *srcp) || (dstc != srcc))) {
- 12733 Putchar(*srcp);
- 12734 *dstp++ = *srcp++;
- 12735 x++;
- 12736 }
- 12737 } else {
- 12738 *dstp++ = *srcp++;
- 12739 x++;
- 12740 }
- 12741 } /* for */
- 12742 twin->_minchng[lineno] = _NO_CHANGE;
- 12743 twin->_maxchng[lineno] = _NO_CHANGE;
- 12744 } /* transformline */
- 12745
- 12746 /****************************************************************/
- 12747 /* Doupdate() updates the physical screen to look like _curs- */
- 12748 /* Var.tmpwin if curscr is not 'Clear-marked'. Otherwise it */
- 12749 /* Updates the screen to look like curscr. */
- 12750 /****************************************************************/
- 12751
- 12752 void doupdate()
- 12753 {
- 12754 int i;
- 12755
- 12756 twin = _cursvar.tmpwin;
- 12757 if (curscr->_clear)
- 12758 clrupdate(curscr);
- 12759 else {
- 12760 if (twin->_clear)
- 12761 clrupdate(twin);
- 12762 else {
- 12763 for (i = 0; i < LINES; i++)
- 12764 if (twin->_minchng[i] != _NO_CHANGE)
- 12765 transformline(i);
- 12766 }
- 12767 }
- 12768 curscr->_curx = twin->_curx;
- 12769 curscr->_cury = twin->_cury;
- 12770 gotoxy(curscr->_cury, curscr->_curx);
- 12771 fflush(stdout);
- 12772 } /* doupdate */
- .Op 105 src/lib/curses/waddch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/waddch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12800 #include <curses.h>
- 12801 #include "curspriv.h"
- 12802
- 12803 /****************************************************************/
- 12804 /* Newline() does line advance and returns the new cursor line. */
- 12805 /* If error, return -1. */
- 12806 /****************************************************************/
- 12807
- 12808 _PROTOTYPE( static short newline, (WINDOW *win, int lin));
- 12809
- 12810 static short newline(win, lin)
- 12811 WINDOW *win;
- 12812 int lin;
- 12813 {
- 12814 if (++lin > win->_regbottom) {
- 12815 lin--;
- 12816 if (win->_scroll)
- 12817 scroll(win);
- 12818 else
- 12819 return(-1);
- 12820 } /* if */
- 12821 return(lin);
- 12822 } /* newline */
- 12823
- 12824 /****************************************************************/
- 12825 /* Waddch() inserts character 'c' at the current cursor posi- */
- 12826 /* Tion in window 'win', and takes any actions as dictated by */
- 12827 /* The character. */
- 12828 /****************************************************************/
- 12829
- 12830 int waddch(win, c)
- 12831 WINDOW *win;
- 12832 int c;
- 12833 {
- 12834 int x = win->_curx;
- 12835 int y = win->_cury;
- 12836 int newx;
- 12837 int ch = c;
- 12838 int ts = win->_tabsize;
- 12839
- 12840 ch &= (A_ALTCHARSET | 0xff);
- 12841 if (y > win->_maxy || x > win->_maxx || y < 0 || x < 0) return(ERR);
- 12842 switch (ch) {
- 12843 case 't':
- 12844 for (newx = ((x / ts) + 1) * ts; x < newx; x++) {
- 12845 if (waddch(win, ' ') == ERR) return(ERR);
- 12846 if (win->_curx == 0) /* if tab to next line */
- 12847 return(OK); /* exit the loop */
- 12848 }
- 12849 return(OK);
- 12850
- 12851 case 'n':
- 12852 if (NONL) x = 0;
- 12853 if ((y = newline(win, y)) < 0) return (ERR);
- 12854 break;
- .Ep 106 src/lib/curses/waddch.c
- 12855
- 12856 case 'r': x = 0; break;
- 12857
- 12858 case 'b':
- 12859 if (--x < 0) /* no back over left margin */
- 12860 x = 0;
- 12861 break;
- 12862
- 12863 case 0x7f:
- 12864 {
- 12865 if (waddch(win, '^') == ERR) return(ERR);
- 12866 return(waddch(win, '?'));
- 12867 }
- 12868
- 12869 default:
- 12870 if (ch < ' ') { /* handle control chars */
- 12871 if (waddch(win, '^') == ERR) return(ERR);
- 12872 return(waddch(win, c + '@'));
- 12873 }
- 12874 ch |= (win->_attrs & ATR_MSK);
- 12875 if (win->_line[y][x] != ch) { /* only if data change */
- 12876 if (win->_minchng[y] == _NO_CHANGE)
- 12877 win->_minchng[y] = win->_maxchng[y] = x;
- 12878 else if (x < win->_minchng[y])
- 12879 win->_minchng[y] = x;
- 12880 else if (x > win->_maxchng[y])
- 12881 win->_maxchng[y] = x;
- 12882 } /* if */
- 12883 win->_line[y][x++] = ch;
- 12884 if (x > win->_maxx) { /* wrap around test */
- 12885 x = 0;
- 12886 if ((y = newline(win, y)) < 0) return(ERR);
- 12887 }
- 12888 break;
- 12889
- 12890 } /* switch */
- 12891 win->_curx = x;
- 12892 win->_cury = y;
- 12893 return(OK);
- 12894 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/waddstr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 12900 #include <curses.h>
- 12901 #include "curspriv.h"
- 12902
- 12903 /****************************************************************/
- 12904 /* Waddstr() inserts string 'str' at the current cursor posi- */
- 12905 /* Tion in window 'win', and takes any actions as dictated by */
- 12906 /* The characters. */
- 12907 /****************************************************************/
- 12908
- 12909 int waddstr(win, str)
- .Op 107 src/lib/curses/waddstr.c
- 12910 WINDOW *win;
- 12911 char *str;
- 12912 {
- 12913 while (*str) {
- 12914 if (waddch(win, *str++) == ERR) return(ERR);
- 12915 }
- 12916 return(OK);
- 12917 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wbox.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13000 #include <curses.h>
- 13001 #include "curspriv.h"
- 13002
- 13003 /****************************************************************/
- 13004 /* Wbox(win,ymin,xmin,ymax,xmax,v,h) draws a box in window */
- 13005 /* 'win', enclosing the area xmin-xmax and ymin-xmax. If */
- 13006 /* Xmax and/or ymax is 0, the window max value is used. 'v' and */
- 13007 /* 'h' are the vertical and horizontal characters to use. If */
- 13008 /* 'v' and 'h' are 0, wbox will use the alternate character set */
- 13009 /* In a pretty way. */
- 13010 /****************************************************************/
- 13011
- 13012 int wbox(win, ymin, xmin, ymax, xmax, v, h)
- 13013 WINDOW *win;
- 13014 int ymin, xmin, ymax, xmax;
- 13015 unsigned int v;
- 13016 unsigned int h;
- 13017 {
- 13018 unsigned int vc, hc, ulc, urc, llc, lrc; /* corner chars */
- 13019 int i;
- 13020
- 13021 if (ymax == 0) ymax = win->_maxy;
- 13022 if (xmax == 0) xmax = win->_maxx;
- 13023
- 13024 if (ymin >= win->_maxy || ymax > win->_maxy ||
- 13025 xmin >= win->_maxx || xmax > win->_maxx ||
- 13026 ymin >= ymax || xmin >= xmax)
- 13027 return(ERR);
- 13028
- 13029 vc = v;
- 13030 hc = h;
- 13031 ulc = urc = llc = lrc = vc; /* default same as vertical */
- 13032
- 13033 if (v == 0 && h == 0) {
- 13034 ulc = ACS_ULCORNER;
- 13035 urc = ACS_URCORNER;
- 13036 llc = ACS_LLCORNER;
- 13037 lrc = ACS_LRCORNER;
- 13038 hc = ACS_HLINE;
- 13039 vc = ACS_VLINE;
- 13040 }
- 13041 for (i = xmin + 1; i <= xmax - 1; i++) {
- 13042 win->_line[ymin][i] = hc | win->_attrs;
- 13043 win->_line[ymax][i] = hc | win->_attrs;
- 13044 }
- .Ep 108 src/lib/curses/wbox.c
- 13045 for (i = ymin + 1; i <= ymax - 1; i++) {
- 13046 win->_line[i][xmin] = vc | win->_attrs;
- 13047 win->_line[i][xmax] = vc | win->_attrs;
- 13048 }
- 13049 win->_line[ymin][xmin] = ulc | win->_attrs;
- 13050 win->_line[ymin][xmax] = urc | win->_attrs;
- 13051 win->_line[ymax][xmin] = llc | win->_attrs;
- 13052 win->_line[ymax][xmax] = lrc | win->_attrs;
- 13053
- 13054 for (i = ymin; i <= ymax; i++) {
- 13055 if (win->_minchng[i] == _NO_CHANGE) {
- 13056 win->_minchng[i] = xmin;
- 13057 win->_maxchng[i] = xmax;
- 13058 } else {
- 13059 win->_minchng[i] = min(win->_minchng[i], xmin);
- 13060 win->_maxchng[i] = max(win->_maxchng[i], xmax);
- 13061 }
- 13062 }
- 13063 return(OK);
- 13064 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wclear.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13100 #include <curses.h>
- 13101 #include "curspriv.h"
- 13102
- 13103 /****************************************************************/
- 13104 /* Wclear() fills all lines of window 'win' with blanks, and */
- 13105 /* Marks the window to be cleared at next refresh operation. */
- 13106 /****************************************************************/
- 13107
- 13108 void wclear(win)
- 13109 WINDOW *win;
- 13110 {
- 13111 werase(win);
- 13112 win->_clear = TRUE;
- 13113 } /* wclear */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wclrtobot.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13200 #include <curses.h>
- 13201 #include "curspriv.h"
- 13202
- 13203 /****************************************************************/
- 13204 /* Wclrtobot() fills the right half of the cursor line of */
- 13205 /* Window 'win', and all lines below it with blanks. */
- 13206 /****************************************************************/
- 13207
- 13208 int wclrtobot(win)
- 13209 WINDOW *win;
- .Op 109 src/lib/curses/wclrtobot.c
- 13210 {
- 13211 int y, minx, startx, *ptr, *end, *maxx, blank;
- 13212
- 13213 blank = ' ' | (win->_attrs & ATR_MSK);
- 13214 startx = win->_curx;
- 13215 for (y = win->_cury; y <= win->_regbottom; y++) {
- 13216 minx = _NO_CHANGE;
- 13217 end = &win->_line[y][win->_maxx];
- 13218 for (ptr = &win->_line[y][startx]; ptr <= end; ptr++) {
- 13219 if (*ptr != blank) {
- 13220 maxx = ptr;
- 13221 if (minx == _NO_CHANGE) minx = ptr - win->_line[y];
- 13222 *ptr = blank;
- 13223 } /* if */
- 13224 } /* for */
- 13225 if (minx != _NO_CHANGE) {
- 13226 if ((win->_minchng[y] > minx) || (win->_minchng[y] == _NO_CHANGE))
- 13227 win->_minchng[y] = minx;
- 13228 if (win->_maxchng[y] < maxx - win->_line[y])
- 13229 win->_maxchng[y] = maxx - win->_line[y];
- 13230 } /* if */
- 13231 startx = 0;
- 13232 }
- 13233 return(OK);
- 13234 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wclrtoeol.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13300 #include <curses.h>
- 13301 #include "curspriv.h"
- 13302
- 13303 /****************************************************************/
- 13304 /* Wclrtoeol() fills the half of the cursor line to the right */
- 13305 /* Of the cursor in window 'win' with blanks. */
- 13306 /****************************************************************/
- 13307
- 13308 int wclrtoeol(win)
- 13309 WINDOW *win;
- 13310 {
- 13311 int *maxx, *ptr, *end, y, x, minx, blank;
- 13312
- 13313 y = win->_cury;
- 13314 x = win->_curx;
- 13315 blank = ' ' | (win->_attrs & ATR_MSK);
- 13316
- 13317 end = &win->_line[y][win->_maxx];
- 13318 minx = _NO_CHANGE;
- 13319 maxx = &win->_line[y][x];
- 13320 for (ptr = maxx; ptr <= end; ptr++) {
- 13321 if (*ptr != blank) {
- 13322 maxx = ptr;
- 13323 if (minx == _NO_CHANGE) minx = ptr - win->_line[y];
- 13324 *ptr = blank;
- .Ep 110 src/lib/curses/wclrtoeol.c
- 13325 } /* if */
- 13326 } /* for */
- 13327
- 13328 if (minx != _NO_CHANGE) {
- 13329 if (win->_minchng[y] > minx || win->_minchng[y] == _NO_CHANGE)
- 13330 win->_minchng[y] = minx;
- 13331 if (win->_maxchng[y] < maxx - win->_line[y])
- 13332 win->_maxchng[y] = maxx - win->_line[y];
- 13333 }
- 13334 return(OK);
- 13335 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wdelch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13400 #include <curses.h>
- 13401 #include "curspriv.h"
- 13402
- 13403 /* Wdelch() deletes the character at the window cursor, and the
- 13404 characters to the right of it are shifted left, inserting a
- 13405 space at the last position of the line.
- 13406 */
- 13407
- 13408 int wdelch(win)
- 13409 WINDOW *win;
- 13410 {
- 13411 int *temp1;
- 13412 int *temp2;
- 13413 int *end;
- 13414 int y = win->_cury;
- 13415 int x = win->_curx;
- 13416 int maxx = win->_maxx;
- 13417
- 13418 end = &win->_line[y][maxx];
- 13419 temp1 = &win->_line[y][x];
- 13420 temp2 = temp1 + 1;
- 13421 while (temp1 < end) *temp1++ = *temp2++;
- 13422 *temp1 = ' ' | (win->_attrs & ATR_MSK);
- 13423 win->_maxchng[y] = maxx;
- 13424 if (win->_minchng[y] == _NO_CHANGE || win->_minchng[y] > x)
- 13425 win->_minchng[y] = x;
- 13426 return(OK);
- 13427 }
- .Op 111 src/lib/curses/wdeleteln.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wdeleteln.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13500 #include <curses.h>
- 13501 #include "curspriv.h"
- 13502
- 13503 /****************************************************************/
- 13504 /* Wdeleteln() deletes the line at the window cursor, and the */
- 13505 /* Lines below it are shifted up, inserting a blank line at */
- 13506 /* The bottom of the window. */
- 13507 /****************************************************************/
- 13508
- 13509 int wdeleteln(win)
- 13510 WINDOW *win;
- 13511 {
- 13512 int *end, *temp, y, blank;
- 13513
- 13514 blank = ' ' | (win->_attrs & ATR_MSK);
- 13515
- 13516 temp = win->_line[win->_cury];
- 13517 for (y = win->_cury; y < win->_regbottom; y++) {
- 13518 win->_line[y] = win->_line[y + 1];
- 13519 win->_minchng[y] = 0;
- 13520 win->_maxchng[y] = win->_maxx;
- 13521 }
- 13522 win->_minchng[y] = 0;
- 13523 win->_maxchng[y] = win->_maxx;
- 13524 win->_line[win->_regbottom] = temp;
- 13525 for (end = &(temp[win->_maxx]); temp <= end;) *temp++ = blank;
- 13526 return(OK);
- 13527 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/werase.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13600 #include <curses.h>
- 13601 #include "curspriv.h"
- 13602
- 13603 /****************************************************************/
- 13604 /* Werase() fills all lines of window 'win' with blanks and po- */
- 13605 /* Sitions the cursor at home in the scroll region. */
- 13606 /****************************************************************/
- 13607
- 13608 void werase(win)
- 13609 WINDOW *win;
- 13610 {
- 13611 int *end, *start, y, blank;
- 13612
- 13613 blank = ' ' | (win->_attrs & ATR_MSK);
- 13614
- 13615 for (y = win->_regtop; y <= win->_regbottom; y++) { /* clear all lines */
- 13616 start = win->_line[y];
- 13617 end = &start[win->_maxx];
- 13618 while (start <= end) /* clear all line */
- 13619 *start++ = blank;
- .Ep 112 src/lib/curses/werase.c
- 13620 win->_minchng[y] = 0;
- 13621 win->_maxchng[y] = win->_maxx;
- 13622 }
- 13623 win->_cury = win->_regtop; /* cursor home */
- 13624 win->_curx = 0;
- 13625 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wgetch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13700 #include <curses.h>
- 13701 #include <stdio.h>
- 13702 #include "curspriv.h"
- 13703
- 13704 int wgetch(win)
- 13705 WINDOW *win;
- 13706 {
- 13707 bool weset = FALSE;
- 13708 char inp;
- 13709
- 13710 if (!win->_scroll && (win->_flags & _FULLWIN)
- 13711 && win->_curx == win->_maxx - 1 && win->_cury == win->_maxy - 1)
- 13712 return ERR;
- 13713 if (_cursvar.echoit && !_cursvar.rawmode) {
- 13714 cbreak();
- 13715 weset++;
- 13716 }
- 13717 inp = getchar();
- 13718 if (_cursvar.echoit) {
- 13719 mvwaddch(curscr, win->_cury + win->_begy,
- 13720 win->_curx + win->_begx, inp);
- 13721 waddch(win, inp);
- 13722 }
- 13723 if (weset) nocbreak();
- 13724 return inp;
- 13725 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wgetstr.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13800 #include <curses.h>
- 13801 #include "curspriv.h"
- 13802
- 13803 /****************************************************************/
- 13804 /* Wgetstr(win,str) reads in a string (terminated by n or r) */
- 13805 /* To the buffer pointed to by 'str', and displays the input */
- 13806 /* In window 'win'. The user's erase and kill characters are */
- 13807 /* Active. */
- 13808 /****************************************************************/
- 13809
- .Op 113 src/lib/curses/wgetstr.c
- 13810 int wgetstr(win, str)
- 13811 WINDOW *win;
- 13812 char *str;
- 13813 {
- 13814 while ((*str = wgetch(win)) != ERR && *str != 'n') str++;
- 13815 if (*str == ERR) {
- 13816 *str = ' ';
- 13817 return ERR;
- 13818 }
- 13819 *str = ' ';
- 13820 return OK;
- 13821 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/windel.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 13900 /****************************************************************/
- 13901 /* Delwin() routine of the PCcurses package. */
- 13902 /* */
- 13903 /****************************************************************/
- 13904 /* This version of curses is based on ncurses, a curses version */
- 13905 /* Originally written by Pavel Curtis at Cornell University. */
- 13906 /* I have made substantial changes to make it run on IBM PC's, */
- 13907 /* And therefore consider myself free to make it public domain. */
- 13908 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 13909 /****************************************************************/
- 13910 /* 1.0: Release: 870515 */
- 13911 /****************************************************************/
- 13912 /* Modified to run under the MINIX operating system by Don Cope */
- 13913 /* These changes are also released into the public domain. */
- 13914 /* 900906 */
- 13915 /****************************************************************/
- 13916
- 13917 #include <stdlib.h>
- 13918 #include <curses.h>
- 13919 #include "curspriv.h"
- 13920
- 13921 /****************************************************************/
- 13922 /* Delwin() deallocates all data allocated by 'win'. If 'win' */
- 13923 /* Is a subwindow, it uses the original window's lines for sto- */
- 13924 /* Rage, and thus the line arrays are not deallocated. */
- 13925 /****************************************************************/
- 13926
- 13927 void delwin(win)
- 13928 WINDOW *win;
- 13929 {
- 13930 int i;
- 13931
- 13932 if (!(win->_flags & _SUBWIN)) { /* subwindow uses 'parent's' lines */
- 13933 for (i = 0; i <= win->_maxy && win->_line[i]; i++)
- 13934 free(win->_line[i]);
- 13935 }
- 13936 free(win->_minchng);
- 13937 free(win->_maxchng);
- 13938 free(win->_line);
- 13939 free(win);
- .Ep 114 src/lib/curses/windel.c
- 13940 } /* delwin */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/winmove.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14000 /****************************************************************/
- 14001 /* Mvwin() routine of the PCcurses package */
- 14002 /* */
- 14003 /****************************************************************/
- 14004 /* This version of curses is based on ncurses, a curses version */
- 14005 /* Originally written by Pavel Curtis at Cornell University. */
- 14006 /* I have made substantial changes to make it run on IBM PC's, */
- 14007 /* And therefore consider myself free to make it public domain. */
- 14008 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 14009 /****************************************************************/
- 14010 /* 1.0: Release: 870515 */
- 14011 /****************************************************************/
- 14012 /* Modified to run under the MINIX operating system by Don Cope */
- 14013 /* These changes are also released into the public domain. */
- 14014 /* 900906 */
- 14015 /****************************************************************/
- 14016
- 14017 #include <curses.h>
- 14018 #include "curspriv.h"
- 14019
- 14020 /****************************************************************/
- 14021 /* Mvwin() moves window 'win' to position (begx, begy) on the */
- 14022 /* Screen. */
- 14023 /****************************************************************/
- 14024
- 14025 int mvwin(win, begy, begx)
- 14026 WINDOW *win;
- 14027 int begy, begx;
- 14028 {
- 14029 if ((begy + win->_maxy) > (LINES - 1) || (begx + win->_maxx) > (COLS - 1))
- 14030 return(ERR);
- 14031 win->_begy = begy;
- 14032 win->_begx = begx;
- 14033 touchwin(win);
- 14034 return(OK);
- 14035 } /* mvwin */
- .Op 115 src/lib/curses/winsch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/winsch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14100 #include <curses.h>
- 14101 #include "curspriv.h"
- 14102
- 14103 /* Winsch() inserts character 'c' at the cursor position in
- 14104 window 'win'. The cursor is advanced.
- 14105 */
- 14106
- 14107 int winsch(win, c)
- 14108 WINDOW *win;
- 14109 char c;
- 14110 {
- 14111 int *temp1;
- 14112 int *temp2;
- 14113 int *end;
- 14114 int x = win->_curx;
- 14115 int y = win->_cury;
- 14116 int maxx = win->_maxx;
- 14117
- 14118 if ((c < ' ') && (c == 'n' || c == 'r' || c == 't' || c == 'b'))
- 14119 return(waddch(win, c));
- 14120 end = &win->_line[y][x];
- 14121 temp1 = &win->_line[y][maxx];
- 14122 temp2 = temp1 - 1;
- 14123 if (c < ' ') /* if CTRL-char make space for 2 */
- 14124 temp2--;
- 14125 while (temp1 > end) *temp1-- = *temp2--;
- 14126 win->_maxchng[y] = maxx;
- 14127 if ((win->_minchng[y] == _NO_CHANGE) || (win->_minchng[y] > x))
- 14128 win->_minchng[y] = x;
- 14129 return(waddch(win, c)); /* fixes CTRL-chars too */
- 14130 } /* winsch */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/winscrol.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14200 /****************************************************************/
- 14201 /* Scroll() routine of the PCcurses package */
- 14202 /* */
- 14203 /****************************************************************/
- 14204 /* This version of curses is based on ncurses, a curses version */
- 14205 /* Originally written by Pavel Curtis at Cornell University. */
- 14206 /* I have made substantial changes to make it run on IBM PC's, */
- 14207 /* And therefore consider myself free to make it public domain. */
- 14208 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 14209 /****************************************************************/
- 14210 /* 1.0: Release: 870515 */
- 14211 /****************************************************************/
- 14212 /* Modified to run under the MINIX operating system by Don Cope */
- 14213 /* These changes are also released into the public domain. */
- 14214 /* 900906 */
- .Ep 116 src/lib/curses/winscrol.c
- 14215 /****************************************************************/
- 14216
- 14217 #include <curses.h>
- 14218 #include "curspriv.h"
- 14219
- 14220 /****************************************************************/
- 14221 /* Scroll() scrolls the scrolling region of 'win', but only if */
- 14222 /* Scrolling is allowed and if the cursor is inside the scrol- */
- 14223 /* Ling region. */
- 14224 /****************************************************************/
- 14225
- 14226 void scroll(win)
- 14227 WINDOW *win;
- 14228 {
- 14229 int i;
- 14230 int *ptr;
- 14231 int *temp;
- 14232 static int blank;
- 14233
- 14234 blank = ' ' | (win->_attrs & ATR_MSK);
- 14235 if ((!win->_scroll) /* check if window scrolls */
- 14236 ||(win->_cury < win->_regtop) /* and cursor in region */
- 14237 ||(win->_cury > win->_regbottom)
- 14238 )
- 14239 return;
- 14240
- 14241 temp = win->_line[win->_regtop];
- 14242 for (i = win->_regtop; i < win->_regbottom; i++) {
- 14243 win->_line[i] = win->_line[i + 1]; /* re-arrange line pointers */
- 14244 win->_minchng[i] = 0;
- 14245 win->_maxchng[i] = win->_maxx;
- 14246 }
- 14247 for (ptr = temp; ptr - temp <= win->_maxx; ptr++)
- 14248 *ptr = blank; /* make a blank line */
- 14249 win->_line[win->_regbottom] = temp;
- 14250 if (win->_cury > win->_regtop)/* if not on top line */
- 14251 win->_cury--; /* cursor scrolls too */
- 14252 win->_minchng[win->_regbottom] = 0;
- 14253 win->_maxchng[win->_regbottom] = win->_maxx;
- 14254 } /* scroll */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/winsertln.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14300 #include <curses.h>
- 14301 #include "curspriv.h"
- 14302
- 14303 /****************************************************************/
- 14304 /* Winsertln() inserts a blank line instead of the cursor line */
- 14305 /* In window 'win' and pushes other lines down. */
- 14306 /****************************************************************/
- 14307
- 14308 int winsertln(win)
- 14309 WINDOW *win;
- .Op 117 src/lib/curses/winsertln.c
- 14310 {
- 14311 int *temp, *end, y, blank;
- 14312
- 14313 blank = ' ' | (win->_attrs & ATR_MSK);
- 14314 temp = win->_line[win->_regbottom];
- 14315 for (y = win->_regbottom; y > win->_cury; y--) {
- 14316 win->_line[y] = win->_line[y - 1];
- 14317 win->_minchng[y] = 0;
- 14318 win->_maxchng[y] = win->_maxx;
- 14319 }
- 14320 win->_line[win->_cury] = temp;
- 14321 for (end = &temp[win->_maxx]; temp <= end; temp++) *temp = blank;
- 14322 win->_minchng[win->_cury] = 0;
- 14323 win->_maxchng[win->_cury] = win->_maxx;
- 14324 return(OK);
- 14325 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/curses/wintouch.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14400 /****************************************************************/
- 14401 /* Touchwin() routine of the PCcurses package */
- 14402 /* */
- 14403 /****************************************************************/
- 14404 /* This version of curses is based on ncurses, a curses version */
- 14405 /* Originally written by Pavel Curtis at Cornell University. */
- 14406 /* I have made substantial changes to make it run on IBM PC's, */
- 14407 /* And therefore consider myself free to make it public domain. */
- 14408 /* Bjorn Larsson (...mcvax!enea!infovax!bl) */
- 14409 /****************************************************************/
- 14410 /* 1.0: Release: 870515 */
- 14411 /****************************************************************/
- 14412 /* Modified to run under the MINIX operating system by Don Cope */
- 14413 /* These changes are also released into the public domain. */
- 14414 /* 900906 */
- 14415 /****************************************************************/
- 14416
- 14417 #include <curses.h>
- 14418 #include "curspriv.h"
- 14419
- 14420 /****************************************************************/
- 14421 /* Touchwin() marks all lines of window 'win' as changed, from */
- 14422 /* The first to the last character on the line. */
- 14423 /****************************************************************/
- 14424
- 14425 void touchwin(win)
- 14426 WINDOW *win;
- 14427 {
- 14428 int y;
- 14429 int maxy;
- 14430 int maxx;
- 14431
- 14432 maxy = win->_maxy;
- 14433 maxx = win->_maxx;
- 14434
- .Ep 118 src/lib/curses/wintouch.c
- 14435 for (y = 0; y <= maxy; y++) {
- 14436 win->_minchng[y] = 0;
- 14437 win->_maxchng[y] = maxx;
- 14438 } /* for */
- 14439 } /* touchwin */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/editline.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14500 /* $Revision: 1.3 $
- 14501 **
- 14502 ** Internal header file for editline library.
- 14503 */
- 14504 #include <stdio.h>
- 14505 #if defined(HAVE_STDLIB)
- 14506 #include <stdlib.h>
- 14507 #include <string.h>
- 14508 #endif /* defined(HAVE_STDLIB) */
- 14509 #if defined(SYS_UNIX)
- 14510 #include "unix.h"
- 14511 #endif /* defined(SYS_UNIX) */
- 14512 #if defined(SYS_OS9)
- 14513 #include "os9.h"
- 14514 #endif /* defined(SYS_OS9) */
- 14515
- 14516 #if !defined(SIZE_T)
- 14517 #define SIZE_T unsigned int
- 14518 #endif /* !defined(SIZE_T) */
- 14519
- 14520 typedef unsigned char CHAR;
- 14521
- 14522 #if defined(HIDE)
- 14523 #define STATIC static
- 14524 #else
- 14525 #define STATIC /* NULL */
- 14526 #endif /* !defined(HIDE) */
- 14527
- 14528 #if !defined(CONST)
- 14529 #if defined(__STDC__)
- 14530 #define CONST const
- 14531 #else
- 14532 #define CONST
- 14533 #endif /* defined(__STDC__) */
- 14534 #endif /* !defined(CONST) */
- 14535
- 14536
- 14537 #define MEM_INC 64
- 14538 #define SCREEN_INC 256
- 14539
- 14540 #define DISPOSE(p) free((char *)(p))
- 14541 #define NEW(T, c)
- 14542 ((T *)malloc((unsigned int)(sizeof (T) * (c))))
- 14543 #define RENEW(p, T, c)
- 14544 (p = (T *)realloc((char *)(p), (unsigned int)(sizeof (T) * (c))))
- .Op 119 src/lib/editline/editline.h
- 14545 #define COPYFROMTO(new, p, len)
- 14546 (void)memcpy((char *)(new), (char *)(p), (int)(len))
- 14547
- 14548
- 14549 /*
- 14550 ** Variables and routines internal to this package.
- 14551 */
- 14552 extern int rl_eof;
- 14553 extern int rl_erase;
- 14554 extern int rl_intr;
- 14555 extern int rl_kill;
- 14556 extern int rl_quit;
- 14557 extern char *rl_complete();
- 14558 extern int rl_list_possib();
- 14559 extern void rl_ttyset();
- 14560 extern void rl_add_slash();
- 14561
- 14562 #if !defined(HAVE_STDLIB)
- 14563 extern char *getenv();
- 14564 extern char *malloc();
- 14565 extern char *realloc();
- 14566 extern char *memcpy();
- 14567 extern char *strcat();
- 14568 extern char *strchr();
- 14569 extern char *strrchr();
- 14570 extern char *strcpy();
- 14571 extern int strcmp();
- 14572 extern int strlen();
- 14573 extern int strncmp();
- 14574 #endif /* !defined(HAVE_STDLIB) */
- 14575
- 14576 #if defined(NEED_STRDUP)
- 14577 extern char *strdup();
- 14578 #endif
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/os9.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14600 /* $Revision: 1.1 $
- 14601 **
- 14602 ** Editline system header file for OS-9 (on 68k).
- 14603 */
- 14604
- 14605 #define CRLF "rl"
- 14606 #define FORWARD extern
- 14607
- 14608 #include <dir.h>
- 14609 typedef struct direct DIRENTRY;
- .Ep 120 src/lib/editline/unix.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/unix.h
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14700 /* $Revision: 1.1 $
- 14701 **
- 14702 ** Editline system header file for Unix.
- 14703 */
- 14704
- 14705 #define CRLF "rn"
- 14706 #define FORWARD STATIC
- 14707
- 14708 #include <sys/types.h>
- 14709 #include <sys/stat.h>
- 14710
- 14711 #if defined(USE_DIRENT)
- 14712 #include <dirent.h>
- 14713 typedef struct dirent DIRENTRY;
- 14714 #else
- 14715 #include <sys/dir.h>
- 14716 typedef struct direct DIRENTRY;
- 14717 #endif /* defined(USE_DIRENT) */
- 14718
- 14719 #if !defined(S_ISDIR)
- 14720 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
- 14721 #endif /* !defined(S_ISDIR) */
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/complete.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 14800 /* $Revision: 1.4 $
- 14801 **
- 14802 ** History and file completion functions for editline library.
- 14803 */
- 14804 #include "editline.h"
- 14805
- 14806
- 14807 #if defined(NEED_STRDUP)
- 14808 /*
- 14809 ** Return an allocated copy of a string.
- 14810 */
- 14811 char *
- 14812 strdup(p)
- 14813 char *p;
- 14814 {
- 14815 char *new;
- 14816
- 14817 if ((new = NEW(char, strlen(p) + 1)) != NULL)
- 14818 (void)strcpy(new, p);
- 14819 return new;
- 14820 }
- 14821 #endif /* defined(NEED_STRDUP) */
- 14822
- 14823 /*
- 14824 ** strcmp-like sorting predicate for qsort.
- .Op 121 src/lib/editline/complete.c
- 14825 */
- 14826 STATIC int
- 14827 compare(p1, p2)
- 14828 CONST void *p1;
- 14829 CONST void *p2;
- 14830 {
- 14831 CONST char **v1;
- 14832 CONST char **v2;
- 14833
- 14834 v1 = (CONST char **)p1;
- 14835 v2 = (CONST char **)p2;
- 14836 return strcmp(*v1, *v2);
- 14837 }
-
- 14839 /*
- 14840 ** Fill in *avp with an array of names that match file, up to its length.
- 14841 ** Ignore . and .. .
- 14842 */
- 14843 STATIC int
- 14844 FindMatches(dir, file, avp)
- 14845 char *dir;
- 14846 char *file;
- 14847 char ***avp;
- 14848 {
- 14849 char **av;
- 14850 char **new;
- 14851 char *p;
- 14852 DIR *dp;
- 14853 DIRENTRY *ep;
- 14854 SIZE_T ac;
- 14855 SIZE_T len;
- 14856 SIZE_T choices;
- 14857 SIZE_T total;
- 14858
- 14859 if ((dp = opendir(dir)) == NULL)
- 14860 return 0;
- 14861
- 14862 av = NULL;
- 14863 ac = 0;
- 14864 len = strlen(file);
- 14865 choices = 0;
- 14866 total = 0;
- 14867 while ((ep = readdir(dp)) != NULL) {
- 14868 p = ep->d_name;
- 14869 if (p[0] == '.' && (p[1] == ' ' || (p[1] == '.' && p[2] == ' ')))
- 14870 continue;
- 14871 if (len && strncmp(p, file, len) != 0)
- 14872 continue;
- 14873
- 14874 choices++;
- 14875 if ((total += strlen(p)) > 1024) {
- 14876 /* This is a bit too much. */
- 14877 while (ac > 0) DISPOSE(av[--ac]);
- 14878 continue;
- 14879 }
- 14880
- 14881 if ((ac % MEM_INC) == 0) {
- 14882 if ((new = NEW(char*, ac + MEM_INC)) == NULL) {
- 14883 total = 0;
- 14884 break;
- .Ep 122 src/lib/editline/complete.c
- 14885 }
- 14886 if (ac) {
- 14887 COPYFROMTO(new, av, ac * sizeof (char **));
- 14888 DISPOSE(av);
- 14889 }
- 14890 *avp = av = new;
- 14891 }
- 14892
- 14893 if ((av[ac] = strdup(p)) == NULL) {
- 14894 if (ac == 0)
- 14895 DISPOSE(av);
- 14896 total = 0;
- 14897 break;
- 14898 }
- 14899 ac++;
- 14900 }
- 14901
- 14902 /* Clean up and return. */
- 14903 (void)closedir(dp);
- 14904 if (total > 1024) {
- 14905 char many[sizeof(total) * 3];
- 14906 p = many + sizeof(many);
- 14907 *--p = ' ';
- 14908 while (choices > 0) {
- 14909 *--p = '0' + choices % 10;
- 14910 choices /= 10;
- 14911 }
- 14912 while (p > many + sizeof(many) - 8) *--p = ' ';
- 14913 if ((p = strdup(p)) != NULL) av[ac++] = p;
- 14914 if ((p = strdup("choices")) != NULL) av[ac++] = p;
- 14915 } else {
- 14916 if (ac)
- 14917 qsort(av, ac, sizeof (char **), compare);
- 14918 }
- 14919 return ac;
- 14920 }
-
- 14922 /*
- 14923 ** Split a pathname into allocated directory and trailing filename parts.
- 14924 */
- 14925 STATIC int
- 14926 SplitPath(path, dirpart, filepart)
- 14927 char *path;
- 14928 char **dirpart;
- 14929 char **filepart;
- 14930 {
- 14931 static char DOT[] = ".";
- 14932 char *dpart;
- 14933 char *fpart;
- 14934
- 14935 if ((fpart = strrchr(path, '/')) == NULL) {
- 14936 if ((dpart = strdup(DOT)) == NULL)
- 14937 return -1;
- 14938 if ((fpart = strdup(path)) == NULL) {
- 14939 DISPOSE(dpart);
- 14940 return -1;
- 14941 }
- 14942 }
- 14943 else {
- 14944 if ((dpart = strdup(path)) == NULL)
- .Op 123 src/lib/editline/complete.c
- 14945 return -1;
- 14946 dpart[fpart - path + 1] = ' ';
- 14947 if ((fpart = strdup(++fpart)) == NULL) {
- 14948 DISPOSE(dpart);
- 14949 return -1;
- 14950 }
- 14951 }
- 14952 *dirpart = dpart;
- 14953 *filepart = fpart;
- 14954 return 0;
- 14955 }
-
- 14957 /*
- 14958 ** Attempt to complete the pathname, returning an allocated copy.
- 14959 ** Fill in *unique if we completed it, or set it to 0 if ambiguous.
- 14960 */
- 14961 char *
- 14962 rl_complete(pathname, unique)
- 14963 char *pathname;
- 14964 int *unique;
- 14965 {
- 14966 char **av;
- 14967 char *dir;
- 14968 char *file;
- 14969 char *new;
- 14970 char *p;
- 14971 SIZE_T ac;
- 14972 SIZE_T end;
- 14973 SIZE_T i;
- 14974 SIZE_T j;
- 14975 SIZE_T len;
- 14976
- 14977 if (SplitPath(pathname, &dir, &file) < 0)
- 14978 return NULL;
- 14979 if ((ac = FindMatches(dir, file, &av)) == 0) {
- 14980 DISPOSE(dir);
- 14981 DISPOSE(file);
- 14982 return NULL;
- 14983 }
- 14984
- 14985 p = NULL;
- 14986 len = strlen(file);
- 14987 if (ac == 1) {
- 14988 /* Exactly one match -- finish it off. */
- 14989 *unique = 1;
- 14990 j = strlen(av[0]) - len + 2;
- 14991 if ((p = NEW(char, j + 1)) != NULL) {
- 14992 COPYFROMTO(p, av[0] + len, j);
- 14993 if ((new = NEW(char, strlen(dir) + strlen(av[0]) + 2)) != NULL) {
- 14994 (void)strcpy(new, dir);
- 14995 (void)strcat(new, "/");
- 14996 (void)strcat(new, av[0]);
- 14997 rl_add_slash(new, p);
- 14998 DISPOSE(new);
- 14999 }
- 15000 }
- 15001 }
- 15002 else {
- 15003 *unique = 0;
- 15004 if (len) {
- .Ep 124 src/lib/editline/complete.c
- 15005 /* Find largest matching substring. */
- 15006 for (i = len, end = strlen(av[0]); i < end; i++)
- 15007 for (j = 1; j < ac; j++)
- 15008 if (av[0][i] != av[j][i])
- 15009 goto breakout;
- 15010 breakout:
- 15011 if (i > len) {
- 15012 j = i - len + 1;
- 15013 if ((p = NEW(char, j)) != NULL) {
- 15014 COPYFROMTO(p, av[0] + len, j);
- 15015 p[j - 1] = ' ';
- 15016 }
- 15017 }
- 15018 }
- 15019 }
- 15020
- 15021 /* Clean up and return. */
- 15022 DISPOSE(dir);
- 15023 DISPOSE(file);
- 15024 for (i = 0; i < ac; i++)
- 15025 DISPOSE(av[i]);
- 15026 DISPOSE(av);
- 15027 return p;
- 15028 }
-
- 15030 /*
- 15031 ** Return all possible completions.
- 15032 */
- 15033 int
- 15034 rl_list_possib(pathname, avp)
- 15035 char *pathname;
- 15036 char ***avp;
- 15037 {
- 15038 char *dir;
- 15039 char *file;
- 15040 int ac;
- 15041
- 15042 if (SplitPath(pathname, &dir, &file) < 0)
- 15043 return 0;
- 15044 ac = FindMatches(dir, file, avp);
- 15045 DISPOSE(dir);
- 15046 DISPOSE(file);
- 15047 return ac;
- 15048 }
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- src/lib/editline/editline.c
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 15100 /* $Revision: 1.7 $
- 15101 **
- 15102 ** Main editing routines for editline library.
- 15103 */
- 15104 #include "editline.h"
- 15105 #include <signal.h>
- 15106 #include <ctype.h>
- 15107
- 15108 /*
- 15109 ** Manifest constants.
- .Op 125 src/lib/editline/editline.c
- 15110 */
- 15111 #define SCREEN_WIDTH 80
- 15112 #define SCREEN_ROWS 24
- 15113 #define NO_ARG (-1)
- 15114 #define DEL 127
- 15115 #define CTL(x) ((x) & 0x1F)
- 15116 #define ISCTL(x) ((x) && (x) < ' ')
- 15117 #define UNCTL(x) ((x) + 64)
- 15118 #define META(x) ((x) | 0x80)
- 15119 #define ISMETA(x) ((x) & 0x80)
- 15120 #define UNMETA(x) ((x) & 0x7F)
- 15121 #if !defined(HIST_SIZE)
- 15122 #define HIST_SIZE 20
- 15123 #endif /* !defined(HIST_SIZE) */
- 15124
- 15125 /*
- 15126 ** Command status codes.
- 15127 */
- 15128 typedef enum _STATUS {
- 15129 CSdone, CSeof, CSmove, CSdispatch, CSstay, CSsignal
- 15130 } STATUS;
- 15131
- 15132 /*
- 15133 ** The type of case-changing to perform.
- 15134 */
- 15135 typedef enum _CASE {
- 15136 TOupper, TOlower
- 15137 } CASE;