Skip to content

Commit

Permalink
Fix checkpatch.pl warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
johanmalm committed May 5, 2017
1 parent 94c2e7a commit 15bf619
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 59 deletions.
3 changes: 0 additions & 3 deletions scripts/checkpatch-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,6 @@ do
-e 'CamelCase.*XQueryPointer' \
-e 'CamelCase.*XQueryTree' \
-e 'CamelCase.*XSetErrorHandler' \
-e 'CamelCase.*XSetting' \
-e 'CamelCase.*XSettingsBuffer' \
-e 'CamelCase.*XSettingsColor' \
-e 'CamelCase.*XUngrabKeyboard' \
-e 'CamelCase.*XUngrabPointer' \
-e 'CamelCase.*XVisualInfo' \
Expand Down
6 changes: 3 additions & 3 deletions xpm-color-table.h
Original file line number Diff line number Diff line change
Expand Up @@ -673,14 +673,14 @@ static const char color_names[] =
"yellow4\0"
"YellowGreen\0";

typedef struct {
struct xpm_color_entry {
u_int16_t name_offset;
unsigned char red;
unsigned char green;
unsigned char blue;
} XPMColorEntry;
};

static const XPMColorEntry xColors[] = {
static const struct xpm_color_entry xcolors[] = {
{ 0, 240, 248, 255 },
{ 10, 250, 235, 215 },
{ 23, 255, 239, 219 },
Expand Down
56 changes: 28 additions & 28 deletions xpm-loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@

enum buf_op { op_header, op_cmap, op_body };

typedef struct {
struct xpm_color {
char *color_string;
u_int16_t red;
u_int16_t green;
u_int16_t blue;
int transparent;
} XPMColor;
};

struct file_handle {
FILE *infile;
Expand Down Expand Up @@ -127,20 +127,20 @@ struct mem_handle {

static int compare_xcolor_entries(const void *a, const void *b)
{
return strcasecmp((const char *)a, color_names + ((const XPMColorEntry *)b)->name_offset);
return strcasecmp((const char *)a, color_names + ((const struct xpm_color_entry *)b)->name_offset);
}

static int find_color(const char *name, XPMColor *colorPtr)
static int find_color(const char *name, struct xpm_color *color_ptr)
{
XPMColorEntry *found;
struct xpm_color_entry *found;

found = bsearch(name, xColors, G_N_ELEMENTS(xColors), sizeof(XPMColorEntry), compare_xcolor_entries);
found = bsearch(name, xcolors, G_N_ELEMENTS(xcolors), sizeof(struct xpm_color_entry), compare_xcolor_entries);
if (!found)
return 0;

colorPtr->red = (found->red * 65535) / 255;
colorPtr->green = (found->green * 65535) / 255;
colorPtr->blue = (found->blue * 65535) / 255;
color_ptr->red = (found->red * 65535) / 255;
color_ptr->green = (found->green * 65535) / 255;
color_ptr->blue = (found->blue * 65535) / 255;

return 1;
}
Expand All @@ -161,7 +161,7 @@ static int find_color(const char *name, XPMColor *colorPtr)
*----------------------------------------------------------------------
*/

static int parse_color(const char *spec, XPMColor *colorPtr)
static int parse_color(const char *spec, struct xpm_color *color_ptr)
{
if (spec[0] == '#') {
int i, red, green, blue;
Expand All @@ -174,30 +174,30 @@ static int parse_color(const char *spec, XPMColor *colorPtr)
if (i == 4) {
if (sscanf(spec + 1, "%4x%4x%4x", &red, &green, &blue) != 3)
return 0;
colorPtr->red = red;
colorPtr->green = green;
colorPtr->blue = blue;
color_ptr->red = red;
color_ptr->green = green;
color_ptr->blue = blue;
} else if (i == 1) {
if (sscanf(spec + 1, "%1x%1x%1x", &red, &green, &blue) != 3)
return 0;
colorPtr->red = (red * 65535) / 15;
colorPtr->green = (green * 65535) / 15;
colorPtr->blue = (blue * 65535) / 15;
color_ptr->red = (red * 65535) / 15;
color_ptr->green = (green * 65535) / 15;
color_ptr->blue = (blue * 65535) / 15;
} else if (i == 2) {
if (sscanf(spec + 1, "%2x%2x%2x", &red, &green, &blue) != 3)
return 0;
colorPtr->red = (red * 65535) / 255;
colorPtr->green = (green * 65535) / 255;
colorPtr->blue = (blue * 65535) / 255;
color_ptr->red = (red * 65535) / 255;
color_ptr->green = (green * 65535) / 255;
color_ptr->blue = (blue * 65535) / 255;
} else /* if (i == 3) */ {
if (sscanf(spec + 1, "%3x%3x%3x", &red, &green, &blue) != 3)
return 0;
colorPtr->red = (red * 65535) / 4095;
colorPtr->green = (green * 65535) / 4095;
colorPtr->blue = (blue * 65535) / 4095;
color_ptr->red = (red * 65535) / 4095;
color_ptr->green = (green * 65535) / 4095;
color_ptr->blue = (blue * 65535) / 4095;
}
} else {
if (!find_color(spec, colorPtr))
if (!find_color(spec, color_ptr))
return 0;
}
return 1;
Expand Down Expand Up @@ -407,12 +407,12 @@ static const char *file_buffer(enum buf_op op, void *handle)
return NULL;
}

static XPMColor *lookup_color(XPMColor *colors, int n_colors, const char *name)
static struct xpm_color *lookup_color(struct xpm_color *colors, int n_colors, const char *name)
{
int i;

for (i = 0; i < n_colors; i++) {
XPMColor *color = &colors[i];
struct xpm_color *color = &colors[i];

if (strcmp(name, color->color_string) == 0)
return color;
Expand All @@ -432,7 +432,7 @@ static u_int32_t *pixbuf_create_from_xpm(const char *(*get_buf)(enum buf_op op,
const char *buffer;
char *name_buf;
char pixel_str[32];
XPMColor *colors, *color, *fallbackcolor;
struct xpm_color *colors, *color, *fallbackcolor;
u_int32_t *data = NULL;

fallbackcolor = NULL;
Expand All @@ -450,13 +450,13 @@ static u_int32_t *pixbuf_create_from_xpm(const char *(*get_buf)(enum buf_op op,
return NULL;
if (cpp <= 0 || cpp >= 32)
return NULL;
if (n_col <= 0 || n_col >= INT_MAX / (cpp + 1) || n_col >= INT_MAX / (int)sizeof(XPMColor))
if (n_col <= 0 || n_col >= INT_MAX / (cpp + 1) || n_col >= INT_MAX / (int)sizeof(struct xpm_color))
return NULL;

name_buf = (char *)calloc(n_col, cpp + 1);
if (!name_buf)
return NULL;
colors = (XPMColor *)calloc(n_col, sizeof(XPMColor));
colors = (struct xpm_color *)calloc(n_col, sizeof(struct xpm_color));
if (!colors) {
free(name_buf);
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions xsettings-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "xsettings-helper.h"
#include "xsettings.h"

static void print_setting(XSetting *setting)
static void print_setting(struct xsetting *setting)
{
printf("%s: ", setting->name);
if (setting->type == XSETTINGS_TYPE_INT)
Expand All @@ -26,7 +26,7 @@ static void print_setting(XSetting *setting)
printf("??\n");
}

static void print_settings(XSetting *settings, size_t count, const char *key,
static void print_settings(struct xsetting *settings, size_t count, const char *key,
struct sbuf *s)
{
size_t i;
Expand All @@ -49,7 +49,7 @@ int xsettings_get(struct sbuf *s, const char *key)
Display *display;
size_t count;
static int ret;
XSetting *settings;
struct xsetting *settings;

if (!key)
return 1;
Expand Down
30 changes: 15 additions & 15 deletions xsettings.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
#include <stdlib.h>
#include <string.h>

typedef struct XSettingsBuffer {
struct xsettings_buffer {
char byte_order;
size_t len;
unsigned char *data;
unsigned char *pos;
} XSettingsBuffer;
};

#define XSETTINGS_PAD(n, m) ((n + m - 1) & (~(m - 1)))
#define BYTES_LEFT(buffer) ((buffer)->data + (buffer)->len - (buffer)->pos)
Expand All @@ -50,7 +50,7 @@ static int ignore_x11_errors(Display *display, XErrorEvent *event)
return True;
}

static Bool fetch_card8(XSettingsBuffer *buffer, CARD8 *result)
static Bool fetch_card8(struct xsettings_buffer *buffer, CARD8 *result)
{
if (BYTES_LEFT(buffer) < 1)
return False;
Expand All @@ -59,7 +59,7 @@ static Bool fetch_card8(XSettingsBuffer *buffer, CARD8 *result)
return True;
}

static Bool fetch_card16(XSettingsBuffer *buffer, CARD16 *result)
static Bool fetch_card16(struct xsettings_buffer *buffer, CARD16 *result)
{
CARD16 x;

Expand All @@ -74,7 +74,7 @@ static Bool fetch_card16(XSettingsBuffer *buffer, CARD16 *result)
return True;
}

static Bool fetch_ushort(XSettingsBuffer *buffer, unsigned short *result)
static Bool fetch_ushort(struct xsettings_buffer *buffer, unsigned short *result)
{
CARD16 x;

Expand All @@ -84,7 +84,7 @@ static Bool fetch_ushort(XSettingsBuffer *buffer, unsigned short *result)
return True;
}

static Bool fetch_card32(XSettingsBuffer *buffer, CARD32 *result)
static Bool fetch_card32(struct xsettings_buffer *buffer, CARD32 *result)
{
CARD32 x;

Expand All @@ -104,10 +104,10 @@ static Bool fetch_card32(XSettingsBuffer *buffer, CARD32 *result)

#define XSETTINGS_PAD(n, m) ((n + m - 1) & (~(m - 1)))

static XSetting *parse_settings(unsigned char *data, size_t len, size_t *count)
static struct xsetting *parse_settings(unsigned char *data, size_t len, size_t *count)
{
XSetting *result = NULL;
XSettingsBuffer buffer;
struct xsetting *result = NULL;
struct xsettings_buffer buffer;
CARD32 serial;
CARD32 n_entries;
size_t i;
Expand All @@ -133,15 +133,15 @@ static XSetting *parse_settings(unsigned char *data, size_t len, size_t *count)
if (!fetch_card32(&buffer, &n_entries) || !n_entries)
goto err;

result = calloc(n_entries, sizeof(XSetting));
result = calloc(n_entries, sizeof(struct xsetting));
if (!result)
goto err;
*count = n_entries;

for (i = 0; i < n_entries; i++) {
CARD16 name_len;
int pad_len;
XSetting *setting;
struct xsetting *setting;

setting = &result[i];

Expand Down Expand Up @@ -207,14 +207,14 @@ static XSetting *parse_settings(unsigned char *data, size_t len, size_t *count)
return NULL;
}

void free_xsettings(XSetting *settings, size_t count)
void free_xsettings(struct xsetting *settings, size_t count)
{
size_t i;

if (!settings)
return;
for (i = 0; i < count; i++) {
XSetting *setting = &settings[i];
struct xsetting *setting = &settings[i];

if (setting->type == XSETTINGS_TYPE_STRING)
free(setting->value.string_value);
Expand Down Expand Up @@ -286,12 +286,12 @@ static unsigned char *read_xsettings(Display *display, Window manager,
return result;
}

XSetting *get_xsettings(Display *display, size_t *count)
struct xsetting *get_xsettings(Display *display, size_t *count)
{
Window manager = get_xsettings_manager(display);
unsigned long size;
unsigned char *buffer;
XSetting *result;
struct xsetting *result;

/* no xsettings daemon found */
if (!manager)
Expand Down
14 changes: 7 additions & 7 deletions xsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@
#define XSETTINGS_TYPE_COLOR 2
#define XSETTINGS_TYPE_NONE 0xff

typedef struct XSettingsColor {
struct xsettings_color {
unsigned short red, green, blue, alpha;
} XSettingsColor;
};

typedef struct XSetting {
struct xsetting {
unsigned char type;
char *name;
union {
int int_value;
char *string_value;
XSettingsColor color_value;
struct xsettings_color color_value;
} value;
CARD32 serial;
} XSetting;
};

XSetting *get_xsettings(Display *display, size_t *count);
void free_xsettings(XSetting *settings, size_t count);
struct xsetting *get_xsettings(Display *display, size_t *count);
void free_xsettings(struct xsetting *settings, size_t count);

#endif /* XSETTINGS_H */

0 comments on commit 15bf619

Please sign in to comment.