summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cmndline.cc39
-rw-r--r--apt-pkg/contrib/cmndline.h8
-rw-r--r--apt-pkg/contrib/configuration.cc18
3 files changed, 53 insertions, 12 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 6b36325c7..8e25d395f 100644
--- a/apt-pkg/contrib/cmndline.cc
+++ b/apt-pkg/contrib/cmndline.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cmndline.cc,v 1.1 1998/09/22 05:30:26 jgg Exp $
+// $Id: cmndline.cc,v 1.2 1998/09/26 05:34:24 jgg Exp $
/* ######################################################################
Command Line Class - Sophisticated command line parser
@@ -24,11 +24,20 @@ CommandLine::CommandLine(Args *AList,Configuration *Conf) : ArgList(AList),
{
}
/*}}}*/
+// CommandLine::~CommandLine - Destructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+CommandLine::~CommandLine()
+{
+ delete [] FileList;
+}
+ /*}}}*/
// CommandLine::Parse - Main action member /*{{{*/
// ---------------------------------------------------------------------
/* */
bool CommandLine::Parse(int argc,const char **argv)
{
+ delete [] FileList;
FileList = new const char *[argc];
const char **Files = FileList;
int I;
@@ -99,6 +108,10 @@ bool CommandLine::Parse(int argc,const char **argv)
if (A->end() == true)
return _error->Error("Command line option %s is not understood",argv[I]);
+
+ // The option is not boolean
+ if (A->IsBoolean() == false)
+ return _error->Error("Command line option %s is not boolean",argv[I]);
}
// Deal with it.
@@ -164,6 +177,19 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
// Parse a configuration file
if ((A->Flags & ConfigFile) == ConfigFile)
return ReadConfigFile(*Conf,Argument);
+
+ // Arbitary item specification
+ if ((A->Flags & ArbItem) == ArbItem)
+ {
+ const char *J;
+ for (J = Argument; *J != 0 && *J != '='; J++);
+ if (*J == 0)
+ return _error->Error("Option %s: Configuration item sepecification must have an =.",argv[I]);
+
+ Conf->Set(string(Argument,J-Argument),string(J+1));
+
+ return true;
+ }
Conf->Set(A->ConfName,Argument);
return true;
@@ -278,3 +304,14 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
return true;
}
/*}}}*/
+// CommandLine::FileSize - Count the number of filenames /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+unsigned int CommandLine::FileSize() const
+{
+ unsigned int Count = 0;
+ for (const char **I = FileList; I != 0 && *I != 0; I++)
+ Count++;
+ return Count;
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/cmndline.h b/apt-pkg/contrib/cmndline.h
index 038f421e7..27f69729c 100644
--- a/apt-pkg/contrib/cmndline.h
+++ b/apt-pkg/contrib/cmndline.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: cmndline.h,v 1.1 1998/09/22 05:30:26 jgg Exp $
+// $Id: cmndline.h,v 1.2 1998/09/26 05:34:25 jgg Exp $
/* ######################################################################
Command Line Class - Sophisticated command line parser
@@ -67,15 +67,18 @@ class CommandLine
IntLevel = (1 << 1),
Boolean = (1 << 2),
InvBoolean = (1 << 3),
- ConfigFile = (1 << 4) | HasArg
+ ConfigFile = (1 << 4) | HasArg,
+ ArbItem = (1 << 5) | HasArg
};
const char **FileList;
bool Parse(int argc,const char **argv);
void ShowHelp();
+ unsigned int FileSize() const;
CommandLine(Args *AList,Configuration *Conf);
+ ~CommandLine();
};
struct CommandLine::Args
@@ -86,6 +89,7 @@ struct CommandLine::Args
unsigned long Flags;
inline bool end() {return ShortOpt == 0 && LongOpt == 0;};
+ inline bool IsBoolean() {return Flags == 0 || (Flags & (Boolean|InvBoolean)) != 0;};
};
#endif
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index bff2dc6e3..b12fed6be 100644
--- a/apt-pkg/contrib/configuration.cc
+++ b/apt-pkg/contrib/configuration.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.cc,v 1.4 1998/09/22 05:30:26 jgg Exp $
+// $Id: configuration.cc,v 1.5 1998/09/26 05:34:26 jgg Exp $
/* ######################################################################
Configuration Class
@@ -156,17 +156,17 @@ bool Configuration::FindB(const char *Name,bool Default)
if (End == Itm->Value.c_str() || Res < 0 || Res > 1)
{
// Check for positives
- if (strcasecmp(Itm->Value,"no") == 0 ||
- strcasecmp(Itm->Value,"false") == 0 ||
- strcasecmp(Itm->Value,"without") == 0 ||
- strcasecmp(Itm->Value,"disable") == 0)
+ if (strcasecmp(Itm->Value.c_str(),"no") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"false") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"without") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"disable") == 0)
return false;
// Check for negatives
- if (strcasecmp(Itm->Value,"no") == 0 ||
- strcasecmp(Itm->Value,"false") == 0 ||
- strcasecmp(Itm->Value,"without") == 0 ||
- strcasecmp(Itm->Value,"disable") == 0)
+ if (strcasecmp(Itm->Value.c_str(),"yes") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"true") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"with") == 0 ||
+ strcasecmp(Itm->Value.c_str(),"enable") == 0)
return false;
return Default;