Partially sync files.el from XEmacs 21.5 for wildcard support.
[sxemacs] / src / events / event-stream.c
index e7d4a84..126d4f3 100644 (file)
@@ -92,6 +92,9 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>. */
 #include "sysfile.h"
 #include "systime.h"           /* to set Vlast_input_time */
 
+/* for extract_float() and CHECK_NUMBER */
+#include "ent/ent.h"
+
 #include "events-mod.h"
 #ifdef EF_USE_ASYNEQ
 #include "event-queue.h"
@@ -224,7 +227,7 @@ Lisp_Object Qretry_undefined_key_binding_unshifted;
 #ifdef HAVE_XIM
 /* If composed input is undefined, use self-insert-char */
 Lisp_Object Vcomposed_character_default_binding;
-#endif                         /* HAVE_XIM */
+#endif  /* HAVE_XIM */
 
 /* Console that corresponds to our controlling terminal */
 Lisp_Object Vcontrolling_terminal;
@@ -287,7 +290,7 @@ event_queue_t asyneq = Qnull_pointer;
 static Lisp_Object Vasyneq;
 #define EQ_EMPTY_P()   eq_queue_empty_p(asyneq)
 #define EQ_LARGE_P()   (eq_queue_size(asyneq) > 1)
-#else
+#else  /* !EF_USE_ASYNEQ */
 /* This structure is basically a typeahead queue: things like
    wait-reading-process-output will delay the execution of
    keyboard and mouse events by pushing them here.
@@ -299,7 +302,7 @@ static Lisp_Object command_event_queue;
 static Lisp_Object command_event_queue_tail;
 #define EQ_EMPTY_P()   NILP(command_event_queue)
 #define EQ_LARGE_P()   !NILP(command_event_queue_tail)
-#endif
+#endif /* EF_USE_ASYNEQ */
 
 /* Nonzero means echo unfinished commands after this many seconds of pause. */
 static Lisp_Object Vecho_keystrokes;
@@ -330,7 +333,8 @@ static Lisp_Object recursive_sit_for;
 #define COMMAND_BUILDERP(x) RECORDP (x, command_builder)
 #define CHECK_COMMAND_BUILDER(x) CHECK_RECORD (x, command_builder)
 
-static Lisp_Object mark_command_builder(Lisp_Object obj)
+static Lisp_Object
+mark_command_builder(Lisp_Object obj)
 {
        struct command_builder *builder = XCOMMAND_BUILDER(obj);
        mark_object(builder->prefix_events);
@@ -342,7 +346,8 @@ static Lisp_Object mark_command_builder(Lisp_Object obj)
        return builder->console;
 }
 
