1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
int main( int argc, char** argv )
{
// Parse command arguments .................................................
if ((argc == 1) or ishelp( argv[ 1 ] ))
return usage( argv[ 0 ], 0 );
bool verbose = isverbose( argv[ 1 ] );
if (argc != (verbose ? 4 : 3))
return usage( argv[ 0 ], 1, "Incorrect arguments" );
int days = getdays( argv[ verbose ? 2 : 1 ] );
if (days < 0)
return usage( argv[ 0 ], 1, "Invalid DAYS" );
ifstream f( argv[ verbose ? 3 : 2 ] );
if (!f)
return usage( argv[ 0 ], 1, "Invalid FILENAME" );
date_t today = now();
date_t tomorrow = today; tomorrow += days;
// Skip the non-data lines .................................................
// (up to and including the first line starting with a "-")
vector <certificate_t <> > certificates;
{
string s;
do { getline( f, s ); }
while (s.substr( 0, 1 ) != "-");
copy(
istream_iterator <certificate_t <> > ( f ),
istream_iterator <certificate_t <> > (),
back_inserter( certificates )
);
}
cout << "There are " << certificates.size() << " certificates.\n\n";
// Find and display all items past due .....................................
// (Expired items are moved to the END of the vector)
vector <certificate_t <> > ::iterator
certificates_past_due_begin
= stable_partition(
certificates.begin(),
certificates.end(),
expired( today )
);
if (certificates_past_due_begin != certificates.end())
{
cout << "Items PAST DUE\n ";
if (verbose)
copy(
certificates_past_due_begin,
certificates.end(),
ostream_iterator <certificate_t <true> > ( cout, "\n " )
);
else
copy(
certificates_past_due_begin,
certificates.end(),
ostream_iterator <certificate_t <false> > ( cout, "\n " )
);
certificates.erase( certificates_past_due_begin, certificates.end() );
}
else
cout << "No items past due\n";
// Find and display all items due "tomorrow" (today + DAYS) ................
// (Erase all items not soon to expire)
certificates.erase(
remove_if(
certificates.begin(),
certificates.end(),
expired( tomorrow )
),
certificates.end()
);
if (certificates.size())
{
cout << "\nItems due to expire in " << days << " DAYS\n ";
if (verbose)
copy(
certificates.begin(),
certificates.end(),
ostream_iterator <certificate_t <true> > ( cout, "\n " )
);
else
copy(
certificates.begin(),
certificates.end(),
ostream_iterator <certificate_t <false> > ( cout, "\n " )
);
}
else
cout << "\nNo items due to expire in " << days << " days\n";
return 0;
}
|