~ubuntu-branches/ubuntu/trusty/apt/trusty

« back to all changes in this revision

Viewing changes to apt-pkg/tagfile.cc

  • Committer: Package Import Robot
  • Author(s): Michael Vogt
  • Date: 2014-02-07 21:03:22 UTC
  • mfrom: (1.4.80 sid)
  • Revision ID: package-import@ubuntu.com-20140207210322-s7f833aga98ibdkm
Tags: 0.9.15.1ubuntu1
mergedĀ fromĀ debian/sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
207
207
      unsigned long long Dist = Offset - d->iOffset;
208
208
      d->Start += Dist;
209
209
      d->iOffset += Dist;
210
 
      return Step(Tag);
 
210
      // if we have seen the end, don't ask for more
 
211
      if (d->Done == true)
 
212
         return Tag.Scan(d->Start, d->End - d->Start);
 
213
      else
 
214
         return Step(Tag);
211
215
   }
212
216
 
213
217
   // Reposition and reload..
259
263
   TagCount = 0;
260
264
   while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
261
265
   {
262
 
       TrimRecord(true,End);
 
266
      TrimRecord(true,End);
 
267
 
 
268
      // this can happen when TrimRecord trims away the entire Record
 
269
      // (e.g. because it just contains comments)
 
270
      if(Stop == End)
 
271
         return true;
263
272
 
264
273
      // Start a new index and add it to the hash
265
274
      if (isspace(Stop[0]) == 0)
273
282
      if (Stop == 0)
274
283
         return false;
275
284
 
276
 
      for (; Stop+1 < End && Stop[1] == '\r'; Stop++);
 
285
      for (; Stop+1 < End && Stop[1] == '\r'; Stop++)
 
286
         /* nothing */
 
287
         ;
277
288
 
278
289
      // Double newline marks the end of the record
279
290
      if (Stop+1 < End && Stop[1] == '\n')
560
571
   }
561
572
   
562
573
   // Write all all of the tags, in order.
563
 
   for (unsigned int I = 0; Order[I] != 0; I++)
 
574
   if (Order != NULL)
564
575
   {
565
 
      bool Rewritten = false;
566
 
      
567
 
      // See if this is a field that needs to be rewritten
568
 
      for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
 
576
      for (unsigned int I = 0; Order[I] != 0; I++)
569
577
      {
570
 
         if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0)
571
 
         {
572
 
            Visited[J] |= 2;
573
 
            if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
574
 
            {
575
 
               if (isspace(Rewrite[J].Rewrite[0]))
576
 
                  fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
577
 
               else
578
 
                  fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
579
 
            }
580
 
            
581
 
            Rewritten = true;
582
 
            break;
583
 
         }
584
 
      }      
585
 
            
586
 
      // See if it is in the fragment
587
 
      unsigned Pos;
588
 
      if (Tags.Find(Order[I],Pos) == false)
589
 
         continue;
590
 
      Visited[Pos] |= 1;
 
578
         bool Rewritten = false;
 
579
         
 
580
         // See if this is a field that needs to be rewritten
 
581
         for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
 
582
         {
 
583
            if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0)
 
584
            {
 
585
               Visited[J] |= 2;
 
586
               if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
 
587
               {
 
588
                  if (isspace(Rewrite[J].Rewrite[0]))
 
589
                     fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
 
590
                  else
 
591
                     fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
 
592
               }
 
593
               Rewritten = true;
 
594
               break;
 
595
            }
 
596
         }
 
597
            
 
598
         // See if it is in the fragment
 
599
         unsigned Pos;
 
600
         if (Tags.Find(Order[I],Pos) == false)
 
601
            continue;
 
602
         Visited[Pos] |= 1;
591
603
 
592
 
      if (Rewritten == true)
593
 
         continue;
594
 
      
595
 
      /* Write out this element, taking a moment to rewrite the tag
596
 
         in case of changes of case. */
597
 
      const char *Start;
598
 
      const char *Stop;
599
 
      Tags.Get(Start,Stop,Pos);
600
 
      
601
 
      if (fputs(Order[I],Output) < 0)
602
 
         return _error->Errno("fputs","IO Error to output");
603
 
      Start += strlen(Order[I]);
604
 
      if (fwrite(Start,Stop - Start,1,Output) != 1)
605
 
         return _error->Errno("fwrite","IO Error to output");
606
 
      if (Stop[-1] != '\n')
607
 
         fprintf(Output,"\n");
608
 
   }   
 
604
         if (Rewritten == true)
 
605
            continue;
 
606
      
 
607
         /* Write out this element, taking a moment to rewrite the tag
 
608
            in case of changes of case. */
 
609
         const char *Start;
 
610
         const char *Stop;
 
611
         Tags.Get(Start,Stop,Pos);
 
612
      
 
613
         if (fputs(Order[I],Output) < 0)
 
614
            return _error->Errno("fputs","IO Error to output");
 
615
         Start += strlen(Order[I]);
 
616
         if (fwrite(Start,Stop - Start,1,Output) != 1)
 
617
            return _error->Errno("fwrite","IO Error to output");
 
618
         if (Stop[-1] != '\n')
 
619
            fprintf(Output,"\n");
 
620
      }
 
621
   }
609
622
 
610
623
   // Now write all the old tags that were missed.
611
624
   for (unsigned int I = 0; I != Tags.Count(); I++)