-static void finalize_command_builder(void *header, int for_disksave)
+static void
+finalize_command_builder(void *header, int for_disksave)
 {
        if (!for_disksave) {
                xfree(((struct command_builder *)header)->echo_buf);
@@ -365,12 +370,13 @@ static void reset_command_builder_event_chain(struct command_builder *builder)
        builder->munge_me[1].first_mungeable_event = Qnil;
 }
 
-Lisp_Object allocate_command_builder(Lisp_Object console)
+Lisp_Object
+allocate_command_builder(Lisp_Object console)
 {
        Lisp_Object builder_obj;
        struct command_builder *builder =
-           alloc_lcrecord_type(struct command_builder,
-                               &lrecord_command_builder);
+               alloc_lcrecord_type(
+                       struct command_builder, &lrecord_command_builder);
 
        builder->console = console;
        reset_command_builder_event_chain(builder);
@@ -391,16 +397,20 @@ command_builder_append_event(struct command_builder *builder, Lisp_Object event)
 {
        assert(EVENTP(event));
 
-       if (EVENTP(builder->most_current_event))
+       if (EVENTP(builder->most_current_event)) {
                XSET_EVENT_NEXT(builder->most_current_event, event);
-       else
+       } else {
                builder->current_events = event;
+       }
 
        builder->most_current_event = event;
-       if (NILP(builder->munge_me[0].first_mungeable_event))
+       if (NILP(builder->munge_me[0].first_mungeable_event)) {
                builder->munge_me[0].first_mungeable_event = event;
-       if (NILP(builder->munge_me[1].first_mungeable_event))
+       }
+       if (NILP(builder->munge_me[1].first_mungeable_event)) {
                builder->munge_me[1].first_mungeable_event = event;
+       }
+       return;
 }
 \f
 /**********************************************************************/
@@ -414,7 +424,8 @@ enum event_stream_operation {
        EVENT_STREAM_READ
 };
 
-static void check_event_stream_ok(enum event_stream_operation op)
+static void
+check_event_stream_ok(enum event_stream_operation op)
 {
        if (!event_stream && noninteractive) {
                switch (op) {
@@ -433,20 +444,26 @@ static void check_event_stream_ok(enum event_stream_operation op)
                error
                    ("event-stream callbacks not initialized (internal error?)");
        }
+       return;
 }
 
-static int event_stream_event_pending_p(int user)
+static int
+event_stream_event_pending_p(int user)
 {
        return event_stream && event_stream->event_pending_p(user);
 }
 
-static void event_stream_force_event_pending(struct frame *f)
+static void
+event_stream_force_event_pending(struct frame *f)
 {
-       if (event_stream->force_event_pending)
+       if (event_stream->force_event_pending) {
                event_stream->force_event_pending(f);
+       }
+       return;
 }
 
-static int maybe_read_quit_event(Lisp_Event * event)
+static int
+maybe_read_quit_event(Lisp_Event * event)
 {
        /* A C-g that came from `sigint_happened' will always come from the
           controlling terminal.  If that doesn't exist, however, then the
@@ -473,7 +490,8 @@ static int maybe_read_quit_event(Lisp_Event * event)
        return 0;
 }
 
-void event_stream_next_event(Lisp_Event * event)
+void
+event_stream_next_event(Lisp_Event * event)
 {
        Lisp_Object event_obj;
 
@@ -501,74 +519,90 @@ void event_stream_next_event(Lisp_Event * event)
 #ifdef DEBUG_SXEMACS
        /* timeout events have more info set later, so
           print the event out in next_event_internal(). */
-       if (event->event_type != timeout_event)
+       if (event->event_type != timeout_event) {
                DEBUG_PRINT_EMACS_EVENT("real", event_obj);
+       }
 #endif
        maybe_kbd_translate(event_obj);
+       return;
 }
 
-void event_stream_handle_magic_event(Lisp_Event * event)
+void
+event_stream_handle_magic_event(Lisp_Event * event)
 {
        check_event_stream_ok(EVENT_STREAM_READ);
        event_stream->handle_magic_event_cb(event);
+       return;
 }
 
-static int event_stream_add_timeout(EMACS_TIME timeout)
+static int
+event_stream_add_timeout(EMACS_TIME timeout)
 {
        check_event_stream_ok(EVENT_STREAM_TIMEOUT);
        return event_stream->add_timeout_cb(timeout);
 }
 
-static void event_stream_remove_timeout(int id)
+static void
+event_stream_remove_timeout(int id)
 {
        check_event_stream_ok(EVENT_STREAM_TIMEOUT);
        event_stream->remove_timeout_cb(id);
+       return;
 }
 
-void event_stream_select_console(struct console *con)
+void
+event_stream_select_console(struct console *con)
 {
        check_event_stream_ok(EVENT_STREAM_CONSOLE);
        if (!con->input_enabled) {
                event_stream->select_console_cb(con);
                con->input_enabled = 1;
        }
+       return;
 }
 
-void event_stream_unselect_console(struct console *con)
+void
+event_stream_unselect_console(struct console *con)
 {
        check_event_stream_ok(EVENT_STREAM_CONSOLE);
        if (con->input_enabled) {
                event_stream->unselect_console_cb(con);
                con->input_enabled = 0;
        }
+       return;
 }
 
-void event_stream_select_process(Lisp_Process * proc)
+void
+event_stream_select_process(Lisp_Process * proc)
 {
        check_event_stream_ok(EVENT_STREAM_PROCESS);
        if (!get_process_selected_p(proc)) {
                event_stream->select_process_cb(proc);
                set_process_selected_p(proc, 1);
        }
+       return;
 }
 
-void event_stream_unselect_process(Lisp_Process * proc)
+void
+event_stream_unselect_process(Lisp_Process * proc)
 {
        check_event_stream_ok(EVENT_STREAM_PROCESS);
        if (get_process_selected_p(proc)) {
                event_stream->unselect_process_cb(proc);
                set_process_selected_p(proc, 0);
        }
+       return;
 }
 
 USID
-event_stream_create_stream_pair(void *inhandle, void *outhandle,
-                               Lisp_Object * instream, Lisp_Object * outstream,
-                               int flags)
+event_stream_create_stream_pair(
+       void *inhandle, void *outhandle,
+       Lisp_Object * instream, Lisp_Object * outstream,
+       int flags)
 {
        check_event_stream_ok(EVENT_STREAM_PROCESS);
-       return event_stream->create_stream_pair_cb
-           (inhandle, outhandle, instream, outstream, flags);
+       return event_stream->create_stream_pair_cb(
+               inhandle, outhandle, instream, outstream, flags);
 }
 
 USID
@@ -578,18 +612,22 @@ event_stream_delete_stream_pair(Lisp_Object instream, Lisp_Object outstream)
        return event_stream->delete_stream_pair_cb(instream, outstream);
 }
 
-void event_stream_quit_p(void)
+void
+event_stream_quit_p(void)
 {
-       if (event_stream)
+       if (event_stream) {
                event_stream->quit_p_cb();
+       }
 }
 
-static int event_stream_current_event_timestamp(struct console *c)
+static int
+event_stream_current_event_timestamp(struct console *c)
 {
-       if (event_stream && event_stream->current_event_timestamp_cb)
+       if (event_stream && event_stream->current_event_timestamp_cb) {
                return event_stream->current_event_timestamp_cb(c);
-       else
+       } else {
                return 0;
+       }
 }
 \f
 /**********************************************************************/
@@ -613,8 +651,9 @@ echo_key_event(struct command_builder *command_builder, Lisp_Object event)
        format_event_object(buf, XEVENT(event), 1);
        len = strlen(buf);
 
-       if (len + buf_index + 4 > command_builder->echo_buf_length)
+       if (len + buf_index + 4 > command_builder->echo_buf_length) {
                return;
+       }
        e = command_builder->echo_buf + buf_index;
        memcpy(e, buf, len);
        e += len;
@@ -625,6 +664,7 @@ echo_key_event(struct command_builder *command_builder, Lisp_Object event)
        e[3] = 0;
 
        command_builder->echo_buf_index = buf_index + len + 1;
+       return;
 }
 
 static void
@@ -634,8 +674,10 @@ regenerate_echo_keys_from_this_command_keys(struct command_builder *builder)
 
        builder->echo_buf_index = 0;
 
-       EVENT_CHAIN_LOOP(event, Vthis_command_keys)
-           echo_key_event(builder, event);
+       EVENT_CHAIN_LOOP(event, Vthis_command_keys) {
+               echo_key_event(builder, event);
+       }
+       return;
 }
 
 static void
