commit b11819949a45426ee0ef59443092b6c412c5964e
parent 07189d6ba709c3bda53d09f1fcd3e283dfc467d2
Author: ukai <ukai>
Date: Fri, 15 Nov 2002 16:05:13 +0000
[w3m-dev 03439] restore alarm event
* fm.h (AL_RESTORE): added
* main.c (alarm_sec): deleted
(alarm_status): deleted
(alarm_buffer): deleted
(alarm_event): deleted
(AlarmEvent): added
(CurrentAlarm): added
(PrevAlarm): added
(main): rewrite with CurrentAlarm
(SigAlarm): rewrite with CurrentAlarm
(copyAlarmEvent): added
(setAlarm): if AL_RESTORE, copy back from PrevAlarm
rewrite with CurrentAlarm
From: Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
Diffstat:
M | ChangeLog | | | 17 | +++++++++++++++++ |
M | fm.h | | | 1 | + |
M | main.c | | | 90 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
3 files changed, 79 insertions(+), 29 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -1,5 +1,22 @@
2002-11-16 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+ * [w3m-dev 03439] restore alarm event
+ * fm.h (AL_RESTORE): added
+ * main.c (alarm_sec): deleted
+ (alarm_status): deleted
+ (alarm_buffer): deleted
+ (alarm_event): deleted
+ (AlarmEvent): added
+ (CurrentAlarm): added
+ (PrevAlarm): added
+ (main): rewrite with CurrentAlarm
+ (SigAlarm): rewrite with CurrentAlarm
+ (copyAlarmEvent): added
+ (setAlarm): if AL_RESTORE, copy back from PrevAlarm
+ rewrite with CurrentAlarm
+
+2002-11-16 Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp>
+
* [w3m-dev 03438] Re: segmentation fault by large complex table.
* table.c (check_table_height): check MAXROWCELL
* table.h (MAXROWCELL): added
diff --git a/fm.h b/fm.h
@@ -1070,6 +1070,7 @@ void w3m_exit(int i);
#define AL_IMPLICIT_DONE 4
#define AL_ONCE 8
#define AL_IMPLICIT_ONCE (AL_IMPLICIT|AL_ONCE)
+#define AL_RESTORE 16
#endif
/*
diff --git a/main.c b/main.c
@@ -42,10 +42,19 @@ static Event eventQueue[N_EVENT_QUEUE];
static int n_event_queue;
#ifdef USE_ALARM
-static int alarm_sec = 0;
-static short alarm_status = AL_UNSET;
-static Buffer *alarm_buffer;
-static Event alarm_event;
+typedef struct {
+ int sec;
+ int cmd;
+ void *data;
+ short status;
+ Buffer *buffer;
+} AlarmEvent;
+static AlarmEvent CurrentAlarm = {
+ 0, FUNCNAME_nulcmd, NULL, AL_UNSET, NULL
+};
+static AlarmEvent PrevAlarm = {
+ 0, FUNCNAME_nulcmd, NULL, AL_UNSET, NULL
+};
static MySignalHandler SigAlarm(SIGNAL_ARG);
#endif
@@ -977,16 +986,18 @@ main(int argc, char **argv, char **envp)
mouse_active();
#endif /* USE_MOUSE */
#ifdef USE_ALARM
- if (alarm_status & AL_IMPLICIT) {
- alarm_buffer = Currentbuf;
- alarm_status = AL_IMPLICIT_DONE | (alarm_status & AL_ONCE);
+ if (CurrentAlarm.status & AL_IMPLICIT) {
+ CurrentAlarm.buffer = Currentbuf;
+ CurrentAlarm.status = AL_IMPLICIT_DONE
+ | (CurrentAlarm.status & AL_ONCE);
}
- else if (alarm_status & AL_IMPLICIT_DONE && alarm_buffer != Currentbuf) {
- setAlarmEvent(0, AL_UNSET, FUNCNAME_nulcmd, NULL);
+ else if (CurrentAlarm.status & AL_IMPLICIT_DONE &&
+ CurrentAlarm.buffer != Currentbuf) {
+ setAlarmEvent(0, AL_RESTORE, FUNCNAME_nulcmd, NULL);
}
- if (alarm_sec > 0) {
+ if (CurrentAlarm.sec > 0) {
signal(SIGALRM, SigAlarm);
- alarm(alarm_sec);
+ alarm(CurrentAlarm.sec);
}
#endif
#ifdef SIGWINCH
@@ -1009,7 +1020,7 @@ main(int argc, char **argv, char **envp)
signal(SIGWINCH, resize_hook);
#endif
#ifdef USE_ALARM
- if (alarm_sec > 0) {
+ if (CurrentAlarm.sec > 0) {
alarm(0);
}
#endif
@@ -5237,37 +5248,51 @@ SigAlarm(SIGNAL_ARG)
{
char *data;
- if (alarm_sec > 0) {
+ if (CurrentAlarm.sec > 0) {
CurrentKey = -1;
CurrentKeyData = NULL;
- CurrentCmdData = data = (char *)alarm_event.user_data;
+ CurrentCmdData = data = (char *)CurrentAlarm.data;
#ifdef USE_MOUSE
if (use_mouse)
mouse_inactive();
#endif
- w3mFuncList[alarm_event.cmd].func();
+ w3mFuncList[CurrentAlarm.cmd].func();
#ifdef USE_MOUSE
if (use_mouse)
mouse_active();
#endif
CurrentCmdData = NULL;
onA();
- if (alarm_status & AL_IMPLICIT) {
- alarm_buffer = Currentbuf;
- alarm_status = AL_IMPLICIT_DONE | (alarm_status & AL_ONCE);
+ if (CurrentAlarm.status & AL_IMPLICIT) {
+ CurrentAlarm.buffer = Currentbuf;
+ CurrentAlarm.status = AL_IMPLICIT_DONE
+ | (CurrentAlarm.status & AL_ONCE);
}
- else if (alarm_status & AL_IMPLICIT_DONE
- && (alarm_buffer != Currentbuf || alarm_status & AL_ONCE)) {
- setAlarmEvent(0, AL_UNSET, FUNCNAME_nulcmd, NULL);
+ else if (CurrentAlarm.status & AL_IMPLICIT_DONE
+ && (CurrentAlarm.buffer != Currentbuf ||
+ CurrentAlarm.status & AL_ONCE)) {
+ setAlarmEvent(0, AL_RESTORE, FUNCNAME_nulcmd, NULL);
}
- if (alarm_sec > 0) {
+ if (CurrentAlarm.sec > 0) {
signal(SIGALRM, SigAlarm);
- alarm(alarm_sec);
+ alarm(CurrentAlarm.sec);
}
}
SIGNAL_RETURN;
}
+static void
+copyAlarmEvent(AlarmEvent *src, AlarmEvent *dst)
+{
+ if (!src || !dst)
+ return;
+ dst->sec = src->sec;
+ dst->cmd = src->cmd;
+ dst->data = src->data;
+ dst->status = src->status;
+ dst->buffer = src->buffer;
+}
+
void
setAlarm(void)
{
@@ -5303,13 +5328,20 @@ setAlarm(void)
void
setAlarmEvent(int sec, short status, int cmd, void *data)
{
- if (status == AL_UNSET || status == AL_EXPLICIT
- || (status & AL_IMPLICIT && alarm_status != AL_EXPLICIT)) {
- alarm_sec = sec;
- alarm_status = status;
- alarm_event.cmd = cmd;
- alarm_event.user_data = data;
+ if (status == AL_RESTORE) {
+ copyAlarmEvent(&PrevAlarm, &CurrentAlarm);
+ PrevAlarm.sec = 0;
+ PrevAlarm.status = AL_UNSET;
+ return;
}
+ if (CurrentAlarm.status == AL_EXPLICIT &&
+ (status == AL_IMPLICIT || status == AL_IMPLICIT_ONCE))
+ copyAlarmEvent(&CurrentAlarm, &PrevAlarm);
+ CurrentAlarm.sec = sec;
+ CurrentAlarm.cmd = cmd;
+ CurrentAlarm.data = data;
+ CurrentAlarm.status = status;
+ CurrentAlarm.buffer = NULL;
}
#endif