Debian Codegraph @

samtools/sam_opts.h

raw symbols SCIP
1 /* sam_opts.h -- utilities to aid parsing common command line options.
2
3 Copyright (C) 2015, 2019 Genome Research Ltd.
4
5 Author: James Bonfield <[email protected]>
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 DEALINGS IN THE SOFTWARE. */
24
25 #ifndef SAM_OPTS_H
26 #define SAM_OPTS_H
27
28 #include <stdio.h>
29 #include <limits.h>
30 #include <getopt.h>
31 #include <htslib/hts.h>
32
33 typedef struct sam_global_args {
34 htsFormat in;
35 htsFormat out;
36 char *reference;
37 int nthreads;
38 int write_index;
39 } sam_global_args;
40
41 #define SAM_GLOBAL_ARGS_INIT {{0},{0}}
42
43 enum {
44 SAM_OPT_INPUT_FMT = CHAR_MAX+1,
45 SAM_OPT_INPUT_FMT_OPTION,
46 SAM_OPT_OUTPUT_FMT,
47 SAM_OPT_OUTPUT_FMT_OPTION,
48 SAM_OPT_REFERENCE,
49 SAM_OPT_NTHREADS,
50 SAM_OPT_WRITE_INDEX,
51 SAM_OPT_VERBOSITY,
52 };
53
54 #define SAM_OPT_VAL(val, defval) ((val) == '-')? '?' : (val)? (val) : (defval)
55
56 // Use this within struct option lopts[] = {...} to add the standard global
57 // options. The arguments determine whether the corresponding option is
58 // enabled and, if so, whether it has a short option equivalent:
59 // 0 No short option has been assigned. Use --long-opt only.
60 // '-' Both long and short options are disabled.
61 // <c> Otherwise the equivalent short option is character <c>.
62 #define SAM_OPT_GLOBAL_OPTIONS(o1, o2, o3, o4, o5, o6) \
63 {"input-fmt", required_argument, NULL, SAM_OPT_VAL(o1, SAM_OPT_INPUT_FMT)}, \
64 {"input-fmt-option", required_argument, NULL, SAM_OPT_VAL(o2, SAM_OPT_INPUT_FMT_OPTION)}, \
65 {"output-fmt", required_argument, NULL, SAM_OPT_VAL(o3, SAM_OPT_OUTPUT_FMT)}, \
66 {"output-fmt-option", required_argument, NULL, SAM_OPT_VAL(o4, SAM_OPT_OUTPUT_FMT_OPTION)}, \
67 {"reference", required_argument, NULL, SAM_OPT_VAL(o5, SAM_OPT_REFERENCE)}, \
68 {"threads", required_argument, NULL, SAM_OPT_VAL(o6, SAM_OPT_NTHREADS)}, \
69 {"write-index", no_argument, NULL, SAM_OPT_WRITE_INDEX}, \
70 {"verbosity", required_argument, NULL, SAM_OPT_VERBOSITY}
71
72 /*
73 * Processes a standard "global" samtools long option.
74 *
75 * The 'c' value is the return value from a getopt_long() call. It is checked
76 * against the lopt[] array to find the corresponding value as this may have
77 * been reassigned by the individual subcommand.
78 *
79 * Having found the entry, the corresponding long form is used to apply the
80 * option, storing the setting in sam_global_args *ga.
81 *
82 * Returns 0 on success,
83 * -1 on failure.
84 */
85 int parse_sam_global_opt(int c, const char *optarg, const struct option *lopt,
86 sam_global_args *ga);
87
88 /*
89 * Report the usage for global options.
90 *
91 * This accepts a string with one character per SAM_OPT_GLOBAL_OPTIONS option
92 * to determine which options need to be printed and how.
93 * Each character should be one of:
94 * '.' No short option has been assigned. Use --long-opt only.
95 * '-' The long (and short) option has been disabled.
96 * <c> Otherwise the short option is character <c>.
97 */
98 void sam_global_opt_help(FILE *fp, const char *shortopts);
99
100
101 void sam_global_args_init(sam_global_args *ga);
102 void sam_global_args_free(sam_global_args *ga);
103
104 #endif