From 8064189b6ed3e7f57fdec77387520410b36aeaf2 Mon Sep 17 00:00:00 2001 From: Daniel Jones Date: Tue, 9 Oct 2012 15:53:12 -0700 Subject: [PATCH] Buffer size option. --- src/fastq-sort.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/fastq-sort.c b/src/fastq-sort.c index e96d9bf..ff77441 100644 --- a/src/fastq-sort.c +++ b/src/fastq-sort.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -357,6 +358,20 @@ void print_help() } +/* Parse a size specification, which is just a number with a K, M, G suffix. */ +size_t parse_size(const char* str) +{ + char* endptr; + unsigned long size = strtoul(str, &endptr, 10); + + if (toupper(*endptr) == 'K') size *= 1000; + else if (toupper(*endptr) == 'M') size *= 1000000; + else if (toupper(*endptr) == 'G') size *= 1000000000; + + return size; +} + + int main(int argc, char* argv[]) { int opt, opt_idx; @@ -366,29 +381,34 @@ int main(int argc, char* argv[]) static struct option long_options[] = { - {"reverse", no_argument, NULL, 'r'}, - {"id", no_argument, NULL, 'I'}, - {"seq", no_argument, NULL, 'S'}, - {"random", no_argument, NULL, 'R'}, - {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'V'}, + {"buffer-size", required_argument, NULL, 'S'}, + {"reverse", no_argument, NULL, 'r'}, + {"id", no_argument, NULL, 'i'}, + {"seq", no_argument, NULL, 's'}, + {"random", no_argument, NULL, 'R'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'V'}, {0, 0, 0, 0} }; while (true) { - opt = getopt_long(argc, argv, "rISRhV", long_options, &opt_idx); + opt = getopt_long(argc, argv, "S:risRhV", long_options, &opt_idx); if (opt == -1) break; switch (opt) { + case 'S': + buffer_size = parse_size(optarg); + break; + case 'r': reverse_sort = true; break; - case 'I': + case 'i': user_cmp = seq_cmp_id; break; - case 'S': + case 's': user_cmp = seq_cmp_seq; break; -- 2.39.2