|
10 | 10 |
|
11 | 11 | #include <stdio.h>
|
12 | 12 | #include <string.h>
|
| 13 | +#include <unistd.h> |
13 | 14 | #include <ctype.h>
|
14 | 15 | #include <stdlib.h>
|
15 | 16 | #include <time.h>
|
@@ -75,70 +76,80 @@ main(argc, argv)
|
75 | 76 | char db_password[DB_STRING_MAX];
|
76 | 77 | int port= 3306;
|
77 | 78 |
|
78 |
| - int i; |
| 79 | + int i,c; |
79 | 80 |
|
80 | 81 | MYSQL* resp;
|
81 | 82 |
|
82 | 83 | /* initialize */
|
83 | 84 | count_ware = 0;
|
84 | 85 |
|
85 | 86 | printf("*************************************\n");
|
86 |
| - printf("*** ###easy### TPC-C Data Loader ***\n"); |
| 87 | + printf("*** TPCC-mysql Data Loader ***\n"); |
87 | 88 | printf("*************************************\n");
|
88 | 89 |
|
89 |
| - /* Parse args */ |
90 |
| - if (argc != 9) { |
91 |
| - if (argc != 6) { |
92 |
| - fprintf(stderr, |
93 |
| - "\n usage: tpcc_load [server] [DB] [user] [pass] [warehouse]\n" |
94 |
| - " OR\n" |
95 |
| - " tpcc_load [server] [DB] [user] [pass] [warehouse] [part] [min_wh] [max_wh]\n\n" |
96 |
| - " * [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS\n" |
97 |
| - ); |
98 |
| - exit(1); |
99 |
| - } |
100 |
| - }else{ |
| 90 | + /* Parse args */ |
| 91 | + |
| 92 | + while ( (c = getopt(argc, argv, "h:P:d:u:p:w:l:m:n:")) != -1) { |
| 93 | + switch (c) { |
| 94 | + case 'h': |
| 95 | + printf ("option h with value '%s'\n", optarg); |
| 96 | + strncpy(connect_string, optarg, DB_STRING_MAX); |
| 97 | + break; |
| 98 | + case 'd': |
| 99 | + printf ("option d with value '%s'\n", optarg); |
| 100 | + strncpy(db_string, optarg, DB_STRING_MAX); |
| 101 | + break; |
| 102 | + case 'u': |
| 103 | + printf ("option u with value '%s'\n", optarg); |
| 104 | + strncpy(db_user, optarg, DB_STRING_MAX); |
| 105 | + break; |
| 106 | + case 'p': |
| 107 | + printf ("option p with value '%s'\n", optarg); |
| 108 | + strncpy(db_password, optarg, DB_STRING_MAX); |
| 109 | + break; |
| 110 | + case 'w': |
| 111 | + printf ("option w with value '%s'\n", optarg); |
| 112 | + count_ware = atoi(optarg); |
| 113 | + break; |
| 114 | + case 'l': |
| 115 | + printf ("option l with value '%s'\n", optarg); |
| 116 | + part_no = atoi(optarg); |
101 | 117 | particle_flg = 1;
|
102 |
| - } |
103 |
| - |
104 |
| - if ( strlen(argv[1]) >= DB_STRING_MAX ) { |
105 |
| - fprintf(stderr, "\n server phrase is too long\n"); |
106 |
| - exit(1); |
107 |
| - } |
108 |
| - if ( strlen(argv[2]) >= DB_STRING_MAX ) { |
109 |
| - fprintf(stderr, "\n DBname phrase is too long\n"); |
110 |
| - exit(1); |
111 |
| - } |
112 |
| - if ( strlen(argv[3]) >= DB_STRING_MAX ) { |
113 |
| - fprintf(stderr, "\n user phrase is too long\n"); |
114 |
| - exit(1); |
115 |
| - } |
116 |
| - if ( strlen(argv[4]) >= DB_STRING_MAX ) { |
117 |
| - fprintf(stderr, "\n pass phrase is too long\n"); |
118 |
| - exit(1); |
119 |
| - } |
120 |
| - if ((count_ware = atoi(argv[5])) <= 0) { |
121 |
| - fprintf(stderr, "\n expecting positive number of warehouses\n"); |
122 |
| - exit(1); |
123 |
| - } |
124 |
| - //strcpy(connect_string, argv[1]); |
125 |
| - parse_host(connect_string, argv[1]); |
126 |
| - port= parse_port(argv[1]); |
127 |
| - strcpy( db_string, argv[2] ); |
128 |
| - strcpy( db_user, argv[3] ); |
129 |
| - strcpy( db_password, argv[4] ); |
| 118 | + break; |
| 119 | + case 'm': |
| 120 | + printf ("option m with value '%s'\n", optarg); |
| 121 | + min_ware = atoi(optarg); |
| 122 | + break; |
| 123 | + case 'n': |
| 124 | + printf ("option n with value '%s'\n", optarg); |
| 125 | + max_ware = atoi(optarg); |
| 126 | + break; |
| 127 | + case 'P': |
| 128 | + printf ("option P with value '%s'\n", optarg); |
| 129 | + port = atoi(optarg); |
| 130 | + break; |
| 131 | + case '?': |
| 132 | + printf("Usage: tpcc_load -h server_host -P port -d database_name -u mysql_user -p mysql_password -w warehouses -l part -m min_wh -n max_wh\n"); |
| 133 | + printf("* [part]: 1=ITEMS 2=WAREHOUSE 3=CUSTOMER 4=ORDERS\n"); |
| 134 | + exit(0); |
| 135 | + default: |
| 136 | + printf ("?? getopt returned character code 0%o ??\n", c); |
| 137 | + } |
| 138 | + } |
| 139 | + if (optind < argc) { |
| 140 | + printf ("non-option ARGV-elements: "); |
| 141 | + while (optind < argc) |
| 142 | + printf ("%s ", argv[optind++]); |
| 143 | + printf ("\n"); |
| 144 | + } |
130 | 145 |
|
131 | 146 | if(strcmp(connect_string,"l")==0){
|
132 | 147 | is_local = 1;
|
133 | 148 | }else{
|
134 | 149 | is_local = 0;
|
135 | 150 | }
|
136 | 151 |
|
137 |
| - if(particle_flg==1){ |
138 |
| - part_no = atoi(argv[6]); |
139 |
| - min_ware = atoi(argv[7]); |
140 |
| - max_ware = atoi(argv[8]); |
141 |
| - }else{ |
| 152 | + if(particle_flg==0){ |
142 | 153 | min_ware = 1;
|
143 | 154 | max_ware = count_ware;
|
144 | 155 | }
|
|
0 commit comments