emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r113365: * sysdep.c, term.c, termcap.c, terminal.c:


From: Paul Eggert
Subject: [Emacs-diffs] trunk r113365: * sysdep.c, term.c, termcap.c, terminal.c: Integer-related minor fixes.
Date: Thu, 11 Jul 2013 02:17:51 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113365
revision-id: address@hidden
parent: address@hidden
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Wed 2013-07-10 19:17:47 -0700
message:
  * sysdep.c, term.c, termcap.c, terminal.c: Integer-related minor fixes.
  
  * sysdep.c (emacs_get_tty): Return void, since nobody uses the value.
  (emacs_set_tty): Now static.
  * sysdep.c (emacs_set_tty, tabs_safe_p, emacs_close):
  * term.c (tty_capable_p, tty_default_color_capabilities)
  (get_tty_terminal, term_mouse_movement)
  (handle_one_term_event, init_tty, maybe_fatal):
  * termcap.c (tgetst1, struct termcap_buffer, valid_filename_p)
  (tgetent, scan_file, name_match, compare_contin):
  * terminal.c (get_terminal):
  Use bool for boolean.
  * sysdep.c (init_system_name): Don't overflow stack on huge hostname.
  Prefer char to unsigned char if either will do.
  * term.c (OUTPUT, turn_on_face): Omit unnecessary casts to int.
  (tty_write_glyphs): Prefer int to unsigned.
  (produce_glyphless_glyph): Remove 2nd (unused) int arg.
  All callers changed.
  * termcap.c (tprint, main) [TEST]: Remove non-working test.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/dispextern.h               
dispextern.h-20091113204419-o5vbwnq5f7feedwu-218
  src/sysdep.c                   sysdep.c-20091113204419-o5vbwnq5f7feedwu-448
  src/term.c                     term.c-20091113204419-o5vbwnq5f7feedwu-220
  src/termcap.c                  termcap.c-20091113204419-o5vbwnq5f7feedwu-775
  src/termhooks.h                termhooks.h-20091113204419-o5vbwnq5f7feedwu-249
  src/terminal.c                 terminal.c-20091113204419-o5vbwnq5f7feedwu-6118
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-07-10 23:23:57 +0000
+++ b/src/ChangeLog     2013-07-11 02:17:47 +0000
@@ -1,3 +1,24 @@
+2013-07-11  Paul Eggert  <address@hidden>
+
+       * sysdep.c, term.c, termcap.c, terminal.c: Integer-related minor fixes.
+       * sysdep.c (emacs_get_tty): Return void, since nobody uses the value.
+       (emacs_set_tty): Now static.
+       * sysdep.c (emacs_set_tty, tabs_safe_p, emacs_close):
+       * term.c (tty_capable_p, tty_default_color_capabilities)
+       (get_tty_terminal, term_mouse_movement)
+       (handle_one_term_event, init_tty, maybe_fatal):
+       * termcap.c (tgetst1, struct termcap_buffer, valid_filename_p)
+       (tgetent, scan_file, name_match, compare_contin):
+       * terminal.c (get_terminal):
+       Use bool for boolean.
+       * sysdep.c (init_system_name): Don't overflow stack on huge hostname.
+       Prefer char to unsigned char if either will do.
+       * term.c (OUTPUT, turn_on_face): Omit unnecessary casts to int.
+       (tty_write_glyphs): Prefer int to unsigned.
+       (produce_glyphless_glyph): Remove 2nd (unused) int arg.
+       All callers changed.
+       * termcap.c (tprint, main) [TEST]: Remove non-working test.
+
 2013-07-10  Paul Eggert  <address@hidden>
 
        Port to C89.

=== modified file 'src/dispextern.h'
--- a/src/dispextern.h  2013-07-06 10:41:38 +0000
+++ b/src/dispextern.h  2013-07-11 02:17:47 +0000
@@ -3298,7 +3298,7 @@
 void get_tty_size (int, int *, int *);
 void request_sigio (void);
 void unrequest_sigio (void);
