Parsing text file

Hi guys.
I am trying to parse a file that contains a list of digital certificates and their expiration dates. The file looks like this:

Profile Name Profile Certificate Certificate Certificate User DN
Password Type Renewal Start Private Key
Policy Date (GMT) Expiry (GMT)
------------------------------------------------------------------------------------------------------------------
HSM1: **** HumanPwd Signing 06 Apr 2011 15 Jul 2011 cn=***,o=***,o=***
HSM1: **** AppliPwd Signing 29 Aug 2011 07 Dec 2011 cn=***,o=***,o=***
HSM1: **** AppliPwd Signing 29 Aug 2011 07 Dec 2011 cn=***,o=***,o=***
HSM1: **** HumanPwd Encryption 05 Oct 2011 13 Jan 2012 cn=***,o=***,o=***
HSM1: **** HumanPwd Encryption 12 Jan 2012 21 Apr 2012 cn=***,o=***,o=***


Every line has a fixed number of spaces between each item:
HSM1:****[2]HumanPwd[4]Signing[6]06 Apr 2011[5]15 Jul 2011[5]cn=***,o=***,o=***

With some help from another guy, I got some code done.
I am able to correctly skip the file's header, but when I try to read the contents, it fails and does not load any data into the vectors.
Full code is http://pastebin.com/7GWD56dT (too long to post it), but this is the part where I should be reading the file:

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;
}



Any clues as to what could be wrong?
That program works for me.
Unfortunately it doesn't here :(

root@UBILUSNAGPRD01:~# ./parser2 200 certtest.txt
There are 0 certificates.

No items past due

No items due to expire in 200 days


"certtest.txt" is exactly the same as the one I included in my original post.
And I tried the code on both Linux and Windows (with dev-c++)..

What am I doing wrong?
Its hard to diagnose a problem when you can't reproduce it. One thing I did think of though is possibly your computer's system clock is not set correctly?
That's an incredibly comlpicated way parse a simple file. Sometimes the simple ways are the best.
Given the task to me, I would gladly whip out a Perl script to do that and that is if the employer has no issue with me using Perl.

Some employers have common standardized programming language. You cannot use others (even if they are free), you can only use those mandated.
Unfortunately it has to be in C++ because in a few months I'll be leaving this job and the other guy at the IT dept only knows C++.
Anyhow, both clocks are set to the correct date/timezone - but I don't think that is the issue, because the code doesn't even load any certificates (I always get the "There are 0 certificates." on the console).
Any ideas on where should I start with the debugging?
Topic archived. No new replies allowed.