MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / FProcessCalendarFile

Function FProcessCalendarFile

io.cpp:1108–1182  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1106// file handle.
1107
1108flag FProcessCalendarFile(CONST char *szFile, FILE *file)
1109{
1110 char szLine[cchSzLine], *pch;
1111 int nState = -1, hr, min, sec;
1112 flag fHaveFile, fRet = fFalse;
1113
1114 fHaveFile = (file != NULL);
1115 if (!fHaveFile) {
1116 file = FileOpen(szFile, 0, NULL);
1117 if (file == NULL)
1118 goto LDone;
1119 }
1120 is.fileIn = file;
1121
1122 loop {
1123 fgets(szLine, cchSzMax, file);
1124 if (feof(file))
1125 break;
1126 for (pch = szLine; *pch; pch++)
1127 ;
1128 while (pch > szLine && pch[-1] <= ' ')
1129 *(--pch) = chNull;
1130
1131 if (nState < 0) {
1132 if (!FMatchSz("BEGIN:VEVENT", szLine))
1133 continue;
1134 nState = 0;
1135 ciCore.nam = ciCore.loc = "";
1136 continue;
1137 }
1138 if (FMatchSz("SUMMARY:", szLine))
1139 ciCore.nam = SzClone(szLine + 8);
1140 else if (FMatchSz("LOCATION:", szLine))
1141 ciCore.loc = SzClone(szLine + 9);
1142 else if (FMatchSz("DTSTART", szLine)) {
1143 for (pch = szLine + 7; *pch && *pch != ':'; pch++)
1144 ;
1145 if (CchSz(pch) < 16)
1146 continue;
1147 pch++;
1148 YY = (pch[0]-'0')*1000 + (pch[1]-'0')*100 + (pch[2]-'0')*10 +
1149 (pch[3]-'0');
1150 if (!FBetween(YY, 0, 9999))
1151 continue;
1152 pch += 4;
1153 MM = (pch[0]-'0')*10 + (pch[1]-'0');
1154 if (!FValidMon(MM))
1155 continue;
1156 pch += 2;
1157 DD = (pch[0]-'0')*10 + (pch[1]-'0');
1158 if (!FValidDay(DD, MM, YY))
1159 continue;
1160 pch += 3;
1161 hr = (pch[0]-'0')*10 + (pch[1]-'0');
1162 min = (pch[2]-'0')*10 + (pch[3]-'0');
1163 sec = (pch[4]-'0')*10 + (pch[5]-'0');
1164 TT = HMS(hr, min, sec);
1165 if (!FValidTim(TT))

Callers 1

FInputDataFunction · 0.85

Calls 5

FileOpenFunction · 0.85
FMatchSzFunction · 0.85
SzCloneFunction · 0.85
CchSzFunction · 0.85
FAppendCIListFunction · 0.85

Tested by

no test coverage detected