@@ -645,13 +687,15 @@ maybe_echo_keys(struct command_builder *command_builder, int no_snooze)
        double echo_keystrokes;
        struct frame *f = selected_frame();
        /* Message turns off echoing unless more keystrokes turn it on again. */
-       if (echo_area_active(f) && !EQ(Qcommand, echo_area_status(f)))
+       if (echo_area_active(f) && !EQ(Qcommand, echo_area_status(f))) {
                return;
+       }
 
-       if (INTP(Vecho_keystrokes) || FLOATP(Vecho_keystrokes))
+       if (INTP(Vecho_keystrokes) || FLOATP(Vecho_keystrokes)) {
                echo_keystrokes = extract_float(Vecho_keystrokes);
-       else
+       } else {
                echo_keystrokes = 0;
+       }
 
        if (minibuf_level == 0 && echo_keystrokes > 0.0
 #if defined (HAVE_X_WINDOWS) && defined (LWLIB_MENUBARS_LUCID)
@@ -659,11 +703,13 @@ maybe_echo_keys(struct command_builder *command_builder, int no_snooze)
 #endif
            ) {
                if (!no_snooze) {
-                       /* #### C-g here will cause QUIT.  Setting dont_check_for_quit
+                       /* #### C-g here will cause QUIT.
+                          Setting dont_check_for_quit
                           doesn't work.  See check_quit. */
-                       if (NILP(Fsit_for(Vecho_keystrokes, Qnil)))
+                       if (NILP(Fsit_for(Vecho_keystrokes, Qnil))) {
                                /* input came in, so don't echo. */
                                return;
+                       }
                }
 
                echo_area_message(f, command_builder->echo_buf, Qnil, 0,
@@ -672,6 +718,7 @@ maybe_echo_keys(struct command_builder *command_builder, int no_snooze)
                                  strlen((char *)command_builder->echo_buf),
                                  Qcommand);
        }
