From b425dda0a48b4a3e24a9f22d25e864d42679feee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Thu, 9 Aug 2007 21:35:28 +0000 Subject: [PATCH] * strlen holy war: loops. in loops it's very evil. the easy ones go away now. --- citadel/citserver.c | 7 +++- citadel/client_chat.c | 2 +- citadel/commands.c | 51 +++++++++++++----------- citadel/file_ops.c | 14 +++---- citadel/html.c | 10 ++--- citadel/internet_addressing.c | 9 +++-- citadel/modules/calendar/serv_calendar.c | 2 +- citadel/modules/imap/imap_fetch.c | 14 ++++--- citadel/modules/imap/imap_list.c | 6 +-- citadel/modules/imap/imap_misc.c | 2 +- citadel/modules/imap/imap_tools.c | 10 ++--- citadel/modules/ldap/serv_ldap.c | 9 +++-- citadel/modules/network/serv_network.c | 8 ++-- citadel/modules/notes/serv_notes.c | 3 +- citadel/modules/smtp/serv_smtp.c | 6 +-- citadel/modules/vandelay/serv_vandelay.c | 2 +- citadel/modules/vcard/serv_vcard.c | 8 ++-- citadel/msgbase.c | 10 ++--- citadel/room_ops.c | 1 - citadel/rooms.c | 4 +- citadel/routines.c | 15 +++---- citadel/routines2.c | 4 +- citadel/support.c | 16 ++++---- 23 files changed, 114 insertions(+), 99 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index c221d6aaf..6032caeaa 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -334,8 +334,11 @@ int is_public_client(void) fp = fopen(public_clients_file, "r"); if (fp != NULL) while (fgets(buf, sizeof buf, fp)!=NULL) { - for (i=0; i= (77 - strlen(fullname))) { pos = 0; - for (a = 0; a < strlen(wbuf); ++a) { + for (a = 0; !IsEmptyStr(&wbuf[a]); ++a) { if (wbuf[a] == 32) pos = a; } diff --git a/citadel/commands.c b/citadel/commands.c index 0a2042e3a..7ee8d5d2d 100644 --- a/citadel/commands.c +++ b/citadel/commands.c @@ -186,7 +186,7 @@ void pprintf(const char *format, ...) { vsnprintf(buf, sizeof(buf), format, arg_ptr); va_end(arg_ptr); - for (i=0; i' || strbuf[a+1] == '+' || strbuf[a+1] == '-'; + int noecho = *(ptr+1) == '<' || *(ptr+1) == '>' || + *(ptr+1) == '+' || *(ptr+1) == '-'; if (mode == 0) { - strcpy(&exp[a], &exp[a + 1 + noecho]); + strcpy(ptr, ptr + 1 + noecho); } if (mode == 1) { - exp[a] = '<'; - strcpy(buf, &exp[a + 2]); - exp[a + 2] = '>'; - exp[a + 3] = 0; + *ptr = '<'; + strcpy(buf, ptr + 2); + *(ptr + 2) = '>'; + *(ptr+ 3) = 0; strcat(exp, buf); } } - if (!strncmp(&exp[a], "^r", 2)) { + if (!strncmp(ptr, "^r", 2)) { strcpy(buf, exp); - strcpy(&exp[a], room_name); - strcat(exp, &buf[a + 2]); + strcpy(ptr, room_name); + strcat(exp, &buf[ptr - exp + 2]); } - if (!strncmp(&exp[a], "^c", 2)) { - exp[a] = ','; - strcpy(&exp[a + 1], &exp[a + 2]); + if (!strncmp(ptr, "^c", 2)) { + *ptr = ','; + strcpy(ptr + 1], ptr + 2]); } } @@ -1048,7 +1051,7 @@ int requires_string(struct citcmd *cptr, int ncomp) char buf[64]; strcpy(buf, cptr->c_keys[ncomp - 1]); - for (a = 0; a < strlen(buf); ++a) { + for (a = 0; !IsEmptyStr(&buf[a]); ++a) { if (buf[a] == ':') return (1); } @@ -1579,7 +1582,7 @@ void look_for_ansi(void) } } while (FD_ISSET(0, &rfds)); - for (a = 0; a < strlen(abuf); ++a) { + for (a = 0; !IsEmptyStr(&abuf[a]); ++a) { if ((abuf[a] == 27) && (abuf[a + 1] == '[') && (abuf[a + 2] == '?')) { enable_color = 1; @@ -1596,7 +1599,7 @@ void keyopt(char *buf) { int i; color(DIM_WHITE); - for (i=0; i') ) { - for (a=0; aroom, ctdl_image_dir); } else { - for (a = 0; a < strlen(filename); ++a) { + for (a = 0; !IsEmptyStr(&filename[0]); ++a) { filename[a] = tolower(filename[a]); if (filename[a] == '/') { filename[a] = '_'; @@ -485,7 +485,7 @@ void cmd_uopn(char *cmdbuf) return; } - for (a = 0; a < strlen(CC->upl_file); ++a) { + for (a = 0; !IsEmptyStr(&CC->upl_file[a]); ++a) { if (CC->upl_file[a] == '/') { CC->upl_file[a] = '_'; } @@ -544,7 +544,7 @@ void cmd_uimg(char *cmdbuf) strcpy(CC->upl_path, ""); - for (a = 0; a < strlen(basenm); ++a) { + for (a = 0; !IsEmptyStr(&basenm[a]); ++a) { basenm[a] = tolower(basenm[a]); if (basenm[a] == '/') { basenm[a] = '_'; diff --git a/citadel/html.c b/citadel/html.c index 1bb6cd4e2..afc97e964 100644 --- a/citadel/html.c +++ b/citadel/html.c @@ -100,7 +100,7 @@ char *html_to_ascii(char *inputmsg, int msglen, int screenwidth, int do_citaform if (!IsEmptyStr(inbuf)) { /* Fold in all the spacing */ - for (i=0; iusernum)) { return 0; } - - for (a=0; afullname); ++a) { + len = strlen(matchstring); + for (a=0; !IsEmptyStr(&us->fullname[a]); ++a) { if (!strncasecmp(&us->fullname[a], - matchstring, strlen(matchstring))) { + matchstring, len)) { return 0; } } @@ -552,7 +553,7 @@ void directory_key(char *key, char *addr) { int i; int keylen = 0; - for (i=0; iroom.QRname, config.c_fqdn); - for (i=0; icm_fields['R'], 256, "room_%s@%s", CC->room.QRname, config.c_fqdn); - for (i=0; icm_fields['R']); ++i) { + for (i=0; !IsEmptyStr(&msg->cm_fields['R'][i]); ++i) { if (isspace(msg->cm_fields['R'][i])) { msg->cm_fields['R'][i] = '_'; } @@ -702,7 +702,7 @@ void network_spool_msg(long msgnum, void *userdata) { snprintf(msg->cm_fields['F'], SIZ, "room_%s@%s", CC->room.QRname, config.c_fqdn); - for (i=0; icm_fields['F']); ++i) { + for (i=0; !IsEmptyStr(&msg->cm_fields['F'][i]); ++i) { if (isspace(msg->cm_fields['F'][i])) { msg->cm_fields['F'][i] = '_'; } @@ -973,7 +973,7 @@ void network_spoolout_room(char *room_to_spool) { /* If we wrote a digest, deliver it and then close it */ snprintf(buf, sizeof buf, "room_%s@%s", CC->room.QRname, config.c_fqdn); - for (i=0; i 0) { if (!strncasecmp(p, "X-KOrg-Note-Id: ", 16)) { /* Found it */ safestrncpy(uuid, p + 16, sizeof(uuid)); - for (i = 0; i') rp = i; } diff --git a/citadel/modules/vandelay/serv_vandelay.c b/citadel/modules/vandelay/serv_vandelay.c index 8380cec4d..a77eb4920 100644 --- a/citadel/modules/vandelay/serv_vandelay.c +++ b/citadel/modules/vandelay/serv_vandelay.c @@ -587,7 +587,7 @@ void artv_import_visit(void) { client_getln(buf, sizeof buf); vbuf.v_lastseen = atol(buf); - for (i=0; i='0') && (buf[c]<='9')) { b = strlen(tmpzip); tmpzip[b] = buf[c]; @@ -789,7 +789,7 @@ void vcard_newuser(struct ctdluser *usbuf) { v = vcard_new(); if (v == NULL) return; sprintf(buf, "%s@%s", usbuf->fullname, config.c_fqdn); - for (i=0; ifullname); @@ -1178,7 +1178,7 @@ struct vCard *vcard_new_from_rfc822_addr(char *addr) { vcard_set_prop(v, "email;internet", email, 0); snprintf(uid, sizeof uid, "collected: %s %s@%s", name, user, node); - for (i=0; icm_anon_type == MES_ANONOPT)) { cprintf("From: \"anonymous\" %s", nl); } - else if (strlen(fuser) > 0) { + else if (!IsEmptyStr(fuser)) { cprintf("From: \"%s\" <%s>%s", luser, fuser, nl); } else { @@ -2385,7 +2385,7 @@ long CtdlSubmitMsg(struct CtdlMessage *msg, /* message to save */ if (msg->cm_fields['P'] == NULL) { if (msg->cm_fields['A'] != NULL) { msg->cm_fields['P'] = strdup(msg->cm_fields['A']); - for (a=0; acm_fields['P']); ++a) { + for (a=0; !IsEmptyStr(&msg->cm_fields['P'][a]); ++a) { if (isspace(msg->cm_fields['P'][a])) { msg->cm_fields['P'][a] = ' '; } @@ -3140,7 +3140,7 @@ struct recptypes *validate_recipients(char *supplied_recipients) { ret->recptypes_magic = RECPTYPES_MAGIC; /* Change all valid separator characters to commas */ - for (i=0; iServInfo.moreprompt); ++a) + for (a=0; !IsEmptyStr(&ipc->ServInfo.moreprompt[0]); ++a) scr_putc(' '); scr_putc(13); stty_ctdl(1); @@ -345,10 +345,11 @@ int getstring(FILE *fp, char *string) /* Searches for patn in search string */ int pattern(char *search, char *patn) { - int a,b; - - for (a=0; a126) string[a]=32; } @@ -451,7 +452,7 @@ void locate_host(CtdlIPC* ipc, char *hbuf) pclose(who); b = 0; - for (a=0; a') || (flnm[a] == '?') || (flnm[a] == '*') || (flnm[a] == ';') || (flnm[a] == '&')) @@ -592,7 +592,7 @@ void list_bio(CtdlIPC *ipc) pprintf("%s\n", buf); return; } - while (resp && strlen(resp)) { + while (resp && !IsEmptyStr(resp)) { extract_token(buf, resp, 0, '\n', sizeof buf); remove_token(resp, 0, '\n'); if ((pos + strlen(buf) + 5) > screenwidth) { diff --git a/citadel/support.c b/citadel/support.c index b88ee9913..a3ebffc19 100644 --- a/citadel/support.c +++ b/citadel/support.c @@ -29,7 +29,7 @@ void strproc(char *string) if (IsEmptyStr(string)) return; /* Convert non-printable characters to blanks */ - for (a=0; a126) string[a]=32; } @@ -41,7 +41,7 @@ void strproc(char *string) string[strlen(string)-1]=0; /* Remove double blanks */ - for (a=0; a