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

View File

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

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -20,7 +20,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/array.h"
/* Array */ /* Array */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -20,7 +20,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/buffer.h"
/* Buffer */ /* Buffer */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,8 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/error.h"
#include "System/config.h"
/* Config */ /* Config */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -17,44 +17,30 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include "System/error.h"
#include "System.h"
/* Error */
/* private */ /* private */
/* error_do */ /* prototypes */
static char const * _error_do(int * codeptr, char const * format, va_list args) static String const * _error_do(int * codeptr, String 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;
}
/* public */ /* public */
/* accessors */ /* accessors */
/* error_get */ /* 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 */ /* XXX workaround for portability */
return _get_do(NULL); 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_list args;
va_start(args, null); va_start(args, null);
@ -65,17 +51,17 @@ static char const * _get_do(char const * null, ...)
/* error_get_code */ /* 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 */ /* XXX workaround for portability */
return _get_code_do(code); 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_list args;
va_start(args, code); va_start(args, code);
@ -86,7 +72,7 @@ static char const * _get_code_do(int * code, ...)
/* error_set */ /* error_set */
void error_set(char const * format, ...) void error_set(String const * format, ...)
{ {
va_list args; va_list args;
@ -97,7 +83,7 @@ void error_set(char const * format, ...)
/* error_set_code */ /* error_set_code */
int error_set_code(int code, char const * format, ...) int error_set_code(int code, String const * format, ...)
{ {
va_list args; va_list args;
@ -109,7 +95,7 @@ int error_set_code(int code, char const * format, ...)
/* error_set_print */ /* 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; va_list args;
@ -122,15 +108,15 @@ int error_set_print(char const * program, int code, char const * format, ...)
/* useful */ /* useful */
/* error_print */ /* 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 */ /* XXX workaround for portability */
return _print_do(program); return _print_do(program);
} }
static int _print_do(char const * program, ...) static int _print_do(String const * program, ...)
{ {
int ret = 0; int ret = 0;
va_list args; va_list args;
@ -146,3 +132,25 @@ static int _print_do(char const * program, ...)
va_end(args); va_end(args);
return ret; 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> # include <stdio.h>
#endif #endif
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/array.h"
#include "System/error.h"
#include "System/object.h"
#include "System/event.h"
/* macros */ /* macros */
#ifndef max #ifndef max

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -17,7 +17,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/hash.h"
/* HashEntry */ /* HashEntry */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -21,7 +21,7 @@
#endif #endif
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/object.h"
/* Object */ /* Object */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,9 @@
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/parser.h"
#include "token.h" #include "token.h"

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -24,7 +24,8 @@
#else #else
# include <dlfcn.h> # include <dlfcn.h>
#endif #endif
#include "System.h" #include "System/error.h"
#include "System/plugin.h"
/* Plugin */ /* Plugin */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -22,7 +22,9 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/string.h"
/* String */ /* String */

View File

@ -1,5 +1,5 @@
/* $Id$ */ /* $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 file is part of DeforaOS System libSystem */
/* This program is free software: you can redistribute it and/or modify /* 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 * it under the terms of the GNU Lesser General Public License as published by
@ -21,7 +21,10 @@
#ifdef DEBUG #ifdef DEBUG
# include <stdio.h> # include <stdio.h>
#endif #endif
#include "System.h" #include "System/error.h"
#include "System/object.h"
#include "System/string.h"
#include "System/token.h"
#include "token.h" #include "token.h"

View File

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

View File

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