From 9ebd728e9b5119c8968c9a6b553fcf7f2df50fa2 Mon Sep 17 00:00:00 2001 From: Michael Hampton Date: Mon, 23 Oct 2000 20:26:51 +0000 Subject: [PATCH] * War on goto: rewrote a few easy functions to eliminate unnecessary gotos --- citadel/ChangeLog | 4 ++- citadel/serv_chat.c | 7 +---- citadel/serv_expire.c | 61 ++++++++++++++++++++--------------------- citadel/serv_vandelay.c | 5 ++-- 4 files changed, 36 insertions(+), 41 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index 16090e6da..9cec42607 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -1,4 +1,7 @@ $Log$ + Revision 573.14 2000/10/23 20:26:51 error + * War on goto: rewrote a few easy functions to eliminate unnecessary gotos + Revision 573.13 2000/10/11 23:03:44 error * utilsmenu: obey $PAGER environment var, if any. Default to more if neither $PAGER nor less is available. @@ -2097,4 +2100,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant Fri Jul 10 1998 Art Cancro * Initial CVS import - diff --git a/citadel/serv_chat.c b/citadel/serv_chat.c index 326d12355..3d3419459 100644 --- a/citadel/serv_chat.c +++ b/citadel/serv_chat.c @@ -98,16 +98,11 @@ void allwrite(char *cmdbuf, int flag, char *username) } /* Then, before releasing the lock, free the expired messages */ - while (1) { - if (ChatQueue == NULL) - goto DONE_FREEING; - if ((now - ChatQueue->chat_time) < 120L) - goto DONE_FREEING; + while ((ChatQueue != NULL) && (now - ChatQueue->chat_time >= 120L)) { clptr = ChatQueue; ChatQueue = ChatQueue->next; phree(clptr); } -DONE_FREEING: end_critical_section(S_CHATQUEUE); } diff --git a/citadel/serv_expire.c b/citadel/serv_expire.c index 6cf08d77c..d66970b52 100644 --- a/citadel/serv_expire.c +++ b/citadel/serv_expire.c @@ -112,7 +112,7 @@ void DoPurgeMessages(struct quickroom *qrbuf, void *data) { time(&now); GetExpirePolicy(&epbuf, qrbuf); - + /* If the room is set to never expire messages ... do nothing */ if (epbuf.expire_mode == EXPIRE_NEXTLEVEL) return; if (epbuf.expire_mode == EXPIRE_MANUAL) return; @@ -126,7 +126,7 @@ void DoPurgeMessages(struct quickroom *qrbuf, void *data) { num_msgs = cdbfr->len / sizeof(long); cdb_free(cdbfr); } - + /* Nothing to do if there aren't any messages */ if (num_msgs == 0) { end_critical_section(S_QUICKROOM); @@ -172,7 +172,7 @@ void DoPurgeMessages(struct quickroom *qrbuf, void *data) { if (num_msgs > 0) { num_msgs = sort_msglist(msglist, num_msgs); } - + cdb_store(CDB_MSGLISTS, &qrbuf->QRnumber, sizeof(long), msglist, (num_msgs * sizeof(long)) ); @@ -218,38 +218,37 @@ void DoPurgeRooms(struct quickroom *qrbuf, void *data) { * it. Bypass any other rules. */ if (qrbuf->QRflags & QR_MAILBOX) { + /* if user not found, do_purge will be 1 */ + do_purge = 1; for (vuptr=ValidUserList; vuptr!=NULL; vuptr=vuptr->next) { if (vuptr->vu_usernum == atol(qrbuf->QRname)) { do_purge = 0; - goto BYPASS; } } - /* user not found */ - do_purge = 1; - goto BYPASS; } - - /* Any of these attributes render a room non-purgable */ - if (qrbuf->QRflags & QR_PERMANENT) return; - if (qrbuf->QRflags & QR_DIRECTORY) return; - if (qrbuf->QRflags & QR_NETWORK) return; - if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return; - if (is_noneditable(qrbuf)) return; - - /* If we don't know the modification date, be safe and don't purge */ - if (qrbuf->QRmtime <= (time_t)0) return; - - /* If no room purge time is set, be safe and don't purge */ - if (config.c_roompurge < 0) return; - - /* Otherwise, check the date of last modification */ - age = time(NULL) - (qrbuf->QRmtime); - purge_secs = (time_t)config.c_roompurge * (time_t)86400; - if (purge_secs <= (time_t)0) return; - lprintf(9, "<%s> is <%ld> seconds old\n", qrbuf->QRname, age); - if (age > purge_secs) do_purge = 1; - -BYPASS: if (do_purge) { + else { + /* Any of these attributes render a room non-purgable */ + if (qrbuf->QRflags & QR_PERMANENT) return; + if (qrbuf->QRflags & QR_DIRECTORY) return; + if (qrbuf->QRflags & QR_NETWORK) return; + if (!strcasecmp(qrbuf->QRname, SYSCONFIGROOM)) return; + if (is_noneditable(qrbuf)) return; + + /* If we don't know the modification date, be safe and don't purge */ + if (qrbuf->QRmtime <= (time_t)0) return; + + /* If no room purge time is set, be safe and don't purge */ + if (config.c_roompurge < 0) return; + + /* Otherwise, check the date of last modification */ + age = time(NULL) - (qrbuf->QRmtime); + purge_secs = (time_t)config.c_roompurge * (time_t)86400; + if (purge_secs <= (time_t)0) return; + lprintf(9, "<%s> is <%ld> seconds old\n", qrbuf->QRname, age); + if (age > purge_secs) do_purge = 1; + } /* !QR_MAILBOX */ + + if (do_purge) { pptr = (struct PurgeList *) mallok(sizeof(struct PurgeList)); pptr->next = RoomPurgeList; strcpy(pptr->name, qrbuf->QRname); @@ -257,7 +256,7 @@ BYPASS: if (do_purge) { } } - + int PurgeRooms(void) { @@ -489,7 +488,7 @@ int PurgeVisits(void) { VisitPurgeList = vptr; ++purged; } - + return(purged); } diff --git a/citadel/serv_vandelay.c b/citadel/serv_vandelay.c index 29ee4ecd3..d6d90cf9d 100644 --- a/citadel/serv_vandelay.c +++ b/citadel/serv_vandelay.c @@ -503,7 +503,7 @@ void artv_do_import(void) { version = atoi(s_version); if ((version < REV_MIN) || (version > REV_LEVEL)) { lprintf(7, "Version mismatch - aborting\n"); - goto artv_flush_import; + break; } } else if (!strcasecmp(buf, "config")) artv_import_config(); @@ -513,9 +513,8 @@ void artv_do_import(void) { else if (!strcasecmp(buf, "floor")) artv_import_floor(); else if (!strcasecmp(buf, "visit")) artv_import_visit(); else if (!strcasecmp(buf, "message")) artv_import_message(); - else goto artv_flush_import; + else break; } -artv_flush_import: lprintf(7, "Invalid keyword <%s>. Flushing input.\n", buf); while (client_gets(buf), strcmp(buf, "000")) ;; } -- 2.39.2