From 4aa293b5bbb34573386c9e58d5fe08763b890b9a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Nov 2009 00:06:24 +0100 Subject: Options processing --- src/pattern_sim.c | 49 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/pattern_sim.c b/src/pattern_sim.c index 50319dce..ea7ed053 100644 --- a/src/pattern_sim.c +++ b/src/pattern_sim.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "image.h" #include "diffraction.h" @@ -30,11 +31,21 @@ #define CRYSTAL_SIZE (500.0e-9) -static void main_show_help(const char *s) +static void show_help(const char *s) { - printf("Syntax: %s [...]\n\n", s); - printf("Simulate diffraction patterns\n\n"); - printf(" -h Display this help message\n"); + printf("Syntax: %s\n\n", s); + printf("Simulate diffraction patterns from small crystals\n"); + printf(" probed with femosecond pulses from a free electron laser\n\n"); + printf(" -h, --help Display this help message\n"); + printf(" --simulation-details Show details of the simulation\n"); +} + + +static void show_details(const char *s) +{ + printf("%s: Simulation Details\n\n", s); + printf("Simulates diffraction patterns from small crystals\n"); + printf("probed with femtosecond pulses from a free electron laser\n\n"); } @@ -44,20 +55,38 @@ int main(int argc, char *argv[]) struct image image; char filename[1024]; int number = 1; + int config_simdetails = 0; + + const struct option longopts[] = { + {"help", 0, NULL, 'h'}, + {"simulation-details", 0, &config_simdetails, 1}, + {0, 0, NULL, 0} + }; - while ((c = getopt(argc, argv, "h")) != -1) { + while ((c = getopt_long(argc, argv, "h", longopts, NULL)) != -1) { - switch ( c ) { + switch (c) { + case 'h' : { + show_help(argv[0]); + return 0; + } - case 'h' : { - main_show_help(argv[0]); - return 0; - } + case 0 : { + break; + } + default : { + return 1; + } } } + if ( config_simdetails ) { + show_details(argv[0]); + return 0; + } + /* Define image parameters */ image.width = 1024; image.height = 1024; -- cgit v1.2.3