Split utils header into string functions and everything else

split out the string handling API from the rest of the utils header
and fix up all the fallout.
This commit is contained in:
Vincent Sanders 2016-04-21 22:36:21 +01:00
parent 3488e337b6
commit 7d9c9dba36
41 changed files with 187 additions and 182 deletions

View File

@ -47,6 +47,7 @@
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/string.h"
#include "desktop/download.h"
#include "desktop/save_complete.h"
#include "desktop/browser.h"

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>

View File

@ -18,6 +18,7 @@
#include "amiga/os3support.h"
#include <stdlib.h>
#include <string.h>
#include <proto/clicktab.h>

View File

@ -18,6 +18,7 @@
#include "amiga/os3support.h"
#include <stdlib.h>
#include <proto/window.h>
#include <proto/layout.h>
#include <proto/space.h>

View File

@ -29,6 +29,7 @@
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/nsoption.h"
#include "utils/string.h"
#include "content/urldb.h"
#include "content/fetch.h"
#include "desktop/save_complete.h"

View File

@ -29,6 +29,7 @@
#include "utils/url.h"
#include "utils/nsurl.h"
#include "utils/file.h"
#include "utils/string.h"
/**
* \file

View File

@ -24,6 +24,7 @@ extern "C" {
#include "desktop/download.h"
#include "desktop/gui_download.h"
#include "utils/utils.h"
#include "utils/string.h"
}
#include "beos/download.h"

View File

@ -31,6 +31,7 @@
* fetches are stored in the ::queue_ring waiting for use.
*/
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>

View File