-int tabs_safe_p (int);
+bool tabs_safe_p (int);
 void init_baud_rate (int);
 void init_sigio (int);
 void ignore_sigio (void);
@@ -3470,11 +3470,12 @@
 extern int per_line_cost (const char *);
 extern void calculate_costs (struct frame *);
 extern void produce_glyphs (struct it *);
-extern int tty_capable_p (struct tty_display_info *, unsigned, unsigned long, 
unsigned long);
+extern bool tty_capable_p (struct tty_display_info *, unsigned,
+                          unsigned long, unsigned long);
 extern void set_tty_color_mode (struct tty_display_info *, struct frame *);
 extern struct terminal *get_named_tty (const char *);
 extern void create_tty_output (struct frame *);
-extern struct terminal *init_tty (const char *, const char *, int);
+extern struct terminal *init_tty (const char *, const char *, bool);
 extern void tty_append_glyph (struct it *);
 
 

=== modified file 'src/sysdep.c'
--- a/src/sysdep.c      2013-07-10 23:23:57 +0000
+++ b/src/sysdep.c      2013-07-11 02:17:47 +0000
@@ -102,8 +102,8 @@
 #include "syssignal.h"
 #include "systime.h"
 
-static int emacs_get_tty (int, struct emacs_tty *);
-static int emacs_set_tty (int, struct emacs_tty *, int);
+static void emacs_get_tty (int, struct emacs_tty *);
+static int emacs_set_tty (int, struct emacs_tty *, bool);
 
 /* ULLONG_MAX is missing on Red Hat Linux 7.3; see Bug#11781.  */
 #ifndef ULLONG_MAX
@@ -769,31 +769,26 @@
 
 /* Getting and setting emacs_tty structures.  */
 
-/* Set *TC to the parameters associated with the terminal FD.
-   Return zero if all's well, or -1 if we ran into an error we
-   couldn't deal with.  */
-int
+/* Set *TC to the parameters associated with the terminal FD,
+   or clear it if the parameters are not available.  */
+static void
 emacs_get_tty (int fd, struct emacs_tty *settings)
 {
   /* Retrieve the primary parameters - baud rate, character size, etcetera.  */
 #ifndef DOS_NT
   /* We have those nifty POSIX tcmumbleattr functions.  */
   memset (&settings->main, 0, sizeof (settings->main));
-  if (tcgetattr (fd, &settings->main) < 0)
-    return -1;
+  tcgetattr (fd, &settings->main);
 #endif
-
-  /* We have survived the tempest.  */
-  return 0;
 }
 
 
 /* Set the parameters of the tty on FD according to the contents of
-   *SETTINGS.  If FLUSHP is non-zero, we discard input.
-   Return 0 if all went well, and -1 if anything failed.  */
+   *SETTINGS.  If FLUSHP, discard input.
+   Return 0 if all went well, and -1 (setting errno) if anything failed.  */
 
-int
-emacs_set_tty (int fd, struct emacs_tty *settings, int flushp)
+static int
+emacs_set_tty (int fd, struct emacs_tty *settings, bool flushp)
 {
   /* Set the primary parameters - baud rate, character size, etcetera.  */
 #ifndef DOS_NT
@@ -1118,10 +1113,10 @@
   tty_out->term_initted = 1;
 }
 
-/* Return nonzero if safe to use tabs in output.
+/* Return true if safe to use tabs in output.
    At the time this is called, init_sys_modes has not been done yet.  */
 
