| MLib Reference Manual | ||||
|---|---|---|---|---|
| Top | Description | ||||
#include <mlib.h> struct MErrorFuncFlag; struct MErrorString; #define MERRORSTRINGINIT #define MErrorString_new (name) struct MErrorStrings; #define MERRORSTRINGSINIT #define MErrorStrings_new (name) #define m_xerror_if (expr, m_error_str) #define m_xerror_func_if (expr, m_error_str) MErrorStrings * m_xerror_init (mconstchars directory); MStatus m_xerror (mconstchars expr,mconstchars function,MErrorStrings *m_error_str);
MLib definisce degli strumenti utilizzati per la stampa su stdoutput di messaggi di errore associati a condizioni di 'if' utilizzando file in formato xml.
ATTENZIONE: le macros e le funzioni della famiglia m_xerror utilizzanti file in formato xml non hanno nulla in comune con le macros e le funzioni della libreria GLib utilizzanti strutture del tipo GError!!!
XML Error Reporting include:
Only UTF-8 encoding is allowed.
No user-defined entities.
XML Error Reporting format does support:
Only this elements: <MErrorStrings>,<MErrorString>,<function>,<expr>,<string>
Attributes
5 standard entities: & < > " '
livelli di errore:
0 = livello basso, messaggio di errore;
1 = livello medio, messaggio di errore;
2 = livello alto, messaggio di errore, uscita forzata dal programma;
<!-- & (&)
< (<)
> (>)
' (')
" (") -->
<!-- info_errors -->
<?xml version="1.0" encoding="UTF-8"?>
<MErrorStrings lib_version="0.0.0" lang="ENGLISH" context='public'>
<!-- Test -->
<MErrorString version="0.0.1" level='1'>
<function>func</function>
<expr>( a == b )</expr>
<string> Error medium ... </string>
</MErrorString>
<MErrorString version="0.0.1" level='2'>
<function>func</function>
<expr>( a > b )</expr>
<string> Error hight ... </string>
</MErrorString>
<MErrorString version="0.0.1" level='0'>
<function>main</function>
<expr>( check ( 3, 2 ) != MCORRECT )</expr>
<string> Error low ... </string>
</MErrorString>
</MErrorStrings>
Example 10. Using a A XML system.
#include <mlib.h>
#include <glib/gprintf.h>
MStatus
check ( muint a, muint b )
{
if ( a < b ) { return MCORRECT; }
return MERROR;
}
void
func ( MErrorStrings* error_str,
muint a,
muint b )
{
m_xerror_if ( ( a == b ), error_str )
{
g_printf ( "\n Error B !!!!!!! \n" );
return;
}
m_xerror_if ( ( a > b ), error_str )
{
// questo codice non verrà eseguito perchè m_xerror forzerà l'uscita prima
g_printf ( "\n Error C !!!!!!! \n" );
return;
}
else
{
g_printf ( "\n\n a: %u, b: %u \n\n", a, b );
}
return;
}
int
m_main ( argc, argv )
{
m_main_init ( argc, argv );
MErrorStrings* error_str = m_xerror_init ( "./info_errors.xml" );
m_return_val_if_fail ( (error_str != NULL), MERROR );
m_xerror_func_if ( ( check ( 3, 2 ) != MCORRECT ), error_str )
{
g_printf ( "\n Error A !!!!!!! \n" );
}
func ( error_str, 1, 2 ); // no error
func ( error_str, 2, 2 ); // error
func ( error_str, 3, 2 ); // error and exit
g_printf ( "\n Hello World ... ? \n" ); // questo codice non verrà eseguito perchè m_xerror forzerà l'uscita prima
return MCORRECT;
}
struct MErrorFuncFlag {
ndsDefine define;
volatile mboolean dat;
};
Flag riservato del sistema di gestione errori.
struct MErrorString {
/*< attribute >*/
GString* version;
mchars level;
/*< element >*/
mchars function;
mchars expr;
mchars string;
};
La struttura MErrorString contiene informazioni riguardo
la visualizzazione di un messaggio di errore nel caso
una espressione expr verificata risultasse vera all'interno
di una funzione function .
see also: m_xerror(), m_xerror_if , m_xerror_func_if
#define MErrorString_new(name) MErrorString name = MERRORSTRINGINIT
Declare and define a new MErrorString structure.
|
name of a new MErrorString structure |
struct MErrorStrings {
/*< attribute >*/
GString* lib_version;
mchars lang;
mchars context;
/*< element >*/
GArray* m_error_string;
};
La struttura MErrorStrings contiene informazioni riguardo la stampa di errori in relazione alla verifica di una espressione.
see also: m_xerror(), m_xerror_if , m_xerror_func_if
GString * |
versione della libreria utilizzata |
mchars |
lingua utilizzata nei messaggi di errore |
mchars |
contesto, 'private' se riservato alla mlib, 'public' se utilizzato dall'utente finale |
GArray * |
array di strutture MErrorString |
#define MErrorStrings_new(name) MErrorStrings name = MERRORSTRINGSINIT
Declare and define a new MErrorStrings structure.
|
name of a new MErrorStrings structure |
#define m_xerror_if(expr,m_error_str)
stability: Unstable
Verifica una espressione expr, nel caso sia TRUE provvede
a richiamare la funzione m_xerror().
Questa macro è da utilizzare con espressioni non utilizzanti funzioni.
Example 11. Using a m_xerror_if.
m_xerror_if ( (1 _greater_ 2), error_str ) // espressione sempre racchiusa tra parentesi tonde
{
g_printf ( "1 > 2" ); // codice nel caso l'espressione sia vera
} // ( visualizza messaggio di errore )
else
{
g_printf ( "1 < 2" ); // codice nel caso l'espressione sia falsa
} // ( nessun messaggio di errore )
_greater_ è una macro definita in <mlib/mcharacterspellings.h> e viene espansa nel carattere ' > '.
Guarda anche: Character Spellings
|
una espressione |
|
indirizzo ad una struttura MErrorStrings |
#define m_xerror_func_if(expr,m_error_str)
stability: Unstable
Verifica una espressione expr, nel caso sia TRUE provvede
a richiamare la funzione m_xerror().
Questa macro è da utilizzare con espressioni utilizzanti funzioni.
Example 12. Using a m_xerror_func_if.
m_xerror_func_if ( ( !m_strcmp0 ( setlocale (LC_ALL, NULL), "en_US.utf8" ) ), error_str )
{
g_printf ( "It's: en_US.utf8" );
}
else
{
g_printf ( "It isn't: en_US.utf8 \n" );
g_printf ( "It's: %s;", setlocale (LC_ALL, NULL) );
}
|
una espressione |
|
indirizzo ad una struttura MErrorStrings |
MErrorStrings * m_xerror_init (mconstchars directory);
stability: Unstable
Inizializza il sistema di gestione degli errori. E' utilizzata dall'utente finale che passando una directory valida dove e' posto un file.xml riceve un puntatore a MErrorStrings utilizzato per la visualizzazione degli errori personali.
|
indirizzo di un file.xml |
Returns : |
un nuovo MErrorStrings oppure NULL in caso di errore.
|
Since 0.0.1
MStatus m_xerror (mconstchars expr,mconstchars function,MErrorStrings *m_error_str);
stability: Unstable
Verifica una espressione e nel caso risulti vera, ricerca
tra le informazioni della struttura m_error_str la presenza
o meno di un messaggio di errore visualizzabile.
Provoca nel caso in cui il livello di errore lo preveda, l'uscita forzata dal processo.
|
espressione da verificare |
|
funzione chiamante |
|
contiene le informazioni relative agli errori |
Returns : |
MCORRECT in caso di corretta esecuzione
MERROR in caso di errore
|
Since 0.0.1