From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: new file tparam.h to fix Emacs API glitch Date: Tue, 08 Mar 2011 11:07:24 -0800 Organization: UCLA Computer Science Department Message-ID: <4D767E6C.7080000@cs.ucla.edu> References: <4D767635.5070700@cs.ucla.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1299611265 20915 80.91.229.12 (8 Mar 2011 19:07:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 19:07:45 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 08 20:07:40 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Px2Fw-0003bG-D8 for ged-emacs-devel@m.gmane.org; Tue, 08 Mar 2011 20:07:40 +0100 Original-Received: from localhost ([127.0.0.1]:41835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px2Fv-0002PN-KY for ged-emacs-devel@m.gmane.org; Tue, 08 Mar 2011 14:07:39 -0500 Original-Received: from [140.186.70.92] (port=53070 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px2Fm-0002Np-Ph for emacs-devel@gnu.org; Tue, 08 Mar 2011 14:07:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Px2Fk-0000Ef-VN for emacs-devel@gnu.org; Tue, 08 Mar 2011 14:07:30 -0500 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:35477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Px2Fk-0000E2-Hf for emacs-devel@gnu.org; Tue, 08 Mar 2011 14:07:28 -0500 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 376FB39E80F5 for ; Tue, 8 Mar 2011 11:07:26 -0800 (PST) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 94m4GSrbBkPX for ; Tue, 8 Mar 2011 11:07:25 -0800 (PST) Original-Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id F221739E80DF for ; Tue, 8 Mar 2011 11:07:24 -0800 (PST) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101209 Fedora/3.1.7-0.35.b3pre.fc14 Thunderbird/3.1.7 In-Reply-To: <4D767635.5070700@cs.ucla.edu> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:136907 Archived-At: Following up on my previous message, termcap.c implements part of the interface described in the new tparam.h, so it should include it. From the Windows point of view the only part of the proposed patch below that should matter is the new dependency of termcap.o on tparam.h. The rest of the patch inserts "const" to stay compatible with the interface. * deps.mk (termcap.o): Depend on tparam.h. * termcap.c: Include it. (term_entry, tgetst1, find_capability, tgetnum, tgetflag, tgetstr): (tgetst1, scan_file, compare_contin, name_match, tgetent): Adjust to API's use of const char * rather than char *. === modified file 'src/deps.mk' --- src/deps.mk 2011-03-08 18:26:34 +0000 +++ src/deps.mk 2011-03-08 18:41:16 +0000 @@ -191,7 +191,7 @@ cm.h frame.h disptab.h keyboard.h character.h charset.h coding.h ccl.h \ xterm.h msdos.h window.h keymap.h blockinput.h atimer.h systime.h \ systty.h syssignal.h tparam.h $(INTERVALS_H) buffer.h ../lib/unistd.h -termcap.o: termcap.c lisp.h $(config_h) +termcap.o: termcap.c tparam.h lisp.h $(config_h) terminal.o: terminal.c frame.h termchar.h termhooks.h charset.h coding.h \ keyboard.h lisp.h globals.h $(config_h) dispextern.h composite.h systime.h \ msdos.h === modified file 'src/termcap.c' --- src/termcap.c 2011-02-19 19:41:00 +0000 +++ src/termcap.c 2011-03-08 18:55:36 +0000 @@ -25,6 +25,7 @@ #include #include "lisp.h" +#include "tparam.h" #ifndef NULL #define NULL (char *) 0 @@ -56,16 +57,16 @@ /* The pointer to the data made by tgetent is left here for tgetnum, tgetflag and tgetstr to find. */ -static char *term_entry; +static const char *term_entry; -static char *tgetst1 (char *ptr, char **area); +static char *tgetst1 (const 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 (register char *bp, register char *cap) +static const char * +find_capability (register const char *bp, register const char *cap) { for (; *bp; bp++) if (bp[0] == ':' @@ -78,7 +79,7 @@ int tgetnum (char *cap) { - register char *ptr = find_capability (term_entry, cap); + register const char *ptr = find_capability (term_entry, cap); if (!ptr || ptr[-1] != '#') return -1; return atoi (ptr); @@ -87,7 +88,7 @@ int tgetflag (char *cap) { - register char *ptr = find_capability (term_entry, cap); + register const char *ptr = find_capability (term_entry, cap); return ptr && ptr[-1] == ':'; } @@ -99,7 +100,7 @@ char * tgetstr (char *cap, char **area) { - register char *ptr = find_capability (term_entry, cap); + register const char *ptr = find_capability (term_entry, cap); if (!ptr || (ptr[-1] != '=' && ptr[-1] != '~')) return NULL; return tgetst1 (ptr, area); @@ -135,9 +136,10 @@ or NULL if PTR is NULL. */ static char * -tgetst1 (char *ptr, char **area) +tgetst1 (const char *ptr, char **area) { - register char *p, *r; + register const char *p; + register char *r; register int c; register int size; char *ret; @@ -218,7 +220,7 @@ { register int last_p_param = 0; int remove_p_params = 1; - struct { char *beg; int len; } cut[11]; + struct { const char *beg; int len; } cut[11]; for (cut[0].beg = p = ret; p < r - 3; p++) { @@ -263,7 +265,7 @@ char PC; void -tputs (register char *str, int nlines, register int (*outfun) (/* ??? */)) +tputs (register const char *str, int nlines, register int (*outfun) (int)) { register int padcount = 0; register int speed; @@ -327,10 +329,10 @@ /* Forward declarations of static functions. */ -static int scan_file (char *str, int fd, register struct termcap_buffer *bufp); +static int scan_file (const char *str, int fd, 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); +static int compare_contin (const char *str1, const char *str2); +static int name_match (const char *line, const char *name); #ifdef MSDOS /* MW, May 1993 */ static int @@ -355,17 +357,17 @@ in it, and some other value otherwise. */ int -tgetent (char *bp, char *name) +tgetent (char *bp, const char *name) { - register char *termcap_name; + register const char *termcap_name; register int fd; struct termcap_buffer buf; register char *bp1; - char *tc_search_point; - char *term; + const char *tc_search_point; + const char *term; int malloc_size = 0; register int c; - char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ + const char *tcenv = NULL; /* TERMCAP value, if it contains :tc=. */ char *indirect = NULL; /* Terminal type in :tc= in TERMCAP value. */ int filep; @@ -414,9 +416,11 @@ if (!indirect) { if (!bp) - bp = termcap_name; - else - strcpy (bp, termcap_name); + { + term_entry = termcap_name; + return 1; + } + strcpy (bp, termcap_name); goto ret; } else @@ -471,16 +475,15 @@ } /* Free old `term' if appropriate. */ - if (term != name) - free (term); + free (indirect); /* If BP is malloc'd by us, make sure it is big enough. */ if (malloc_size) { int offset1 = bp1 - bp, offset2 = tc_search_point - bp; malloc_size = offset1 + buf.size; - bp = termcap_name = (char *) xrealloc (bp, malloc_size); - bp1 = termcap_name + offset1; + termcap_name = bp = (char *) xrealloc (bp, malloc_size); + bp1 = bp + offset1; tc_search_point = termcap_name + offset2; } @@ -498,7 +501,7 @@ /* Does this entry refer to another terminal type's entry? If something is found, copy it into heap and null-terminate it. */ tc_search_point = find_capability (tc_search_point, "tc"); - term = tgetst1 (tc_search_point, (char **) 0); + term = indirect = tgetst1 (tc_search_point, (char **) 0); } close (fd); @@ -519,7 +522,7 @@ or 0 if no entry is found in the file. */ static int -scan_file (char *str, int fd, register struct termcap_buffer *bufp) +scan_file (const char *str, int fd, register struct termcap_buffer *bufp) { register char *end; @@ -556,9 +559,9 @@ by termcap entry LINE. */ static int -name_match (char *line, char *name) +name_match (const char *line, const char *name) { - register char *tem; + register const char *tem; if (!compare_contin (line, name)) return 1; @@ -571,7 +574,7 @@ } static int -compare_contin (register char *str1, register char *str2) +compare_contin (register const char *str1, register const char *str2) { register int c1, c2; while (1) @@ -711,4 +714,3 @@ } #endif /* TEST */ -