Skip to content

Commit

Permalink
Now that we're explicitly declaring C99, may as well use it.
Browse files Browse the repository at this point in the history
  • Loading branch information
divVerent committed Jan 14, 2020
1 parent 169ae00 commit 1e68ccc
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 59 deletions.
23 changes: 9 additions & 14 deletions helpers/auth_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,7 @@ const char *GetIndicators(int *warning, int *have_multiple_layouts) {
have_output = 1;
}

int i;
for (i = 0; i < XkbNumIndicators; i++) {
for (int i = 0; i < XkbNumIndicators; i++) {
if (!(istate & (1U << i))) {
continue;
}
Expand Down Expand Up @@ -495,8 +494,7 @@ const char *GetIndicators(int *warning, int *have_multiple_layouts) {
}

void DestroyPerMonitorWindows(size_t keep_windows) {
size_t i;
for (i = keep_windows; i < num_windows; ++i) {
for (size_t i = keep_windows; i < num_windows; ++i) {
#ifdef HAVE_XFT_EXT
XftDrawDestroy(xft_draws[i]);
#endif
Expand Down Expand Up @@ -618,8 +616,7 @@ void UpdatePerMonitorWindows(int monitors_changed, int region_w, int region_h,
unsigned int unused_mask;
XQueryPointer(display, parent_window, &unused_root, &unused_child,
&unused_root_x, &unused_root_y, &x, &y, &unused_mask);
size_t i;
for (i = 0; i < num_monitors; ++i) {
for (size_t i = 0; i < num_monitors; ++i) {
if (x >= monitors[i].x && x < monitors[i].x + monitors[i].width &&
y >= monitors[i].y && y < monitors[i].y + monitors[i].height) {
CreateOrUpdatePerMonitorWindow(0, &monitors[i], region_w, region_h,
Expand All @@ -641,8 +638,7 @@ void UpdatePerMonitorWindows(int monitors_changed, int region_w, int region_h,
size_t new_num_windows = num_monitors;

// Update or create everything.
size_t i;
for (i = 0; i < new_num_windows; ++i) {
for (size_t i = 0; i < new_num_windows; ++i) {
CreateOrUpdatePerMonitorWindow(i, &monitors[i], region_w, region_h,
x_offset, y_offset);
}
Expand Down Expand Up @@ -875,8 +871,7 @@ void DisplayMessage(const char *title, const char *str, int is_warning) {
x_offset, y_offset);
per_monitor_windows_dirty = 0;

size_t i;
for (i = 0; i < num_windows; ++i) {
for (size_t i = 0; i < num_windows; ++i) {
int cx = region_w / 2;
int cy = region_h / 2;
int y = cy + to - box_h / 2;
Expand Down Expand Up @@ -1095,8 +1090,8 @@ int Prompt(const char *msg, char **response, int echo) {
stride * DISCO_PASSWORD_DANCERS * strlen(disco_dancers[0]) +
strlen(disco_combiner);

size_t i, bit;
for (i = 0, bit = 1; i < DISCO_PASSWORD_DANCERS; ++i, bit <<= 1) {
for (size_t i = 0, bit = 1; i < DISCO_PASSWORD_DANCERS;
++i, bit <<= 1) {
const char *dancer =
disco_dancers[(priv.displaymarker & bit) ? 1 : 0];
memcpy(priv.displaybuf + i * stride, disco_combiner,
Expand Down Expand Up @@ -1468,8 +1463,8 @@ enum PasswordPrompt GetPasswordPromptFromFlags(
: PASSWORD_PROMPT_ASTERISKS;
}

enum PasswordPrompt prompt;
for (prompt = 0; prompt < PASSWORD_PROMPT_COUNT; ++prompt) {
for (enum PasswordPrompt prompt = 0; prompt < PASSWORD_PROMPT_COUNT;
++prompt) {
if (strcmp(password_prompt_flag, PasswordPromptStrings[prompt]) == 0) {
return prompt;
}
Expand Down
11 changes: 5 additions & 6 deletions helpers/authproto_pam.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ int Converse(int num_msg, const struct pam_message **msg,

*resp = calloc(num_msg, sizeof(struct pam_response));

int i;
for (i = 0; i < num_msg; ++i) {
for (int i = 0; i < num_msg; ++i) {
int status = ConverseOne(msg[i], &(*resp)[i]);
if (status != PAM_SUCCESS) {
for (i = 0; i < num_msg; ++i) {
if ((*resp)[i].resp != NULL) {
explicit_bzero((*resp)[i].resp, strlen((*resp)[i].resp));
for (int j = 0; j < num_msg; ++j) {
if ((*resp)[j].resp != NULL) {
explicit_bzero((*resp)[j].resp, strlen((*resp)[j].resp));
}
free((*resp)[i].resp);
free((*resp)[j].resp);
}
free(*resp);
*resp = NULL;
Expand Down
11 changes: 4 additions & 7 deletions helpers/dimmer.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ void DitherEffectDrawFrame(void *self, Display *display, Window dim_window,
int start_pframe = frame * dimmer->pattern_frames / dimmer->super.frame_count;
int end_pframe =
(frame + 1) * dimmer->pattern_frames / dimmer->super.frame_count;
int pframe;
for (pframe = start_pframe; pframe < end_pframe; ++pframe) {
for (int pframe = start_pframe; pframe < end_pframe; ++pframe) {
int x, y;
Bayer(pframe, dimmer->pattern_power, &x, &y);
XDrawPoint(display, dimmer->pattern, dimmer->pattern_gc, x, y);
Expand All @@ -168,13 +167,12 @@ void DitherEffectDrawFrame(void *self, Display *display, Window dim_window,
XChangeGC(display, dimmer->dim_gc, GCStipple, &dimmer->gc_values);
// But do it in some sub-rectangles to be easier on the X server on large
// screens.
int x, y;
for (y = 0; y < h; y += dimmer->max_fill_size) {
for (int y = 0; y < h; y += dimmer->max_fill_size) {
int hh = h - y;
if (hh > dimmer->max_fill_size) {
hh = dimmer->max_fill_size;
}
for (x = 0; x < w; x += dimmer->max_fill_size) {
for (int x = 0; x < w; x += dimmer->max_fill_size) {
int ww = w - x;
if (ww > dimmer->max_fill_size) {
ww = dimmer->max_fill_size;
Expand Down Expand Up @@ -376,8 +374,7 @@ int main(int argc, char **argv) {
sleep_ts.tv_sec = sleep_time_ns / 1000000000;
sleep_ts.tv_nsec = sleep_time_ns % 1000000000;
XMapRaised(display, dim_window);
int i;
for (i = 0; i < dimmer->frame_count; ++i) {
for (int i = 0; i < dimmer->frame_count; ++i) {
// Advance the dim pattern by one step.
dimmer->DrawFrame(dimmer, display, dim_window, i, w, h);
// Sleep a while. Yes, even at the end now - we want the user to see this
Expand Down
12 changes: 4 additions & 8 deletions helpers/monitors.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ static void AddMonitor(Monitor* out_monitors, size_t* num_monitors,
return;
}
// Skip overlapping "monitors" (typically in cloned display setups).
size_t i;
for (i = 0; i < *num_monitors; ++i) {
for (size_t i = 0; i < *num_monitors; ++i) {
if (IntervalsOverlap(x, w, out_monitors[i].x, out_monitors[i].width) &&
IntervalsOverlap(y, h, out_monitors[i].y, out_monitors[i].height)) {
#ifdef DEBUG_EVENTS
Expand All @@ -139,8 +138,7 @@ static int GetMonitorsXRandR12(Display* dpy, Window window, int wx, int wy,
if (screenres == NULL) {
return 0;
}
int i;
for (i = 0; i < screenres->noutput; ++i) {
for (int i = 0; i < screenres->noutput; ++i) {
XRROutputInfo* output =
XRRGetOutputInfo(dpy, screenres, screenres->outputs[i]);
if (output == NULL) {
Expand Down Expand Up @@ -182,8 +180,7 @@ static int GetMonitorsXRandR15(Display* dpy, Window window, int wx, int wy,
if (rrmonitors == NULL) {
return 0;
}
int i;
for (i = 0; i < num_rrmonitors; ++i) {
for (int i = 0; i < num_rrmonitors; ++i) {
XRRMonitorInfo* info = &rrmonitors[i];
int x = CLAMP(info->x, wx, wx + ww) - wx;
int y = CLAMP(info->y, wy, wy + wh) - wy;
Expand Down Expand Up @@ -233,8 +230,7 @@ static void GetMonitorsGuess(const XWindowAttributes* xwa,
size_t guessed_monitors = CLAMP((size_t)(xwa->width * 9 + xwa->height * 8) /
(size_t)(xwa->height * 16), //
1, max_monitors);
size_t i;
for (i = 0; i < guessed_monitors; ++i) {
for (size_t i = 0; i < guessed_monitors; ++i) {
int x = xwa->width * i / guessed_monitors;
int y = 0;
int w = (xwa->width * (i + 1) / guessed_monitors) -
Expand Down
9 changes: 3 additions & 6 deletions helpers/saver_multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ static size_t num_monitors;
static Window windows[MAX_MONITORS];

static void WatchSavers(void) {
size_t i;
for (i = 0; i < num_monitors; ++i) {
for (size_t i = 0; i < num_monitors; ++i) {
WatchSaverChild(display, windows[i], i, saver_executable, 1);
}
}

static void SpawnSavers(Window parent, int argc, char* const* argv) {
XSetWindowAttributes attrs = {0};
attrs.background_pixel = BlackPixel(display, DefaultScreen(display));
size_t i;
for (i = 0; i < num_monitors; ++i) {
for (size_t i = 0; i < num_monitors; ++i) {
windows[i] =
XCreateWindow(display, parent, monitors[i].x, monitors[i].y,
monitors[i].width, monitors[i].height, 0, CopyFromParent,
Expand All @@ -75,8 +73,7 @@ static void SpawnSavers(Window parent, int argc, char* const* argv) {
}

static void KillSavers(void) {
size_t i;
for (i = 0; i < num_monitors; ++i) {
for (size_t i = 0; i < num_monitors; ++i) {
WatchSaverChild(display, windows[i], i, saver_executable, 0);
XDestroyWindow(display, windows[i]);
}
Expand Down
3 changes: 1 addition & 2 deletions helpers/until_nonidle.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ uint64_t GetIdleTimeForSingleTimer(Display *display, Window w,
} else {
#ifdef HAVE_XSYNC_EXT
if (have_xsync_ext) {
int i;
for (i = 0; i < num_xsync_counters; ++i) {
for (int i = 0; i < num_xsync_counters; ++i) {
if (!strcmp(timer,
xsync_counters[i].name)) { // I know this is inefficient.
XSyncValue value;
Expand Down
11 changes: 5 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,7 @@ void LoadDefaults() {
* Possible errors will be printed on stderr.
*/
void ParseArgumentsOrExit(int argc, char **argv) {
int i;
for (i = 1; i < argc; ++i) {
for (int i = 1; i < argc; ++i) {
if (!strncmp(argv[i], "auth_", 5)) {
Log("Setting auth child name from command line is DEPRECATED. Use "
"the XSECURELOCK_AUTH environment variable instead");
Expand Down Expand Up @@ -983,8 +982,8 @@ int main(int argc, char **argv) {
XIMPreeditNone | XIMStatusNothing, // Status might be invisible.
XIMPreeditNone | XIMStatusNone // Standard handling.
};
size_t i;
for (i = 0; i < sizeof(input_styles) / sizeof(input_styles[0]); ++i) {
for (size_t i = 0; i < sizeof(input_styles) / sizeof(input_styles[0]);
++i) {
// Note: we draw XIM stuff in auth_window so it's above the saver/auth
// child. However, we receive events for the grab window.
xic = XCreateIC(xim, XNInputStyle, input_styles[i], XNClientWindow,
Expand Down Expand Up @@ -1020,11 +1019,11 @@ int main(int argc, char **argv) {

// Acquire all grabs we need. Retry in case the window manager is still
// holding some grabs while starting XSecureLock.
int retries;
int last_normal_attempt = force_grab ? 1 : 0;
Window previous_focused_window = None;
int previous_revert_focus_to = RevertToNone;
for (retries = 10; retries >= 0; --retries) {
int retries = 10;
for (; retries >= 0; --retries) {
if (AcquireGrabs(display, root_window, my_windows, n_my_windows,
transparent_cursor,
/*silent=*/retries > last_normal_attempt,
Expand Down
3 changes: 1 addition & 2 deletions saver_child.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ static pid_t saver_child_pid[MAX_SAVERS] = {0};
void KillAllSaverChildrenSigHandler(int signo) {
// This is a signal handler, so we're not going to make this too
// complicated. Just kill 'em all.
int i;
for (i = 0; i < MAX_SAVERS; ++i) {
for (int i = 0; i < MAX_SAVERS; ++i) {
if (saver_child_pid[i] != 0) {
KillPgrp(saver_child_pid[i], signo);
}
Expand Down
14 changes: 6 additions & 8 deletions unmap_all.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ int InitUnmapAllWindowsState(UnmapAllWindowsState* state, Display* display,
XQueryTree(state->display, state->root_window, &unused_root_return,
&unused_parent_return, &state->windows, &state->n_windows);
state->first_unmapped_window = state->n_windows; // That means none unmapped.
unsigned int i;
for (i = 0; i < state->n_windows; ++i) {
for (unsigned int i = 0; i < state->n_windows; ++i) {
XWindowAttributes xwa;
XGetWindowAttributes(display, state->windows[i], &xwa);
// Not mapped -> nothing to do.
Expand All @@ -36,8 +35,7 @@ int InitUnmapAllWindowsState(UnmapAllWindowsState* state, Display* display,
state->windows[i] = XmuClientWindow(display, state->windows[i]);
}
// If any window we'd be unmapping is in the ignore list, skip it.
unsigned int j;
for (j = 0; j < n_ignored_windows; ++j) {
for (unsigned int j = 0; j < n_ignored_windows; ++j) {
if (state->windows[i] == ignored_windows[j]) {
state->windows[i] = None;
}
Expand Down Expand Up @@ -76,8 +74,8 @@ int UnmapAllWindows(UnmapAllWindowsState* state,
if (state->first_unmapped_window == 0) { // Already all unmapped.
return 0;
}
unsigned int i;
for (i = state->first_unmapped_window - 1;; --i) { // Top-to-bottom order!
for (unsigned int i = state->first_unmapped_window - 1;;
--i) { // Top-to-bottom order!
if (state->windows[i] != None) {
XUnmapWindow(state->display, state->windows[i]);
state->first_unmapped_window = i;
Expand All @@ -94,8 +92,8 @@ int UnmapAllWindows(UnmapAllWindowsState* state,
}

void RemapAllWindows(UnmapAllWindowsState* state) {
unsigned int i;
for (i = state->first_unmapped_window; i < state->n_windows; ++i) {
for (unsigned int i = state->first_unmapped_window; i < state->n_windows;
++i) {
if (state->windows[i] != None) {
XMapWindow(state->display, state->windows[i]);
}
Expand Down

0 comments on commit 1e68ccc

Please sign in to comment.