From fa5642244aa4b0882b8604d1e693d31882a7adda Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 20 Nov 2022 09:25:13 -0800 Subject: Reformat code to X.Org standard style Signed-off-by: Alan Coopersmith --- include/X11/extensions/XRes.h | 132 +++++++++--------- src/XRes.c | 307 ++++++++++++++++++++---------------------- 2 files changed, 214 insertions(+), 225 deletions(-) diff --git a/include/X11/extensions/XRes.h b/include/X11/extensions/XRes.h index bedf625..c5a9d1e 100644 --- a/include/X11/extensions/XRes.h +++ b/include/X11/extensions/XRes.h @@ -10,127 +10,127 @@ /* v1.0 */ typedef struct { - XID resource_base; - XID resource_mask; + XID resource_base; + XID resource_mask; } XResClient; typedef struct { - Atom resource_type; - unsigned int count; + Atom resource_type; + unsigned int count; } XResType; /* v1.2 */ typedef enum { - XRES_CLIENT_ID_XID, - XRES_CLIENT_ID_PID, - XRES_CLIENT_ID_NR + XRES_CLIENT_ID_XID, + XRES_CLIENT_ID_PID, + XRES_CLIENT_ID_NR } XResClientIdType; typedef enum { - XRES_CLIENT_ID_XID_MASK = 1 << XRES_CLIENT_ID_XID, - XRES_CLIENT_ID_PID_MASK = 1 << XRES_CLIENT_ID_PID + XRES_CLIENT_ID_XID_MASK = 1 << XRES_CLIENT_ID_XID, + XRES_CLIENT_ID_PID_MASK = 1 << XRES_CLIENT_ID_PID } XResClientIdMask; typedef struct { - XID client; - unsigned int mask; + XID client; + unsigned int mask; } XResClientIdSpec; typedef struct { - XResClientIdSpec spec; - long length; - void *value; + XResClientIdSpec spec; + long length; + void *value; } XResClientIdValue; typedef struct { - XID resource; - Atom type; + XID resource; + Atom type; } XResResourceIdSpec; typedef struct { - XResResourceIdSpec spec; - long bytes; - long ref_count; - long use_count; + XResResourceIdSpec spec; + long bytes; + long ref_count; + long use_count; } XResResourceSizeSpec; typedef struct { - XResResourceSizeSpec size; - long num_cross_references; - XResResourceSizeSpec *cross_references; + XResResourceSizeSpec size; + long num_cross_references; + XResResourceSizeSpec *cross_references; } XResResourceSizeValue; _XFUNCPROTOBEGIN /* v1.0 */ -Bool XResQueryExtension ( - Display *dpy, - int *event_base_return, - int *error_base_return +Bool XResQueryExtension( + Display *dpy, + int *event_base_return, + int *error_base_return ); -Status XResQueryVersion ( - Display *dpy, - int *major_version_return, - int *minor_version_return +Status XResQueryVersion( + Display *dpy, + int *major_version_return, + int *minor_version_return ); -Status XResQueryClients ( - Display *dpy, - int *num_clients, - XResClient **clients +Status XResQueryClients( + Display *dpy, + int *num_clients, + XResClient **clients ); -Status XResQueryClientResources ( - Display *dpy, - XID xid, - int *num_types, - XResType **types +Status XResQueryClientResources( + Display *dpy, + XID xid, + int *num_types, + XResType **types ); -Status XResQueryClientPixmapBytes ( - Display *dpy, - XID xid, - unsigned long *bytes +Status XResQueryClientPixmapBytes( + Display *dpy, + XID xid, + unsigned long *bytes ); /* v1.2 */ /* Returns an array of uint32_t values, not an array of long */ -Status XResQueryClientIds ( - Display *dpy, - long num_specs, - XResClientIdSpec *client_specs, /* in */ - long *num_ids, /* out */ - XResClientIdValue **client_ids /* out */ +Status XResQueryClientIds( + Display *dpy, + long num_specs, + XResClientIdSpec *client_specs, /* in */ + long *num_ids, /* out */ + XResClientIdValue **client_ids /* out */ ); -XResClientIdType XResGetClientIdType(XResClientIdValue* value); +XResClientIdType XResGetClientIdType(XResClientIdValue *value); /* return -1 if no pid associated to the value */ -pid_t XResGetClientPid(XResClientIdValue* value); +pid_t XResGetClientPid(XResClientIdValue *value); -void XResClientIdsDestroy ( - long num_ids, - XResClientIdValue *client_ids +void XResClientIdsDestroy( + long num_ids, + XResClientIdValue *client_ids ); -Status XResQueryResourceBytes ( - Display *dpy, - XID client, - long num_specs, - XResResourceIdSpec *resource_specs, /* in */ - long *num_sizes, /* out */ - XResResourceSizeValue **sizes /* out */ +Status XResQueryResourceBytes( + Display *dpy, + XID client, + long num_specs, + XResResourceIdSpec *resource_specs, /* in */ + long *num_sizes, /* out */ + XResResourceSizeValue **sizes /* out */ ); -void XResResourceSizeValuesDestroy ( - long num_sizes, - XResResourceSizeValue *sizes +void XResResourceSizeValuesDestroy( + long num_sizes, + XResResourceSizeValue *sizes ); _XFUNCPROTOEND -#endif /* _XRES_H */ +#endif /* _XRES_H */ diff --git a/src/XRes.c b/src/XRes.c index 10f166e..dc5a548 100644 --- a/src/XRes.c +++ b/src/XRes.c @@ -22,82 +22,74 @@ static const char *xres_extension_name = XRES_NAME; #define XResCheckExtension(dpy,i,val) \ XextCheckExtension (dpy, i, xres_extension_name, val) -static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xres_ext_info) +static XEXT_GENERATE_CLOSE_DISPLAY(close_display, xres_ext_info) static XExtensionHooks xres_extension_hooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - close_display, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + close_display, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_FIND_DISPLAY (find_display, xres_ext_info, - xres_extension_name, - &xres_extension_hooks, - 0, NULL) +static +XEXT_GENERATE_FIND_DISPLAY(find_display, xres_ext_info, xres_extension_name, + &xres_extension_hooks, 0, NULL) -Bool XResQueryExtension ( - Display *dpy, - int *event_base_return, - int *error_base_return -) +Bool +XResQueryExtension(Display *dpy, + int *event_base_return, int *error_base_return) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); if (XextHasExtension(info)) { *event_base_return = info->codes->first_event; *error_base_return = info->codes->first_error; return True; - } else { + } + else { return False; } } -Status XResQueryVersion( - Display *dpy, - int *major_version_return, - int *minor_version_return -) +Status +XResQueryVersion(Display *dpy, + int *major_version_return, int *minor_version_return) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryVersionReply rep; xXResQueryVersionReq *req; - XResCheckExtension (dpy, info, 0); + XResCheckExtension(dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryVersion, req); + LockDisplay(dpy); + GetReq(XResQueryVersion, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryVersion; req->client_major = XRES_MAJOR_VERSION; req->client_minor = XRES_MINOR_VERSION; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); + if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay(dpy); + SyncHandle(); return 0; } *major_version_return = rep.server_major; *minor_version_return = rep.server_minor; - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return 1; } - -Status XResQueryClients ( - Display *dpy, - int *num_clients, - XResClient **clients -) +Status +XResQueryClients(Display *dpy, int *num_clients, XResClient **clients) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryClientsReq *req; xXResQueryClientsReply rep; XResClient *clnts; @@ -106,19 +98,19 @@ Status XResQueryClients ( *num_clients = 0; *clients = NULL; - XResCheckExtension (dpy, info, 0); + XResCheckExtension(dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryClients, req); + LockDisplay(dpy); + GetReq(XResQueryClients, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryClients; - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay (dpy); - SyncHandle (); + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); return 0; } - if(rep.num_clients) { + if (rep.num_clients) { if (rep.num_clients < (INT_MAX / sizeof(XResClient))) clnts = Xmalloc(sizeof(XResClient) * rep.num_clients); else @@ -128,32 +120,30 @@ Status XResQueryClients ( xXResClient scratch; int i; - for(i = 0; i < rep.num_clients; i++) { - _XRead(dpy, (char*)&scratch, sz_xXResClient); + for (i = 0; i < rep.num_clients; i++) { + _XRead(dpy, (char *) &scratch, sz_xXResClient); clnts[i].resource_base = scratch.resource_base; clnts[i].resource_mask = scratch.resource_mask; } *clients = clnts; *num_clients = rep.num_clients; result = 1; - } else { + } + else { _XEatDataWords(dpy, rep.length); } } - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return result; } -Status XResQueryClientResources ( - Display *dpy, - XID xid, - int *num_types, - XResType **types -) +Status +XResQueryClientResources(Display *dpy, XID xid, + int *num_types, XResType **types) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryClientResourcesReq *req; xXResQueryClientResourcesReply rep; XResType *typs; @@ -162,20 +152,20 @@ Status XResQueryClientResources ( *num_types = 0; *types = NULL; - XResCheckExtension (dpy, info, 0); + XResCheckExtension(dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryClientResources, req); + LockDisplay(dpy); + GetReq(XResQueryClientResources, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryClientResources; req->xid = xid; - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { - UnlockDisplay (dpy); - SyncHandle (); + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); return 0; } - if(rep.num_types) { + if (rep.num_types) { if (rep.num_types < (INT_MAX / sizeof(XResType))) typs = Xmalloc(sizeof(XResType) * rep.num_types); else @@ -185,46 +175,44 @@ Status XResQueryClientResources ( xXResType scratch; int i; - for(i = 0; i < rep.num_types; i++) { - _XRead(dpy, (char*)&scratch, sz_xXResType); + for (i = 0; i < rep.num_types; i++) { + _XRead(dpy, (char *) &scratch, sz_xXResType); typs[i].resource_type = scratch.resource_type; typs[i].count = scratch.count; } *types = typs; *num_types = rep.num_types; result = 1; - } else { + } + else { _XEatDataWords(dpy, rep.length); } } - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return result; } -Status XResQueryClientPixmapBytes ( - Display *dpy, - XID xid, - unsigned long *bytes -) +Status +XResQueryClientPixmapBytes(Display *dpy, XID xid, unsigned long *bytes) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryClientPixmapBytesReq *req; xXResQueryClientPixmapBytesReply rep; *bytes = 0; - XResCheckExtension (dpy, info, 0); + XResCheckExtension(dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryClientPixmapBytes, req); + LockDisplay(dpy); + GetReq(XResQueryClientPixmapBytes, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryClientPixmapBytes; req->xid = xid; - if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) { - UnlockDisplay (dpy); - SyncHandle (); + if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { + UnlockDisplay(dpy); + SyncHandle(); return 0; } @@ -234,55 +222,56 @@ Status XResQueryClientPixmapBytes ( *bytes = rep.bytes_overflow ? 0xffffffff : rep.bytes; #endif - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return 1; } -static Bool ReadClientValues( - Display *dpy, - long num_ids, - XResClientIdValue *client_ids /* out */ -) +static Bool +ReadClientValues(Display *dpy, long num_ids, + XResClientIdValue *client_ids /* out */) { int c; + for (c = 0; c < num_ids; ++c) { - XResClientIdValue* client = client_ids + c; + XResClientIdValue *client = client_ids + c; long int value; - _XRead32 (dpy, &value, 4); + + _XRead32(dpy, &value, 4); client->spec.client = value; - _XRead32 (dpy, &value, 4); + _XRead32(dpy, &value, 4); client->spec.mask = value; - _XRead32 (dpy, &value, 4); + _XRead32(dpy, &value, 4); client->length = value; client->value = malloc(client->length); - _XRead (dpy, client->value, client->length); + _XRead(dpy, client->value, client->length); } return True; } /* Returns an array of uint32_t values, not an array of long */ -Status XResQueryClientIds ( - Display *dpy, - long num_specs, - XResClientIdSpec *client_specs, /* in */ - long *num_ids, /* out */ - XResClientIdValue **client_ids /* out */ +Status +XResQueryClientIds( + Display *dpy, + long num_specs, + XResClientIdSpec *client_specs, /* in */ + long *num_ids, /* out */ + XResClientIdValue **client_ids /* out */ ) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryClientIdsReq *req; xXResQueryClientIdsReply rep; int c; *num_ids = 0; - XResCheckExtension (dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryClientIds, req); + XResCheckExtension(dpy, info, 0); + LockDisplay(dpy); + GetReq(XResQueryClientIds, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryClientIds; - req->length += num_specs * 2; /* 2 longs per client id spec */ + req->length += num_specs * 2; /* 2 longs per client id spec */ req->numSpecs = num_specs; for (c = 0; c < num_specs; ++c) { @@ -290,7 +279,7 @@ Status XResQueryClientIds ( Data32(dpy, &client_specs[c].mask, 4); } - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { goto error; } @@ -301,38 +290,37 @@ Status XResQueryClientIds ( goto error; } - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return Success; error: - XResClientIdsDestroy (*num_ids, *client_ids); + XResClientIdsDestroy(*num_ids, *client_ids); *client_ids = NULL; - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return !Success; } -void XResClientIdsDestroy ( - long num_ids, - XResClientIdValue *client_ids -) +void +XResClientIdsDestroy(long num_ids, XResClientIdValue *client_ids) { int c; + for (c = 0; c < num_ids; ++c) { free(client_ids[c].value); } free(client_ids); } -XResClientIdType XResGetClientIdType( - XResClientIdValue* value -) +XResClientIdType +XResGetClientIdType(XResClientIdValue *value) { int bit; XResClientIdType idType = 0; Bool found = False; + for (bit = 0; bit < XRES_CLIENT_ID_NR; ++bit) { if (value->spec.mask & (1 << bit)) { assert(!found); @@ -346,23 +334,22 @@ XResClientIdType XResGetClientIdType( return idType; } -pid_t XResGetClientPid( - XResClientIdValue* value -) +pid_t +XResGetClientPid(XResClientIdValue *value) { if (value->spec.mask & XRES_CLIENT_ID_PID_MASK && value->length >= 4) { - return (pid_t) * (CARD32*) value->value; - } else { - return (pid_t) -1; + return (pid_t) * (CARD32 *) value->value; + } + else { + return (pid_t) - 1; } } -static Status ReadResourceSizeSpec( - Display *dpy, - XResResourceSizeSpec *size -) +static Status +ReadResourceSizeSpec(Display *dpy, XResResourceSizeSpec *size) { long int value; + _XRead32(dpy, &value, 4); size->spec.resource = value; _XRead32(dpy, &value, 4); @@ -376,19 +363,21 @@ static Status ReadResourceSizeSpec( return 0; } -static Status ReadResourceSizeValues( - Display *dpy, - long num_sizes, - XResResourceSizeValue *sizes) +static Status +ReadResourceSizeValues(Display *dpy, + long num_sizes, XResResourceSizeValue *sizes) { int c; int d; + for (c = 0; c < num_sizes; ++c) { long int num; + ReadResourceSizeSpec(dpy, &sizes[c].size); _XRead32(dpy, &num, 4); sizes[c].num_cross_references = num; - sizes[c].cross_references = num ? calloc(num, sizeof(*sizes[c].cross_references)) : NULL; + sizes[c].cross_references = + num ? calloc(num, sizeof(*sizes[c].cross_references)) : NULL; for (d = 0; d < num; ++d) { ReadResourceSizeSpec(dpy, &sizes[c].cross_references[d]); } @@ -396,29 +385,30 @@ static Status ReadResourceSizeValues( return Success; } -Status XResQueryResourceBytes ( - Display *dpy, - XID client, - long num_specs, - XResResourceIdSpec *resource_specs, /* in */ - long *num_sizes, /* out */ - XResResourceSizeValue **sizes /* out */ +Status +XResQueryResourceBytes( + Display *dpy, + XID client, + long num_specs, + XResResourceIdSpec *resource_specs, /* in */ + long *num_sizes, /* out */ + XResResourceSizeValue **sizes /* out */ ) { - XExtDisplayInfo *info = find_display (dpy); + XExtDisplayInfo *info = find_display(dpy); xXResQueryResourceBytesReq *req; xXResQueryResourceBytesReply rep; int c; *num_sizes = 0; - XResCheckExtension (dpy, info, 0); + XResCheckExtension(dpy, info, 0); - LockDisplay (dpy); - GetReq (XResQueryResourceBytes, req); + LockDisplay(dpy); + GetReq(XResQueryResourceBytes, req); req->reqType = info->codes->major_opcode; req->XResReqType = X_XResQueryResourceBytes; - req->length += num_specs * 2; /* 2 longs per client id spec */ + req->length += num_specs * 2; /* 2 longs per client id spec */ req->client = client; req->numSpecs = num_specs; @@ -430,7 +420,7 @@ Status XResQueryResourceBytes ( *num_sizes = 0; *sizes = NULL; - if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) { + if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) { goto error; } @@ -441,24 +431,23 @@ Status XResQueryResourceBytes ( goto error; } - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return Success; error: XResResourceSizeValuesDestroy(*num_sizes, *sizes); - UnlockDisplay (dpy); - SyncHandle (); + UnlockDisplay(dpy); + SyncHandle(); return !Success; } -void XResResourceSizeValuesDestroy ( - long num_sizes, - XResResourceSizeValue *sizes -) +void +XResResourceSizeValuesDestroy(long num_sizes, XResResourceSizeValue *sizes) { int c; + for (c = 0; c < num_sizes; ++c) { free(sizes[c].cross_references); } -- cgit v1.2.1