Code cleanup

This commit is contained in:
Pierre Pronchery 2013-06-22 17:07:16 -04:00
parent f8d103c891
commit a68f068423
15 changed files with 106 additions and 73 deletions

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2006-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2006-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -19,15 +19,16 @@
# define LIBSYSTEM_CONFIG_H
# include "hash.h"
# include "string.h"
/* Config */
/* types */
typedef Hash Config;
typedef void (*ConfigForeachCallback)(char const * section, void * priv);
typedef void (*ConfigForeachSectionCallback)(char const * variable,
char const * value, void * priv);
typedef void (*ConfigForeachCallback)(String const * section, void * priv);
typedef void (*ConfigForeachSectionCallback)(String const * variable,
String const * value, void * priv);
/* functions */
@ -35,19 +36,19 @@ Config * config_new(void);
void config_delete(Config * config);
/* accessors */
char const * config_get(Config * config, char const * section,
char const * variable);
int config_set(Config * config, char const * section, char const * variable,
char const * value);
String const * config_get(Config * config, String const * section,
String const * variable);
int config_set(Config * config, String const * section, String const * variable,
String const * value);
/* useful */
void config_foreach(Config * config, ConfigForeachCallback callback,
void * priv);
void config_foreach_section(Config * config, char const * section,
void config_foreach_section(Config * config, String const * section,
ConfigForeachSectionCallback callback, void * priv);
int config_load(Config * config, char const * filename);
int config_load(Config * config, String const * filename);
int config_reset(Config * config);
int config_save(Config * config, char const * filename);
int config_save(Config * config, String const * filename);
#endif /* !LIBSYSTEM_CONFIG_H */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2007-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2007-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -18,17 +18,20 @@
#ifndef LIBSYSTEM_ERROR_H
# define LIBSYSTEM_ERROR_H
# include "string.h"
/* functions */
/* accessors */
char const * error_get(void);
char const * error_get_code(int * code);
String const * error_get(void);
String const * error_get_code(int * code);
void error_set(char const * format, ...);
int error_set_code(int code, char const * format, ...);
int error_set_print(char const * program, int code, char const * format, ...);
void error_set(String const * format, ...);
int error_set_code(int code, String const * format, ...);
int error_set_print(String const * program, int code,
String const * format, ...);
/* useful */
int error_print(char const * program);
int error_print(String const * program);
#endif /* !LIBSYSTEM_ERROR_H */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2005-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2005-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -20,7 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/array.h"
/* Array */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2006-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2006-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -20,7 +20,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/buffer.h"
/* Buffer */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2005-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2005-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,8 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "System.h"
#include "System/error.h"
#include "System/config.h"
/* Config */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2007-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2007-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -17,44 +17,30 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "System.h"
#include "System/error.h"
/* Error */
/* private */
/* error_do */
static char const * _error_do(int * codeptr, char const * format, va_list args)
{
static char buf[256] = "";
static int code = 0;
if(format != NULL) /* setting the error */
{
vsnprintf(buf, sizeof(buf), format, args);
if(codeptr != NULL)
code = *codeptr;
return buf;
}
if(codeptr != NULL)
*codeptr = code;
return buf;
}
/* prototypes */
static String const * _error_do(int * codeptr, String const * format,
va_list args);
/* public */
/* accessors */
/* error_get */
static char const * _get_do(char const * null, ...);
static String const * _get_do(String const * null, ...);
char const * error_get(void)
String const * error_get(void)
{
/* XXX workaround for portability */
return _get_do(NULL);
}
static char const * _get_do(char const * null, ...)
static String const * _get_do(String const * null, ...)
{
char const * ret;
String const * ret;
va_list args;
va_start(args, null);
@ -65,17 +51,17 @@ static char const * _get_do(char const * null, ...)
/* error_get_code */
static char const * _get_code_do(int * code, ...);
static String const * _get_code_do(int * code, ...);
char const * error_get_code(int * code)
String const * error_get_code(int * code)
{
/* XXX workaround for portability */
return _get_code_do(code);
}
static char const * _get_code_do(int * code, ...)
static String const * _get_code_do(int * code, ...)
{
char const * ret;
String const * ret;
va_list args;
va_start(args, code);
@ -86,7 +72,7 @@ static char const * _get_code_do(int * code, ...)
/* error_set */
void error_set(char const * format, ...)
void error_set(String const * format, ...)
{
va_list args;
@ -97,7 +83,7 @@ void error_set(char const * format, ...)
/* error_set_code */
int error_set_code(int code, char const * format, ...)
int error_set_code(int code, String const * format, ...)
{
va_list args;
@ -109,7 +95,7 @@ int error_set_code(int code, char const * format, ...)
/* error_set_print */
int error_set_print(char const * program, int code, char const * format, ...)
int error_set_print(String const * program, int code, String const * format, ...)
{
va_list args;
@ -122,15 +108,15 @@ int error_set_print(char const * program, int code, char const * format, ...)
/* useful */
/* error_print */
static int _print_do(char const * program, ...);
static int _print_do(String const * program, ...);
int error_print(char const * program)
int error_print(String const * program)
{
/* XXX workaround for portability */
return _print_do(program);
}
static int _print_do(char const * program, ...)
static int _print_do(String const * program, ...)
{
int ret = 0;
va_list args;
@ -146,3 +132,25 @@ static int _print_do(char const * program, ...)
va_end(args);
return ret;
}
/* private */
/* functions */
/* error_do */
static String const * _error_do(int * codeptr, String const * format,
va_list args)
{
static String buf[256] = "";
static int code = 0;
if(format != NULL) /* setting the error */
{
vsnprintf(buf, sizeof(buf), format, args);
if(codeptr != NULL)
code = *codeptr;
return buf;
}
if(codeptr != NULL)
*codeptr = code;
return buf;
}

View File

@ -32,7 +32,10 @@ typedef int suseconds_t; /* XXX */
# include <stdio.h>
#endif
#include <errno.h>
#include "System.h"
#include "System/array.h"
#include "System/error.h"
#include "System/object.h"
#include "System/event.h"
/* macros */
#ifndef max

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2005-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2005-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -17,7 +17,9 @@
#include <stdlib.h>
#include <string.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/hash.h"
/* HashEntry */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2008-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2008-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -21,7 +21,7 @@
#endif
#include <string.h>
#include <errno.h>
#include "System.h"
#include "System/object.h"
/* Object */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2008-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2008-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,9 @@
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/parser.h"
#include "token.h"

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2008-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2008-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -24,7 +24,8 @@
#else
# include <dlfcn.h>
#endif
#include "System.h"
#include "System/error.h"
#include "System/plugin.h"
/* Plugin */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2005-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2005-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,9 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/string.h"
/* String */

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2008-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2008-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -21,7 +21,10 @@
#ifdef DEBUG
# include <stdio.h>
#endif
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/string.h"
#include "System/token.h"
#include "token.h"

View File

@ -1,5 +1,5 @@
/* $Id$ */
/* Copyright (c) 2010-2012 Pierre Pronchery <khorben@defora.org> */
/* Copyright (c) 2010-2013 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@ -21,6 +21,7 @@
/* Token */
/* functions */
/* protected */
Token * token_new(char const * filename, unsigned int line, unsigned int col);
#endif /* !_LIBSYSTEM_TOKEN_H */

View File

@ -20,7 +20,9 @@
#include <string.h>
#include <errno.h>
#include <arpa/inet.h>
#include "System.h"
#include "System/error.h"
#include "System/object.h"
#include "System/variable.h"
/* Variable */