From: Ralph Corderoy Date: Mon, 4 Sep 2017 09:07:35 +0000 (+0100) Subject: Replace FALSE and TRUE with C99's false and true. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/c08cb60fe34b42b0a83bc88b57fd41b07793863f?ds=inline Replace FALSE and TRUE with C99's false and true. Remove the duplicate definitions of FALSE and TRUE. Change a few variables from int to bool at the same time. The semantics of bool are different to int because `bool b = 42' maps 42 to 1, but if the code was relying on that then it needs shaking out anyway. --- diff --git a/h/crawl_folders.h b/h/crawl_folders.h index dac08f8b..f5d29cb8 100644 --- a/h/crawl_folders.h +++ b/h/crawl_folders.h @@ -3,7 +3,7 @@ #define CRAWL_NUMFOLDERS 100 -/* Callbacks return TRUE crawl_folders should crawl the children of `folder'. +/* Callbacks return true crawl_folders should crawl the children of `folder'. * Callbacks need not duplicate folder, as crawl_folders does not free it. */ typedef bool (crawl_callback_t)(char *folder, void *baton); diff --git a/h/mf.h b/h/mf.h index b0301237..6b17a4c0 100644 --- a/h/mf.h +++ b/h/mf.h @@ -3,14 +3,6 @@ #include -#ifndef TRUE -# define TRUE 1 -#endif - -#ifndef FALSE -# define FALSE 0 -#endif - #ifndef NOTOK # define NOTOK (-1) #endif diff --git a/h/mh.h b/h/mh.h index 8823d919..069d9cbe 100644 --- a/h/mh.h +++ b/h/mh.h @@ -22,13 +22,6 @@ */ #define NMH_BUFSIZ max(BUFSIZ, 8192) -#ifndef FALSE -#define FALSE false -#endif -#ifndef TRUE -#define TRUE true -#endif - /* If we're using gcc then tell it extra information so it can do more * compile-time checks. */ #if __GNUC__ > 2 diff --git a/h/oauth.h b/h/oauth.h index 3d5826d9..e6873df4 100644 --- a/h/oauth.h +++ b/h/oauth.h @@ -128,7 +128,7 @@ mh_oauth_do_xoauth(const char *user, const char *svc, unsigned char **oauth_res, * * Accesses global m_defs via context_find. * - * On error, return FALSE and set an error in ctx; ctx is always allocated. + * On error, return false and set an error in ctx; ctx is always allocated. */ bool mh_oauth_new(mh_oauth_ctx **ctx, const char *svc_name); @@ -196,7 +196,7 @@ mh_oauth_authorize(const char *code, mh_oauth_ctx *ctx); /* * Refresh access (and maybe refresh) token if refresh token present. * - * On error, return FALSE and leave cred untouched. + * On error, return false and leave cred untouched. */ bool mh_oauth_refresh(mh_oauth_cred *cred); @@ -226,7 +226,7 @@ mh_oauth_cred_fn(const char *svc_name); /* * Serialize OAuth tokens to file. * - * On error, return FALSE. + * On error, return false. */ bool mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred, const char *user); diff --git a/mts/smtp/smtp.c b/mts/smtp/smtp.c index 2f32877c..3d2a8e5b 100644 --- a/mts/smtp/smtp.c +++ b/mts/smtp/smtp.c @@ -38,7 +38,7 @@ static int sm_addrs = 0; static int sm_child = NOTOK; static int sm_debug = 0; -static int sm_nl = TRUE; +static bool sm_nl = true; static int sm_verbose = 0; static netsec_context *nsc = NULL; @@ -92,7 +92,7 @@ smtp_init (char *client, char *server, char *port, int watch, int verbose, char *errstr, *chosen_server; if (watch) - verbose = TRUE; + verbose = true; sm_verbose = verbose; sm_debug = debug; @@ -263,7 +263,7 @@ sendmail_init (char *client, int watch, int verbose, int debug, int sasl, char *vec[15], *errstr; if (watch) - verbose = TRUE; + verbose = true; sm_verbose = verbose; sm_debug = debug; @@ -509,7 +509,7 @@ sm_waend (void) { switch (smtalk (SM_DATA, "DATA")) { case 354: - sm_nl = TRUE; + sm_nl = true; return RP_OK; case 451: @@ -720,7 +720,7 @@ sm_wstream (char *buffer, int len) for (bp = buffer; bp && len > 0; bp++, len--) { switch (*bp) { case '\n': - sm_nl = TRUE; + sm_nl = true; if (netsec_write(nsc, "\r", 1, &errstr) != OK) { sm_nerror(errstr); return NOTOK; @@ -736,7 +736,7 @@ sm_wstream (char *buffer, int len) /* FALLTHRU */ default: - sm_nl = FALSE; + sm_nl = false; } if (netsec_write(nsc, bp, 1, &errstr) != OK) { sm_nerror(errstr); @@ -753,7 +753,8 @@ sm_wstream (char *buffer, int len) static int smhear (void) { - int i, code, cont, more; + int i, code; + bool cont, more; size_t buflen, rc; unsigned char *bp; char *rp; @@ -785,7 +786,7 @@ again: ; rp = sm_reply.text; rc = sizeof(sm_reply.text) - 1; - for (more = FALSE; (buffer = netsec_readline(nsc, &buflen, + for (more = false; (buffer = netsec_readline(nsc, &buflen, &errstr)) != NULL ; ) { if (doingEHLO @@ -811,13 +812,13 @@ again: ; for (; buflen > 0 && (!isascii (*bp) || !isdigit (*bp)); bp++, buflen--) continue; - cont = FALSE; + cont = false; code = atoi ((char *) bp); bp += 3, buflen -= 3; for (; buflen > 0 && isspace (*bp); bp++, buflen--) continue; if (buflen > 0 && *bp == '-') { - cont = TRUE; + cont = true; bp++, buflen--; for (; buflen > 0 && isspace (*bp); bp++, buflen--) continue; @@ -826,7 +827,7 @@ again: ; if (more) { if (code != sm_reply.code || cont) continue; - more = FALSE; + more = false; } else { sm_reply.code = code; more = cont; diff --git a/sbr/m_getfld.c b/sbr/m_getfld.c index eb377411..f5fa9a4e 100644 --- a/sbr/m_getfld.c +++ b/sbr/m_getfld.c @@ -94,7 +94,7 @@ To speed things up considerably, the routine Eom() was made an auxiliary function called by the macro eom(). Unless we are bursting a maildrop, - the eom() macro returns FALSE saying we aren't at the end of the + the eom() macro returns false saying we aren't at the end of the message. The next thing to do is to read the mts.conf file and initialize diff --git a/sbr/oauth.c b/sbr/oauth.c index a792729f..3aeeccbe 100755 --- a/sbr/oauth.c +++ b/sbr/oauth.c @@ -263,13 +263,13 @@ mh_oauth_new(mh_oauth_ctx **result, const char *svc_name) if (!mh_oauth_get_service_info(svc_name, &ctx->svc, ctx->err_buf, sizeof(ctx->err_buf))) { set_err_details(ctx, MH_OAUTH_BAD_PROFILE, ctx->err_buf); - return FALSE; + return false; } ctx->curl = curl_easy_init(); if (ctx->curl == NULL) { set_err(ctx, MH_OAUTH_CURL_INIT); - return FALSE; + return false; } curl_easy_setopt(ctx->curl, CURLOPT_ERRORBUFFER, ctx->err_buf); @@ -278,10 +278,10 @@ mh_oauth_new(mh_oauth_ctx **result, const char *svc_name) if (curl_easy_setopt(ctx->curl, CURLOPT_USERAGENT, ctx->user_agent) != CURLE_OK) { set_err_details(ctx, MH_OAUTH_CURL_INIT, ctx->err_buf); - return FALSE; + return false; } - return TRUE; + return true; } void @@ -397,12 +397,12 @@ static bool cred_from_response(mh_oauth_cred *cred, const char *content_type, const char *input, size_t input_len) { - bool result = FALSE; + bool result = false; char *access_token, *expires_in, *refresh_token; const mh_oauth_ctx *ctx = cred->ctx; if (!is_json(content_type)) { - return FALSE; + return false; } access_token = expires_in = refresh_token = NULL; @@ -421,7 +421,7 @@ cred_from_response(mh_oauth_cred *cred, const char *content_type, } } - result = TRUE; + result = true; free(cred->access_token); cred->access_token = access_token; @@ -470,21 +470,21 @@ do_access_request(mh_oauth_cred *cred, const char *req_body) } else { set_err_details(ctx, MH_OAUTH_POST, ctx->err_buf); } - return FALSE; + return false; } if (curl_ctx.res_code != 200) { set_err_http(ctx, &curl_ctx); - return FALSE; + return false; } if (!cred_from_response(cred, curl_ctx.content_type, curl_ctx.res_body, curl_ctx.res_len)) { set_err(ctx, MH_OAUTH_RESPONSE_BAD); - return FALSE; + return false; } - return TRUE; + return true; } mh_oauth_cred * @@ -523,7 +523,7 @@ mh_oauth_refresh(mh_oauth_cred *cred) if (cred->refresh_token == NULL) { set_err(ctx, MH_OAUTH_NO_REFRESH); - return FALSE; + return false; } if (!make_query_url(ctx->buf, sizeof ctx->buf, ctx->curl, NULL, @@ -533,14 +533,14 @@ mh_oauth_refresh(mh_oauth_cred *cred) "client_secret", ctx->svc.client_secret, (void *)NULL)) { set_err(ctx, MH_OAUTH_REQUEST_INIT); - return FALSE; + return false; } result = do_access_request(cred, ctx->buf); if (result && cred->access_token == NULL) { set_err_details(ctx, MH_OAUTH_RESPONSE_BAD, "no access token"); - return FALSE; + return false; } return result; @@ -613,7 +613,7 @@ free_user_creds(struct user_creds *user_creds) static bool load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) { - bool success = FALSE; + bool success = false; char name[NAMESZ], value_buf[BUFSIZ]; int state; m_getfld_state_t getfld_ctx; @@ -681,7 +681,7 @@ load_creds(struct user_creds **result, FILE *fp, mh_oauth_ctx *ctx) case BODY: case FILEEOF: - success = TRUE; + success = true; break; default: @@ -708,17 +708,17 @@ save_user(FILE *fp, const char *user, const char *access, const char *refresh, long expires_at) { if (access != NULL) { - if (fprintf(fp, "access-%s: %s\n", user, access) < 0) return FALSE; + if (fprintf(fp, "access-%s: %s\n", user, access) < 0) return false; } if (refresh != NULL) { - if (fprintf(fp, "refresh-%s: %s\n", user, refresh) < 0) return FALSE; + if (fprintf(fp, "refresh-%s: %s\n", user, refresh) < 0) return false; } if (expires_at > 0) { if (fprintf(fp, "expire-%s: %ld\n", user, (long)expires_at) < 0) { - return FALSE; + return false; } } - return TRUE; + return true; } bool @@ -730,7 +730,7 @@ mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred, const char *user) /* Load existing creds if any. */ if (!load_creds(&user_creds, fp, cred->ctx)) { - return FALSE; + return false; } if (fchmod(fd, S_IRUSR | S_IWUSR) < 0) goto err; @@ -755,12 +755,12 @@ mh_oauth_cred_save(FILE *fp, mh_oauth_cred *cred, const char *user) free_user_creds(user_creds); - return TRUE; + return true; err: free_user_creds(user_creds); set_err(cred->ctx, MH_OAUTH_CRED_FILE); - return FALSE; + return false; } mh_oauth_cred * @@ -827,14 +827,14 @@ mh_oauth_sasl_client_response(size_t *res_len, /* * Build null-terminated URL in the array pointed to by s. If the URL doesn't - * fit within size (including the terminating null byte), return FALSE without * + * fit within size (including the terminating null byte), return false without * * building the entire URL. Some of URL may already have been written into the * result array in that case. */ static bool make_query_url(char *s, size_t size, CURL *curl, const char *base_url, ...) { - bool result = FALSE; + bool result = false; size_t len; char *prefix; va_list ap; @@ -846,7 +846,7 @@ make_query_url(char *s, size_t size, CURL *curl, const char *base_url, ...) } else { len = strlen(base_url); if (len > size - 1) /* Less one for NUL. */ - return FALSE; + return false; strcpy(s, base_url); prefix = "?"; } @@ -873,7 +873,7 @@ make_query_url(char *s, size_t size, CURL *curl, const char *base_url, ...) prefix = "&"; } - result = TRUE; + result = true; out: va_end(ap); @@ -920,7 +920,7 @@ write_callback(const char *ptr, size_t size, size_t nmemb, void *userdata) size *= nmemb; new_len = ctx->res_len + size; if (new_len > sizeof ctx->res_body) { - ctx->too_big = TRUE; + ctx->too_big = true; return 0; } @@ -936,7 +936,7 @@ post(struct curl_ctx *ctx, const char *url, const char *req_body) CURL *curl = ctx->curl; CURLcode status; - ctx->too_big = FALSE; + ctx->too_big = false; ctx->res_len = 0; if (ctx->log != NULL) { @@ -946,7 +946,7 @@ post(struct curl_ctx *ctx, const char *url, const char *req_body) } if ((status = curl_easy_setopt(curl, CURLOPT_URL, url)) != CURLE_OK) { - return FALSE; + return false; } curl_easy_setopt(curl, CURLOPT_POSTFIELDS, req_body); @@ -964,21 +964,21 @@ post(struct curl_ctx *ctx, const char *url, const char *req_body) status = curl_easy_perform(curl); /* first check for error from callback */ if (ctx->too_big) { - return FALSE; + return false; } /* now from curl */ if (status != CURLE_OK) { - return FALSE; + return false; } if ((status = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &ctx->res_code)) != CURLE_OK || (status = curl_easy_getinfo(curl, CURLINFO_CONTENT_TYPE, &ctx->content_type)) != CURLE_OK) { - return FALSE; + return false; } - return TRUE; + return true; } /******************************************************************************* @@ -1020,10 +1020,10 @@ parse_json(jsmntok_t **tokens, size_t *tokens_len, *tokens = mh_xrealloc(*tokens, *tokens_len * sizeof **tokens); } if (r <= 0) { - return FALSE; + return false; } - return TRUE; + return true; } /* @@ -1043,7 +1043,7 @@ get_json_string(char **val, const char *input, const jsmntok_t *tokens, int skip_tokens = 0; /* whether the current token represents a field name */ /* The next token will be the value. */ - bool is_key = TRUE; + bool is_key = true; int i; for (i = 1; i <= token_count; i++) { @@ -1069,11 +1069,11 @@ get_json_string(char **val, const char *input, const jsmntok_t *tokens, if (skip_tokens > 0) { skip_tokens--; /* When we finish with the object or list, we'll have a key. */ - is_key = TRUE; + is_key = true; continue; } if (is_key) { - is_key = FALSE; + is_key = false; continue; } key = input + tokens[i - 1].start; @@ -1085,7 +1085,7 @@ get_json_string(char **val, const char *input, const jsmntok_t *tokens, (*val)[val_len] = '\0'; return; } - is_key = TRUE; + is_key = true; } } @@ -1109,7 +1109,7 @@ get_json_string(char **val, const char *input, const jsmntok_t *tokens, static bool get_json_strings(const char *input, size_t input_len, FILE *log, ...) { - bool result = FALSE; + bool result = false; jsmntok_t *tokens; size_t tokens_len; va_list ap; @@ -1123,7 +1123,7 @@ get_json_strings(const char *input, size_t input_len, FILE *log, ...) goto out; } - result = TRUE; + result = true; va_start(ap, log); for (name = va_arg(ap, char *); name != NULL; name = va_arg(ap, char *)) { diff --git a/sbr/oauth_prof.c b/sbr/oauth_prof.c index 1da1eb3f..26132fa2 100644 --- a/sbr/oauth_prof.c +++ b/sbr/oauth_prof.c @@ -85,7 +85,7 @@ update_svc(mh_oauth_service_info *svc, const char *svc_name, char *errbuf, if (svc->name == NULL) { \ snprintf(errbuf, errbuflen, "%s", #name " is missing"); \ errbuf[errbuflen - 1] = '\0'; \ - return FALSE; \ + return false; \ } update(scope); update(client_id); @@ -103,7 +103,7 @@ update_svc(mh_oauth_service_info *svc, const char *svc_name, char *errbuf, svc->display_name = svc->name; } - return TRUE; + return true; } bool @@ -125,10 +125,10 @@ mh_oauth_get_service_info(const char *svc_name, mh_oauth_service_info *svcinfo, } if (!update_svc(svcinfo, svc_name, errbuf, errbuflen)) { - return FALSE; + return false; } - return TRUE; + return true; } const char * diff --git a/sbr/print_help.c b/sbr/print_help.c index 0fca1db7..9a022582 100644 --- a/sbr/print_help.c +++ b/sbr/print_help.c @@ -30,7 +30,7 @@ print_help (char *str, struct swit *swp, int print_context) /* and for further info */ putchar('\n'); - print_intro (stdout, TRUE); + print_intro (stdout, true); puts ("\nSee the BUGS section of the nmh(7) man page for more information."); } diff --git a/uip/flist.c b/uip/flist.c index 03fd5c0e..cd505043 100644 --- a/uip/flist.c +++ b/uip/flist.c @@ -158,41 +158,41 @@ main(int argc, char **argv) break; case ALLSW: - all = TRUE; + all = true; break; case NOALLSW: - all = FALSE; + all = false; break; case SHOWZERO: - showzero = TRUE; + showzero = true; break; case NOSHOWZERO: - showzero = FALSE; + showzero = false; break; case ALPHASW: - alphaOrder = TRUE; + alphaOrder = true; break; case NOALPHASW: - alphaOrder = FALSE; + alphaOrder = false; break; case NOFASTSW: case TOTALSW: - Total = TRUE; + Total = true; break; case FASTSW: case NOTOTALSW: - Total = FALSE; + Total = false; break; case RECURSE: - recurse = TRUE; + recurse = true; break; case NORECURSE: - recurse = FALSE; + recurse = false; break; } } else { diff --git a/uip/folder.c b/uip/folder.c index f21ddcab..84d0de53 100644 --- a/uip/folder.c +++ b/uip/folder.c @@ -406,7 +406,7 @@ get_folder_info_body (char *fold, char *msg, bool *crawl_children) */ if (!(mp = folder_read (fold, fpack))) { inform("unable to read folder %s, continuing...", fold); - *crawl_children = FALSE; + *crawl_children = false; return 0; } @@ -416,7 +416,7 @@ get_folder_info_body (char *fold, char *msg, bool *crawl_children) if (fpack) { if (folder_pack (&mp, fverb) == -1) { - *crawl_children = FALSE; /* to please clang static analyzer */ + *crawl_children = false; /* to please clang static analyzer */ done (1); } seq_save (mp); /* synchronize the sequences */ diff --git a/uip/install-mh.c b/uip/install-mh.c index b9c69f54..ff663575 100644 --- a/uip/install-mh.c +++ b/uip/install-mh.c @@ -216,7 +216,7 @@ query: fclose (out); puts ("\nPlease see the nmh(7) man page for an introduction to nmh.\n"); - print_intro (stdout, FALSE); + print_intro (stdout, false); /* Initialize the saved nmh version. The Path profile entry was added above, that's all this needs. */ diff --git a/uip/new.c b/uip/new.c index 137f2bcb..a787806d 100644 --- a/uip/new.c +++ b/uip/new.c @@ -75,7 +75,7 @@ count_messages(char *field) return total; } -/* Return TRUE if the sequence 'name' is in 'sequences'. */ +/* Return true if the sequence 'name' is in 'sequences'. */ static bool seq_in_list(char *name, char *sequences[]) { @@ -83,11 +83,11 @@ seq_in_list(char *name, char *sequences[]) for (i = 0; sequences[i] != NULL; i++) { if (strcmp(name, sequences[i]) == 0) { - return TRUE; + return true; } } - return FALSE; + return false; } /* Return the string list of message numbers from the sequences file, or NULL @@ -229,7 +229,7 @@ static bool crawl_callback(char *folder, void *baton) { check_folder(folder, strlen(folder), baton); - return TRUE; + return true; } /* Scan folders, returning: