Refactor some code.

This commit is contained in:
Dianne Skoll
2024-03-16 14:01:21 -04:00
parent 61f55bceee
commit 29c579a301

View File

@@ -153,14 +153,14 @@ static char const *QueueFilename(char const *fname)
return elem->fname; return elem->fname;
} }
static void del_reminder(unsigned long qid) static void del_reminder(QueuedRem *qid)
{ {
QueuedRem *q = QueueHead; QueuedRem *q = QueueHead;
QueuedRem *next; QueuedRem *next;
if (!q) { if (!q) {
return; return;
} }
if ((unsigned long) q == qid) { if (q == qid) {
QueueHead = q->next; QueueHead = q->next;
if (q->text) free((void *) q->text); if (q->text) free((void *) q->text);
free(q); free(q);
@@ -168,7 +168,7 @@ static void del_reminder(unsigned long qid)
} }
while(q->next) { while(q->next) {
next = q->next; next = q->next;
if ((unsigned long) q->next == qid) { if (q->next == qid) {
q->next = q->next->next; q->next = q->next->next;
if (next->text) free((void *) next->text); if (next->text) free((void *) next->text);
free(next); free(next);
@@ -178,6 +178,10 @@ static void del_reminder(unsigned long qid)
} }
} }
static void del_reminder_ul(unsigned long qid) {
del_reminder((QueuedRem *) qid);
}
/***************************************************************/ /***************************************************************/
/* */ /* */
/* QueueReminder */ /* QueueReminder */
@@ -502,7 +506,7 @@ void HandleQueuedReminders(void)
/* If queued reminder has expired, actually remove it from queue /* If queued reminder has expired, actually remove it from queue
and update status */ and update status */
if (q->tt.nexttime == NO_TIME) { if (q->tt.nexttime == NO_TIME) {
del_reminder((unsigned long) q); del_reminder(q);
if (IsServerMode()) { if (IsServerMode()) {
print_num_queued(); print_num_queued();
} }
@@ -887,7 +891,7 @@ static void DaemonWait(struct timeval *sleep_tv)
} else if (!strncmp(cmdLine, "DEL ", 4)) { } else if (!strncmp(cmdLine, "DEL ", 4)) {
unsigned long qid; unsigned long qid;
if (sscanf(cmdLine, "DEL %lx", &qid) == 1) { if (sscanf(cmdLine, "DEL %lx", &qid) == 1) {
del_reminder(qid); del_reminder_ul(qid);
} }
print_num_queued(); print_num_queued();
fflush(stdout); fflush(stdout);