summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
986abce)
Knowing the domain of the variable is Boolean aids comprehension of the
variable's name and purpose.
19 files changed:
argsplit(char *command, char **file, int *argp)
{
char **argvarray, *p;
argsplit(char *command, char **file, int *argp)
{
char **argvarray, *p;
- int space = 0, metachar = 0, i;
+ bool space = false;
+ bool metachar = false;
for (p = command; *p; p++) {
if (*p == ' ' || *p == '\t') {
for (p = command; *p; p++) {
if (*p == ' ' || *p == '\t') {
} else if (strchr(METACHARS, *p)) {
} else if (strchr(METACHARS, *p)) {
{
unsigned int cc, n;
unsigned char inbuf[3];
{
unsigned int cc, n;
unsigned char inbuf[3];
n = BPERLIN;
while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) {
unsigned long bits;
n = BPERLIN;
while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) {
unsigned long bits;
inbuf[cc++] = '\n';
else
ungetc('\n', in);
inbuf[cc++] = '\n';
else
ungetc('\n', in);
} else {
/* This only works as long as sizeof(inbuf) == 3 */
ungetc(inbuf[cc - 1], in);
} else {
/* This only works as long as sizeof(inbuf) == 3 */
ungetc(inbuf[cc - 1], in);
inbuf[++i] = '\n';
}
} else {
inbuf[++i] = '\n';
}
} else {
decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
int skip_crs, unsigned char *digest) {
const char *cp = encoded;
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. */
int bitno, skip;
uint32_t bits;
/* Size the decoded string very conservatively. */
+ bool self_delimiting = false;
for (; *cp; ++cp) {
switch (*cp) {
unsigned char value;
for (; *cp; ++cp) {
switch (*cp) {
unsigned char value;
case '=':
if (++skip <= 3)
goto test_end;
case '=':
if (++skip <= 3)
goto test_end;
+ self_delimiting = true;
field_encode_quoted(const char *name, char **value, const char *charset,
int ascii, int encoded, int phraserules)
{
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;
int charsetlen = strlen(charset), utf8;
char *output = NULL, *p, *q = NULL;
utf8 = strcasecmp(charset, "UTF-8") == 0;
utf8 = strcasecmp(charset, "UTF-8") == 0;
while (*p != '\0') {
/*
* Start a new line, if it's time
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;
tokenlen = snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
q += tokenlen;
column = prefixlen + tokenlen;
continue;
if (column >= ENCODELINELIMIT - 2) {
continue;
if (column >= ENCODELINELIMIT - 2) {
} else if (utf8) {
/*
* Okay, this is a bit weird, but to explain a bit more ...
} 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) {
* allow for the encoded output.
*/
if (column + (utf8len(p) * 3) > ENCODELINELIMIT - 2) {
int vecp; /* Vector index */
char *program; /* Name of program to execute */
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 ((hook = context_find(hook_name)) == NULL)
return OK;
if (status == OK)
return OK;
if (status == OK)
return OK;
- if (did_message == 0) {
char *msghook;
if ((msghook = context_find("msg-hook")) != NULL)
inform("%s", msghook);
char *msghook;
if ((msghook = context_find("msg-hook")) != NULL)
inform("%s", msghook);
snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
pidstatus(status, stderr, errbuf);
}
snprintf(errbuf, sizeof(errbuf), "external hook \"%s\"", hook);
pidstatus(status, stderr, errbuf);
}
int
fdcompare (int fd1, int fd2)
{
int
fdcompare (int fd1, int fd2)
{
char *c1, *c2;
char b1[BUFSIZ], b2[BUFSIZ];
char *c1, *c2;
char b1[BUFSIZ], b2[BUFSIZ];
while ((n1 = read (fd1, b1, sizeof(b1))) >= 0
&& (n2 = read (fd2, b2, sizeof(b2))) >= 0
&& n1 == n2) {
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++) {
c2 = b2;
for (i = n1 < (int) sizeof(b1) ? n1 : (int) sizeof(b1); i--;)
if (*c1++ != *c2++) {
goto leave;
}
if (n1 < (int) sizeof(b1))
goto leave;
}
goto leave;
}
if (n1 < (int) sizeof(b1))
goto leave;
}
leave: ;
lseek(fd1, 0, SEEK_SET);
leave: ;
lseek(fd1, 0, SEEK_SET);
- static int comptable_initialized = 0;
+ static bool comptable_initialized;
format_string = mh_xstrdup(fstring);
usr_fstring = fstring;
if (reset_comptable || !comptable_initialized) {
free_comptable();
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
}
/* 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? */
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 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;
iconv_t cd = NULL;
int fromutf8 = 0;
char *saveq, *convbuf = NULL;
if (!strchr (str, '='))
return 0;
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);
for (p = str, q = dst; *p; p++) {
/* reset iconv */
#ifdef HAVE_ICONV
if (use_iconv) {
iconv_close(cd);
*/
if (equals_pending) {
ADDCHR('=');
*/
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 (between_encodings && is_lws(*p))
whitespace++;
else
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 */
- equals_pending = 1; /* we have a '=' pending */
/* Check for initial =? */
if (*p == '=' && p[1] == '?' && p[2]) {
/* Check for initial =? */
if (*p == '=' && p[1] == '?' && p[2]) {
fromutf8 = !strcasecmp(startofmime, "UTF-8");
*pp = '?';
if (cd == (iconv_t)-1) continue;
fromutf8 = !strcasecmp(startofmime, "UTF-8");
*pp = '?';
if (cd == (iconv_t)-1) continue;
* We've found an encoded word, so we can drop
* the '=' that was pending
*/
* We've found an encoded word, so we can drop
* the '=' that was pending
*/
+ equals_pending = false;
/*
* If we are between two encoded words separated only by
/*
* If we are between two encoded words separated only by
* malloc 0 bytes but skip on to the end
*/
if (endofmime == startofmime && use_iconv) {
* malloc 0 bytes but skip on to the end
*/
if (endofmime == startofmime && use_iconv) {
p = endofmime + 1;
encoding_found = 1; /* we found (at least 1) encoded word */
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 */
}
}
whitespace = 0; /* re-initialize amount of whitespace */
}
}
char *altstr = NULL;
#endif
char *sp; /* current position in source string */
char *altstr = NULL;
#endif
char *sp; /* current position in source string */
/* get alignment */
rjust = 0;
/* get alignment */
rjust = 0;
trimmed = rjust ? charstring_create(remaining) : dest;
trimmed = rjust ? charstring_create(remaining) : dest;
if ((sp = str)) {
#ifdef MULTIBYTE_SUPPORT
if (mbtowc(NULL, NULL, 0)) {} /* reset shift state */
if ((sp = str)) {
#ifdef MULTIBYTE_SUPPORT
if (mbtowc(NULL, NULL, 0)) {} /* reset shift state */
#ifdef MULTIBYTE_SUPPORT
if (w >= 0 && remaining >= w) {
#ifdef MULTIBYTE_SUPPORT
if (w >= 0 && remaining >= w) {
int
m_convert (struct msgs *mp, char *name)
{
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 */
char *bp, *cp;
/* check if user defined sequence */
/*
* Check for special "new" sequence, which
/*
* Check for special "new" sequence, which
} else if (*cp == ':' || *cp == '=') {
} else if (*cp == ':' || *cp == '=') {
- if (*cp == '=')
- is_range = 0;
-
+ bool is_range = *cp == ':';
char op;
int i, j;
int found,
char op;
int i, j;
int found,
count = 0, /* range given? else use entire sequence */
count = 0, /* range given? else use entire sequence */
- just_one = 0, /* want entire sequence or range */
}
/* Check for sequence negation */
}
/* Check for sequence negation */
if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) {
if ((dp = context_find (nsequence)) && *dp != '\0' && ssequal (dp, cp)) {
for (dp = cp; isalnum((unsigned char)*dp); dp++)
continue;
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 (*dp == ':') {
bp = dp++;
count = 1;
if (count == 0 || *ep)
return BADLST;
if (count == 0 || *ep)
return BADLST;
op = *bp;
*bp = '\0'; /* temporarily terminate sequence name */
}
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.
*/
* characters up to the end of this field (newline
* followed by non-blank) or bufsz-1 characters.
*/
cp = buf;
max = *bufsz-1;
n = 0;
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;
while (c != '\n' && c != EOF && n++ < max) {
if ((c = Getc (s)) != EOF)
*cp++ = c;
--s->bytes_read;
}
s->state = FLDPLUS;
--s->bytes_read;
}
s->state = FLDPLUS;
} 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;
} 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;
} else {
/* Folded header field, continues on the next line. */
}
} else {
/* Folded header field, continues on the next line. */
}
{
static char tmpfil[BUFSIZ];
int fd = -1;
{
static char tmpfil[BUFSIZ];
int fd = -1;
mode_t oldmode = umask(077);
if (pfx_in == NULL) {
mode_t oldmode = umask(077);
if (pfx_in == NULL) {
register_for_removal(tmpfil);
register_for_removal(tmpfil);
+ bool keep_open = false;
if (fd_ret != NULL) {
*fd_ret = fd;
if (fd_ret != NULL) {
*fd_ret = fd;
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
return NULL;
}
*fp_ret = fp;
return NULL;
}
*fp_ret = fp;
}
if (!keep_open) {
close(fd);
}
if (!keep_open) {
close(fd);
{
char *tmpfil;
int fd = -1;
{
char *tmpfil;
int fd = -1;
mode_t oldmode = umask(077);
if (suffix == NULL) {
mode_t oldmode = umask(077);
if (suffix == NULL) {
register_for_removal(tmpfil);
register_for_removal(tmpfil);
+ bool keep_open = false;
if (fd_ret != NULL) {
*fd_ret = fd;
if (fd_ret != NULL) {
*fd_ret = fd;
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
}
if (fp_ret != NULL) {
FILE *fp = fdopen(fd, "w+");
return NULL;
}
*fp_ret = fp;
return NULL;
}
*fp_ret = fp;
}
if (!keep_open) {
close(fd);
}
if (!keep_open) {
close(fd);
*/
#include <stdlib.h> /* for abs(), srand(), rand(), arc4random() */
*/
#include <stdlib.h> /* for abs(), srand(), rand(), arc4random() */
#include <stdio.h> /* for fopen(), fread(), fclose() */
#include <unistd.h> /* for getpid() */
#include <time.h> /* for time() */
#include <stdio.h> /* for fopen(), fread(), fclose() */
#include <unistd.h> /* for getpid() */
#include <time.h> /* for time() */
#include "m_rand.h"
#if !HAVE_ARC4RANDOM
#include "m_rand.h"
#if !HAVE_ARC4RANDOM
+static bool seeded = false;
unsigned int seed;
if ((devurandom = fopen ("/dev/urandom", "r"))) {
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;
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));
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));
{
char path[PATH_MAX];
char* folder_perms_ASCII;
{
char path[PATH_MAX];
char* folder_perms_ASCII;
mode_t folder_perms, saved_umask;
char* c;
mode_t folder_perms, saved_umask;
char* c;
c = strncpy(path, dir, sizeof(path));
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");
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");
}
/* Create an outer directory. */
if (mkdir(path, folder_perms)) {
advise (dir, "unable to create directory");
}
/* Create an outer directory. */
if (mkdir(path, folder_perms)) {
advise (dir, "unable to create directory");
asked to create. */
if (mkdir (dir, folder_perms) == -1) {
advise (dir, "unable to create directory");
asked to create. */
if (mkdir (dir, folder_perms) == -1) {
advise (dir, "unable to create directory");
mime_type(const char *file_name) {
char *content_type = NULL; /* mime content type */
char *p;
mime_type(const char *file_name) {
char *content_type = NULL; /* mime content type */
char *p;
- static int loaded_defaults = 0;
#ifdef MIMETYPEPROC
char *mimetype;
#ifdef MIMETYPEPROC
char *mimetype;
struct node *np; /* Content scan node pointer */
FILE *fp; /* File pointer for mhn.defaults */
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"))) {
if (! loaded_defaults &&
(fp = fopen(p = etcpath("mhn.defaults"), "r"))) {
+ loaded_defaults = true;
readconfig(NULL, fp, p, 0);
fclose(fp);
}
readconfig(NULL, fp, p, 0);
fclose(fp);
}
if (content_type == NULL) {
FILE *fp;
if (content_type == NULL) {
FILE *fp;
if (!(fp = fopen(file_name, "r"))) {
inform("unable to access file \"%s\"", file_name);
return NULL;
}
if (!(fp = fopen(file_name, "r"))) {
inform("unable to access file \"%s\"", file_name);
return NULL;
}
while ((c = getc(fp)) != EOF) {
if (! isascii(c) || c == 0) {
while ((c = getc(fp)) != EOF) {
if (! isascii(c) || c == 0) {
void
ruserpass(const char *host, char **aname, char **apass, int flags)
{
void
ruserpass(const char *host, char **aname, char **apass, int flags)
{
struct stat stb;
init_credentials_file ();
struct stat stb;
init_credentials_file ();
char tokval[MAX_TOKVAL_SIZE];
tokval[0] = '\0';
char tokval[MAX_TOKVAL_SIZE];
tokval[0] = '\0';
+ bool usedefault = false;
while ((t = token(tokval))) {
switch(t) {
case DEFAULT:
while ((t = token(tokval))) {
switch(t) {
case DEFAULT:
/* FALLTHRU */
case MACH:
/* FALLTHRU */
case MACH:
seq_addsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
seq_addsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
- int msgnum, new_seq = 1;
if (!seq_nameok (cp))
return 0;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
/*
* Get the number for this sequence
*/
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
{
unsigned int i;
seq_addmsg (struct msgs *mp, char *cp, int msgnum, int public, int zero)
{
unsigned int i;
if (!seq_nameok (cp))
return 0;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
/*
* Get the number for this sequence
*/
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
seq_delsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
seq_delsel (struct msgs *mp, char *cp, int public, int zero)
{
unsigned int i;
- int msgnum, new_seq = 1;
if (!seq_nameok (cp))
return 0;
if (!seq_nameok (cp))
return 0;
/*
* Get the number for this sequence
*/
/*
* Get the number for this sequence
*/
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
for (i = 0; i < svector_size (mp->msgattrs); i++) {
if (!strcmp (svector_at (mp->msgattrs, i), cp)) {
showfile (char **arg, char *file)
{
pid_t pid;
showfile (char **arg, char *file)
{
pid_t pid;
char **vec, *program;
int retval = 1;
char **vec, *program;
int retval = 1;
case 0:
/* child */
vec = argsplit(lproc, &program, &vecp);
case 0:
/* child */
vec = argsplit(lproc, &program, &vecp);
if (arg) {
while (*arg) {
if (**arg != '-')
if (arg) {
while (*arg) {
if (**arg != '-')
vec[vecp++] = *arg++;
}
}
vec[vecp++] = *arg++;
}
}
/* Read context, if supposed to. */
if (read_context) {
/* Read context, if supposed to. */
if (read_context) {
- int allow_version_check = 1;
- int check_older_version = 0;
char *cp;
context_read();
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)) {
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. */
} 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
}
/* Check to see if the user is running a different (or older, if