argsplit(char *command, char **file, int *argp)
{
char **argvarray, *p;
- int space = 0, metachar = 0, i;
+ int i;
+ bool space = false;
+ bool metachar = false;
for (p = command; *p; p++) {
if (*p == ' ' || *p == '\t') {
- space = 1;
+ space = true;
} else if (strchr(METACHARS, *p)) {
- metachar = 1;
+ metachar = true;
break;
}
}
{
unsigned int cc, n;
unsigned char inbuf[3];
- int skipnl = 0;
+ bool skipnl = false;
n = BPERLIN;
while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) {
unsigned long bits;
inbuf[cc++] = '\n';
else
ungetc('\n', in);
- skipnl = 1;
+ skipnl = true;
} else {
/* This only works as long as sizeof(inbuf) == 3 */
ungetc(inbuf[cc - 1], in);
inbuf[++i] = '\n';
}
} else {
- skipnl = 0;
+ skipnl = false;
}
}
}
decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
int skip_crs, unsigned char *digest) {
const char *cp = encoded;
- int self_delimiting = 0;
int bitno, skip;
uint32_t bits;
/* Size the decoded string very conservatively. */
bits = 0L;
skip = 0;
+ bool self_delimiting = false;
for (; *cp; ++cp) {
switch (*cp) {
unsigned char value;
case '=':
if (++skip <= 3)
goto test_end;
- self_delimiting = 1;
+ self_delimiting = true;
break;
}
}
field_encode_quoted(const char *name, char **value, const char *charset,
int ascii, int encoded, int phraserules)
{
- int prefixlen = name ? strlen(name) + 2: 0, outlen = 0, column, newline = 1;
+ int prefixlen = name ? strlen(name) + 2: 0, outlen = 0, column;
int charsetlen = strlen(charset), utf8;
char *output = NULL, *p, *q = NULL;
utf8 = strcasecmp(charset, "UTF-8") == 0;
+ bool newline = true;
while (*p != '\0') {
/*
* Start a new line, if it's time
tokenlen = snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
q += tokenlen;
column = prefixlen + tokenlen;
- newline = 0;
+ newline = false;
}
/*
continue;
if (column >= ENCODELINELIMIT - 2) {
- newline = 1;
+ newline = true;
} else if (utf8) {
/*
* Okay, this is a bit weird, but to explain a bit more ...
* allow for the encoded output.
*/
if (column + (utf8len(p) * 3) > ENCODELINELIMIT - 2) {
- newline = 1;
+ newline = true;
}
}
}
int vecp; /* Vector index */
char *program; /* Name of program to execute */
- static int did_message = 0; /* set if we've already output a message */
+ static bool did_message; /* set if we've already output a message */
if ((hook = context_find(hook_name)) == NULL)
return OK;
if (status == OK)
return OK;
- if (did_message == 0) {
+ if (!did_message) {
char *msghook;
if ((msghook = context_find("msg-hook")) != NULL)
inform("%s", msghook);
snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
pidstatus(status, stderr, errbuf);
}
- did_message = 1;
+ did_message = true;
}
return NOTOK;
int
fdcompare (int fd1, int fd2)
{
- int i, n1, n2, resp;
+ int i, n1, n2;
char *c1, *c2;
char b1[BUFSIZ], b2[BUFSIZ];
- resp = 1;
+ bool resp = true;
while ((n1 = read (fd1, b1, sizeof(b1))) >= 0
&& (n2 = read (fd2, b2, sizeof(b2))) >= 0
&& n1 == n2) {
c2 = b2;
for (i = n1 < (int) sizeof(b1) ? n1 : (int) sizeof(b1); i--;)
if (*c1++ != *c2++) {
- resp = 0;
+ resp = false;
goto leave;
}
if (n1 < (int) sizeof(b1))
goto leave;
}
- resp = 0;
+ resp = false;
leave: ;
lseek(fd1, 0, SEEK_SET);
{
char *cp;
size_t i;
- static int comptable_initialized = 0;
+ static bool comptable_initialized;
format_string = mh_xstrdup(fstring);
usr_fstring = fstring;
if (reset_comptable || !comptable_initialized) {
free_comptable();
- comptable_initialized = 1;
+ comptable_initialized = true;
}
/* it takes at least 4 char to generate one format so we
char *startofmime, *endofmime, *endofcharset;
int c, quoted_printable;
int encoding_found = 0; /* did we decode anything? */
- int between_encodings = 0; /* are we between two encodings? */
- int equals_pending = 0; /* is there a '=' pending? */
int whitespace = 0; /* how much whitespace between encodings? */
#ifdef HAVE_ICONV
- int use_iconv = 0; /* are we converting encoding with iconv? */
iconv_t cd = NULL;
int fromutf8 = 0;
char *saveq, *convbuf = NULL;
if (!strchr (str, '='))
return 0;
+ bool use_iconv = false; /* are we converting encoding with iconv? */
+ bool between_encodings = false;
+ bool equals_pending = false;
for (p = str, q = dst; *p; p++) {
/* reset iconv */
#ifdef HAVE_ICONV
if (use_iconv) {
iconv_close(cd);
- use_iconv = 0;
+ use_iconv = false;
}
#endif
/*
*/
if (equals_pending) {
ADDCHR('=');
- equals_pending = 0;
- between_encodings = 0; /* we have added non-whitespace text */
+ equals_pending = false;
+ between_encodings = false; /* we have added non-whitespace text */
}
if (*p != '=') {
if (between_encodings && is_lws(*p))
whitespace++;
else
- between_encodings = 0; /* we have added non-whitespace text */
+ between_encodings = false; /* we have added non-whitespace text */
ADDCHR(*p);
continue;
}
- equals_pending = 1; /* we have a '=' pending */
+ equals_pending = true;
/* Check for initial =? */
if (*p == '=' && p[1] == '?' && p[2]) {
fromutf8 = !strcasecmp(startofmime, "UTF-8");
*pp = '?';
if (cd == (iconv_t)-1) continue;
- use_iconv = 1;
+ use_iconv = true;
#else
continue;
#endif
* We've found an encoded word, so we can drop
* the '=' that was pending
*/
- equals_pending = 0;
+ equals_pending = false;
/*
* If we are between two encoded words separated only by
* malloc 0 bytes but skip on to the end
*/
if (endofmime == startofmime && use_iconv) {
- use_iconv = 0;
+ use_iconv = false;
iconv_close(cd);
}
p = endofmime + 1;
encoding_found = 1; /* we found (at least 1) encoded word */
- between_encodings = 1; /* we have just decoded something */
+ between_encodings = true; /* we have just decoded something */
whitespace = 0; /* re-initialize amount of whitespace */
}
}
char *altstr = NULL;
#endif
char *sp; /* current position in source string */
- int prevCtrl = 1;
/* get alignment */
rjust = 0;
trimmed = rjust ? charstring_create(remaining) : dest;
+ bool prevCtrl = true;
if ((sp = str)) {
#ifdef MULTIBYTE_SUPPORT
if (mbtowc(NULL, NULL, 0)) {} /* reset shift state */
remaining--;
}
- prevCtrl = 1;
+ prevCtrl = true;
continue;
}
- prevCtrl = 0;
+ prevCtrl = false;
#ifdef MULTIBYTE_SUPPORT
if (w >= 0 && remaining >= w) {
int
m_convert (struct msgs *mp, char *name)
{
- int first, last, found, count, is_range, err;
+ int first, last, found, count, err;
char *bp, *cp;
/* check if user defined sequence */
*/
found = 0;
- is_range = 1;
/*
* Check for special "new" sequence, which
} else if (*cp == ':' || *cp == '=') {
- if (*cp == '=')
- is_range = 0;
-
+ bool is_range = *cp == ':';
cp++;
if (*cp == '-') {
char op;
int i, j;
int found,
- inverted = 0,
count = 0, /* range given? else use entire sequence */
- just_one = 0, /* want entire sequence or range */
first = 0,
start = 0;
}
/* Check for sequence negation */
+ bool inverted = false;
if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) {
- inverted = 1;
+ inverted = true;
cp += strlen (dp);
}
for (dp = cp; isalnum((unsigned char)*dp); dp++)
continue;
+ bool just_one = *dp == '='; /* want entire sequence or range */
+
if (*dp == ':') {
bp = dp++;
count = 1;
if (count == 0 || *ep)
return BADLST;
- just_one = 1;
-
op = *bp;
*bp = '\0'; /* temporarily terminate sequence name */
}
* characters up to the end of this field (newline
* followed by non-blank) or bufsz-1 characters.
*/
- int finished;
-
cp = buf;
max = *bufsz-1;
n = 0;
- for (finished = 0; ! finished; ) {
+ for (bool finished = false; !finished; ) {
while (c != '\n' && c != EOF && n++ < max) {
if ((c = Getc (s)) != EOF)
*cp++ = c;
--s->bytes_read;
}
s->state = FLDPLUS;
- finished = 1;
+ finished = true;
} else if (c != ' ' && c != '\t') {
/* The next character is not folded whitespace, so
prepare to move on to the next field. It's OK
if c is EOF, it will be handled on the next
call to m_getfld (). */
s->state = FLD;
- finished = 1;
+ finished = true;
} else {
/* Folded header field, continues on the next line. */
}
{
static char tmpfil[BUFSIZ];
int fd = -1;
- int keep_open = 0;
mode_t oldmode = umask(077);
if (pfx_in == NULL) {
register_for_removal(tmpfil);
+ bool keep_open = false;
if (fd_ret != NULL) {
*fd_ret = fd;
- keep_open = 1;
+ keep_open = true;
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
return NULL;
}
*fp_ret = fp;
- keep_open = 1;
+ keep_open = true;
}
if (!keep_open) {
close(fd);
{
char *tmpfil;
int fd = -1;
- int keep_open = 0;
mode_t oldmode = umask(077);
if (suffix == NULL) {
register_for_removal(tmpfil);
+ bool keep_open = false;
if (fd_ret != NULL) {
*fd_ret = fd;
- keep_open = 1;
+ keep_open = true;
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
return NULL;
}
*fp_ret = fp;
- keep_open = 1;
+ keep_open = true;
}
if (!keep_open) {
close(fd);
*/
#include <stdlib.h> /* for abs(), srand(), rand(), arc4random() */
+#include <stdbool.h>
#include <stdio.h> /* for fopen(), fread(), fclose() */
#include <unistd.h> /* for getpid() */
#include <time.h> /* for time() */
#include "m_rand.h"
#if !HAVE_ARC4RANDOM
-static int seeded = 0;
+static bool seeded = false;
#endif
unsigned int seed;
if ((devurandom = fopen ("/dev/urandom", "r"))) {
- if (fread (&seed, sizeof (seed), 1, devurandom) == 1) seeded = 1;
+ if (fread (&seed, sizeof (seed), 1, devurandom) == 1)
+ seeded = true;
fclose (devurandom);
}
arXiv:1005.4117v1 [physics.comp-ph], 22 May 2010, p. 19.
time() and getpid() shouldn't fail on POSIX platforms. */
seed = abs ((int) ((time (0) * 181 * ((getpid ()-83) * 359)) % 104729));
- seeded = 1;
+ seeded = true;
}
srand (seed);
{
char path[PATH_MAX];
char* folder_perms_ASCII;
- int had_an_error = 0;
mode_t folder_perms, saved_umask;
char* c;
c = strncpy(path, dir, sizeof(path));
+ bool had_an_error = false;
while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {
*c = '\0';
if (access(path, X_OK)) {
if (errno != ENOENT){
advise (dir, "unable to create directory");
- had_an_error = 1;
+ had_an_error = true;
}
/* Create an outer directory. */
if (mkdir(path, folder_perms)) {
advise (dir, "unable to create directory");
- had_an_error = 1;
+ had_an_error = true;
}
}
*c = '/';
asked to create. */
if (mkdir (dir, folder_perms) == -1) {
advise (dir, "unable to create directory");
- had_an_error = 1;
+ had_an_error = true;
}
}
mime_type(const char *file_name) {
char *content_type = NULL; /* mime content type */
char *p;
- static int loaded_defaults = 0;
#ifdef MIMETYPEPROC
char *mimetype;
struct node *np; /* Content scan node pointer */
FILE *fp; /* File pointer for mhn.defaults */
+ static bool loaded_defaults;
if (! loaded_defaults &&
(fp = fopen(p = etcpath("mhn.defaults"), "r"))) {
- loaded_defaults = 1;
+ loaded_defaults = true;
readconfig(NULL, fp, p, 0);
fclose(fp);
}
if (content_type == NULL) {
FILE *fp;
- int binary = 0, c;
+ int c;
if (!(fp = fopen(file_name, "r"))) {
inform("unable to access file \"%s\"", file_name);
return NULL;
}
+ bool binary = false;
while ((c = getc(fp)) != EOF) {
if (! isascii(c) || c == 0) {
- binary = 1;
+ binary = true;
break;
}
}
void
ruserpass(const char *host, char **aname, char **apass, int flags)
{
- int t, usedefault = 0;
+ int t;
struct stat stb;
init_credentials_file ();
char tokval[MAX_TOKVAL_SIZE];
tokval[0] = '\0';
+ bool usedefault = false;
while ((t = token(tokval))) {
switch(t) {
case DEFAULT:
- usedefault = 1;
+ usedefault = true;
/* FALLTHRU */
case MACH:
seq_addsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
- int msgnum, new_seq = 1;
+ int msgnum;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
+ bool new_seq = true;
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
- new_seq = 0;
+ new_seq = false;
break;
}
}
seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
{
unsigned int i;
- int j, new_seq = 1;
+ int j;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
+ bool new_seq = true;
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
- new_seq = 0;
+ new_seq = false;
break;
}
}
seq_delsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
- int msgnum, new_seq = 1;
+ int msgnum;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
+ bool new_seq = true;
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
- new_seq = 0;
+ new_seq = false;
break;
}
}
showfile (char **arg, char *file)
{
pid_t pid;
- int isdraft, vecp;
+ int vecp;
char **vec, *program;
int retval = 1;
case 0:
/* child */
vec = argsplit(lproc, &program, &vecp);
- isdraft = 1;
+ bool isdraft = true;
if (arg) {
while (*arg) {
if (**arg != '-')
- isdraft = 0;
+ isdraft = false;
vec[vecp++] = *arg++;
}
}
/* Read context, if supposed to. */
if (read_context) {
- int allow_version_check = 1;
- int check_older_version = 0;
char *cp;
context_read();
+ bool allow_version_check = true;
+ bool check_older_version = false;
if (!check_version ||
((cp = context_find ("Welcome")) && strcasecmp (cp, "disable") == 0)) {
- allow_version_check = 0;
+ allow_version_check = false;
} else if ((cp = getenv ("MHCONTEXT")) != NULL && *cp != '\0') {
/* Context file comes from $MHCONTEXT, so only print the message
if the context file has an older version. If it does, or if it
doesn't have a version at all, update the version. */
- check_older_version = 1;
+ check_older_version = true;
}
/* Check to see if the user is running a different (or older, if