コード例 #1
0
ファイル: bin2asc.c プロジェクト: rsmin/testfs
void main(int argc, char *argv[])
{
  int numrecs;

  if (argc < 2) 
  {
    fprintf(stderr,"Usage: %s binary-file ascii-file\n");
    exit(1);
  }

  binaryFile = fopen(argv[1],"r");
  if (binaryFile == NULL)
  {
    fprintf(stderr,"Unable to open input file '%s' for reading\n", argv[1]);
    exit(1);
  }

  asciiFile = fopen(argv[2],"w");
  if (asciiFile == NULL)
  {
    fprintf(stderr,"Unable to open output file '%s' for writing\n", argv[2]);
    exit(1);
  }

  numrecs = processHeader();
  processRecords(numrecs);

  fclose(asciiFile);
  fclose(binaryFile);
}
コード例 #2
0
ファイル: sample.cpp プロジェクト: mdsmus/humdrum
int main(int argc, char* argv[]) {
   HumdrumFile infile, outfile;

   // process the command-line options
   checkOptions(options, argc, argv);

   // figure out the number of input files to process
   int numinputs = options.getArgCount();

   for (int i=0; i<numinputs || i==0; i++) {
      infile.clear();
      outfile.clear();

      // if no command-line arguments read data file from standard input
      if (numinputs < 1) {
         infile.read(cin);
      } else {
         infile.read(options.getArg(i+1));
      }
      // analyze the input file according to command-line options
      processRecords(infile, outfile);

      outfile.write(cout);
   }

   return 0;
}
コード例 #3
0
// Listing 4
// Listing 5 code/ch17
int handle_child (void)
{
  ACE_TRACE (ACE_TEXT ("::handle_child"));

  ACE_GUARD_RETURN (ACE_Process_Mutex, ace_mon, coordMutex, -1);

  ALLOCATOR * shmem_allocator = 0;
  ACE_MMAP_Memory_Pool_Options options
    (ACE_DEFAULT_BASE_ADDR,
     ACE_MMAP_Memory_Pool_Options::ALWAYS_FIXED);

  ACE_NEW_RETURN (shmem_allocator,
                  ALLOCATOR (BACKING_STORE,
                             BACKING_STORE,
                             &options),
                  -1);

  MAP *map = smap (shmem_allocator);

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("(%P|%t) Map has %d entries\n"),
              map->current_size ()));
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("In child, map is located at %@\n"),
              map));

  processRecords (map, shmem_allocator);
  shmem_allocator->sync ();
  delete shmem_allocator;

  return 0;
}
コード例 #4
0
ファイル: Connection.cpp プロジェクト: go4and/lib
void Connection::handleRead(const boost::system::error_code & ec, size_t bt, const ConnectionPtr & ptr)
{
    MLOG_MESSAGE(Debug, "handleRead(" << ec << ')');

    if(!ec)
    {
        pos_ += bt;
        if(processRecords())
            startRead();
    }
}
コード例 #5
0
void BudgetBalancer::advancePeriodToDate(QDate const& date)
{
   // if no budget is defined, instantiate a default 1-month budget cycle to
   // attempt to give useful info out of the box
   if (m_period.isNull())
   {
      m_period = DateRange(date, Interval(1, Interval::Period::MONTHS));
   }

   while (m_period.endDate() < date)
   {
      allocateCategories();
      processRecords();
      ++m_period;
   }
}
コード例 #6
0
void BudgetBalancer::processItem(LedgerBudget const& budget)
{
   // if there is a budget period, process recorded items until we are within
   // range of this budget command
   advancePeriodToDate(budget.date());

   // if the current period started before today, or if it already has recorded
   // commands, then end the period today and process what we have
   if (m_period.startDate() != budget.date() || m_numRecords != 0)
   {
      m_period = DateRange(m_period.startDate(), budget.date());
      allocateCategories();
      processRecords();
   }

   // remove categories that are not in this budget command, or that have
   // changed, and allocate their funds to the available category
   auto categories = budget.categories();
   for (auto it = m_categories.cbegin(); it != m_categories.cend(); ++it)
   {
      if (!categories.contains(it.key()) ||
          categories[it.key()].type != it->type)
      {
         switch (it->type)
         {
            case LedgerBudget::Category::Type::GOAL:
               // nothing to do for goals
               break;
            case LedgerBudget::Category::Type::INCOME:
               // nothing to do for income type
               break;
            case LedgerBudget::Category::Type::RESERVE_AMOUNT:
            {
               Currency amount = m_reserveAmountAllocator.deallocate(it.key());
               if (!amount.isZero())
               {
                  emit message(budget,
                               QString("Reserve category '%1' was closed with "
                                       "a balance of %2.  Those funds are "
                                       "available again.")
                               .arg(it.key())
                               .arg(amount.toString()));
               }
               m_available += amount;
               break;
            }
            case LedgerBudget::Category::Type::RESERVE_PERCENT:
            {
               Currency amount = m_reservePercentAllocator.deallocate(it.key());
               if (!amount.isZero())
               {
                  emit message(budget,
                               QString("Reserve category '%1' was closed with "
                                       "a balance of %2.  Those funds are "
                                       "available again.")
                               .arg(it.key())
                               .arg(amount.toString()));
               }
               m_available += amount;
               break;
            }
            case LedgerBudget::Category::Type::ROUTINE:
               m_routineAllocator.deallocate(it.key());
               break;
         }
      }
   }

   // configure new and changed budget categories
   for (auto it = categories.cbegin(); it != categories.cend(); ++it)
   {
      switch (it->type)
      {
         case LedgerBudget::Category::Type::GOAL:
            m_goalAllocator.budget(budget.date());
            break;
         case LedgerBudget::Category::Type::INCOME:
            // nothing to do for income
            break;
         case LedgerBudget::Category::Type::RESERVE_AMOUNT:
            m_reserveAmountAllocator.budget(budget.date(), it.key(), it->amount,
                                            it->interval);
            break;
         case LedgerBudget::Category::Type::RESERVE_PERCENT:
            m_reservePercentAllocator.budget(it.key(), it->percentage);
            break;
         case LedgerBudget::Category::Type::ROUTINE:
            // nothing to do for routine expenses
            break;
      }
   }
   m_categories = categories;

   // reset the dates for the new period
   m_period = DateRange(budget.date(), budget.interval());
}