]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/contrib/cmndline.cc
Fixed espy's bug with experimental
[apt.git] / apt-pkg / contrib / cmndline.cc
index 9546eac8f20fcdb9bdd823e988578cff72775e57..3c3717c99f939efae1c2afb2774c359b71baaa44 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: cmndline.cc,v 1.5 1998/10/24 20:14:34 jgg Exp $
+// $Id: cmndline.cc,v 1.9 1999/01/27 02:48:52 jgg Exp $
 /* ######################################################################
 
    Command Line Class - Sophisticated command line parser
@@ -13,7 +13,7 @@
 #endif
 #include <apt-pkg/cmndline.h>
 #include <apt-pkg/error.h>
-#include <strutl.h>
+#include <apt-pkg/strutl.h>
                                                                        /*}}}*/
 
 // CommandLine::CommandLine - Constructor                              /*{{{*/
@@ -96,7 +96,6 @@ bool CommandLine::Parse(int argc,const char **argv)
         if (Opt == OptEnd)
            return _error->Error("Command line option %s is not understood",argv[I]);
         Opt++;
-        cout << Opt << endl;
         
         for (A = ArgList; A->end() == false &&
              stringcasecmp(Opt,OptEnd,A->LongOpt) != 0; A++);
@@ -205,7 +204,13 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
         return true;
       }
       
-      Conf->Set(A->ConfName,Argument);
+      const char *I = A->ConfName;
+      for (; *I != 0 && *I != ' '; I++);
+      if (*I == ' ')
+        Conf->Set(string(A->ConfName,0,I-A->ConfName),string(I+1) + Argument);
+      else
+        Conf->Set(A->ConfName,string(I) + Argument);
+        
       return true;
    }
    
@@ -302,7 +307,7 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
    return true;
 }
                                                                        /*}}}*/
-// CommandLine::FileSize - Count the number of filenames                                                                       /*{{{*/
+// CommandLine::FileSize - Count the number of filenames               /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 unsigned int CommandLine::FileSize() const
@@ -313,3 +318,30 @@ unsigned int CommandLine::FileSize() const
    return Count;
 }
                                                                        /*}}}*/
+// CommandLine::DispatchArg - Do something with the first arg          /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+bool CommandLine::DispatchArg(Dispatch *Map,bool NoMatch)
+{
+   int I;
+   for (I = 0; Map[I].Match != 0; I++)
+   {
+      if (strcmp(FileList[0],Map[I].Match) == 0)
+      {
+        bool Res = Map[I].Handler(*this);
+        if (Res == false && _error->PendingError() == false)
+           _error->Error("Handler silently failed");
+        return Res;
+      }
+   }
+   
+   // No matching name
+   if (Map[I].Match == 0)
+   {
+      if (NoMatch == true)
+        _error->Error("Invalid operation %s",FileList[0]);
+   }
+   
+   return false;
+}
+                                                                       /*}}}*/