1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /*
- * Copyright (C) 2020, 2019, 2018, 2017 Girish M
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- */
- #ifndef COMMON_H
- #define COMMON_H
- #include <assert.h>
- #include <ctype.h>
- #include <errno.h>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #define UNDEF -1
- #define BUF_LEN 256
- #define INFTY 1000000
- #define EPS 0.0001
- #ifndef MAX
- #define MAX(a,b) (((a)>(b))?(a):(b))
- #define MIN(a,b) (((a)<(b))?(a):(b))
- #endif
- #ifndef SQR
- #define SQR(x) ((x) * (x))
- #endif
- #define ERR_MESG(x) { perror(x); return -1; }
- #if DEBUG
- //#ifdef __GNUC__
- #define dprintf(format, ...) fprintf(stderr, format, ## __VA_ARGS__)
- #else
- #define dprintf(format, ...)
- #endif
- #define Malloc(n,type) (type *) malloc( (unsigned) ((n)*sizeof(type)))
- #define Realloc(loc,n,type) (type *) realloc( (char *)(loc), \
- (unsigned) ((n)*sizeof(type)))
- #define matrix_alloc(mat,rows,cols,type) { \
- int ii; \
- type *temp; \
- \
- if (NULL == (temp = (type *) malloc(rows*cols*sizeof(type))) || \
- NULL == (mat = (type **) malloc(rows * sizeof(type *)))) \
- ERR_MESG("Out of memory"); \
- for (ii = 0; ii < rows; temp += cols, ii++) \
- mat[ii] = temp; \
- }
- #define matrix_free(mat) { \
- free(mat[0]); \
- free(mat); \
- }
- #endif
|