+       return;
 }
 
 static void
@@ -681,34 +728,41 @@ reset_key_echo(struct command_builder *command_builder,
        /* This function can GC */
        struct frame *f = selected_frame();
 
-       if (command_builder)
+       if (command_builder) {
                command_builder->echo_buf_index = -1;
+       }
 
-       if (remove_echo_area_echo)
+       if (remove_echo_area_echo) {
                clear_echo_area(f, Qcommand, 0);
+       }
+       return;
 }
 \f
 /**********************************************************************/
 /*                          random junk                               */
 /**********************************************************************/
 
-static void maybe_kbd_translate(Lisp_Object event)
+static void
+maybe_kbd_translate(Lisp_Object event)
 {
        Emchar c;
        int did_translate = 0;
 
-       if (XEVENT_TYPE(event) != key_press_event)
+       if (XEVENT_TYPE(event) != key_press_event) {
                return;
-       if (!HASH_TABLEP(Vkeyboard_translate_table))
+       }
+       if (!HASH_TABLEP(Vkeyboard_translate_table)) {
                return;
-       if (EQ(Fhash_table_count(Vkeyboard_translate_table), Qzero))
+       }
+       if (EQ(Fhash_table_count(Vkeyboard_translate_table), Qzero)) {
                return;
+       }
 
        c = event_to_character(XEVENT(event), 0, 0, 0);
        if (c != -1) {
-               Lisp_Object traduit =
-                   Fgethash(make_char(c), Vkeyboard_translate_table,
-                            Qnil);
+               Lisp_Object traduit = Fgethash(
+                       make_char(c), Vkeyboard_translate_table, Qnil);
+
                if (!NILP(traduit) && SYMBOLP(traduit)) {
                        XEVENT(event)->event.key.keysym = traduit;
                        XEVENT(event)->event.key.modifiers = 0;
@@ -716,23 +770,24 @@ static void maybe_kbd_translate(Lisp_Object event)
                } else if (CHARP(traduit)) {
                        Lisp_Event ev2;
 
-                       /* This used to call Fcharacter_to_event() directly into EVENT,
-                          but that can eradicate timestamps and other such stuff.
-                          This way is safer. */
+                       /* This used to call Fcharacter_to_event() directly into
+                          EVENT, but that can eradicate timestamps and other
+                          such stuff.  This way is safer. */
                        zero_event(&ev2);
-                       character_to_event(XCHAR(traduit), &ev2,
-                                          XCONSOLE(EVENT_CHANNEL
-                                                   (XEVENT(event))), 0, 1);
+                       character_to_event(
+                               XCHAR(traduit), &ev2,
+                               XCONSOLE(EVENT_CHANNEL(XEVENT(event))), 0, 1);
                        XEVENT(event)->event.key.keysym = ev2.event.key.keysym;
                        XEVENT(event)->event.key.modifiers =
-                           ev2.event.key.modifiers;
+                               ev2.event.key.modifiers;
                        did_translate = 1;
                }
        }
 
        if (!did_translate) {
-               Lisp_Object traduit = Fgethash(XEVENT(event)->event.key.keysym,
-                                              Vkeyboard_translate_table, Qnil);
+               Lisp_Object traduit = Fgethash(
+                       XEVENT(event)->event.key.keysym,
+                       Vkeyboard_translate_table, Qnil);
                if (!NILP(traduit) && SYMBOLP(traduit)) {
                        XEVENT(event)->event.key.keysym = traduit;
                        did_translate = 1;
@@ -740,19 +795,21 @@ static void maybe_kbd_translate(Lisp_Object event)
                        Lisp_Event ev2;
 
                        zero_event(&ev2);
-                       character_to_event(XCHAR(traduit), &ev2,
-                                          XCONSOLE(EVENT_CHANNEL
-                                                   (XEVENT(event))), 0, 1);
+                       character_to_event(
+                               XCHAR(traduit), &ev2,
+                               XCONSOLE(EVENT_CHANNEL(XEVENT(event))), 0, 1);
                        XEVENT(event)->event.key.keysym = ev2.event.key.keysym;
                        XEVENT(event)->event.key.modifiers |=
-                           ev2.event.key.modifiers;
+                               ev2.event.key.modifiers;
                        did_translate = 1;
                }
        }
 #ifdef DEBUG_SXEMACS
-       if (did_translate)
+       if (did_translate) {
                DEBUG_PRINT_EMACS_EVENT("->keyboard-translate-table", event);
-#endif
+       }
+#endif /* DEBUG_SXEMACS */
+       return;
 }
 
 /* NB: The following auto-save stuff is in keyboard.c in FSFmacs, and
@@ -762,19 +819,24 @@ static void maybe_kbd_translate(Lisp_Object event)
 /* When an auto-save happens, record the number of keystrokes, and
    don't do again soon.  */
 
