X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/1913a2b35da45eeeb71ef851975be7d57c11de78..40be44e2a95cd703e49022c8f8aa0ce5b9b29ea6:/src/termcap.c diff --git a/src/termcap.c b/src/termcap.c index dee5465ebf..69ce56d93b 100644 --- a/src/termcap.c +++ b/src/termcap.c @@ -1,6 +1,6 @@ /* Work-alike for termcap, plus extra features. Copyright (C) 1985, 1986, 1993, 1994, 1995, 2000, 2001, 2002, 2003, - 2004, 2005, 2006 Free Software Foundation, Inc. + 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,55 +18,18 @@ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ /* Emacs config.h may rename various library functions such as malloc. */ -#ifdef HAVE_CONFIG_H #include -#endif - -#ifdef emacs - -#include /* xmalloc is here */ -/* Get the O_* definitions for open et al. */ +#include #include -#ifdef HAVE_FCNTL_H #include -#endif -#ifdef HAVE_UNISTD_H -#include -#endif - -#else /* not emacs */ - -#ifdef STDC_HEADERS -#include -#include -#else -char *getenv (); -char *malloc (); -char *realloc (); -#endif - -/* Do this after the include, in case string.h prototypes bcopy. */ -#if (defined(HAVE_STRING_H) || defined(STDC_HEADERS)) && !defined(bcopy) -#define bcopy(s, d, n) memcpy ((d), (s), (n)) -#endif - -#ifdef HAVE_UNISTD_H #include -#endif -#ifdef HAVE_FCNTL_H -#include -#endif -#endif /* not emacs */ +#include "lisp.h" #ifndef NULL #define NULL (char *) 0 #endif -#ifndef O_RDONLY -#define O_RDONLY 0 -#endif - /* BUFSIZE is the initial size allocated for the buffer for reading the termcap file. It is not a limit. @@ -88,37 +51,6 @@ int bufsize = 128; #define TERMCAP_FILE "/etc/termcap" #endif -#ifndef emacs -static void -memory_out () -{ - write (2, "virtual memory exhausted\n", 25); - exit (1); -} - -static char * -xmalloc (size) - unsigned size; -{ - register char *tem = malloc (size); - - if (!tem) - memory_out (); - return tem; -} - -static char * -xrealloc (ptr, size) - char *ptr; - unsigned size; -{ - register char *tem = realloc (ptr, size); - - if (!tem) - memory_out (); - return tem; -} -#endif /* not emacs */ /* Looking up capabilities in the entry already found. */ @@ -126,15 +58,14 @@ xrealloc (ptr, size) for tgetnum, tgetflag and tgetstr to find. */ static char *term_entry; -static char *tgetst1 (); +static char *tgetst1 (char *ptr, char **area); /* Search entry BP for capability CAP. Return a pointer to the capability (in BP) if found, 0 if not found. */ static char * -find_capability (bp, cap) - register char *bp, *cap; +find_capability (register char *bp, register char *cap) { for (; *bp; bp++) if (bp[0] == ':' @@ -144,12 +75,8 @@ find_capability (bp, cap) return NULL; } -/* These are already defined in the System framework in Mac OS X and - cause prebinding to fail. */ -#ifndef MAC_OSX int -tgetnum (cap) - char *cap; +tgetnum (char *cap) { register char *ptr = find_capability (term_entry, cap); if (!ptr || ptr[-1] != '#') @@ -158,8 +85,7 @@ tgetnum (cap) } int -tgetflag (cap) - char *cap; +tgetflag (char *cap) { register char *ptr = find_capability (term_entry, cap); return ptr && ptr[-1] == ':'; @@ -171,23 +97,20 @@ tgetflag (cap) If AREA is null, space is allocated with `malloc'. */ char * -tgetstr (cap, area) - char *cap; - char **area; +tgetstr (char *cap, char **area) { register char *ptr = find_capability (term_entry, cap); if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) return NULL; return tgetst1 (ptr, area); } -#endif /* MAC_OSX */ #ifdef IS_EBCDIC_HOST /* Table, indexed by a character in range 0200 to 0300 with 0200 subtracted, gives meaning of character following \, or a space if no special meaning. Sixteen characters per line within the string. */ -static char esctab[] +static const char esctab[] = " \057\026 \047\014 \ \025 \015 \ \005 \013 \ @@ -197,7 +120,7 @@ static char esctab[] gives meaning of character following \, or a space if no special meaning. Eight characters per line within the string. */ -static char esctab[] +static const char esctab[] = " \007\010 \033\014 \ \012 \ \015 \011 \013 \ @@ -212,9 +135,7 @@ static char esctab[] or NULL if PTR is NULL. */ static char * -tgetst1 (ptr, area) - char *ptr; - char **area; +tgetst1 (char *ptr, char **area) { register char *p, *r; register int c; @@ -325,7 +246,7 @@ tgetst1 (ptr, area) cut[last_p_param].len = r - cut[last_p_param].beg; for (i = 0, wp = ret; i <= last_p_param; wp += cut[i++].len) - bcopy (cut[i].beg, wp, cut[i].len); + memcpy (wp, cut[i].beg, cut[i].len); r = wp; } } @@ -339,60 +260,19 @@ tgetst1 (ptr, area) /* Outputting a string with padding. */ -#ifndef emacs -short ospeed; -/* If OSPEED is 0, we use this as the actual baud rate. */ -int tputs_baud_rate; -#endif - -/* Already defined in the System framework in Mac OS X and causes - prebinding to fail. */ -#ifndef MAC_OSX char PC; -#endif /* MAC_OSX */ -#ifndef emacs -/* Actual baud rate if positive; - - baud rate / 100 if negative. */ - -static int speeds[] = - { -#ifdef VMS - 0, 50, 75, 110, 134, 150, -3, -6, -12, -18, - -20, -24, -36, -48, -72, -96, -192 -#else /* not VMS */ - 0, 50, 75, 110, 135, 150, -2, -3, -6, -12, - -18, -24, -48, -96, -192, -288, -384, -576, -1152 -#endif /* not VMS */ - }; - -#endif /* not emacs */ - -/* Already defined in the System framework in Mac OS X and causes - prebinding to fail. */ -#ifndef MAC_OSX void -tputs (str, nlines, outfun) - register char *str; - int nlines; - register int (*outfun) (); +tputs (register char *str, int nlines, register int (*outfun) (/* ??? */)) { register int padcount = 0; register int speed; -#ifdef emacs - extern EMACS_INT baud_rate; speed = baud_rate; /* For quite high speeds, convert to the smaller units to avoid overflow. */ if (speed > 10000) speed = - speed / 100; -#else - if (ospeed == 0) - speed = tputs_baud_rate; - else - speed = speeds[ospeed]; -#endif if (!str) return; @@ -433,7 +313,6 @@ tputs (str, nlines, outfun) while (padcount-- > 0) (*outfun) (PC); } -#endif /* MAC_OSX */ /* Finding the termcap entry in the termcap data base. */ @@ -448,38 +327,10 @@ struct termcap_buffer /* Forward declarations of static functions. */ -static int scan_file (); -static char *gobble_line (); -static int compare_contin (); -static int name_match (); - -#ifdef VMS - -#include -#include -#include -#include - -static int -valid_filename_p (fn) - char *fn; -{ - struct FAB fab = cc$rms_fab; - struct NAM nam = cc$rms_nam; - char esa[NAM$C_MAXRSS]; - - fab.fab$l_fna = fn; - fab.fab$b_fns = strlen(fn); - fab.fab$l_nam = &nam; - fab.fab$l_fop = FAB$M_NAM; - - nam.nam$l_esa = esa; - nam.nam$b_ess = sizeof esa; - - return SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL; -} - -#else /* !VMS */ +static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); +static char *gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end); +static int compare_contin (register char *str1, register char *str2); +static int name_match (char *line, char *name); #ifdef MSDOS /* MW, May 1993 */ static int @@ -492,8 +343,6 @@ valid_filename_p (fn) #define valid_filename_p(fn) (*(fn) == '/') #endif -#endif /* !VMS */ - /* Find the termcap entry data for terminal type NAME and store it in the block that BP points to. Record its address for future use. @@ -505,12 +354,8 @@ valid_filename_p (fn) 0 if the data base is accessible but the type NAME is not defined in it, and some other value otherwise. */ -/* Already defined in the System framework in Mac OS X and causes - prebinding to fail. */ -#ifndef MAC_OSX int -tgetent (bp, name) - char *bp, *name; +tgetent (char *bp, char *name) { register char *termcap_name; register int fd; @@ -666,7 +511,6 @@ tgetent (bp, name) term_entry = bp; return 1; } -#endif /* MAC_OSX */ /* Given file open on FD and buffer BUFP, scan the file from the beginning until a line is found @@ -675,10 +519,7 @@ tgetent (bp, name) or 0 if no entry is found in the file. */ static int -scan_file (str, fd, bufp) - char *str; - int fd; - register struct termcap_buffer *bufp; +scan_file (char *str, int fd, register struct termcap_buffer *bufp) { register char *end; @@ -715,8 +556,7 @@ scan_file (str, fd, bufp) by termcap entry LINE. */ static int -name_match (line, name) - char *line, *name; +name_match (char *line, char *name) { register char *tem; @@ -731,8 +571,7 @@ name_match (line, name) } static int -compare_contin (str1, str2) - register char *str1, *str2; +compare_contin (register char *str1, register char *str2) { register int c1, c2; while (1) @@ -772,10 +611,7 @@ compare_contin (str1, str2) thing as one line. The caller decides when a line is continued. */ static char * -gobble_line (fd, bufp, append_end) - int fd; - register struct termcap_buffer *bufp; - char *append_end; +gobble_line (int fd, register struct termcap_buffer *bufp, char *append_end) { register char *end; register int nread; @@ -808,7 +644,7 @@ gobble_line (fd, bufp, append_end) else { append_end -= bufp->ptr - buf; - bcopy (bufp->ptr, buf, bufp->full -= bufp->ptr - buf); + memcpy (buf, bufp->ptr, bufp->full -= bufp->ptr - buf); bufp->ptr = buf; } if (!(nread = read (fd, buf + bufp->full, bufp->size - bufp->full))) @@ -876,5 +712,3 @@ tprint (cap) #endif /* TEST */ -/* arch-tag: c2e8d427-2271-4fac-95fe-411857238b80 - (do not change this comment) */