1 //===- OptTable.cpp - Option Table Implementation -------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/ADT/STLExtras.h"
10 #include "llvm/ADT/StringRef.h"
11 #include "llvm/ADT/StringSet.h"
12 #include "llvm/Option/Arg.h"
13 #include "llvm/Option/ArgList.h"
14 #include "llvm/Option/Option.h"
15 #include "llvm/Option/OptSpecifier.h"
16 #include "llvm/Option/OptTable.h"
17 #include "llvm/Support/Compiler.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include <algorithm>
21 #include <cassert>
22 #include <cctype>
23 #include <cstring>
24 #include <map>
25 #include <string>
26 #include <utility>
27 #include <vector>
28 
29 using namespace llvm;
30 using namespace llvm::opt;
31 
32 namespace llvm {
33 namespace opt {
34 
35 // Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
36 // with an exception. '\0' comes at the end of the alphabet instead of the
37 // beginning (thus options precede any other options which prefix them).
38 static int StrCmpOptionNameIgnoreCase(const char *A, const char *B) {
39   const char *X = A, *Y = B;
40   char a = tolower(*A), b = tolower(*B);
41   while (a == b) {
42     if (a == '\0')
43       return 0;
44 
45     a = tolower(*++X);
46     b = tolower(*++Y);
47   }
48 
49   if (a == '\0') // A is a prefix of B.
50     return 1;
51   if (b == '\0') // B is a prefix of A.
52     return -1;
53 
54   // Otherwise lexicographic.
55   return (a < b) ? -1 : 1;
56 }
57 
58 #ifndef NDEBUG
59 static int StrCmpOptionName(const char *A, const char *B) {
60   if (int N = StrCmpOptionNameIgnoreCase(A, B))
61     return N;
62   return strcmp(A, B);
63 }
64 
65 static inline bool operator<(const OptTable::Info &A, const OptTable::Info &B) {
66   if (&A == &B)
67     return false;
68 
69   if (int N = StrCmpOptionName(A.Name, B.Name))
70     return N < 0;
71 
72   for (const char * const *APre = A.Prefixes,
73                   * const *BPre = B.Prefixes;
74                           *APre != nullptr && *BPre != nullptr; ++APre, ++BPre){
75     if (int N = StrCmpOptionName(*APre, *BPre))
76       return N < 0;
77   }
78 
79   // Names are the same, check that classes are in order; exactly one
80   // should be joined, and it should succeed the other.
81   assert(((A.Kind == Option::JoinedClass) ^ (B.Kind == Option::JoinedClass)) &&
82          "Unexpected classes for options with same name.");
83   return B.Kind == Option::JoinedClass;
84 }
85 #endif
86 
87 // Support lower_bound between info and an option name.
88 static inline bool operator<(const OptTable::Info &I, const char *Name) {
89   return StrCmpOptionNameIgnoreCase(I.Name, Name) < 0;
90 }
91 
92 } // end namespace opt
93 } // end namespace llvm
94 
95 OptSpecifier::OptSpecifier(const Option *Opt) : ID(Opt->getID()) {}
96 
97 OptTable::OptTable(ArrayRef<Info> OptionInfos, bool IgnoreCase)
98     : OptionInfos(OptionInfos), IgnoreCase(IgnoreCase) {
99   // Explicitly zero initialize the error to work around a bug in array
100   // value-initialization on MinGW with gcc 4.3.5.
101 
102   // Find start of normal options.
103   for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
104     unsigned Kind = getInfo(i + 1).Kind;
105     if (Kind == Option::InputClass) {
106       assert(!TheInputOptionID && "Cannot have multiple input options!");
107       TheInputOptionID = getInfo(i + 1).ID;
108     } else if (Kind == Option::UnknownClass) {
109       assert(!TheUnknownOptionID && "Cannot have multiple unknown options!");
110       TheUnknownOptionID = getInfo(i + 1).ID;
111     } else if (Kind != Option::GroupClass) {
112       FirstSearchableIndex = i;
113       break;
114     }
115   }
116   assert(FirstSearchableIndex != 0 && "No searchable options?");
117 
118 #ifndef NDEBUG
119   // Check that everything after the first searchable option is a
120   // regular option class.
121   for (unsigned i = FirstSearchableIndex, e = getNumOptions(); i != e; ++i) {
122     Option::OptionClass Kind = (Option::OptionClass) getInfo(i + 1).Kind;
123     assert((Kind != Option::InputClass && Kind != Option::UnknownClass &&
124             Kind != Option::GroupClass) &&
125            "Special options should be defined first!");
126   }
127 
128   // Check that options are in order.
129   for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions(); i != e; ++i){
130     if (!(getInfo(i) < getInfo(i + 1))) {
131       getOption(i).dump();
132       getOption(i + 1).dump();
133       llvm_unreachable("Options are not in order!");
134     }
135   }
136 #endif
137 
138   // Build prefixes.
139   for (unsigned i = FirstSearchableIndex + 1, e = getNumOptions() + 1;
140                 i != e; ++i) {
141     if (const char *const *P = getInfo(i).Prefixes) {
142       for (; *P != nullptr; ++P) {
143         PrefixesUnion.insert(*P);
144       }
145     }
146   }
147 
148   // Build prefix chars.
149   for (StringSet<>::const_iterator I = PrefixesUnion.begin(),
150                                    E = PrefixesUnion.end(); I != E; ++I) {
151     StringRef Prefix = I->getKey();
152     for (StringRef::const_iterator C = Prefix.begin(), CE = Prefix.end();
153                                    C != CE; ++C)
154       if (!is_contained(PrefixChars, *C))
155         PrefixChars.push_back(*C);
156   }
157 }
158 
159 OptTable::~OptTable() = default;
160 
161 const Option OptTable::getOption(OptSpecifier Opt) const {
162   unsigned id = Opt.getID();
163   if (id == 0)
164     return Option(nullptr, nullptr);
165   assert((unsigned) (id - 1) < getNumOptions() && "Invalid ID.");
166   return Option(&getInfo(id), this);
167 }
168 
169 static bool isInput(const StringSet<> &Prefixes, StringRef Arg) {
170   if (Arg == "-")
171     return true;
172   for (StringSet<>::const_iterator I = Prefixes.begin(),
173                                    E = Prefixes.end(); I != E; ++I)
174     if (Arg.startswith(I->getKey()))
175       return false;
176   return true;
177 }
178 
179 /// \returns Matched size. 0 means no match.
180 static unsigned matchOption(const OptTable::Info *I, StringRef Str,
181                             bool IgnoreCase) {
182   for (const char * const *Pre = I->Prefixes; *Pre != nullptr; ++Pre) {
183     StringRef Prefix(*Pre);
184     if (Str.startswith(Prefix)) {
185       StringRef Rest = Str.substr(Prefix.size());
186       bool Matched = IgnoreCase
187           ? Rest.startswith_lower(I->Name)
188           : Rest.startswith(I->Name);
189       if (Matched)
190         return Prefix.size() + StringRef(I->Name).size();
191     }
192   }
193   return 0;
194 }
195 
196 // Returns true if one of the Prefixes + In.Names matches Option
197 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
198   if (In.Prefixes)
199     for (size_t I = 0; In.Prefixes[I]; I++)
200       if (Option == std::string(In.Prefixes[I]) + In.Name)
201         return true;
202   return false;
203 }
204 
205 // This function is for flag value completion.
206 // Eg. When "-stdlib=" and "l" was passed to this function, it will return
207 // appropiriate values for stdlib, which starts with l.
208 std::vector<std::string>
209 OptTable::suggestValueCompletions(StringRef Option, StringRef Arg) const {
210   // Search all options and return possible values.
211   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
212     const Info &In = OptionInfos[I];
213     if (!In.Values || !optionMatches(In, Option))
214       continue;
215 
216     SmallVector<StringRef, 8> Candidates;
217     StringRef(In.Values).split(Candidates, ",", -1, false);
218 
219     std::vector<std::string> Result;
220     for (StringRef Val : Candidates)
221       if (Val.startswith(Arg) && Arg.compare(Val))
222         Result.push_back(std::string(Val));
223     return Result;
224   }
225   return {};
226 }
227 
228 std::vector<std::string>
229 OptTable::findByPrefix(StringRef Cur, unsigned short DisableFlags) const {
230   std::vector<std::string> Ret;
231   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
232     const Info &In = OptionInfos[I];
233     if (!In.Prefixes || (!In.HelpText && !In.GroupID))
234       continue;
235     if (In.Flags & DisableFlags)
236       continue;
237 
238     for (int I = 0; In.Prefixes[I]; I++) {
239       std::string S = std::string(In.Prefixes[I]) + std::string(In.Name) + "\t";
240       if (In.HelpText)
241         S += In.HelpText;
242       if (StringRef(S).startswith(Cur) && S.compare(std::string(Cur) + "\t"))
243         Ret.push_back(S);
244     }
245   }
246   return Ret;
247 }
248 
249 unsigned OptTable::findNearest(StringRef Option, std::string &NearestString,
250                                unsigned FlagsToInclude, unsigned FlagsToExclude,
251                                unsigned MinimumLength) const {
252   assert(!Option.empty());
253 
254   // Consider each [option prefix + option name] pair as a candidate, finding
255   // the closest match.
256   unsigned BestDistance = UINT_MAX;
257   for (const Info &CandidateInfo :
258        ArrayRef<Info>(OptionInfos).drop_front(FirstSearchableIndex)) {
259     StringRef CandidateName = CandidateInfo.Name;
260 
261     // We can eliminate some option prefix/name pairs as candidates right away:
262     // * Ignore option candidates with empty names, such as "--", or names
263     //   that do not meet the minimum length.
264     if (CandidateName.empty() || CandidateName.size() < MinimumLength)
265       continue;
266 
267     // * If FlagsToInclude were specified, ignore options that don't include
268     //   those flags.
269     if (FlagsToInclude && !(CandidateInfo.Flags & FlagsToInclude))
270       continue;
271     // * Ignore options that contain the FlagsToExclude.
272     if (CandidateInfo.Flags & FlagsToExclude)
273       continue;
274 
275     // * Ignore positional argument option candidates (which do not
276     //   have prefixes).
277     if (!CandidateInfo.Prefixes)
278       continue;
279 
280     // Now check if the candidate ends with a character commonly used when
281     // delimiting an option from its value, such as '=' or ':'. If it does,
282     // attempt to split the given option based on that delimiter.
283     StringRef LHS, RHS;
284     char Last = CandidateName.back();
285     bool CandidateHasDelimiter = Last == '=' || Last == ':';
286     std::string NormalizedName = std::string(Option);
287     if (CandidateHasDelimiter) {
288       std::tie(LHS, RHS) = Option.split(Last);
289       NormalizedName = std::string(LHS);
290       if (Option.find(Last) == LHS.size())
291         NormalizedName += Last;
292     }
293 
294     // Consider each possible prefix for each candidate to find the most
295     // appropriate one. For example, if a user asks for "--helm", suggest
296     // "--help" over "-help".
297     for (int P = 0;
298          const char *const CandidatePrefix = CandidateInfo.Prefixes[P]; P++) {
299       std::string Candidate = (CandidatePrefix + CandidateName).str();
300       StringRef CandidateRef = Candidate;
301       unsigned Distance =
302           CandidateRef.edit_distance(NormalizedName, /*AllowReplacements=*/true,
303                                      /*MaxEditDistance=*/BestDistance);
304       if (RHS.empty() && CandidateHasDelimiter) {
305         // The Candidate ends with a = or : delimiter, but the option passed in
306         // didn't contain the delimiter (or doesn't have anything after it).
307         // In that case, penalize the correction: `-nodefaultlibs` is more
308         // likely to be a spello for `-nodefaultlib` than `-nodefaultlib:` even
309         // though both have an unmodified editing distance of 1, since the
310         // latter would need an argument.
311         ++Distance;
312       }
313       if (Distance < BestDistance) {
314         BestDistance = Distance;
315         NearestString = (Candidate + RHS).str();
316       }
317     }
318   }
319   return BestDistance;
320 }
321 
322 bool OptTable::addValues(const char *Option, const char *Values) {
323   for (size_t I = FirstSearchableIndex, E = OptionInfos.size(); I < E; I++) {
324     Info &In = OptionInfos[I];
325     if (optionMatches(In, Option)) {
326       In.Values = Values;
327       return true;
328     }
329   }
330   return false;
331 }
332 
333 // Parse a single argument, return the new argument, and update Index. If
334 // GroupedShortOptions is true, -a matches "-abc" and the argument in Args will
335 // be updated to "-bc". This overload does not support
336 // FlagsToInclude/FlagsToExclude or case insensitive options.
337 Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
338   // Anything that doesn't start with PrefixesUnion is an input, as is '-'
339   // itself.
340   const char *CStr = Args.getArgString(Index);
341   StringRef Str(CStr);
342   if (isInput(PrefixesUnion, Str))
343     return new Arg(getOption(TheInputOptionID), Str, Index++, CStr);
344 
345   const Info *End = OptionInfos.data() + OptionInfos.size();
346   StringRef Name = Str.ltrim(PrefixChars);
347   const Info *Start = std::lower_bound(
348       OptionInfos.data() + FirstSearchableIndex, End, Name.data());
349   const Info *Fallback = nullptr;
350   unsigned Prev = Index;
351 
352   // Search for the option which matches Str.
353   for (; Start != End; ++Start) {
354     unsigned ArgSize = matchOption(Start, Str, IgnoreCase);
355     if (!ArgSize)
356       continue;
357 
358     Option Opt(Start, this);
359     if (Arg *A = Opt.accept(Args, StringRef(Args.getArgString(Index), ArgSize),
360                             false, Index))
361       return A;
362 
363     // If Opt is a Flag of length 2 (e.g. "-a"), we know it is a prefix of
364     // the current argument (e.g. "-abc"). Match it as a fallback if no longer
365     // option (e.g. "-ab") exists.
366     if (ArgSize == 2 && Opt.getKind() == Option::FlagClass)
367       Fallback = Start;
368 
369     // Otherwise, see if the argument is missing.
370     if (Prev != Index)
371       return nullptr;
372   }
373   if (Fallback) {
374     Option Opt(Fallback, this);
375     if (Arg *A = Opt.accept(Args, Str.substr(0, 2), true, Index)) {
376       if (Str.size() == 2)
377         ++Index;
378       else
379         Args.replaceArgString(Index, Twine('-') + Str.substr(2));
380       return A;
381     }
382   }
383 
384   return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
385 }
386 
387 Arg *OptTable::ParseOneArg(const ArgList &Args, unsigned &Index,
388                            unsigned FlagsToInclude,
389                            unsigned FlagsToExclude) const {
390   unsigned Prev = Index;
391   const char *Str = Args.getArgString(Index);
392 
393   // Anything that doesn't start with PrefixesUnion is an input, as is '-'
394   // itself.
395   if (isInput(PrefixesUnion, Str))
396     return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
397 
398   const Info *Start = OptionInfos.data() + FirstSearchableIndex;
399   const Info *End = OptionInfos.data() + OptionInfos.size();
400   StringRef Name = StringRef(Str).ltrim(PrefixChars);
401 
402   // Search for the first next option which could be a prefix.
403   Start = std::lower_bound(Start, End, Name.data());
404 
405   // Options are stored in sorted order, with '\0' at the end of the
406   // alphabet. Since the only options which can accept a string must
407   // prefix it, we iteratively search for the next option which could
408   // be a prefix.
409   //
410   // FIXME: This is searching much more than necessary, but I am
411   // blanking on the simplest way to make it fast. We can solve this
412   // problem when we move to TableGen.
413   for (; Start != End; ++Start) {
414     unsigned ArgSize = 0;
415     // Scan for first option which is a proper prefix.
416     for (; Start != End; ++Start)
417       if ((ArgSize = matchOption(Start, Str, IgnoreCase)))
418         break;
419     if (Start == End)
420       break;
421 
422     Option Opt(Start, this);
423 
424     if (FlagsToInclude && !Opt.hasFlag(FlagsToInclude))
425       continue;
426     if (Opt.hasFlag(FlagsToExclude))
427       continue;
428 
429     // See if this option matches.
430     if (Arg *A = Opt.accept(Args, StringRef(Args.getArgString(Index), ArgSize),
431                             false, Index))
432       return A;
433 
434     // Otherwise, see if this argument was missing values.
435     if (Prev != Index)
436       return nullptr;
437   }
438 
439   // If we failed to find an option and this arg started with /, then it's
440   // probably an input path.
441   if (Str[0] == '/')
442     return new Arg(getOption(TheInputOptionID), Str, Index++, Str);
443 
444   return new Arg(getOption(TheUnknownOptionID), Str, Index++, Str);
445 }
446 
447 InputArgList OptTable::ParseArgs(ArrayRef<const char *> ArgArr,
448                                  unsigned &MissingArgIndex,
449                                  unsigned &MissingArgCount,
450                                  unsigned FlagsToInclude,
451                                  unsigned FlagsToExclude) const {
452   InputArgList Args(ArgArr.begin(), ArgArr.end());
453 
454   // FIXME: Handle '@' args (or at least error on them).
455 
456   MissingArgIndex = MissingArgCount = 0;
457   unsigned Index = 0, End = ArgArr.size();
458   while (Index < End) {
459     // Ingore nullptrs, they are response file's EOL markers
460     if (Args.getArgString(Index) == nullptr) {
461       ++Index;
462       continue;
463     }
464     // Ignore empty arguments (other things may still take them as arguments).
465     StringRef Str = Args.getArgString(Index);
466     if (Str == "") {
467       ++Index;
468       continue;
469     }
470 
471     unsigned Prev = Index;
472     Arg *A = GroupedShortOptions
473                  ? parseOneArgGrouped(Args, Index)
474                  : ParseOneArg(Args, Index, FlagsToInclude, FlagsToExclude);
475     assert((Index > Prev || GroupedShortOptions) &&
476            "Parser failed to consume argument.");
477 
478     // Check for missing argument error.
479     if (!A) {
480       assert(Index >= End && "Unexpected parser error.");
481       assert(Index - Prev - 1 && "No missing arguments!");
482       MissingArgIndex = Prev;
483       MissingArgCount = Index - Prev - 1;
484       break;
485     }
486 
487     Args.append(A);
488   }
489 
490   return Args;
491 }
492 
493 static std::string getOptionHelpName(const OptTable &Opts, OptSpecifier Id) {
494   const Option O = Opts.getOption(Id);
495   std::string Name = O.getPrefixedName();
496 
497   // Add metavar, if used.
498   switch (O.getKind()) {
499   case Option::GroupClass: case Option::InputClass: case Option::UnknownClass:
500     llvm_unreachable("Invalid option with help text.");
501 
502   case Option::MultiArgClass:
503     if (const char *MetaVarName = Opts.getOptionMetaVar(Id)) {
504       // For MultiArgs, metavar is full list of all argument names.
505       Name += ' ';
506       Name += MetaVarName;
507     }
508     else {
509       // For MultiArgs<N>, if metavar not supplied, print <value> N times.
510       for (unsigned i=0, e=O.getNumArgs(); i< e; ++i) {
511         Name += " <value>";
512       }
513     }
514     break;
515 
516   case Option::FlagClass:
517     break;
518 
519   case Option::ValuesClass:
520     break;
521 
522   case Option::SeparateClass: case Option::JoinedOrSeparateClass:
523   case Option::RemainingArgsClass: case Option::RemainingArgsJoinedClass:
524     Name += ' ';
525     LLVM_FALLTHROUGH;
526   case Option::JoinedClass: case Option::CommaJoinedClass:
527   case Option::JoinedAndSeparateClass:
528     if (const char *MetaVarName = Opts.getOptionMetaVar(Id))
529       Name += MetaVarName;
530     else
531       Name += "<value>";
532     break;
533   }
534 
535   return Name;
536 }
537 
538 namespace {
539 struct OptionInfo {
540   std::string Name;
541   StringRef HelpText;
542 };
543 } // namespace
544 
545 static void PrintHelpOptionList(raw_ostream &OS, StringRef Title,
546                                 std::vector<OptionInfo> &OptionHelp) {
547   OS << Title << ":\n";
548 
549   // Find the maximum option length.
550   unsigned OptionFieldWidth = 0;
551   for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
552     // Limit the amount of padding we are willing to give up for alignment.
553     unsigned Length = OptionHelp[i].Name.size();
554     if (Length <= 23)
555       OptionFieldWidth = std::max(OptionFieldWidth, Length);
556   }
557 
558   const unsigned InitialPad = 2;
559   for (unsigned i = 0, e = OptionHelp.size(); i != e; ++i) {
560     const std::string &Option = OptionHelp[i].Name;
561     int Pad = OptionFieldWidth - int(Option.size());
562     OS.indent(InitialPad) << Option;
563 
564     // Break on long option names.
565     if (Pad < 0) {
566       OS << "\n";
567       Pad = OptionFieldWidth + InitialPad;
568     }
569     OS.indent(Pad + 1) << OptionHelp[i].HelpText << '\n';
570   }
571 }
572 
573 static const char *getOptionHelpGroup(const OptTable &Opts, OptSpecifier Id) {
574   unsigned GroupID = Opts.getOptionGroupID(Id);
575 
576   // If not in a group, return the default help group.
577   if (!GroupID)
578     return "OPTIONS";
579 
580   // Abuse the help text of the option groups to store the "help group"
581   // name.
582   //
583   // FIXME: Split out option groups.
584   if (const char *GroupHelp = Opts.getOptionHelpText(GroupID))
585     return GroupHelp;
586 
587   // Otherwise keep looking.
588   return getOptionHelpGroup(Opts, GroupID);
589 }
590 
591 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
592                          bool ShowHidden, bool ShowAllAliases) const {
593   PrintHelp(OS, Usage, Title, /*Include*/ 0, /*Exclude*/
594             (ShowHidden ? 0 : HelpHidden), ShowAllAliases);
595 }
596 
597 void OptTable::PrintHelp(raw_ostream &OS, const char *Usage, const char *Title,
598                          unsigned FlagsToInclude, unsigned FlagsToExclude,
599                          bool ShowAllAliases) const {
600   OS << "OVERVIEW: " << Title << "\n\n";
601   OS << "USAGE: " << Usage << "\n\n";
602 
603   // Render help text into a map of group-name to a list of (option, help)
604   // pairs.
605   std::map<std::string, std::vector<OptionInfo>> GroupedOptionHelp;
606 
607   for (unsigned Id = 1, e = getNumOptions() + 1; Id != e; ++Id) {
608     // FIXME: Split out option groups.
609     if (getOptionKind(Id) == Option::GroupClass)
610       continue;
611 
612     unsigned Flags = getInfo(Id).Flags;
613     if (FlagsToInclude && !(Flags & FlagsToInclude))
614       continue;
615     if (Flags & FlagsToExclude)
616       continue;
617 
618     // If an alias doesn't have a help text, show a help text for the aliased
619     // option instead.
620     const char *HelpText = getOptionHelpText(Id);
621     if (!HelpText && ShowAllAliases) {
622       const Option Alias = getOption(Id).getAlias();
623       if (Alias.isValid())
624         HelpText = getOptionHelpText(Alias.getID());
625     }
626 
627     if (HelpText) {
628       const char *HelpGroup = getOptionHelpGroup(*this, Id);
629       const std::string &OptName = getOptionHelpName(*this, Id);
630       GroupedOptionHelp[HelpGroup].push_back({OptName, HelpText});
631     }
632   }
633 
634   for (auto& OptionGroup : GroupedOptionHelp) {
635     if (OptionGroup.first != GroupedOptionHelp.begin()->first)
636       OS << "\n";
637     PrintHelpOptionList(OS, OptionGroup.first, OptionGroup.second);
638   }
639 
640   OS.flush();
641 }
642