Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "libqhull.h"
00012 #include <string.h>
00013 #include <stdio.h>
00014 #include <stdlib.h>
00015
00016 #ifdef _MSC_VER
00017 #pragma warning( disable : 4706)
00018 #pragma warning( disable : 4996)
00019 #endif
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 int qh_argv_to_command(int argc, char *argv[], char* command, int max_size) {
00041 int i, remaining;
00042 char *s;
00043 *command= '\0';
00044
00045 if (argc) {
00046 if ((s= strrchr( argv[0], '\\'))
00047 || (s= strrchr( argv[0], '/')))
00048 s++;
00049 else
00050 s= argv[0];
00051 if ((int)strlen(s) < max_size)
00052 strcpy(command, s);
00053 else
00054 goto error_argv;
00055 if ((s= strstr(command, ".EXE"))
00056 || (s= strstr(command, ".exe")))
00057 *s= '\0';
00058 }
00059 for (i=1; i < argc; i++) {
00060 s= argv[i];
00061 remaining= max_size - (int)strlen(command) - (int)strlen(s) - 2;
00062 if (!*s || strchr(s, ' ')) {
00063 char *t= command + strlen(command);
00064 remaining -= 2;
00065 if (remaining < 0) {
00066 goto error_argv;
00067 }
00068 *t++= ' ';
00069 *t++= '"';
00070 while (*s) {
00071 if (*s == '"') {
00072 if (--remaining < 0)
00073 goto error_argv;
00074 *t++= '\\';
00075 }
00076 *t++= *s++;
00077 }
00078 *t++= '"';
00079 *t= '\0';
00080 }else if (remaining < 0) {
00081 goto error_argv;
00082 }else
00083 strcat(command, " ");
00084 strcat(command, s);
00085 }
00086 return 1;
00087
00088 error_argv:
00089 return 0;
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 int qh_argv_to_command_size(int argc, char *argv[]) {
00104 unsigned int count= 1;
00105 int i;
00106 char *s;
00107
00108 for (i=0; i<argc; i++){
00109 count += (int)strlen(argv[i]) + 1;
00110 if (i>0 && strchr(argv[i], ' ')) {
00111 count += 2;
00112 for (s=argv[i]; *s; s++) {
00113 if (*s == '"') {
00114 count++;
00115 }
00116 }
00117 }
00118 }
00119 return count;
00120 }
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 int qh_rand_seed= 1;
00142
00143 #define qh_rand_a 16807
00144 #define qh_rand_m 2147483647
00145 #define qh_rand_q 127773
00146 #define qh_rand_r 2836
00147
00148 int qh_rand( void) {
00149 int lo, hi, test;
00150 int seed = qh_rand_seed;
00151
00152 hi = seed / qh_rand_q;
00153 lo = seed % qh_rand_q;
00154 test = qh_rand_a * lo - qh_rand_r * hi;
00155 if (test > 0)
00156 seed= test;
00157 else
00158 seed= test + qh_rand_m;
00159 qh_rand_seed= seed;
00160
00161
00162 return seed;
00163 }
00164
00165 void qh_srand( int seed) {
00166 if (seed < 1)
00167 qh_rand_seed= 1;
00168 else if (seed >= qh_rand_m)
00169 qh_rand_seed= qh_rand_m - 1;
00170 else
00171 qh_rand_seed= seed;
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 realT qh_randomfactor(realT scale, realT offset) {
00184 realT randr;
00185
00186 randr= qh_RANDOMint;
00187 return randr * scale + offset;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202 void qh_randommatrix(realT *buffer, int dim, realT **rows) {
00203 int i, k;
00204 realT **rowi, *coord, realr;
00205
00206 coord= buffer;
00207 rowi= rows;
00208 for (i=0; i < dim; i++) {
00209 *(rowi++)= coord;
00210 for (k=0; k < dim; k++) {
00211 realr= qh_RANDOMint;
00212 *(coord++)= 2.0 * realr/(qh_RANDOMmax+1) - 1.0;
00213 }
00214 }
00215 *rowi= coord;
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 double qh_strtod(const char *s, char **endp) {
00228 double result;
00229
00230 result= strtod(s, endp);
00231 if (s < (*endp) && (*endp)[-1] == ' ')
00232 (*endp)--;
00233 return result;
00234 }
00235
00236 int qh_strtol(const char *s, char **endp) {
00237 int result;
00238
00239 result= (int) strtol(s, endp, 10);
00240 if (s< (*endp) && (*endp)[-1] == ' ')
00241 (*endp)--;
00242 return result;
00243 }