Added a 'companyname' attribute in the Ledger.
[account.git] / account.cpp
index ef1d0b8..ea071d6 100644 (file)
@@ -379,7 +379,7 @@ void Ledger::XML_saldi(std::ostream &s, date period_begin, date period_end)
    int  i;
 
    s << "<?xml version='1.0'?>\n";
-   s << "<accounting>\n";
+   s << "<accounting companyname='" << companyname << "'>\n";
    s << "<balance-sheet begin='" << period_begin << "' end='" << period_end << "'>\n";
    for (i=0; i<nr_accs; i++)
    {
@@ -575,6 +575,7 @@ void Ledger::read(char *filename)
 {
    std::ifstream   in(filename);
    Account   A;
+   char      line_begin;
 
    if (!in)
    {
@@ -583,9 +584,61 @@ void Ledger::read(char *filename)
    }
 
    nr_accs = 0;
-   while (in  >> A)
-      accs[nr_accs++] = A;
+   while (in)
+   {
+      in.get(line_begin);
+      if (isdigit(line_begin))
+      {
+         in.putback(line_begin);
+         in >> A;
+         accs[nr_accs++] = A;
+      }
+      else if (line_begin == '$')
+      {
+         // Optional attributes
+         String  attribute;
+         String  a_name, a_value;
+
+         in >> attribute;
+
+         int  separator = attribute.index('=');
+         do
+         {
+            separator--;
+         }
+         while (isspace(attribute[separator]));
+         a_name = attribute(0, separator+1);
+
+         separator = attribute.index('=');
+         do
+         {
+            separator++;
+         }
+         while (isspace(attribute[separator]));
+         a_value = attribute;
+         a_value(0, separator) = "";
+
+         if (a_name == "companyname")
+         {
+            companyname = a_value;
+         }
+         else
+         {
+            std::cerr << "Unrecognized attribute in Ledger: " << a_name << "\n";
+         }
+      }
+      else if (line_begin == '\n')
+      {
+         //  Ignore empty lines
+      }
+      else
+      {
+         //  Anything else is comment: eat it.
+         String comment;
 
+         in >> comment;
+      }
+   }
    accs[nr_accs].Name() = String("Rekening bestaat niet");
 
 }