-void record_auto_save(void)
+void
+record_auto_save(void)
 {
        keystrokes_since_auto_save = 0;
+       return;
 }
 
 /* Make an auto save happen as soon as possible at command level.  */
 
-void force_auto_save_soon(void)
+void
+force_auto_save_soon(void)
 {
        keystrokes_since_auto_save = 1 + max(auto_save_interval, 20);
+       return;
 }
 
-static void maybe_do_auto_save(void)
+static void
+maybe_do_auto_save(void)
 {
        /* This function can call lisp */
        keystrokes_since_auto_save++;
@@ -784,9 +846,11 @@ static void maybe_do_auto_save(void)
                Fdo_auto_save(Qnil, Qnil);
                record_auto_save();
        }
+       return;
 }
 
-static Lisp_Object print_help(Lisp_Object object)
+static Lisp_Object
+print_help(Lisp_Object object)
 {
        Fprinc(object, Qnil);
        return Qnil;
@@ -799,9 +863,10 @@ execute_help_form(struct command_builder *command_builder, Lisp_Object event)
        Lisp_Object help = Qnil;
        int speccount = specpdl_depth();
        Bytecount buf_index = command_builder->echo_buf_index;
-       Lisp_Object echo = ((buf_index <= 0)
-                           ? Qnil : make_string(command_builder->echo_buf,
-                                                buf_index));
+       Lisp_Object echo =
+               ((buf_index <= 0)
+                ? Qnil
+                : make_string(command_builder->echo_buf, buf_index));
        struct gcpro gcpro1, gcpro2;
        GCPRO2(echo, help);
 
@@ -810,9 +875,10 @@ execute_help_form(struct command_builder *command_builder, Lisp_Object event)
        reset_key_echo(command_builder, 1);
 
        help = Feval(Vhelp_form);
-       if (STRINGP(help))
-               internal_with_output_to_temp_buffer(build_string("*Help*"),
-                                                   print_help, help, Qnil);
+       if (STRINGP(help)) {
+               internal_with_output_to_temp_buffer(
+                       build_string("*Help*"), print_help, help, Qnil);
+       }
        Fnext_command_event(event, Qnil);
        /* Remove the help from the frame */
        unbind_to(speccount, Qnil);
@@ -837,25 +903,31 @@ execute_help_form(struct command_builder *command_builder, Lisp_Object event)
        }
 
        command_builder->echo_buf_index = buf_index;
-       if (buf_index > 0)
-               memcpy(command_builder->echo_buf, XSTRING_DATA(echo), buf_index + 1);   /* terminating 0 */
+       if (buf_index > 0) {
+               memcpy(command_builder->echo_buf,
+                      XSTRING_DATA(echo), buf_index + /* terminating 0 */1);
+       }
        UNGCPRO;
+       return;
 }
 \f
 /**********************************************************************/
 /*                          input pending                             */
 /**********************************************************************/
 
-int detect_input_pending(void)
+int
+detect_input_pending(void)
 {
        /* Always call the event_pending_p hook even if there's an unread
           character, because that might do some needed ^G detection (on
           systems without SIGIO, for example).
         */
-       if (event_stream_event_pending_p(1))
+       if (event_stream_event_pending_p(1)) {
                return 1;
-       if (!NILP(Vunread_command_events) || !NILP(Vunread_command_event))
+       }
+       if (!NILP(Vunread_command_events) || !NILP(Vunread_command_event)) {
                return 1;
+       }
        if (!EQ_EMPTY_P()) {
                Lisp_Object event;
 
@@ -866,13 +938,13 @@ int detect_input_pending(void)
                            XEVENT_TYPE(event) != magic_eval_event) {
                                RETURN_FROM_EQ_TRAVERSE(asyneq, 1);
                        });
-#else
+#else  /* !EF_USE_ASYNEQ */
                EVENT_CHAIN_LOOP(event, command_event_queue) {
                        if (XEVENT_TYPE(event) != eval_event
                            && XEVENT_TYPE(event) != magic_eval_event)
                                return 1;
                }
