changeset 135:07800b7af208

Huge cosmetic, no breakage
author David Demelier <markand@malikania.fr>
date Tue, 20 Mar 2012 22:49:37 +0100
parents 195cdc5f4a32
children c6d9eb5702e8
files array.h buf.h ini.c ini.h pack.h parray.h
diffstat 6 files changed, 102 insertions(+), 84 deletions(-) [+]
line wrap: on
line diff
--- a/array.h	Mon Mar 12 21:49:59 2012 +0100
+++ b/array.h	Tue Mar 20 22:49:37 2012 +0100
@@ -19,12 +19,12 @@
 #ifndef _ARRAY_H_
 #define _ARRAY_H_
 
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdarg.h>
-
 #ifndef ARRAY_DEFAULT_BSIZE
 #define ARRAY_DEFAULT_BSIZE	128
 #endif
@@ -35,12 +35,12 @@
 };
 
 struct array {
-	int	type;	/* array's type (default FIXED) */
-	void	*data;	/* array of data */
-	int	length;	/* number of element inside */
-	size_t	size;	/* current buffer size (allocated memory) */
-	size_t	unit;	/* unit size (sizeof the object) */
-	int	bsize;	/* block size (used when growing array) */
+	int	type;		/* (ro) array's type (default FIXED) */
+	void	*data;		/* (rw) array of data */
+	int	length;		/* (ro) number of element inside */
+	size_t	size;		/* (ro) current buffer size (allocated memory) */
+	size_t	unit;		/* (ro) unit size (sizeof the object) */
+	int	bsize;		/* (rw) block size (used when growing array) */
 
 	/* Own allocation functions */
 	void * (*malloc)(size_t);
--- a/buf.h	Mon Mar 12 21:49:59 2012 +0100
+++ b/buf.h	Tue Mar 20 22:49:37 2012 +0100
@@ -19,12 +19,12 @@
 #ifndef _BUF_H_
 #define _BUF_H_
 
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdarg.h>
-
 #ifndef BUF_DEFAULT_BSIZE
 #define BUF_DEFAULT_BSIZE	128
 #endif
@@ -46,11 +46,11 @@
 };
 
 struct buf {
-	int		flags;	/* string flags */
-	char		*text;	/* string text */
-	size_t		length;	/* string length */
-	size_t		alsize;	/* allocated size */
-	int		bsize;	/* block size (used when growing array) */
+	int		flags;		/* (ro) string flags */
+	char		*text;		/* (ro) string text */
+	size_t		length;		/* (ro) string length */
+	size_t		alsize;		/* (ro) allocated size */
+	int		bsize;		/* (ro) block size (used when growing */
 
 	/* Own allocation functions */
 	void * (*malloc)(size_t);
--- a/ini.c	Mon Mar 12 21:49:59 2012 +0100
+++ b/ini.c	Tue Mar 20 22:49:37 2012 +0100
@@ -65,14 +65,14 @@
 	if ((fp = fopen(path, "r")) == NULL)
 		return ini_fatal(conf, fp, "%s: %s", path, strerror(errno));
 
-	if ((conf->_line = calloc(1024 + 1, 1)) == NULL)
+	if ((conf->ic_line = calloc(1024 + 1, 1)) == NULL)
 		return ini_fatal(conf, fp, "%s", strerror(errno));
 
 	conf->path	= path;
 	conf->flags	= flags;
-	conf->_ignore	= 1;
-	conf->_lineno	= 1;
-	conf->_linesize	= 1024;
+	conf->ic_ignore	= 1;
+	conf->ic_lineno	= 1;
+	conf->ic_linesize	= 1024;
 
 	return ini_read(conf, fp);
 }
