CARS

/home/nicola/Dropbox/Progetto SOL/CARS_terfram/src/commons.h

Go to the documentation of this file.
00001 
00008 /*    Copyright (C) 2011  Nicola Corti
00009 
00010     This program is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     This program is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU General Public License for more details.
00019 
00020     You should have received a copy of the GNU General Public License
00021     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00022 
00023                  For further information, Nicola Corti - <cortin [at] cli.di.unipi.it>
00024 */
00025 #include "settings.h"
00026 
00027 #include <stdlib.h>
00028 #include <stdio.h>
00029 
00030 #ifndef __COMMONS_H
00031 #define __COMMONS_H
00032 
00033 /* Macro per la gestione degli errori... */
00034 
00041 #define ec_neg1(s,m) \
00042         if ( (s) == -1 ) {perror(m); exit(errno);}
00043 
00050 #define ec_null(s,m) \
00051         if ( (s) == NULL ) {perror(m); exit(errno);}
00052 
00059 #define ec_neg1_c(s,m,c) \
00060         if ( (s) == -1 ) {perror(m); c}
00061 
00068 #define ec_null_c(s,m,c) \
00069         if ( (s) == NULL ) {perror(m); c}
00070 
00077 #define ec_zero(s, m) \
00078         if ( (s) != 0) {perror(m); exit(errno);}
00079 
00086 #define ec_zero_c(s, m, c) \
00087         if ( (s) != 0) {perror(m); c}
00088 
00094 #define print(s) \
00095         {printf(s); fflush(stdout);}
00096 
00103 #define print_1(s, p) \
00104         {printf(s, p); fflush(stdout);}
00105 
00112 #define print_2(s, p, b) \
00113         {printf(s, p, b); fflush(stdout);}
00114 
00120 #define err_print(s) \
00121         {fprintf(stderr, s);}
00122 
00129 #define err_print_1(s, p) \
00130         {fprintf(stderr, s, p);}
00131 
00140 #define sys_print(s) \
00141         {printf(s); fflush(stdout);}
00142 
00152 #define sys_print_1(s, p) \
00153         {printf(s, p); fflush(stdout);}
00154 
00162 #ifndef VERBOSE
00163         #undef sys_print
00164         #define sys_print(s)
00165         #undef sys_print_1
00166         #define sys_print_1(s, p)
00167 #endif
00168 
00169 #endif