Kojo / TrainStat
Committer:
takashikojo
Date:
Fri Oct 23 05:51:49 2015 +0000
Revision:
5:6105553963bb
Parent:
4:acfd6fbf9f9e
Child:
6:d4d781f31f70
Initial public version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takashikojo 4:acfd6fbf9f9e 1 #include <mbed.h>
takashikojo 4:acfd6fbf9f9e 2 #include <stdio.h>
takashikojo 4:acfd6fbf9f9e 3 #include <string.h>
takashikojo 4:acfd6fbf9f9e 4 #include <vector>
takashikojo 4:acfd6fbf9f9e 5
takashikojo 4:acfd6fbf9f9e 6 #include <SDFileSystem.h>
takashikojo 4:acfd6fbf9f9e 7 #include "matchLine.h"
takashikojo 4:acfd6fbf9f9e 8
takashikojo 4:acfd6fbf9f9e 9 SDFileSystem sdCard(PTE3, PTE1, PTE2, PTE4, "sd");
takashikojo 4:acfd6fbf9f9e 10
takashikojo 4:acfd6fbf9f9e 11 #define ERR(x, ...) std::printf("[DigitalClock : ERR]"x"\r\n", ##__VA_ARGS__);
takashikojo 4:acfd6fbf9f9e 12
takashikojo 4:acfd6fbf9f9e 13 matchLine::matchLine() {} ;
takashikojo 4:acfd6fbf9f9e 14 matchLine:: ~matchLine () { };
takashikojo 4:acfd6fbf9f9e 15
takashikojo 4:acfd6fbf9f9e 16 static void removeCRLF(char *str)
takashikojo 4:acfd6fbf9f9e 17 {
takashikojo 4:acfd6fbf9f9e 18 for(int i = strlen(str)-1; i>0 ; i--) {
takashikojo 4:acfd6fbf9f9e 19 if((str[strlen(str)-1] == '\n') || (str[strlen(str)-1] == '\r'))
takashikojo 4:acfd6fbf9f9e 20 str[strlen(str)-1] = '\0' ;
takashikojo 4:acfd6fbf9f9e 21 else break ;
takashikojo 4:acfd6fbf9f9e 22 }
takashikojo 4:acfd6fbf9f9e 23 }
takashikojo 4:acfd6fbf9f9e 24
takashikojo 4:acfd6fbf9f9e 25 bool matchLine::getList(string filename)
takashikojo 4:acfd6fbf9f9e 26 {
takashikojo 4:acfd6fbf9f9e 27 int cnt = 0 ;
takashikojo 4:acfd6fbf9f9e 28 char line[100] ;
takashikojo 4:acfd6fbf9f9e 29 FILE *fp ;
takashikojo 4:acfd6fbf9f9e 30 fp = fopen(filename.c_str(), "r");
takashikojo 4:acfd6fbf9f9e 31 if (fp == NULL) {
takashikojo 4:acfd6fbf9f9e 32 ERR("Cannot open \"%s\"\n",filename.c_str()) ;
takashikojo 4:acfd6fbf9f9e 33 return false ;
takashikojo 4:acfd6fbf9f9e 34 }
takashikojo 4:acfd6fbf9f9e 35 while (fgets(line, sizeof(line), fp)) {
takashikojo 4:acfd6fbf9f9e 36 removeCRLF(line) ;
takashikojo 4:acfd6fbf9f9e 37 list.push_back(line) ;
takashikojo 4:acfd6fbf9f9e 38 }
takashikojo 5:6105553963bb 39 fclose(fp) ;
takashikojo 4:acfd6fbf9f9e 40 return true ;
takashikojo 4:acfd6fbf9f9e 41 }
takashikojo 4:acfd6fbf9f9e 42
takashikojo 4:acfd6fbf9f9e 43 bool matchLine::find(string line)
takashikojo 4:acfd6fbf9f9e 44 {
takashikojo 4:acfd6fbf9f9e 45 int pos ;
takashikojo 4:acfd6fbf9f9e 46 string name ;
takashikojo 4:acfd6fbf9f9e 47 for(int i=0; i<list.size(); i++) {
takashikojo 4:acfd6fbf9f9e 48 pos = line.find(list[i]) ;
takashikojo 4:acfd6fbf9f9e 49 if(pos != string::npos)return true ;
takashikojo 4:acfd6fbf9f9e 50 }
takashikojo 4:acfd6fbf9f9e 51 return false ;
takashikojo 4:acfd6fbf9f9e 52 } ;