Skip to content

Commit

Permalink
Fix some typos and standardise define prefixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jtanx committed Aug 10, 2016
1 parent 5aadb27 commit 83f2da9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 88 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if ((APPLE OR LIBCLIPBOARD_FORCE_COCOA) AND NOT (LIBCLIPBOARD_FORCE_WIN32 OR LIB
endif()

if (NOT (LIBCLIPBOARD_BUILD_WIN32 OR LIBCLIPBOARD_BUILD_X11 OR LIBCLIPBOARD_BUILD_COCOA))
message(FATAL_ERROR "Invalid build options. Can only specify one backen to be built.")
message(FATAL_ERROR "Invalid build options. Can only specify one backend to be built.")
endif()

# Set compiler flags
Expand Down
20 changes: 10 additions & 10 deletions include/libclipboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ extern "C" {
#endif

/** Default action timeout of 1500ms **/
#define LC_X11_ACTION_TIMEOUT_DEFAULT 1500
#define LCB_X11_ACTION_TIMEOUT_DEFAULT 1500
/** Default transfer size (X11 only), default 1MB (must be multiple of 4) **/
#define LC_X11_TRANSFER_SIZE_DEFAULT 1048576
#define LCB_X11_TRANSFER_SIZE_DEFAULT 1048576
/** Default max number of retries to try to obtain clipboard lock **/
#define LC_WIN32_MAX_RETRIES_DEFAULT 5
#define LCB_WIN32_MAX_RETRIES_DEFAULT 5
/** Default delay in ms between retries to obtain clipboard lock **/
#define LC_WIN32_RETRY_DELAY_DEFAULT 5
#define LCB_WIN32_RETRY_DELAY_DEFAULT 5

/**
* \brief For internal use only. Initialises custom allocators.
*
* \param [out] cb Clipboard context
* \param [in] opts Clipboard options
*/
#define LC_SET_ALLOCATORS(cb, opts) do { \
#define LCB_SET_ALLOCATORS(cb, opts) do { \
(cb)->malloc = (opts) && (opts)->user_malloc_fn ? (opts)->user_malloc_fn : malloc; \
(cb)->calloc = (opts) && (opts)->user_calloc_fn ? (opts)->user_calloc_fn : calloc; \
(cb)->realloc = (opts) && (opts)->user_realloc_fn ? (opts)->user_realloc_fn : realloc; \
Expand All @@ -90,11 +90,11 @@ typedef void (*clipboard_free_fn)(void *ptr);
*/
typedef enum clipboard_mode {
/** The primary (global) clipboard **/
LC_CLIPBOARD = 0,
LCB_CLIPBOARD = 0,
/** The (global) mouse selection clipboard **/
LC_SELECTION,
LCB_SELECTION,
/** Sentinel value for end of clipboard modes **/
LC_MODE_END
LCB_MODE_END
} clipboard_mode;

/**
Expand Down Expand Up @@ -193,7 +193,7 @@ LCB_API char *LCB_CC clipboard_text_ex(clipboard_c *cb, int *length, clipboard_m
* \param [in] cb The clipboard to retrieve from
* \return As per clipboard_text_ex.
*
* \details This function assumes LC_CLIPBOARD as the clipboard mode.
* \details This function assumes LCB_CLIPBOARD as the clipboard mode.
*/
LCB_API char *LCB_CC clipboard_text(clipboard_c *cb);

Expand All @@ -219,7 +219,7 @@ LCB_API bool LCB_CC clipboard_set_text_ex(clipboard_c *cb, const char *src, int
* \param [in] src The UTF-8 encoded NULL terminated string to be set.
* \return true iff the clipboard was set (false on error)
*
* \details This function assumes LC_CLIPBOARD as the clipboard mode.
* \details This function assumes LCB_CLIPBOARD as the clipboard mode.
*/
LCB_API bool LCB_CC clipboard_set_text(clipboard_c *cb, const char *src);

Expand Down
4 changes: 2 additions & 2 deletions samples/clipboard_sample1.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ bool parse_mode(const char *name, const char *arg, app_opts *opts) {
if (arg[2] == '\0') {
return true;
} else if (!strcmp(arg + 2, "=CLIPBOARD")) {
opts->mode = LC_CLIPBOARD;
opts->mode = LCB_CLIPBOARD;
} else if (!strcmp(arg + 2, "=SELECTION")) {
opts->mode = LC_SELECTION;
opts->mode = LCB_SELECTION;
} else {
printf("Error: Unknown mode: %s\n", arg);
help(name, true);
Expand Down
2 changes: 1 addition & 1 deletion src/clipboard_cocoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LCB_API clipboard_c *LCB_CC clipboard_new(clipboard_opts *cb_opts) {
if (cb == NULL) {
return NULL;
}
LC_SET_ALLOCATORS(cb, cb_opts);
LCB_SET_ALLOCATORS(cb, cb_opts);
cb->pb = [NSPasteboard generalPasteboard];
return cb;
}
Expand Down
4 changes: 2 additions & 2 deletions src/clipboard_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <stdlib.h>

LCB_API char *LCB_CC clipboard_text(clipboard_c *cb) {
return clipboard_text_ex(cb, NULL, LC_CLIPBOARD);
return clipboard_text_ex(cb, NULL, LCB_CLIPBOARD);
}

LCB_API bool LCB_CC clipboard_set_text(clipboard_c *cb, const char *src) {
return clipboard_set_text_ex(cb, src, -1, LC_CLIPBOARD);
return clipboard_set_text_ex(cb, src, -1, LCB_CLIPBOARD);
}
6 changes: 3 additions & 3 deletions src/clipboard_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ LCB_API clipboard_c *LCB_CC clipboard_new(clipboard_opts *cb_opts) {
if (ret == NULL) {
return NULL;
}
LC_SET_ALLOCATORS(ret, cb_opts);
LCB_SET_ALLOCATORS(ret, cb_opts);

ret->max_retries = LC_WIN32_MAX_RETRIES_DEFAULT;
ret->retry_delay = LC_WIN32_RETRY_DELAY_DEFAULT;
ret->max_retries = LCB_WIN32_MAX_RETRIES_DEFAULT;
ret->retry_delay = LCB_WIN32_RETRY_DELAY_DEFAULT;

if (cb_opts) {
if (cb_opts->win32.max_retries > 0) {
Expand Down
34 changes: 17 additions & 17 deletions src/clipboard_x11.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct clipboard_c {
bool cond_initted;

/** Selection data **/
selection_c selections[LC_MODE_END];
selection_c selections[LCB_MODE_END];

/** malloc **/
clipboard_malloc_fn malloc;
Expand Down Expand Up @@ -184,7 +184,7 @@ static void x11_clear_selection(clipboard_c *cb, xcb_selection_clear_event_t *e)
return;
}

for (int i = 0; i < LC_MODE_END; i++) {
for (int i = 0; i < LCB_MODE_END; i++) {
if (cb->selections[i].xmode == e->selection && (pthread_mutex_lock(&cb->mu) == 0)) {
xcb_atom_t xmode = cb->selections[i].xmode;
cb->free(cb->selections[i].data);
Expand Down Expand Up @@ -263,7 +263,7 @@ static void x11_retrieve_selection(clipboard_c *cb, xcb_selection_notify_event_t

if (buf != NULL && (pthread_mutex_lock(&cb->mu) == 0)) {
selection_c *sel = NULL;
for (int i = 0; i < LC_MODE_END; i++) {
for (int i = 0; i < LCB_MODE_END; i++) {
if (cb->selections[i].xmode == e->property) {
sel = &cb->selections[i];
break;
Expand Down Expand Up @@ -322,7 +322,7 @@ static bool x11_transmit_selection(clipboard_c *cb, xcb_selection_request_event_
return false;
}

for (int i = 0; i < LC_MODE_END; i++) {
for (int i = 0; i < LCB_MODE_END; i++) {
if (cb->selections[i].xmode == e->selection) {
sel = &cb->selections[i];
break;
Expand Down Expand Up @@ -413,8 +413,8 @@ static void *x11_event_loop(void *arg) {
LCB_API clipboard_c *LCB_CC clipboard_new(clipboard_opts *cb_opts) {
clipboard_opts defaults = {
.x11.display_name = NULL,
.x11.action_timeout = LC_X11_ACTION_TIMEOUT_DEFAULT,
.x11.transfer_size = LC_X11_TRANSFER_SIZE_DEFAULT,
.x11.action_timeout = LCB_X11_ACTION_TIMEOUT_DEFAULT,
.x11.transfer_size = LCB_X11_TRANSFER_SIZE_DEFAULT,
};

if (cb_opts == NULL) {
Expand All @@ -426,14 +426,14 @@ LCB_API clipboard_c *LCB_CC clipboard_new(clipboard_opts *cb_opts) {
if (cb == NULL) {
return NULL;
}
LC_SET_ALLOCATORS(cb, cb_opts);
LCB_SET_ALLOCATORS(cb, cb_opts);

cb->action_timeout = cb_opts->x11.action_timeout > 0 ?
cb_opts->x11.action_timeout : LC_X11_ACTION_TIMEOUT_DEFAULT;
cb_opts->x11.action_timeout : LCB_X11_ACTION_TIMEOUT_DEFAULT;
/* Round down to nearest multiple of 4 */
cb->transfer_size = (cb_opts->x11.transfer_size / 4) * 4;
if (cb->transfer_size == 0) {
cb->transfer_size = LC_X11_TRANSFER_SIZE_DEFAULT;
cb->transfer_size = LCB_X11_TRANSFER_SIZE_DEFAULT;
}

cb->mu_initted = pthread_mutex_init(&cb->mu, NULL) == 0;
Expand Down Expand Up @@ -463,8 +463,8 @@ LCB_API clipboard_c *LCB_CC clipboard_new(clipboard_opts *cb_opts) {
return NULL;
}

cb->selections[LC_CLIPBOARD].xmode = cb->std_atoms[X_ATOM_CLIPBOARD].atom;
cb->selections[LC_SELECTION].xmode = XCB_ATOM_PRIMARY;
cb->selections[LCB_CLIPBOARD].xmode = cb->std_atoms[X_ATOM_CLIPBOARD].atom;
cb->selections[LCB_SELECTION].xmode = XCB_ATOM_PRIMARY;

/* Structure notify mask to get DestroyNotify messages */
/* Property change mask for PropertyChange messages */
Expand Down Expand Up @@ -520,7 +520,7 @@ LCB_API void LCB_CC clipboard_free(clipboard_c *cb) {
}

/* Free selection data */
for (int i = 0; i < LC_MODE_END; i++) {
for (int i = 0; i < LCB_MODE_END; i++) {
if (cb->selections[i].data != NULL) {
cb->free(cb->selections[i].data);
}
Expand All @@ -537,10 +537,10 @@ LCB_API void LCB_CC clipboard_clear(clipboard_c *cb, clipboard_mode mode) {
xcb_atom_t sel;

switch (mode) {
case LC_CLIPBOARD:
case LCB_CLIPBOARD:
sel = cb->std_atoms[X_ATOM_CLIPBOARD].atom;
break;
case LC_SELECTION:
case LCB_SELECTION:
sel = XCB_ATOM_PRIMARY;
break;
default:
Expand All @@ -554,7 +554,7 @@ LCB_API void LCB_CC clipboard_clear(clipboard_c *cb, clipboard_mode mode) {
LCB_API bool LCB_CC clipboard_has_ownership(clipboard_c *cb, clipboard_mode mode) {
bool ret = false;

if (mode != LC_CLIPBOARD && mode != LC_SELECTION) {
if (mode != LCB_CLIPBOARD && mode != LCB_SELECTION) {
return false;
}

Expand Down Expand Up @@ -590,7 +590,7 @@ static void retrieve_text_selection(clipboard_c *cb, selection_c *sel, char **re
LCB_API char LCB_CC *clipboard_text_ex(clipboard_c *cb, int *length, clipboard_mode mode) {
char *ret = NULL;

if (cb == NULL || (mode != LC_CLIPBOARD && mode != LC_SELECTION)) {
if (cb == NULL || (mode != LCB_CLIPBOARD && mode != LCB_SELECTION)) {
return NULL;
}

Expand Down Expand Up @@ -649,7 +649,7 @@ LCB_API char LCB_CC *clipboard_text_ex(clipboard_c *cb, int *length, clipboard_m
LCB_API bool LCB_CC clipboard_set_text_ex(clipboard_c *cb, const char *src, int length, clipboard_mode mode) {
bool ret = false;

if (cb == NULL || src == NULL || length == 0 || (mode != LC_CLIPBOARD && mode != LC_SELECTION)) {
if (cb == NULL || src == NULL || length == 0 || (mode != LCB_CLIPBOARD && mode != LCB_SELECTION)) {
return false;
}

Expand Down
7 changes: 3 additions & 4 deletions test/libclipboard-test-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
#ifdef LIBCLIPBOARD_BUILD_X11
# include <thread>
# include <chrono>
using std::this_thread::sleep_for;
using std::chrono::milliseconds;
# include <iostream>

# define TRY_RUN(fn, ev, ret, oper) do { \
ret = fn; \
for (int i = 0; i < 10 && oper(ret, ev); i++) { \
std::cout << "Warning(test_basics.cpp:" TO_STRING(__LINE__) "): " TO_STRING(fn) " returned '" << \
std::cout << "Warning(at line:" TO_STRING(__LINE__) "): " TO_STRING(fn) " returned '" << \
ret << "' trying again!" << std::endl; \
sleep_for(milliseconds(50)); \
std::this_thread::sleep_for(std::chrono::milliseconds(50)); \
ret = fn; \
} \
} while (0)
Expand Down
Loading

0 comments on commit 83f2da9

Please sign in to comment.