diff options
author | Arch Librarian <arch@canonical.com> | 2004-09-20 16:51:09 +0000 |
---|---|---|
committer | Arch Librarian <arch@canonical.com> | 2004-09-20 16:51:09 +0000 |
commit | 0a8a80e58374771acc225fe1e08ed8e0fe0016cc (patch) | |
tree | afa40f2a73b369e2ba930e47c961992170a669b7 /apt-pkg/contrib | |
parent | 93641593cafac296b9072288d8ef9e1a526d745b (diff) |
Sync
Author: jgg
Date: 1998-10-22 04:56:38 GMT
Sync
Diffstat (limited to 'apt-pkg/contrib')
-rw-r--r-- | apt-pkg/contrib/configuration.cc | 18 | ||||
-rw-r--r-- | apt-pkg/contrib/configuration.h | 7 | ||||
-rw-r--r-- | apt-pkg/contrib/fileutl.cc | 8 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.cc | 75 | ||||
-rw-r--r-- | apt-pkg/contrib/strutl.h | 9 |
5 files changed, 106 insertions, 11 deletions
diff --git a/apt-pkg/contrib/configuration.cc b/apt-pkg/contrib/configuration.cc index 82418f9c2..fa07ed35a 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.7 1998/10/20 02:39:26 jgg Exp $ +// $Id: configuration.cc,v 1.8 1998/10/22 04:56:45 jgg Exp $ /* ###################################################################### Configuration Class @@ -33,7 +33,7 @@ Configuration::Configuration() Root = new Item; } /*}}}*/ -// Configuration::Lookup - Lookup a single item /*{{{*/ +// Configuration::Lookup - Lookup a single item /*{{{*/ // --------------------------------------------------------------------- /* This will lookup a single item by name below another item. It is a helper function for the main lookup function */ @@ -66,6 +66,9 @@ Configuration::Item *Configuration::Lookup(Item *Head,const char *S, new items */ Configuration::Item *Configuration::Lookup(const char *Name,bool Create) { + if (Name == 0) + return Root->Child; + const char *Start = Name; const char *End = Start + strlen(Name); const char *TagEnd = Name; @@ -210,6 +213,17 @@ bool Configuration::Exists(const char *Name) } /*}}}*/ +// Configuration::Item::FullTag - Return the fully scoped tag /*{{{*/ +// --------------------------------------------------------------------- +/* */ +string Configuration::Item::FullTag() const +{ + if (Parent == 0 || Parent->Parent == 0) + return Tag; + return Parent->FullTag() + "::" + Tag; +} + /*}}}*/ + // ReadConfigFile - Read a configuration file /*{{{*/ // --------------------------------------------------------------------- /* The configuration format is very much like the named.conf format diff --git a/apt-pkg/contrib/configuration.h b/apt-pkg/contrib/configuration.h index c98b0bb14..14c80e4ad 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.5 1998/10/20 02:39:27 jgg Exp $ +// $Id: configuration.h,v 1.6 1998/10/22 04:56:46 jgg Exp $ /* ###################################################################### Configuration Class @@ -39,6 +39,9 @@ class Configuration Item *Parent; Item *Child; Item *Next; + + string FullTag() const; + Item() : Child(0), Next(0) {}; }; Item *Root; @@ -61,6 +64,8 @@ class Configuration inline bool Exists(string Name) {return Exists(Name.c_str());}; bool Exists(const char *Name); + inline const Item *Tree(const char *Name) {return Lookup(Name,false);}; + Configuration(); }; diff --git a/apt-pkg/contrib/fileutl.cc b/apt-pkg/contrib/fileutl.cc index bfc674c62..3d5c4686b 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.10 1998/10/20 04:33:16 jgg Exp $ +// $Id: fileutl.cc,v 1.11 1998/10/22 04:56:47 jgg Exp $ /* ###################################################################### File Utilities @@ -136,8 +136,8 @@ void SetCloseExec(int Fd,bool Close) /* */ void SetNonBlock(int Fd,bool Block) { - int Flags = fcntl(Fd,F_GETFL); - if (fcntl(Fd,F_SETFL,(Flags & ~O_NONBLOCK) | (Block == false)?0:O_NONBLOCK) != 0) + int Flags = fcntl(Fd,F_GETFL) & (~O_NONBLOCK); + if (fcntl(Fd,F_SETFL,Flags | ((Block == false)?0:O_NONBLOCK)) != 0) { cerr << "FATAL -> Could not set non-blocking flag " << strerror(errno) << endl; exit(100); @@ -153,8 +153,10 @@ 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; } /*}}}*/ diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index c615f6229..04a3c7bb7 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.5 1998/10/20 02:39:30 jgg Exp $ +// $Id: strutl.cc,v 1.6 1998/10/22 04:56:48 jgg Exp $ /* ###################################################################### String Util - Some usefull string functions. @@ -14,9 +14,12 @@ /*}}}*/ // Includes /*{{{*/ #include <strutl.h> +#include <apt-pkg/fileutl.h> + #include <ctype.h> #include <string.h> #include <stdio.h> +#include <time.h> /*}}}*/ // strstrip - Remove white space from the front and back of a string /*{{{*/ @@ -310,7 +313,7 @@ string URIAccess(string URI) { string::size_type Pos = URI.find(':'); if (Pos == string::npos) - return string(); + return URI; return string(URI,0,Pos); } /*}}}*/ @@ -472,3 +475,71 @@ int StringToBool(string Text,int Default = -1) return Default; } /*}}}*/ +// TimeRFC1123 - Convert a time_t into RFC1123 format /*{{{*/ +// --------------------------------------------------------------------- +/* This converts a time_t into a string time representation that is + year 2000 complient and timezone neutral */ +string TimeRFC1123(time_t Date) +{ + struct tm Conv = *gmtime(&Date); + char Buf[300]; + + const char *Day[] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; + const char *Month[] = {"Jan","Feb","Mar","Apr","May","Jun","Jul", + "Aug","Sep","Oct","Nov","Dec"}; + + sprintf(Buf,"%s, %02i %s %i %02i:%02i:%02i GMT",Day[Conv.tm_wday], + Conv.tm_mday,Month[Conv.tm_mon],Conv.tm_year+1900,Conv.tm_hour, + Conv.tm_min,Conv.tm_sec); + return Buf; +} + /*}}}*/ +// ReadMessages - Read messages from the FD /*{{{*/ +// --------------------------------------------------------------------- +/* This pulls full messages from the input FD into the message buffer. + It assumes that messages will not pause during transit so no + fancy buffering is used. */ +bool ReadMessages(int Fd, vector<string> &List) +{ + char Buffer[4000]; + char *End = Buffer; + + while (1) + { + int Res = read(Fd,End,sizeof(Buffer) - (End-Buffer)); + + // Process is dead, this is kind of bad.. + if (Res == 0) + return false; + + // No data + if (Res <= 0) + return true; + + End += Res; + + // Look for the end of the message + for (char *I = Buffer; I < End; I++) + { + if (I[0] != '\n' || I[1] != '\n') + continue; + + // Pull the message out + string Message(Buffer,0,I-Buffer); + + // Fix up the buffer + for (; I < End && *I == '\n'; I++); + End -= I-Buffer; + memmove(Buffer,I,End-Buffer); + I = Buffer; + + List.push_back(Message); + } + if (End == Buffer) + return true; + + if (WaitFd(Fd) == false) + return false; + } +} + /*}}}*/ diff --git a/apt-pkg/contrib/strutl.h b/apt-pkg/contrib/strutl.h index 38aca5762..fca36fc38 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.5 1998/10/20 02:39:31 jgg Exp $ +// $Id: strutl.h,v 1.6 1998/10/22 04:56:49 jgg Exp $ /* ###################################################################### String Util - These are some usefull string functions @@ -20,6 +20,7 @@ #include <stdlib.h> #include <string> +#include <vector> char *_strstrip(char *String); char *_strtabexpand(char *String,size_t Len); @@ -32,12 +33,14 @@ string SubstVar(string Str,string Subst,string Contents); string Base64Encode(string Str); string URItoFileName(string URI); string URIAccess(string URI); +string TimeRFC1123(time_t Date); +string LookupTag(string Message,const char *Tag,const char *Default = 0); +int StringToBool(string Text,int Default = -1); +bool ReadMessages(int Fd, vector<string> &List); 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 |