-#endif
+#endif /* EF_USE_ASYNEQ */
        }
        return 0;
 }
@@ -918,8 +990,9 @@ add_low_level_timeout(struct low_level_timeout **timeout_list, EMACS_TIME thyme)
 
        tm = Blocktype_alloc(the_low_level_timeout_blocktype);
        tm->next = NULL;
-       if (low_level_timeout_id_tick == 0)
+       if (low_level_timeout_id_tick == 0) {
                low_level_timeout_id_tick++;
+       }
        tm->id = low_level_timeout_id_tick++;
        tm->time = thyme;
 
@@ -940,24 +1013,29 @@ add_low_level_timeout(struct low_level_timeout **timeout_list, EMACS_TIME thyme)
 /* Remove the low-level timeout identified by ID from TIMEOUT_LIST.
    If the timeout is not there, do nothing. */
 
-void remove_low_level_timeout(struct low_level_timeout **timeout_list, int id)
+void
+remove_low_level_timeout(struct low_level_timeout **timeout_list, int id)
 {
        struct low_level_timeout *t, *prev;
 
        /* find it */
 
-       for (t = *timeout_list, prev = NULL; t && t->id != id; t = t->next)
+       for (t = *timeout_list, prev = NULL; t && t->id != id; t = t->next) {
                prev = t;
+       }
 
-       if (!t)
-               return;         /* couldn't find it */
+       if (!t) {
+               /* couldn't find it */
+               return;
+       }
 
-       if (!prev)
+       if (!prev) {
                *timeout_list = t->next;
-       else
+       } else {
                prev->next = t->next;
-
+       }
        Blocktype_free(the_low_level_timeout_blocktype, t);
+       return;
 }
 
 /* If there are timeouts on TIMEOUT_LIST, store the relative time
@@ -965,12 +1043,13 @@ void remove_low_level_timeout(struct low_level_timeout **timeout_list, int id)
    return 1.  Otherwise, return 0. */
 
 int
