1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors: |
34 | * Gradient Systems |
35 | */ |
36 | |
37 | #include "config.h" |
38 | #include "porting.h" |
39 | #include <stdio.h> |
40 | #include <time.h> |
41 | #include <errno.h> |
42 | #include <ctype.h> |
43 | #include <math.h> |
44 | #ifndef USE_STDLIB_H |
45 | #include <malloc.h> |
46 | #endif |
47 | #include <fcntl.h> |
48 | #ifdef AIX |
49 | #include <sys/mode.h> |
50 | #endif /* AIX */ |
51 | #include <sys/types.h> |
52 | #include <sys/stat.h> |
53 | #include "date.h" |
54 | #include "decimal.h" |
55 | #include "dist.h" |
56 | #include "misc.h" |
57 | #include "tdefs.h" |
58 | #include "r_params.h" |
59 | #include "genrand.h" |
60 | |
61 | static char alpha_num[65] = "0123456789abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ," ; |
62 | |
63 | char *getenv(const char *name); |
64 | int print_separator(int sep); |
65 | |
66 | extern long Seed[]; |
67 | |
68 | #ifdef WIN32 |
69 | #define PATH_SEP '\\' |
70 | #else |
71 | #define PATH_SEP '/' |
72 | #endif |
73 | |
74 | int file_num = -1; |
75 | |
76 | /* |
77 | * |
78 | * Various routines that handle distributions, value selections and |
79 | * seed value management for the DSS benchmark. Current functions: |
80 | * env_config -- set config vars with optional environment override |
81 | * a_rnd(min, max) -- random alphanumeric within length range |
82 | */ |
83 | |
84 | /* |
85 | * env_config: look for a environmental variable setting and return its |
86 | * value; otherwise return the default supplied |
87 | */ |
88 | char *env_config(char *var, char *dflt) { |
89 | static char *evar; |
90 | |
91 | if ((evar = getenv(var)) != NULL) |
92 | return (evar); |
93 | else |
94 | return (dflt); |
95 | } |
96 | |
97 | /* |
98 | * generate a random string with length randomly selected in [min, max] |
99 | * and using the characters in alphanum (currently includes a space |
100 | * and comma) |
101 | */ |
102 | int a_rnd(int min, int max, int column, char *dest) { |
103 | int i, len, char_int; |
104 | |
105 | genrand_integer(&len, DIST_UNIFORM, min, max, 0, column); |
106 | for (i = 0; i < len; i++) { |
107 | if (i % 5 == 0) |
108 | genrand_integer(&char_int, DIST_UNIFORM, 0, 1 << 30, 0, column); |
109 | *(dest + i) = alpha_num[char_int & 077]; |
110 | char_int >>= 6; |
111 | } |
112 | *(dest + len) = '\0'; |
113 | return (len); |
114 | } |
115 | |