util.h

Go to the documentation of this file.
00001 #ifndef _UTIL_H_
00002 
00003 #define _UTIL_H_
00004 
00005 #include <stdio.h> 
00006 #include <sys/time.h>
00007 
00008 /**
00009  * \file util.h Algumas funções, macros e constantes utilizadas no programa.
00010  */
00011 
00012 /// Verdadeiro
00013 #define TRUE 1
00014 /// Falso
00015 #define FALSE 0
00016 
00017 /// Numero de Euler
00018 #define E 2.718281828459045
00019 /// Pi
00020 #define PI 3.141592653589793
00021 
00022 /// Não é utilizado
00023 #define REALLOC_SIZE 10
00024 
00025 /* Codigos de erro */
00026 #define OK            0         /* Sem erro                       */
00027 #define E_NONE        0         /* Sem erro                       */
00028 #define E_NOMEM     (-1)        /* Memória insuficiente           */
00029 #define E_FOPEN     (-2)        /* Não consegue abrir arquivo     */
00030 #define E_FREAD     (-3)        /* Erro na leitura do arquivo     */
00031 #define E_FWRITE    (-4)        /* Erro na escrita do arquivo     */
00032 #define E_OPTION    (-5)        /* Opcao desconhecida             */
00033 #define E_OPTARG    (-6)        /* Opcao de argumento invalida    */
00034 #define E_FRINEXIST (-7)        /* Arquivo de entrada inexistente */
00035 #define E_UNKNOWN   (-8)        /* Erro desconhecido              */
00036 #define E_NOTFOUND  (-9)        /* Elemento nao encontrado        */
00037 #define E_PARSEFAIL (-10)       /* Problems parsing input file    */
00038 
00039 /// Retorna a diferença de tempo entre 2 structs timeval.
00040 #define ELAPSE(e,n,s) { e.tv_sec+=n.tv_sec-s.tv_sec; e.tv_usec+=n.tv_usec-s.tv_usec; if(e.tv_usec<0){ e.tv_sec--; e.tv_usec+=1000000; } if(e.tv_usec>1000000){ e.tv_sec+=e.tv_usec/1000000; e.tv_usec=e.tv_usec%1000000; }}
00041 
00042 /// Retorna o maior entre 2 valores
00043 #define max(a, b) ((a) > (b) ? (a) : (b))
00044 /// Retorna o menor entre 2 valores
00045 #define min(a, b) ((a) < (b) ? (a) : (b))
00046 
00047 /// Converte uma struct timeval (retornada por getrusage() e gettimeofday() ) 
00048 /// em um double.
00049 #define time2double(x) ( (double)(x).tv_sec+0.000001*(double)(x).tv_usec )
00050 
00051 /*typedef void _DESTROY(void *value);
00052 typedef int _HASH_CODE(void *value);
00053 typedef int _COMPARE(const void *value1, const void *value2);
00054 typedef void* _CLONE(const void *value);*/
00055 
00056 void error (int, ...);
00057 
00058 char *read_line(FILE*);
00059 
00060 char *elapsed_time(struct timeval, struct timeval);
00061 
00062 #endif

Generated on Tue Jan 17 19:18:39 2006 for Void by  doxygen 1.4.6