emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: new file tparam.h to fix Emacs API glitch


From: Paul Eggert
Subject: Re: new file tparam.h to fix Emacs API glitch
Date: Tue, 08 Mar 2011 11:07:24 -0800
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

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 <unistd.h>

 #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 */
-




reply via email to

[Prev in Thread] Current Thread [Next in Thread]