00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
#ifndef OFCMDLN_H
00035
#define OFCMDLN_H
00036
00037
#include "osconfig.h"
00038
#include "oftypes.h"
00039
#include "oflist.h"
00040
#include "ofstring.h"
00041
#include "ofconsol.h"
00042
00043
#define INCLUDE_CSTDIO
00044
#include "ofstdinc.h"
00045
00046
00047
00048
00049
00050
00052
typedef signed long OFCmdSignedInt;
00054
typedef unsigned long OFCmdUnsignedInt;
00056
typedef double OFCmdFloat;
00058
typedef OFString OFCmdString;
00059
00060
00061
typedef OFListIterator(
OFString) OFListIterator_OFString;
00062
00063
00064
00065
00066
00067
00068 struct OFCmdOption;
00069 struct OFCmdParamPos;
00070
00071
00072
00073
00074
00075
00079 struct
OFCmdParam
00080 {
00081
00084 enum E_ParamMode
00085 {
00087 PM_Mandatory,
00089 PM_Optional,
00091 PM_MultiMandatory,
00093 PM_MultiOptional
00094 };
00095
00102 OFCmdParam(
const char *param,
00103
const char *descr,
00104
const E_ParamMode mode)
00105 : ParamName(param),
00106 ParamDescription(descr),
00107 ParamMode(mode)
00108 {
00109 }
00110
00112 const OFString ParamName;
00114 const OFString ParamDescription;
00116 const E_ParamMode ParamMode;
00117
00118
private:
00119
00121 OFCmdParam& operator=(
const OFCmdParam& arg);
00122 };
00123
00124
00125
00126
00127
00128
00133 class OFCommandLine
00134 {
00135
00136
public:
00137
00138
00139
00142 enum E_ParseStatus
00143 {
00145
PS_Normal,
00147
PS_NoArguments,
00149
PS_UnknownOption,
00151
PS_MissingValue,
00153
PS_MissingParameter,
00155
PS_TooManyParameters,
00157
PS_CannotOpenCommandFile
00158 };
00159
00160
00163 enum E_ValueStatus
00164 {
00166
VS_Normal,
00168
VS_Invalid,
00170
VS_NoMore,
00172
VS_Empty,
00174
VS_Underflow,
00176
VS_Overflow
00177 };
00178
00179
00182 enum E_ParamValueStatus
00183 {
00185
PVS_Normal,
00187
PVS_Invalid,
00189
PVS_CantFind,
00191
PVS_Empty,
00193
PVS_Underflow,
00195
PVS_Overflow
00196 };
00197
00200 enum E_FindOptionMode
00201 {
00203
FOM_Normal,
00205
FOM_First,
00207
FOM_Next
00208 };
00209
00210
00211
00212
00215
OFCommandLine();
00216
00219
virtual ~OFCommandLine();
00220
00221
00222
00223
00228
void setOptionChars(
const char *chars);
00229
00235
void setOptionColumns(
const int longCols,
00236
const int shortCols);
00237
00242
void setParamColumn(
const int column);
00243
00258 OFBool
addOption(
const char *longOpt,
00259
const char *shortOpt,
00260
const int valueCount,
00261
const char *valueDescr,
00262
const char *optDescr,
00263
const OFBool exclusive = OFFalse);
00264
00277 OFBool
addOption(
const char *longOpt,
00278
const char *shortOpt,
00279
const char *optDescr,
00280
const OFBool exclusive = OFFalse);
00281
00295 OFBool
addOption(
const char *longOpt,
00296
const int valueCount,
00297
const char *valueDescr,
00298
const char *optDescr,
00299
const OFBool exclusive = OFFalse);
00300
00312 OFBool
addOption(
const char *longOpt,
00313
const char *optDescr,
00314
const OFBool exclusive = OFFalse);
00315
00323
void addGroup(
const char *name,
00324
const int longCols = 0,
00325
const int shortCols = 0);
00326
00334
void addSubGroup(
const char *name,
00335
const int longCols = 0,
00336
const int shortCols = 0);
00337
00347 OFBool
addParam(
const char *param,
00348
const char *descr,
00349
const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory);
00350
00359 OFBool
addParam(
const char *param,
00360
const OFCmdParam::E_ParamMode mode = OFCmdParam::PM_Mandatory);
00361
00362
00363
00364
00370 int getArgCount()
const
00371
{
00372
return ArgumentList.
size();
00373 }
00374
00380 OFBool
gotoFirstArg();
00381
00387 OFBool
gotoNextArg();
00388
00396 OFBool
getCurrentArg(
const char *&arg);
00397
00406 OFBool
getCurrentArg(OFCmdString &arg);
00407
00413 int getParamCount()
const
00414
{
00415
return ParamPosList.
size();
00416 }
00417
00422 int getMinParamCount()
const
00423
{
00424
return MinParamCount;
00425 }
00426
00431 int getMaxParamCount()
const
00432
{
00433
return MaxParamCount;
00434 }
00435
00442 OFBool
hasExclusiveOption()
const
00443
{
00444
return ExclusiveOption;
00445 }
00446
00447
00448
00449
00456 OFBool
findParam(
const int pos);
00457
00458
00466 E_ParamValueStatus
getParam(
const int pos,
00467 OFCmdSignedInt &value);
00468
00478 E_ParamValueStatus
getParamAndCheckMin(
const int pos,
00479 OFCmdSignedInt &value,
00480
const OFCmdSignedInt low,
00481
const OFBool incl = OFTrue);
00482
00492 E_ParamValueStatus
getParamAndCheckMinMax(
const int pos,
00493 OFCmdSignedInt &value,
00494
const OFCmdSignedInt low,
00495
const OFCmdSignedInt high);
00496
00506 E_ParamValueStatus
getParam(
const int pos,
00507 OFCmdUnsignedInt &value);
00508
00520 E_ParamValueStatus
getParamAndCheckMin(
const int pos,
00521 OFCmdUnsignedInt &value,
00522
const OFCmdUnsignedInt low,
00523
const OFBool incl = OFTrue);
00524
00536 E_ParamValueStatus
getParamAndCheckMinMax(
const int pos,
00537 OFCmdUnsignedInt &value,
00538
const OFCmdUnsignedInt low,
00539
const OFCmdUnsignedInt high);
00540
00548 E_ParamValueStatus
getParam(
const int pos,
00549 OFCmdFloat &value);
00550
00560 E_ParamValueStatus
getParamAndCheckMin(
const int pos,
00561 OFCmdFloat &value,
00562
const OFCmdFloat low,
00563
const OFBool incl = OFTrue);
00564
00574 E_ParamValueStatus
getParamAndCheckMinMax(
const int pos,
00575 OFCmdFloat &value,
00576
const OFCmdFloat low,
00577
const OFCmdFloat high);
00578
00586 E_ParamValueStatus
getParam(
const int pos,
00587
const char *¶m);
00588
00596 E_ParamValueStatus
getParam(
const int pos,
00597 OFCmdString ¶m);
00598
00599
00600
00601
00616 OFBool
findOption(
const char *longOpt,
00617
const signed int pos = 0,
00618
const E_FindOptionMode mode = FOM_Normal);
00619
00625 OFBool
gotoFirstOption();
00626
00632 OFBool
gotoNextOption();
00633
00642 OFBool
getCurrentOption(
const char *&opt);
00643
00652 OFBool
getCurrentOption(OFCmdString &opt);
00653
00656
void beginOptionBlock();
00657
00660
void endOptionBlock();
00661
00662
00663
00664
00671 E_ValueStatus
getValue(OFCmdSignedInt &value);
00672
00681 E_ValueStatus
getValueAndCheckMin(OFCmdSignedInt &value,
00682
const OFCmdSignedInt low,
00683
const OFBool incl = OFTrue);
00684
00693 E_ValueStatus
getValueAndCheckMinMax(OFCmdSignedInt &value,
00694
const OFCmdSignedInt low,
00695
const OFCmdSignedInt high);
00696
00703 E_ValueStatus
getValue(OFCmdUnsignedInt &value);
00704
00713 E_ValueStatus
getValueAndCheckMin(OFCmdUnsignedInt &value,
00714
const OFCmdUnsignedInt low,
00715
const OFBool incl = OFTrue);
00716
00725 E_ValueStatus
getValueAndCheckMinMax(OFCmdUnsignedInt &value,
00726
const OFCmdUnsignedInt low,
00727
const OFCmdUnsignedInt high);
00728
00735 E_ValueStatus
getValue(OFCmdFloat &value);
00736
00745 E_ValueStatus
getValueAndCheckMin(OFCmdFloat &value,
00746
const OFCmdFloat low,
00747
const OFBool incl = OFTrue);
00748
00757 E_ValueStatus
getValueAndCheckMinMax(OFCmdFloat &value,
00758
const OFCmdFloat low,
00759
const OFCmdFloat high);
00760
00767 E_ValueStatus
getValue(
const char *&value);
00768
00775 E_ValueStatus
getValue(OFCmdString &value);
00776
00777
00778
00779
00792 E_ParseStatus
parseLine(
int argCount,
00793
char *argValue[],
00794
const int flags = 0,
00795
const int startPos = 1);
00796
00797
00798
00799
00805
void getSyntaxString(
OFString &syntaxStr)
const;
00806
00813
void getOptionString(
OFString &optionStr)
const;
00814
00820
void getParamString(
OFString ¶mStr)
const;
00821
00827
void getStatusString(
const E_ParseStatus status,
00828
OFString &statusStr);
00829
00835
void getStatusString(
const E_ParamValueStatus status,
00836
OFString &statusStr);
00837
00843
void getStatusString(
const E_ValueStatus status,
00844
OFString &statusStr);
00845
00846
00847
00848
00850 static const int ExpandWildcards;
00852 static const int NoCommandFiles;
00853
00854
00855
protected:
00856
00859 OFBool
checkOption(
const OFString &option,
00860
const OFBool mode = OFTrue)
const;
00861
00864 OFBool
findParam(
int pos,
00865
OFListIterator(OFCmdParamPos *) &pos_iter);
00866
00869
const OFCmdOption *
findCmdOption(
const OFString &option)
const;
00870
00873
void storeParameter(
const OFString ¶m,
00874
const int directOption = 0);
00875
00878
E_ParseStatus parseCommandFile(
const char *argValue,
00879
OFList<OFString> &argList);
00880
00883
int packColumnValues(
int longCols,
00884
int shortCols)
const;
00885
00888
void unpackColumnValues(
const int value,
00889
unsigned int &longCols,
00890
unsigned int &shortCols)
const;
00891
00892
#ifdef HAVE_WINDOWS_H
00893
00896
void expandWildcards(
const OFString ¶m,
00897
int directOption = 0);
00898
#endif
00899
00902
E_ParseStatus checkParamCount();
00903
00906 OFBool
getLastArg(
OFString &arg);
00907
00910 OFBool
getMissingParam(
OFString ¶m);
00911
00912
00913
private:
00914
00916 OFList<OFCmdOption *> ValidOptionList;
00918 OFList<OFCmdParam *> ValidParamList;
00919
00921 OFList<OFString> ArgumentList;
00923
OFListIterator(
OFString) ArgumentIterator;
00924
00926 OFList<OFCmdParamPos *> ParamPosList;
00928 OFList<OFListIterator_OFString> OptionPosList;
00930 OFListIterator(OFListIterator_OFString) OptionPosIterator;
00932 OFListIterator(OFListIterator_OFString) OptionBlockIterator;
00933
00935 OFBool OptionBlockMode;
00937 OFString OptionChars;
00938
00940 OFBool ExclusiveOption;
00941
00943 int LongColumn;
00945 int ShortColumn;
00947 int ParamColumn;
00948
00950 int MinParamCount;
00952 int MaxParamCount;
00953
00955 OFCmdParam::E_ParamMode LastParamMode;
00956
00957
00958 private:
00959
00961
OFCommandLine &operator=(const
OFCommandLine &obj);
00962 };
00963
00964
00965 #endif
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103