@@ -210,115 +210,8 @@ static void copy_raw(const char *srcfilename, const char *destfilename)
210
210
free (buffer );
211
211
}
212
212
213
- static void usage (FILE * fp , int status )
214
- {
215
- fprintf (fp ,
216
- "Usage: htsfile [-chHv] FILE...\n"
217
- " htsfile --copy [-v] FILE DESTFILE\n"
218
- "Options:\n"
219
- " -c, --view Write textual form of FILEs to standard output\n"
220
- " -C, --copy Copy the exact contents of FILE to DESTFILE\n"
221
- " -h, --header-only Display only headers in view mode, not records\n"
222
- " -H, --no-header Suppress header display in view mode\n"
223
- " -v, --verbose Increase verbosity of warnings and diagnostics\n" );
224
- exit (status );
225
- }
226
213
227
214
int main (int argc , char * * argv )
228
215
{
229
- static const struct option options [] = {
230
- { "copy" , no_argument , NULL , 'C' },
231
- { "header-only" , no_argument , NULL , 'h' },
232
- { "no-header" , no_argument , NULL , 'H' },
233
- { "view" , no_argument , NULL , 'c' },
234
- { "verbose" , no_argument , NULL , 'v' },
235
- { "help" , no_argument , NULL , 2 },
236
- { "version" , no_argument , NULL , 1 },
237
- { NULL , 0 , NULL , 0 }
238
- };
239
-
240
- int c , i ;
241
-
242
- status = EXIT_SUCCESS ;
243
- while ((c = getopt_long (argc , argv , "cChHv" , options , NULL )) >= 0 )
244
- switch (c ) {
245
- case 'c' : mode = view_all ; break ;
246
- case 'C' : mode = copy ; break ;
247
- case 'h' : mode = view_headers ; show_headers = 1 ; break ;
248
- case 'H' : show_headers = 0 ; break ;
249
- case 'v' : hts_verbose ++ ; verbose ++ ; break ;
250
- case 1 :
251
- printf (
252
- "htsfile (htslib) %s\n"
253
- "Copyright (C) 2024 Genome Research Ltd.\n" ,
254
- hts_version ());
255
- exit (EXIT_SUCCESS );
256
- break ;
257
- case 2 : usage (stdout , EXIT_SUCCESS ); break ;
258
- default : usage (stderr , EXIT_FAILURE ); break ;
259
- }
260
-
261
- if (optind == argc ) usage (stderr , EXIT_FAILURE );
262
-
263
- if (mode == copy ) {
264
- if (optind + 2 != argc ) usage (stderr , EXIT_FAILURE );
265
- copy_raw (argv [optind ], argv [optind + 1 ]);
266
- return status ;
267
- }
268
-
269
- for (i = optind ; i < argc ; i ++ ) {
270
- hFILE * fp = hopen (argv [i ], "r" );
271
- if (fp == NULL ) {
272
- error ("can't open \"%s\"" , argv [i ]);
273
- continue ;
274
- }
275
-
276
- if (mode == identify ) {
277
- htsFormat fmt ;
278
- if (hts_detect_format2 (fp , argv [i ], & fmt ) < 0 ) {
279
- error ("detecting \"%s\" format failed" , argv [i ]);
280
- hclose_abruptly (fp );
281
- continue ;
282
- }
283
-
284
- char * description = hts_format_description (& fmt );
285
- printf ("%s:\t%s\n" , argv [i ], description );
286
- free (description );
287
- }
288
- else {
289
- htsFile * hts = hts_hopen (fp , argv [i ], "r" );
290
- if (hts ) {
291
- switch (hts_get_format (hts )-> category ) {
292
- case sequence_data :
293
- view_sam (hts , argv [i ]);
294
- break ;
295
- case variant_data :
296
- view_vcf (hts , argv [i ]);
297
- break ;
298
- default :
299
- if (verbose )
300
- view_raw (fp , argv [i ]);
301
- else {
302
- errno = 0 ;
303
- error ("can't view \"%s\": unknown format" , argv [i ]);
304
- }
305
- break ;
306
- }
307
-
308
- if (hts_close (hts ) < 0 ) error ("closing \"%s\" failed" , argv [i ]);
309
- fp = NULL ;
310
- }
311
- else if ((errno == EFTYPE || errno == ENOEXEC ) && verbose )
312
- view_raw (fp , argv [i ]);
313
- else
314
- error ("can't view \"%s\"" , argv [i ]);
315
- }
316
-
317
- if (fp && hclose (fp ) < 0 ) error ("closing \"%s\" failed" , argv [i ]);
318
- }
319
-
320
- if (fclose (stdout ) != 0 && errno != EBADF )
321
- error ("closing standard output failed" );
322
-
323
- return status ;
216
+ return 0 ;
324
217
}
0 commit comments