1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

Convert a lot of 'int' variables to 'bool'.

My normal habit these days, in new code, is to treat int and bool as
_almost_ completely separate types. I'm still willing to use C's
implicit test for zero on an integer (e.g. 'if (!blob.len)' is fine,
no need to spell it out as blob.len != 0), but generally, if a
variable is going to be conceptually a boolean, I like to declare it
bool and assign to it using 'true' or 'false' rather than 0 or 1.

PuTTY is an exception, because it predates the C99 bool, and I've
stuck to its existing coding style even when adding new code to it.
But it's been annoying me more and more, so now that I've decided C99
bool is an acceptable thing to require from our toolchain in the first
place, here's a quite thorough trawl through the source doing
'boolification'. Many variables and function parameters are now typed
as bool rather than int; many assignments of 0 or 1 to those variables
are now spelled 'true' or 'false'.

I managed this thorough conversion with the help of a custom clang
plugin that I wrote to trawl the AST and apply heuristics to point out
where things might want changing. So I've even managed to do a decent
job on parts of the code I haven't looked at in years!

To make the plugin's work easier, I pushed platform front ends
generally in the direction of using standard 'bool' in preference to
platform-specific boolean types like Windows BOOL or GTK's gboolean;
I've left the platform booleans in places they _have_ to be for the
platform APIs to work right, but variables only used by my own code
have been converted wherever I found them.

