]> git.saurik.com Git - apt.git/blobdiff - apt-pkg/tagfile.cc
Fixed a few minor dpkg settings
[apt.git] / apt-pkg / tagfile.cc
index 7f2bf6b1de8ef373ad6cab9b41488d6fe986f1e8..bdfa302d8ca6b44aafddfc27264a817e6fc9ca7b 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: tagfile.cc,v 1.18 1998/12/08 05:24:41 jgg Exp $
+// $Id: tagfile.cc,v 1.21 1999/01/31 07:01:11 jgg Exp $
 /* ######################################################################
 
    Fast scanner for RFC-822 type header information
@@ -17,6 +17,7 @@
 
 #include <apt-pkg/tagfile.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
 
 #include <string>
 #include <stdio.h>
@@ -140,6 +141,7 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
    TagCount = 0;
    while (TagCount < sizeof(Indexes)/sizeof(Indexes[0]))
    {
+      // Start a new index and add it to the hash
       if (isspace(Stop[0]) == 0)
       {
         Indexes[TagCount++] = Stop - Section;
@@ -153,9 +155,10 @@ bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
       
       if (Stop == 0)
         return false;
-      for (; Stop[1] == '\r' && Stop < End; Stop++);
+      for (; Stop[1] == '\r' && Stop+1 < End; Stop++);
 
-      if (Stop[1] == '\n')
+      // Double newline or end of file marks the end of the record
+      if (Stop+1 >= End || Stop[1] == '\n')
       {
         Indexes[TagCount] = Stop - Section;
         for (; (Stop[0] == '\n' || Stop[0] == '\r') && Stop < End; Stop++);
@@ -225,14 +228,54 @@ string pkgTagSection::FindS(const char *Tag)
 // TagSection::FindI - Find an integer                                 /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-unsigned int pkgTagSection::FindI(const char *Tag)
+signed int pkgTagSection::FindI(const char *Tag,signed long Default)
 {
    const char *Start;
-   const char *End;
-   if (Find(Tag,Start,End) == false)
-      return 0;
+   const char *Stop;
+   if (Find(Tag,Start,Stop) == false)
+      return Default;
+
+   // Copy it into a temp buffer so we can use strtol
+   char S[300];
+   if ((unsigned)(Stop - Start) >= sizeof(S))
+      return Default;
+   strncpy(S,Start,Stop-Start);
+   S[Stop - Start] = 0;
+   
+   char *End;
+   signed long Result = strtol(S,&End,10);
+   if (S == End)
+      return Default;
+   return Result;
+}
+                                                                       /*}}}*/
+// TagSection::FindFlag - Locate a yes/no type flag                    /*{{{*/
+// ---------------------------------------------------------------------
+/* The bits marked in Flag are masked on/off in Flags */
+bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags,
+                            unsigned long Flag)
+{
+   const char *Start;
+   const char *Stop;
+   if (Find(Tag,Start,Stop) == false)
+      return true;
    
-   return atoi(string(Start,End).c_str());
+   switch (StringToBool(string(Start,Stop)))
+   {     
+      case 0:
+      Flags &= ~Flag;
+      return true;
+
+      case 1:
+      Flags |= Flag;
+      return true;
+
+      default:
+      _error->Warning("Unknown flag value");
+      return true;
+   }
+   return true;
 }
                                                                        /*}}}*/
-                                 
+
+