~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Support/SlowOperationInformer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===-- SlowOperationInformer.cpp - Keep the user informed ----------------===//
 
2
//
 
3
//                     The LLVM Compiler Infrastructure
 
4
//
 
5
// This file is distributed under the University of Illinois Open Source
 
6
// License. See LICENSE.TXT for details.
 
7
//
 
8
//===----------------------------------------------------------------------===//
 
9
//
 
10
// This file implements the SlowOperationInformer class for the LLVM debugger.
 
11
//
 
12
//===----------------------------------------------------------------------===//
 
13
 
 
14
#include "llvm/Support/SlowOperationInformer.h"
 
15
#include "llvm/Support/raw_ostream.h"
 
16
#include "llvm/System/Alarm.h"
 
17
#include <sstream>
 
18
#include <cassert>
 
19
using namespace llvm;
 
20
 
 
21
SlowOperationInformer::SlowOperationInformer(const std::string &Name)
 
22
  : OperationName(Name), LastPrintAmount(0) {
 
23
  sys::SetupAlarm(1);
 
24
}
 
25
 
 
26
SlowOperationInformer::~SlowOperationInformer() {
 
27
  sys::TerminateAlarm();
 
28
  if (LastPrintAmount) {
 
29
    // If we have printed something, make _sure_ we print the 100% amount, and
 
30
    // also print a newline.
 
31
    outs() << std::string(LastPrintAmount, '\b') << "Progress "
 
32
           << OperationName << ": 100%  \n";
 
33
  }
 
34
}
 
35
 
 
36
/// progress - Clients should periodically call this method when they are in
 
37
/// an exception-safe state.  The Amount variable should indicate how far
 
38
/// along the operation is, given in 1/10ths of a percent (in other words,
 
39
/// Amount should range from 0 to 1000).
 
40
bool SlowOperationInformer::progress(unsigned Amount) {
 
41
  int status = sys::AlarmStatus();
 
42
  if (status == -1) {
 
43
    outs() << "\n";
 
44
    LastPrintAmount = 0;
 
45
    return true;
 
46
  }
 
47
 
 
48
  // If we haven't spent enough time in this operation to warrant displaying the
 
49
  // progress bar, don't do so yet.
 
50
  if (status == 0)
 
51
    return false;
 
52
 
 
53
  // Delete whatever we printed last time.
 
54
  std::string ToPrint = std::string(LastPrintAmount, '\b');
 
55
 
 
56
  std::ostringstream OS;
 
57
  OS << "Progress " << OperationName << ": " << Amount/10;
 
58
  if (unsigned Rem = Amount % 10)
 
59
    OS << "." << Rem << "%";
 
60
  else
 
61
    OS << "%  ";
 
62
 
 
63
  LastPrintAmount = OS.str().size();
 
64
  outs() << ToPrint+OS.str();
 
65
  outs().flush();
 
66
  return false;
 
67
}