From 6a783002e8b17995132fc6334b4e0900c36bf9a0 Mon Sep 17 00:00:00 2001 From: Michael Drake Date: Wed, 15 Aug 2018 13:41:42 +0100 Subject: Library: Use `nsl` as library namespace. --- dev/main.c | 4 +- docs/architecture.md | 2 +- include/libnslayout/error.h | 46 ++++++------- include/libnslayout/nslayout.h | 142 ++++++++++++++++++++--------------------- src/dom/debug.h | 4 +- src/dom/watcher.c | 26 ++++---- src/dom/watcher.h | 16 ++--- src/layout.c | 44 ++++++------- src/layout.h | 6 +- src/request.h | 72 ++++++++++----------- src/util/dom-str.c | 10 +-- src/util/dom-str.h | 12 ++-- src/util/util.h | 8 +-- test/assert-tests.c | 16 ++--- test/nslayout-object-tests.c | 32 +++++----- test/test-loader.c | 24 +++---- test/tests.c | 4 +- test/tests.h | 8 +-- 18 files changed, 238 insertions(+), 238 deletions(-) diff --git a/dev/main.c b/dev/main.c index 77c408b..a2f9f1a 100644 --- a/dev/main.c +++ b/dev/main.c @@ -30,12 +30,12 @@ int main(void) &buffer); if (!ok) return EXIT_FAILURE; - nslayout_init(); + nsl_init(); ok = test_loader(buffer, CSS_MEDIA_ALL, 15); if (!ok) return EXIT_FAILURE; - nslayout_fini(); + nsl_fini(); test_loader_free_buffer(buffer); diff --git a/docs/architecture.md b/docs/architecture.md index 63142fe..e347b24 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -169,7 +169,7 @@ resource. Since there is a non-null client resource handle, LibNSLayout knows it's a replaced element, and can ask the client for intrinsic dimensions. ```c -nslayout_res nslayout_dom_event_add_element_replaced( +nsl_res nsl_dom_event_add_element_replaced( nslayout *layout, dom_node *element, nsl_resource_t *replaced, diff --git a/include/libnslayout/error.h b/include/libnslayout/error.h index 5e7b87a..ee8a428 100644 --- a/include/libnslayout/error.h +++ b/include/libnslayout/error.h @@ -8,8 +8,8 @@ * Layout object handling */ -#ifndef nslayout_error_h_ -#define nslayout_error_h_ +#ifndef nsl_error_h_ +#define nsl_error_h_ #ifdef __cplusplus extern "C" @@ -17,27 +17,27 @@ extern "C" #endif /** - * Number of bits in an `nslayout_error` that indicate the source of the error. + * Number of bits in an `nsl_error` that indicate the source of the error. */ -#define NSLAYOUT_ERROR_PROV 8 +#define NSL_ERROR_PROV 8 /** * Libnslayout return codes * - * NSLAYOUT_OK indicates no error. + * NSL_OK indicates no error. */ -typedef enum nslayout_error { +typedef enum nsl_error { /** No error code */ - NSLAYOUT_OK = 0, + NSL_OK = 0, /** Error provenance (bits 0..7) */ - NSLAYOUT_NSLAYOUT = (1 << 0), - NSLAYOUT_LIBDOM = (1 << 1), - NSLAYOUT_LIBCSS = (1 << 2), + NSL_NSLAYOUT = (1 << 0), + NSL_LIBDOM = (1 << 1), + NSL_LIBCSS = (1 << 2), /** LibNSLayout errors (bits 8..31) */ - NSLAYOUT_NO_MEM = (1 << NSLAYOUT_ERROR_PROV) | NSLAYOUT_NSLAYOUT, -} nslayout_error; + NSL_NO_MEM = (1 << NSL_ERROR_PROV) | NSL_NSLAYOUT, +} nsl_error; /** @@ -46,9 +46,9 @@ typedef enum nslayout_error { * \param[in] err Error code to test * \return error provenance */ -static inline nslayout_error nslayout_error_provenance(nslayout_error err) +static inline nsl_error nsl_error_provenance(nsl_error err) { - return err & ((1 << NSLAYOUT_ERROR_PROV) - 1); + return err & ((1 << NSL_ERROR_PROV) - 1); } @@ -58,9 +58,9 @@ static inline nslayout_error nslayout_error_provenance(nslayout_error err) * \param[in] err Error code to test * \return true iff error is from libnslayout */ -static inline bool nslayout_error_is_layout(nslayout_error err) +static inline bool nsl_error_is_layout(nsl_error err) { - return err & NSLAYOUT_NSLAYOUT; + return err & NSL_NSLAYOUT; } @@ -70,9 +70,9 @@ static inline bool nslayout_error_is_layout(nslayout_error err) * \param[in] err Error code to test * \return true iff error is from libdom */ -static inline bool nslayout_error_is_libdom(nslayout_error err) +static inline bool nsl_error_is_libdom(nsl_error err) { - return err & NSLAYOUT_LIBDOM; + return err & NSL_LIBDOM; } /** @@ -81,9 +81,9 @@ static inline bool nslayout_error_is_libdom(nslayout_error err) * \param[in] err Error code to test * \return true iff error is from libcss */ -static inline bool nslayout_error_is_libcss(nslayout_error err) +static inline bool nsl_error_is_libcss(nsl_error err) { - return err & NSLAYOUT_LIBCSS; + return err & NSL_LIBCSS; } /** @@ -92,7 +92,7 @@ static inline bool nslayout_error_is_libcss(nslayout_error err) * \param[in] err Error code to convert * \return libnslayout error */ -static inline nslayout_error nslayout_error_to_layout(nslayout_error err) +static inline nsl_error nsl_error_to_layout(nsl_error err) { return err; } @@ -103,7 +103,7 @@ static inline nslayout_error nslayout_error_to_layout(nslayout_error err) * \param[in] err Error code to convert * \return dom exception */ -static inline dom_exception nslayout_error_to_libdom(nslayout_error err) +static inline dom_exception nsl_error_to_libdom(nsl_error err) { return err >> 8; } @@ -114,7 +114,7 @@ static inline dom_exception nslayout_error_to_libdom(nslayout_error err) * \param[in] err Error code to convert * \return libcss error */ -static inline css_error nslayout_error_to_libcss(nslayout_error err) +static inline css_error nsl_error_to_libcss(nsl_error err) { return err >> 8; } diff --git a/include/libnslayout/nslayout.h b/include/libnslayout/nslayout.h index 62ce584..551e550 100644 --- a/include/libnslayout/nslayout.h +++ b/include/libnslayout/nslayout.h @@ -9,8 +9,8 @@ * Layout object handling */ -#ifndef nslayout_nslayout_h_ -#define nslayout_nslayout_h_ +#ifndef nsl_nslayout_h_ +#define nsl_nslayout_h_ #ifdef __cplusplus extern "C" @@ -23,45 +23,45 @@ extern "C" #include /** A client-defined replaced element structure */ -typedef struct nslayout_replaced nslayout_replaced; +typedef struct nsl_replaced nsl_replaced; /** A rectangle */ -typedef struct nslayout_rect { +typedef struct nsl_rect { int x; /**< X position of left of rect in px */ int y; /**< Y position of top of rect in px */ int w; /**< Width of rect in px */ int h; /**< Height of rect in px */ -} nslayout_rect; +} nsl_rect; /***/ -enum nslayout_dom_node_event_type { - NSLAYOUT_DOM_NODE_INSERTED, - NSLAYOUT_DOM_NODE_MODIFIED, - NSLAYOUT_DOM_NODE_REMOVED, - NSLAYOUT_DOM_NODE__COUNT, +enum nsl_dom_node_event_type { + NSL_DOM_NODE_INSERTED, + NSL_DOM_NODE_MODIFIED, + NSL_DOM_NODE_REMOVED, + NSL_DOM_NODE__COUNT, }; /** Render list */ -typedef struct nslayout_render_list { -} nslayout_render_list; +typedef struct nsl_render_list { +} nsl_render_list; /** Opaque layout tree object */ -typedef struct nslayout_layout nslayout_layout; +typedef struct nsl_layout nsl_layout; /** * A LibNSLayout request * Client calls to set replaced element intrinsic dimensions. * - * Passed to the client via nslayout_callback + * Passed to the client via nsl_callback */ -typedef struct nslayout_request { +typedef struct nsl_request { /** Request type */ enum { - NSLAYOUT_GET_RESOURCE, - NSLAYOUT_RENDER, - NSLAYOUT_SET_EXTENTS, - NSLAYOUT_GET_INTRINSIC_SIZE + NSL_GET_RESOURCE, + NSL_RENDER, + NSL_SET_EXTENTS, + NSL_GET_INTRINSIC_SIZE } type; /** Request's type-specific parameters */ union { @@ -69,27 +69,27 @@ typedef struct nslayout_request { const char *url; /**< Absolute URL */ } get_resource; struct { - nslayout_render_list *list; /**< Render list */ + nsl_render_list *list; /**< Render list */ } render; struct { unsigned int width; /**< Document width in px */ unsigned int height; /**< Document height in px */ } set_extents; struct { - nslayout_replaced *replaced; /** A replacement object */ + nsl_replaced *replaced; /** A replacement object */ } get_intrinsic_size; } request; /** Request's type-specific return values */ union { struct { - nslayout_replaced **replaced; /** Replacement object */ + nsl_replaced **replaced; /** Replacement object */ } get_resource; struct { unsigned int *width; /** Replacement object's width */ unsigned int *height; /** Replacement object's height */ } get_intrinsic_size; } response; -} nslayout_request; +} nsl_request; /** @@ -98,12 +98,12 @@ typedef struct nslayout_request { * \param[in] layout The layout requiring update for DOM change. * \param[in] node The DOM node which is concerned in the event. * \param[in] type The type of DOM change event. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_dom_node_event( - nslayout_layout *layout, +nsl_error nsl_dom_node_event( + nsl_layout *layout, dom_event_target *node, - enum nslayout_dom_node_event_type type); + enum nsl_dom_node_event_type type); /** * Client calls to set node as client-replaced. @@ -111,12 +111,12 @@ nslayout_error nslayout_dom_node_event( * \param[in] layout The layout to replace an element in. * \param[in] node The DOM node which is to be replaced. * \param[in] replaced The client's replacement object to register with node. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_node_event_set_replaced( - nslayout_layout *layout, +nsl_error nsl_node_event_set_replaced( + nsl_layout *layout, dom_event_target *node, - nslayout_replaced *replaced); + nsl_replaced *replaced); /** @@ -126,10 +126,10 @@ nslayout_error nslayout_node_event_set_replaced( * \param[in] node The DOM node which is to be replaced. * \param[in] width Width in pixels. * \param[in] height Height in pixels. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_node_event_set_intrinsic_dimensions( - nslayout_layout *layout, +nsl_error nsl_node_event_set_intrinsic_dimensions( + nsl_layout *layout, dom_event_target *node, unsigned int width, unsigned int height); @@ -139,25 +139,25 @@ nslayout_error nslayout_node_event_set_intrinsic_dimensions( * Client calls to tell NSLayout that everything requires reselection. * * \param[in]layout The layout to who's selection context has changed. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_selection_context_updated( - nslayout_layout *layout); +nsl_error nsl_selection_context_updated( + nsl_layout *layout); /** * Initialise LibNSLayout * - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_init(void); +nsl_error nsl_init(void); /** * Finalise LibNSLayout * - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_fini(void); +nsl_error nsl_fini(void); /** * LibNSLayout client callback function @@ -165,12 +165,12 @@ nslayout_error nslayout_fini(void); * \param[in] layout The layout we're making a request for. * \param[in] pw The client's private data for this layout. * \param[in,out] req The request details. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -typedef nslayout_error (*nslayout_callback)( - nslayout_layout *layout, +typedef nsl_error (*nsl_callback)( + nsl_layout *layout, void *pw, - nslayout_request *req); + nsl_request *req); /** * Create a Layout object for a given DOM @@ -181,24 +181,24 @@ typedef nslayout_error (*nslayout_callback)( * \param[in] cb The client's private data for this layout. * \param[in] pw The client's private data for this layout. * \param[out] layout Returns a pointer to the created layout object. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_layout_create( +nsl_error nsl_layout_create( dom_document *doc, css_select_ctx *css_ctx, css_media_type *media, - nslayout_callback cb, + nsl_callback cb, void *pw, - nslayout_layout **layout); + nsl_layout **layout); /** * Destroy a Layout object * * \param[in] layout Returns a pointer to the created layout object. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_layout_destroy( - nslayout_layout *layout); +nsl_error nsl_layout_destroy( + nsl_layout *layout); /** * Update the viewport for a layout @@ -211,11 +211,11 @@ nslayout_error nslayout_layout_destroy( * \param[in] viewport Viewport dimensions and offset. * \param[in] scale Rendering scale. * \param[in] dpi DPI of render target with viewport. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_update_viewport( - nslayout_layout *layout, - nslayout_rect *viewport, +nsl_error nsl_update_viewport( + nsl_layout *layout, + nsl_rect *viewport, css_fixed scale, unsigned int dpi); @@ -225,12 +225,12 @@ nslayout_error nslayout_update_viewport( * \param[in] layout Layout to locate an element in. * \param[in] element Element to get area of. * \param[out] area Returns area with position relative to viewport. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_element_get_location( - nslayout_layout *layout, +nsl_error nsl_element_get_location( + nsl_layout *layout, dom_element *element, - nslayout_rect *area); + nsl_rect *area); /** * Find the top-most element at a given point, in terms of z-order. @@ -239,10 +239,10 @@ nslayout_error nslayout_element_get_location( * \param[in] x Mouse x-coordinate (viewport relative). * \param[in] y Mouse y-coordinate (viewport relative). * \param[out] element Returns the element we found. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_element_at_point( - nslayout_layout *layout, +nsl_error nsl_element_at_point( + nsl_layout *layout, unsigned int x, unsigned int y, dom_event_target **element); @@ -254,23 +254,23 @@ nslayout_error nslayout_element_at_point( * \param[in] element Element to mark as needing redraw. * \param[in] rel_area Area of element to redraw relative to object's top-left. * May be NULL, to redraw whole element. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_layout_dirty_element( - nslayout_layout *layout, +nsl_error nsl_layout_dirty_element( + nsl_layout *layout, dom_element *element, - nslayout_rect *rel_area); + nsl_rect *rel_area); /** * Mark an area as needing redraw. * * \param[in] layout Layout to indicate redraw is required for. * \param[in] area Area to redraw relative to viewport's top-left. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nslayout_layout_dirty_area( - nslayout_layout *layout, - nslayout_rect *area); +nsl_error nsl_layout_dirty_area( + nsl_layout *layout, + nsl_rect *area); #ifdef __cplusplus } diff --git a/src/dom/debug.h b/src/dom/debug.h index 7d6b186..cbe8559 100644 --- a/src/dom/debug.h +++ b/src/dom/debug.h @@ -8,8 +8,8 @@ * DOM debug */ -#ifndef nslayout_dom_debug_h_ -#define nslayout_dom_debug_h_ +#ifndef nsl_dom_debug_h_ +#define nsl_dom_debug_h_ /** Define to enable DOM trace debug output */ #undef NSL_DOM_TRACE diff --git a/src/dom/watcher.c b/src/dom/watcher.c index d515cf6..db1f8a9 100644 --- a/src/dom/watcher.c +++ b/src/dom/watcher.c @@ -113,9 +113,9 @@ fail: * * \param[in] listener The listener to destroy * \param[in] document The document that the listener was registerd for. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static nslayout_error nsl__dom_listener_destroy( +static nsl_error nsl__dom_listener_destroy( dom_event_listener *listener, dom_document *document) { @@ -130,7 +130,7 @@ static nslayout_error nsl__dom_listener_destroy( dom_event_listener_unref(listener); - return NSLAYOUT_OK; + return NSL_OK; } @@ -139,9 +139,9 @@ static nslayout_error nsl__dom_listener_destroy( * * \param[out] listener_out Returns a dom listener for watcher's document. * \param[in] watcher DOM watcher object that listener is used for. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static nslayout_error nsl__dom_listener_create( +static nsl_error nsl__dom_listener_create( dom_event_listener **listener_out, const struct nsl_dom_watcher *watcher) { @@ -183,7 +183,7 @@ static nslayout_error nsl__dom_listener_create( } *listener_out = listener; - return NSLAYOUT_OK; + return NSL_OK; error: nsl__dom_listener_destroy(listener, watcher->document); @@ -192,18 +192,18 @@ error: } /* Exported function, documented in src/dom/watcher.h */ -nslayout_error nsl_dom_watcher_create( +nsl_error nsl_dom_watcher_create( struct nsl_dom_watcher **watcher_out, dom_document *document, nsl_dom_watcher_cb watcher_cb, void *pw) { struct nsl_dom_watcher *watcher; - nslayout_error err; + nsl_error err; watcher = malloc(sizeof(*watcher)); if (watcher == NULL) { - return NSLAYOUT_NO_MEM; + return NSL_NO_MEM; } watcher->document = document; @@ -211,21 +211,21 @@ nslayout_error nsl_dom_watcher_create( watcher->pw = pw; err = nsl__dom_listener_create(&watcher->listener, watcher); - if (err != NSLAYOUT_OK) { + if (err != NSL_OK) { free(watcher); return err; } *watcher_out = watcher; - return NSLAYOUT_OK; + return NSL_OK; } /* Exported function, documented in src/dom/watcher.h */ -nslayout_error nsl_dom_watcher_destroy( +nsl_error nsl_dom_watcher_destroy( struct nsl_dom_watcher *watcher) { nsl__dom_listener_destroy(watcher->listener, watcher->document); free(watcher); - return NSLAYOUT_OK; + return NSL_OK; } diff --git a/src/dom/watcher.h b/src/dom/watcher.h index 0883fd2..2cfa26e 100644 --- a/src/dom/watcher.h +++ b/src/dom/watcher.h @@ -8,8 +8,8 @@ * Interface to DOM mutation watching. */ -#ifndef nslayout_dom_watcher_h_ -#define nslayout_dom_watcher_h_ +#ifndef nsl_dom_watcher_h_ +#define nsl_dom_watcher_h_ struct dom_document; struct nsl_dom_watcher; @@ -34,9 +34,9 @@ enum nsl_dom_watcher_type { * \param[in] node The target node. (Caller yields ownership.) * \param[in] node_type The type of node. * \param[in] pw The dom watcher owner's private data. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -typedef nslayout_error (*nsl_dom_watcher_cb)( +typedef nsl_error (*nsl_dom_watcher_cb)( enum nsl_dom_watcher_type type, dom_event_target *node, dom_node_type node_type, @@ -50,9 +50,9 @@ typedef nslayout_error (*nsl_dom_watcher_cb)( * \param[in] document DOM document to create watcher for. * \param[in] watcher_cb Function to call when dom modification happens. * \param[in] pw Private data passed back to `watcher_cb`. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nsl_dom_watcher_create( +nsl_error nsl_dom_watcher_create( struct nsl_dom_watcher **watcher_out, dom_document *document, nsl_dom_watcher_cb watcher_cb, @@ -63,9 +63,9 @@ nslayout_error nsl_dom_watcher_create( * Destroy a document change DOM change watcher. * * \param[in] watcher DOM change watcher to destroy. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nsl_dom_watcher_destroy( +nsl_error nsl_dom_watcher_destroy( struct nsl_dom_watcher *watcher); #endif diff --git a/src/layout.c b/src/layout.c index e4824bf..0c11660 100644 --- a/src/layout.c +++ b/src/layout.c @@ -22,11 +22,11 @@ /** * The layout object for a DOM document */ -struct nslayout_layout { +struct nsl_layout { dom_document *document; css_select_ctx *css_ctx; css_media_type *media; - nslayout_callback cb; + nsl_callback cb; void *pw; struct nsl_dom_watcher *watcher; @@ -34,14 +34,14 @@ struct nslayout_layout { /* Publically exported function, documented in include/libnslayout/nslayout.h */ -nslayout_error nslayout_init(void) +nsl_error nsl_init(void) { return nsl_dom_str_init(); } /* Publically exported function, documented in include/libnslayout/nslayout.h */ -nslayout_error nslayout_fini(void) +nsl_error nsl_fini(void) { return nsl_dom_str_fini(); } @@ -54,15 +54,15 @@ nslayout_error nslayout_fini(void) * \param[in] node The target node. (Caller yields ownership.) * \param[in] node_type The type of node. * \param[in] pw The layout object. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static nslayout_error nsl_layout_dom_watcher_cb( +static nsl_error nsl_layout_dom_watcher_cb( enum nsl_dom_watcher_type type, dom_event_target *node, dom_node_type node_type, void *pw) { - nslayout_layout *layout = pw; + nsl_layout *layout = pw; UNUSED(type); UNUSED(layout); @@ -77,30 +77,30 @@ static nslayout_error nsl_layout_dom_watcher_cb( dom_node_unref(node); - return NSLAYOUT_OK; + return NSL_OK; } /* Publically exported function, documented in include/libnslayout/nslayout.h */ -nslayout_error nslayout_layout_create( +nsl_error nsl_layout_create( dom_document *doc, css_select_ctx *css_ctx, css_media_type *media, - nslayout_callback cb, + nsl_callback cb, void *pw, - nslayout_layout **layout) + nsl_layout **layout) { - nslayout_layout *l = NULL; - nslayout_error err; + nsl_layout *l = NULL; + nsl_error err; assert(doc != NULL); assert(css_ctx != NULL); assert(media != NULL); assert(cb != NULL); - l = calloc(1, sizeof(nslayout_layout)); + l = calloc(1, sizeof(nsl_layout)); if (l == NULL) { - return NSLAYOUT_NO_MEM; + return NSL_NO_MEM; } /* TODO: Decide: ownership will probably be passed to libnslayout */ @@ -112,29 +112,29 @@ nslayout_error nslayout_layout_create( err = nsl_dom_watcher_create(&l->watcher, l->document, nsl_layout_dom_watcher_cb, l); - if (err != NSLAYOUT_OK) { + if (err != NSL_OK) { return err; } *layout = l; - return NSLAYOUT_OK; + return NSL_OK; } /* Publically exported function, documented in include/libnslayout/nslayout.h */ -nslayout_error nslayout_layout_destroy( - nslayout_layout *layout) +nsl_error nsl_layout_destroy( + nsl_layout *layout) { - nslayout_error err; + nsl_error err; assert(layout != NULL); /* TODO: free/unref the stuff we own in the layout */ err = nsl_dom_watcher_destroy(layout->watcher); - if (err != NSLAYOUT_OK) { + if (err != NSL_OK) { return err; } free(layout); - return NSLAYOUT_OK; + return NSL_OK; } diff --git a/src/layout.h b/src/layout.h index d8fa3b2..22c05e4 100644 --- a/src/layout.h +++ b/src/layout.h @@ -8,9 +8,9 @@ * Layout object handling */ -#ifndef nslayout_layout_h_ -#define nslayout_layout_h_ +#ifndef nsl_layout_h_ +#define nsl_layout_h_ -struct nslayout_layout; +struct nsl_layout; #endif diff --git a/src/request.h b/src/request.h index c28468e..7c21731 100644 --- a/src/request.h +++ b/src/request.h @@ -8,8 +8,8 @@ * Client callback wrappers */ -#ifndef nslayout_request_h_ -#define nslayout_request_h_ +#ifndef nsl_request_h_ +#define nsl_request_h_ #include @@ -19,17 +19,17 @@ * \param[in] layout Layout object that the request concerns. * \param[in] url Absolute URL to request replaced object handle for. * \param[out] replaced Returns the replaced element content handle. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static inline nslayout_error nsl_request_get_resource( - nslayout_layout *layout, +static inline nsl_error nsl_request_get_resource( + nsl_layout *layout, const char *url, - nslayout_replaced **replaced) + nsl_replaced **replaced) { - nslayout_error err; - nslayout_request req; + nsl_error err; + nsl_request req; - req.type = NSLAYOUT_GET_RESOURCE; + req.type = NSL_GET_RESOURCE; req.request.get_resource.url = url; err = layout->cb(layout, layout->pw, &req); @@ -44,17 +44,17 @@ static inline nslayout_error nsl_request_get_resource( * \param[in] layout Layout object that the request concerns. * \param[in] element DOM element that needs replacement object. * \param[out] replaced Returns the replaced element content handle. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static inline nslayout_error nsl_request_create_replaced( - nslayout_layout *layout, +static inline nsl_error nsl_request_create_replaced( + nsl_layout *layout, dom_element *element, - nslayout_replaced **replaced) + nsl_replaced **replaced) { - nslayout_error err; - nslayout_request req; + nsl_error err; + nsl_request req; - req.type = NSLAYOUT_CREATE_REPLACED; + req.type = NSL_CREATE_REPLACED; req.request.create_replaced.element = element; err = layout->cb(layout, layout->pw, &req); @@ -68,16 +68,16 @@ static inline nslayout_error nsl_request_create_replaced( * * \param[in] layout Layout object being rendered. * \param[in] list Render list to render. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static inline nslayout_error nsl_request_render( - nslayout_layout *layout, - nslayout_render_list *list) +static inline nsl_error nsl_request_render( + nsl_layout *layout, + nsl_render_list *list) { - nslayout_error err; - nslayout_request req; + nsl_error err; + nsl_request req; - req.type = NSLAYOUT_RENDER; + req.type = NSL_RENDER; req.request.render.list = list; err = layout->cb(layout, layout->pw, &req); @@ -91,17 +91,17 @@ static inline nslayout_error nsl_request_render( * \param[in] layout Layout object that the request concerns. * \param[in] width The layout's full width. * \param[in] height The layout's full height. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static inline nslayout_error nsl_request_set_extents( - nslayout_layout *layout, +static inline nsl_error nsl_request_set_extents( + nsl_layout *layout, unsigned int width, unsigned int height) { - nslayout_error err; - nslayout_request req; + nsl_error err; + nsl_request req; - req.type = NSLAYOUT_SET_EXTENTS; + req.type = NSL_SET_EXTENTS; req.request.set_extents.width = width; req.request.set_extents.height = height; @@ -117,18 +117,18 @@ static inline nslayout_error nsl_request_set_extents( * \param[in] replaced Replaced object to get intrinsic size of. * \param[out] width Returns the replaced object's width. * \param[out] height Returns the replaced object's height. - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -static inline nslayout_error nsl_request_get_intrinsic_size( - nslayout_layout *layout, - nslayout_replaced *replaced, +static inline nsl_error nsl_request_get_intrinsic_size( + nsl_layout *layout, + nsl_replaced *replaced, unsigned int *width, unsigned int *height) { - nslayout_error err; - nslayout_request req; + nsl_error err; + nsl_request req; - req.type = NSLAYOUT_GET_INTRINSIC_SIZE; + req.type = NSL_GET_INTRINSIC_SIZE; req.request.get_intrinsic_size.replaced = replaced; err = layout->cb(layout, layout->pw, &req); diff --git a/src/util/dom-str.c b/src/util/dom-str.c index 3c0865a..db53c76 100644 --- a/src/util/dom-str.c +++ b/src/util/dom-str.c @@ -23,9 +23,9 @@ dom_string *nsl_dom_str_characterdata_modified; /* Exported function, documented in src/util/dom-str.h */ -nslayout_error nsl_dom_str_init(void) +nsl_error nsl_dom_str_init(void) { - nslayout_error err; + nsl_error err; dom_exception exc; exc = dom_string_create((const uint8_t *)"DOMNodeInserted", @@ -59,7 +59,7 @@ nslayout_error nsl_dom_str_init(void) goto out; } - err = NSLAYOUT_OK; + err = NSL_OK; out: if (exc != DOM_NO_ERR) { printf("Failed to initialise dom_str!\n"); @@ -72,7 +72,7 @@ out: /* Exported function, documented in src/util/dom-str.h */ -nslayout_error nsl_dom_str_fini(void) +nsl_error nsl_dom_str_fini(void) { dom_string_unref(nsl_dom_str_node_inserted); dom_string_unref(nsl_dom_str_node_removed); @@ -80,5 +80,5 @@ nslayout_error nsl_dom_str_fini(void) dom_string_unref(nsl_dom_str_attr_modified); dom_string_unref(nsl_dom_str_characterdata_modified); - return NSLAYOUT_OK; + return NSL_OK; } diff --git a/src/util/dom-str.h b/src/util/dom-str.h index 9ce7bb9..fb2d0ff 100644 --- a/src/util/dom-str.h +++ b/src/util/dom-str.h @@ -8,8 +8,8 @@ * Layout object handling */ -#ifndef nslayout_util_dom_str_h_ -#define nslayout_util_dom_str_h_ +#ifndef nsl_util_dom_str_h_ +#define nsl_util_dom_str_h_ extern dom_string *nsl_dom_str_node_inserted; extern dom_string *nsl_dom_str_node_removed; @@ -20,15 +20,15 @@ extern dom_string *nsl_dom_str_characterdata_modified; /** * Create the internal DOM strings * - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nsl_dom_str_init(void); +nsl_error nsl_dom_str_init(void); /** * Unref the internal DOM strings * - * \return NSLAYOUT_OK on success, appropriate error otherwise. + * \return NSL_OK on success, appropriate error otherwise. */ -nslayout_error nsl_dom_str_fini(void); +nsl_error nsl_dom_str_fini(void); #endif diff --git a/src/util/util.h b/src/util/util.h index f63f40f..5bb661e 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -8,8 +8,8 @@ * Layout object handling */ -#ifndef nslayout_util_util_h_ -#define nslayout_util_util_h_ +#ifndef nsl_util_util_h_ +#define nsl_util_util_h_ #ifndef UNUSED #define UNUSED(x_) (void)(x_) @@ -19,7 +19,7 @@ #define SLEN(x_) (sizeof((x_)) - 1) #endif -#define NSL_DOM_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBDOM) -#define NSL_CSS_ERR(x_) ((x_ << 8) | NSLAYOUT_LIBCSS) +#define NSL_DOM_ERR(x_) ((x_ << 8) | NSL_LIBDOM) +#define NSL_CSS_ERR(x_) ((x_ << 8) | NSL_LIBCSS) #endif diff --git a/test/assert-tests.c b/test/assert-tests.c index 44bc2f7..f30efed 100644 --- a/test/assert-tests.c +++ b/test/assert-tests.c @@ -15,34 +15,34 @@ #endif /* TODO: Test for each individual param being NULL. */ -START_TEST (test_nslayout_layout_create_aborts1) +START_TEST (test_nsl_layout_create_aborts1) { - nslayout_layout *layout; + nsl_layout *layout; - (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout); + (void) nsl_layout_create(NULL, NULL, NULL, NULL, NULL, &layout); } END_TEST /* TODO: Test for each individual param being NULL. */ -START_TEST (test_nslayout_layout_destroy_aborts1) +START_TEST (test_nsl_layout_destroy_aborts1) { - (void) nslayout_layout_destroy(NULL); + (void) nsl_layout_destroy(NULL); } END_TEST -void nslayout_assert_suite(SRunner *sr) +void nsl_assert_suite(SRunner *sr) { Suite *s = suite_create("libnslayout: API Assert tests"); TCase *tc_assert = tcase_create("Creation/Destruction"); tcase_add_test_raise_signal( tc_assert, - test_nslayout_layout_create_aborts1, + test_nsl_layout_create_aborts1, SIGABRT); tcase_add_test_raise_signal( tc_assert, - test_nslayout_layout_destroy_aborts1, + test_nsl_layout_destroy_aborts1, SIGABRT); suite_add_tcase(s, tc_assert); diff --git a/test/nslayout-object-tests.c b/test/nslayout-object-tests.c index 612a983..4a3f2c4 100644 --- a/test/nslayout-object-tests.c +++ b/test/nslayout-object-tests.c @@ -14,21 +14,21 @@ #define UNUSED(x) (void)(x) #endif -static nslayout_error nslayout_test_callback( - nslayout_layout *layout, +static nsl_error nsl_test_callback( + nsl_layout *layout, void *pw, - nslayout_request *req) + nsl_request *req) { UNUSED(req); UNUSED(layout); UNUSED(pw); - return NSLAYOUT_OK; + return NSL_OK; } -START_TEST (test_nslayout_layout_create_ok) +START_TEST (test_nsl_layout_create_ok) { - nslayout_layout *layout = NULL; - nslayout_error error; + nsl_layout *layout = NULL; + nsl_error error; dom_exception dom_error; css_error css_err; dom_document *doc; @@ -44,24 +44,24 @@ START_TEST (test_nslayout_layout_create_ok) css_err = css_select_ctx_create(&css_ctx); ck_assert(css_err == CSS_OK); - ck_assert(nslayout_init() == NSLAYOUT_OK); + ck_assert(nsl_init() == NSL_OK); - error = nslayout_layout_create(doc, + error = nsl_layout_create(doc, css_ctx, &media, - nslayout_test_callback, + nsl_test_callback, NULL, &layout); - fail_unless(error == NSLAYOUT_OK, + fail_unless(error == NSL_OK, "Unable to create layout"); fail_unless(layout != NULL, "Returned OK but str was still NULL"); - error = nslayout_layout_destroy(layout); - fail_unless(error == NSLAYOUT_OK, + error = nsl_layout_destroy(layout); + fail_unless(error == NSL_OK, "Unable to destroy layout"); - ck_assert(nslayout_fini() == NSLAYOUT_OK); + ck_assert(nsl_fini() == NSL_OK); css_err = css_select_ctx_destroy(css_ctx); ck_assert(css_err == CSS_OK); @@ -71,12 +71,12 @@ START_TEST (test_nslayout_layout_create_ok) END_TEST -void nslayout_nslayout_object_suite(SRunner *sr) +void nsl_nsl_object_suite(SRunner *sr) { Suite *s = suite_create("libnslayout: nslayout object tests"); TCase *tc_layout_basic = tcase_create("Creation/Destruction"); - tcase_add_test(tc_layout_basic, test_nslayout_layout_create_ok); + tcase_add_test(tc_layout_basic, test_nsl_layout_create_ok); suite_add_tcase(s, tc_layout_basic); srunner_add_suite(sr, s); diff --git a/test/test-loader.c b/test/test-loader.c index 6d52691..cab08d6 100644 --- a/test/test-loader.c +++ b/test/test-loader.c @@ -19,15 +19,15 @@ #define UNUSED(x) (void)(x) #endif -static nslayout_error test_loader_nslayout_test_callback( - nslayout_layout *layout, +static nsl_error test_loader_nsl_test_callback( + nsl_layout *layout, void *pw, - nslayout_request *req) + nsl_request *req) { UNUSED(req); UNUSED(layout); UNUSED(pw); - return NSLAYOUT_OK; + return NSL_OK; } struct test_loader_buffer { @@ -293,8 +293,8 @@ static bool test_loader( css_media_type media, size_t chunk_size) { - nslayout_layout *layout = NULL; - nslayout_error error; + nsl_layout *layout = NULL; + nsl_error error; struct test_loader_ctx load_ctx; bool complete = false; bool ret = false; @@ -320,13 +320,13 @@ static bool test_loader( } printf("Creating nsl layout\n"); - error = nslayout_layout_create(load_ctx.doc, + error = nsl_layout_create(load_ctx.doc, load_ctx.css_ctx, &media, - test_loader_nslayout_test_callback, + test_loader_nsl_test_callback, NULL, &layout); - if (error != NSLAYOUT_OK) { + if (error != NSL_OK) { goto fail; } @@ -340,13 +340,13 @@ static bool test_loader( } printf("Destroying layout\n"); - error = nslayout_layout_destroy(layout); + error = nsl_layout_destroy(layout); layout = NULL; - ret = (error == NSLAYOUT_OK); + ret = (error == NSL_OK); fail: if (layout != NULL) { - nslayout_layout_destroy(layout); + nsl_layout_destroy(layout); } test_loader_css_fini(&load_ctx); dom_node_unref(load_ctx.doc); diff --git a/test/tests.c b/test/tests.c index 48fc68c..9ca987c 100644 --- a/test/tests.c +++ b/test/tests.c @@ -38,9 +38,9 @@ int main(int argc, char **argv) sr = srunner_create(suite_create("Test suite for libnslayout")); #ifndef NDEBUG - nslayout_assert_suite(sr); + nsl_assert_suite(sr); #endif - nslayout_nslayout_object_suite(sr); + nsl_nsl_object_suite(sr); srunner_set_fork_status(sr, CK_FORK); srunner_run_all(sr, CK_ENV); diff --git a/test/tests.h b/test/tests.h index 9f05d9c..fd89bea 100644 --- a/test/tests.h +++ b/test/tests.h @@ -4,8 +4,8 @@ * Copyright 2015 Michael Drake */ -#ifndef nslayout_tests_h_ -#define nslayout_tests_h_ +#ifndef nsl_tests_h_ +#define nsl_tests_h_ #include @@ -13,7 +13,7 @@ #include -extern void nslayout_assert_suite(SRunner *); -extern void nslayout_nslayout_object_suite(SRunner *); +extern void nsl_assert_suite(SRunner *); +extern void nsl_nsl_object_suite(SRunner *); #endif -- cgit v1.2.3