1 /* 2 Copyright (c) 2003 by Stefan Kurtz and The Institute for 3 Genomic Research. This is OSI Certified Open Source Software. 4 Please see the file LICENSE for licensing information and 5 the file ACKNOWLEDGEMENTS for names of contributors to the 6 code base. 7 */ 8 9 //\Ignore{ 10 11 #ifndef ARGS_H 12 #define ARGS_H 13 #include <stdlib.h> 14 #include <stdio.h> 15 16 //} 17 18 /* 19 This header file implements three macros for checking argument numbers 20 and to parse integers and floats from strings. 21 */ 22 23 /* 24 The following macro checks if the number of argument is exactly 25 \texttt{N}. Otherwise, an error message is thrown. 26 */ 27 28 #define CHECKARGNUM(N,S)\ 29 if (argc != N)\ 30 {\ 31 fprintf(stderr,"Usage: %s %s\n",argv[0],S);\ 32 exit(EXIT_FAILURE);\ 33 } 34 35 /* 36 The following scans an integer \texttt{readint} from a string. 37 */ 38 39 #define PARSEINTARG(S)\ 40 if(sscanf(S,"%ld",&readint) != 1 || readint < 0)\ 41 {\ 42 fprintf(stderr,"invalid argument \"%s\": " \ 43 "non-negative number expected\n",S);\ 44 exit(EXIT_FAILURE);\ 45 } 46 47 /* 48 The following scans a floating point value \texttt{readfloat} from a 49 string. 50 */ 51 52 #define PARSEFLOATARG(S)\ 53 if(sscanf(S,"%f",&readfloat) != 1)\ 54 {\ 55 fprintf(stderr,"invalid argument \"%s\":"\ 56 " floating point number expected\n",S);\ 57 exit(EXIT_FAILURE);\ 58 } 59 60 //\IgnoreLatex{ 61 62 #endif 63 64 //} 65