-get_low_level_timeout_interval(struct low_level_timeout *timeout_list,
-                              EMACS_TIME * interval)
+get_low_level_timeout_interval(
+       struct low_level_timeout *timeout_list, EMACS_TIME *interval)
 {
-       if (!timeout_list)      /* no timer events; block indefinitely */
+       if (!timeout_list) {
+               /* no timer events; block indefinitely */
                return 0;
-       else {
+       else {
                EMACS_TIME current_time;
 
                /* The time to block is the difference between the first
@@ -979,13 +1058,15 @@ get_low_level_timeout_interval(struct low_level_timeout *timeout_list,
                   but we still have to call select(), with a zero-valued
                   timeout: user events must have precedence over timer events. */
                EMACS_GET_TIME(current_time);
-               if (EMACS_TIME_GREATER(timeout_list->time, current_time))
+               if (EMACS_TIME_GREATER(timeout_list->time, current_time)) {
                        EMACS_SUB_TIME(*interval, timeout_list->time,
                                       current_time);
-               else
+               } else {
                        EMACS_SET_SECS_USECS(*interval, 0, 0);
+               }
                return 1;
        }
+       /* not reached */
 }
 
 /* Pop the first (i.e. soonest) timeout off of TIMEOUT_LIST and return
@@ -993,16 +1074,17 @@ get_low_level_timeout_interval(struct low_level_timeout *timeout_list,
    timeout into TIME_OUT. */
 
 int
-pop_low_level_timeout(struct low_level_timeout **timeout_list,
-                     EMACS_TIME * time_out)
+pop_low_level_timeout(
+       struct low_level_timeout **timeout_list, EMACS_TIME *time_out)
 {
        struct low_level_timeout *tm = *timeout_list;
        int id;
 
        assert(tm);
        id = tm->id;
-       if (time_out)
+       if (time_out) {
                *time_out = tm->time;
+       }
        *timeout_list = tm->next;
        Blocktype_free(the_low_level_timeout_blocktype, tm);
        return id;
@@ -1018,7 +1100,8 @@ static Lisp_Object pending_timeout_list, pending_async_timeout_list;
 static Lisp_Object Vtimeout_free_list;
 #endif /* !BDWGC */
 
-static Lisp_Object mark_timeout(Lisp_Object obj)
+static Lisp_Object
+mark_timeout(Lisp_Object obj)
 {
        Lisp_Timeout *tm = XTIMEOUT(obj);
        mark_object(tm->function);
@@ -1030,11 +1113,11 @@ static void
 print_timeout(Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
 {
        const Lisp_Timeout *t = XTIMEOUT(obj);
-       char buf[64];
-
-       sprintf(buf, "#<INTERNAL OBJECT (SXEmacs bug?) (timeout) 0x%lx>",
+       write_fmt_string(
+               printcharfun,
+               "#<INTERNAL OBJECT (SXEmacs bug?) (timeout) 0x%lx>",
                (unsigned long)t);
-       write_c_string(buf, printcharfun);
+       return;
 }
 
 static const struct lrecord_description timeout_description[] = {
@@ -1077,12 +1160,13 @@ event_stream_generate_wakeup(unsigned int milliseconds,
 
        if (async_p) {
                timeout->interval_id =
-                   event_stream_add_async_timeout(timeout->next_signal_time);
-               pending_async_timeout_list = noseeum_cons(op,
-                                                         pending_async_timeout_list);
+                       event_stream_add_async_timeout(
+                               timeout->next_signal_time);
+               pending_async_timeout_list = noseeum_cons(
+                       op, pending_async_timeout_list);
        } else {
                timeout->interval_id =
-                   event_stream_add_timeout(timeout->next_signal_time);
+                       event_stream_add_timeout(timeout->next_signal_time);
                pending_timeout_list = noseeum_cons(op, pending_timeout_list);
        }
        return timeout->id;
@@ -1112,17 +1196,18 @@ event_stream_resignal_wakeup(int interval_id, int async_p,
        struct gcpro gcpro1;
        int id;
 
-       GCPRO1(op);             /* just in case ...  because it's removed from the list
-                                  for awhile. */
+       /* just in case ...  because it's removed from the list for awhile. */
+       GCPRO1(op);
 
        timeout_list =
-           async_p ? &pending_async_timeout_list : &pending_timeout_list;
+               async_p ? &pending_async_timeout_list : &pending_timeout_list;
 
        /* Find the timeout on the list of pending ones. */
        LIST_LOOP(rest, *timeout_list) {
                timeout = XTIMEOUT(XCAR(rest));
-               if (timeout->interval_id == interval_id)
+               if (timeout->interval_id == interval_id) {
                        break;
+               }
        }
 
        assert(!NILP(rest));
@@ -1155,8 +1240,8 @@ event_stream_resignal_wakeup(int interval_id, int async_p,
                do {
                        EMACS_ADD_TIME(timeout->next_signal_time,
                                       timeout->next_signal_time, interval);
-               } while (EMACS_TIME_GREATER
-                        (current_time, timeout->next_signal_time));
+               } while (EMACS_TIME_GREATER(
+                                current_time, timeout->next_signal_time));
 
                if (async_p) {
                        timeout->interval_id =
@@ -1182,7 +1267,8 @@ event_stream_resignal_wakeup(int interval_id, int async_p,
        return id;
 }
 
-void event_stream_disable_wakeup(int id, int async_p)
+void
+event_stream_disable_wakeup(int id, int async_p)
 {
        Lisp_Timeout *timeout = 0;
        Lisp_Object rest;
@@ -1217,19 +1303,22 @@ void event_stream_disable_wakeup(int id, int async_p)
                free_managed_lcrecord(Vtimeout_free_list, op);
 #endif /* BDWGC */
        }
+       return;
 }
 
-static int event_stream_wakeup_pending_p(int id, int async_p)
+static int
+event_stream_wakeup_pending_p(int id, int async_p)
 {
        Lisp_Timeout *timeout;
        Lisp_Object rest;
        Lisp_Object timeout_list;
        int found = 0;
 
-       if (async_p)
+       if (async_p) {
                timeout_list = pending_async_timeout_list;
-       else
+       } else {
                timeout_list = pending_timeout_list;
+       }
 
        /* Find the element on the list of pending ones, if it's still there. */
        LIST_LOOP(rest, timeout_list) {
@@ -1253,7 +1342,8 @@ extern int poll_for_quit_id;
 extern int poll_for_sigchld_id;
 #endif
 
-void event_stream_deal_with_async_timeout(int interval_id)
+void
+event_stream_deal_with_async_timeout(int interval_id)
 {
        /* This function can GC */
        Lisp_Object humpty, dumpty;
@@