Convert (most) functions in src to standard C.
[bpt/emacs.git] / src / fringe.c
index f24ab34..9e1d700 100644 (file)
@@ -1,14 +1,14 @@
 /* Fringe handling (split from xdisp.c).
    Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1997,
                  1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007  Free Software Foundation, Inc.
+                 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,12 +16,11 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING.  If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.  */
+along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <stdio.h>
+#include <setjmp.h>
 
 #include "lisp.h"
 #include "frame.h"
@@ -484,15 +483,14 @@ static struct fringe_bitmap **fringe_bitmaps;
 static Lisp_Object *fringe_faces;
 static int max_fringe_bitmaps;
 
-static int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
+int max_used_fringe_bitmap = MAX_STANDARD_FRINGE_BITMAPS;
 
 
 /* Lookup bitmap number for symbol BITMAP.
    Return 0 if not a bitmap.  */
 
 int
-lookup_fringe_bitmap (bitmap)
-     Lisp_Object bitmap;
+lookup_fringe_bitmap (Lisp_Object bitmap)
 {
   int bn;
 
@@ -518,8 +516,7 @@ lookup_fringe_bitmap (bitmap)
    Return BN if not found in Vfringe_bitmaps.  */
 
 static Lisp_Object
-get_fringe_bitmap_name (bn)
-     int bn;
+get_fringe_bitmap_name (int bn)
 {
   Lisp_Object bitmaps;
   Lisp_Object num;
@@ -551,11 +548,7 @@ get_fringe_bitmap_name (bn)
 */
 
 static void
-draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
-     struct window *w;
-     struct glyph_row *row;
-     int left_p, overlay;
-     int which;
+draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int overlay, int which)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   struct draw_fringe_bitmap_params p;
@@ -691,9 +684,7 @@ draw_fringe_bitmap_1 (w, row, left_p, overlay, which)
 }
 
 static int
-get_logical_cursor_bitmap (w, cursor)
-     struct window *w;
-     Lisp_Object cursor;
+get_logical_cursor_bitmap (struct window *w, Lisp_Object cursor)
 {
   Lisp_Object cmap, bm = Qnil;
 
@@ -716,10 +707,7 @@ get_logical_cursor_bitmap (w, cursor)
 }
 
 static int
-get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
-     struct window *w;
-     Lisp_Object bitmap;
-     int right_p, partial_p;
+get_logical_fringe_bitmap (struct window *w, Lisp_Object bitmap, int right_p, int partial_p)
 {
   Lisp_Object cmap, bm1 = Qnil, bm2 = Qnil, bm;
   int ln1 = 0, ln2 = 0;
@@ -731,7 +719,7 @@ get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
      Elements are:
        BITMAP          -- use for all
        (L R)           -- use for left right (whether partial or not)
-       (L R PL PR)     -- use for left rigth partial-left partial-right
+       (L R PL PR)     -- use for left right partial-left partial-right
        If any value in local binding is not present or t, use global value.
 
      If partial, lookup partial bitmap in default value if not found here.
@@ -819,14 +807,11 @@ get_logical_fringe_bitmap (w, bitmap, right_p, partial_p)
 
 
 void
-draw_fringe_bitmap (w, row, left_p)
-     struct window *w;
-     struct glyph_row *row;
-     int left_p;
+draw_fringe_bitmap (struct window *w, struct glyph_row *row, int left_p)
 {
   int overlay = 0;
 
-  if (!left_p && row->cursor_in_fringe_p)
+  if (left_p == row->reversed_p && row->cursor_in_fringe_p)
     {
       Lisp_Object cursor = Qnil;
 
@@ -858,7 +843,7 @@ draw_fringe_bitmap (w, row, left_p)
          int bm = get_logical_cursor_bitmap (w, cursor);
          if (bm != NO_FRINGE_BITMAP)
            {
-             draw_fringe_bitmap_1 (w, row, 0, 2, bm);
+             draw_fringe_bitmap_1 (w, row, left_p, 2, bm);
              overlay = EQ (cursor, Qbox) ? 3 : 1;
            }
        }
@@ -875,9 +860,7 @@ draw_fringe_bitmap (w, row, left_p)
    function with input blocked.  */
 
 void
-draw_row_fringe_bitmaps (w, row)
-     struct window *w;
-     struct glyph_row *row;
+draw_row_fringe_bitmaps (struct window *w, struct glyph_row *row)
 {
   xassert (interrupt_input_blocked);
 
@@ -905,9 +888,7 @@ draw_row_fringe_bitmaps (w, row)
 */
 
 int
-draw_window_fringes (w, no_fringe)
-     struct window *w;
-     int no_fringe;
+draw_window_fringes (struct window *w, int no_fringe)
 {
   struct glyph_row *row;
   int yb = window_text_bottom_y (w);
@@ -945,9 +926,7 @@ draw_window_fringes (w, no_fringe)
    If KEEP_CURRENT_P is 0, update current_matrix too.  */
 
 int
-update_window_fringes (w, keep_current_p)
-     struct window *w;
-     int keep_current_p;
+update_window_fringes (struct window *w, int keep_current_p)
 {
   struct glyph_row *row, *cur = 0;
   int yb = window_text_bottom_y (w);
@@ -1083,7 +1062,8 @@ update_window_fringes (w, keep_current_p)
          left = row->left_user_fringe_bitmap;
          left_face_id = row->left_user_fringe_face_id;
        }
-      else if (row->truncated_on_left_p)
+      else if ((!row->reversed_p && row->truncated_on_left_p)
+              || (row->reversed_p && row->truncated_on_right_p))
        left = LEFT_FRINGE(0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qleft))
        left = ((row->indicate_eob_p && EQ (boundary_bot, Qleft))
@@ -1091,7 +1071,8 @@ update_window_fringes (w, keep_current_p)
                : LEFT_FRINGE (2, Qtop, 0));
       else if (row->indicate_eob_p && EQ (boundary_bot, Qleft))
        left = LEFT_FRINGE (3, Qbottom, row->ends_at_zv_p);
-      else if (MATRIX_ROW_CONTINUATION_LINE_P (row))
+      else if ((!row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row))
+              || (row->reversed_p && row->continued_p))
        left = LEFT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_empty_line_p && EQ (empty_pos, Qleft))
        left = LEFT_FRINGE (5, Qempty_line, 0);
@@ -1110,7 +1091,8 @@ update_window_fringes (w, keep_current_p)
          right = row->right_user_fringe_bitmap;
          right_face_id = row->right_user_fringe_face_id;
        }
