Changeset 4927:8fa254c85099 in roaraudio for roarclients
- Timestamp:
- 05/08/11 11:29:38 (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roarclients/roarvio.c
r4886 r4927 35 35 READ, 36 36 WRITE, 37 PASS, 37 38 EXPLAIN 38 39 }; … … 40 41 41 42 void usage (const char * progname) { 42 fprintf(stderr, "Usage: %s [OPTIONS]... FILE \n", progname);43 fprintf(stderr, "Usage: %s [OPTIONS]... FILE [FILE]\n", progname); 43 44 44 45 fprintf(stderr, "\nOptions:\n\n"); … … 48 49 " --read - Reading mode (like 'cat file').\n" 49 50 " --write - Writing mode (like 'cat > file').\n" 51 " --pass - Passing mode (like 'cat infile > outfile').\n" 50 52 " --explain - Explain VIO object.\n"); 51 53 } … … 157 159 int main (int argc, char * argv[]) { 158 160 struct roar_vio_defaults def; 159 struct roar_vio_calls vio ;161 struct roar_vio_calls vio0, vio1; 160 162 enum action action = READ; 161 163 int i; 162 164 char * k; 163 char * file = NULL; 165 char * file0 = NULL; 166 char * file1 = NULL; 164 167 int o_flags = -1; 165 168 int ret = 0; … … 175 178 } else if ( !strcmp(k, "--write") ) { 176 179 action = WRITE; 180 } else if ( !strcmp(k, "--pass") ) { 181 action = PASS; 177 182 } else if ( !strcmp(k, "--explain") ) { 178 183 action = EXPLAIN; 179 184 } else if ( !strcmp(k, "--verbose") ) { 180 185 g_verbose++; 181 } else if ( file == NULL ) { 182 file = k; 186 } else if ( file0 == NULL ) { 187 file0 = k; 188 } else if ( file1 == NULL ) { 189 file1 = k; 183 190 } else { 184 191 ROAR_ERR("Too many parameters or unknown parameter: %s", k); … … 188 195 } 189 196 190 if ( file == NULL ) { 197 if ( file0 == NULL ) { 198 usage(argv[0]); 199 return 1; 200 } 201 202 if ( (file1 != NULL && action != PASS) || (action == PASS && file1 == NULL) ) { 191 203 usage(argv[0]); 192 204 return 1; … … 195 207 switch (action) { 196 208 case READ: 209 case PASS: 197 210 case EXPLAIN: 198 211 o_flags = O_RDONLY; … … 213 226 } 214 227 215 if ( roar_vio_open_dstr(&vio, file, &def, 1) == -1 ) { 216 ROAR_ERR("Can not open file: %s: %s", file, roar_error2str(roar_error)); 217 return 1; 228 if ( roar_vio_open_dstr(&vio0, file0, &def, 1) == -1 ) { 229 ROAR_ERR("Can not open file: %s: %s", file0, roar_error2str(roar_error)); 230 return 1; 231 } 232 233 if ( action == PASS ) { 234 if ( roar_vio_dstr_init_defaults(&def, ROAR_VIO_DEF_TYPE_NONE, O_WRONLY|O_CREAT|O_TRUNC, 0644) == -1 ) { 235 ROAR_ERR("Can not init DSTR defaults. Bad."); 236 roar_vio_close(&vio0); 237 return 1; 238 } 239 240 if ( roar_vio_open_dstr(&vio1, file1, &def, 1) == -1 ) { 241 ROAR_ERR("Can not open file: %s: %s", file1, roar_error2str(roar_error)); 242 roar_vio_close(&vio0); 243 return 1; 244 } 218 245 } 219 246 220 247 switch (action) { 221 248 case READ: 222 roar_vio_copy_data(roar_stdout, &vio );249 roar_vio_copy_data(roar_stdout, &vio0); 223 250 break; 224 251 case WRITE: 225 roar_vio_copy_data(&vio, roar_stdin); 252 roar_vio_copy_data(&vio0, roar_stdin); 253 break; 254 case PASS: 255 roar_vio_copy_data(&vio1, &vio0); 226 256 break; 227 257 case EXPLAIN: 228 if ( do_explain(&vio ) == -1 )258 if ( do_explain(&vio0) == -1 ) 229 259 ret = 4; 230 260 break; … … 235 265 } 236 266 237 roar_vio_close(&vio); 267 roar_vio_close(&vio0); 268 if ( file1 != NULL ) 269 roar_vio_close(&vio1); 238 270 239 271 return ret;
Note: See TracChangeset
for help on using the changeset viewer.