浏览代码

formatting and error reporting

Wolfgang Ortmann 7 年之前
父节点
当前提交
59e508a6fe
共有 6 个文件被更改,包括 18 次插入39 次删除
  1. 1 16
      src/DateTime.cpp
  2. 10 10
      src/DateTime.h
  3. 3 4
      src/FileName.cpp
  4. 1 2
      src/Image.cpp
  5. 3 5
      src/Lexer.cpp
  6. 0 2
      src/Strings.h

+ 1 - 16
src/DateTime.cpp

@@ -21,7 +21,7 @@ void DateTime::get(int& year, int& month, int& mday,
 
 DateTime::DateTime(int Y, int M, int D, int h, int m, int s)
 {
-  struct tm ltm;
+  tm ltm;
   ltm.tm_year = Y - 1900;
   ltm.tm_mon = M - 1;
   ltm.tm_mday = D;
@@ -32,21 +32,6 @@ DateTime::DateTime(int Y, int M, int D, int h, int m, int s)
   theTime = mktime(&ltm);
 }
 
-#if 0
-struct tm
-{
-  int tm_sec;    /* Seconds (0-60) */
-  int tm_min;    /* Minutes (0-59) */
-  int tm_hour;   /* Hours (0-23) */
-  int tm_mday;   /* Day of the month (1-31) */
-  int tm_mon;    /* Month (0-11) */
-  int tm_year;   /* Year - 1900 */
-  int tm_wday;   /* Day of the week (0-6, Sunday = 0) */
-  int tm_yday;   /* Day in the year (0-365, 1 Jan = 0) */
-  int tm_isdst;  /* Daylight saving time */
-};
-#endif
-
 bool DateTime::match(const set<int>& Y, const set<int>& M, const set<int>& D,
                      const set<int>& W,
                      const set<int>& h, const set<int>& m, const set<int>& s) const

+ 10 - 10
src/DateTime.h

@@ -11,7 +11,7 @@ class DateTime
 public:
   static DateTime now()
   {
-    return DateTime(time(NULL));
+    return DateTime(time(nullptr));
   }
 
   DateTime(): theTime(0) {}
@@ -20,6 +20,11 @@ public:
 
   DateTime(int Y, int M, int D, int h, int m, int s);
 
+  void get(int& year, int& month, int& mday,
+           int& hour, int& min, int& sec) const;
+
+  std::string getString(char typ = 'h') const;
+
   friend DateTime operator+(const DateTime& t1, time_t t2)
   {
     return DateTime(t1.theTime + t2);
@@ -31,10 +36,10 @@ public:
     return *this;
   }
 
-  void get(int& year, int& month, int& mday,
-           int& hour, int& min, int& sec) const;
-
-  std::string getString(char typ = 'h') const;
+  friend DateTime operator-(const DateTime& t1, time_t t2)
+  {
+    return DateTime(t1.theTime - t2);
+  }
 
   const DateTime& operator-=(time_t t2)
   {
@@ -42,11 +47,6 @@ public:
     return *this;
   }
 
-  friend DateTime operator-(const DateTime& t1, time_t t2)
-  {
-    return DateTime(t1.theTime - t2);
-  }
-
   friend time_t operator-(const DateTime& t1, const DateTime& t2)
   {
     return t1.theTime - t2.theTime;

+ 3 - 4
src/FileName.cpp

@@ -64,7 +64,7 @@ void FileName::setName(const string& n)
 {
   for (unsigned int i = 0; i < n.size(); ++i)
     if (n[i] == pathdel)
-      throw Exception("Filename", "path delimiter in name");
+      throw Exception("Filename::setName", "path delimiter in name");
   name = n;
 }
 
@@ -73,9 +73,9 @@ void FileName::setExtension(const string& n)
   for (unsigned int i = 0; i < n.size(); ++i)
     {
       if (n[i] == extdel)
-        throw Exception("Filename", "extension delimiter in extension");
+        throw Exception("Filename::setExtension", "extension delimiter in extension");
       if (n[i] == pathdel)
-        throw Exception("Filename", "path delimiter in extension");
+        throw Exception("Filename::setExtension", "path delimiter in extension");
     }
   extension = n;
 }
@@ -144,4 +144,3 @@ int main(int argc, char** argv)
     }
 }
 #endif
-

+ 1 - 2
src/Image.cpp

@@ -26,7 +26,7 @@ Image::Image(const string& dir): name(dir)
       Strings expireText;
       file2Strings(expireFileName, expireText);
       if (expireText.empty())
-        throw Exception("expireDate", "expire empty");
+        throw Exception("expireDate", "expire file empty");
       stringToDate(expireText[0], expire, series);
       expireRule = expireText[1];
     }
@@ -42,7 +42,6 @@ void Image::printInfo() const
       cout << "created: " << time.getString('h') << endl;
       cout << "expires: " << expire.getString('h') << " -  " << timeString(expire - DateTime::now()) << endl;
     }
-
   else
     cout << "invalid" << endl;
 }

+ 3 - 5
src/Lexer.cpp

@@ -22,7 +22,8 @@ char Lexer::getChar()
 
 void Lexer::skipChar()
 {
-  pos++;
+  if (pos < str.size())
+    pos++;
 }
 
 void Lexer::skipWhiteSpace()
@@ -43,7 +44,7 @@ void Lexer::nextToken()
       if (isdigit(f))
         {
           // token is number
-          type = integer; // assume "integer"
+          type = integer; // assume "integer", changed later if necessarry
           // number
           f = nextChar();
           while (isdigit(f) || f == '.')
@@ -78,11 +79,9 @@ void Lexer::nextToken()
         }
       else if (isalpha(f))
         {
-          //    cout << "id"<<endl;
           // identifier
           type = identifier;
           f = nextChar();
-          //    cout << (int)f << " " << f << endl;
           while (isalnum(f))
             {
               token += f;
@@ -101,7 +100,6 @@ void Lexer::nextToken()
 
 long int Lexer::getInt()
 {
-  // cout << "type: " << type << " token:" << token << endl;
   if (type != integer)
     throw Exception("getInt", "integer value expected");
   int res = stol(token);

+ 0 - 2
src/Strings.h

@@ -19,6 +19,4 @@ public:
     return *this;
   }
 };
-
-
 #endif