-      else if (row->truncated_on_right_p)
+      else if ((!row->reversed_p && row->truncated_on_right_p)
+              || (row->reversed_p && row->truncated_on_left_p))
        right = RIGHT_FRINGE (0, Qtruncation, 0);
       else if (row->indicate_bob_p && EQ (boundary_top, Qright))
        right = ((row->indicate_eob_p && EQ (boundary_bot, Qright))
@@ -1118,7 +1100,8 @@ update_window_fringes (w, keep_current_p)
                 : RIGHT_FRINGE (2, Qtop, 0));
       else if (row->indicate_eob_p && EQ (boundary_bot, Qright))
        right = RIGHT_FRINGE (3, Qbottom, row->ends_at_zv_p);
-      else if (row->continued_p)
+      else if ((!row->reversed_p && row->continued_p)
+              || (row->reversed_p && MATRIX_ROW_CONTINUATION_LINE_P (row)))
        right = RIGHT_FRINGE (4, Qcontinuation, 0);
       else if (row->indicate_top_line_p && EQ (arrow_top, Qright))
        right = RIGHT_FRINGE (6, Qup, 0);
@@ -1185,9 +1168,7 @@ update_window_fringes (w, keep_current_p)
 */
 
 void
-compute_fringe_widths (f, redraw)
-     struct frame *f;
-     int redraw;
+compute_fringe_widths (struct frame *f, int redraw)
 {
   int o_left = FRAME_LEFT_FRINGE_WIDTH (f);
   int o_right = FRAME_RIGHT_FRINGE_WIDTH (f);
@@ -1269,8 +1250,7 @@ compute_fringe_widths (f, redraw)
 /* Free resources used by a user-defined bitmap.  */
 
 void
-destroy_fringe_bitmap (n)
-     int n;
+destroy_fringe_bitmap (int n)
 {
   struct fringe_bitmap **fbp;
 
@@ -1331,7 +1311,7 @@ If BITMAP overrides a standard fringe bitmap, the original bitmap is restored.
 */
 
 #if defined (HAVE_X_WINDOWS)
-static unsigned char swap_nibble[16] = {
+static const unsigned char swap_nibble[16] = {
   0x0, 0x8, 0x4, 0xc,           /* 0000 1000 0100 1100 */
   0x2, 0xa, 0x6, 0xe,           /* 0010 1010 0110 1110 */
   0x1, 0x9, 0x5, 0xd,           /* 0001 1001 0101 1101 */
@@ -1339,10 +1319,7 @@ static unsigned char swap_nibble[16] = {
 #endif                          /* HAVE_X_WINDOWS */
 
 void
-init_fringe_bitmap (which, fb, once_p)
-     int which;
-     struct fringe_bitmap *fb;
-     int once_p;
+init_fringe_bitmap (int which, struct fringe_bitmap *fb, int once_p)
 {
   if (once_p || fb->dynamic)
     {
@@ -1371,20 +1348,15 @@ init_fringe_bitmap (which, fb, once_p)
                                   | (swap_nibble[(b>>4) & 0xf] << 8)
                                   | (swap_nibble[(b>>8) & 0xf] << 4)
                                   | (swap_nibble[(b>>12) & 0xf]));
-             *bits++ = (b >> (16 - fb->width));
+             b >>= (16 - fb->width);
+#ifdef WORDS_BIG_ENDIAN
+             b = ((b >> 8) | (b << 8));
+#endif
+             *bits++ = b;
            }
        }
 #endif /* HAVE_X_WINDOWS */
 
-#if defined (MAC_OS) && defined (WORDS_BIG_ENDIAN)
-      unsigned short *bits = fb->bits;
-      int j;
-      for (j = 0; j < fb->height; j++)
-       {
-         unsigned short b = *bits;
-         *bits++ = ((b >> 8) & 0xff) | ((b & 0xff) << 8);
-       }
-#endif /* MAC_OS && WORDS_BIG_ENDIAN */
     }
 
   if (!once_p)
@@ -1413,7 +1385,7 @@ HEIGHT is height of bitmap.  If HEIGHT is nil, use length of BITS.
 WIDTH must be an integer between 1 and 16, or nil which defaults to 8.
 Optional fifth arg ALIGN may be one of `top', `center', or `bottom',
 indicating the positioning of the bitmap relative to the rows where it
-is used; the default is to center the bitmap.  Fourth arg may also be a
+is used; the default is to center the bitmap.  Fifth arg may also be a
 list (ALIGN PERIODIC) where PERIODIC non-nil specifies that the bitmap
 should be repeated.
 If BITMAP already exists, the existing definition is replaced.  */)
@@ -1622,19 +1594,19 @@ Return nil if POS is not visible in WINDOW.  */)
  ***********************************************************************/
 
 void
-syms_of_fringe ()
+syms_of_fringe (void)
 {
-  Qtruncation = intern ("truncation");
+  Qtruncation = intern_c_string ("truncation");
   staticpro (&Qtruncation);
-  Qcontinuation = intern ("continuation");
+  Qcontinuation = intern_c_string ("continuation");
   staticpro (&Qcontinuation);
-  Qoverlay_arrow = intern ("overlay-arrow");
+  Qoverlay_arrow = intern_c_string ("overlay-arrow");
   staticpro (&Qoverlay_arrow);
-  Qempty_line = intern ("empty-line");
+  Qempty_line = intern_c_string ("empty-line");
   staticpro (&Qempty_line);
-  Qtop_bottom = intern ("top-bottom");
+  Qtop_bottom = intern_c_string ("top-bottom");
   staticpro (&Qtop_bottom);
-  Qhollow_small = intern ("hollow-small");
+  Qhollow_small = intern_c_string ("hollow-small");
   staticpro (&Qhollow_small);
 
   defsubr (&Sdestroy_fringe_bitmap);
@@ -1659,7 +1631,7 @@ If nil, also continue lines which are exactly as wide as the window.  */);
 /* Garbage collection hook */
 
 void
-mark_fringe_data ()
+mark_fringe_data (void)
 {
   int i;
 
@@ -1671,7 +1643,7 @@ mark_fringe_data ()
 /* Initialize this module when Emacs starts.  */
 
 void
-init_fringe_once ()
+init_fringe_once (void)
 {
   int bt;
 
@@ -1680,7 +1652,7 @@ init_fringe_once ()
 }
 
 void
-init_fringe ()
+init_fringe (void)
 {
   int i;
 
@@ -1698,15 +1670,10 @@ init_fringe ()
     }
 }
 
-#if defined (HAVE_NTGUI) || defined (MAC_OS)
+#ifdef HAVE_NTGUI
 
 void
-#ifdef HAVE_NTGUI
-w32_init_fringe (rif)
-#else  /* MAC_OS */
-mac_init_fringe (rif)
-#endif
-     struct redisplay_interface *rif;
+w32_init_fringe (struct redisplay_interface *rif)
 {
   int bt;
 
@@ -1719,9 +1686,7 @@ mac_init_fringe (rif)
       rif->define_fringe_bitmap (bt, fb->bits, fb->height, fb->width);
     }
 }
-#endif
 
-#ifdef HAVE_NTGUI
 void
 w32_reset_fringes ()
 {