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 OPTDESC_H
12 #define OPTDESC_H
13 #include "types.h"
14 #include "errordef.h"
15 
16 //}
17 
18 /*
19   This file defines some macros to manipulate and a type to store
20   information about options.
21 */
22 
23 /*
24   The macro \texttt{OPTION} fills the component of a structure of
25   type \texttt{OptionDesc}. This macro should not be used. It
26   is mainly for compatibility of the code.
27 */
28 
29 #define OPTION(S,N,O,D)\
30         S[N].optname = O;\
31         S[N].description = D;\
32         S[N].optval = N;\
33         S[N].isalreadyset = False;\
34         S[N].declared = True
35 
36 /*
37   The macro \texttt{ADDOPTION} has a similar effect, but adding the
38   option is done via the function \texttt{addoption}. This is the
39   recommended way to add an option.
40 */
41 
42 #define ADDOPTION(N,O,D)\
43         if(addoption(&options[0],(Uint) NUMOFOPTIONS,(Uint) N,O,D) != 0)\
44         {\
45           return -1;\
46         }
47 
48 /*
49   The following macro checks if an option is already set.
50 */
51 
52 #define ISSET(N)  (options[N].isalreadyset)
53 
54 /*
55   The following macro checks if an option is used. If not, then
56   an error is reported.
57 */
58 
59 #define OPTIONMANDATORY(A)\
60         if(!ISSET(A))\
61         {\
62           ERROR1("option %s is mandatory",options[A].optname);\
63           return -1;\
64         }
65 
66 /*
67   The following four macros check if all options \texttt{B}
68   (\texttt{C}, \texttt{D}, \texttt{E}) are used, whenever option
69   \texttt{A} is used.
70 */
71 
72 #define OPTIONIMPLY(A,B)\
73         if(ISSET(A) && !ISSET(B))\
74         {\
75           ERROR2("option %s requires option %s",\
76                   options[A].optname,options[B].optname);\
77           return -1;\
78         }
79 
80 #define OPTIONIMPLYEITHER2(A,B,C)\
81         if(ISSET(A))\
82         {\
83           if(!ISSET(B) && !ISSET(C))\
84           {\
85             ERROR3("option %s requires either option %s or %s",\
86                     options[A].optname,options[B].optname,\
87                     options[C].optname);\
88             return -1;\
89           }\
90         }
91 
92 #define OPTIONIMPLYEITHER3(A,B,C,D)\
93         if(ISSET(A))\
94         {\
95           if(!ISSET(B) && !ISSET(C) && !ISSET(D))\
96           {\
97             ERROR4("option %s requires one of the options %s, %s, %s",\
98                     options[A].optname,\
99                     options[B].optname,\
100                     options[C].optname,\
101                     options[D].optname);\
102             return -1;\
103           }\
104         }
105 
106 #define OPTIONIMPLYEITHER4(A,B,C,D,E)\
107         if(ISSET(A))\
108         {\
109           if(!ISSET(B) && !ISSET(C) && !ISSET(D) && !ISSET(E))\
110           {\
111             ERROR5("option %s requires one of the options %s, %s, %s, %s",\
112                     options[A].optname,\
113                     options[B].optname,\
114                     options[C].optname,\
115                     options[D].optname,\
116                     options[E].optname);\
117             return -1;\
118           }\
119         }
120 
121 /*
122   The following macro checks if two options are used simultaneously.
123   If so, then an error is reported.
124 */
125 
126 #define OPTIONEXCLUDE(A,B)\
127         if(ISSET(A) && ISSET(B))\
128         {\
129           ERROR2("option %s and option %s exclude each other",\
130                   options[A].optname,options[B].optname);\
131           return -1;\
132         }
133 
134 /*
135   An option is described by the following type.
136 */
137 
138 typedef struct
139 {
140   char *optname,             // the option string, begins with -
141        *description;         // help text describing purpose of option
142   Uint optval;               // the unique number of an option
143   BOOL isalreadyset,         // has the option already been set?
144        declared;             // is the option declared by
145                              // a line of the form \texttt{ADDOPTION}
146 } OptionDescription;         // \Typedef{OptionDescription}
147 
148 //\Ignore{
149 
150 #endif
151 
152 //}
153