tagfile.cc 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: tagfile.cc,v 1.37.2.2 2003/12/31 16:02:30 mdz Exp $
  4. /* ######################################################################
  5. Fast scanner for RFC-822 type header information
  6. This uses a rotating buffer to load the package information into.
  7. The scanner runs over it and isolates and indexes a single section.
  8. ##################################################################### */
  9. /*}}}*/
  10. // Include Files /*{{{*/
  11. #include<config.h>
  12. #include <apt-pkg/tagfile.h>
  13. #include <apt-pkg/error.h>
  14. #include <apt-pkg/strutl.h>
  15. #include <apt-pkg/fileutl.h>
  16. #include <string>
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <apti18n.h>
  22. /*}}}*/
  23. using std::string;
  24. class pkgTagFilePrivate
  25. {
  26. public:
  27. pkgTagFilePrivate(FileFd *pFd, unsigned long long Size) : Fd(*pFd), Buffer(NULL),
  28. Start(NULL), End(NULL),
  29. Done(false), iOffset(0),
  30. Size(Size)
  31. {
  32. }
  33. FileFd &Fd;
  34. char *Buffer;
  35. char *Start;
  36. char *End;
  37. bool Done;
  38. unsigned long long iOffset;
  39. unsigned long long Size;
  40. };
  41. // TagFile::pkgTagFile - Constructor /*{{{*/
  42. // ---------------------------------------------------------------------
  43. /* */
  44. pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long long Size)
  45. : d(NULL)
  46. {
  47. Init(pFd, Size);
  48. }
  49. void pkgTagFile::Init(FileFd *pFd,unsigned long long Size)
  50. {
  51. /* The size is increased by 4 because if we start with the Size of the
  52. filename we need to try to read 1 char more to see an EOF faster, 1
  53. char the end-pointer can be on and maybe 2 newlines need to be added
  54. to the end of the file -> 4 extra chars */
  55. Size += 4;
  56. if(d != NULL)
  57. {
  58. free(d->Buffer);
  59. delete d;
  60. }
  61. d = new pkgTagFilePrivate(pFd, Size);
  62. if (d->Fd.IsOpen() == false)
  63. d->Start = d->End = d->Buffer = 0;
  64. else
  65. d->Buffer = (char*)malloc(sizeof(char) * Size);
  66. if (d->Buffer == NULL)
  67. d->Done = true;
  68. else
  69. d->Done = false;
  70. d->Start = d->End = d->Buffer;
  71. d->iOffset = 0;
  72. if (d->Done == false)
  73. Fill();
  74. }
  75. /*}}}*/
  76. // TagFile::~pkgTagFile - Destructor /*{{{*/
  77. // ---------------------------------------------------------------------
  78. /* */
  79. pkgTagFile::~pkgTagFile()
  80. {
  81. free(d->Buffer);
  82. delete d;
  83. }
  84. /*}}}*/
  85. // TagFile::Offset - Return the current offset in the buffer /*{{{*/
  86. APT_PURE unsigned long pkgTagFile::Offset()
  87. {
  88. return d->iOffset;
  89. }
  90. /*}}}*/
  91. // TagFile::Resize - Resize the internal buffer /*{{{*/
  92. // ---------------------------------------------------------------------
  93. /* Resize the internal buffer (double it in size). Fail if a maximum size
  94. * size is reached.
  95. */
  96. bool pkgTagFile::Resize()
  97. {
  98. // fail is the buffer grows too big
  99. if(d->Size > 1024*1024+1)
  100. return false;
  101. return Resize(d->Size * 2);
  102. }
  103. bool pkgTagFile::Resize(unsigned long long const newSize)
  104. {
  105. unsigned long long const EndSize = d->End - d->Start;
  106. // get new buffer and use it
  107. char* newBuffer = (char*)realloc(d->Buffer, sizeof(char) * newSize);
  108. if (newBuffer == NULL)
  109. return false;
  110. d->Buffer = newBuffer;
  111. d->Size = newSize;
  112. // update the start/end pointers to the new buffer
  113. d->Start = d->Buffer;
  114. d->End = d->Start + EndSize;
  115. return true;
  116. }
  117. /*}}}*/
  118. // TagFile::Step - Advance to the next section /*{{{*/
  119. // ---------------------------------------------------------------------
  120. /* If the Section Scanner fails we refill the buffer and try again.
  121. * If that fails too, double the buffer size and try again until a
  122. * maximum buffer is reached.
  123. */
  124. bool pkgTagFile::Step(pkgTagSection &Tag)
  125. {
  126. while (Tag.Scan(d->Start,d->End - d->Start) == false)
  127. {
  128. if (Fill() == false)
  129. return false;
  130. if(Tag.Scan(d->Start,d->End - d->Start))
  131. break;
  132. if (Resize() == false)
  133. return _error->Error(_("Unable to parse package file %s (1)"),
  134. d->Fd.Name().c_str());
  135. }
  136. d->Start += Tag.size();
  137. d->iOffset += Tag.size();
  138. Tag.Trim();
  139. return true;
  140. }
  141. /*}}}*/
  142. // TagFile::Fill - Top up the buffer /*{{{*/
  143. // ---------------------------------------------------------------------
  144. /* This takes the bit at the end of the buffer and puts it at the start
  145. then fills the rest from the file */
  146. bool pkgTagFile::Fill()
  147. {
  148. unsigned long long EndSize = d->End - d->Start;
  149. unsigned long long Actual = 0;
  150. memmove(d->Buffer,d->Start,EndSize);
  151. d->Start = d->Buffer;
  152. d->End = d->Buffer + EndSize;
  153. if (d->Done == false)
  154. {
  155. // See if only a bit of the file is left
  156. unsigned long long const dataSize = d->Size - ((d->End - d->Buffer) + 1);
  157. if (d->Fd.Read(d->End, dataSize, &Actual) == false)
  158. return false;
  159. if (Actual != dataSize)
  160. d->Done = true;
  161. d->End += Actual;
  162. }
  163. if (d->Done == true)
  164. {
  165. if (EndSize <= 3 && Actual == 0)
  166. return false;
  167. if (d->Size - (d->End - d->Buffer) < 4)
  168. return true;
  169. // Append a double new line if one does not exist
  170. unsigned int LineCount = 0;
  171. for (const char *E = d->End - 1; E - d->End < 6 && (*E == '\n' || *E == '\r'); E--)
  172. if (*E == '\n')
  173. LineCount++;
  174. if (LineCount < 2)
  175. {
  176. if ((unsigned)(d->End - d->Buffer) >= d->Size)
  177. Resize(d->Size + 3);
  178. for (; LineCount < 2; LineCount++)
  179. *d->End++ = '\n';
  180. }
  181. return true;
  182. }
  183. return true;
  184. }
  185. /*}}}*/
  186. // TagFile::Jump - Jump to a pre-recorded location in the file /*{{{*/
  187. // ---------------------------------------------------------------------
  188. /* This jumps to a pre-recorded file location and reads the record
  189. that is there */
  190. bool pkgTagFile::Jump(pkgTagSection &Tag,unsigned long long Offset)
  191. {
  192. // We are within a buffer space of the next hit..
  193. if (Offset >= d->iOffset && d->iOffset + (d->End - d->Start) > Offset)
  194. {
  195. unsigned long long Dist = Offset - d->iOffset;
  196. d->Start += Dist;
  197. d->iOffset += Dist;
  198. // if we have seen the end, don't ask for more
  199. if (d->Done == true)
  200. return Tag.Scan(d->Start, d->End - d->Start);
  201. else
  202. return Step(Tag);
  203. }
  204. // Reposition and reload..
  205. d->iOffset = Offset;
  206. d->Done = false;
  207. if (d->Fd.Seek(Offset) == false)
  208. return false;
  209. d->End = d->Start = d->Buffer;
  210. if (Fill() == false)
  211. return false;
  212. if (Tag.Scan(d->Start, d->End - d->Start) == true)
  213. return true;
  214. // This appends a double new line (for the real eof handling)
  215. if (Fill() == false)
  216. return false;
  217. if (Tag.Scan(d->Start, d->End - d->Start) == false)
  218. return _error->Error(_("Unable to parse package file %s (2)"),d->Fd.Name().c_str());
  219. return true;
  220. }
  221. /*}}}*/
  222. // pkgTagSection::pkgTagSection - Constructor /*{{{*/
  223. // ---------------------------------------------------------------------
  224. /* */
  225. pkgTagSection::pkgTagSection()
  226. : Section(0), TagCount(0), d(NULL), Stop(0)
  227. {
  228. memset(&Indexes, 0, sizeof(Indexes));
  229. memset(&AlphaIndexes, 0, sizeof(AlphaIndexes));
  230. }
  231. /*}}}*/
  232. // TagSection::Scan - Scan for the end of the header information /*{{{*/
  233. // ---------------------------------------------------------------------
  234. /* This looks for the first double new line in the data stream.
  235. It also indexes the tags in the section. */
  236. bool pkgTagSection::Scan(const char *Start,unsigned long MaxLength)
  237. {
  238. const char *End = Start + MaxLength;
  239. Stop = Section = Start;
  240. memset(AlphaIndexes,0,sizeof(AlphaIndexes));
  241. if (Stop == 0)
  242. return false;
  243. TagCount = 0;
  244. while (TagCount+1 < sizeof(Indexes)/sizeof(Indexes[0]) && Stop < End)
  245. {
  246. TrimRecord(true,End);
  247. // this can happen when TrimRecord trims away the entire Record
  248. // (e.g. because it just contains comments)
  249. if(Stop == End)
  250. return true;
  251. // Start a new index and add it to the hash
  252. if (isspace(Stop[0]) == 0)
  253. {
  254. Indexes[TagCount++] = Stop - Section;
  255. AlphaIndexes[AlphaHash(Stop,End)] = TagCount;
  256. }
  257. Stop = (const char *)memchr(Stop,'\n',End - Stop);
  258. if (Stop == 0)
  259. return false;
  260. for (; Stop+1 < End && Stop[1] == '\r'; Stop++)
  261. /* nothing */
  262. ;
  263. // Double newline marks the end of the record
  264. if (Stop+1 < End && Stop[1] == '\n')
  265. {
  266. Indexes[TagCount] = Stop - Section;
  267. TrimRecord(false,End);
  268. return true;
  269. }
  270. Stop++;
  271. }
  272. return false;
  273. }
  274. /*}}}*/
  275. // TagSection::TrimRecord - Trim off any garbage before/after a record /*{{{*/
  276. // ---------------------------------------------------------------------
  277. /* There should be exactly 2 newline at the end of the record, no more. */
  278. void pkgTagSection::TrimRecord(bool BeforeRecord, const char*& End)
  279. {
  280. if (BeforeRecord == true)
  281. return;
  282. for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r'); Stop++);
  283. }
  284. /*}}}*/
  285. // TagSection::Trim - Trim off any trailing garbage /*{{{*/
  286. // ---------------------------------------------------------------------
  287. /* There should be exactly 1 newline at the end of the buffer, no more. */
  288. void pkgTagSection::Trim()
  289. {
  290. for (; Stop > Section + 2 && (Stop[-2] == '\n' || Stop[-2] == '\r'); Stop--);
  291. }
  292. /*}}}*/
  293. // TagSection::Exists - return True if a tag exists /*{{{*/
  294. bool pkgTagSection::Exists(const char* const Tag)
  295. {
  296. unsigned int tmp;
  297. return Find(Tag, tmp);
  298. }
  299. /*}}}*/
  300. // TagSection::Find - Locate a tag /*{{{*/
  301. // ---------------------------------------------------------------------
  302. /* This searches the section for a tag that matches the given string. */
  303. bool pkgTagSection::Find(const char *Tag,unsigned int &Pos) const
  304. {
  305. unsigned int Length = strlen(Tag);
  306. unsigned int I = AlphaIndexes[AlphaHash(Tag)];
  307. if (I == 0)
  308. return false;
  309. I--;
  310. for (unsigned int Counter = 0; Counter != TagCount; Counter++,
  311. I = (I+1)%TagCount)
  312. {
  313. const char *St;
  314. St = Section + Indexes[I];
  315. if (strncasecmp(Tag,St,Length) != 0)
  316. continue;
  317. // Make sure the colon is in the right place
  318. const char *C = St + Length;
  319. for (; isspace(*C) != 0; C++);
  320. if (*C != ':')
  321. continue;
  322. Pos = I;
  323. return true;
  324. }
  325. Pos = 0;
  326. return false;
  327. }
  328. /*}}}*/
  329. // TagSection::Find - Locate a tag /*{{{*/
  330. // ---------------------------------------------------------------------
  331. /* This searches the section for a tag that matches the given string. */
  332. bool pkgTagSection::Find(const char *Tag,const char *&Start,
  333. const char *&End) const
  334. {
  335. unsigned int Length = strlen(Tag);
  336. unsigned int I = AlphaIndexes[AlphaHash(Tag)];
  337. if (I == 0)
  338. return false;
  339. I--;
  340. for (unsigned int Counter = 0; Counter != TagCount; Counter++,
  341. I = (I+1)%TagCount)
  342. {
  343. const char *St;
  344. St = Section + Indexes[I];
  345. if (strncasecmp(Tag,St,Length) != 0)
  346. continue;
  347. // Make sure the colon is in the right place
  348. const char *C = St + Length;
  349. for (; isspace(*C) != 0; C++);
  350. if (*C != ':')
  351. continue;
  352. // Strip off the gunk from the start end
  353. Start = C;
  354. End = Section + Indexes[I+1];
  355. if (Start >= End)
  356. return _error->Error("Internal parsing error");
  357. for (; (isspace(*Start) != 0 || *Start == ':') && Start < End; Start++);
  358. for (; isspace(End[-1]) != 0 && End > Start; End--);
  359. return true;
  360. }
  361. Start = End = 0;
  362. return false;
  363. }
  364. /*}}}*/
  365. // TagSection::FindS - Find a string /*{{{*/
  366. // ---------------------------------------------------------------------
  367. /* */
  368. string pkgTagSection::FindS(const char *Tag) const
  369. {
  370. const char *Start;
  371. const char *End;
  372. if (Find(Tag,Start,End) == false)
  373. return string();
  374. return string(Start,End);
  375. }
  376. /*}}}*/
  377. // TagSection::FindI - Find an integer /*{{{*/
  378. // ---------------------------------------------------------------------
  379. /* */
  380. signed int pkgTagSection::FindI(const char *Tag,signed long Default) const
  381. {
  382. const char *Start;
  383. const char *Stop;
  384. if (Find(Tag,Start,Stop) == false)
  385. return Default;
  386. // Copy it into a temp buffer so we can use strtol
  387. char S[300];
  388. if ((unsigned)(Stop - Start) >= sizeof(S))
  389. return Default;
  390. strncpy(S,Start,Stop-Start);
  391. S[Stop - Start] = 0;
  392. char *End;
  393. signed long Result = strtol(S,&End,10);
  394. if (S == End)
  395. return Default;
  396. return Result;
  397. }
  398. /*}}}*/
  399. // TagSection::FindULL - Find an unsigned long long integer /*{{{*/
  400. // ---------------------------------------------------------------------
  401. /* */
  402. unsigned long long pkgTagSection::FindULL(const char *Tag, unsigned long long const &Default) const
  403. {
  404. const char *Start;
  405. const char *Stop;
  406. if (Find(Tag,Start,Stop) == false)
  407. return Default;
  408. // Copy it into a temp buffer so we can use strtoull
  409. char S[100];
  410. if ((unsigned)(Stop - Start) >= sizeof(S))
  411. return Default;
  412. strncpy(S,Start,Stop-Start);
  413. S[Stop - Start] = 0;
  414. char *End;
  415. unsigned long long Result = strtoull(S,&End,10);
  416. if (S == End)
  417. return Default;
  418. return Result;
  419. }
  420. /*}}}*/
  421. // TagSection::FindFlag - Locate a yes/no type flag /*{{{*/
  422. // ---------------------------------------------------------------------
  423. /* The bits marked in Flag are masked on/off in Flags */
  424. bool pkgTagSection::FindFlag(const char *Tag,unsigned long &Flags,
  425. unsigned long Flag) const
  426. {
  427. const char *Start;
  428. const char *Stop;
  429. if (Find(Tag,Start,Stop) == false)
  430. return true;
  431. return FindFlag(Flags, Flag, Start, Stop);
  432. }
  433. bool pkgTagSection::FindFlag(unsigned long &Flags, unsigned long Flag,
  434. char const* Start, char const* Stop)
  435. {
  436. switch (StringToBool(string(Start, Stop)))
  437. {
  438. case 0:
  439. Flags &= ~Flag;
  440. return true;
  441. case 1:
  442. Flags |= Flag;
  443. return true;
  444. default:
  445. _error->Warning("Unknown flag value: %s",string(Start,Stop).c_str());
  446. return true;
  447. }
  448. return true;
  449. }
  450. /*}}}*/
  451. // TFRewrite - Rewrite a control record /*{{{*/
  452. // ---------------------------------------------------------------------
  453. /* This writes the control record to stdout rewriting it as necessary. The
  454. override map item specificies the rewriting rules to follow. This also
  455. takes the time to sort the feild list. */
  456. /* The order of this list is taken from dpkg source lib/parse.c the fieldinfos
  457. array. */
  458. static const char *iTFRewritePackageOrder[] = {
  459. "Package",
  460. "Essential",
  461. "Status",
  462. "Priority",
  463. "Section",
  464. "Installed-Size",
  465. "Maintainer",
  466. "Original-Maintainer",
  467. "Architecture",
  468. "Source",
  469. "Version",
  470. "Revision", // Obsolete
  471. "Config-Version", // Obsolete
  472. "Replaces",
  473. "Provides",
  474. "Depends",
  475. "Pre-Depends",
  476. "Recommends",
  477. "Suggests",
  478. "Conflicts",
  479. "Breaks",
  480. "Conffiles",
  481. "Filename",
  482. "Size",
  483. "MD5Sum",
  484. "SHA1",
  485. "SHA256",
  486. "SHA512",
  487. "MSDOS-Filename", // Obsolete
  488. "Description",
  489. 0};
  490. static const char *iTFRewriteSourceOrder[] = {"Package",
  491. "Source",
  492. "Binary",
  493. "Version",
  494. "Priority",
  495. "Section",
  496. "Maintainer",
  497. "Original-Maintainer",
  498. "Build-Depends",
  499. "Build-Depends-Indep",
  500. "Build-Conflicts",
  501. "Build-Conflicts-Indep",
  502. "Architecture",
  503. "Standards-Version",
  504. "Format",
  505. "Directory",
  506. "Files",
  507. 0};
  508. /* Two levels of initialization are used because gcc will set the symbol
  509. size of an array to the length of the array, causing dynamic relinking
  510. errors. Doing this makes the symbol size constant */
  511. const char **TFRewritePackageOrder = iTFRewritePackageOrder;
  512. const char **TFRewriteSourceOrder = iTFRewriteSourceOrder;
  513. bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[],
  514. TFRewriteData *Rewrite)
  515. {
  516. unsigned char Visited[256]; // Bit 1 is Order, Bit 2 is Rewrite
  517. for (unsigned I = 0; I != 256; I++)
  518. Visited[I] = 0;
  519. // Set new tag up as necessary.
  520. for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
  521. {
  522. if (Rewrite[J].NewTag == 0)
  523. Rewrite[J].NewTag = Rewrite[J].Tag;
  524. }
  525. // Write all all of the tags, in order.
  526. if (Order != NULL)
  527. {
  528. for (unsigned int I = 0; Order[I] != 0; I++)
  529. {
  530. bool Rewritten = false;
  531. // See if this is a field that needs to be rewritten
  532. for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
  533. {
  534. if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0)
  535. {
  536. Visited[J] |= 2;
  537. if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
  538. {
  539. if (isspace(Rewrite[J].Rewrite[0]))
  540. fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
  541. else
  542. fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
  543. }
  544. Rewritten = true;
  545. break;
  546. }
  547. }
  548. // See if it is in the fragment
  549. unsigned Pos;
  550. if (Tags.Find(Order[I],Pos) == false)
  551. continue;
  552. Visited[Pos] |= 1;
  553. if (Rewritten == true)
  554. continue;
  555. /* Write out this element, taking a moment to rewrite the tag
  556. in case of changes of case. */
  557. const char *Start;
  558. const char *Stop;
  559. Tags.Get(Start,Stop,Pos);
  560. if (fputs(Order[I],Output) < 0)
  561. return _error->Errno("fputs","IO Error to output");
  562. Start += strlen(Order[I]);
  563. if (fwrite(Start,Stop - Start,1,Output) != 1)
  564. return _error->Errno("fwrite","IO Error to output");
  565. if (Stop[-1] != '\n')
  566. fprintf(Output,"\n");
  567. }
  568. }
  569. // Now write all the old tags that were missed.
  570. for (unsigned int I = 0; I != Tags.Count(); I++)
  571. {
  572. if ((Visited[I] & 1) == 1)
  573. continue;
  574. const char *Start;
  575. const char *Stop;
  576. Tags.Get(Start,Stop,I);
  577. const char *End = Start;
  578. for (; End < Stop && *End != ':'; End++);
  579. // See if this is a field that needs to be rewritten
  580. bool Rewritten = false;
  581. for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
  582. {
  583. if (stringcasecmp(Start,End,Rewrite[J].Tag) == 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. if (Rewritten == true)
  598. continue;
  599. // Write out this element
  600. if (fwrite(Start,Stop - Start,1,Output) != 1)
  601. return _error->Errno("fwrite","IO Error to output");
  602. if (Stop[-1] != '\n')
  603. fprintf(Output,"\n");
  604. }
  605. // Now write all the rewrites that were missed
  606. for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++)
  607. {
  608. if ((Visited[J] & 2) == 2)
  609. continue;
  610. if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0)
  611. {
  612. if (isspace(Rewrite[J].Rewrite[0]))
  613. fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
  614. else
  615. fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite);
  616. }
  617. }
  618. return true;
  619. }
  620. /*}}}*/