@ -16,7 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \file content/fetchers/about.c
/**
* \file
*
* URL handling for the "about" scheme.
*
@ -25,39 +26,24 @@
* information from the browser from a known, fixed URL.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <libwapcaplet/libwapcaplet.h>
#include "testament.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/utils.h"
#include "utils/ring.h"
#include "utils/config.h"
#include "utils/dirent.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/fetchers/about.h"
#include "content/urldb.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/ring.h"
#include "content/content_type.h"
#include "image/image_cache.h"
struct fetch_about_context;
typedef bool (*fetch_about_handler)(struct fetch_about_context *);

View File

@ -51,6 +51,7 @@
#include "utils/ring.h"
#include "utils/useragent.h"
#include "utils/file.h"
#include "utils/string.h"
#include "desktop/gui_fetch.h"
#include "desktop/gui_internal.h"

View File

@ -16,32 +16,28 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* data: URL handling. See http://tools.ietf.org/html/rfc2397 */
/**
* \file
* data scheme handling. See http://tools.ietf.org/html/rfc2397
*/
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <curl/curl.h> /* for URL unescaping functions */
#include <stdlib.h>
#include <curl/curl.h> /* for URL unescaping functions */
#include <libwapcaplet/libwapcaplet.h>
#include "utils/config.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/fetchers/data.h"
#include "content/urldb.h"
#include "utils/nsurl.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/ring.h"
#include "utils/base64.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/fetchers/data.h"
struct fetch_data_context {
struct fetch *parent_fetch;
char *url;

View File

@ -24,33 +24,26 @@
#include "utils/config.h"
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <inttypes.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#ifdef HAVE_MMAP
#include <sys/mman.h>
#endif
#include <libwapcaplet/libwapcaplet.h>
#include "utils/nsurl.h"
#include "utils/dirent.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/errors.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/ring.h"
@ -61,7 +54,6 @@
#include "content/dirlist.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/urldb.h"
#include "content/fetchers/file.h"
/* Maximum size of read buffer */

View File

@ -21,27 +21,15 @@
* resource scheme URL handling. Based on the data fetcher by Rob Kendrick
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <stdbool.h>
#include <inttypes.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <libwapcaplet/libwapcaplet.h>
#include "utils/dirent.h"
#include "utils/errors.h"
#include "utils/nsurl.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
@ -52,7 +40,6 @@
#include "content/fetch.h"
#include "content/fetchers.h"
#include "content/fetchers/resource.h"
#include "content/urldb.h"
#define DIRECT_ETAG_VALUE 123456

View File

@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <sys/types.h>
#include <assert.h>
#include <stdint.h>

View File

@ -22,6 +22,7 @@
* Implementation of gtk about dialog.
*/
#include <stdlib.h>
#include <stdint.h>
#include "utils/utils.h"

View File

@ -28,6 +28,7 @@
#include "utils/nsurl.h"
#include "utils/messages.h"
#include "utils/nsoption.h"
#include "utils/string.h"
#include "desktop/download.h"
#include "desktop/gui_download.h"

View File

@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <gtk/gtk.h>
#include "utils/log.h"

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <string.h>

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <gtk/gtk.h>

View File

@ -21,6 +21,7 @@
* Generic tree handling (implementation).
*/
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <limits.h>

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <gtk/gtk.h>
#include "utils/utils.h"

View File

@ -22,6 +22,7 @@
* Implementation of gtk windowing.
*/
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>
#include <limits.h>

View File

@ -22,36 +22,17 @@
* This fetcher implements http://www.whatwg.org/specs/web-apps/current-work/multipage/browsers.html#javascript-protocol
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <inttypes.h>
#include <string.h>
#include <strings.h>
#include <time.h>
#include <stdio.h>
#include <limits.h>
#include <stdarg.h>
#include <stdlib.h>
#include <libwapcaplet/libwapcaplet.h>
#include "utils/config.h"
#include "utils/errors.h"
#include "utils/nsurl.h"
#include "utils/corestrings.h"
#include "utils/nsoption.h"
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/ring.h"
#include "content/fetch.h"
#include "content/fetchers.h"
#include "javascript/fetcher.h"
#include "content/urldb.h"
/** Context for an resource fetch */
struct fetch_javascript_context {
@ -62,7 +43,7 @@ struct fetch_javascript_context {
bool aborted; /**< Flag indicating fetch has been aborted */
bool locked; /**< Flag indicating entry is already entered */
nsurl *url;
nsurl *url; /**< The URL being fetched */
};
static struct fetch_javascript_context *ring = NULL;

View File

@ -19,6 +19,7 @@
/* Browser-related callbacks */
#include <stdio.h>
#include <stdlib.h>
#include "utils/utils.h"
#include "utils/ring.h"

View File

@ -22,7 +22,7 @@
/**
* \file
* Conversion of XML tree to box tree (implementation).
* Implementation of conversion from DOM tree to box tree.
*/
#include <assert.h>
@ -34,11 +34,6 @@
#include <strings.h>
#include "utils/config.h"
#include "content/content_protected.h"
#include "css/css.h"
#include "css/hints.h"
#include "css/select.h"
#include "css/utils.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/locale.h"
@ -46,6 +41,12 @@
#include "utils/messages.h"
#include "utils/talloc.h"
#include "utils/utils.h"
#include "utils/string.h"
#include "content/content_protected.h"
#include "css/css.h"
#include "css/hints.h"
#include "css/select.h"
#include "css/utils.h"
#include "desktop/gui_misc.h"
#include "desktop/gui_internal.h"

View File

@ -39,6 +39,7 @@
#include "utils/talloc.h"
#include "utils/utf8.h"
#include "utils/nsoption.h"
#include "utils/string.h"
#include "content/content_protected.h"
#include "content/fetch.h"
#include "content/hlcache.h"

View File

@ -52,6 +52,7 @@
#include "utils/nsurl.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "utils/string.h"
#include "utils/corestrings.h"
#include "desktop/gui_download.h"
#include "desktop/download.h"

View File

@ -18,6 +18,7 @@
#include <stdbool.h>
#include <swis.h>
#include <stdlib.h>
#include <oslib/colourtrans.h>
#include <oslib/osspriteop.h>

View File

@ -23,8 +23,9 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "oslib/osfile.h"
#include "oslib/wimp.h"
#include <stdlib.h>
#include <oslib/osfile.h>
#include <oslib/wimp.h>
#include "utils/log.h"
#include "utils/utf8.h"

View File

@ -23,6 +23,7 @@
#include <assert.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <oslib/osbyte.h>
#include <oslib/territory.h>

View File

@ -29,8 +29,9 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "oslib/inetsuite.h"
#include "oslib/wimp.h"
#include <stdlib.h>
#include <oslib/inetsuite.h>
#include <oslib/wimp.h>
#include "utils/log.h"
#include "utils/messages.h"

View File

@ -51,6 +51,7 @@
#include "utils/utf8.h"
#include "utils/utils.h"
#include "utils/messages.h"
#include "utils/string.h"
#include "content/content.h"
#include "content/hlcache.h"
#include "content/urldb.h"

View File

@ -33,6 +33,7 @@
#include "utils/corestrings.h"
#include "utils/url.h"
#include "utils/nsurl.h"
#include "utils/string.h"
#include "utils/file.h"
/**

View File

@ -25,6 +25,7 @@
* fast access.
*/
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>

115
utils/string.h Normal file
View File

@ -0,0 +1,115 @@
/*
* Copyright 2016 Vincent Sanders <vince@netsurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file
* \brief Interface to utility string handling.
*/
#ifndef _NETSURF_UTILS_STRING_H_
#define _NETSURF_UTILS_STRING_H_
#include <stdlib.h>
#include <stdarg.h>
#include "utils/errors.h"
/**
* Replace consecutive whitespace with a single space.
*
* @todo determine if squash_whitespace utf-8 safe and that it needs to be
*
* \param s source string
* \return heap allocated result, or NULL on memory exhaustion
*/
char *squash_whitespace(const char * s);
/**
* Converts NUL terminated UTF-8 encoded string s containing zero or more
* spaces (char 32) or TABs (char 9) to non-breaking spaces
* (0xC2 + 0xA0 in UTF-8 encoding).
*
* Caller needs to free() result. Returns NULL in case of error. No
* checking is done on validness of the UTF-8 input string.
*/
char *cnv_space2nbsp(const char *s);
/**
* Create a human readable representation of a size in bytes.
*
* Does a simple conversion which assumes the user speaks English.
* The buffer returned is one of three static ones so may change each
* time this call is made. Don't store the buffer for later use.
* It's done this way for convenience and to fight possible memory
* leaks, it is not necessarily pretty.
*
* @param bytesize The size in bytes.
* @return A human readable string representing the size.
*/
char *human_friendly_bytesize(unsigned long bytesize);
/**
* Generate a string from one or more component elements separated with
* a single value.
*
* This is similar in intent to the perl join function creating a
* single delimited string from an array of several.
*
* @note If a string is allocated it must be freed by the caller.
*
* @param[in,out] str pointer to string pointer if this is NULL enough
* storage will be allocated for the complete path.
* @param[in,out] size The size of the space available if \a str not
* NULL on input and if not NULL set to the total
* output length on output.
* @param[in] sep The character to separate the elements with.
* @param[in] nelm The number of elements up to a maximum of 16.
* @param[in] ap The elements of the path as string pointers.
* @return NSERROR_OK and the complete path is written to str or error
* code on failure.
*/
nserror vsnstrjoin(char **str, size_t *size, char sep, size_t nelm, va_list ap);
/**
* Generate a string from one or more component elements separated with
* a single value.
*
* This is similar in intent to the Perl join function creating a
* single delimited string from an array of several.
*
* @note If a string is allocated it must be freed by the caller.
*
* @param[in,out] str pointer to string pointer if this is NULL enough
* storage will be allocated for the complete path.
* @param[in,out] size The size of the space available if \a str not
* NULL on input and if not NULL set to the total
* output length on output.
* @param[in] sep The character to separate the elements with.
* @param[in] nelm The number of elements up to a maximum of 16.
* @param[in] ... The elements of the path as string pointers.
* @return NSERROR_OK and the complete path is written to str or error
* code on failure.
*/
nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...);
#endif

View File

@ -24,11 +24,11 @@
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
#include "utils/config.h"
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/url.h"

View File

@ -40,6 +40,7 @@
#include "utils/sys_time.h"
#include "utils/inet.h"
#include "utils/dirent.h"
#include "utils/string.h"
#include "utils/utils.h"
/* exported interface documented in utils/utils.h */

View File

@ -28,10 +28,6 @@
#include <inttypes.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#include "utils/errors.h"
/** Rectangle coordinates */
struct rect {
@ -114,92 +110,11 @@ struct dirent;
#define SLEN(x) (sizeof((x)) - 1)
/**
* Replace consecutive whitespace with a single space.
*
* @todo determine if squash_whitespace utf-8 safe and that it needs to be
*
* \param s source string
* \return heap allocated result, or NULL on memory exhaustion
*/
char * squash_whitespace(const char * s);
/**
* Converts NUL terminated UTF-8 encoded string s containing zero or more
* spaces (char 32) or TABs (char 9) to non-breaking spaces
* (0xC2 + 0xA0 in UTF-8 encoding).
*
* Caller needs to free() result. Returns NULL in case of error. No
* checking is done on validness of the UTF-8 input string.
*/
char *cnv_space2nbsp(const char *s);
/**
* Check if a directory exists.
*/
bool is_dir(const char *path);
/**
* Create a human redable representation of a size in bytes.
*
* Does a simple conversion which assumes the user speaks English.
* The buffer returned is one of three static ones so may change each
* time this call is made. Don't store the buffer for later use.
* It's done this way for convenience and to fight possible memory
* leaks, it is not necessarily pretty.
*
* @todo This implementation is strange doe sit need
* reconsidering?
*
* @param bytesize The size in bytes.
* @return A human readable string representing the size.
*/
char *human_friendly_bytesize(unsigned long bytesize);
/**
* Generate a string from one or more component elemnts separated with
* a single value.
*
* This is similar in intent to the perl join function creating a
* single delimited string from an array of several.
*
* @note If a string is allocated it must be freed by the caller.
*
* @param[in,out] str pointer to string pointer if this is NULL enough
* storage will be allocated for the complete path.
* @param[in,out] size The size of the space available if \a str not
* NULL on input and if not NULL set to the total
* output length on output.
* @param[in] sep The character to separete the elemnts with.
* @param[in] nelm The number of elements up to a maximum of 16.
* @param[in] ap The elements of the path as string pointers.
* @return NSERROR_OK and the complete path is written to str or error
* code on faliure.
*/
nserror vsnstrjoin(char **str, size_t *size, char sep, size_t nelm, va_list ap);
/**
* Generate a string from one or more component elemnts separated with
* a single value.
*
* This is similar in intent to the perl join function creating a
* single delimited string from an array of several.
*
* @note If a string is allocated it must be freed by the caller.
*
* @param[in,out] str pointer to string pointer if this is NULL enough
* storage will be allocated for the complete path.
* @param[in,out] size The size of the space available if \a str not
* NULL on input and if not NULL set to the total
* output length on output.
* @param[in] sep The character to separete the elemnts with.
* @param[in] nelm The number of elements up to a maximum of 16.
* @param[in] ... The elements of the path as string pointers.
* @return NSERROR_OK and the complete path is written to str or error
* code on faliure.
*/
nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...);
/* Platform specific functions */
void warn_user(const char *warning, const char *detail);

View File

@ -29,6 +29,7 @@
#include "utils/url.h"
#include "utils/nsurl.h"
#include "utils/utils.h"
#include "utils/string.h"
#include "content/fetch.h"
#include "desktop/gui_download.h"
#include "desktop/download.h"

View File

@ -34,6 +34,7 @@
#include "utils/corestrings.h"
#include "utils/url.h"
#include "utils/file.h"
#include "utils/string.h"
#include "desktop/browser.h"
#include "windows/file.h"

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <time.h>
#include "utils/sys_time.h"