| 1 | /* $Id$Revision: */ | 
|---|
| 2 | /* vim:set shiftwidth=4 ts=8: */ | 
|---|
| 3 |  | 
|---|
| 4 | /************************************************************************* | 
|---|
| 5 | * Copyright (c) 2011 AT&T Intellectual Property | 
|---|
| 6 | * All rights reserved. This program and the accompanying materials | 
|---|
| 7 | * are made available under the terms of the Eclipse Public License v1.0 | 
|---|
| 8 | * which accompanies this distribution, and is available at | 
|---|
| 9 | * http://www.eclipse.org/legal/epl-v10.html | 
|---|
| 10 | * | 
|---|
| 11 | * Contributors: See CVS logs. Details at http://www.graphviz.org/ | 
|---|
| 12 | *************************************************************************/ | 
|---|
| 13 |  | 
|---|
| 14 | #ifndef GENERAL_H | 
|---|
| 15 | #define GENERAL_H | 
|---|
| 16 |  | 
|---|
| 17 | #include <stdlib.h> | 
|---|
| 18 | #include <stdio.h> | 
|---|
| 19 | #include <math.h> | 
|---|
| 20 | #include <string.h> | 
|---|
| 21 | #include <assert.h> | 
|---|
| 22 | /* Applications that do not use the common library can define STANDALONE | 
|---|
| 23 | * to get definitions/definitions that are normally provided there. | 
|---|
| 24 | * In particular, note that Verbose is declared but undefined. | 
|---|
| 25 | */ | 
|---|
| 26 | #ifndef STANDALONE | 
|---|
| 27 | #include "cgraph.h" | 
|---|
| 28 | #include "globals.h" | 
|---|
| 29 | #include "logic.h" | 
|---|
| 30 | #include "arith.h" | 
|---|
| 31 | #include "memory.h" | 
|---|
| 32 | #endif  /* STANDALONE */ | 
|---|
| 33 |  | 
|---|
| 34 | #define real double | 
|---|
| 35 |  | 
|---|
| 36 | #define set_flag(a, flag) ((a)=((a)|(flag))) | 
|---|
| 37 | #define test_flag(a, flag) ((a)&(flag)) | 
|---|
| 38 | #define clear_flag(a, flag) ((a) &=(~(flag))) | 
|---|
| 39 |  | 
|---|
| 40 | #ifdef STANDALONE | 
|---|
| 41 | #define MALLOC malloc | 
|---|
| 42 | #define REALLOC realloc | 
|---|
| 43 |  | 
|---|
| 44 | #define N_NEW(n,t)   (t*)malloc((n)*sizeof(t)) | 
|---|
| 45 | #define NEW(t)       (t*)malloc(sizeof(t)) | 
|---|
| 46 | #define MAX(a,b) ((a)>(b)?(a):b) | 
|---|
| 47 | #define MIN(a,b) ((a)<(b)?(a):b) | 
|---|
| 48 | #define ABS(a) (((a)>0)?(a):(-(a))) | 
|---|
| 49 |  | 
|---|
| 50 | #ifdef TRUE | 
|---|
| 51 | #undef TRUE | 
|---|
| 52 | #endif | 
|---|
| 53 | #define TRUE 1 | 
|---|
| 54 |  | 
|---|
| 55 | #ifdef FALSE | 
|---|
| 56 | #undef FALSE | 
|---|
| 57 | #endif | 
|---|
| 58 | #define FALSE 0 | 
|---|
| 59 |  | 
|---|
| 60 | #define MAXINT 1<<30 | 
|---|
| 61 | #define PI 3.14159 | 
|---|
| 62 |  | 
|---|
| 63 | #define POINTS(inch) 72*(inch) | 
|---|
| 64 |  | 
|---|
| 65 | typedef unsigned int boolean; | 
|---|
| 66 | extern unsigned char Verbose; | 
|---|
| 67 |  | 
|---|
| 68 | #else  /* STANDALONE */ | 
|---|
| 69 | #define MALLOC gmalloc | 
|---|
| 70 | #define REALLOC grealloc | 
|---|
| 71 | #endif    /* STANDALONE */ | 
|---|
| 72 |  | 
|---|
| 73 | #define FREE free | 
|---|
| 74 | #define MEMCPY memcpy | 
|---|
| 75 |  | 
|---|
| 76 | #ifndef DEBUG | 
|---|
| 77 | #ifndef NDEBUG | 
|---|
| 78 | #define NDEBUG /* switch off assert*/ | 
|---|
| 79 | #endif | 
|---|
| 80 | #endif | 
|---|
| 81 |  | 
|---|
| 82 | #ifdef DEBUG | 
|---|
| 83 | extern double _statistics[10]; | 
|---|
| 84 | #endif | 
|---|
| 85 |  | 
|---|
| 86 |  | 
|---|
| 87 | extern int irand(int n); | 
|---|
| 88 | extern real drand(void); | 
|---|
| 89 | extern int *random_permutation(int n);/* random permutation of 0 to n-1 */ | 
|---|
| 90 |  | 
|---|
| 91 |  | 
|---|
| 92 | real* vector_subtract_to(int n, real *x, real *y);/* y = x-y */ | 
|---|
| 93 | real* vector_subtract_from(int n, real *x, real *y);/* y = y-x */ | 
|---|
| 94 | real* vector_add_to(int n, real *x, real *y); | 
|---|
| 95 |  | 
|---|
| 96 | real vector_product(int n, real *x, real *y); | 
|---|
| 97 |  | 
|---|
| 98 | real* vector_saxpy(int n, real *x, real *y, real beta); /* y = x+beta*y */ | 
|---|
| 99 |  | 
|---|
| 100 |  | 
|---|
| 101 | real* vector_saxpy2(int n, real *x, real *y, real beta);/* x = x+beta*y */ | 
|---|
| 102 |  | 
|---|
| 103 | /* take m elements v[p[i]]],i=1,...,m and oput in u. u will be assigned if *u = NULL */ | 
|---|
| 104 | void vector_take(int n, real *v, int m, int *p, real **u); | 
|---|
| 105 | void vector_float_take(int n, float *v, int m, int *p, float **u); | 
|---|
| 106 |  | 
|---|
| 107 | /* give the position of the lagest, second largest etc in vector v if ascending = TRUE | 
|---|
| 108 | or | 
|---|
| 109 | give the position of the smallest, second smallest etc  in vector v if ascending = TRUE. | 
|---|
| 110 | results in p. If *p == NULL, p is assigned. | 
|---|
| 111 | */ | 
|---|
| 112 | void vector_ordering(int n, real *v, int **p, int ascending); | 
|---|
| 113 | void vector_sort_real(int n, real *v, int ascending); | 
|---|
| 114 | void vector_sort_int(int n, int *v, int ascending); | 
|---|
| 115 | real vector_median(int n, real *x); | 
|---|
| 116 | real vector_percentile(int n, real *x, real y);/* find the value such that y% of element of vector x is <= that value.*/ | 
|---|
| 117 |  | 
|---|
| 118 | void vector_print(char *s, int n, real *x); | 
|---|
| 119 |  | 
|---|
| 120 | #define MACHINEACC 1.0e-16 | 
|---|
| 121 | #define SQRT_MACHINEACC 1.0e-8 | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | int excute_system_command3(char *s1, char *s2, char *s3); | 
|---|
| 125 | int excute_system_command(char *s1, char *s2); | 
|---|
| 126 |  | 
|---|
| 127 | #define MINDIST 1.e-15 | 
|---|
| 128 |  | 
|---|
| 129 | enum {UNMATCHED = -1}; | 
|---|
| 130 |  | 
|---|
| 131 |  | 
|---|
| 132 | real distance(real *x, int dim, int i, int j); | 
|---|
| 133 | real distance_cropped(real *x, int dim, int i, int j); | 
|---|
| 134 |  | 
|---|
| 135 | real point_distance(real *p1, real *p2, int dim); | 
|---|
| 136 |  | 
|---|
| 137 | char *strip_dir(char *s); | 
|---|
| 138 |  | 
|---|
| 139 | void scale_to_box(real xmin, real ymin, real xmax, real ymax, int n, int dim, real *x); | 
|---|
| 140 |  | 
|---|
| 141 | /* check to see if this is a string is integer (that can be casted into an integer variable hence very long list of digits are not valid, like 123456789012345. Return 1 if true, 0 if false. */ | 
|---|
| 142 | int validQ_int_string(char *to_convert, int *v); | 
|---|
| 143 |  | 
|---|
| 144 | /* check to see if this is a string of digits consists of 0-9 */ | 
|---|
| 145 | int digitsQ(char *to_convert); | 
|---|
| 146 |  | 
|---|
| 147 | #endif | 
|---|
| 148 |  | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|
| 151 |  | 
|---|