-int
+bool
 tabs_safe_p (int fd)
 {
   struct emacs_tty etty;
@@ -1375,8 +1370,10 @@
   uname (&uts);
   Vsystem_name = build_string (uts.nodename);
 #else /* HAVE_GETHOSTNAME */
-  unsigned int hostname_size = 256;
-  char *hostname = alloca (hostname_size);
+  char *hostname_alloc = NULL;
+  char hostname_buf[256];
+  ptrdiff_t hostname_size = sizeof hostname_buf;
+  char *hostname = hostname_buf;
 
   /* Try to get the host name; if the buffer is too short, try
      again.  Apparently, the only indication gethostname gives of
@@ -1391,8 +1388,8 @@
       if (strlen (hostname) < hostname_size - 1)
        break;
 
-      hostname_size <<= 1;
-      hostname = alloca (hostname_size);
+      hostname = hostname_alloc = xpalloc (hostname_alloc, &hostname_size, 1,
+                                          min (PTRDIFF_MAX, SIZE_MAX), 1);
     }
 #ifdef HAVE_SOCKETS
   /* Turn the hostname into the official, fully-qualified hostname.
@@ -1437,7 +1434,13 @@
               }
             if (it)
               {
-                hostname = alloca (strlen (it->ai_canonname) + 1);
+               ptrdiff_t len = strlen (it->ai_canonname);
+               if (hostname_size <= len)
+                 {
+                   hostname_size = len + 1;
+                   hostname = hostname_alloc = xrealloc (hostname_alloc,
+                                                         hostname_size);
+                 }
                 strcpy (hostname, it->ai_canonname);
               }
             freeaddrinfo (res);
@@ -1484,10 +1487,11 @@
       }
 #endif /* HAVE_SOCKETS */
   Vsystem_name = build_string (hostname);
+  xfree (hostname_alloc);
 #endif /* HAVE_GETHOSTNAME */
   {
-    unsigned char *p;
-    for (p = SDATA (Vsystem_name); *p; p++)
+    char *p;
+    for (p = SSDATA (Vsystem_name); *p; p++)
       if (*p == ' ' || *p == '\t')
        *p = '-';
   }
@@ -2200,8 +2204,8 @@
 int
 emacs_close (int fd)
 {
-  int did_retry = 0;
-  register int rtnval;
+  bool did_retry = 0;
+  int rtnval;
 
   while ((rtnval = close (fd)) == -1
         && (errno == EINTR))

=== modified file 'src/term.c'
--- a/src/term.c        2013-07-06 02:40:50 +0000
+++ b/src/term.c        2013-07-11 02:17:47 +0000
@@ -71,13 +71,13 @@
 static void tty_show_cursor (struct tty_display_info *);
 static void tty_hide_cursor (struct tty_display_info *);
 static void tty_background_highlight (struct tty_display_info *tty);
-static struct terminal *get_tty_terminal (Lisp_Object, int);
+static struct terminal *get_tty_terminal (Lisp_Object, bool);
 static void clear_tty_hooks (struct terminal *terminal);
 static void set_tty_hooks (struct terminal *terminal);
 static void dissociate_if_controlling_tty (int fd);
 static void delete_tty (struct terminal *);
-static _Noreturn void maybe_fatal (int must_succeed, struct terminal *terminal,
-                                  const char *str1, const char *str2, ...)
+static _Noreturn void maybe_fatal (bool, struct terminal *,
+                                  const char *, const char *, ...)
   ATTRIBUTE_FORMAT_PRINTF (3, 5) ATTRIBUTE_FORMAT_PRINTF (4, 5);
 static _Noreturn void vfatal (const char *str, va_list ap)
   ATTRIBUTE_FORMAT_PRINTF (1, 0);
@@ -85,8 +85,7 @@
 
 #define OUTPUT(tty, a)                                          \
   emacs_tputs ((tty), a,                                        \
-               (int) (FRAME_LINES (XFRAME (selected_frame))     \
-                      - curY (tty)),                            \
+               FRAME_LINES (XFRAME (selected_frame)) - curY (tty),     \
                cmputc)
 
 #define OUTPUT1(tty, a) emacs_tputs ((tty), a, 1, cmputc)
@@ -695,7 +694,7 @@
 {
   unsigned char *conversion_buffer;
   struct coding_system *coding;
-  size_t n, stringlen;
+  int n, stringlen;
 
   struct tty_display_info *tty = FRAME_TTY (f);
 
@@ -1431,7 +1430,7 @@
 static void append_composite_glyph (struct it *);
 static void produce_composite_glyph (struct it *);
 static void append_glyphless_glyph (struct it *, int, const char *);
-static void produce_glyphless_glyph (struct it *, int, Lisp_Object);
+static void produce_glyphless_glyph (struct it *, Lisp_Object);
 
 /* Append glyphs to IT's glyph_row.  Called from produce_glyphs for
    terminal frames if IT->glyph_row != NULL.  IT->char_to_display is
@@ -1551,7 +1550,7 @@
 
   if (it->what == IT_GLYPHLESS)
     {
-      produce_glyphless_glyph (it, 0, Qnil);
+      produce_glyphless_glyph (it, Qnil);
       goto done;
     }
 
@@ -1620,7 +1619,7 @@
          Lisp_Object acronym = lookup_glyphless_char_display (-1, it);
 
          eassert (it->what == IT_GLYPHLESS);
-         produce_glyphless_glyph (it, 1, acronym);
+         produce_glyphless_glyph (it, acronym);
        }
     }
 
@@ -1794,14 +1793,12 @@
    the character.  See the description of enum
    glyphless_display_method in dispextern.h for the details.
 
-   FOR_NO_FONT is nonzero if and only if this is for a character that
-   is not supported by the coding system of the terminal.  ACRONYM, if
-   non-nil, is an acronym string for the character.
+   ACRONYM, if non-nil, is an acronym string for the character.
 
    The glyphs actually produced are of type CHAR_GLYPH.  */
 
 static void
-produce_glyphless_glyph (struct it *it, int for_no_font, Lisp_Object acronym)
+produce_glyphless_glyph (struct it *it, Lisp_Object acronym)
 {
   int face_id;
   int len;
@@ -1968,7 +1965,7 @@
       ts = tty->standout_mode ? tty->TS_set_background : 
tty->TS_set_foreground;
       if (fg >= 0 && ts)
        {
-          p = tparam (ts, NULL, 0, (int) fg, 0, 0, 0);
+          p = tparam (ts, NULL, 0, fg, 0, 0, 0);
          OUTPUT (tty, p);
          xfree (p);
        }
@@ -1976,7 +1973,7 @@
       ts = tty->standout_mode ? tty->TS_set_foreground : 
tty->TS_set_background;
       if (bg >= 0 && ts)
        {
-          p = tparam (ts, NULL, 0, (int) bg, 0, 0, 0);
+          p = tparam (ts, NULL, 0, bg, 0, 0, 0);
          OUTPUT (tty, p);
          xfree (p);
        }
@@ -2027,11 +2024,11 @@
 }
 
 
-/* Return non-zero if the terminal on frame F supports all of the
+/* Return true if the terminal on frame F supports all of the
    capabilities in CAPS simultaneously, with foreground and background
    colors FG and BG.  */
 
-int
+bool
 tty_capable_p (struct tty_display_info *tty, unsigned int caps,
               unsigned long fg, unsigned long bg)
 {
@@ -2099,7 +2096,7 @@
 /* Save or restore the default color-related capabilities of this
    terminal.  */
 static void
-tty_default_color_capabilities (struct tty_display_info *tty, int save)
+tty_default_color_capabilities (struct tty_display_info *tty, bool save)
 {
 
   if (save)
@@ -2209,7 +2206,7 @@
 /* Return the tty display object specified by TERMINAL. */
 
 static struct terminal *
-get_tty_terminal (Lisp_Object terminal, int throw)
+get_tty_terminal (Lisp_Object terminal, bool throw)
 {
   struct terminal *t = get_terminal (terminal, throw);
 
@@ -2519,7 +2516,7 @@
   cursor_to (f, save_y, save_x);
 }
 
-static int
+static bool
 term_mouse_movement (FRAME_PTR frame, Gpm_Event *event)
 {
   /* Has the mouse moved off the glyph it was on at the last sighting?  */
@@ -2649,7 +2646,7 @@
 {
   struct frame *f = XFRAME (tty->top_frame);
   struct input_event ie;
-  int do_help = 0;
+  bool do_help = 0;
   int count = 0;
 
   EVENT_INIT (ie);
@@ -2934,7 +2931,7 @@
    If MUST_SUCCEED is true, then all errors are fatal. */
 
 struct terminal *
-init_tty (const char *name, const char *terminal_type, int must_succeed)
+init_tty (const char *name, const char *terminal_type, bool must_succeed)
 {
   char *area = NULL;
   char **address = &area;
@@ -2942,7 +2939,7 @@
   int status;
   struct tty_display_info *tty = NULL;
   struct terminal *terminal = NULL;
-  int ctty = 0;                 /* 1 if asked to open controlling tty. */
+  bool ctty = 0;  /* True if asked to open controlling tty.  */
 
   if (!terminal_type)
     maybe_fatal (must_succeed, 0,
@@ -3412,10 +3409,10 @@
 
 /* Auxiliary error-handling function for init_tty.
    Delete TERMINAL, then call error or fatal with str1 or str2,
-   respectively, according to whether MUST_SUCCEED is zero or not.  */
+   respectively, according to whether MUST_SUCCEED is true.  */
 
 static void
-maybe_fatal (int must_succeed, struct terminal *terminal,
+maybe_fatal (bool must_succeed, struct terminal *terminal,
             const char *str1, const char *str2, ...)
 {
   va_list ap;

=== modified file 'src/termcap.c'
--- a/src/termcap.c     2013-07-06 02:40:50 +0000
+++ b/src/termcap.c     2013-07-11 02:17:47 +0000
@@ -213,8 +213,8 @@
      abbreviation expansion makes that effort a little more hairy than
      its worth; this is cleaner.  */
   {
-    register int last_p_param = 0;
-    int remove_p_params = 1;
+    int last_p_param = 0;
+    bool remove_p_params = 1;
     struct { char *beg; int len; } cut[11];
 
     for (cut[0].beg = p = ret; p < r - 3; p++)
@@ -318,26 +318,26 @@
     char *beg;
     ptrdiff_t size;
     char *ptr;
-    int ateof;
+    bool ateof;
     ptrdiff_t full;
   };
 
 /* Forward declarations of static functions.  */
 
-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);
+static bool scan_file (char *, int, struct termcap_buffer *);
+static char *gobble_line (int, struct termcap_buffer *, char *);
+static bool compare_contin (char *, char *);
+static bool name_match (char *, char *);
 
-#ifdef MSDOS /* MW, May 1993 */
-static int
+static bool
 valid_filename_p (char *fn)
 {
+#ifdef MSDOS
   return *fn == '/' || fn[1] == ':';
-}
 #else
-#define valid_filename_p(fn) (*(fn) == '/')
+  return *fn == '/';
 #endif
+}
 
 /* Find the termcap entry data for terminal type NAME
    and store it in the block that BP points to.
@@ -360,10 +360,10 @@
   char *tc_search_point;
   char *term;
   ptrdiff_t malloc_size = 0;
-  register int c;
+  int c;
   char *tcenv = NULL;          /* TERMCAP value, if it contains :tc=.  */
   char *indirect = NULL;       /* Terminal type in :tc= in TERMCAP value.  */
-  int filep;
+  bool filep;
 
 #ifdef INTERNAL_TERMINAL
   /* For the internal terminal we don't want to read any termcap file,
@@ -510,10 +510,10 @@
    Return 1 if successful, with that line in BUFP,
    or 0 if no entry is found in the file.  */
 
-static int
-scan_file (char *str, int fd, register struct termcap_buffer *bufp)
+static bool
+scan_file (char *str, int fd, struct termcap_buffer *bufp)
 {
-  register char *end;
+  char *end;
 
   bufp->ptr = bufp->beg;
   bufp->full = 0;
@@ -544,13 +544,13 @@
   return 0;
 }
 
-/* Return nonzero if NAME is one of the names specified
+/* Return true if NAME is one of the names specified
    by termcap entry LINE.  */
 
-static int
+static bool
 name_match (char *line, char *name)
 {
-  register char *tem;
+  char *tem;
 
   if (!compare_contin (line, name))
     return 1;
@@ -562,18 +562,18 @@
   return 0;
 }
 
-static int
-compare_contin (register char *str1, register char *str2)
+static bool
+compare_contin (char *str1, char *str2)
 {
-  register int c1, c2;
   while (1)
     {
-      c1 = *str1++;
-      c2 = *str2++;
+      int c1 = *str1++;
+      int c2 = *str2++;
       while (c1 == '\\' && *str1 == '\n')
        {
          str1++;
-         while ((c1 = *str1++) == ' ' || c1 == '\t');
+         while ((c1 = *str1++) == ' ' || c1 == '\t')
+           continue;
        }
       if (c2 == '\0')
        {
@@ -647,57 +647,3 @@
     }
   return end + 1;
 }
-
-#ifdef TEST
-
-#include <stdio.h>
-
-static void
-tprint (char *cap)
-{
-  char *x = tgetstr (cap, 0);
-  register char *y;
-
-  printf ("%s: ", cap);
-  if (x)
-    {
-      for (y = x; *y; y++)
-       if (*y <= ' ' || *y == 0177)
-         printf ("\\%0o", *y);
-       else
-         putchar (*y);
-      free (x);
-    }
-  else
-    printf ("none");
-  putchar ('\n');
-}
-
-int
-main (int argc, char **argv)
-{
-  char *term;
-  char *buf;
-
-  term = argv[1];
-  printf ("TERM: %s\n", term);
-
-  buf = (char *) tgetent (0, term);
-  if ((int) buf <= 0)
-    {
-      printf ("No entry.\n");
-      return 0;
-    }
-
-  printf ("Entry: %s\n", buf);
-
-  tprint ("cm");
-  tprint ("AL");
-
-  printf ("co: %d\n", tgetnum ("co"));
-  printf ("am: %d\n", tgetflag ("am"));
-
-  return 0;
-}
-
-#endif /* TEST */

=== modified file 'src/termhooks.h'
--- a/src/termhooks.h   2013-06-03 13:03:05 +0000
+++ b/src/termhooks.h   2013-07-11 02:17:47 +0000
@@ -643,7 +643,7 @@
   (((d)->type != output_termcap && (d)->type != output_msdos_raw)      \
    || (d)->display_info.tty->input)
 
-extern struct terminal *get_terminal (Lisp_Object terminal, int);
+extern struct terminal *get_terminal (Lisp_Object terminal, bool);
 extern struct terminal *create_terminal (void);
 extern void delete_terminal (struct terminal *);
 

=== modified file 'src/terminal.c'
--- a/src/terminal.c    2013-03-11 01:17:40 +0000
+++ b/src/terminal.c    2013-07-11 02:17:47 +0000
@@ -199,11 +199,11 @@
 
 /* Return the terminal object specified by TERMINAL.  TERMINAL may be
    a terminal object, a frame, or nil for the terminal device of the
-   current frame.  If THROW is zero, return NULL for failure,
+   current frame.  If THROW is false, return NULL for failure,
    otherwise throw an error.  */
 
 struct terminal *
-get_terminal (Lisp_Object terminal, int throw)
+get_terminal (Lisp_Object terminal, bool throw)
 {
   struct terminal *result = NULL;
 


reply via email to

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