@@ -259,18 +259,18 @@
 {
 	while (ini_getline(conf, fp) == 0) {
 		if (ini_readline(conf) == NULL) {
-			free(conf->_line);
+			free(conf->ic_line);
 			ini_free(conf, 1, 1);
 
 			fclose(fp);
 			return NULL;
 		}
 
-		++ conf->_lineno;
+		++ conf->ic_lineno;
 	}
 
 	/* Clean up */
-	free(conf->_line);
+	free(conf->ic_line);
 	fclose(fp);
 
 	return conf;
@@ -287,7 +287,7 @@
 {
 	int ch, pos;
 
-	memset(conf->_line, 0, conf->_linesize);
+	memset(conf->ic_line, 0, conf->ic_linesize);
 	pos = 0;
 
 	while ((ch = fgetc(fp)) != '\n') {
@@ -295,18 +295,18 @@
 			return -1;
 
 		/* End of buffer, realloc */
-		if (pos == conf->_linesize) {
-			conf->_line = realloc(conf->_line, conf->_linesize + 513);
-			if (conf->_line == NULL)
+		if (pos == conf->ic_linesize) {
+			conf->ic_line = realloc(conf->ic_line, conf->ic_linesize + 513);
+			if (conf->ic_line == NULL)
 				return -1;
 
-			conf->_linesize += 512;
+			conf->ic_linesize += 512;
 		}
 
-		conf->_line[pos++] = ch;
+		conf->ic_line[pos++] = ch;
 	}
 
-	conf->_line[pos] = '\0';
+	conf->ic_line[pos] = '\0';
 
 	return 0;
 }
@@ -323,7 +323,7 @@
 	char *lp;
 	int (*handler)(INI_Config *, char **);
 
-	lp = conf->_line;
+	lp = conf->ic_line;
 	SKIP_SPACES(lp);
 
 	/* Ignore empty line or comment */
@@ -338,12 +338,12 @@
 			return conf;
 
 #ifdef INI_DEBUG
-		printf("-- line[%d] == [%s]\n", conf->_lineno, conf->_line);
+		printf("-- line[%d] == [%s]\n", conf->ic_lineno, conf->ic_line);
 #endif
 
 		if (*lp == '[')
 			handler = &ini_switch;
-		else if (!conf->_ignore)
+		else if (!conf->ic_ignore)
 			handler = &ini_register;
 		else {
 			handler = NULL;
@@ -378,44 +378,44 @@
 
 	/* Section not parsed, ignore next option to prevent breakage */
 	if ((endSection = strchr(*lp, ']')) == NULL) {
-		WARN(conf, "line %d: parse error\n", conf->_lineno);
+		WARN(conf, "line %d: parse error\n", conf->ic_lineno);
 		SEEK_NEXT(lp);
-		return (conf->_ignore = 1) - 2;		/* single line rocks */
+		return (conf->ic_ignore = 1) - 2;		/* single line rocks */
 	}
 
 	/* Redefinition of previous section and not allowed? */
 	++(*lp);
-	if (conf->_current != NULL
+	if (conf->ic_current != NULL
 	    && I_NOREDEFINE(conf)
-	    && strncmp(conf->_current->key, *lp, endSection - *lp) == 0)
+	    && strncmp(conf->ic_current->key, *lp, endSection - *lp) == 0)
 	{
-		WARN(conf, "line %d: redefining %s\n", conf->_lineno,
-		    conf->_current->key);
+		WARN(conf, "line %d: redefining %s\n", conf->ic_lineno,
+		    conf->ic_current->key);
 		SEEK_NEXT(lp);
-		return (conf->_ignore = 1) - 2;
+		return (conf->ic_ignore = 1) - 2;
 	}
 
-	if ((conf->_current = malloc(sizeof (INI_Section))) == NULL)
+	if ((conf->ic_current = malloc(sizeof (INI_Section))) == NULL)
 		return -1;
 
-	memset(conf->_current, 0, sizeof (INI_Section));
-	if ((conf->_current->key = xstrndup(*lp, endSection - *lp)) == NULL) {
-		free(conf->_current);
-		conf->_current = NULL;
+	memset(conf->ic_current, 0, sizeof (INI_Section));
+	if ((conf->ic_current->key = xstrndup(*lp, endSection - *lp)) == NULL) {
+		free(conf->ic_current);
+		conf->ic_current = NULL;
 		return -1;
 	}
 
 	*lp = endSection + 1;
 
 #ifdef INI_DEBUG
-	printf("-- current section is now [%s]\n", conf->_current->key);
+	printf("-- current section is now [%s]\n", conf->ic_current->key);
 #endif
 
 	/* Finally add the new section to the config */
-	conf->_current->next	= conf->sections;
-	conf->sections		= conf->_current;
+	conf->ic_current->next	= conf->sections;
+	conf->sections		= conf->ic_current;
 
-	return (conf->_ignore = 0);
+	return (conf->ic_ignore = 0);
 }
 
 /*
@@ -433,7 +433,7 @@
 
 	/* No '=' found */
 	if ((assignKey = strchr(*lp, '=')) == NULL) {
-		WARN(conf, "line %d: missing '='\n", conf->_lineno);
+		WARN(conf, "line %d: missing '='\n", conf->ic_lineno);
 		SEEK_NEXT(lp);
 		return -1;
 	}
@@ -445,7 +445,7 @@
 
 	/* Do not register empty option name */
 	if (endKey - *lp <= 0) {
-		WARN(conf, "line %d: 0-length option\n", conf->_lineno);
+		WARN(conf, "line %d: 0-length option\n", conf->ic_lineno);
 		SEEK_NEXT(lp);
 		return -1;
 	}
@@ -470,7 +470,7 @@
 		if (token != '\0' && *endValue == token)
 			++ endValue;
 		else
-			WARN(conf, "line %d: missing '%c'\n", conf->_lineno, token);
+			WARN(conf, "line %d: missing '%c'\n", conf->ic_lineno, token);
 	} else {
 		for (*lp = endValue; !isspace(*endValue) && *endValue != '\0' && 
 		    *endValue != '#' && *endValue != ';'; ++endValue)
@@ -491,8 +491,8 @@
 
 	/* Finally add the new option to the current section */
 	*lp = endValue;
-	option->next = conf->_current->options;
-	conf->_current->options	= option;
+	option->next = conf->ic_current->options;
+	conf->ic_current->options	= option;
 
 	return 0;
 }
@@ -503,8 +503,8 @@
 	va_list ap;
 
 	if (conf != NULL) {
-		if (conf->_line != NULL)
-			free(conf->_line);
+		if (conf->ic_line != NULL)
+			free(conf->ic_line);
 
 		ini_free(conf, 1, 1);
 	}
--- a/ini.h	Mon Mar 12 21:49:59 2012 +0100
+++ b/ini.h	Tue Mar 20 22:49:37 2012 +0100
@@ -19,6 +19,10 @@
 #ifndef _INI_H_
 #define _INI_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #define	INI_VERBOSE	(1 << 0)	/* be verbose */
 #define	INI_NOREDEFINE	(1 << 1)	/* do not allow redefinitions */
 #define INI_FAILERROR	(1 << 2)	/* abort parsing on first error */
@@ -35,40 +39,42 @@
  * -------------------------------------------------------- */
 
 struct ini_config {
-	/* General settings */
-	const char	*path;		/* file path */
-	int		flags;		/* optional flags */
+	/*
+	 * General settings
+	 */
+	const char	*path;		/* (ro) file path */
+	int		flags;		/* (ro) optional flags */
 
-	/* Sections that have been parsed */
-	INI_Section	*sections;	/* linked-list of sections */
+	/*
+	 * Sections that have been parsed
+	 */
+	INI_Section	*sections;	/* (ro) linked-list of sections */
 
 	/* Private fields */
-	INI_Section	*_current;	/* current working section */
-	char		*_line;		/* line buffer */
-	int		_lineno;	/* number of current line */
-	int		_linesize;	/* initial line size */
-	int		_ignore;	/* must ignore (no redefine) */
+	INI_Section	*ic_current;	/* current working section */
+	char		*ic_line;	/* line buffer */
+	int		ic_lineno;	/* number of current line */
+	int		ic_linesize;	/* initial line size */
+	int		ic_ignore;	/* must ignore (no redefine) */
 };
 
 struct ini_option {
-	char		*key;		/* option name */
-	char		*value;		/* option value */
-	INI_Option	*next;		/* next option */
+	char		*key;		/* (rw) option name */
+	char		*value;		/* (rw) option value */
+	INI_Option	*next;		/* (ro) next option */
 };
 
 struct ini_section {
-	char		*key;		/* section key */	
-	INI_Option	*options;	/* linked-list of options */
-	INI_Section	*next;		/* linked-list of sections */
+	char		*key;		/* (rw) section key */	
+	INI_Option	*options;	/* (ro) linked-list of options */
+	INI_Section	*next;		/* (ro) linked-list of sections */
 };
 
 struct ini_handler {
-	char		*key;		/* option to check */
-	void		*dst;		/* where to store */
-
-	/* Conversion function */
-	INI_ConvertFunc	handler;
-	void		*userdata;	/* optional user data */
+	char		*key;		/* (rw) option to check */
+	void		*dst;		/* (rw) where to store */
+	INI_ConvertFunc	handler;	/* (rw) conversion function */
+	void		*userdata;	/* (rw) optional user data */
 };
 
 /* --------------------------------------------------------
@@ -137,4 +143,8 @@
 void
 ini_convert_string(void *, const char *, void *);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _INI_H_ */
--- a/pack.h	Mon Mar 12 21:49:59 2012 +0100
+++ b/pack.h	Tue Mar 20 22:49:37 2012 +0100
@@ -21,6 +21,10 @@
 
 #include <stdarg.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /*
  * Endian detection based on SDL_endian.h
  */
@@ -62,4 +66,8 @@
 int	pack_fread(int, FILE *, const char *, ...);
 int	pack_vfread(int, FILE *, const char *, va_list);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif /* _PACK_H_ */
--- a/parray.h	Mon Mar 12 21:49:59 2012 +0100
+++ b/parray.h	Tue Mar 20 22:49:37 2012 +0100
@@ -19,12 +19,12 @@
 #ifndef _PARRAY_H_
 #define _PARRAY_H_
 
+#include <stdarg.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdarg.h>
-
 #ifndef PARRAY_DEFAULT_BSIZE
 #define PARRAY_DEFAULT_BSIZE	128
 #endif
@@ -35,11 +35,11 @@
 };
 
 struct parray {
-	int	type;		/* array type (default FIXED) */
-	void	**data;		/* array of data */
-	int	length;		/* number of element inside */
-	size_t	size;		/* current buffer size (allocated memory) */
-	int	bsize;		/* block size (used when growing array) */
+	int	type;		/* (ro) array type (default FIXED) */
+	void	**data;		/* (rw) array of data */
+	int	length;		/* (ro) number of element inside */
+	size_t	size;		/* (ro) current buffer size (allocated memory) */
+	int	bsize;		/* (rw) block size (used when growing array) */
 
 	/* Own allocation functions */
 	void * (*malloc)(size_t);