Feb 90 Letters
Volume Number: 6
Issue Number: 2
Column Tag: Letters
CheckAbort() Revised 
By David E. Smith, Editor & Publisher, MacTutor
Let’s Doodat!
Greg King, Ph.D.
SCIEX
Ontario, Canada
This letter is to point out 2 bugs in Lee Neuse’s “check_abort” routine (Three
Doodats, Sept. 89).
The first bug occurs when the command period event is the last event in the
queue. Mr. Neuse’s code removes the event and then tests to see if it was the last event.
This will never succeed because the event has been removed. The result is usually a
bus error because the qLink field of the last event contains a -1. The funny thing is
that the routine will not crash if the command-period is the only event in the queue.
The second bug is more subtle. Dequeue does not de-allocate the memory for the
event entry being removed from the queue, this is the responsibility of the program
calling it (IM2-383). Mr. Neuse doesn’t do this so every time an event is removed it
hangs around the heap.
Below is my version of a command-period handler that addresses the above stated
problems. It has been tested for the past week in the print and update loops of a 400K
application. It is a scientific application that often has to plot many thousands of data
points on the screen, and it is often desirable to be able to both abort long updates and
queue up multiple keystroke commands. Please excuse my style, I was originally a
Pascal programmer.
/* 1 */
Boolean CmdPeriod()
{
EvQElPtr eq_p, theEntry;
Boolean f_found, last, dispose_entry;
f_found = FALSE;
last = FALSE;
/* Start at head of internal queue. */
eq_p = (EvQElPtr) (EventQueue.qHead);
do {
/* Test for end of queue first. */
if (eq_p == (EvQElPtr) EventQueue.qTail)
last = TRUE;
/* Is this a cmd-period event. */
if ((eq_p->evtQWhat == keyDown
|| eq_p->evtQWhat == autoKey)
&& (eq_p->evtQModifiers & cmdKey)
&& (eq_p->evtQMessage & charCodeMask) == ‘.’)
{
/* Remove the event from the queue. */
Dequeue((QElemPtr) eq_p, &EventQueue);
f_found = TRUE;
/* Setup for disposal */
dispose_entry = TRUE;
/* Point to the beginning of entry. */
theEntry = (EvQElPtr) ((long) eq_p - 4);
}