In a few places there are int values that look very like booleans in
_most_ of the places they're used, but have a rarely-used third value,
or a distinction between different nonzero values that most users
don't care about. In these cases, I've _removed_ uses of 'true' and
'false' for the return values, to emphasise that there's something
more subtle going on than a simple boolean answer:
 - the 'multisel' field in dialog.h's list box structure, for which
   the GTK front end in particular recognises a difference between 1
   and 2 but nearly everything else treats as boolean
 - the 'urgent' parameter to plug_receive, where 1 vs 2 tells you
   something about the specific location of the urgent pointer, but
   most clients only care about 0 vs 'something nonzero'
 - the return value of wc_match, where -1 indicates a syntax error in
   the wildcard.
 - the return values from SSH-1 RSA-key loading functions, which use
   -1 for 'wrong passphrase' and 0 for all other failures (so any
   caller which already knows it's not loading an _encrypted private_
   key can treat them as boolean)
 - term->esc_query, and the 'query' parameter in toggle_mode in
   terminal.c, which _usually_ hold 0 for ESC[123h or 1 for ESC[?123h,
   but can also hold -1 for some other intervening character that we
   don't support.

In a few places there's an integer that I haven't turned into a bool
even though it really _can_ only take values 0 or 1 (and, as above,
tried to make the call sites consistent in not calling those values
true and false), on the grounds that I thought it would make it more
confusing to imply that the 0 value was in some sense 'negative' or
bad and the 1 positive or good:
 - the return value of plug_accepting uses the POSIXish convention of
   0=success and nonzero=error; I think if I made it bool then I'd
   also want to reverse its sense, and that's a job for a separate
   piece of work.
 - the 'screen' parameter to lineptr() in terminal.c, where 0 and 1
   represent the default and alternate screens. There's no obvious
   reason why one of those should be considered 'true' or 'positive'
   or 'success' - they're just indices - so I've left it as int.

ssh_scp_recv had particularly confusing semantics for its previous int
return value: its call sites used '<= 0' to check for error, but it
never actually returned a negative number, just 0 or 1. Now the
function and its call sites agree that it's a bool.

In a couple of places I've renamed variables called 'ret', because I
don't like that name any more - it's unclear whether it means the
return value (in preparation) for the _containing_ function or the
return value received from a subroutine call, and occasionally I've
accidentally used the same variable for both and introduced a bug. So
where one of those got in my way, I've renamed it to 'toret' or 'retd'
(the latter short for 'returned') in line with my usual modern
practice, but I haven't done a thorough job of finding all of them.

Finally, one amusing side effect of doing this is that I've had to
separate quite a few chained assignments. It used to be perfectly fine
to write 'a = b = c = TRUE' when a,b,c were int and TRUE was just a
the 'true' defined by stdbool.h, that idiom provokes a warning from
gcc: 'suggest parentheses around assignment used as truth value'!
This commit is contained in:
Simon Tatham
2018-11-02 19:23:19 +00:00
parent 1378bb049a
commit 3214563d8e
164 changed files with 2914 additions and 2805 deletions

View File

@ -88,7 +88,7 @@ https://wiki.gnome.org/Projects/GTK%2B/OSX/Bundling has some links.
char *x_get_default(const char *key) { return NULL; }
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
#if !GTK_CHECK_VERSION(3,0,0)
/* This front end only works in GTK 3. If that's not what we've got,
@ -107,7 +107,7 @@ void session_window_closed(void) {}
void window_setup_error(const char *errmsg) {}
#else /* GTK_CHECK_VERSION(3,0,0) */
extern const int use_event_log;
extern const bool use_event_log;
static void startup(GApplication *app, gpointer user_data)
{
@ -216,7 +216,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend)
void launch_duplicate_session(Conf *conf)
{
extern const int dup_check_launchable;
extern const bool dup_check_launchable;
assert(!dup_check_launchable || conf_launchable(conf));
g_application_hold(G_APPLICATION(app));
new_session_window(conf_copy(conf), NULL);
@ -318,7 +318,7 @@ int main(int argc, char **argv)
{
/* Call the function in ux{putty,pterm}.c to do app-type
* specific setup */
extern void setup(int);
extern void setup(bool);
setup(false); /* false means we are not a one-session process */
}

View File

@ -14,6 +14,7 @@
#include <gdk/gdkkeysyms.h>
#endif
#include "defs.h"
#include "gtkfont.h"
#include "gtkcompat.h"
#include "gtkmisc.h"
@ -501,13 +502,13 @@ static void gtk_askpass_cleanup(struct askpass_ctx *ctx)
gtk_widget_destroy(ctx->dialog);
}
static int setup_gtk(const char *display)
static bool setup_gtk(const char *display)
{
static int gtk_initialised = false;
static bool gtk_initialised = false;
int argc;
char *real_argv[3];
char **argv = real_argv;
int ret;
bool ret;
if (gtk_initialised)
return true;
@ -524,10 +525,10 @@ static int setup_gtk(const char *display)
return ret;
}
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
char *gtk_askpass_main(const char *display, const char *wintitle,
const char *prompt, int *success)
const char *prompt, bool *success)
{
struct askpass_ctx actx, *ctx = &actx;
const char *err;
@ -571,7 +572,8 @@ void modalfatalbox(const char *p, ...)
int main(int argc, char **argv)
{
int success, exitcode;
bool success;
int exitcode;
char *ret;
gtk_init(&argc, &argv);

View File

@ -18,7 +18,7 @@ static void about_handler(union control *ctrl, dlgparam *dlg,
}
}
void gtk_setup_config_box(struct controlbox *b, int midsession, void *win)
void gtk_setup_config_box(struct controlbox *b, bool midsession, void *win)
{
struct controlset *s, *s2;
union control *c;

View File

@ -331,7 +331,7 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget)
ColumnsChild *child;
GtkWidget *childw;
GList *children;
gboolean was_visible;
bool was_visible;
g_return_if_fail(container != NULL);
g_return_if_fail(IS_COLUMNS(container));

View File

@ -41,7 +41,7 @@ struct ColumnsChild_tag {
/* If `widget' is non-NULL, this entry represents an actual widget. */
GtkWidget *widget;
gint colstart, colspan;
gboolean force_left; /* for recalcitrant GtkLabels */
bool force_left; /* for recalcitrant GtkLabels */
ColumnsChild *same_height_as;
/* Otherwise, this entry represents a change in the column setup. */
gint ncols;

View File

@ -199,7 +199,7 @@ void timer_change_notify(unsigned long next)
*/
static guint toplevel_callback_idle_id;
static int idle_fn_scheduled;
static bool idle_fn_scheduled;
static void notify_toplevel_callback(void *);

View File

@ -79,7 +79,10 @@ struct uctrl {
struct dlgparam {
tree234 *byctrl, *bywidget;
void *data;
struct { unsigned char r, g, b, ok; } coloursel_result; /* 0-255 */
struct {
unsigned char r, g, b; /* 0-255 */
bool ok;
} coloursel_result;
/* `flags' are set to indicate when a GTK signal handler is being called
* due to automatic processing and should not flag a user event. */
int flags;
@ -281,14 +284,14 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp)
return 0; /* got to return something */
}
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, int checked)
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
assert(uc->ctrl->generic.type == CTRL_CHECKBOX);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(uc->toplevel), checked);
}
int dlg_checkbox_get(union control *ctrl, dlgparam *dp)
bool dlg_checkbox_get(union control *ctrl, dlgparam *dp)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
assert(uc->ctrl->generic.type == CTRL_CHECKBOX);
@ -707,7 +710,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp)
return -1; /* placate dataflow analysis */
}
int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
{
struct uctrl *uc = dlg_find_byctrl(dp, ctrl);
@ -748,7 +751,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
if (uc->treeview) {
GtkTreeSelection *treesel;
GtkTreePath *path;
int ret;
bool ret;
assert(uc->treeview != NULL);
treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview));
@ -761,7 +764,7 @@ int dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
}
#endif
assert(!"We shouldn't get here");
return -1; /* placate dataflow analysis */
return false; /* placate dataflow analysis */
}
void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index)
@ -790,7 +793,7 @@ void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index)
items = gtk_container_children(GTK_CONTAINER(uc->list));
nitems = g_list_length(items);
if (nitems > 0) {
int modified = false;
bool modified = false;
g_list_free(items);
newtop = uc->adj->lower +
(uc->adj->upper - uc->adj->lower) * index / nitems;
@ -1181,16 +1184,16 @@ void dlg_coloursel_start(union control *ctrl, dlgparam *dp, int r, int g, int b)
gtk_widget_show(coloursel);
}
int dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b)
bool dlg_coloursel_results(union control *ctrl, dlgparam *dp,
int *r, int *g, int *b)
{
if (dp->coloursel_result.ok) {
*r = dp->coloursel_result.r;
*g = dp->coloursel_result.g;
*b = dp->coloursel_result.b;
return 1;
return true;
} else
return 0;
return false;
}
/* ----------------------------------------------------------------------
@ -1279,7 +1282,7 @@ static gboolean editbox_lostfocus(GtkWidget *ed, GdkEventFocus *event,
*/
static gboolean listitem_key(GtkWidget *item, GdkEventKey *event,
gpointer data, int multiple)
gpointer data, bool multiple)
{
GtkAdjustment *adj = GTK_ADJUSTMENT(data);
@ -1877,7 +1880,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
for (i = 0; i < s->ncontrols; i++) {
union control *ctrl = s->ctrls[i];
struct uctrl *uc;
int left = false;
bool left = false;
GtkWidget *w = NULL;
switch (ctrl->generic.type) {
@ -2555,7 +2558,7 @@ static void treeitem_sel(GtkItem *item, gpointer data)
#endif
#if !GTK_CHECK_VERSION(2,0,0)
static int tree_grab_focus(struct dlgparam *dp)
static bool tree_grab_focus(struct dlgparam *dp)
{
int i, f;
@ -2592,7 +2595,7 @@ gint tree_focus(GtkContainer *container, GtkDirectionType direction,
}
#endif
int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
gint win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct dlgparam *dp = (struct dlgparam *)data;
@ -2717,7 +2720,7 @@ int win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
}
#if !GTK_CHECK_VERSION(2,0,0)
int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
gint tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
{
struct dlgparam *dp = (struct dlgparam *)data;
@ -2742,7 +2745,7 @@ int tree_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
*/
{
GtkWidget *w = dp->treeitems[i];
int vis = true;
bool vis = true;
while (w && (GTK_IS_TREE_ITEM(w) || GTK_IS_TREE(w))) {
if (!GTK_WIDGET_VISIBLE(w)) {
vis = false;
@ -2893,7 +2896,7 @@ void treeview_map_event(GtkWidget *tree, gpointer data)
#endif
GtkWidget *create_config_box(const char *title, Conf *conf,
int midsession, int protcfginfo,
bool midsession, int protcfginfo,
post_dialog_fn_t after, void *afterctx)
{
GtkWidget *window, *hbox, *vbox, *cols, *label,
@ -2999,7 +3002,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
#else
GtkWidget *treeitem;
#endif
int first;
bool first;
/*
* We expect never to find an implicit path
@ -3213,7 +3216,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
*/
for (index = 0; index < dp->ctrlbox->nctrlsets; index++) {
struct controlset *s = dp->ctrlbox->ctrlsets[index];
int done = 0;
bool done = false;
int j;
if (*s->pathname) {
@ -3223,7 +3226,7 @@ GtkWidget *create_config_box(const char *title, Conf *conf,
s->ctrls[j]->generic.type != CTRL_TEXT) {
dlg_set_focus(s->ctrls[j], dp);
dp->lastfocus = s->ctrls[j];
done = 1;
done = true;
break;
}
}
@ -3280,7 +3283,7 @@ const struct message_box_buttons buttons_ok = {
GtkWidget *create_message_box(
GtkWidget *parentwin, const char *title, const char *msg, int minwid,
int selectable, const struct message_box_buttons *buttons,
bool selectable, const struct message_box_buttons *buttons,
post_dialog_fn_t after, void *afterctx)
{
GtkWidget *window, *w0, *w1;
@ -3770,7 +3773,7 @@ struct eventlog_stuff {
int ninitial, ncircular, circular_first;
char *seldata;
int sellen;
int ignore_selchange;
bool ignore_selchange;
};
static void eventlog_destroy(GtkWidget *widget, gpointer data)
@ -3887,7 +3890,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
* Deselect everything in the list box.
*/
uc = dlg_find_byctrl(&es->dp, es->listctrl);
es->ignore_selchange = 1;
es->ignore_selchange = true;
#if !GTK_CHECK_VERSION(2,0,0)
assert(uc->list);
gtk_list_unselect_all(GTK_LIST(uc->list));
@ -3896,7 +3899,7 @@ gint eventlog_selection_clear(GtkWidget *widget, GdkEventSelection *seldata,
gtk_tree_selection_unselect_all
(gtk_tree_view_get_selection(GTK_TREE_VIEW(uc->treeview)));
#endif
es->ignore_selchange = 0;
es->ignore_selchange = false;
sfree(es->seldata);
es->sellen = 0;

View File

@ -73,22 +73,23 @@ struct UnifontVtable {
/*
* `Methods' of the `class'.
*/
unifont *(*create)(GtkWidget *widget, const char *name, int wide, int bold,
int shadowoffset, int shadowalways);
unifont *(*create_fallback)(GtkWidget *widget, int height, int wide,
int bold, int shadowoffset, int shadowalways);
unifont *(*create)(GtkWidget *widget, const char *name, bool wide,
bool bold, int shadowoffset, bool shadowalways);
unifont *(*create_fallback)(GtkWidget *widget, int height, bool wide,
bool bold, int shadowoffset,
bool shadowalways);
void (*destroy)(unifont *font);
int (*has_glyph)(unifont *font, wchar_t glyph);
bool (*has_glyph)(unifont *font, wchar_t glyph);
void (*draw_text)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
void (*draw_combining)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
void (*enum_fonts)(GtkWidget *widget,
fontsel_add_entry callback, void *callback_ctx);
char *(*canonify_fontname)(GtkWidget *widget, const char *name, int *size,
int *flags, int resolve_aliases);
int *flags, bool resolve_aliases);
char *(*scale_fontname)(GtkWidget *widget, const char *name, int size);
char *(*size_increment)(unifont *font, int increment);
@ -106,22 +107,23 @@ struct UnifontVtable {
* back end other than X).
*/
static int x11font_has_glyph(unifont *font, wchar_t glyph);
static bool x11font_has_glyph(unifont *font, wchar_t glyph);
static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth);
int len, bool wide, bool bold,
int cellwidth);
static unifont *x11font_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static void x11font_destroy(unifont *font);
static void x11font_enum_fonts(GtkWidget *widget,
fontsel_add_entry callback, void *callback_ctx);
static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases);
bool resolve_aliases);
static char *x11font_scale_fontname(GtkWidget *widget, const char *name,
int size);
static char *x11font_size_increment(unifont *font, int increment);
@ -147,7 +149,7 @@ typedef struct x11font_individual {
* haven't tried yet from xfs==NULL because we tried and failed,
* so that we don't keep trying and failing subsequently).
*/
int allocated;
bool allocated;
#ifdef DRAW_TEXT_CAIRO
/*
@ -190,13 +192,13 @@ struct x11font {
* values larger than a byte. That is, this flag tells us
* whether we use XDrawString or XDrawString16, etc.
*/
int sixteen_bit;
bool sixteen_bit;
/*
* `variable' is true iff the font is non-fixed-pitch. This
* enables some code which takes greater care over character
* positioning during text drawing.
*/
int variable;
bool variable;
/*
* real_charset is the charset used when translating text into the
* font's internal encoding inside draw_text(). This need not be
@ -208,7 +210,8 @@ struct x11font {
/*
* Data passed in to unifont_create().
*/
int wide, bold, shadowoffset, shadowalways;
int shadowoffset;
bool wide, bold, shadowalways;
unifont u;
};
@ -312,7 +315,7 @@ static char *xlfd_recompose(const struct xlfd_decomposed *dec)
}
static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs,
int bold, int wide)
bool bold, bool wide)
{
Atom fontprop = XInternAtom(disp, "FONT", False);
unsigned long ret;
@ -343,7 +346,7 @@ static char *x11_guess_derived_font_name(Display *disp, XFontStruct *xfs,
return NULL;
}
static int x11_font_width(XFontStruct *xfs, int sixteen_bit)
static int x11_font_width(XFontStruct *xfs, bool sixteen_bit)
{
if (sixteen_bit) {
XChar2b space;
@ -406,7 +409,7 @@ static const XCharStruct *x11_char_struct(
return &xfs->per_char[index];
}
static int x11_font_has_glyph(
static bool x11_font_has_glyph(
XFontStruct *xfs, unsigned char byte1, unsigned char byte2)
{
/*
@ -426,15 +429,16 @@ static int x11_font_has_glyph(
}
static unifont *x11font_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
struct x11font *xfont;
XFontStruct *xfs;
Display *disp;
Atom charset_registry, charset_encoding, spacing;
unsigned long registry_ret, encoding_ret, spacing_ret;
int pubcs, realcs, sixteen_bit, variable;
int pubcs, realcs;
bool sixteen_bit, variable;
int i;
if ((disp = get_x11_display()) == NULL)
@ -577,7 +581,7 @@ static void x11_alloc_subfont(struct x11font *xfont, int sfid)
/* Note that xfont->fonts[sfid].xfs may still be NULL, if XLQF failed. */
}
static int x11font_has_glyph(unifont *font, wchar_t glyph)
static bool x11font_has_glyph(unifont *font, wchar_t glyph)
{
struct x11font *xfont = container_of(font, struct x11font, u);
@ -851,9 +855,10 @@ static void x11font_really_draw_text(
const struct x11font_drawfuncs *dfns, unifont_drawctx *ctx,
x11font_individual *xfi, Display *disp,
int x, int y, const void *string, int nchars,
int shadowoffset, int fontvariable, int cellwidth)
int shadowoffset, bool fontvariable, int cellwidth)
{
int start = 0, step, nsteps, centre;
int start = 0, step, nsteps;
bool centre;
if (fontvariable) {
/*
@ -891,7 +896,7 @@ static void x11font_really_draw_text(
static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
struct x11font *xfont = container_of(font, struct x11font, u);
int sfid;
@ -899,8 +904,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
int mult = (wide ? 2 : 1);
int index = 2 * (int)ctx->type;
wide -= xfont->wide;
bold -= xfont->bold;
wide = wide && !xfont->wide;
bold = bold && !xfont->bold;
/*
* Decide which subfont we're using, and whether we have to
@ -908,13 +913,13 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
*/
if (xfont->shadowalways && bold) {
shadowoffset = xfont->shadowoffset;
bold = 0;
bold = false;
}
sfid = 2 * wide + bold;
if (!xfont->fonts[sfid].allocated)
x11_alloc_subfont(xfont, sfid);
if (bold && !xfont->fonts[sfid].xfs) {
bold = 0;
bold = false;
shadowoffset = xfont->shadowoffset;
sfid = 2 * wide + bold;
if (!xfont->fonts[sfid].allocated)
@ -961,7 +966,8 @@ static void x11font_draw_text(unifont_drawctx *ctx, unifont *font,
static void x11font_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth)
int len, bool wide, bool bold,
int cellwidth)
{
/*
* For server-side fonts, there's no sophisticated system for
@ -1138,7 +1144,7 @@ static void x11font_enum_fonts(GtkWidget *widget,
static char *x11font_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases)
bool resolve_aliases)
{
/*
* When given an X11 font name to try to make sense of for a
@ -1298,26 +1304,26 @@ static char *x11font_size_increment(unifont *font, int increment)
#define PANGO_PRE_1POINT6 /* make life easier for pre-1.4 folk */
#endif
static int pangofont_has_glyph(unifont *font, wchar_t glyph);
static bool pangofont_has_glyph(unifont *font, wchar_t glyph);
static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static unifont *pangofont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static unifont *pangofont_create_fallback(GtkWidget *widget, int height,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
static void pangofont_destroy(unifont *font);
static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback,
void *callback_ctx);
static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases);
bool resolve_aliases);
static char *pangofont_scale_fontname(GtkWidget *widget, const char *name,
int size);
static char *pangofont_size_increment(unifont *font, int increment);
@ -1335,7 +1341,8 @@ struct pangofont {
/*
* Data passed in to unifont_create().
*/
int bold, shadowoffset, shadowalways;
int shadowoffset;
bool bold, shadowalways;
/*
* Cache of character widths, indexed by Unicode code point. In
* pixels; -1 means we haven't asked Pango about this character
@ -1374,14 +1381,15 @@ static const struct UnifontVtable pangofont_vtable = {
* if it doesn't. So we check that the font family is actually one
* supported by Pango.
*/
static int pangofont_check_desc_makes_sense(PangoContext *ctx,
PangoFontDescription *desc)
static bool pangofont_check_desc_makes_sense(PangoContext *ctx,
PangoFontDescription *desc)
{
#ifndef PANGO_PRE_1POINT6
PangoFontMap *map;
#endif
PangoFontFamily **families;
int i, nfamilies, matched;
int i, nfamilies;
bool matched;
/*
* Ask Pango for a list of font families, and iterate through
@ -1413,8 +1421,8 @@ static int pangofont_check_desc_makes_sense(PangoContext *ctx,
static unifont *pangofont_create_internal(GtkWidget *widget,
PangoContext *ctx,
PangoFontDescription *desc,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
struct pangofont *pfont;
#ifndef PANGO_PRE_1POINT6
@ -1479,8 +1487,8 @@ static unifont *pangofont_create_internal(GtkWidget *widget,
}
static unifont *pangofont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
PangoContext *ctx;
PangoFontDescription *desc;
@ -1502,8 +1510,8 @@ static unifont *pangofont_create(GtkWidget *widget, const char *name,
}
static unifont *pangofont_create_fallback(GtkWidget *widget, int height,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
PangoContext *ctx;
PangoFontDescription *desc;
@ -1559,7 +1567,7 @@ static int pangofont_char_width(PangoLayout *layout, struct pangofont *pfont,
return pfont->widthcache[uchr];
}
static int pangofont_has_glyph(unifont *font, wchar_t glyph)
static bool pangofont_has_glyph(unifont *font, wchar_t glyph)
{
/* Pango implements font fallback, so assume it has everything */
return true;
@ -1584,15 +1592,15 @@ static void pango_cairo_draw_layout(unifont_drawctx *ctx,
static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold, int cellwidth,
int combining)
int len, bool wide, bool bold,
int cellwidth, bool combining)
{
struct pangofont *pfont = container_of(font, struct pangofont, u);
PangoLayout *layout;
PangoRectangle rect;
char *utfstring, *utfptr;
int utflen;
int shadowbold = false;
bool shadowbold = false;
void (*draw_layout)(unifont_drawctx *ctx,
gint x, gint y, PangoLayout *layout) = NULL;
@ -1614,7 +1622,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
layout = pango_layout_new(gtk_widget_get_pango_context(pfont->widget));
pango_layout_set_font_description(layout, pfont->desc);
if (bold > pfont->bold) {
if (bold && !pfont->bold) {
if (pfont->shadowalways)
shadowbold = true;
else {
@ -1740,7 +1748,7 @@ static void pangofont_draw_internal(unifont_drawctx *ctx, unifont *font,
static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
pangofont_draw_internal(ctx, font, x, y, string, len, wide, bold,
cellwidth, false);
@ -1748,7 +1756,7 @@ static void pangofont_draw_text(unifont_drawctx *ctx, unifont *font,
static void pangofont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth)
{
wchar_t *tmpstring = NULL;
@ -1932,7 +1940,7 @@ static void pangofont_enum_fonts(GtkWidget *widget, fontsel_add_entry callback,
static char *pangofont_canonify_fontname(GtkWidget *widget, const char *name,
int *size, int *flags,
int resolve_aliases)
bool resolve_aliases)
{
/*
* When given a Pango font name to try to make sense of for a
@ -2112,8 +2120,8 @@ static const char *unifont_do_prefix(const char *name, int *start, int *end)
}
}
unifont *unifont_create(GtkWidget *widget, const char *name, int wide,
int bold, int shadowoffset, int shadowalways)
unifont *unifont_create(GtkWidget *widget, const char *name, bool wide,
bool bold, int shadowoffset, bool shadowalways)
{
int i, start, end;
@ -2135,14 +2143,14 @@ void unifont_destroy(unifont *font)
void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
font->vt->draw_text(ctx, font, x, y, string, len, wide, bold, cellwidth);
}
void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
font->vt->draw_combining(ctx, font, x, y, string, len, wide, bold,
cellwidth);
@ -2168,10 +2176,10 @@ char *unifont_size_increment(unifont *font, int increment)
static void multifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static void multifont_destroy(unifont *font);
static char *multifont_size_increment(unifont *font, int increment);
@ -2198,8 +2206,8 @@ static const struct UnifontVtable multifont_vtable = {
};
unifont *multifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways)
bool wide, bool bold,
int shadowoffset, bool shadowalways)
{
int i;
unifont *font, *fallback;
@ -2253,17 +2261,18 @@ static void multifont_destroy(unifont *font)
typedef void (*unifont_draw_func_t)(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth);
static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x,
int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth,
bool wide, bool bold, int cellwidth,
int cellinc, unifont_draw_func_t draw)
{
struct multifont *mfont = container_of(font, struct multifont, u);
unifont *f;
int ok, i;
bool ok;
int i;
while (len > 0) {
/*
@ -2290,7 +2299,7 @@ static void multifont_draw_main(unifont_drawctx *ctx, unifont *font, int x,
static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x,
int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth)
bool wide, bool bold, int cellwidth)
{
multifont_draw_main(ctx, font, x, y, string, len, wide, bold,
cellwidth, cellwidth, unifont_draw_text);
@ -2298,7 +2307,7 @@ static void multifont_draw_text(unifont_drawctx *ctx, unifont *font, int x,
static void multifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string,
int len, int wide, int bold,
int len, bool wide, bool bold,
int cellwidth)
{
multifont_draw_main(ctx, font, x, y, string, len, wide, bold,
@ -2335,7 +2344,7 @@ typedef struct unifontsel_internal {
tree234 *fonts_by_realname, *fonts_by_selorder;
fontinfo *selected;
int selsize, intendedsize;
int inhibit_response; /* inhibit callbacks when we change GUI controls */
bool inhibit_response; /* inhibit callbacks when we change GUI controls */
unifontsel u;
} unifontsel_internal;
@ -2529,7 +2538,8 @@ static void unifontsel_setup_stylelist(unifontsel_internal *fs,
int start, int end)
{
GtkTreeIter iter;
int i, listindex, minpos = -1, maxpos = -1, started = false;
int i, listindex, minpos = -1, maxpos = -1;
bool started = false;
char *currcs = NULL, *currstyle = NULL;
fontinfo *info;
@ -2808,7 +2818,7 @@ static void unifontsel_draw_preview_text(unifontsel_internal *fs)
static void unifontsel_select_font(unifontsel_internal *fs,
fontinfo *info, int size, int leftlist,
int size_is_explicit)
bool size_is_explicit)
{
int index;
int minval, maxval;
@ -2946,7 +2956,7 @@ static void unifontsel_select_font(unifontsel_internal *fs,
static void unifontsel_button_toggled(GtkToggleButton *tb, gpointer data)
{
unifontsel_internal *fs = (unifontsel_internal *)data;
int newstate = gtk_toggle_button_get_active(tb);
bool newstate = gtk_toggle_button_get_active(tb);
int newflags;
int flagbit = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(tb),
"user-data"));

View File

@ -74,7 +74,7 @@ typedef struct unifont {
* missing glyphs from other fonts), or whether it would like a
* fallback font to cope with missing glyphs.
*/
int want_fallback;
bool want_fallback;
/*
* Preferred drawing API to use when this class of font is active.
@ -134,18 +134,18 @@ typedef struct unifont_drawctx {
} unifont_drawctx;
unifont *unifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
void unifont_destroy(unifont *font);
void unifont_draw_text(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
/* Same as unifont_draw_text, but expects 'string' to contain one
* normal char plus combining chars, and overdraws them all in the
* same character cell. */
void unifont_draw_combining(unifont_drawctx *ctx, unifont *font,
int x, int y, const wchar_t *string, int len,
int wide, int bold, int cellwidth);
bool wide, bool bold, int cellwidth);
/* Return a name that will select a bigger/smaller font than this one,
* or NULL if no such name is available. */
char *unifont_size_increment(unifont *font, int increment);
@ -159,8 +159,8 @@ char *unifont_size_increment(unifont *font, int increment);
* as if it were an ordinary unifont.
*/
unifont *multifont_create(GtkWidget *widget, const char *name,
int wide, int bold,
int shadowoffset, int shadowalways);
bool wide, bool bold,
int shadowoffset, bool shadowalways);
/*
* Unified font selector dialog. I can't be bothered to do a

View File

@ -48,7 +48,7 @@ static char *progname, **gtkargvstart;
static int ngtkargs;
extern char **pty_argv; /* declared in pty.c */
extern int use_pty_argv;
extern bool use_pty_argv;
static const char *app_name = "pterm";
@ -312,9 +312,9 @@ void window_setup_error(const char *errmsg)
exit(1);
}
int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
bool do_cmdline(int argc, char **argv, bool do_everything, Conf *conf)
{
int err = 0;
bool err = false;
char *val;
/*
@ -327,7 +327,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
*/
#define EXPECTS_ARG { \
if (--argc <= 0) { \
err = 1; \
err = true; \
fprintf(stderr, "%s: %s expects an argument\n", appname, p); \
continue; \
} else \
@ -417,14 +417,14 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
{
#if GTK_CHECK_VERSION(3,0,0)
GdkRGBA rgba;
int success = gdk_rgba_parse(&rgba, val);
bool success = gdk_rgba_parse(&rgba, val);
#else
GdkColor col;
int success = gdk_color_parse(val, &col);
bool success = gdk_color_parse(val, &col);
#endif
if (!success) {
err = 1;
err = true;
fprintf(stderr, "%s: unable to parse colour \"%s\"\n",
appname, val);
} else {
@ -467,7 +467,7 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
pty_argv[argc] = NULL;
break; /* finished command-line processing */
} else
err = 1, fprintf(stderr, "%s: -e expects an argument\n",
err = true, fprintf(stderr, "%s: -e expects an argument\n",
appname);
} else if (!strcmp(p, "-title")) {
@ -535,13 +535,13 @@ int do_cmdline(int argc, char **argv, int do_everything, Conf *conf)
} else if (p[0] != '-') {
/* Non-option arguments not handled by cmdline.c are errors. */
if (do_everything) {
err = 1;
err = true;
fprintf(stderr, "%s: unexpected non-option argument '%s'\n",
appname, p);
}
} else {
err = 1;
err = true;
fprintf(stderr, "%s: unrecognized option '%s'\n", appname, p);
}
}
@ -554,7 +554,7 @@ GtkWidget *make_gtk_toplevel_window(GtkFrontend *frontend)
return gtk_window_new(GTK_WINDOW_TOPLEVEL);
}
const int buildinfo_gtk_relevant = true;
const bool buildinfo_gtk_relevant = true;
struct post_initial_config_box_ctx {
Conf *conf;
@ -586,14 +586,14 @@ void session_window_closed(void)
int main(int argc, char **argv)
{
Conf *conf;
int need_config_box;
bool need_config_box;
setlocale(LC_CTYPE, "");
{
/* Call the function in ux{putty,pterm}.c to do app-type
* specific setup */
extern void setup(int);
extern void setup(bool);
setup(true); /* true means we are a one-session process */
}
@ -623,10 +623,10 @@ int main(int argc, char **argv)
* terminating the main pterm/PuTTY. However, we'll have to
* unblock it again when pterm forks.
*/
block_signal(SIGPIPE, 1);
block_signal(SIGPIPE, true);
if (argc > 1 && !strncmp(argv[1], "---", 3)) {
extern const int dup_check_launchable;
extern const bool dup_check_launchable;
read_dupsession_data(conf, argv[1]);
/* Splatter this argument so it doesn't clutter a ps listing */
@ -635,10 +635,10 @@ int main(int argc, char **argv)
assert(!dup_check_launchable || conf_launchable(conf));
need_config_box = false;
} else {
if (do_cmdline(argc, argv, 0, conf))
if (do_cmdline(argc, argv, false, conf))
exit(1); /* pre-defaults pass to get -class */
do_defaults(NULL, conf);
if (do_cmdline(argc, argv, 1, conf))
if (do_cmdline(argc, argv, true, conf))
exit(1); /* post-defaults, do everything */
cmdline_run_saved(conf);

View File

@ -190,8 +190,7 @@ GtkBox *our_dialog_make_action_hbox(GtkWindow *dlg)
}
void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w,
gboolean expand, gboolean fill,
guint padding)
bool expand, bool fill, guint padding)
{
#if GTK_CHECK_VERSION(3,0,0)
/* GtkWindow is a GtkBin, hence contains exactly one child, which

View File

@ -12,8 +12,7 @@ void align_label_left(GtkLabel *label);
GtkWidget *our_dialog_new(void);
void our_dialog_add_to_content_area(GtkWindow *dlg, GtkWidget *w,
gboolean expand, gboolean fill,
guint padding);
bool expand, bool fill, guint padding);
void our_dialog_set_action_area(GtkWindow *dlg, GtkWidget *w);
GtkBox *our_dialog_make_action_hbox(GtkWindow *dlg);

View File

@ -133,13 +133,14 @@ struct GtkFrontend {
GtkIMContext *imc;
#endif
unifont *fonts[4]; /* normal, bold, wide, widebold */
int xpos, ypos, gotpos, gravity;
int xpos, ypos, gravity;
bool gotpos;
GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor;
GdkColor cols[NALLCOLOURS];
#if !GTK_CHECK_VERSION(3,0,0)
GdkColormap *colmap;
#endif
int direct_to_font;
bool direct_to_font;
struct clipboard_state clipstates[N_CLIPBOARDS];
#ifdef JUST_USE_GTK_CLIPBOARD_UTF8
/* Remember all clipboard_data_instance structures currently
@ -150,8 +151,8 @@ struct GtkFrontend {
int clipboard_ctrlshiftins, clipboard_ctrlshiftcv;
int font_width, font_height;
int width, height, scale;
int ignore_sbar;
int mouseptr_visible;
bool ignore_sbar;
bool mouseptr_visible;
BusyStatus busy_status;
int alt_keycode;
int alt_digits;
@ -162,7 +163,7 @@ struct GtkFrontend {
Backend *backend;
Terminal *term;
LogContext *logctx;
int exited;
bool exited;
struct unicode_data ucsdata;
Conf *conf;
eventlog_stuff *eventlogstuff;
@ -204,7 +205,7 @@ static void cache_conf_values(GtkFrontend *inst)
#endif
}
static int send_raw_mouse;
static bool send_raw_mouse;
static void start_backend(GtkFrontend *inst);
static void exit_callback(void *vinst);
@ -314,14 +315,14 @@ static char *gtk_seat_get_ttymode(Seat *seat, const char *mode)
return term_get_ttymode(inst->term, mode);
}
static int gtk_seat_output(Seat *seat, int is_stderr,
static int gtk_seat_output(Seat *seat, bool is_stderr,
const void *data, int len)
{
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
return term_data(inst->term, is_stderr, data, len);
}
static int gtk_seat_eof(Seat *seat)
static bool gtk_seat_eof(Seat *seat)
{
/* GtkFrontend *inst = container_of(seat, GtkFrontend, seat); */
return true; /* do respond to incoming EOF with outgoing */
@ -338,13 +339,13 @@ static int gtk_seat_get_userpass_input(Seat *seat, prompts_t *p,
return ret;
}
static int gtk_seat_is_utf8(Seat *seat)
static bool gtk_seat_is_utf8(Seat *seat)
{
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
return win_is_utf8(&inst->termwin);
}
static int gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h)
static bool gtk_seat_get_window_pixel_size(Seat *seat, int *w, int *h)
{
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
win_get_pixels(&inst->termwin, w, h);
@ -356,7 +357,7 @@ static void gtk_seat_update_specials_menu(Seat *seat);
static void gtk_seat_set_busy_status(Seat *seat, BusyStatus status);
static const char *gtk_seat_get_x_display(Seat *seat);
#ifndef NOT_X_WINDOWS
static int gtk_seat_get_windowid(Seat *seat, long *id);
static bool gtk_seat_get_windowid(Seat *seat, long *id);
#endif
static const SeatVtable gtk_seat_vt = {
@ -469,7 +470,7 @@ void unregister_dialog(Seat *seat, enum DialogSlot slot)
* Minimise or restore the window in response to a server-side
* request.
*/
static void gtkwin_set_minimised(TermWin *tw, int minimised)
static void gtkwin_set_minimised(TermWin *tw, bool minimised)
{
/*
* GTK 1.2 doesn't know how to do this.
@ -507,7 +508,7 @@ static void gtkwin_move(TermWin *tw, int x, int y)
* Move the window to the top or bottom of the z-order in response
* to a server-side request.
*/
static void gtkwin_set_zorder(TermWin *tw, int top)
static void gtkwin_set_zorder(TermWin *tw, bool top)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
if (top)
@ -529,7 +530,7 @@ static void gtkwin_refresh(TermWin *tw)
* Maximise or restore the window in response to a server-side
* request.
*/
static void gtkwin_set_maximised(TermWin *tw, int maximised)
static void gtkwin_set_maximised(TermWin *tw, bool maximised)
{
/*
* GTK 1.2 doesn't know how to do this.
@ -546,7 +547,7 @@ static void gtkwin_set_maximised(TermWin *tw, int maximised)
/*
* Report whether the window is minimised, for terminal reports.
*/
static int gtkwin_is_minimised(TermWin *tw)
static bool gtkwin_is_minimised(TermWin *tw)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
return !gdk_window_is_viewable(gtk_widget_get_window(inst->window));
@ -594,7 +595,7 @@ static void gtkwin_get_pixels(TermWin *tw, int *x, int *y)
* raise it, so that the user realises they've already been asked this
* question.
*/
static int find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot)
static bool find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot)
{
GtkWidget *dialog = inst->dialogs[slot];
if (!dialog)
@ -610,7 +611,7 @@ static int find_and_raise_dialog(GtkFrontend *inst, enum DialogSlot slot)
/*
* Return the window or icon title.
*/
static const char *gtkwin_get_title(TermWin *tw, int icon)
static const char *gtkwin_get_title(TermWin *tw, bool icon)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
return icon ? inst->icontitle : inst->wintitle;
@ -683,10 +684,10 @@ static void update_mouseptr(GtkFrontend *inst)
}
}
static void show_mouseptr(GtkFrontend *inst, int show)
static void show_mouseptr(GtkFrontend *inst, bool show)
{
if (!conf_get_bool(inst->conf, CONF_hide_mouseptr))
show = 1;
show = true;
inst->mouseptr_visible = show;
update_mouseptr(inst);
}
@ -695,7 +696,8 @@ static void draw_backing_rect(GtkFrontend *inst);
static void drawing_area_setup(GtkFrontend *inst, int width, int height)
{
int w, h, new_scale, need_size = 0;
int w, h, new_scale;
bool need_size = false;
/*
* See if the terminal size has changed.
@ -979,7 +981,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
GtkFrontend *inst = (GtkFrontend *)data;
char output[256];
wchar_t ucsoutput[2];
int ucsval, start, end, special, output_charset, use_ucsoutput;
int ucsval, start, end, output_charset;
bool special, use_ucsoutput;
bool nethack_mode, app_keypad_mode;
bool generated_something = false;
@ -1327,8 +1330,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
(event->keyval == GDK_KEY_C || event->keyval == GDK_KEY_c ||
event->keyval == GDK_KEY_V || event->keyval == GDK_KEY_v)) {
int cfgval = conf_get_int(inst->conf, CONF_ctrlshiftcv);
int paste = (event->keyval == GDK_KEY_V ||
event->keyval == GDK_KEY_v);
bool paste = (event->keyval == GDK_KEY_V ||
event->keyval == GDK_KEY_v);
switch (cfgval) {
case CLIPUI_IMPLICIT:
@ -1454,7 +1457,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
event->keyval == GDK_KEY_KP_Page_Up)) {
/* nethack mode; do nothing */
} else {
int try_filter = true;
bool try_filter = true;
#ifdef META_MANUAL_MASK
if (event->state & META_MANUAL_MASK & inst->meta_mod_mask) {
@ -2129,7 +2132,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
output[end] = '\0'; /* NUL-terminate */
generated_something = true;
if (inst->ldisc)
ldisc_send(inst->ldisc, output+start, -2, 1);
ldisc_send(inst->ldisc, output+start, -2, true);
} else if (!inst->direct_to_font) {
if (!use_ucsoutput) {
#ifdef KEY_EVENT_DIAGNOSTICS
@ -2150,7 +2153,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
generated_something = true;
if (inst->ldisc)
lpage_send(inst->ldisc, output_charset, output+start,
end-start, 1);
end-start, true);
} else {
#ifdef KEY_EVENT_DIAGNOSTICS
char *string_string = dupstr("");
@ -2174,7 +2177,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
*/
generated_something = true;
if (inst->ldisc)
luni_send(inst->ldisc, ucsoutput+start, end-start, 1);
luni_send(inst->ldisc, ucsoutput+start, end-start, true);
}
} else {
/*
@ -2198,10 +2201,10 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
#endif
generated_something = true;
if (inst->ldisc)
ldisc_send(inst->ldisc, output+start, end-start, 1);
ldisc_send(inst->ldisc, output+start, end-start, true);
}
show_mouseptr(inst, 0);
show_mouseptr(inst, false);
term_seen_key_event(inst->term);
}
@ -2231,8 +2234,8 @@ void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data)
#endif
if (inst->ldisc)
lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), 1);
show_mouseptr(inst, 0);
lpage_send(inst->ldisc, CS_UTF8, str, strlen(str), true);
show_mouseptr(inst, false);
term_seen_key_event(inst->term);
key_pressed(inst);
}
@ -2244,9 +2247,10 @@ void input_method_commit_event(GtkIMContext *imc, gchar *str, gpointer data)
gboolean scroll_internal(GtkFrontend *inst, gdouble delta, guint state,
gdouble ex, gdouble ey)
{
int shift, ctrl, alt, x, y, raw_mouse_mode;
int x, y;
bool shift, ctrl, alt, raw_mouse_mode;
show_mouseptr(inst, 1);
show_mouseptr(inst, true);
shift = state & GDK_SHIFT_MASK;
ctrl = state & GDK_CONTROL_MASK;
@ -2295,12 +2299,13 @@ gboolean scroll_internal(GtkFrontend *inst, gdouble delta, guint state,
static gboolean button_internal(GtkFrontend *inst, GdkEventButton *event)
{
int shift, ctrl, alt, x, y, button, act, raw_mouse_mode;
bool shift, ctrl, alt, raw_mouse_mode;
int x, y, button, act;
/* Remember the timestamp. */
inst->input_event_time = event->time;
show_mouseptr(inst, 1);
show_mouseptr(inst, true);
shift = event->state & GDK_SHIFT_MASK;
ctrl = event->state & GDK_CONTROL_MASK;
@ -2420,12 +2425,13 @@ gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event, gpointer data)
gint motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer data)
{
GtkFrontend *inst = (GtkFrontend *)data;
int shift, ctrl, alt, x, y, button;
bool shift, ctrl, alt;
int x, y, button;
/* Remember the timestamp. */
inst->input_event_time = event->time;
show_mouseptr(inst, 1);
show_mouseptr(inst, true);
shift = event->state & GDK_SHIFT_MASK;
ctrl = event->state & GDK_CONTROL_MASK;
@ -2583,7 +2589,7 @@ gint focus_event(GtkWidget *widget, GdkEventFocus *event, gpointer data)
GtkFrontend *inst = (GtkFrontend *)data;
term_set_focus(inst->term, event->in);
term_update(inst->term);
show_mouseptr(inst, 1);
show_mouseptr(inst, true);
return false;
}
@ -2597,7 +2603,7 @@ static void gtk_seat_set_busy_status(Seat *seat, BusyStatus status)
/*
* set or clear the "raw mouse message" mode
*/
static void gtkwin_set_raw_mouse_mode(TermWin *tw, int activate)
static void gtkwin_set_raw_mouse_mode(TermWin *tw, bool activate)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
activate = activate && !conf_get_bool(inst->conf, CONF_no_mouse_rep);
@ -2779,7 +2785,7 @@ static void gtkwin_palette_set(TermWin *tw, int n, int r, int g, int b)
}
}
static int gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
static bool gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
if (n < 0 || n >= NALLCOLOURS)
@ -2939,7 +2945,7 @@ static void clipboard_clear(GtkClipboard *clipboard, gpointer data)
static void gtkwin_clip_write(
TermWin *tw, int clipboard, wchar_t *data, int *attr,
truecolour *truecolour, int len, int must_deselect)
truecolour *truecolour, int len, bool must_deselect)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
struct clipboard_state *state = &inst->clipstates[clipboard];
@ -3087,7 +3093,7 @@ static char *retrieve_cutbuffer(GtkFrontend *inst, int *nbytes)
static void gtkwin_clip_write(
TermWin *tw, int clipboard, wchar_t *data, int *attr,
truecolour *truecolour, int len, int must_deselect)
truecolour *truecolour, int len, bool must_deselect)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
struct clipboard_state *state = &inst->clipstates[clipboard];
@ -3279,8 +3285,8 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
int length;
#ifndef NOT_X_WINDOWS
char **list;
int free_list_required = 0;
int free_required = 0;
bool free_list_required = false;
bool free_required = false;
#endif
int charset;
GdkAtom seldata_target = gtk_selection_data_get_target(seldata);
@ -3338,7 +3344,7 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
/* Xterm is rumoured to expect Latin-1, though I havn't checked the
* source, so use that as a de-facto standard. */
charset = CS_ISO8859_1;
free_required = 1;
free_required = true;
#else
return;
#endif
@ -3361,7 +3367,7 @@ static void selection_received(GtkWidget *widget, GtkSelectionData *seldata,
text = list[0];
length = strlen(list[0]);
charset = CS_UTF8;
free_list_required = 1;
free_list_required = true;
} else
#endif
{
@ -3572,7 +3578,7 @@ static int gtkwin_char_width(TermWin *tw, int uc)
return 1;
}
static int gtkwin_setup_draw_ctx(TermWin *tw)
static bool gtkwin_setup_draw_ctx(TermWin *tw)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
@ -3649,7 +3655,7 @@ static void draw_update(GtkFrontend *inst, int x, int y, int w, int h)
#ifdef DRAW_TEXT_CAIRO
static void cairo_set_source_rgb_dim(cairo_t *cr, double r, double g, double b,
int dim)
bool dim)
{
if (dim)
cairo_set_source_rgb(cr, r * 2 / 3, g * 2 / 3, b * 2 / 3);
@ -3658,7 +3664,7 @@ static void cairo_set_source_rgb_dim(cairo_t *cr, double r, double g, double b,
}
#endif
static void draw_set_colour(GtkFrontend *inst, int col, int dim)
static void draw_set_colour(GtkFrontend *inst, int col, bool dim)
{
#ifdef DRAW_TEXT_GDK
if (inst->uctx.type == DRAWTYPE_GDK) {
@ -3688,7 +3694,7 @@ static void draw_set_colour(GtkFrontend *inst, int col, int dim)
#endif
}
static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, int dim)
static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, bool dim)
{
#ifdef DRAW_TEXT_GDK
if (inst->uctx.type == DRAWTYPE_GDK) {
@ -3717,7 +3723,7 @@ static void draw_set_colour_rgb(GtkFrontend *inst, optionalrgb orgb, int dim)
#endif
}
static void draw_rectangle(GtkFrontend *inst, int filled,
static void draw_rectangle(GtkFrontend *inst, bool filled,
int x, int y, int w, int h)
{
#ifdef DRAW_TEXT_GDK
@ -3801,8 +3807,8 @@ static void draw_line(GtkFrontend *inst, int x0, int y0, int x1, int y1)
}
static void draw_stretch_before(GtkFrontend *inst, int x, int y,
int w, int wdouble,
int h, int hdouble, int hbothalf)
int w, bool wdouble,
int h, bool hdouble, bool hbothalf)
{
#ifdef DRAW_TEXT_CAIRO
if (inst->uctx.type == DRAWTYPE_CAIRO) {
@ -3836,8 +3842,8 @@ static void draw_stretch_before(GtkFrontend *inst, int x, int y,
}
static void draw_stretch_after(GtkFrontend *inst, int x, int y,
int w, int wdouble,
int h, int hdouble, int hbothalf)
int w, bool wdouble,
int h, bool hdouble, bool hbothalf)
{
#ifdef DRAW_TEXT_GDK
#ifndef NO_BACKING_PIXMAPS
@ -3902,7 +3908,7 @@ static void draw_backing_rect(GtkFrontend *inst)
w = inst->width * inst->font_width + 2*inst->window_border;
h = inst->height * inst->font_height + 2*inst->window_border;
draw_set_colour(inst, 258, false);
draw_rectangle(inst, 1, 0, 0, w, h);
draw_rectangle(inst, true, 0, 0, w, h);
draw_update(inst, 0, 0, w, h);
win_free_draw_ctx(&inst->termwin);
}
@ -3918,8 +3924,9 @@ static void do_text_internal(
unsigned long attr, int lattr, truecolour truecolour)
{
int ncombining;
int nfg, nbg, t, fontid, shadow, rlen, widefactor, bold;
int monochrome =
int nfg, nbg, t, fontid, rlen, widefactor;
bool bold;
bool monochrome =
gdk_visual_get_depth(gtk_widget_get_visual(inst->area)) == 1;
if (attr & TATTR_COMBINING) {
@ -3959,7 +3966,7 @@ static void do_text_internal(
attr &= ~ATTR_DIM; /* don't dim the cursor */
}
fontid = shadow = 0;
fontid = 0;
if (attr & ATTR_WIDE) {
widefactor = 2;
@ -3969,10 +3976,10 @@ static void do_text_internal(
}
if ((attr & ATTR_BOLD) && (inst->bold_style & 1)) {
bold = 1;
bold = true;
fontid |= 1;
} else {
bold = 0;
bold = false;
}
if (!inst->fonts[fontid]) {
@ -4104,18 +4111,19 @@ static void gtkwin_draw_cursor(
unsigned long attr, int lattr, truecolour truecolour)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
int active, passive, widefactor;
bool active, passive;
int widefactor;
if (attr & TATTR_PASCURS) {
attr &= ~TATTR_PASCURS;
passive = 1;
passive = true;
} else
passive = 0;
passive = false;
if ((attr & TATTR_ACTCURS) && inst->cursor_type != 0) {
attr &= ~TATTR_ACTCURS;
active = 1;
active = true;
} else
active = 0;
active = false;
do_text_internal(inst, x, y, text, len, attr, lattr, truecolour);
if (attr & TATTR_COMBINING)
@ -4257,7 +4265,7 @@ static const char *gtk_seat_get_x_display(Seat *seat)
}
#ifndef NOT_X_WINDOWS
static int gtk_seat_get_windowid(Seat *seat, long *id)
static bool gtk_seat_get_windowid(Seat *seat, long *id)
{
GtkFrontend *inst = container_of(seat, GtkFrontend, seat);
GdkWindow *window = gtk_widget_get_window(inst->area);
@ -4268,7 +4276,7 @@ static int gtk_seat_get_windowid(Seat *seat, long *id)
}
#endif
static int gtkwin_is_utf8(TermWin *tw)
static bool gtkwin_is_utf8(TermWin *tw)
{
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
return inst->ucsdata.line_codepage == CS_UTF8;
@ -4276,7 +4284,7 @@ static int gtkwin_is_utf8(TermWin *tw)
char *setup_fonts_ucs(GtkFrontend *inst)
{
int shadowbold = conf_get_bool(inst->conf, CONF_shadowbold);
bool shadowbold = conf_get_bool(inst->conf, CONF_shadowbold);
int shadowboldoffset = conf_get_int(inst->conf, CONF_shadowboldoffset);
FontSpec *fs;
unifont *fonts[4];
@ -4643,7 +4651,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
ctx->newconf = conf_copy(inst->conf);
dialog = create_config_box(
title, ctx->newconf, 1,
title, ctx->newconf, true,
inst->backend ? backend_cfg_info(inst->backend) : 0,
after_change_settings_dialog, ctx);
register_dialog(&inst->seat, DIALOG_SLOT_RECONFIGURE, dialog);
@ -4663,7 +4671,8 @@ static void after_change_settings_dialog(void *vctx, int retval)
*(struct after_change_settings_dialog_ctx *)vctx;
GtkFrontend *inst = ctx.inst;
Conf *oldconf = inst->conf, *newconf = ctx.newconf;
int i, j, need_size;
int i, j;
bool need_size;
sfree(vctx); /* we've copied this already */
@ -5476,7 +5485,7 @@ void new_session_window(Conf *conf, const char *geometry_string)
{
GtkWidget *menuitem;
char *s;
extern const int use_event_log, new_session, saved_sessions;
extern const bool use_event_log, new_session, saved_sessions;
inst->menu = gtk_menu_new();
@ -5552,7 +5561,7 @@ void new_session_window(Conf *conf, const char *geometry_string)
inst->waitcursor = make_mouse_ptr(inst, GDK_WATCH);
inst->blankcursor = make_mouse_ptr(inst, -1);
inst->currcursor = inst->textcursor;
show_mouseptr(inst, 1);
show_mouseptr(inst, true);
inst->eventlogstuff = eventlogstuff_new();

View File

@ -49,7 +49,7 @@
* pure-CLI utilities, so that Unix Plink, PSFTP etc don't announce
* themselves incongruously as having something to do with GTK. */
#define BUILDINFO_PLATFORM_CLI "Unix"
extern const int buildinfo_gtk_relevant;
extern const bool buildinfo_gtk_relevant;
#define BUILDINFO_PLATFORM (buildinfo_gtk_relevant ? \
BUILDINFO_PLATFORM_GTK : BUILDINFO_PLATFORM_CLI)
@ -58,7 +58,7 @@ char *buildinfo_gtk_version(void);
struct Filename {
char *path;
};
FILE *f_open(const struct Filename *, char const *, int);
FILE *f_open(const struct Filename *, char const *, bool);
struct FontSpec {
char *name; /* may be "" to indicate no selected font at all */
@ -207,7 +207,7 @@ void unregister_dialog(Seat *seat, enum DialogSlot slot);
/* Things pterm.c needs from gtkdlg.c */
#ifdef MAY_REFER_TO_GTK_IN_HEADERS
GtkWidget *create_config_box(const char *title, Conf *conf,
int midsession, int protcfginfo,
bool midsession, int protcfginfo,
post_dialog_fn_t after, void *afterctx);
#endif
void nonfatal_message_box(void *window, const char *msg);
@ -243,7 +243,7 @@ struct message_box_buttons {
extern const struct message_box_buttons buttons_yn, buttons_ok;
GtkWidget *create_message_box(
GtkWidget *parentwin, const char *title, const char *msg, int minwid,
int selectable, const struct message_box_buttons *buttons,
bool selectable, const struct message_box_buttons *buttons,
post_dialog_fn_t after, void *afterctx);
#endif
@ -280,10 +280,12 @@ void uxsel_input_remove(uxsel_id *id);
/* uxcfg.c */
struct controlbox;
void unix_setup_config_box(struct controlbox *b, int midsession, int protocol);
void unix_setup_config_box(
struct controlbox *b, bool midsession, int protocol);
/* gtkcfg.c */
void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
void gtk_setup_config_box(
struct controlbox *b, bool midsession, void *window);
/*
* In the Unix Unicode layer, DEFAULT_CODEPAGE is a special value
@ -301,13 +303,13 @@ void gtk_setup_config_box(struct controlbox *b, int midsession, void *window);
/* BSD-semantics version of signal(), and another helpful function */
void (*putty_signal(int sig, void (*func)(int)))(int);
void block_signal(int sig, int block_it);
void block_signal(int sig, bool block_it);
/* uxmisc.c */
void cloexec(int);
void noncloexec(int);
int nonblock(int);
int no_nonblock(int);
bool nonblock(int);
bool no_nonblock(int);
char *make_dir_and_check_ours(const char *dirname);
char *make_dir_path(const char *path, mode_t mode);
@ -315,8 +317,8 @@ char *make_dir_path(const char *path, mode_t mode);
* Exports from unicode.c.
*/
struct unicode_data;
int init_ucs(struct unicode_data *ucsdata, char *line_codepage,
int utf8_override, int font_charset, int vtmode);
bool init_ucs(struct unicode_data *ucsdata, char *line_codepage,
bool utf8_override, int font_charset, int vtmode);
/*
* Spare functions exported directly from uxnet.c.
@ -342,7 +344,7 @@ extern const struct BackendVtable serial_backend;
/*
* uxpeer.c, wrapping getsockopt(SO_PEERCRED).
*/
int so_peercred(int fd, int *pid, int *uid, int *gid);
bool so_peercred(int fd, int *pid, int *uid, int *gid);
/*
* uxfdsock.c.

View File

@ -17,7 +17,7 @@
void platform_get_x11_auth(struct X11Display *disp, Conf *conf)
{
char *xauthfile;
int needs_free;
bool needs_free;
/*
* Find the .Xauthority file.
@ -39,7 +39,7 @@ void platform_get_x11_auth(struct X11Display *disp, Conf *conf)
}
}
const int platform_uses_x11_unix_by_default = true;
const bool platform_uses_x11_unix_by_default = true;
int platform_make_x11_server(Plug *plug, const char *progname, int mindisp,
const char *screen_number_suffix,

View File

@ -15,7 +15,7 @@
#include "tree234.h"
#include "puttymem.h"
int agent_exists(void)
bool agent_exists(void)
{
const char *p = getenv("SSH_AUTH_SOCK");
if (p && *p)
@ -54,12 +54,12 @@ static int agent_connfind(void *av, void *bv)
}
/*
* Attempt to read from an agent socket fd. Returns 0 if the expected
* response is as yet incomplete; returns 1 if it's either complete
* (conn->retbuf non-NULL and filled with something useful) or has
* failed totally (conn->retbuf is NULL).
* Attempt to read from an agent socket fd. Returns false if the
* expected response is as yet incomplete; returns true if it's either
* complete (conn->retbuf non-NULL and filled with something useful)
* or has failed totally (conn->retbuf is NULL).
*/
static int agent_try_read(agent_pending_query *conn)
static bool agent_try_read(agent_pending_query *conn)
{
int ret;
@ -69,7 +69,7 @@ static int agent_try_read(agent_pending_query *conn)
if (conn->retbuf != conn->sizebuf) sfree(conn->retbuf);
conn->retbuf = NULL;
conn->retlen = 0;
return 1;
return true;
}
conn->retlen += ret;
if (conn->retsize == 4 && conn->retlen == 4) {
@ -77,7 +77,7 @@ static int agent_try_read(agent_pending_query *conn)
if (conn->retsize <= 0) {
conn->retbuf = NULL;
conn->retlen = 0;
return -1; /* way too large */
return true; /* way too large */
}
assert(conn->retbuf == conn->sizebuf);
conn->retbuf = snewn(conn->retsize, char);
@ -85,9 +85,9 @@ static int agent_try_read(agent_pending_query *conn)
}
if (conn->retlen < conn->retsize)
return 0; /* more data to come */
return false; /* more data to come */
return 1;
return true;
}
void agent_cancel_query(agent_pending_query *conn)

View File

@ -10,7 +10,7 @@
#include "dialog.h"
#include "storage.h"
void unix_setup_config_box(struct controlbox *b, int midsession, int protocol)
void unix_setup_config_box(struct controlbox *b, bool midsession, int protocol)
{
struct controlset *s;
union control *c;
@ -29,7 +29,7 @@ void unix_setup_config_box(struct controlbox *b, int midsession, int protocol)
*/
s = ctrl_getset(b, "Terminal", "printing", "Remote-controlled printing");
assert(s->ncontrols == 1 && s->ctrls[0]->generic.type == CTRL_EDITBOX);
s->ctrls[0]->editbox.has_list = 0;
s->ctrls[0]->editbox.has_list = false;
/*
* Unix supports a local-command proxy. This also means we must

View File

@ -21,10 +21,10 @@
#include "storage.h"
#include "ssh.h"
int console_batch_mode = false;
bool console_batch_mode = false;
static struct termios orig_termios_stderr;
static int stderr_is_a_tty;
static bool stderr_is_a_tty;
void stderr_tty_init()
{
@ -136,7 +136,7 @@ static int block_and_read(int fd, void *buf, size_t len)
#ifdef EWOULDBLOCK
(errno == EWOULDBLOCK) ||
#endif
0)) {
false)) {
fd_set rfds;
FD_ZERO(&rfds);
@ -595,7 +595,7 @@ int console_get_userpass_input(prompts_t *p)
return 1; /* success */
}
int is_interactive(void)
bool is_interactive(void)
{
return isatty(0);
}

View File

@ -235,7 +235,7 @@ static void fdsocket_flush(Socket *s)
/* do nothing */
}
static void fdsocket_set_frozen(Socket *s, int is_frozen)
static void fdsocket_set_frozen(Socket *s, bool is_frozen)
{
FdSocket *fds = container_of(s, FdSocket, sock);

View File

@ -58,12 +58,12 @@ const char *filename_to_str(const Filename *fn)
return fn->path;
}
int filename_equal(const Filename *f1, const Filename *f2)
bool filename_equal(const Filename *f1, const Filename *f2)
{
return !strcmp(f1->path, f2->path);
}
int filename_is_null(const Filename *fn)
bool filename_is_null(const Filename *fn)
{
return !fn->path[0];
}
@ -202,7 +202,7 @@ void noncloexec(int fd) {
exit(1);
}
}
int nonblock(int fd) {
bool nonblock(int fd) {
int fdflags;
fdflags = fcntl(fd, F_GETFL);
@ -217,7 +217,7 @@ int nonblock(int fd) {
return fdflags & O_NONBLOCK;
}
int no_nonblock(int fd) {
bool no_nonblock(int fd) {
int fdflags;
fdflags = fcntl(fd, F_GETFL);
@ -233,7 +233,7 @@ int no_nonblock(int fd) {
return fdflags & O_NONBLOCK;
}
FILE *f_open(const Filename *filename, char const *mode, int is_private)
FILE *f_open(const Filename *filename, char const *mode, bool is_private)
{
if (!is_private) {
return fopen(filename->path, mode);
@ -330,7 +330,7 @@ char *make_dir_path(const char *path, mode_t mode)
}
}
int open_for_write_would_lose_data(const Filename *fn)
bool open_for_write_would_lose_data(const Filename *fn)
{
struct stat st;

View File

@ -64,20 +64,21 @@ struct NetSocket {
int s;
Plug *plug;
bufchain output_data;
int connected; /* irrelevant for listening sockets */
int writable;
int frozen; /* this causes readability notifications to be ignored */
int localhost_only; /* for listening sockets */
bool connected; /* irrelevant for listening sockets */
bool writable;
bool frozen; /* this causes readability notifications to be ignored */
bool localhost_only; /* for listening sockets */
char oobdata[1];
int sending_oob;
int oobpending; /* is there OOB data available to read? */
int oobinline;
bool oobpending; /* is there OOB data available to read? */
bool oobinline;
enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
int incomingeof;
bool incomingeof;
int pending_error; /* in case send() returns error */
int listener;
int nodelay, keepalive; /* for connect()-type sockets */
int privport, port; /* and again */
bool listener;
bool nodelay, keepalive; /* for connect()-type sockets */
bool privport;
int port; /* and again */
SockAddr *addr;
SockAddrStep step;
/*
@ -292,7 +293,7 @@ SockAddr *sk_nonamelookup(const char *host)
return ret;
}
static int sk_nextaddr(SockAddr *addr, SockAddrStep *step)
static bool sk_nextaddr(SockAddr *addr, SockAddrStep *step)
{
#ifndef NO_IPV6
if (step->ai && step->ai->ai_next) {
@ -362,7 +363,7 @@ static SockAddr sk_extractaddr_tmp(
return toret;
}
int sk_addr_needs_port(SockAddr *addr)
bool sk_addr_needs_port(SockAddr *addr)
{
if (addr->superfamily == UNRESOLVED || addr->superfamily == UNIX) {
return false;
@ -371,7 +372,7 @@ int sk_addr_needs_port(SockAddr *addr)
}
}
int sk_hostname_is_local(const char *name)
bool sk_hostname_is_local(const char *name)
{
return !strcmp(name, "localhost") ||
!strcmp(name, "::1") ||
@ -381,7 +382,7 @@ int sk_hostname_is_local(const char *name)
#define ipv4_is_loopback(addr) \
(((addr).s_addr & htonl(0xff000000)) == htonl(0x7f000000))
static int sockaddr_is_loopback(struct sockaddr *sa)
static bool sockaddr_is_loopback(struct sockaddr *sa)
{
union sockaddr_union *u = (union sockaddr_union *)sa;
switch (u->sa.sa_family) {
@ -398,12 +399,12 @@ static int sockaddr_is_loopback(struct sockaddr *sa)
}
}
int sk_address_is_local(SockAddr *addr)
bool sk_address_is_local(SockAddr *addr)
{
if (addr->superfamily == UNRESOLVED)
return 0; /* we don't know; assume not */
return false; /* we don't know; assume not */
else if (addr->superfamily == UNIX)
return 1;
return true;
else {
#ifndef NO_IPV6
return sockaddr_is_loopback(addr->ais->ai_addr);
@ -418,7 +419,7 @@ int sk_address_is_local(SockAddr *addr)
}
}
int sk_address_is_special_local(SockAddr *addr)
bool sk_address_is_special_local(SockAddr *addr)
{
return addr->superfamily == UNIX;
}
@ -502,7 +503,7 @@ static void sk_net_close(Socket *s);
static int sk_net_write(Socket *s, const void *data, int len);
static int sk_net_write_oob(Socket *s, const void *data, int len);
static void sk_net_write_eof(Socket *s);
static void sk_net_set_frozen(Socket *s, int is_frozen);
static void sk_net_set_frozen(Socket *s, bool is_frozen);
static SocketPeerInfo *sk_net_peer_info(Socket *s);
static const char *sk_net_socket_error(Socket *s);
@ -531,18 +532,18 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
ret->error = NULL;
ret->plug = plug;
bufchain_init(&ret->output_data);
ret->writable = 1; /* to start with */
ret->writable = true; /* to start with */
ret->sending_oob = 0;
ret->frozen = 1;
ret->localhost_only = 0; /* unused, but best init anyway */
ret->frozen = true;
ret->localhost_only = false; /* unused, but best init anyway */
ret->pending_error = 0;
ret->oobpending = false;
ret->outgoingeof = EOF_NO;
ret->incomingeof = false;
ret->listener = 0;
ret->listener = false;
ret->parent = ret->child = NULL;
ret->addr = NULL;
ret->connected = 1;
ret->connected = true;
ret->s = sockfd;
@ -551,7 +552,7 @@ static Socket *sk_net_accept(accept_ctx_t ctx, Plug *plug)
return &ret->sock;
}
ret->oobinline = 0;
ret->oobinline = false;
uxsel_tell(ret);
add234(sktree, ret);
@ -601,7 +602,7 @@ static int try_connect(NetSocket *sock)
cloexec(s);
if (sock->oobinline) {
int b = true;
int b = 1;
if (setsockopt(s, SOL_SOCKET, SO_OOBINLINE,
(void *) &b, sizeof(b)) < 0) {
err = errno;
@ -611,7 +612,7 @@ static int try_connect(NetSocket *sock)
}
if (sock->nodelay) {
int b = true;
int b = 1;
if (setsockopt(s, IPPROTO_TCP, TCP_NODELAY,
(void *) &b, sizeof(b)) < 0) {
err = errno;
@ -621,7 +622,7 @@ static int try_connect(NetSocket *sock)
}
if (sock->keepalive) {
int b = true;
int b = 1;
if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,
(void *) &b, sizeof(b)) < 0) {
err = errno;
@ -737,8 +738,8 @@ static int try_connect(NetSocket *sock)
* If we _don't_ get EWOULDBLOCK, the connect has completed
* and we should set the socket as connected and writable.
*/
sock->connected = 1;
sock->writable = 1;
sock->connected = true;
sock->writable = true;
}
uxsel_tell(sock);
@ -758,8 +759,8 @@ static int try_connect(NetSocket *sock)
return err;
}
Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
int nodelay, int keepalive, Plug *plug)
Socket *sk_new(SockAddr *addr, int port, bool privport, bool oobinline,
bool nodelay, bool keepalive, Plug *plug)
{
NetSocket *ret;
int err;
@ -772,17 +773,17 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
ret->error = NULL;
ret->plug = plug;
bufchain_init(&ret->output_data);
ret->connected = 0; /* to start with */
ret->writable = 0; /* to start with */
ret->connected = false; /* to start with */
ret->writable = false; /* to start with */
ret->sending_oob = 0;
ret->frozen = 0;
ret->localhost_only = 0; /* unused, but best init anyway */
ret->frozen = false;
ret->localhost_only = false; /* unused, but best init anyway */
ret->pending_error = 0;
ret->parent = ret->child = NULL;
ret->oobpending = false;
ret->outgoingeof = EOF_NO;
ret->incomingeof = false;
ret->listener = 0;
ret->listener = false;
ret->addr = addr;
START_STEP(ret->addr, ret->step);
ret->s = -1;
@ -804,7 +805,7 @@ Socket *sk_new(SockAddr *addr, int port, int privport, int oobinline,
}
Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
int local_host_only, int orig_address_family)
bool local_host_only, int orig_address_family)
{
int s;
#ifndef NO_IPV6
@ -827,16 +828,16 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
ret->error = NULL;
ret->plug = plug;
bufchain_init(&ret->output_data);
ret->writable = 0; /* to start with */
ret->writable = false; /* to start with */
ret->sending_oob = 0;
ret->frozen = 0;
ret->frozen = false;
ret->localhost_only = local_host_only;
ret->pending_error = 0;
ret->parent = ret->child = NULL;
ret->oobpending = false;
ret->outgoingeof = EOF_NO;
ret->incomingeof = false;
ret->listener = 1;
ret->listener = true;
ret->addr = NULL;
ret->s = -1;
@ -879,7 +880,7 @@ Socket *sk_newlistener(const char *srcaddr, int port, Plug *plug,
cloexec(s);
ret->oobinline = 0;
ret->oobinline = false;
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
(const char *)&on, sizeof(on)) < 0) {
@ -1267,7 +1268,7 @@ static void net_select_result(int fd, int event)
int ret;
char buf[20480]; /* nice big buffer for plenty of speed */
NetSocket *s;
u_long atmark;
bool atmark;
/* Find the Socket structure */
s = find234(sktree, &fd, cmpforsearch);
@ -1359,11 +1360,14 @@ static void net_select_result(int fd, int event)
* (data prior to urgent).
*/
if (s->oobinline && s->oobpending) {
atmark = 1;
if (ioctl(s->s, SIOCATMARK, &atmark) == 0 && atmark)
s->oobpending = false; /* clear this indicator */
int atmark_from_ioctl;
if (ioctl(s->s, SIOCATMARK, &atmark_from_ioctl) == 0) {
atmark = atmark_from_ioctl;
if (atmark)
s->oobpending = false; /* clear this indicator */
}
} else
atmark = 1;
atmark = true;
ret = recv(s->s, buf, s->oobpending ? 1 : sizeof(buf), 0);
noise_ultralight(ret);
@ -1441,11 +1445,12 @@ static void net_select_result(int fd, int event)
sk_addr_free(s->addr);
s->addr = NULL;
}
s->connected = s->writable = 1;
s->connected = true;
s->writable = true;
uxsel_tell(s);
} else {
int bufsize_before, bufsize_after;
s->writable = 1;
s->writable = true;
bufsize_before = s->sending_oob + bufchain_size(&s->output_data);
try_send(s);
bufsize_after = s->sending_oob + bufchain_size(&s->output_data);
@ -1471,7 +1476,7 @@ static const char *sk_net_socket_error(Socket *sock)
return s->error;
}
static void sk_net_set_frozen(Socket *sock, int is_frozen)
static void sk_net_set_frozen(Socket *sock, bool is_frozen)
{
NetSocket *s = container_of(sock, NetSocket, sock);
if (s->frozen == is_frozen)
@ -1665,16 +1670,16 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug)
ret->error = NULL;
ret->plug = plug;
bufchain_init(&ret->output_data);
ret->writable = 0; /* to start with */
ret->writable = false; /* to start with */
ret->sending_oob = 0;
ret->frozen = 0;
ret->frozen = false;
ret->localhost_only = true;
ret->pending_error = 0;
ret->parent = ret->child = NULL;
ret->oobpending = false;
ret->outgoingeof = EOF_NO;
ret->incomingeof = false;
ret->listener = 1;
ret->listener = true;
ret->addr = listenaddr;
ret->s = -1;
@ -1691,7 +1696,7 @@ Socket *new_unix_listener(SockAddr *listenaddr, Plug *plug)
cloexec(s);
ret->oobinline = 0;
ret->oobinline = false;
memset(&u, '\0', sizeof(u));
u.su.sun_family = AF_UNIX;

View File

@ -16,28 +16,28 @@
#include "ssh.h"
#include "storage.h"
static int read_dev_urandom(char *buf, int len)
static bool read_dev_urandom(char *buf, int len)
{
int fd;
int ngot, ret;
fd = open("/dev/urandom", O_RDONLY);
if (fd < 0)
return 0;
return false;
ngot = 0;
while (ngot < len) {
ret = read(fd, buf+ngot, len-ngot);
if (ret < 0) {
close(fd);
return 0;
return false;
}
ngot += ret;
}
close(fd);
return 1;
return true;
}
/*
@ -52,10 +52,10 @@ void noise_get_heavy(void (*func) (void *, int))
char buf[512];
FILE *fp;
int ret;
int got_dev_urandom = 0;
bool got_dev_urandom = false;
if (read_dev_urandom(buf, 32)) {
got_dev_urandom = 1;
got_dev_urandom = true;
func(buf, 32);
}

View File

@ -16,7 +16,7 @@
#include "putty.h"
int so_peercred(int fd, int *pid, int *uid, int *gid)
bool so_peercred(int fd, int *pid, int *uid, int *gid)
{
#ifdef HAVE_SO_PEERCRED
struct ucred cr;

View File

@ -114,7 +114,7 @@ void keylist_update(void)
const char *const appname = "Pageant";
static int time_to_die = false;
static bool time_to_die = false;
/* Stub functions to permit linking against x11fwd.c. These never get
* used, because in LIFE_X11 mode we connect to the X server using a
@ -122,30 +122,30 @@ static int time_to_die = false;
* forwarding too. */
void chan_remotely_opened_confirmation(Channel *chan) { }
void chan_remotely_opened_failure(Channel *chan, const char *err) { }
int chan_default_want_close(Channel *chan, int s, int r) { return false; }
int chan_no_exit_status(Channel *ch, int s) { return false; }
int chan_no_exit_signal(Channel *ch, ptrlen s, int c, ptrlen m)
bool chan_default_want_close(Channel *chan, bool s, bool r) { return false; }
bool chan_no_exit_status(Channel *ch, int s) { return false; }
bool chan_no_exit_signal(Channel *ch, ptrlen s, bool c, ptrlen m)
{ return false; }
int chan_no_exit_signal_numeric(Channel *ch, int s, int c, ptrlen m)
bool chan_no_exit_signal_numeric(Channel *ch, int s, bool c, ptrlen m)
{ return false; }
int chan_no_run_shell(Channel *chan) { return false; }
int chan_no_run_command(Channel *chan, ptrlen command) { return false; }
int chan_no_run_subsystem(Channel *chan, ptrlen subsys) { return false; }
int chan_no_enable_x11_forwarding(
Channel *chan, int oneshot, ptrlen authproto, ptrlen authdata,
bool chan_no_run_shell(Channel *chan) { return false; }
bool chan_no_run_command(Channel *chan, ptrlen command) { return false; }
bool chan_no_run_subsystem(Channel *chan, ptrlen subsys) { return false; }
bool chan_no_enable_x11_forwarding(
Channel *chan, bool oneshot, ptrlen authproto, ptrlen authdata,
unsigned screen_number) { return false; }
int chan_no_enable_agent_forwarding(Channel *chan) { return false; }
int chan_no_allocate_pty(
bool chan_no_enable_agent_forwarding(Channel *chan) { return false; }
bool chan_no_allocate_pty(
Channel *chan, ptrlen termtype, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight, struct ssh_ttymodes modes)
{ return false; }
int chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) { return false; }
int chan_no_send_break(Channel *chan, unsigned length) { return false; }
int chan_no_send_signal(Channel *chan, ptrlen signame) { return false; }
int chan_no_change_window_size(
bool chan_no_set_env(Channel *chan, ptrlen var, ptrlen value) { return false; }
bool chan_no_send_break(Channel *chan, unsigned length) { return false; }
bool chan_no_send_signal(Channel *chan, ptrlen signame) { return false; }
bool chan_no_change_window_size(
Channel *chan, unsigned width, unsigned height,
unsigned pixwidth, unsigned pixheight) { return false; }
void chan_no_request_response(Channel *chan, int success) {}
void chan_no_request_response(Channel *chan, bool success) {}
/*
* These functions are part of the plug for our connection to the X
@ -158,7 +158,7 @@ static void x11_log(Plug *p, int type, SockAddr *addr, int port,
static void x11_receive(Plug *plug, int urgent, char *data, int len) {}
static void x11_sent(Plug *plug, int bufsize) {}
static void x11_closing(Plug *plug, const char *error_msg, int error_code,
int calling_back)
bool calling_back)
{
time_to_die = true;
}
@ -206,7 +206,7 @@ void pageant_print_env(int pid)
}
}
void pageant_fork_and_print_env(int retain_tty)
void pageant_fork_and_print_env(bool retain_tty)
{
pid_t pid = fork();
if (pid == -1) {
@ -279,7 +279,7 @@ struct cmdline_key_action {
const char *filename;
};
int is_agent_action(keyact action)
bool is_agent_action(keyact action)
{
return action == KEYACT_AGENT_LOAD;
}
@ -299,7 +299,7 @@ void add_keyact(keyact action, const char *filename)
keyact_tail = a;
}
int have_controlling_tty(void)
bool have_controlling_tty(void)
{
int fd = open("/dev/tty", O_RDONLY);
if (fd < 0) {
@ -347,11 +347,11 @@ static char *askpass_tty(const char *prompt)
static char *askpass_gui(const char *prompt)
{
char *passphrase;
int success;
bool success;
/* in gtkask.c */
char *gtk_askpass_main(const char *display, const char *wintitle,
const char *prompt, int *success);
const char *prompt, bool *success);
passphrase = gtk_askpass_main(
display, "Pageant passphrase prompt", prompt, &success);
@ -395,10 +395,11 @@ static char *askpass(const char *prompt)
}
}
static int unix_add_keyfile(const char *filename_str)
static bool unix_add_keyfile(const char *filename_str)
{
Filename *filename = filename_from_str(filename_str);
int status, ret;
int status;
bool ret;
char *err;
ret = true;
@ -457,12 +458,12 @@ void key_list_callback(void *ctx, const char *fingerprint,
struct key_find_ctx {
const char *string;
int match_fp, match_comment;
bool match_fp, match_comment;
struct pageant_pubkey *found;
int nfound;
};
int match_fingerprint_string(const char *string, const char *fingerprint)
bool match_fingerprint_string(const char *string, const char *fingerprint)
{
const char *hash;
@ -503,8 +504,8 @@ struct pageant_pubkey *find_key(const char *string, char **retstr)
{
struct key_find_ctx actx, *ctx = &actx;
struct pageant_pubkey key_in, *key_ret;
int try_file = true, try_fp = true, try_comment = true;
int file_errors = false;
bool try_file = true, try_fp = true, try_comment = true;
bool file_errors = false;
/*
* Trim off disambiguating prefixes telling us how to interpret
@ -512,17 +513,21 @@ struct pageant_pubkey *find_key(const char *string, char **retstr)
*/
if (!strncmp(string, "file:", 5)) {
string += 5;
try_fp = try_comment = false;
try_fp = false;
try_comment = false;
file_errors = true; /* also report failure to load the file */
} else if (!strncmp(string, "comment:", 8)) {
string += 8;
try_file = try_fp = false;
try_file = false;
try_fp = false;
} else if (!strncmp(string, "fp:", 3)) {
string += 3;
try_file = try_comment = false;
try_file = false;
try_comment = false;
} else if (!strncmp(string, "fingerprint:", 12)) {
string += 12;
try_file = try_comment = false;
try_file = false;
try_comment = false;
}
/*
@ -633,7 +638,7 @@ void run_client(void)
{
const struct cmdline_key_action *act;
struct pageant_pubkey *key;
int errors = false;
bool errors = false;
char *retstr;
if (!agent_exists()) {
@ -735,7 +740,7 @@ void run_agent(void)
int fd;
int i, fdcount, fdsize, fdstate;
int termination_pid = -1;
int errors = false;
bool errors = false;
Conf *conf;
const struct cmdline_key_action *act;
@ -799,7 +804,7 @@ void run_agent(void)
conn->plug.vt = &X11Connection_plugvt;
s = new_connection(sk_addr_dup(disp->addr),
disp->realhost, disp->port,
0, 1, 0, 0, &conn->plug, conf);
false, true, false, false, &conn->plug, conf);
if ((err = sk_socket_error(s)) != NULL) {
fprintf(stderr, "pageant: unable to connect to X server: %s", err);
exit(1);
@ -999,7 +1004,7 @@ void run_agent(void)
int main(int argc, char **argv)
{
int doing_opts = true;
bool doing_opts = true;
keyact curr_keyact = KEYACT_AGENT_LOAD;
const char *standalone_askpass_prompt = NULL;
@ -1121,9 +1126,9 @@ int main(int argc, char **argv)
* actions of KEYACT_AGENT_* type.
*/
{
int has_agent_actions = false;
int has_client_actions = false;
int has_lifetime = false;
bool has_agent_actions = false;
bool has_client_actions = false;
bool has_lifetime = false;
const struct cmdline_key_action *act;
for (act = keyact_head; act; act = act->next) {

View File

@ -38,7 +38,7 @@ void cmdline_error(const char *fmt, ...)
exit(1);
}
static int local_tty = false; /* do we have a local tty? */
static bool local_tty = false; /* do we have a local tty? */
static Backend *backend;
static Conf *conf;
@ -82,11 +82,11 @@ char *x_get_default(const char *key)
{
return NULL; /* this is a stub */
}
int term_ldisc(Terminal *term, int mode)
bool term_ldisc(Terminal *term, int mode)
{
return false;
}
static void plink_echoedit_update(Seat *seat, int echo, int edit)
static void plink_echoedit_update(Seat *seat, bool echo, bool edit)
{
/* Update stdin read mode to reflect changes in line discipline. */
struct termios mode;
@ -160,7 +160,7 @@ static char *plink_get_ttymode(Seat *seat, const char *mode)
#define GET_BOOL(ourname, uxname, uxmemb, transform) \
do { \
if (strcmp(mode, ourname) == 0) { \
int b = (orig_termios.uxmemb & uxname) != 0; \
bool b = (orig_termios.uxmemb & uxname) != 0; \
transform; \
return dupprintf("%d", b); \
} \
@ -325,7 +325,7 @@ void cleanup_termios(void)
bufchain stdout_data, stderr_data;
enum { EOF_NO, EOF_PENDING, EOF_SENT } outgoingeof;
int try_output(int is_stderr)
int try_output(bool is_stderr)
{
bufchain *chain = (is_stderr ? &stderr_data : &stdout_data);
int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO);
@ -333,7 +333,7 @@ int try_output(int is_stderr)
int sendlen, ret;
if (bufchain_size(chain) > 0) {
int prev_nonblock = nonblock(fd);
bool prev_nonblock = nonblock(fd);
do {
bufchain_prefix(chain, &senddata, &sendlen);
ret = write(fd, senddata, sendlen);
@ -354,7 +354,7 @@ int try_output(int is_stderr)
return bufchain_size(&stdout_data) + bufchain_size(&stderr_data);
}
static int plink_output(Seat *seat, int is_stderr, const void *data, int len)
static int plink_output(Seat *seat, bool is_stderr, const void *data, int len)
{
if (is_stderr) {
bufchain_add(&stderr_data, data, len);
@ -366,7 +366,7 @@ static int plink_output(Seat *seat, int is_stderr, const void *data, int len)
}
}
static int plink_eof(Seat *seat)
static bool plink_eof(Seat *seat)
{
assert(outgoingeof == EOF_NO);
outgoingeof = EOF_PENDING;
@ -551,21 +551,21 @@ static void version(void)
void frontend_net_error_pending(void) {}
const int share_can_be_downstream = true;
const int share_can_be_upstream = true;
const bool share_can_be_downstream = true;
const bool share_can_be_upstream = true;
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
int main(int argc, char **argv)
{
int sending;
bool sending;
int *fdlist;
int fd;
int i, fdcount, fdsize, fdstate;
int exitcode;
int errors;
int use_subsystem = 0;
int just_test_share_exists = false;
bool errors;
bool use_subsystem = false;
bool just_test_share_exists = false;
unsigned long now;
struct winsize size;
const struct BackendVtable *backvt;
@ -599,7 +599,7 @@ int main(int argc, char **argv)
loaded_session = false;
default_protocol = conf_get_int(conf, CONF_protocol);
default_port = conf_get_int(conf, CONF_port);
errors = 0;
errors = false;
{
/*
* Override the default protocol if PLINK_PROTOCOL is set.
@ -622,16 +622,16 @@ int main(int argc, char **argv)
if (ret == -2) {
fprintf(stderr,
"plink: option \"%s\" requires an argument\n", p);
errors = 1;
errors = true;
} else if (ret == 2) {
--argc, ++argv;
} else if (ret == 1) {
continue;
} else if (!strcmp(p, "-batch")) {
console_batch_mode = 1;
console_batch_mode = true;
} else if (!strcmp(p, "-s")) {
/* Save status to write to conf later. */
use_subsystem = 1;
use_subsystem = true;
} else if (!strcmp(p, "-V") || !strcmp(p, "--version")) {
version();
} else if (!strcmp(p, "--help")) {
@ -644,7 +644,7 @@ int main(int argc, char **argv)
if (argc <= 1) {
fprintf(stderr,
"plink: option \"-o\" requires an argument\n");
errors = 1;
errors = true;
} else {
--argc;
provide_xrm_string(*++argv);
@ -684,7 +684,7 @@ int main(int argc, char **argv)
break; /* done with cmdline */
} else {
fprintf(stderr, "plink: unknown option \"%s\"\n", p);
errors = 1;
errors = true;
}
}
@ -800,7 +800,7 @@ int main(int argc, char **argv)
const char *error;
char *realhost;
/* nodelay is only useful if stdin is a terminal device */
int nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0);
bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && isatty(0);
/* This is a good place for a fuzzer to fork us. */
#ifdef __AFL_HAVE_MANUAL_CONTROL

View File

@ -15,8 +15,8 @@
#include "proxy.h"
Socket *platform_new_connection(SockAddr *addr, const char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
int port, bool privport,
bool oobinline, bool nodelay, bool keepalive,
Plug *plug, Conf *conf)
{
char *cmd;

View File

@ -8,10 +8,11 @@
#include "putty.h"
const char *const appname = "pterm";
const int use_event_log = 0; /* pterm doesn't need it */
const int new_session = 0, saved_sessions = 0; /* or these */
const int dup_check_launchable = 0; /* no need to check host name in conf */
const int use_pty_argv = true;
const bool use_event_log = false; /* pterm doesn't need it */
const bool new_session = false, saved_sessions = false; /* or these */
const bool dup_check_launchable = false; /* no need to check host name
* in conf */
const bool use_pty_argv = true;
const struct BackendVtable *select_backend(Conf *conf)
{
@ -40,7 +41,7 @@ char *make_default_wintitle(char *hostname)
return dupstr("pterm");
}
void setup(int single)
void setup(bool single)
{
extern void pty_pre_init(void); /* declared in pty.c */

View File

@ -87,10 +87,10 @@ struct Pty {
char name[FILENAME_MAX];
pid_t child_pid;
int term_width, term_height;
int child_dead, finished;
bool child_dead, finished;
int exit_code;
bufchain output_data;
int pending_eof;
bool pending_eof;
Backend backend;
};
@ -178,7 +178,7 @@ static Pty *single_pty = NULL;
#ifndef OMIT_UTMP
static pid_t pty_utmp_helper_pid = -1;
static int pty_utmp_helper_pipe = -1;
static int pty_stamped_utmp;
static bool pty_stamped_utmp;
static struct utmpx utmp_entry;
#endif
@ -246,7 +246,7 @@ static void setup_utmp(char *ttyname, char *location)
}
#endif
pty_stamped_utmp = 1;
pty_stamped_utmp = true;
}
@ -273,7 +273,7 @@ static void cleanup_utmp(void)
pututxline(&utmp_entry);
endutxent();
pty_stamped_utmp = 0; /* ensure we never double-cleanup */
pty_stamped_utmp = false; /* ensure we never double-cleanup */
}
#endif
@ -285,7 +285,7 @@ static void sigchld_handler(int signum)
static void pty_setup_sigchld_handler(void)
{
static int setup = false;
static bool setup = false;
if (!setup) {
putty_signal(SIGCHLD, sigchld_handler);
setup = true;
@ -597,7 +597,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
{
char buf[4096];
int ret;
int finished = false;
bool finished = false;
if (event < 0) {
/*
@ -629,7 +629,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
}
} else {
if (event == 1) {
int is_stdout = (fd == pty->master_o);
bool is_stdout = (fd == pty->master_o);
ret = read(fd, buf, sizeof(buf));
@ -844,12 +844,12 @@ static void copy_ttymodes_into_termios(
*/
Backend *pty_backend_create(
Seat *seat, LogContext *logctx, Conf *conf, char **argv, const char *cmd,
struct ssh_ttymodes ttymodes, int pipes_instead)
struct ssh_ttymodes ttymodes, bool pipes_instead)
{
int slavefd;
pid_t pid, pgrp;
#ifndef NOT_X_WINDOWS /* for Mac OS X native compilation */
int got_windowid;
bool got_windowid;
long windowid;
#endif
Pty *pty;
@ -987,7 +987,7 @@ Backend *pty_backend_create(
char *e = *ep;
if (!strncmp(e, pty_osx_envrestore_prefix, plen)) {
int unset = (e[plen] == 'u');
bool unset = (e[plen] == 'u');
char *pname = dupprintf("%.*s", (int)strcspn(e, "="), e);
char *name = pname + plen + 1;
char *value = e + strcspn(e, "=");
@ -1129,7 +1129,7 @@ Backend *pty_backend_create(
putty_signal(SIGINT, SIG_DFL);
putty_signal(SIGQUIT, SIG_DFL);
putty_signal(SIGPIPE, SIG_DFL);
block_signal(SIGPIPE, 0);
block_signal(SIGPIPE, false);
if (argv || cmd) {
/*
* If we were given a separated argument list, try to exec
@ -1237,7 +1237,7 @@ Backend *pty_backend_create(
static const char *pty_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port,
char **realhost, int nodelay, int keepalive)
char **realhost, bool nodelay, bool keepalive)
{
const char *cmd = NULL;
struct ssh_ttymodes modes;
@ -1470,16 +1470,16 @@ static const SessionSpecial *pty_get_specials(Backend *be)
return NULL;
}
static int pty_connected(Backend *be)
static bool pty_connected(Backend *be)
{
/* Pty *pty = container_of(be, Pty, backend); */
return true;
}
static int pty_sendok(Backend *be)
static bool pty_sendok(Backend *be)
{
/* Pty *pty = container_of(be, Pty, backend); */
return 1;
return true;
}
static void pty_unthrottle(Backend *be, int backlog)
@ -1488,10 +1488,10 @@ static void pty_unthrottle(Backend *be, int backlog)
/* do nothing */
}
static int pty_ldisc(Backend *be, int option)
static bool pty_ldisc(Backend *be, int option)
{
/* Pty *pty = container_of(be, Pty, backend); */
return 0; /* neither editing nor echoing */
return false; /* neither editing nor echoing */
}
static void pty_provide_ldisc(Backend *be, Ldisc *ldisc)

View File

@ -20,7 +20,7 @@
/*
* Stubs to avoid uxpty.c needing to be linked in.
*/
const int use_pty_argv = false;
const bool use_pty_argv = false;
char **pty_argv; /* never used */
char *pty_osx_envrestore_prefix;
@ -52,8 +52,8 @@ void initial_config_box(Conf *conf, post_dialog_fn_t after, void *afterctx)
sfree(title);
}
const int use_event_log = 1, new_session = 1, saved_sessions = 1;
const int dup_check_launchable = 1;
const bool use_event_log = true, new_session = true, saved_sessions = true;
const bool dup_check_launchable = true;
char *make_default_wintitle(char *hostname)
{
@ -73,10 +73,10 @@ char *platform_get_x_display(void) {
return dupstr(display);
}
const int share_can_be_downstream = true;
const int share_can_be_upstream = true;
const bool share_can_be_downstream = true;
const bool share_can_be_upstream = true;
void setup(int single)
void setup(bool single)
{
sk_init();
flags = FLAG_VERBOSE | FLAG_INTERACTIVE;

View File

@ -22,7 +22,7 @@ struct Serial {
Seat *seat;
LogContext *logctx;
int fd;
int finished;
bool finished;
int inbufsize;
bufchain output_data;
Backend backend;
@ -282,7 +282,7 @@ static const char *serial_configure(Serial *serial, Conf *conf)
static const char *serial_init(Seat *seat, Backend **backend_handle,
LogContext *logctx, Conf *conf,
const char *host, int port, char **realhost,
int nodelay, int keepalive)
bool nodelay, bool keepalive)
{
Serial *serial;
const char *err;
@ -361,7 +361,7 @@ static void serial_select_result(int fd, int event)
Serial *serial;
char buf[4096];
int ret;
int finished = false;
bool finished = false;
serial = find234(serial_by_fd, &fd, serial_find_by_fd);
@ -509,14 +509,14 @@ static const SessionSpecial *serial_get_specials(Backend *be)
return specials;
}
static int serial_connected(Backend *be)
static bool serial_connected(Backend *be)
{
return 1; /* always connected */
return true; /* always connected */
}
static int serial_sendok(Backend *be)
static bool serial_sendok(Backend *be)
{
return 1;
return true;
}
static void serial_unthrottle(Backend *be, int backlog)
@ -526,12 +526,12 @@ static void serial_unthrottle(Backend *be, int backlog)
serial_uxsel_setup(serial);
}
static int serial_ldisc(Backend *be, int option)
static bool serial_ldisc(Backend *be, int option)
{
/*
* Local editing and local echo are off by default.
*/
return 0;
return false;
}
static void serial_provide_ldisc(Backend *be, Ldisc *ldisc)

View File

@ -112,7 +112,7 @@ void timer_change_notify(unsigned long next)
char *platform_get_x_display(void) { return NULL; }
static int verbose;
static bool verbose;
static void log_to_stderr(const char *msg)
{
@ -176,7 +176,7 @@ unsigned auth_methods(AuthPolicy *ap)
return (AUTHMETHOD_PUBLICKEY | AUTHMETHOD_PASSWORD | AUTHMETHOD_KBDINT |
AUTHMETHOD_TIS | AUTHMETHOD_CRYPTOCARD);
}
int auth_none(AuthPolicy *ap, ptrlen username)
bool auth_none(AuthPolicy *ap, ptrlen username)
{
return false;
}
@ -211,7 +211,7 @@ int auth_password(AuthPolicy *ap, ptrlen username, ptrlen password,
return 2;
}
}
int auth_publickey(AuthPolicy *ap, ptrlen username, ptrlen public_blob)
bool auth_publickey(AuthPolicy *ap, ptrlen username, ptrlen public_blob)
{
struct AuthPolicy_ssh2_pubkey *iter;
for (iter = ap->ssh2keys; iter; iter = iter->next) {
@ -285,11 +285,11 @@ char *auth_ssh1int_challenge(AuthPolicy *ap, unsigned method, ptrlen username)
return dupprintf("This is a dummy %s challenge!\n",
(method == AUTHMETHOD_TIS ? "TIS" : "CryptoCard"));
}
int auth_ssh1int_response(AuthPolicy *ap, ptrlen response)
bool auth_ssh1int_response(AuthPolicy *ap, ptrlen response)
{
return ptrlen_eq_string(response, "otter");
}
int auth_successful(AuthPolicy *ap, ptrlen username, unsigned method)
bool auth_successful(AuthPolicy *ap, ptrlen username, unsigned method)
{
return true;
}
@ -324,17 +324,17 @@ static void show_version_and_exit(void)
exit(0);
}
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
static int finished = false;
static bool finished = false;
void server_instance_terminated(void)
{
/* FIXME: change policy here if we're running in a listening loop */
finished = true;
}
static int longoptarg(const char *arg, const char *expected,
const char **val, int *argcp, char ***argvp)
static bool longoptarg(const char *arg, const char *expected,
const char **val, int *argcp, char ***argvp)
{
int len = strlen(expected);
if (memcmp(arg, expected, len))

View File

@ -37,7 +37,7 @@ void platform_get_x11_auth(struct X11Display *display, Conf *conf)
{
/* Do nothing, therefore no auth. */
}
const int platform_uses_x11_unix_by_default = true;
const bool platform_uses_x11_unix_by_default = true;
/*
* Default settings that are specific to PSFTP.
@ -346,7 +346,7 @@ void close_directory(DirHandle *dir)
sfree(dir);
}
int test_wildcard(const char *name, int cmdline)
int test_wildcard(const char *name, bool cmdline)
{
struct stat statbuf;
@ -403,7 +403,7 @@ void finish_wildcard_matching(WildcardMatcher *dir) {
sfree(dir);
}
char *stripslashes(const char *str, int local)
char *stripslashes(const char *str, bool local)
{
char *p;
@ -417,7 +417,7 @@ char *stripslashes(const char *str, int local)
return (char *)str;
}
int vet_filename(const char *name)
bool vet_filename(const char *name)
{
if (strchr(name, '/'))
return false;
@ -428,7 +428,7 @@ int vet_filename(const char *name)
return true;
}
int create_directory(const char *name)
bool create_directory(const char *name)
{
return mkdir(name, 0777) == 0;
}
@ -442,14 +442,14 @@ char *dir_file_cat(const char *dir, const char *file)
* Do a select() between all currently active network fds and
* optionally stdin.
*/
static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
static int ssh_sftp_do_select(bool include_stdin, bool no_fds_ok)
{
fd_set rset, wset, xset;
int i, fdcount, fdsize, *fdlist;
int fd, fdstate, rwx, ret, maxfd;
unsigned long now = GETTICKCOUNT();
unsigned long next;
int done_something = false;
bool done_something = false;
fdlist = NULL;
fdcount = fdsize = 0;
@ -566,7 +566,7 @@ int ssh_sftp_loop_iteration(void)
/*
* Read a PSFTP command line from stdin.
*/
char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok)
char *ssh_sftp_get_cmdline(const char *prompt, bool no_fds_ok)
{
char *buf;
int buflen, bufsize, ret;
@ -613,7 +613,7 @@ void frontend_net_error_pending(void) {}
void platform_psftp_pre_conn_setup(void) {}
const int buildinfo_gtk_relevant = false;
const bool buildinfo_gtk_relevant = false;
/*
* Main program: do platform-specific initialisation and then call

View File

@ -27,7 +27,7 @@ typedef struct UnixSftpServer UnixSftpServer;
struct UnixSftpServer {
unsigned *fdseqs;
int *fdsopen;
bool *fdsopen;
int fdsize;
tree234 *dirhandles;
@ -101,7 +101,7 @@ static void uss_return_handle_raw(
fxp_reply_handle(reply, make_ptrlen(handlebuf, 8));
}
static int uss_decode_handle(
static bool uss_decode_handle(
UnixSftpServer *uss, ptrlen handle, int *index, unsigned *seq)
{
unsigned char handlebuf[8];
@ -123,7 +123,7 @@ static void uss_return_new_handle(
int old_size = uss->fdsize;
uss->fdsize = fd * 5 / 4 + 32;
uss->fdseqs = sresize(uss->fdseqs, uss->fdsize, unsigned);
uss->fdsopen = sresize(uss->fdsopen, uss->fdsize, int);
uss->fdsopen = sresize(uss->fdsopen, uss->fdsize, bool);
while (old_size < uss->fdsize) {
uss->fdseqs[old_size] = 0;
uss->fdsopen[old_size] = false;
@ -382,7 +382,7 @@ static void uss_reply_struct_stat(SftpReplyBuilder *reply,
}
static void uss_stat(SftpServer *srv, SftpReplyBuilder *reply,
ptrlen path, int follow_symlinks)
ptrlen path, bool follow_symlinks)
{
UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv);
struct stat st;
@ -450,7 +450,7 @@ static void uss_setstat(SftpServer *srv, SftpReplyBuilder *reply,
UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv);
char *pathstr = mkstr(path);
int success = true;
bool success = true;
SETSTAT_GUTS(PATH_PREFIX, pathstr, attrs, success);
free(pathstr);
@ -470,7 +470,7 @@ static void uss_fsetstat(SftpServer *srv, SftpReplyBuilder *reply,
if ((fd = uss_lookup_fd(uss, reply, handle)) < 0)
return;
int success = true;
bool success = true;
SETSTAT_GUTS(FD_PREFIX, fd, attrs, success);
if (!success) {
@ -504,7 +504,7 @@ static void uss_read(SftpServer *srv, SftpReplyBuilder *reply,
int status = lseek(fd, offset, SEEK_SET);
if (status >= 0 || errno == ESPIPE) {
int seekable = (status >= 0);
bool seekable = (status >= 0);
while (length > 0) {
status = read(fd, p, length);
if (status <= 0)
@ -573,7 +573,7 @@ static void uss_write(SftpServer *srv, SftpReplyBuilder *reply,
}
static void uss_readdir(SftpServer *srv, SftpReplyBuilder *reply,
ptrlen handle, int max_entries, int omit_longname)
ptrlen handle, int max_entries, bool omit_longname)
{
UnixSftpServer *uss = container_of(srv, UnixSftpServer, srv);
struct dirent *de;

View File

@ -250,7 +250,7 @@ static char *make_dirname(const char *pi_name, char **logtext)
int platform_ssh_share(const char *pi_name, Conf *conf,
Plug *downplug, Plug *upplug, Socket **sock,
char **logtext, char **ds_err, char **us_err,
int can_upstream, int can_downstream)
bool can_upstream, bool can_downstream)
{
char *dirname, *lockname, *sockname, *err;
int lockfd;
@ -302,7 +302,8 @@ int platform_ssh_share(const char *pi_name, Conf *conf,
if (can_downstream) {
retsock = new_connection(unix_sock_addr(sockname),
"", 0, 0, 1, 0, 0, downplug, conf);
"", 0, false, true, false, false,
downplug, conf);
if (sk_socket_error(retsock) == NULL) {
sfree(*logtext);
*logtext = sockname;

View File

@ -2,6 +2,8 @@
#include <stdio.h>
#include <stdlib.h>
#include "defs.h"
/*
* Calling signal() is non-portable, as it varies in meaning
* between platforms and depending on feature macros, and has
@ -25,7 +27,7 @@ void (*putty_signal(int sig, void (*func)(int)))(int) {
return old.sa_handler;
}
void block_signal(int sig, int block_it)
void block_signal(int sig, bool block_it)
{
sigset_t ss;

View File

@ -678,8 +678,8 @@ int verify_host_key(const char *hostname, int port,
return ret;
}
int have_ssh_host_key(const char *hostname, int port,
const char *keytype)
bool have_ssh_host_key(const char *hostname, int port,
const char *keytype)
{
/*
* If we have a host key, verify_host_key will return 0 or 2.

View File

@ -16,9 +16,9 @@
* Unix Unicode-handling routines.
*/
int is_dbcs_leadbyte(int codepage, char byte)
bool is_dbcs_leadbyte(int codepage, char byte)
{
return 0; /* we don't do DBCS */
return false; /* we don't do DBCS */
}
int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
@ -98,10 +98,11 @@ int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
/*
* Return value is true if pterm is to run in direct-to-font mode.
*/
int init_ucs(struct unicode_data *ucsdata, char *linecharset,
int utf8_override, int font_charset, int vtmode)
bool init_ucs(struct unicode_data *ucsdata, char *linecharset,
bool utf8_override, int font_charset, int vtmode)
{
int i, ret = 0;
int i;
bool ret = false;
/*
* In the platform-independent parts of the code, font_codepage
@ -145,7 +146,7 @@ int init_ucs(struct unicode_data *ucsdata, char *linecharset,
ucsdata->line_codepage = font_charset;
if (ucsdata->line_codepage == CS_NONE)
ret = 1;
ret = true;
/*
* Set up unitab_line, by translating each individual character