summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r--apt-pkg/contrib/cmndline.cc29
-rw-r--r--apt-pkg/contrib/configuration.cc42
-rw-r--r--apt-pkg/contrib/configuration.h3
-rw-r--r--apt-pkg/contrib/fileutl.cc42
-rw-r--r--apt-pkg/contrib/fileutl.h5
-rw-r--r--apt-pkg/contrib/strutl.cc75
-rw-r--r--apt-pkg/contrib/strutl.h5
7 files changed, 144 insertions, 57 deletions
diff --git a/apt-pkg/contrib/cmndline.cc b/apt-pkg/contrib/cmndline.cc
index 7f5ab59a5..94ca4dc70 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.3 1998/10/08 04:55:01 jgg Exp $
+// $Id: cmndline.cc,v 1.4 1998/10/20 02:39:25 jgg Exp $
/* ######################################################################
Command Line Class - Sophisticated command line parser
@@ -259,14 +259,10 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
break;
}
- // Check for positives
- if (strcasecmp(Argument,"yes") == 0 ||
- strcasecmp(Argument,"true") == 0 ||
- strcasecmp(Argument,"with") == 0 ||
- strcasecmp(Argument,"enable") == 0)
+ // Check for boolean
+ Sense = StringToBool(Argument);
+ if (Sense >= 0)
{
- Sense = 1;
-
// Eat the argument
if (Argument != Buffer)
{
@@ -276,23 +272,6 @@ bool CommandLine::HandleOpt(int &I,int argc,const char *argv[],
break;
}
- // Check for negatives
- if (strcasecmp(Argument,"no") == 0 ||
- strcasecmp(Argument,"false") == 0 ||
- strcasecmp(Argument,"without") == 0 ||
- strcasecmp(Argument,"disable") == 0)
- {
- Sense = 0;
-
- // Eat the argument
- if (Argument != Buffer)
- {
- Opt += strlen(Opt);
- I += IncI;
- }
- break;
- }
-
if (CertainArg == true)
return _error->Error("Sense %s is not understood, try true or false.",Argument);
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc
index 433b92244..82418f9c2 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.6 1998/10/02 04:39:49 jgg Exp $
+// $Id: configuration.cc,v 1.7 1998/10/20 02:39:26 jgg Exp $
/* ######################################################################
Configuration Class
@@ -102,12 +102,12 @@ string Configuration::Find(const char *Name,const char *Default)
return Itm->Value;
}
/*}}}*/
-// Configuration::FindDir - Find a directory /*{{{*/
+// Configuration::FindFile - Find a Filename /*{{{*/
// ---------------------------------------------------------------------
/* Directories are stored as the base dir in the Parent node and the
- sub directory in sub nodes
+ sub directory in sub nodes with the final node being the end filename
*/
-string Configuration::FindDir(const char *Name,const char *Default = 0)
+string Configuration::FindFile(const char *Name,const char *Default)
{
Item *Itm = Lookup(Name,false);
if (Itm == 0 || Itm->Value.empty() == true)
@@ -134,6 +134,17 @@ string Configuration::FindDir(const char *Name,const char *Default = 0)
return Itm->Parent->Value + '/' + Itm->Value;
}
/*}}}*/
+// Configuration::FindDir - Find a directory name /*{{{*/
+// ---------------------------------------------------------------------
+/* This is like findfile execept the result is terminated in a / */
+string Configuration::FindDir(const char *Name,const char *Default)
+{
+ string Res = FindFile(Name,Default);
+ if (Res.end()[-1] != '/')
+ return Res + '/';
+ return Res;
+}
+ /*}}}*/
// Configuration::FindI - Find an integer value /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -160,28 +171,7 @@ bool Configuration::FindB(const char *Name,bool Default)
if (Itm == 0 || Itm->Value.empty() == true)
return Default;
- char *End;
- int Res = strtol(Itm->Value.c_str(),&End,0);
- if (End == Itm->Value.c_str() || Res < 0 || Res > 1)
- {
- // Check for positives
- 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.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 true;
-
- return Default;
- }
-
- return Res;
+ return StringToBool(Itm->Value,Default);
}
/*}}}*/
// Configuration::Set - Set a value /*{{{*/
diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h
index 1cdf67860..c98b0bb14 100644
--- a/apt-pkg/contrib/configuration.h
+++ b/apt-pkg/contrib/configuration.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: configuration.h,v 1.4 1998/09/22 05:30:27 jgg Exp $
+// $Id: configuration.h,v 1.5 1998/10/20 02:39:27 jgg Exp $
/* ######################################################################
Configuration Class
@@ -49,6 +49,7 @@ class Configuration
public:
string Find(const char *Name,const char *Default = 0);
+ string FindFile(const char *Name,const char *Default = 0);
string FindDir(const char *Name,const char *Default = 0);
int FindI(const char *Name,int Default = 0);
bool FindB(const char *Name,bool Default = false);
diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc
index 60b9f8b75..cc0363da5 100644
--- a/apt-pkg/contrib/fileutl.cc
+++ b/apt-pkg/contrib/fileutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.cc,v 1.8 1998/10/02 04:39:50 jgg Exp $
+// $Id: fileutl.cc,v 1.9 1998/10/20 02:39:28 jgg Exp $
/* ######################################################################
File Utilities
@@ -119,6 +119,45 @@ string flNotDir(string File)
return string(File,Res,Res - File.length());
}
/*}}}*/
+// SetCloseExec - Set the close on exec flag /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void SetCloseExec(int Fd,bool Close)
+{
+ if (fcntl(Fd,F_SETFD,(Close == false)?0:FD_CLOEXEC) != 0)
+ {
+ cerr << "FATAL -> Could not set close on exec " << strerror(errno) << endl;
+ exit(100);
+ }
+}
+ /*}}}*/
+// SetNonBlock - Set the nonblocking flag /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void SetNonBlock(int Fd,bool Block)
+{
+ int Flags = fcntl(Fd,F_GETFL);
+ if (fcntl(Fd,F_SETFL,(Block == false)?0:O_NONBLOCK) != 0)
+ {
+ cerr << "FATAL -> Could not set non-blocking flag " << strerror(errno) << endl;
+ exit(100);
+ }
+}
+ /*}}}*/
+// WaitFd - Wait for a FD to become readable /*{{{*/
+// ---------------------------------------------------------------------
+/* This waits for a FD to become readable using select. It is usefull for
+ applications making use of non-blocking sockets. */
+bool WaitFd(int Fd)
+{
+ fd_set Set;
+ FD_ZERO(&Set);
+ FD_SET(Fd,&Set);
+ if (select(Fd+1,&Set,0,0,0) <= 0)
+ return false;
+ return true;
+}
+ /*}}}*/
// FileFd::FileFd - Open a file /*{{{*/
// ---------------------------------------------------------------------
@@ -155,6 +194,7 @@ FileFd::FileFd(string FileName,OpenMode Mode, unsigned long Perms)
_error->Errno("open","Could not open file %s",FileName.c_str());
else
this->FileName = FileName;
+ SetCloseExec(iFd,true);
}
/*}}}*/
// FileFd::~File - Closes the file /*{{{*/
diff --git a/apt-pkg/contrib/fileutl.h b/apt-pkg/contrib/fileutl.h
index c468c95d3..7a72df09f 100644
--- a/apt-pkg/contrib/fileutl.h
+++ b/apt-pkg/contrib/fileutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: fileutl.h,v 1.6 1998/10/02 04:39:52 jgg Exp $
+// $Id: fileutl.h,v 1.7 1998/10/20 02:39:29 jgg Exp $
/* ######################################################################
File Utilities
@@ -63,6 +63,9 @@ bool CopyFile(FileFd From,FileFd To);
int GetLock(string File,bool Errors = true);
bool FileExists(string File);
string SafeGetCWD();
+void SetCloseExec(int Fd,bool Close);
+void SetNonBlock(int Fd,bool Block);
+bool WaitFd(int Fd);
// File string manipulators
string flNotDir(string File);
diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc
index 5a61f269c..c615f6229 100644
--- a/apt-pkg/contrib/strutl.cc
+++ b/apt-pkg/contrib/strutl.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.cc,v 1.4 1998/09/22 05:30:28 jgg Exp $
+// $Id: strutl.cc,v 1.5 1998/10/20 02:39:30 jgg Exp $
/* ######################################################################
String Util - Some usefull string functions.
@@ -303,6 +303,17 @@ string URItoFileName(string URI)
return URI;
}
/*}}}*/
+// URIAccess - Return the access method for the URI /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+string URIAccess(string URI)
+{
+ string::size_type Pos = URI.find(':');
+ if (Pos == string::npos)
+ return string();
+ return string(URI,0,Pos);
+}
+ /*}}}*/
// Base64Encode - Base64 Encoding routine for short strings /*{{{*/
// ---------------------------------------------------------------------
/* This routine performs a base64 transformation on a string. It was ripped
@@ -389,7 +400,7 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd)
for (; A != AEnd && B != BEnd; A++, B++)
if (toupper(*A) != toupper(*B))
break;
-
+
if (A == AEnd && B == BEnd)
return 0;
if (A == AEnd)
@@ -401,3 +412,63 @@ int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd)
return 1;
}
/*}}}*/
+// LookupTag - Lookup the value of a tag in a taged string /*{{{*/
+// ---------------------------------------------------------------------
+/* The format is like those used in package files and the method
+ communication system */
+string LookupTag(string Message,const char *Tag,const char *Default)
+{
+ // Look for a matching tag.
+ int Length = strlen(Tag);
+ for (string::iterator I = Message.begin(); I + Length < Message.end(); I++)
+ {
+ // Found the tag
+ if (I[Length] == ':' && stringcasecmp(I,I+Length,Tag) == 0)
+ {
+ // Find the end of line and strip the leading/trailing spaces
+ string::iterator J;
+ I += Length + 1;
+ for (; isspace(*I) != 0 && I < Message.end(); I++);
+ for (J = I; *J != '\n' && J < Message.end(); J++);
+ for (; J > I && isspace(J[-1]) != 0; J--);
+
+ return string(I,J-I);
+ }
+
+ for (; *I != '\n' && I < Message.end(); I++);
+ }
+
+ // Failed to find a match
+ if (Default == 0)
+ return string();
+ return Default;
+}
+ /*}}}*/
+// StringToBool - Converts a string into a boolean /*{{{*/
+// ---------------------------------------------------------------------
+/* This inspects the string to see if it is true or if it is false and
+ then returns the result. Several varients on true/false are checked. */
+int StringToBool(string Text,int Default = -1)
+{
+ char *End;
+ int Res = strtol(Text.c_str(),&End,0);
+ if (End != Text.c_str() && Res >= 0 && Res <= 1)
+ return Res;
+
+ // Check for positives
+ if (strcasecmp(Text.c_str(),"no") == 0 ||
+ strcasecmp(Text.c_str(),"false") == 0 ||
+ strcasecmp(Text.c_str(),"without") == 0 ||
+ strcasecmp(Text.c_str(),"disable") == 0)
+ return 0;
+
+ // Check for negatives
+ if (strcasecmp(Text.c_str(),"yes") == 0 ||
+ strcasecmp(Text.c_str(),"true") == 0 ||
+ strcasecmp(Text.c_str(),"with") == 0 ||
+ strcasecmp(Text.c_str(),"enable") == 0)
+ return 1;
+
+ return Default;
+}
+ /*}}}*/
diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h
index 7af215587..38aca5762 100644
--- a/apt-pkg/contrib/strutl.h
+++ b/apt-pkg/contrib/strutl.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: strutl.h,v 1.4 1998/09/22 05:30:29 jgg Exp $
+// $Id: strutl.h,v 1.5 1998/10/20 02:39:31 jgg Exp $
/* ######################################################################
String Util - These are some usefull string functions
@@ -31,10 +31,13 @@ string TimeToStr(unsigned long Sec);
string SubstVar(string Str,string Subst,string Contents);
string Base64Encode(string Str);
string URItoFileName(string URI);
+string URIAccess(string URI);
int stringcmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcmp(const char *A,const char *AEnd,const char *B) {return stringcmp(A,AEnd,B,B+strlen(B));};
int stringcasecmp(const char *A,const char *AEnd,const char *B,const char *BEnd);
inline int stringcasecmp(const char *A,const char *AEnd,const char *B) {return stringcasecmp(A,AEnd,B,B+strlen(B));};
+string LookupTag(string Message,const char *Tag,const char *Default = 0);
+int StringToBool(string Text,int Default = -1);
#endif