Kojo / TrainStat
Revision:
4:acfd6fbf9f9e
Child:
5:6105553963bb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/matchLine.cpp	Sun Jul 05 08:09:02 2015 +0000
@@ -0,0 +1,51 @@
+#include <mbed.h>
+#include <stdio.h>
+#include <string.h>
+#include <vector>
+
+#include <SDFileSystem.h>
+#include "matchLine.h"
+
+SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd");
+
+#define ERR(x, ...) std::printf("[DigitalClock : ERR]"x"\r\n", ##__VA_ARGS__);
+
+matchLine::matchLine()  {} ;
+matchLine:: ~matchLine () { };
+
+static void removeCRLF(char *str)
+{
+    for(int i = strlen(str)-1; i>0 ; i--) {
+        if((str[strlen(str)-1] == '\n') || (str[strlen(str)-1] == '\r'))
+            str[strlen(str)-1] = '\0' ;
+        else break ;
+    }
+}
+
+bool matchLine::getList(string filename)
+{
+    int cnt = 0 ;
+    char line[100] ;
+    FILE *fp ;
+    fp = fopen(filename.c_str(), "r");
+    if (fp == NULL) {
+        ERR("Cannot open \"%s\"\n",filename.c_str()) ;
+        return false ;
+    }
+    while (fgets(line, sizeof(line), fp)) {
+        removeCRLF(line) ;
+        list.push_back(line) ;
+    }
+    return true ;
+}
+
+bool matchLine::find(string line)
+{
+    int pos ;
+    string name ;
+    for(int i=0; i<list.size(); i++) {
+        pos = line.find(list[i]) ;
+        if(pos != string::npos)return true ;
+    }
+    return false ;
+} ;